/** * @ingroup SystemInit * This function will init the system scheduler * */ void rt_system_scheduler_init(void) { register rt_base_t offset; rt_scheduler_lock_nest = 0; for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++) { rt_list_init(&rt_thread_priority_table[offset]); } rt_current_priority = RT_THREAD_PRIORITY_MAX - 1; rt_current_thread = RT_NULL; /* init ready priority group */ rt_thread_ready_priority_group = 0; #if RT_THREAD_PRIORITY_MAX > 32 /* init ready table */ rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table)); #endif #ifdef RT_USING_HEAP /* init thread defunct */ rt_list_init(&rt_thread_defunct); #endif }
/** * @ingroup SystemInit * This function will initialize the system scheduler */ void rt_system_scheduler_init(void) { register rt_base_t offset; rt_scheduler_lock_nest = 0; RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("start scheduler: max priority 0x%02x\n", RT_THREAD_PRIORITY_MAX)); for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++) { rt_list_init(&rt_thread_priority_table[offset]); } rt_current_priority = RT_THREAD_PRIORITY_MAX - 1; rt_current_thread = RT_NULL; /* initialize ready priority group */ rt_thread_ready_priority_group = 0; #if RT_THREAD_PRIORITY_MAX > 32 /* initialize ready table */ rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table)); #endif /* initialize thread defunct */ rt_list_init(&rt_thread_defunct); }
rt_err_t rt_data_queue_init(struct rt_data_queue *queue, rt_uint16_t size, rt_uint16_t lwm, void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event)) { RT_ASSERT(queue != RT_NULL); queue->evt_notify = evt_notify; queue->size = size; queue->lwm = lwm; queue->waiting_lwm = RT_FALSE; queue->get_index = 0; queue->put_index = 0; rt_list_init(&(queue->suspended_push_list)); rt_list_init(&(queue->suspended_pop_list)); queue->queue = (struct rt_data_item *)rt_malloc(sizeof(struct rt_data_item) * size); if (queue->queue == RT_NULL) { return -RT_ENOMEM; } return RT_EOK; }
/** * @ingroup SystemInit * * This function will initialize system timer * */ void rt_system_timer_init(void) { rt_list_init(&rt_timer_list); #ifdef RT_USING_TIMER_SOFT rt_list_init(&rt_soft_timer_list); rt_sem_init(&timer_sem, "timer", 0, RT_IPC_FLAG_FIFO); #endif }
static rt_err_t _rt_rms_init(struct rt_rms *rms, rt_uint8_t period, rt_uint8_t wcet) { /* init rms list */ rt_list_init(&(rms->rlist)); rms->thread->stat = RT_RMS_INIT; rms->period = period; rms->wcet = wcet; rms->utilization = (float)wcet / period; utilization += rms->utilization; RT_ASSERT(utilization <= 1); /* init the rms timer for activating next job */ rt_timer_init(&(rms->rms_timer), rms->thread->name, rt_rms_wakeup, (void *)rms->period, rms->period, RT_TIMER_FLAG_PERIODIC); /* start the rms timer */ rt_timer_start(&(rms->rms_timer)); return RT_RMS_EOK; }
/** * This function will initialize an IPC object * * @param ipc the IPC object * * @return the operation status, RT_EOK on successful */ rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc) { /* init ipc object */ rt_list_init(&(ipc->suspend_thread)); return RT_EOK; }
static void _rt_timer_init(rt_timer_t timer, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag) { int i; /* set flag */ timer->parent.flag = flag; /* set deactivated */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; timer->timeout_func = timeout; timer->parameter = parameter; timer->timeout_tick = 0; timer->init_tick = time; /* initialize timer list */ for (i = 0; i < RT_TIMER_SKIP_LIST_LEVEL; i++) { rt_list_init(&(timer->row[i])); } }
/** * @ingroup SystemInit * * This function will initialize system timer thread */ void rt_system_timer_thread_init(void) { #ifdef RT_USING_TIMER_SOFT int i; for (i = 0; i < sizeof(rt_soft_timer_list)/sizeof(rt_soft_timer_list[0]); i++) { rt_list_init(rt_soft_timer_list+i); } /* start software timer thread */ rt_thread_init(&timer_thread, "timer", rt_thread_timer_entry, RT_NULL, &timer_thread_stack[0], sizeof(timer_thread_stack), RT_TIMER_THREAD_PRIO, 10); /* startup */ rt_thread_startup(&timer_thread); #endif }
/** * @ingroup SystemInit * * This function will initialize system timer */ void rt_system_timer_init(void) { int i; for (i = 0; i < sizeof(rt_timer_list)/sizeof(rt_timer_list[0]); i++) { rt_list_init(rt_timer_list+i); } }
void rt_completion_init(struct rt_completion *completion) { rt_base_t level; RT_ASSERT(completion != RT_NULL); level = rt_hw_interrupt_disable(); completion->flag = RT_UNCOMPLETED; rt_list_init(&completion->suspended_list); rt_hw_interrupt_enable(level); }
/** * This function will create a mempool object and allocate the memory pool from * heap. * * @param name the name of memory pool * @param block_count the count of blocks in memory pool * @param block_size the size for each block * * @return the created mempool object */ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_size) { rt_uint8_t *block_ptr; struct rt_mempool *mp; register rt_base_t offset; RT_DEBUG_NOT_IN_INTERRUPT; /* allocate object */ mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name); /* allocate object failed */ if (mp == RT_NULL) return RT_NULL; /* initialize memory pool */ block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE); mp->block_size = block_size; mp->size = (block_size + sizeof(rt_uint8_t *)) * block_count; /* allocate memory */ mp->start_address = rt_malloc((block_size + sizeof(rt_uint8_t *)) * block_count); if (mp->start_address == RT_NULL) { /* no memory, delete memory pool object */ rt_object_delete(&(mp->parent)); return RT_NULL; } mp->block_total_count = block_count; mp->block_free_count = mp->block_total_count; /* initialize suspended thread list */ rt_list_init(&(mp->suspend_thread)); mp->suspend_thread_count = 0; /* initialize free block list */ block_ptr = (rt_uint8_t *)mp->start_address; for (offset = 0; offset < mp->block_total_count; offset ++) { *(rt_uint8_t **)(block_ptr + offset * (block_size + sizeof(rt_uint8_t *))) = block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *)); } *(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) = RT_NULL; mp->block_list = block_ptr; return mp; }
static rt_err_t _rt_thread_init(struct rt_thread *thread, const char *name, void (*entry)(void *parameter), void *parameter, void *stack_start, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick) { /* init thread list */ rt_list_init(&(thread->tlist)); thread->entry = (void *)entry; thread->parameter = parameter; /* stack init */ thread->stack_addr = stack_start; thread->stack_size = (rt_uint16_t)stack_size; /* init thread stack */ rt_memset(thread->stack_addr, '#', thread->stack_size); thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, (void *)((char *)thread->stack_addr + thread->stack_size - 4), (void *)rt_thread_exit); /* priority init */ RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX); thread->init_priority = priority; thread->current_priority = priority; /* tick init */ thread->init_tick = tick; thread->remaining_tick = tick; /* error and flags */ thread->error = RT_EOK; thread->stat = RT_THREAD_INIT; /* initialize cleanup function and user data */ thread->cleanup = 0; thread->user_data = 0; /* init thread timer */ rt_timer_init(&(thread->thread_timer), thread->name, rt_thread_timeout, thread, 0, RT_TIMER_FLAG_ONE_SHOT); return RT_EOK; }
/** * This function will initialize a memory pool object, normally which is used * for static object. * * @param mp the memory pool object * @param name the name of memory pool * @param start the star address of memory pool * @param size the total size of memory pool * @param block_size the size for each block * * @return RT_EOK */ rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_size_t size, rt_size_t block_size) { rt_uint8_t *block_ptr; register rt_base_t offset; /* parameter check */ RT_ASSERT(mp != RT_NULL); /* initialize object */ rt_object_init(&(mp->parent), RT_Object_Class_MemPool, name); /* initialize memory pool */ mp->start_address = start; mp->size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE); /* align the block size */ block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE); mp->block_size = block_size; /* align to align size byte */ mp->block_total_count = mp->size / (mp->block_size + sizeof(rt_uint8_t *)); mp->block_free_count = mp->block_total_count; /* initialize suspended thread list */ rt_list_init(&(mp->suspend_thread)); mp->suspend_thread_count = 0; /* initialize free block list */ block_ptr = (rt_uint8_t *)mp->start_address; for (offset = 0; offset < mp->block_total_count; offset ++) { *(rt_uint8_t **)(block_ptr + offset * (block_size + sizeof(rt_uint8_t *))) = (rt_uint8_t *)(block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *))); } *(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) = RT_NULL; mp->block_list = block_ptr; return RT_EOK; }
static void _rt_timer_init(rt_timer_t timer, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag) { /* set flag */ timer->parent.flag = flag; /* set deactivated */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; timer->timeout_func = timeout; timer->parameter = parameter; timer->timeout_tick = 0; timer->init_tick = time; /* initialize timer list */ rt_list_init(&(timer->list)); }
rt_err_t rt_prio_queue_init(struct rt_prio_queue *que, const char *name, void *buf, rt_size_t bufsz, rt_size_t itemsz) { RT_ASSERT(que); rt_memset(que, 0, sizeof(*que)); rt_list_init(&(que->suspended_pop_list)); rt_mp_init(&que->pool, name, buf, bufsz, sizeof(struct rt_prio_queue_item) + itemsz); que->item_sz = itemsz; return RT_EOK; }
/** * @ingroup SystemInit * * This function will init system timer * */ void rt_system_timer_init() { rt_list_init(&rt_timer_list); rt_list_init(&rt_soft_timer_list); }
void rt_mq_system_init() { rt_list_init(&_mq_list); _mq_list_mutex = SDL_CreateMutex(); }
/** * @ingroup SystemInit * * This function will initialize system object management * */ void rt_system_object_init(void) { /* init object container - thread */ rt_list_init(&(rt_object_container[RT_Object_Class_Thread].object_list)); rt_object_container[RT_Object_Class_Thread].object_size = sizeof(struct rt_thread); rt_object_container[RT_Object_Class_Thread].type = RT_Object_Class_Thread; #ifdef RT_USING_MODULE /* init object container - module */ rt_list_init(&(rt_object_container[RT_Object_Class_Module].object_list)); rt_object_container[RT_Object_Class_Module].object_size = sizeof(struct rt_module); rt_object_container[RT_Object_Class_Module].type = RT_Object_Class_Module; #endif #ifdef RT_USING_SEMAPHORE /* init object container - semaphore */ rt_list_init(&(rt_object_container[RT_Object_Class_Semaphore].object_list)); rt_object_container[RT_Object_Class_Semaphore].object_size = sizeof(struct rt_semaphore); rt_object_container[RT_Object_Class_Semaphore].type = RT_Object_Class_Semaphore; #endif #ifdef RT_USING_MUTEX /* init object container - mutex */ rt_list_init(&(rt_object_container[RT_Object_Class_Mutex].object_list)); rt_object_container[RT_Object_Class_Mutex].object_size = sizeof(struct rt_mutex); rt_object_container[RT_Object_Class_Mutex].type = RT_Object_Class_Mutex; #endif #ifdef RT_USING_EVENT /* init object container - event */ rt_list_init(&(rt_object_container[RT_Object_Class_Event].object_list)); rt_object_container[RT_Object_Class_Event].object_size = sizeof(struct rt_event); rt_object_container[RT_Object_Class_Event].type = RT_Object_Class_Event; #endif #ifdef RT_USING_MAILBOX /* init object container - mailbox */ rt_list_init(&(rt_object_container[RT_Object_Class_MailBox].object_list)); rt_object_container[RT_Object_Class_MailBox].object_size = sizeof(struct rt_mailbox); rt_object_container[RT_Object_Class_MailBox].type = RT_Object_Class_MailBox; #endif #ifdef RT_USING_MESSAGEQUEUE /* init object container - message queue */ rt_list_init(&(rt_object_container[RT_Object_Class_MessageQueue].object_list)); rt_object_container[RT_Object_Class_MessageQueue].object_size = sizeof(struct rt_messagequeue); rt_object_container[RT_Object_Class_MessageQueue].type = RT_Object_Class_MessageQueue; #endif #ifdef RT_USING_MEMPOOL /* init object container - memory pool */ rt_list_init(&(rt_object_container[RT_Object_Class_MemPool].object_list)); rt_object_container[RT_Object_Class_MemPool].object_size = sizeof(struct rt_mempool); rt_object_container[RT_Object_Class_MemPool].type = RT_Object_Class_MemPool; #endif #ifdef RT_USING_DEVICE /* init object container - device */ rt_list_init(&(rt_object_container[RT_Object_Class_Device].object_list)); rt_object_container[RT_Object_Class_Device].object_size = sizeof(struct rt_device); rt_object_container[RT_Object_Class_Device].type = RT_Object_Class_Device; #endif /* init object container - timer */ rt_list_init(&(rt_object_container[RT_Object_Class_Timer].object_list)); rt_object_container[RT_Object_Class_Timer].object_size = sizeof(struct rt_timer); rt_object_container[RT_Object_Class_Timer].type = RT_Object_Class_Timer; }
void rt_module_init_object_container(struct rt_module *module) { RT_ASSERT(module != RT_NULL); /* initialize object container - thread */ rt_list_init(&(module->module_object[RT_Object_Class_Thread].object_list)); module->module_object[RT_Object_Class_Thread].object_size = sizeof(struct rt_thread); module->module_object[RT_Object_Class_Thread].type = RT_Object_Class_Thread; #ifdef RT_USING_SEMAPHORE /* initialize object container - semaphore */ rt_list_init(&(module->module_object[RT_Object_Class_Semaphore].object_list)); module->module_object[RT_Object_Class_Semaphore].object_size = sizeof(struct rt_semaphore); module->module_object[RT_Object_Class_Semaphore].type = RT_Object_Class_Semaphore; #endif #ifdef RT_USING_MUTEX /* initialize object container - mutex */ rt_list_init(&(module->module_object[RT_Object_Class_Mutex].object_list)); module->module_object[RT_Object_Class_Mutex].object_size = sizeof(struct rt_mutex); module->module_object[RT_Object_Class_Mutex].type = RT_Object_Class_Mutex; #endif #ifdef RT_USING_EVENT /* initialize object container - event */ rt_list_init(&(module->module_object[RT_Object_Class_Event].object_list)); module->module_object[RT_Object_Class_Event].object_size = sizeof(struct rt_event); module->module_object[RT_Object_Class_Event].type = RT_Object_Class_Event; #endif #ifdef RT_USING_MAILBOX /* initialize object container - mailbox */ rt_list_init(&(module->module_object[RT_Object_Class_MailBox].object_list)); module->module_object[RT_Object_Class_MailBox].object_size = sizeof(struct rt_mailbox); module->module_object[RT_Object_Class_MailBox].type = RT_Object_Class_MailBox; #endif #ifdef RT_USING_MESSAGEQUEUE /* initialize object container - message queue */ rt_list_init(&(module->module_object[RT_Object_Class_MessageQueue].object_list)); module->module_object[RT_Object_Class_MessageQueue].object_size = sizeof(struct rt_messagequeue); module->module_object[RT_Object_Class_MessageQueue].type = RT_Object_Class_MessageQueue; #endif #ifdef RT_USING_MEMHEAP /* initialize object container - memory heap */ rt_list_init(&(module->module_object[RT_Object_Class_MemHeap].object_list)); module->module_object[RT_Object_Class_MemHeap].object_size = sizeof(struct rt_memheap); module->module_object[RT_Object_Class_MemHeap].type = RT_Object_Class_MemHeap; #endif #ifdef RT_USING_MEMPOOL /* initialize object container - memory pool */ rt_list_init(&(module->module_object[RT_Object_Class_MemPool].object_list)); module->module_object[RT_Object_Class_MemPool].object_size = sizeof(struct rt_mempool); module->module_object[RT_Object_Class_MemPool].type = RT_Object_Class_MemPool; #endif #ifdef RT_USING_DEVICE /* initialize object container - device */ rt_list_init(&(module->module_object[RT_Object_Class_Device].object_list)); module->module_object[RT_Object_Class_Device].object_size = sizeof(struct rt_device); module->module_object[RT_Object_Class_Device].type = RT_Object_Class_Device; #endif /* initialize object container - timer */ rt_list_init(&(module->module_object[RT_Object_Class_Timer].object_list)); module->module_object[RT_Object_Class_Timer].object_size = sizeof(struct rt_timer); module->module_object[RT_Object_Class_Timer].type = RT_Object_Class_Timer; }