Пример #1
0
void server_task 
   (
      uint_32 param
   )
{
   SERVER_MESSAGE_PTR msg_ptr;
   _mqx_uint          i;
   _queue_id          server_qid;
   boolean            result;
   _task_id           task_id;

   /* open a message queue */
   server_qid = _msgq_open(SERVER_QUEUE, 0);
   
   if (server_qid == 0) {
      printf("\nCould not open the server message queue\n");
      _mqx_exit(0);
   }

   /* create a message pool */   
   message_pool = _msgpool_create(sizeof(SERVER_MESSAGE), 
      NUM_CLIENTS, 0, 0);
      
   if (message_pool == MSGPOOL_NULL_POOL_ID) {
      printf("\nCount not create a message pool\n");
      _mqx_exit(0);
   }

   /* create the client tasks */
   for (i = 0; i < NUM_CLIENTS; i++) {
      task_id = _task_create(0, CLIENT_TASK, (uint_32)i);
      
      if (task_id == 0) {
         printf("\nCould not create a client task\n");
         _mqx_exit(0);
      }
   }
      
   while (TRUE) {
      msg_ptr = _msgq_receive(server_qid, 0);
      
      if (msg_ptr == NULL) {
         printf("\nCould not receive a message\n");
         _mqx_exit(0);
      }

      printf(" %c \n", msg_ptr->DATA[0]);
  
      /* return the message */   
      msg_ptr->HEADER.TARGET_QID = msg_ptr->HEADER.SOURCE_QID;
      msg_ptr->HEADER.SOURCE_QID = server_qid;
      
      result = _msgq_send(msg_ptr);
      
      if (result != TRUE) {
         printf("\nCould not send a message\n");
         _mqx_exit(0);
      }
   }
}
Пример #2
0
void Logging_task(uint_32 param)
{
   _queue_id         log_qid;
   LOG_MESSAGE_PTR   msg_ptr;
#if DEMOCFG_ENABLE_USB_FILESYSTEM
  MQX_FILE_PTR      log_fp;
#endif
 
   // create a pool of logging messages   
   log_pool = _msgpool_create(sizeof(LOG_MESSAGE), LOG_POOL_SIZE, 0, 0);

   // open a message queue to receive log message on
   log_qid = _msgq_open(LOG_QUEUE, 0);
   
      
   // signal that initialization is complete
   _lwsem_post(&Logging_init_sem);

   while (TRUE) {
      // wait for a message
      msg_ptr = _msgq_receive(log_qid, 0);

      if (msg_ptr) {
         #if DEMOCFG_ENABLE_USB_FILESYSTEM
            // check to see if a filesystem is available
            if (_lwsem_poll(&USB_Stick)) {

               // Open the log file and position to the end
               log_fp = fopen(LOG_FILE,"a");

               if (log_fp) {
                  fseek(log_fp,0,IO_SEEK_END);
         
                  do {
                     // Write the message to the log file
                     write(log_fp,msg_ptr->MESSAGE, strlen(msg_ptr->MESSAGE));

                     // Return the message back to the message pool
                     _msg_free(msg_ptr);

                     // check for another message
                     msg_ptr = _msgq_poll(log_qid);
                  } while (msg_ptr != NULL);

                  // close the file
                  fclose(log_fp);
               }

               // Indicate that the USB stick is no longer in use
               _lwsem_post(&USB_Stick);
            } else {
               _msg_free(msg_ptr);
            }
         #else
            printf(msg_ptr->MESSAGE);
            _msg_free(msg_ptr);
         #endif
      }
   }
}
Пример #3
0
void Responder
(
    uint_32   parameter
)
{
    MESSAGE_HEADER_STRUCT_PTR   msg_ptr;

    Responder_Queue_qid = _msgq_open( MSGQ_FREE_QUEUE, SIZE_UNLIMITED);
    if (Responder_Queue_qid == (_queue_id)0) {
        /* queue could not be opened */
    }
    /*
    ** LOOP -
    */
    while ( TRUE ) {
        /*
        * Service the message queue - Responder_Queue
        */
        msg_ptr = _msgq_receive_ticks(Responder_Queue_qid, NO_TIMEOUT);
        /* process message Respond_msg */
        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);

        putchar('.');
    } /* endwhile */
} /*end of task*/
Пример #4
0
void responder_task(uint_32 param) 
{
    THE_MESSAGE_PTR    msg_ptr;
    _queue_id          my_qid,temp_qid;

    printf("\n\n\nResponder task started\n");
    my_qid = _msgq_open(RESPONDER_QUEUE,0);
    while (TRUE) {
        printf("Responder task receiving...");
        msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE,0);
        printf("done\n");
        if (msg_ptr != NULL) {
            printf("Message: Size=%x, SQID= %x, TQID=%x, DATA = %x\n", msg_ptr->HEADER.SIZE, msg_ptr->HEADER.SOURCE_QID,
                msg_ptr->HEADER.TARGET_QID, msg_ptr->DATA );
            // Swap source & Destination
            temp_qid                   = msg_ptr->HEADER.SOURCE_QID;
            msg_ptr->HEADER.SOURCE_QID = msg_ptr->HEADER.TARGET_QID;
            msg_ptr->HEADER.TARGET_QID = temp_qid;
            msg_ptr->DATA++;
            _msgq_send(msg_ptr);
        } else {
            log_error("Responder task receive error\n");
        }
    }
}
Пример #5
0
void responder_task
   (
      uint32_t dummy
   ) 
{
   THE_MESSAGE_PTR    msg_ptr;
   _queue_id          qid;
   _queue_id          my_qid;

   puts("Receiver running...\n");
   my_qid = _msgq_open(RESPONDER_QUEUE,0);
   while (TRUE) {
      msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE,0);
      if (msg_ptr != NULL) {
         qid      = msg_ptr->HEADER.SOURCE_QID;
         msg_ptr->HEADER.SOURCE_QID = my_qid;
         msg_ptr->HEADER.TARGET_QID = qid;
         if (MSG_MUST_CONVERT_DATA_ENDIAN(msg_ptr->HEADER.CONTROL)) {
            _mem_swap_endian(global_endian_swap_def, &msg_ptr->DATA);
            MSG_SET_DATA_ENDIAN(msg_ptr->HEADER.CONTROL);
         } /* Endif */                               
         msg_ptr->DATA++;
         putchar('+');
         _msgq_send(msg_ptr);
      } else {
         puts("RESPONDER RECEIVE ERROR\n");
         _task_block();
      }
   }
} 
Пример #6
0
_queue_id _initializeQueue(int queueNum){
	_queue_id queueId = _msgq_open(queueNum, 0);
	if(queueId == MSGQ_NULL_QUEUE_ID){
		printf("Failed to open queue %d.\n", queueNum);
		_task_block();
	}
	return queueId;
}
Пример #7
0
void client_task 
   (
      uint32_t index
   )
{
   SERVER_MESSAGE_PTR msg_ptr;
   _queue_id          client_qid;
   bool            result;

   client_qid  = _msgq_open((_queue_number)(CLIENT_QUEUE_BASE +
      index), 0);

   if (client_qid == 0) {
      printf("\nCould not open a client message queue\n");
      _task_block();
   }
   
   while (TRUE) {
      /*allocate a message*/
      msg_ptr = (SERVER_MESSAGE_PTR)_msg_alloc(message_pool);

      if (msg_ptr == NULL) {
         printf("\nCould not allocate a message\n");
         _task_block();
      }

      msg_ptr->HEADER.SOURCE_QID = client_qid;      
      msg_ptr->HEADER.TARGET_QID = _msgq_get_id(0, SERVER_QUEUE);
      msg_ptr->HEADER.SIZE = sizeof(MESSAGE_HEADER_STRUCT) + 
         strlen((char *)msg_ptr->DATA) + 1;
      msg_ptr->DATA[0] = ('A'+ index);
     
      printf("Client Task %ld\n", index);  
      
      result = _msgq_send(msg_ptr);
      
      if (result != TRUE) {
         printf("\nCould not send a message\n");
         _task_block();
      }
   
      /* wait for a return message */
      msg_ptr = _msgq_receive(client_qid, 0);
      
      if (msg_ptr == NULL) {
         printf("\nCould not receive a message\n");
         _task_block();
      }
    
       /* free the message */
      _msg_free(msg_ptr);
   }

}
Пример #8
0
void main_task(uint_32 dest_core)
{
    _pool_id        msgpool;
    THE_MESSAGE_PTR msg_ptr;
    _queue_id       my_qid,temp_qid;
    uint_32         expected;

    printf("\n\n\nMain task started\n");

    /* start aux core (M4) */
    _bsp_aux_core_start((void*)0x3f000000);

    /* wait for P1 to boot */
    _time_delay(1000);

    my_qid   = _msgq_open(MAIN_QUEUE,0);
    msgpool = _msgpool_create(sizeof(THE_MESSAGE), 8, 8, 0);
    msg_ptr = (THE_MESSAGE_PTR)_msg_alloc(msgpool);

    if (msg_ptr != NULL) {
        msg_ptr->HEADER.TARGET_QID = _msgq_get_id((_processor_number) dest_core,RESPONDER_QUEUE);
        msg_ptr->HEADER.SOURCE_QID = my_qid;
        msg_ptr->DATA = 0;
    }

    while (msg_ptr != NULL) {
        expected = msg_ptr->DATA+1;
        printf("Main task sending\n");
        _msgq_send(msg_ptr);
        printf("Main task receiving...");
        msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE, 0);
        printf("done\n");
        if (msg_ptr != NULL) {
           printf("Message: Size=%x, SQID= %x, TQID=%x, DATA = %x\n", msg_ptr->HEADER.SIZE, msg_ptr->HEADER.SOURCE_QID,
               msg_ptr->HEADER.TARGET_QID, msg_ptr->DATA );
           if (msg_ptr->HEADER.SIZE != sizeof(THE_MESSAGE)) {
                log_error("Message wrong size\n");
           } else if (msg_ptr->DATA != expected) {
                log_error("Message data incorrect\n");
           }
           temp_qid                   = msg_ptr->HEADER.SOURCE_QID;
           msg_ptr->HEADER.SOURCE_QID = msg_ptr->HEADER.TARGET_QID;
           msg_ptr->HEADER.TARGET_QID = temp_qid;
           msg_ptr->DATA++;
        }
    }
    log_error("Message alloc/receive failed\n");
}
Пример #9
0
void main_task
   (
      uint32_t dummy
   ) 
{
   _pool_id        msgpool;
   THE_MESSAGE_PTR msg_ptr;
   _queue_id       qid;
   _queue_id       my_qid;
   uint32_t         test_number = 0;

   my_qid  = _msgq_open(MAIN_QUEUE,0);
   qid     = _msgq_get_id(TEST2_ID,RESPONDER_QUEUE);
   msgpool = _msgpool_create(sizeof(THE_MESSAGE), 8, 8, 16);
   while (test_number < 1000) {
      msg_ptr = (THE_MESSAGE_PTR)_msg_alloc(msgpool);
      msg_ptr->HEADER.TARGET_QID = qid;
      msg_ptr->HEADER.SOURCE_QID = my_qid;
      msg_ptr->DATA = test_number++;
      putchar('-');
      _msgq_send(msg_ptr);
      msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE, 1000);
      if (msg_ptr == NULL) {
         puts("Receive failed\n");
         //_task_block();
      } else {
         if (msg_ptr->HEADER.SIZE != sizeof(THE_MESSAGE)) {
            puts("Message wrong size\n");
            //_task_block();
         } else {
            if (MSG_MUST_CONVERT_DATA_ENDIAN(msg_ptr->HEADER.CONTROL)) {
               _mem_swap_endian(global_endian_swap_def, &msg_ptr->DATA);
            } /* Endif */
            if (msg_ptr->DATA != test_number) {
               puts("Message data incorrect\n");
               //_task_block();
            } else {
               puts("Message received\n");
            }
         }
         _msg_free(msg_ptr);
      }
   } 
   puts("All complete\n");
   _task_block();
} 
Пример #10
0
void responder_task(uint_32 param)
{
    THE_MESSAGE_PTR    msg_ptr;
    _queue_id          my_qid,temp_qid;

/* As the serial console is shared in case of Vybrid do not print out responder task log to avoid conflicts */
#ifndef PSP_MQX_CPU_IS_VYBRID_M4
    printf("\n\n\nResponder task started\n");
#endif
    my_qid = _msgq_open(RESPONDER_QUEUE,0);
    while (TRUE) {
#ifndef PSP_MQX_CPU_IS_VYBRID_M4
        printf("Responder task receiving...");
#endif
        msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE,0);
#ifndef PSP_MQX_CPU_IS_VYBRID_M4
        printf("done\n");
#endif
        if (msg_ptr != NULL) {
#ifndef PSP_MQX_CPU_IS_VYBRID_M4
            printf("Message: Size=%x, SQID= %x, TQID=%x, DATA = %x\n", msg_ptr->HEADER.SIZE, msg_ptr->HEADER.SOURCE_QID,
                msg_ptr->HEADER.TARGET_QID, msg_ptr->DATA );
#endif
            /* Swap source & destination */
            temp_qid                   = msg_ptr->HEADER.SOURCE_QID;
            msg_ptr->HEADER.SOURCE_QID = msg_ptr->HEADER.TARGET_QID;
            msg_ptr->HEADER.TARGET_QID = temp_qid;
            msg_ptr->DATA++;
            _msgq_send(msg_ptr);
        } else {
#ifndef PSP_MQX_CPU_IS_VYBRID_M4
            log_error("Responder task receive error\n");
#endif
        }
    }
}
Пример #11
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*/