/*! * \brief Creates the periodic timer queue. * * \param[in] period_ptr The location of the data structure to be initialized. * \param[in] period The cycle length of this timer in ticks. * \param[in] wait_ticks The number of ticks to wait before starting this queue. * * \return MQX_OK * * \see _lwtimer_add_timer_to_queue * \see _lwtimer_cancel_period * \see _lwtimer_cancel_timer * \see _lwtimer_create_periodic_queue * \see LWTIMER_PERIOD_STRUCT */ _mqx_uint _lwtimer_create_periodic_queue ( LWTIMER_PERIOD_STRUCT_PTR period_ptr, _mqx_uint period, _mqx_uint wait_ticks ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; _GET_KERNEL_DATA(kernel_data); _KLOGE4(KLOG_lwtimer_create_periodic_queue, period_ptr, period, wait_ticks); period_ptr->PERIOD = period; period_ptr->EXPIRY = 0; period_ptr->WAIT = wait_ticks; _QUEUE_INIT(&period_ptr->TIMERS,0); period_ptr->TIMER_PTR = (void *) &period_ptr->TIMERS; _int_disable(); if (kernel_data->LWTIMERS.NEXT == NULL) { /* Initialize the light weight timer queue */ _QUEUE_INIT(&kernel_data->LWTIMERS, 0); kernel_data->LWTIMER_ISR = _lwtimer_isr_internal; } /* Endif */ period_ptr->VALID = LWTIMER_VALID; _QUEUE_ENQUEUE(&kernel_data->LWTIMERS, &period_ptr->LINK); _int_enable(); _KLOGX2(KLOG_lwtimer_create_periodic_queue, MQX_OK); return (MQX_OK); } /* Endbody */
pointer _taskq_create ( /* [IN] the policy of this task queue (fifo or priority queueing) */ _mqx_uint policy ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TASK_QUEUE_STRUCT_PTR task_queue_ptr; _GET_KERNEL_DATA(kernel_data); _KLOGE2(KLOG_taskq_create, policy); #if MQX_CHECK_ERRORS if (! ((policy == MQX_TASK_QUEUE_FIFO) || (policy == MQX_TASK_QUEUE_BY_PRIORITY))) { _task_set_error(MQX_INVALID_PARAMETER); _KLOGX2(KLOG_taskq_create, NULL); return (NULL); } /* Endif */ if (kernel_data->IN_ISR) { _task_set_error(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); _KLOGX2(KLOG_taskq_create, NULL); return(NULL); }/* Endif */ #endif task_queue_ptr = (TASK_QUEUE_STRUCT_PTR)_mem_alloc_system((_mem_size) sizeof(TASK_QUEUE_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (task_queue_ptr == NULL) { _KLOGX2(KLOG_taskq_create, NULL); return(NULL); } /* Endif */ #endif _mem_set_type(task_queue_ptr, MEM_TYPE_TASK_Q); task_queue_ptr->POLICY = policy; _QUEUE_INIT(&task_queue_ptr->TD_QUEUE, 0); task_queue_ptr->VALID = TASK_QUEUE_VALID; _int_disable(); if (kernel_data->KERNEL_TASK_QUEUES.NEXT == NULL) { /* Initialize the task queue */ _QUEUE_INIT(&kernel_data->KERNEL_TASK_QUEUES,0); } /* Endif */ _QUEUE_ENQUEUE(&kernel_data->KERNEL_TASK_QUEUES, task_queue_ptr); _int_enable(); _KLOGX2(KLOG_taskq_create, task_queue_ptr); return(task_queue_ptr); } /* Endbody */
_mqx_uint _partition_create_component ( void ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; PARTITION_COMPONENT_STRUCT_PTR part_component_ptr; _GET_KERNEL_DATA(kernel_data); _KLOGE1(KLOG_partition_create_component); #if MQX_CHECK_ERRORS if (kernel_data->IN_ISR) { _KLOGX2(KLOG_partition_create_component, MQX_CANNOT_CALL_FUNCTION_FROM_ISR); return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); } /* Endif */ #endif _lwsem_wait((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); #if MQX_CHECK_ERRORS if (kernel_data->KERNEL_COMPONENTS[KERNEL_PARTITIONS] != NULL) { _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_partition_create_component, MQX_OK); return(MQX_OK); } /* Endif */ #endif part_component_ptr = _mem_alloc_system_zero( (_mem_size)sizeof(PARTITION_COMPONENT_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (part_component_ptr == NULL) { _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_partition_create_component, MQX_OUT_OF_MEMORY); return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(part_component_ptr, MEM_TYPE_PARTITION_COMPONENT); kernel_data->KERNEL_COMPONENTS[KERNEL_PARTITIONS] = part_component_ptr; /* START CR 308 */ part_component_ptr->VALID = PARTITION_VALID; /* END CR 308 */ _QUEUE_INIT(&part_component_ptr->PARTITIONS, 0); #if MQX_COMPONENT_DESTRUCTION kernel_data->COMPONENT_CLEANUP[KERNEL_PARTITIONS] = _partition_cleanup; #endif _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_partition_create_component, MQX_OK); return(MQX_OK); } /* Endbody */
_mqx_uint _io_init ( void ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; _GET_KERNEL_DATA(kernel_data); _QUEUE_INIT(&kernel_data->IO_DEVICES, 0); return (_lwsem_create((LWSEM_STRUCT_PTR)&kernel_data->IO_LWSEM, 1)); } /* Endbody */
/*! * \private * * \brief Used by a task to create an instance of a lightweight event. * * \param[in] event_ptr Pointer representing location of the event. * \param[in] flags Flags for the light weight event. * \param[in] user User mode * * \return MQX_OK * \return MQX_EINVAL (lwevent is already initialized.) * \return MQX_LWEVENT_INVALID (In case of user mode, MQX tries to access * a lwevent with inappropriate access rights.) * * \see _lwevent_create * \see LWEVENT_STRUCT */ _mqx_uint _lwevent_create_internal ( LWEVENT_STRUCT_PTR event_ptr, _mqx_uint flags, bool user ) { KERNEL_DATA_STRUCT_PTR kernel_data; LWEVENT_STRUCT_PTR event_chk_ptr; #if MQX_ENABLE_USER_MODE if (user && !_psp_mem_check_access_mask((uint32_t)event_ptr, sizeof(LWEVENT_STRUCT), MPU_UM_R, MPU_UM_RW) ) { return MQX_LWEVENT_INVALID; } #endif _GET_KERNEL_DATA(kernel_data); _KLOGE2(KLOG_lwevent_create, event_ptr); _QUEUE_INIT(&event_ptr->WAITING_TASKS, 0); event_ptr->VALUE = 0; event_ptr->FLAGS = flags; if (flags & LWEVENT_AUTO_CLEAR) event_ptr->AUTO = ~0; else event_ptr->AUTO = 0; _int_disable(); #if MQX_ENABLE_USER_MODE if (user) { if (kernel_data->USR_LWEVENTS.NEXT == NULL) { /* Initialize the light weight event queue */ _QUEUE_INIT(&kernel_data->USR_LWEVENTS, 0); } } else #endif { if (kernel_data->LWEVENTS.NEXT == NULL) { /* Initialize the light weight event queue */ _QUEUE_INIT(&kernel_data->LWEVENTS, 0); } } event_ptr->VALID = LWEVENT_VALID; #if MQX_CHECK_ERRORS /* Check if lwevent is already initialized */ #if MQX_ENABLE_USER_MODE if (user) { event_chk_ptr = (LWEVENT_STRUCT_PTR)((void *)kernel_data->USR_LWEVENTS.NEXT); while (event_chk_ptr != (LWEVENT_STRUCT_PTR)((void *)&kernel_data->USR_LWEVENTS)) { if (event_chk_ptr == event_ptr) { _int_enable(); _KLOGX2(KLOG_lwevent_create, MQX_EINVAL); return(MQX_EINVAL); } event_chk_ptr = (LWEVENT_STRUCT_PTR)((void *)event_chk_ptr->LINK.NEXT); } } else #endif { event_chk_ptr = (LWEVENT_STRUCT_PTR) ((void *) kernel_data->LWEVENTS.NEXT); while (event_chk_ptr != (LWEVENT_STRUCT_PTR) ((void *) &kernel_data->LWEVENTS)) { if (event_chk_ptr == event_ptr) { _int_enable(); _KLOGX2(KLOG_lwevent_create, MQX_EINVAL); return (MQX_EINVAL); } event_chk_ptr = (LWEVENT_STRUCT_PTR) ((void *) event_chk_ptr->LINK.NEXT); } } #endif #if MQX_ENABLE_USER_MODE if (user) { _QUEUE_ENQUEUE(&kernel_data->USR_LWEVENTS, &event_ptr->LINK); } else #endif { _QUEUE_ENQUEUE(&kernel_data->LWEVENTS, &event_ptr->LINK); } _int_enable(); _KLOGX2(KLOG_lwevent_create, MQX_OK); return (MQX_OK); }
_mqx_uint _mutex_init ( /* [IN] - the address where the mutex is to be initialized */ register MUTEX_STRUCT_PTR mutex_ptr, /* [IN] - Initialization parameters for the mutex */ register MUTEX_ATTR_STRUCT_PTR attr_ptr ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; MUTEX_COMPONENT_STRUCT_PTR mutex_component_ptr; MUTEX_ATTR_STRUCT default_attr; #if MQX_CHECK_ERRORS MUTEX_STRUCT_PTR mutex_chk_ptr; #endif _mqx_uint result; _GET_KERNEL_DATA(kernel_data); if (attr_ptr == NULL) { attr_ptr = &default_attr; _mutatr_init(attr_ptr); _KLOGE3(KLOG_mutex_init, mutex_ptr, NULL); } else { _KLOGE3(KLOG_mutex_init, mutex_ptr, attr_ptr); } /* Endif */ #if MQX_CHECK_ERRORS if (mutex_ptr == NULL) { _KLOGX2(KLOG_mutex_init, MQX_EINVAL); return(MQX_EINVAL); } /* Endif */ #endif #if MQX_CHECK_VALIDITY if (attr_ptr->VALID != MUTEX_VALID) { _KLOGX2(KLOG_mutex_init, MQX_EINVAL); return(MQX_EINVAL); } /* Endif */ #endif mutex_component_ptr = (MUTEX_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_MUTEXES]; if (mutex_component_ptr == NULL) { result = _mutex_create_component(); mutex_component_ptr = (MUTEX_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_MUTEXES]; #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (mutex_component_ptr == NULL){ _KLOGX2(KLOG_mutex_init, result); return(result); } /* Endif */ #endif } /* Endif */ #if MQX_CHECK_VALIDITY if (mutex_component_ptr->VALID != MUTEX_VALID) { _KLOGX2(KLOG_mutex_init, MQX_INVALID_COMPONENT_BASE); return(MQX_INVALID_COMPONENT_BASE); } /* Endif */ #endif _int_disable(); #if MQX_CHECK_ERRORS /* Check if mutex is already initialized */ mutex_chk_ptr = (MUTEX_STRUCT_PTR) ((pointer)mutex_component_ptr->MUTEXES.NEXT); while (mutex_chk_ptr != (MUTEX_STRUCT_PTR) ((pointer)&mutex_component_ptr->MUTEXES)) { if (mutex_chk_ptr == mutex_ptr) { _int_enable(); _KLOGX2(KLOG_mutex_init, MQX_EINVAL); return(MQX_EINVAL); } /* Endif */ mutex_chk_ptr = (MUTEX_STRUCT_PTR)((pointer)mutex_chk_ptr->LINK.NEXT); } /* Endif */ #endif mutex_ptr->PROTOCOLS = attr_ptr->SCHED_PROTOCOL | attr_ptr->WAIT_PROTOCOL; mutex_ptr->VALID = MUTEX_VALID; mutex_ptr->COUNT = attr_ptr->COUNT; mutex_ptr->PRIORITY_CEILING = attr_ptr->PRIORITY_CEILING; mutex_ptr->LOCK = 0; mutex_ptr->BOOSTED = 0; mutex_ptr->OWNER_TD = NULL; _QUEUE_INIT(&mutex_ptr->WAITING_TASKS, 0); _QUEUE_ENQUEUE(&mutex_component_ptr->MUTEXES, mutex_ptr); _int_enable(); _KLOGX2(KLOG_mutex_init, MQX_EOK); return(MQX_EOK); } /* Endbody */
_mqx_uint _timer_create_component ( /* [IN] the task priority of the timer task */ _mqx_uint timer_task_priority, /* [IN] the stack size for the timer task */ _mqx_uint timer_task_stack_size ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TIMER_COMPONENT_STRUCT_PTR timer_component_ptr; TASK_TEMPLATE_STRUCT timer_tt; _GET_KERNEL_DATA(kernel_data); _KLOGE2(KLOG_timer_create_component, timer_task_priority); #if MQX_CHECK_ERRORS if (kernel_data->IN_ISR) { _KLOGX2(KLOG_timer_create_component, MQX_CANNOT_CALL_FUNCTION_FROM_ISR); return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); } /* Endif */ #endif _lwsem_wait((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); if (kernel_data->KERNEL_COMPONENTS[KERNEL_TIMER] != NULL) { _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_timer_create_component, MQX_OK); return(MQX_OK); } /* Endif */ /* Get the timer component data structure */ timer_component_ptr = _mem_alloc_system_zero( (_mem_size)sizeof(TIMER_COMPONENT_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (timer_component_ptr == NULL) { _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_timer_create_component, MQX_OUT_OF_MEMORY); return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(timer_component_ptr, MEM_TYPE_TIMER_COMPONENT); _QUEUE_INIT(&timer_component_ptr->ELAPSED_TIMER_ENTRIES, 0); _QUEUE_INIT(&timer_component_ptr->KERNEL_TIMER_ENTRIES, 0); timer_tt.TASK_TEMPLATE_INDEX = 0; timer_tt.TASK_ADDRESS = _timer_task; if (timer_task_stack_size == 0) { timer_tt.TASK_STACKSIZE = TIMER_DEFAULT_STACK_SIZE; } else { timer_tt.TASK_STACKSIZE = timer_task_stack_size; } /* Endif */ if (timer_task_priority == 0) { timer_tt.TASK_PRIORITY = TIMER_DEFAULT_TASK_PRIORITY; } else { timer_tt.TASK_PRIORITY = timer_task_priority; } /* Endif */ timer_tt.TASK_NAME = "Timer Task"; timer_tt.TASK_ATTRIBUTES = 0; timer_tt.DEFAULT_TIME_SLICE = 0; kernel_data->KERNEL_COMPONENTS[KERNEL_TIMER] = timer_component_ptr; timer_component_ptr->TIMER_TID = _task_create(0, 0, (uint_32)&timer_tt); #if MQX_CHECK_ERRORS if (timer_component_ptr->TIMER_TID == MQX_NULL_TASK_ID) { _mqx_uint result; kernel_data->KERNEL_COMPONENTS[KERNEL_TIMER] = NULL; timer_component_ptr->VALID = 0; result = _task_get_error(); if (result == MQX_OK) { result = MQX_OUT_OF_MEMORY; } /* Endif */ _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _mem_free(timer_component_ptr); _KLOGX2(KLOG_timer_create_component, result); return(result); }/* Endif */ #endif #if MQX_COMPONENT_DESTRUCTION kernel_data->COMPONENT_CLEANUP[KERNEL_EVENTS] = _timer_cleanup; #endif _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_timer_create_component, MQX_OK); return(MQX_OK); } /* Endbody */
_mqx_uint _mem_create_pool_internal ( /* [IN] the start of the memory pool */ pointer start, /* [IN] the end of the memory pool */ pointer end, /* [IN] where to store the memory pool context info. */ MEMPOOL_STRUCT_PTR mem_pool_ptr ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; STOREBLOCK_STRUCT_PTR block_ptr; STOREBLOCK_STRUCT_PTR end_block_ptr; _GET_KERNEL_DATA(kernel_data); #if MQX_CHECK_VALIDITY _INT_DISABLE(); if (kernel_data->MEM_COMP.VALID != MEMPOOL_VALID) { /* The RTOS memory system has been corrupted */ _int_enable(); return(MQX_CORRUPT_MEMORY_SYSTEM); } /* Endif */ _INT_ENABLE(); #endif /* Align the start of the pool */ mem_pool_ptr->POOL_PTR = (STOREBLOCK_STRUCT_PTR) _ALIGN_ADDR_TO_HIGHER_MEM(start); /* Set the end of memory (aligned) */ mem_pool_ptr->POOL_LIMIT = (STOREBLOCK_STRUCT_PTR) _ALIGN_ADDR_TO_LOWER_MEM(end); #if MQX_CHECK_ERRORS if ( (uchar_ptr)mem_pool_ptr->POOL_LIMIT <= ((uchar_ptr)mem_pool_ptr->POOL_PTR + MQX_MIN_MEMORY_POOL_SIZE) ) { return MQX_MEM_POOL_TOO_SMALL; } /* Endif */ #endif block_ptr = (STOREBLOCK_STRUCT_PTR)mem_pool_ptr->POOL_PTR; mem_pool_ptr->POOL_HIGHEST_MEMORY_USED = (pointer)block_ptr; mem_pool_ptr->POOL_CHECK_POOL_PTR = (char _PTR_)mem_pool_ptr->POOL_PTR; mem_pool_ptr->POOL_BLOCK_IN_ERROR = NULL; /* Compute the pool size. */ mem_pool_ptr->POOL_SIZE = (_mem_size)((uchar_ptr)mem_pool_ptr->POOL_LIMIT - (uchar_ptr)mem_pool_ptr->POOL_PTR); /* Set up the first block as an idle block */ block_ptr->BLOCKSIZE = mem_pool_ptr->POOL_SIZE - MQX_MIN_MEMORY_STORAGE_SIZE; block_ptr->USER_AREA = NULL; block_ptr->PREVBLOCK = NULL; block_ptr->NEXTBLOCK = NULL; MARK_BLOCK_AS_FREE(block_ptr); CALC_CHECKSUM(block_ptr); mem_pool_ptr->POOL_FREE_LIST_PTR = block_ptr; /* ** Set up last block as an in_use block, so that the _mem_free algorithm ** will work (block coalescing) */ end_block_ptr = (STOREBLOCK_STRUCT_PTR) ((uchar_ptr)block_ptr + block_ptr->BLOCKSIZE); end_block_ptr->BLOCKSIZE = (_mem_size)(MQX_MIN_MEMORY_STORAGE_SIZE); end_block_ptr->USER_AREA = 0; end_block_ptr->PREVBLOCK = (struct storeblock_struct _PTR_)block_ptr; end_block_ptr->NEXTBLOCK = NULL; MARK_BLOCK_AS_USED(end_block_ptr, SYSTEM_TASK_ID(kernel_data)); CALC_CHECKSUM(end_block_ptr); mem_pool_ptr->POOL_END_PTR = end_block_ptr; /* Initialize the list of extensions to this pool */ _QUEUE_INIT(&mem_pool_ptr->EXT_LIST, 0); mem_pool_ptr->VALID = MEMPOOL_VALID; /* Protect the list of pools while adding new pool */ _lwsem_wait((LWSEM_STRUCT_PTR)&kernel_data->MEM_COMP.SEM); _QUEUE_ENQUEUE(&kernel_data->MEM_COMP.POOLS, &mem_pool_ptr->LINK); _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->MEM_COMP.SEM); return MQX_OK; } /* Endbody */
void _mqx_init_kernel_data_internal ( void ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TASK_TEMPLATE_STRUCT_PTR task_template_ptr; TD_STRUCT_PTR td_ptr; _mqx_uint priority_levels; _mqx_uint i; _GET_KERNEL_DATA(kernel_data); /* Store the configuration used when the kernel was compiled */ kernel_data->CONFIG1 = MQX_CNFG1; kernel_data->CONFIG2 = MQX_CNFG2; /* Store the addressability of the processor. How many bits in a byte. */ kernel_data->ADDRESSING_CAPABILITY = PSP_MEMORY_ADDRESSING_CAPABILITY; /* Indicate the endianess of the target */ kernel_data->ENDIANESS = PSP_ENDIAN; /* Store PSP memory alignment information */ #if PSP_MEM_STOREBLOCK_ALIGNMENT != 0 kernel_data->PSP_CFG_MEM_STOREBLOCK_ALIGNMENT = PSP_MEM_STOREBLOCK_ALIGNMENT; #endif kernel_data->PSP_CFG_MEMORY_ALIGNMENT = PSP_MEMORY_ALIGNMENT; kernel_data->PSP_CFG_STACK_ALIGNMENT = PSP_STACK_ALIGNMENT; /* ** Fill in fields of the kernel data structure from the initialization ** structure. */ //kernel_data->PROCESSOR_NUMBER = kernel_data->INIT.PROCESSOR_NUMBER; /* Set IPC id for compatibility */ #if MQX_USE_IPC kernel_data->MY_IPC_ID = BUILD_TASKID(kernel_data->INIT.PROCESSOR_NUMBER, 1); #endif /* Store location of current interrupt vector table */ #if MQX_EXIT_ENABLED kernel_data->USERS_VBR = (_mqx_max_type)_int_get_vector_table(); #endif #if MQX_CHECK_ERRORS if (kernel_data->INIT.TASK_TEMPLATE_LIST == NULL) { _mqx_exit(MQX_INVALID_POINTER); } /* Endif */ #endif #if MQX_HAS_TIME_SLICE /* Set the default scheduling policy for created tasks */ kernel_data->SCHED_POLICY = MQX_SCHED_FIFO; #endif #if MQX_KD_HAS_COUNTER /* Initialize the kernel counter. */ kernel_data->COUNTER = 1U; #endif /* Set up the disable and enable priority levels */ _psp_set_kernel_disable_level(); /* ** Initialize the system task so that functions which update the ** task error code can be called. ** The system task never runs, but it's TD is used for error codes ** during initialization, and for storage of memory blocks assigned ** to the system. */ td_ptr = (TD_STRUCT_PTR)&kernel_data->SYSTEM_TD; kernel_data->ACTIVE_PTR = td_ptr; kernel_data->ACTIVE_SR = kernel_data->DISABLE_SR; td_ptr->TASK_SR = kernel_data->DISABLE_SR; td_ptr->TASK_ID = BUILD_TASKID(kernel_data->INIT.PROCESSOR_NUMBER, SYSTEM_TASK_NUMBER); td_ptr->STATE = BLOCKED; /* Initialize the light weight semaphores queue */ _QUEUE_INIT(&kernel_data->LWSEM, 0); #if MQX_ENABLE_USER_MODE _QUEUE_INIT(&kernel_data->USR_LWSEM, 0); #endif #if MQX_HAS_TICK /* Set up the timeout queue */ _QUEUE_INIT(&kernel_data->TIMEOUT_QUEUE, 0); #endif /* ** Compute the number of MQX priority levels needed. This is done ** by determining the task that has the lowest priority (highest number) */ priority_levels = 0; task_template_ptr = kernel_data->INIT.TASK_TEMPLATE_LIST; for (i = 0; task_template_ptr->TASK_TEMPLATE_INDEX && (i < MQX_MAXIMUM_NUMBER_OF_TASK_TEMPLATES); ++i, ++task_template_ptr) { if (priority_levels < task_template_ptr->TASK_PRIORITY) { priority_levels = task_template_ptr->TASK_PRIORITY; } /* Endif */ } /* Endfor */ kernel_data->LOWEST_TASK_PRIORITY = priority_levels; #if MQX_USE_IDLE_TASK /* ** Initialize the task template for the IDLE Task. ** NOTE that the idle task runs at 1 level lower than any user task. */ task_template_ptr = (TASK_TEMPLATE_STRUCT_PTR) &kernel_data->IDLE_TASK_TEMPLATE; task_template_ptr->TASK_TEMPLATE_INDEX = IDLE_TASK; task_template_ptr->TASK_STACKSIZE = PSP_IDLE_STACK_SIZE; task_template_ptr->TASK_NAME = MQX_IDLE_TASK_NAME; task_template_ptr->TASK_ADDRESS = _mqx_idle_task; task_template_ptr->TASK_PRIORITY = priority_levels + 1; #endif /* ** Initialize the linked list of all TDs in the system. ** Initially zero. Not including system TD */ _QUEUE_INIT(&kernel_data->TD_LIST, 0); /* Set the TD counter */ /* Start SPR P171-0014-02 */ /* kernel_data->TD_COUNTER = 1; */ kernel_data->TASK_NUMBER = 1; /* End SPR P171-0014-02 */ } /* Endbody */
_mqx_uint _event_create_internal ( /* [IN] the string name for the event */ char _PTR_ name_ptr, /* [OUT] where the event pointer is */ EVENT_STRUCT_PTR _PTR_ event_ptr_ptr ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; register EVENT_COMPONENT_STRUCT_PTR event_component_ptr; register EVENT_STRUCT_PTR event_ptr; _mqx_uint result; _GET_KERNEL_DATA(kernel_data); _KLOGE2(KLOG_event_create, name_ptr); #if MQX_CHECK_ERRORS if (kernel_data->IN_ISR) { _KLOGX2(KLOG_event_create, MQX_CANNOT_CALL_FUNCTION_FROM_ISR); return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); } /* Endif */ #endif event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS]; if (event_component_ptr == NULL) { result = _event_create_component(EVENT_DEFAULT_INITIAL_NUMBER, EVENT_DEFAULT_GROW_NUMBER, EVENT_DEFAULT_MAXIMUM_NUMBER); event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS]; #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (event_component_ptr == NULL){ _KLOGX2(KLOG_event_create, result); return(result); } /* Endif */ #endif } /* Endif */ #if MQX_CHECK_VALIDITY if (event_component_ptr->VALID != EVENT_VALID){ _KLOGX2(KLOG_event_create, MQX_INVALID_COMPONENT_BASE); return(MQX_INVALID_COMPONENT_BASE); } /* Endif */ #endif event_ptr = (EVENT_STRUCT_PTR)_mem_alloc_system_zero( (_mem_size)sizeof(EVENT_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (event_ptr == NULL) { _KLOGX2(KLOG_event_create, MQX_OUT_OF_MEMORY); return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(event_ptr, MEM_TYPE_EVENT); _QUEUE_INIT(&event_ptr->WAITING_TASKS, EVENT_MAX_WAITING_TASKS); strncpy(event_ptr->NAME, name_ptr, (_mqx_uint)NAME_MAX_NAME_SIZE-1); event_ptr->NAME[NAME_MAX_NAME_SIZE-1] = '\0'; result = _name_add_internal(event_component_ptr->NAME_TABLE_HANDLE, event_ptr->NAME, (_mqx_uint)event_ptr); #if MQX_CHECK_ERRORS if (result != MQX_OK) { _mem_free(event_ptr); if (result == NAME_EXISTS) { _KLOGX2(KLOG_event_create, EVENT_EXISTS); return(EVENT_EXISTS); } else if (result == NAME_TABLE_FULL) { _KLOGX2(KLOG_event_create, EVENT_TABLE_FULL); return(EVENT_TABLE_FULL); } /* Endif */ _KLOGX2(KLOG_event_create, result); return(result); } /* Endif */ #endif event_ptr->VALID = EVENT_VALID; *event_ptr_ptr = event_ptr; _KLOGX2(KLOG_event_create, result); return(result); } /* Endbody */