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 } } }
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"); } } }
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); } } }
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(); } } }
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); } }
void runSerialHandler(os_task_param_t task_init_data) { printf("[Serial Handler] Task started.\n"); // Initialize queues and message pools _queue_id interruptQueue = _initializeQueue(HANDLER_INTERRUPT_QUEUE_ID); _queue_id inputQueue = _initializeQueue(HANDLER_INPUT_QUEUE_ID); _initializeHandlerMessagePools(); // Initialize Handler Handler handler; g_Handler = &handler; _initializeHandlerMutex(&g_HandlerMutex); _initializeHandler(g_Handler, interruptQueue, inputQueue, myUART_IDX); #ifdef PEX_USE_RTOS while (1) { #endif // Wait for any incoming messages GenericMessagePtr receivedMessage = (GenericMessagePtr) _msgq_receive(MSGQ_ANY_QUEUE, 0); if (receivedMessage == NULL){ printf("[Serial Handler] Failed to receive a message.\n"); _task_block(); } // Lock access to the handler while it processses the message if(_mutex_lock(&g_HandlerMutex) != MQX_OK){ printf("[Serial Handler] Mutex lock failed.\n"); _task_block(); } // If the message is an serial message from the current writer, handle the writer input if(receivedMessage->HEADER.TARGET_QID == inputQueue){ _handleWriteMessage((SerialMessagePtr) receivedMessage, g_Handler); } // If the message is an interrupt message from the UART event handler, handle the character press else if (receivedMessage->HEADER.TARGET_QID == interruptQueue){ _handleInterruptMessage((InterruptMessagePtr) receivedMessage, g_Handler); } _msg_free(receivedMessage); // Unlock the handler for user access _mutex_unlock(&g_HandlerMutex); #ifdef PEX_USE_RTOS } #endif }
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"); }
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(); }
void runScheduler(os_task_param_t task_init_data) { printf("[Scheduler] Task started.\n"); _queue_id requestQueue = _initializeQueue(SCHEDULER_INTERFACE_QUEUE_ID); _initializeScheduler(requestQueue, USER_TASKS, USER_TASK_COUNT); MQX_TICK_STRUCT nextDeadline; SchedulerRequestMessagePtr requestMessage; #ifdef PEX_USE_RTOS while (1) { #endif requestMessage = NULL; bool deadlineExists = _getNextDeadline(&nextDeadline); // If the scheduler currently has tasks, wait for a new message or the next deadline if(deadlineExists){ requestMessage = _msgq_receive_until(requestQueue, &nextDeadline); // Handle reached deadlines if(requestMessage == NULL){ _handleDeadlineReached(); continue; } } // Otherwise wait indefinitely for a scheduler request else{ requestMessage = _msgq_receive(requestQueue, 0); } // Handle scheduler requests _handleSchedulerRequest(requestMessage); _msg_free(requestMessage); #ifdef PEX_USE_RTOS } #endif }
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 } } }