RAW_VOID raw_malloc_init() { MACB *macb = (MACB*)((RAW_U32)(&malloc_macb) & ~0x00000007U); if ((RAW_U32)(&malloc_macb) != (RAW_U32)macb) { RAW_ASSERT(0); } list_init(&macb->areaque); list_init(&macb->freeque); macb->pagesz = 2048; macb->testmode = 0; macb->getblk = raw_page_allocate; macb->relblk = raw_page_free; raw_mutex_create(&macb->mem_lock, (RAW_U8 *)"malloc_lock", RAW_MUTEX_INHERIT_POLICY, 0); }
/* ************************************************************************************************************************ * Init raw os * * Description: This function is called to init raw os. * * Arguments :None * ----- * * * * Returns RAW_U16: RAW_SUCCESS. * * Note(s) * * ************************************************************************************************************************ */ RAW_OS_ERROR raw_os_init(void) { TRACE_INIT(); raw_os_active = RAW_OS_STOPPED; run_queue_init(&raw_ready_queue); /*Init the tick heart system*/ tick_list_init(); /*Init the task debug head list*/ list_init(&(raw_task_debug.task_head)); #if (CONFIG_RAW_USER_HOOK > 0) raw_os_init_hook(); #endif /*Start the first idle task*/ raw_task_create(&raw_idle_obj, (RAW_U8 *)"idle_task", 0, IDLE_PRIORITY, 0, idle_stack, IDLE_STACK_SIZE, raw_idle_task, 1); /*The timer module need mutex*/ #if (CONFIG_RAW_TIMER > 0) raw_timer_init(); raw_mutex_create(&timer_mutex, (RAW_U8 *)"timer_mutex", RAW_MUTEX_INHERIT_POLICY, 0); #endif /*tick task to reduce interrupt time*/ #if (CONFIG_RAW_TICK_TASK > 0) tick_task_start(); #endif /*For statistic*/ #if (RAW_CONFIG_CPU_TASK > 0) cpu_task_start(); #endif return RAW_SUCCESS; }
void test_mutex1(void * pParam) { raw_mutex_create(&mutext1, (RAW_U8 *)"mutex1", RAW_MUTEX_INHERIT_POLICY, 0); //raw_mutex_create(&mutext1, (RAW_U8 *)"mutex1", RAW_MUTEX_CEILING_POLICY, 9); //raw_mutex_create(&mutext1, (RAW_U8 *)"mutex1", RAW_MUTEX_NONE_POLICY, 9); while(1) { raw_sleep(RAW_TICKS_PER_SECOND); vc_port_printf("..............................\n"); raw_mutex_get(&mutext1, 2); vc_port_printf("test_mutex1\n"); raw_mutex_put(&mutext1); } }