rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <k_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmsis_os.h>
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
#define DEMO_TASK_PRIORITY 20
extern void stm32_soc_init(void);
static ktask_t demo_task_obj;
static cpu_stack_t demo_task_buf[DEMO_TASK_STACKSIZE];
static osThreadDef_t thread;
static void demo_task(void *arg)
{
int count = 0;
stm32_soc_init();
printf("demo_task here!\n");
printf("rhino memory is %d!\n", krhino_global_space_get());
while (1)
{
printf("hello world! count %d\n", count++);
//sleep 1 second
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
};
}
int main(void)
{
osKernelInitialize();
thread.name = "demo_task";
thread.pthread = (os_pthread)demo_task;
thread.tpriority = osPriorityNormal;
thread.stacksize = DEMO_TASK_STACKSIZE;
thread.ptcb = &demo_task_obj;
thread.pstackspace = demo_task_buf;
osThreadCreate (&thread, NULL);
osKernelStart();
return 0;
}

View file

@ -0,0 +1,108 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <k_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmsis_os.h>
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
#define DEMO_TASK_PRIORITY 20
static ktask_t init_task_obj;
static ktask_t demo_task_obj1;
static ktask_t demo_task_obj2;
static cpu_stack_t init_task_buf[DEMO_TASK_STACKSIZE];
static cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
static cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];
static osThreadDef_t thread_init;
static osThreadDef_t thread1;
static osThreadDef_t thread2;
static kbuf_queue_t buf_queue;
static osMessageQDef_t msg_queue_def;
static osMessageQId p_msgqueue;
static uint32_t msg_buf_space[32];
static void init_task(void *arg)
{
printf("init_task here!\n");
msg_queue_def.name = "buf_queue";
msg_queue_def.queue = &buf_queue;
msg_queue_def.queue_sz = 32;
msg_queue_def.item_sz = 4;
msg_queue_def.pool = msg_buf_space;
p_msgqueue = osMessageCreate (&msg_queue_def, (osThreadId)NULL);
if (p_msgqueue == NULL)
{
printf("osMessageCreate failed\n");
}
else
{
printf("osMessageCreate ok\n");
}
}
static void demo_task1(void *arg)
{
osEvent event;
while (1)
{
event = osMessageGet(p_msgqueue, osWaitForever);
if (event.status == osEventMessage)
{
printf("demo_task1 get msg %d\n", event.value.v);
}
else
{
printf("demo_task1 get msg failed\n");
}
};
}
static void demo_task2(void *arg)
{
uint32_t count = 0;
while (1)
{
osMessagePut(p_msgqueue,count,0xffffffff);
printf("demo_task2 put msg %d\n", count++);
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
};
}
void cmsis_msgqueue_test(void)
{
thread_init.name = "init_task";
thread_init.pthread = (os_pthread)init_task;
thread_init.tpriority = osPriorityHigh;
thread_init.stacksize = DEMO_TASK_STACKSIZE;
thread_init.ptcb = &init_task_obj;
thread_init.pstackspace = init_task_buf;
thread1.name = "demo_task1";
thread1.pthread = (os_pthread)demo_task1;
thread1.tpriority = osPriorityNormal;
thread1.stacksize = DEMO_TASK_STACKSIZE;
thread1.ptcb = &demo_task_obj1;
thread1.pstackspace = demo_task_buf1;
thread2.name = "demo_task2";
thread2.pthread = (os_pthread)demo_task2;
thread2.tpriority = osPriorityNormal;
thread2.stacksize = DEMO_TASK_STACKSIZE;
thread2.ptcb = &demo_task_obj2;
thread2.pstackspace = demo_task_buf2;
osThreadCreate (&thread_init, NULL);
osThreadCreate (&thread1, NULL);
osThreadCreate (&thread2, NULL);
}

View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <k_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmsis_os.h>
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
#define DEMO_TASK_PRIORITY 20
static ktask_t init_task_obj;
static ktask_t demo_task_obj1;
static ktask_t demo_task_obj2;
static cpu_stack_t init_task_buf[DEMO_TASK_STACKSIZE];
static cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
static cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];
static osThreadDef_t thread_init;
static osThreadDef_t thread1;
static osThreadDef_t thread2;
static kmutex_t mutex;
static osMutexDef_t mutex_def;
static osMutexId pMutex;
static void init_task(void *arg)
{
mutex_def.name = "mutex";
mutex_def.mutex = &mutex;
pMutex = osMutexCreate (&mutex_def);
if (pMutex == NULL)
{
printf("osMutexCreate failed\n");
}
else
{
printf("osMutexCreate ok\n");
}
}
static void demo_task1(void *arg)
{
int count = 0;
while (1)
{
osMutexWait(pMutex, 0xffffffff);
printf("demo_task1 get mutex %d\n", count++);
};
}
static void demo_task2(void *arg)
{
int count = 0;
while (1)
{
osMutexRelease(pMutex);
printf("demo_task2 release mutex %d\n", count++);
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
};
}
void cmsis_mutex_test(void)
{
thread_init.name = "init_task";
thread_init.pthread = (os_pthread)init_task;
thread_init.tpriority= osPriorityHigh;
thread_init.stacksize= DEMO_TASK_STACKSIZE;
thread_init.ptcb = &init_task_obj;
thread_init.pstackspace = init_task_buf;
thread1.name = "demo_task1";
thread1.pthread = (os_pthread)demo_task1;
thread1.tpriority= osPriorityNormal;
thread1.stacksize= DEMO_TASK_STACKSIZE;
thread1.ptcb = &demo_task_obj1;
thread1.pstackspace = demo_task_buf1;
thread2.name = "demo_task2";
thread2.pthread = (os_pthread)demo_task2;
thread2.tpriority= osPriorityNormal;
thread2.stacksize= DEMO_TASK_STACKSIZE;
thread2.ptcb = &demo_task_obj2;
thread2.pstackspace = demo_task_buf2;
osThreadCreate (&thread_init, NULL);
osThreadCreate (&thread1, NULL);
osThreadCreate (&thread2, NULL);
}

