Exemple #1
0
static void event(void)
{
#if MQX_USE_EVENTS
   IF_TINIEST(pointer  handle=0);
   IF_TINIEST(_mqx_uint value=0);

   IF_SMALL(_event_create_component(1, 1, 1));
   IF_SMALL(_event_create_fast(1));
   IF_SMALL(_event_create_fast_auto_clear(1));
   IF_SMALL(_event_open("e", &handle));
   IF_SMALL(_event_set(handle, 0));
   IF_SMALL(_event_clear(handle, 0));
   IF_SMALL(_event_wait_all(handle, 0, 0));

   IF_TYPICAL(_event_close(handle));
   IF_TYPICAL(_event_create("e"));
   IF_MAX(_event_create_auto_clear("e"));
   IF_TYPICAL(_event_destroy("e"));
   IF_MAX(_event_destroy_fast(1));
   IF_MAX(_event_get_value(handle, &value));
   IF_MAX(_event_get_wait_count(handle));
   IF_MAX(_event_open_fast(1, &handle));
   IF_MAX(_event_test(&handle));
   IF_MAX(_event_wait_all_for(handle, 0, NULL));
   IF_TYPICAL(_event_wait_all_ticks(handle, 0, 0));
   IF_MAX(_event_wait_all_until(handle, 0, NULL));
   IF_MAX(_event_wait_any(handle, 0, 0));
   IF_MAX(_event_wait_any_for(handle, 0, NULL));
   IF_TYPICAL(_event_wait_any_ticks(handle, 0, 0));
   IF_MAX(_event_wait_any_until(handle, 0, NULL));
#endif

}
Exemple #2
0
void main_task
   (
      uint_32   parameter
   )
{
   MESSAGE_HEADER_STRUCT_PTR msg_ptr;
   _task_id                  created_task;
   _mqx_uint                 log_result;
   _mqx_uint                 event_result;
   _mqx_uint                 sem_result;

_int_install_unexpected_isr();
   printf("\nMQX %s\n",_mqx_version);
   printf("Hello from main_task().\n");

   /* create the log component */
   log_result = _log_create_component();
   if (log_result != MQX_OK) { 
      /* log component could not be created */
   } /* endif */
   /* Create the mutex component */
   if (_mutex_create_component() != MQX_OK) {
      /* an error has been detected */
   }

   /* create the event component */
   event_result = _event_create_component(EVENT_INITIAL_NUMBER, EVENT_GROWTH, 
      EVENT_MAXIMUM);
   if (event_result != MQX_OK) { 
      /* event component could not be created */
      printf("Error: Cannot create event component\n");
      _task_block();
   } /* endif */

   /* create the semaphore component */
   sem_result = _sem_create_component(SEM_INITIAL_NUMBER, SEM_GROWTH, 
      SEM_MAXIMUM);
   if (sem_result != MQX_OK) { 
      /* semaphore component could not be created */
      printf("Error: Cannot create semaphore component\n");
      _task_block();
   } /* endif */
   MsgPool_pool_id = _msgpool_create ( 8, 10, 0, 0);
   if (MsgPool_pool_id == MSGPOOL_NULL_POOL_ID) { 
      /* _msgpool_create did not succeed */ 
      printf("Error: Cannot create message pool\n");
      _task_block();
   } 
   Main_Queue_qid = _msgq_open( MSGQ_FREE_QUEUE, SIZE_UNLIMITED);
   if (Main_Queue_qid == (_queue_id)0){
         /* queue could not be opened */
      printf("Error: Cannot open message pool\n");
      _task_block();
   }
   created_task = _task_create(0, SENDER, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }
   created_task = _task_create(0, MUTEXA, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }
   created_task = _task_create(0, MUTEXB, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }
   created_task = _task_create(0, SEMA, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }
   created_task = _task_create(0, SEMB, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }
   created_task = _task_create(0, EVENTA, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }
   created_task = _task_create(0, EVENTB, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
      printf("Error: Cannot create task\n");
      _task_block();
   }

#if MQX_KERNEL_LOGGING
   /* create log number 0 */
   log_result = _klog_create(200, 0);
   if (log_result != MQX_OK) { 
      /* log 0 could not be created */
      printf("Error: Cannot create kernel log\n");
      _task_block();
   } /* endif */

   /* define kernel logging */
   _klog_control(0xFFFFFFFF, FALSE);
   _klog_control(
      KLOG_ENABLED                  |
      KLOG_FUNCTIONS_ENABLED        |
      KLOG_INTERRUPTS_ENABLED       |
      KLOG_SYSTEM_CLOCK_INT_ENABLED |
      KLOG_CONTEXT_ENABLED          |
      KLOG_TASKING_FUNCTIONS        |
      KLOG_ERROR_FUNCTIONS          |
      KLOG_MESSAGE_FUNCTIONS        |
      KLOG_INTERRUPT_FUNCTIONS      |
      KLOG_MEMORY_FUNCTIONS         |
      KLOG_TIME_FUNCTIONS           |
      KLOG_EVENT_FUNCTIONS          |
      KLOG_NAME_FUNCTIONS           |
      KLOG_MUTEX_FUNCTIONS          |
      KLOG_SEMAPHORE_FUNCTIONS      |
      KLOG_WATCHDOG_FUNCTIONS, 
      TRUE
      );
#endif

   /* 
   ** LOOP - 
   */
   while ( TRUE ) {
      msg_ptr = _msg_alloc((_pool_id) MsgPool_pool_id );
      if (msg_ptr == NULL) { 
         /* No available message buffer */ 
      } 
      msg_ptr->SIZE = sizeof(MESSAGE_HEADER_STRUCT);
      msg_ptr->SOURCE_QID = msg_ptr->TARGET_QID;
      msg_ptr->TARGET_QID = Sender_Queue_qid;
      _msgq_send(msg_ptr);

      /*
      * Service the message queue - Main_Queue
      */
      msg_ptr = _msgq_receive_ticks(Main_Queue_qid, NO_TIMEOUT);
      /* process message End_msg */
      _msg_free(msg_ptr);

   } /* endwhile */ 
} /*end of task*/
Exemple #3
0
_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 */