void background_test_task ( uint_32 parameter ) { _partition_id partition; _lwmem_pool_id lwmem_pool_id; pointer error_ptr; pointer error2_ptr; _mqx_uint error; _mqx_uint result; while (TRUE) { result = _event_test(&error_ptr); if (result != MQX_OK){ printf("\nFailed _event_test: 0x%X.", result); _task_block(); } result = _log_test(&error); if (result != MQX_OK){ printf("\nFailed _log_test: 0x%X.", result); _task_block(); } result = _lwevent_test(&error_ptr, &error2_ptr); if (result != MQX_OK){ printf("\nFailed _lwevent_test: 0x%X.", result); _task_block(); } result = _lwlog_test(&error); if (result != MQX_OK){ printf("\nFailed _lwlog_test: 0x%X.", result); _task_block(); } result = _lwsem_test(&error_ptr, &error2_ptr); if (result != MQX_OK){ printf("\nFailed _lwsem_test: 0x%X.", result); _task_block(); } result = _lwmem_test(&lwmem_pool_id, &error_ptr); if (result != MQX_OK){ printf("\nFailed _lwmem_test: 0x%X.", result); _task_block(); } result = _lwtimer_test(&error_ptr, &error2_ptr); if (result != MQX_OK){ printf("\nFailed _lwtimer_test: 0x%X.", result); _task_block(); } #if ! MQX_USE_LWMEM_ALLOCATOR result = _mem_test_all(&error_ptr); if (result != MQX_OK){ printf("\nFailed _mem_test_all,"); printf("\nError = 0x%X, pool = 0x%X.", result, (_mqx_uint)error_ptr); _task_block(); } #endif /* ** Create the message component. ** Verify the integrity of message pools and message queues. */ if (_msg_create_component() != MQX_OK){ printf("\nError creating the message component."); _task_block(); } if (_msgpool_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _msgpool_test."); _task_block(); } if (_msgq_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _msgq_test."); _task_block(); } if (_mutex_test(&error_ptr) != MQX_OK){ printf("\nFailed _mutex_test."); _task_block(); } if (_name_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _name_test."); _task_block(); } if (_partition_test(&partition, &error_ptr, &error2_ptr) != MQX_OK) { printf("\nFailed _partition_test."); _task_block(); } if (_sem_test(&error_ptr) != MQX_OK){ printf("\nFailed _sem_test."); _task_block(); } if (_taskq_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _takq_test."); _task_block(); } if (_timer_test(&error_ptr) != MQX_OK){ printf("\nFailed _timer_test."); _task_block(); } if (_watchdog_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _watchlog_test."); _task_block(); } printf("All tests passed."); _task_block(); } }
void background_test_task ( uint32_t parameter ) { _partition_id partition; #if MQXCFG_ALLOCATOR == MQX_ALLOCATOR_LWMEM _lwmem_pool_id lwmem_pool_id; #endif void *error_ptr; void *error2_ptr; _mqx_uint error; _mqx_uint result; printf("\nTesting component:"); while (TRUE) { printf("\nevent"); result = _event_test(&error_ptr); if (result != MQX_OK){ printf("\nFailed _event_test: 0x%X.", result); _task_block(); } printf("\nlog"); result = _log_test(&error); if (result != MQX_OK){ printf("\nFailed _log_test: 0x%X.", result); _task_block(); } printf("\nlwevent"); result = _lwevent_test(&error_ptr, &error2_ptr); if (result != MQX_OK){ printf("\nFailed _lwevent_test: 0x%X.", result); _task_block(); } printf("\nlwlog"); result = _lwlog_test(&error); if (result != MQX_OK){ printf("\nFailed _lwlog_test: 0x%X.", result); _task_block(); } printf("\nlwsem"); result = _lwsem_test(&error_ptr, &error2_ptr); if (result != MQX_OK){ printf("\nFailed _lwsem_test: 0x%X.", result); _task_block(); } #if MQXCFG_ALLOCATOR == MQX_ALLOCATOR_LWMEM printf("\nlwmem"); result = _lwmem_test(&lwmem_pool_id, &error_ptr); if (result != MQX_OK){ printf("\nFailed _lwmem_test: 0x%X.", result); _task_block(); } #endif printf("\nlwtimer"); result = _lwtimer_test(&error_ptr, &error2_ptr); if (result != MQX_OK){ printf("\nFailed _lwtimer_test: 0x%X.", result); _task_block(); } #if ! MQXCFG_ALLOCATOR == MQX_ALLOCATOR_LWMEM printf("\nmem"); result = _mem_test_all(&error_ptr); if (result != MQX_OK){ printf("\nFailed _mem_test_all,"); printf("\nError = 0x%X, pool = 0x%X.", result, (_mqx_uint)error_ptr); _task_block(); } #endif /* MQXCFG_ALLOCATOR */ /* ** Create the message component. ** Verify the integrity of message pools and message queues. */ printf("\nmsg"); if (_msg_create_component() != MQX_OK){ printf("\nError creating the message component."); _task_block(); } printf("\nmsgpool"); if (_msgpool_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _msgpool_test."); _task_block(); } printf("\nmsgq"); if (_msgq_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _msgq_test."); _task_block(); } printf("\nmutex"); if (_mutex_test(&error_ptr) != MQX_OK){ printf("\nFailed _mutex_test."); _task_block(); } printf("\nname"); if (_name_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _name_test."); _task_block(); } printf("\npartition"); if (_partition_test(&partition, &error_ptr, &error2_ptr) != MQX_OK) { printf("\nFailed _partition_test."); _task_block(); } printf("\nsem"); if (_sem_test(&error_ptr) != MQX_OK){ printf("\nFailed _sem_test."); _task_block(); } printf("\ntaskq"); if (_taskq_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _takq_test."); _task_block(); } printf("\ntimer"); if (_timer_test(&error_ptr) != MQX_OK){ printf("\nFailed _timer_test."); _task_block(); } printf("\nwatchdog"); if (_watchdog_test(&error_ptr, &error2_ptr) != MQX_OK){ printf("\nFailed _watchlog_test."); _task_block(); } printf("\nAll tests passed."); _task_block(); } }
_pool_id _msgpool_create_internal ( /* [IN] size of the messages being created */ uint_16 message_size, /* [IN] no. of messages in this pool */ uint_16 num_messages, /* [IN] no. of messages to grow pool by if empty */ uint_16 grow_number, /* [IN] maximum number of messages allowed in pool */ uint_16 grow_limit, /* [IN] whether this is a system pool or a regular pool */ _mqx_uint pool_type ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; MSG_COMPONENT_STRUCT_PTR msg_component_ptr; register MSGPOOL_STRUCT_PTR msgpool_ptr; register MSGPOOL_STRUCT_PTR temp_msgpool_ptr; register MSGPOOL_STRUCT_PTR prev_msgpool_ptr; register _mqx_uint i; _mqx_uint result; _GET_KERNEL_DATA(kernel_data); msg_component_ptr = _GET_MSG_COMPONENT_STRUCT_PTR(kernel_data); #if MQX_CHECK_ERRORS if (message_size < sizeof(MESSAGE_HEADER_STRUCT)) { _task_set_error(MSGPOOL_MESSAGE_SIZE_TOO_SMALL); return ((_pool_id) 0); } /* Endif */ #endif /* ** Try to find an available slot in the array of msgpools for a new pool ** if MAX_MSGPOOLS_EVER has not yet reached MAX_MSGPOOLS then ** simply use MAX_MSGPOOLS_EVER as an index value and then increment it ** but if MAX_MSGPOOLS_EVER has reached MAX_MSGPOOLS then ** go back and search through the previously assigned headers to see ** if one has been deallocated and is available for use */ if (msg_component_ptr == NULL) { result = _msg_create_component(); msg_component_ptr = _GET_MSG_COMPONENT_STRUCT_PTR(kernel_data); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (msg_component_ptr == NULL) { _task_set_error(result); return ((_pool_id)0); } /* Endif */ #endif } /* Endif */ _int_disable(); if (msg_component_ptr->MAX_MSGPOOLS_EVER >= msg_component_ptr->MAX_MSGPOOLS) { msgpool_ptr = &msg_component_ptr->MSGPOOLS_PTR[0]; for ( i=0; i < msg_component_ptr->MAX_MSGPOOLS; i++ ) { if (msgpool_ptr->VALID != MSG_VALID) { break; } /* Endif */ msgpool_ptr++; } /* Endfor */ if (i == msg_component_ptr->MAX_MSGPOOLS) { _int_enable(); _task_set_error(MSGPOOL_OUT_OF_POOLS); return ((_pool_id)0); } /* Endif */ } else { msgpool_ptr = &msg_component_ptr->MSGPOOLS_PTR[ msg_component_ptr->MAX_MSGPOOLS_EVER++]; } /* Endif */ msgpool_ptr->VALID = MSG_VALID; msgpool_ptr->MESSAGE_SIZE = message_size; msgpool_ptr->GROW_NUMBER = 0; _int_enable(); msgpool_ptr->MSGPOOL_BLOCK_PTR = NULL; msgpool_ptr->MSG_FREE_LIST_PTR = NULL; msgpool_ptr->NEXT_MSGPOOL_PTR = NULL; msgpool_ptr->SIZE = 0; msgpool_ptr->MAX = 0; if ( grow_number == 0 ) { msgpool_ptr->GROW_LIMIT = num_messages; } else if (grow_limit == 0) { msgpool_ptr->GROW_LIMIT = 0xFFFF; } else { msgpool_ptr->GROW_LIMIT = grow_limit; } /* Endif */ msgpool_ptr->MSGPOOL_TYPE = pool_type; if (num_messages) { _msgpool_add_internal(msgpool_ptr, num_messages); /* no messages could be created, so abort pool creation */ if (msgpool_ptr->SIZE == 0) { msgpool_ptr->VALID = 0; _task_set_error(MQX_OUT_OF_MEMORY); return ((_pool_id)0); } /* Endif */ } /* Endif */ msgpool_ptr->GROW_NUMBER = grow_number; if ( pool_type == SYSTEM_MSG_POOL ) { /* We must insert the pool into the link list of system message pools, ** by order of size, smallest first. */ _int_disable(); prev_msgpool_ptr = msg_component_ptr->SMALLEST_MSGPOOL_PTR; if (prev_msgpool_ptr == NULL) { /* first entry in list */ msg_component_ptr->SMALLEST_MSGPOOL_PTR = msgpool_ptr; msg_component_ptr->LARGEST_MSGPOOL_PTR = msgpool_ptr; } else if (prev_msgpool_ptr->MESSAGE_SIZE >= msgpool_ptr->MESSAGE_SIZE){ /* The new pool is smaller than that at head of list */ msgpool_ptr->NEXT_MSGPOOL_PTR = prev_msgpool_ptr; msg_component_ptr->SMALLEST_MSGPOOL_PTR = msgpool_ptr; } else { temp_msgpool_ptr = prev_msgpool_ptr->NEXT_MSGPOOL_PTR; while (temp_msgpool_ptr != NULL) { /* check the relative message sizes */ if (temp_msgpool_ptr->MESSAGE_SIZE < msgpool_ptr->MESSAGE_SIZE){ /* continue to walk down linked list */ prev_msgpool_ptr = temp_msgpool_ptr; temp_msgpool_ptr = prev_msgpool_ptr->NEXT_MSGPOOL_PTR; } else { /* this entry belongs between prev_ptr and temp_msgpool_ptr */ prev_msgpool_ptr->NEXT_MSGPOOL_PTR = msgpool_ptr; msgpool_ptr->NEXT_MSGPOOL_PTR = temp_msgpool_ptr; break; } /* Endif */ } /* Endwhile */ if (temp_msgpool_ptr == NULL) { /* searched the list and this entry belongs at the bottom */ prev_msgpool_ptr->NEXT_MSGPOOL_PTR = msgpool_ptr; msg_component_ptr->LARGEST_MSGPOOL_PTR = msgpool_ptr; }/* Endif */ } /* Endif */ _int_enable(); } /* Endif */ return ((_pool_id)msgpool_ptr); } /* Endbody */
_queue_id _msgq_open_internal ( /* [IN] the queue being opened */ _queue_number queue, /* [IN] the maximum number of entries allowed in this queue */ uint_16 max_queue_size, /* [IN] the type of queue, NORMAL or SYSTEM */ _mqx_uint queue_type, /* [IN] the function to be called when an entry is put on the queue */ void (_CODE_PTR_ notification_function)(pointer), /* [IN] information to pass to the notification function */ pointer notification_data ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TD_STRUCT_PTR td_ptr; MSG_COMPONENT_STRUCT_PTR msg_component_ptr; register MSGQ_STRUCT_PTR temp_msgq_ptr; register MSGQ_STRUCT_PTR msgq_ptr; register _queue_id qid; register _mqx_uint i; _mqx_uint result; _GET_KERNEL_DATA(kernel_data); msg_component_ptr = _GET_MSG_COMPONENT_STRUCT_PTR(kernel_data); qid = (_queue_id)0; if (msg_component_ptr == NULL) { result = _msg_create_component(); msg_component_ptr = _GET_MSG_COMPONENT_STRUCT_PTR(kernel_data); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (msg_component_ptr == NULL) { _task_set_error(result); return(qid); } /* Endif */ #endif } /* Endif */ _int_disable(); if (queue == MSGQ_FREE_QUEUE) { /* Lets find a free queue entry */ msgq_ptr = &msg_component_ptr->MSGQS_PTR[MSGQ_FIRST_USER_QUEUE]; for (i = MSGQ_FIRST_USER_QUEUE; i <= msg_component_ptr->MAX_MSGQS; ++i) { if (msgq_ptr->QUEUE != (_queue_number)i) { queue = (_queue_number)i; break; /* Found one! */ } /* Endif */ ++msgq_ptr; } /* Endfor */ if (queue == MSGQ_FREE_QUEUE) { /* Did not get one */ _int_enable(); _task_set_error(MSGQ_QUEUE_IN_USE); return(qid); }/* Endif */ } else { if (queue >= msg_component_ptr->MAX_MSGQS) { _int_enable(); _task_set_error(MSGQ_INVALID_QUEUE_NUMBER); return(qid); } } #if MQX_CHECK_ERRORS if ( !VALID_QUEUE(queue)) { _int_enable(); _task_set_error(MSGQ_INVALID_QUEUE_ID); return(qid); } /* Endif */ #endif msgq_ptr = &msg_component_ptr->MSGQS_PTR[queue]; #if MQX_CHECK_ERRORS if (msgq_ptr->QUEUE == queue) { _int_enable(); _task_set_error(MSGQ_QUEUE_IN_USE); return(qid); } /* Endif */ #endif msgq_ptr->QUEUE = queue; msgq_ptr->FIRST_MSG_PTR = NULL; msgq_ptr->LAST_MSG_PTR = NULL; msgq_ptr->NEXT_MSGQ_PTR = NULL; msgq_ptr->NO_OF_ENTRIES = 0; msgq_ptr->TYPE = (uint_16)queue_type; msgq_ptr->MAX_ENTRIES = max_queue_size; msgq_ptr->NOTIFICATION_FUNCTION = notification_function; msgq_ptr->NOTIFICATION_FUNCTION_PARAMETER = notification_data; if ( queue_type == MSG_QUEUE ) { td_ptr = kernel_data->ACTIVE_PTR; msgq_ptr->TD_PTR = td_ptr; if ( td_ptr->MSG_QUEUE_HEAD == NULL ) { td_ptr->MSG_QUEUE_HEAD = (pointer)msgq_ptr; td_ptr->MSG_QUEUE_TAIL = (pointer)msgq_ptr; td_ptr->MESSAGES_AVAILABLE = 0; } else { temp_msgq_ptr = (MSGQ_STRUCT_PTR)(td_ptr->MSG_QUEUE_TAIL); temp_msgq_ptr->NEXT_MSGQ_PTR = msgq_ptr; td_ptr->MSG_QUEUE_TAIL = (pointer)msgq_ptr; } /* Endif */ } else { msgq_ptr->TD_PTR = NULL; } /* Endif */ _INT_ENABLE(); qid = BUILD_QID(kernel_data->INIT.PROCESSOR_NUMBER, queue); return (qid); } /* Endbody */