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 Log(char_ptr msg) { LOG_MESSAGE_PTR msg_ptr; if (log_pool) { msg_ptr = (LOG_MESSAGE_PTR)_msg_alloc(log_pool); if (msg_ptr != NULL) { msg_ptr->HEADER.TARGET_QID = _msgq_get_id(0, LOG_QUEUE); strncpy(msg_ptr->MESSAGE,msg,LOG_MESSAGE_SIZE); _msgq_send(msg_ptr); } } }
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 Temp_task(uint32_t initial_data) { _queue_id health_qid; APPLICATION_MESSAGE * msg; printf("\n Temp task started\n"); _task_block(); // Per Lab 5 requirements health_qid = _msgq_get_id(0, HEALTH_QUEUE); while(1){ _time_delay(5000); msg = _msg_alloc_system(sizeof(*msg)); if( msg != NULL){ msg->HEADER.TARGET_QID = health_qid; msg->MESSAGE_TYPE = TEMP_MESSAGE; msg->DATA = 0; _msgq_send(msg); } } // _task_block(); }