View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <k_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmsis_os.h>
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
#define DEMO_TASK_PRIORITY 20
static ktask_t init_task_obj;
static ktask_t demo_task_obj1;
static ktask_t demo_task_obj2;
static cpu_stack_t init_task_buf[DEMO_TASK_STACKSIZE];
static cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
static cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];
static osThreadDef_t thread_init;
static osThreadDef_t thread1;
static osThreadDef_t thread2;
static ksem_t sem;
static osSemaphoreDef_t sem_def;
static osSemaphoreId pSem;
static void init_task(void *arg)
{
sem_def.name = "sem";
sem_def.sem = &sem;
pSem = osSemaphoreCreate (&sem_def, 0);
if (pSem == NULL)
{
printf("osSemaphoreCreate failed\n");
}
else
{
printf("osSemaphoreCreate ok\n");
}
}
static void demo_task1(void *arg)
{
int count = 0;
while (1)
{
osSemaphoreWait(pSem, 0xffffffff);
printf("demo_task1 get sem %d\n", count++);
};
}
static void demo_task2(void *arg)
{
int count = 0;
while (1)
{
osSemaphoreRelease(pSem);
printf("demo_task2 release sem %d\n", count++);
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
};
}
void cmsis_sem_test(void)
{
thread_init.name = "init_task";
thread_init.pthread = (os_pthread)init_task;
thread_init.tpriority = osPriorityHigh;
thread_init.stacksize = DEMO_TASK_STACKSIZE;
thread_init.ptcb = &init_task_obj;
thread_init.pstackspace = init_task_buf;
thread1.name = "demo_task1";
thread1.pthread = (os_pthread)demo_task1;
thread1.tpriority = osPriorityNormal;
thread1.stacksize = DEMO_TASK_STACKSIZE;
thread1.ptcb = &demo_task_obj1;
thread1.pstackspace = demo_task_buf1;
thread2.name = "demo_task2";
thread2.pthread = (os_pthread)demo_task2;
thread2.tpriority = osPriorityNormal;
thread2.stacksize = DEMO_TASK_STACKSIZE;
thread2.ptcb = &demo_task_obj2;
thread2.pstackspace = demo_task_buf2;
osThreadCreate (&thread_init, NULL);
osThreadCreate (&thread1, NULL);
osThreadCreate (&thread2, NULL);
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <k_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmsis_os.h>
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
#define DEMO_TASK_PRIORITY 20
static ktask_t demo_task_obj;
static cpu_stack_t demo_task_buf[DEMO_TASK_STACKSIZE];
static osThreadDef_t thread;
static osTimerDef_t timer_def;
static ktimer_t timer_space;
static int timer_cb_count = 0;
static void timer_function(void)
{
timer_cb_count ++;
printf("timer cb is called, timer_cb_count = %d\n");
}
static void demo_task(void *arg)
{
int count = 0;
osTimerId pTimerId = NULL;
timer_def.name = "testTimer";
timer_def.cb = (os_ptimer)timer_function;
timer_def.timer= &timer_space;
pTimerId = osTimerCreate (&timer_def, osTimerPeriodic, NULL);
if (pTimerId == NULL)
{
printf("osTimerCreate failed, MAX_TIMER_TICKS = %d\n",MAX_TIMER_TICKS);
}
else
{
printf("osTimerCreate ok\n");
}
osTimerStart (pTimerId, 1000000);
while (1)
{
printf("hello world! count %d\n", count++);
//sleep 1 second
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
if (timer_cb_count > 10)
{
osTimerStop(pTimerId);
}
};
}
void cmsis_timer_test(void)
{
thread.name = "demo_task";
thread.pthread = (os_pthread)demo_task;
thread.tpriority= osPriorityNormal;
thread.stacksize= DEMO_TASK_STACKSIZE;
thread.ptcb = &demo_task_obj;
thread.pstackspace = demo_task_buf;
osThreadCreate (&thread, NULL);
}