static void nasa_osal_test_002_004_execute(void) { uint32 local_qid; uint32 copied; char data[MESSAGE_SIZE]; /* [2.4.1] Retrieving the queue by name.*/ test_set_step(1); { int32 err; err = OS_QueueGetIdByName(&local_qid, "test queue"); test_assert(err == OS_SUCCESS, "queue not found"); } /* [2.4.2] Get operation with a one second timeout, an error is expected.*/ test_set_step(2); { int32 err; err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(1000)); test_assert(err == OS_QUEUE_TIMEOUT, "unexpected error code"); } /* [2.4.3] Get operation in non-blocking mode, an error is expected.*/ test_set_step(3); { int32 err; err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_CHECK); test_assert(err == OS_QUEUE_EMPTY, "unexpected error code"); } }
void task_1(void) { uint32 status; uint32 data_received; uint32 data_size; OS_printf("Starting task 1\n"); OS_TaskRegister(); OS_printf("Delay for 1 second before starting\n"); OS_TaskDelay(1000); while(1) { status = OS_QueueGet(msgq_id, (void*)&data_received, MSGQ_SIZE, &data_size, 1000); if ( status == OS_SUCCESS ) { OS_printf("TASK 1: Recieved a message on the queue\n"); } else if ( status == OS_QUEUE_TIMEOUT ) { OS_printf("TASK 1: Timeout on Queue! Timer counter = %d\n", timer_counter); } else { OS_printf("TASK 1: Queue Get error!\n"); } } }
void task_3(void) { uint32 data_received; uint32 data_size; uint32 status; printf("Starting task 3\n"); OS_TaskRegister(); while(1) { status = OS_QueueGet(msgq_id, (void*)&data_received, MSGQ_SIZE, &data_size, OS_PEND); if (status == OS_SUCCESS) { printf("TASK 3: Received - %d\n", (int)data_received+1); } else { printf("TASK 3: Error calling OS_QueueGet\n"); } } }
static void nasa_osal_test_002_003_execute(void) { uint32 tid; unsigned i; /* [2.3.1] Creataing a queue with depth 4 and message size 20.*/ test_set_step(1); { int32 err; err = OS_QueueCreate(&qid, "test queue", 4, MESSAGE_SIZE, 0); test_assert(err == OS_SUCCESS, "queue creation failed"); } /* [2.3.2] Creating the writer task.*/ test_set_step(2); { int32 err; err = OS_TaskCreate(&tid, "writer task", test_task_writer, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_SUCCESS, "writer task creation failed"); } /* [2.3.3] Reading messages from the writer task.*/ test_set_step(3); { for (i = 0; i < WRITER_NUM_MESSAGES; i++) { int32 err; char data[MESSAGE_SIZE]; uint32 copied; err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(200)); test_assert(err == OS_SUCCESS, "timed out"); test_assert(strncmp(data, "Hello World", sizeof (data)) == 0, "wrong message"); } } /* [2.3.4] Waiting for task termination then checking for errors.*/ test_set_step(4); { (void) OS_TaskWait(tid); tid = 0; test_assert_sequence("", "queue write errors occurred"); } }