/*----------------------------------------------------------------------------*/ void Test_OS_TaskRegister_Success(void) { int32 expected = OS_SUCCESS; int32 actual = 99; /* Setup Inputs */ uint32 tableIdx = 1; uint32 task_id = 4; OsApi_Adaptor_setOsTaskKey(77); OsApi_Adaptor_setTaskTableEntry(tableIdx, FALSE, task_id, "", 0, 0, 1, NULL); OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, task_id, 1); OsApi_SetReturnCode(OSAPI_TASKVARADD_INDEX, VCS_OK, 1); /* Execute Test */ actual = OS_TaskRegister(); /* Verify Outputs */ UtAssert_True(actual == expected, "actual == OS_SUCCESS"); UtAssert_True(OsApi_Adaptor_getOsTaskKey() == tableIdx, "OS_task_key == expected"); /* Verify Semaphore Usage */ UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), "nSemTake == nSemGive"); }
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 status; OS_bin_sem_prop_t bin_sem_prop; int counter = 0; OS_printf("Starting task 3\n"); OS_TaskRegister(); OS_printf("TASK 3: Waiting on the semaphore\n"); status = OS_BinSemTake(bin_sem_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 3: Error calling OS_BinSemTake\n"); } else { status = OS_BinSemGetInfo (bin_sem_id, &bin_sem_prop); OS_printf("TASK 3: out of BinSemTake: %d\n",(int)bin_sem_prop.value); } while(1) { OS_TaskDelay(1000); OS_printf("TASK 3: Doing some work: %d\n", (int)counter++); } }
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 blinker(void) { OS_TaskRegister(); while (true) { palSetLine(LINE_ARD_D13); OS_TaskDelay(500); palClearLine(LINE_ARD_D13); OS_TaskDelay(500); } }
static void blinker(void) { OS_TaskRegister(); while (true) { palSetPad(GPIOD, GPIOD_LED3); /* Orange. */ OS_TaskDelay(500); palClearPad(GPIOD, GPIOD_LED3); /* Orange. */ OS_TaskDelay(500); } }
void task_1(void) { uint32 status; OS_bin_sem_prop_t bin_sem_prop; int printf_counter = 0; OS_printf("Starting task 1\n"); OS_TaskRegister(); OS_printf("Delay for 1 second before starting\n"); OS_TaskDelay(1000); while(1) { status = OS_BinSemTake(bin_sem_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 1:Error calling OS_BinSemTake\n"); exit(-1); } else { printf_counter++; counter++; if ( printf_counter > 100 ) { OS_printf("TASK 1: counter:%d timer_counter:%d\n", (int)counter,(int)timer_counter); printf_counter = 0; } status = OS_BinSemGetInfo (bin_sem_id, &bin_sem_prop); if ( bin_sem_prop.value > 1 ) { OS_printf("Error: Binary sem value > 1 ( in task):%d !\n",(int)bin_sem_prop.value); exit(-1); } else if ( bin_sem_prop.value < -1 ) { OS_printf("Error: Binary sem value < -1 ( in task):%d !\n",(int)bin_sem_prop.value); exit(-1); } } } }
void task_2(void) { uint32 status; printf("Starting task 2\n"); OS_TaskRegister(); while(1) { status = OS_MutSemTake(mutex_id); if ( status != OS_SUCCESS ) { printf("TASK 2:Error calling OS_MutSemTake\n"); } shared_resource_x = task_2_id; status = OS_QueuePut(msgq_id, (void*)&shared_resource_x, sizeof(uint32), 0); if ( status != OS_SUCCESS ) { printf("TASK 2:Error calling OS_QueuePut (1)\n"); } OS_TaskDelay(150); shared_resource_x = task_2_id; status = OS_QueuePut(msgq_id, (void*)&shared_resource_x, sizeof(uint32), 0); if ( status != OS_SUCCESS ) { printf("TASK 2:Error calling OS_QueuePut (2)\n"); } status = OS_MutSemGive(mutex_id); if ( status != OS_SUCCESS ) { printf("TASK 2:Error calling OS_MutSemGive\n"); } OS_TaskDelay(500); } }
/*----------------------------------------------------------------------------*/ void Test_OS_TaskRegister_IdInvalid(void) { int32 expected = OS_ERR_INVALID_ID; int32 actual = 99; /* Setup Inputs */ uint32 task_id = 4; OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, task_id, 1); /* Execute Test */ actual = OS_TaskRegister(); /* Verify Outputs */ UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); /* Verify Semaphore Usage */ UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), "nSemTake == nSemGive"); }
void task_1(void) { uint32 status; OS_printf("Starting task 1\n"); OS_TaskRegister(); while(1) { status = OS_MutSemTake(mutex_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 1:Error calling OS_MutSemTake with mutex_id = %d\n",mutex_id); } shared_resource_x = task_1_id; status = OS_QueuePut(msgq_id, (void*)&shared_resource_x, sizeof(uint32), 0); if ( status != OS_SUCCESS ) { OS_printf("TASK 1:Error calling OS_QueuePut ( 1 )\n"); } shared_resource_x = task_1_id; status = OS_QueuePut(msgq_id, (void*)&shared_resource_x, sizeof(uint32), 0); if ( status != OS_SUCCESS ) { OS_printf("TASK 1:Error calling OS_QueuePut ( 2 )\n"); } status = OS_MutSemGive(mutex_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 1:Error calling OS_MutSemGive\n"); } OS_TaskDelay(100); } }
void task_3(void) { uint32 status; OS_printf("Starting task 3\n"); OS_TaskRegister(); while(1) { OS_TaskDelay(1000); OS_printf("TASK 3: Waiting on the semaphore\n"); status = OS_CountSemTake(count_sem_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 3: Error calling OS_CountSemTake\n"); } else { OS_printf("TASK 3: grabbed Counting Sem\n"); } } }
void task_1(void) { uint32 status; OS_printf("Starting task 1\n"); OS_TaskRegister(); while(1) { OS_TaskDelay(2000); OS_printf("TASK 1: Giving the counting semaphore 1\n"); status = OS_CountSemGive(count_sem_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 1: Error calling OS_CountSemGive 1\n"); } else { OS_printf("TASK 1: Counting Sem Give 1 complete\n"); } OS_TaskDelay(500); OS_printf("TASK 1: Giving the counting semaphore 2\n"); status = OS_CountSemGive(count_sem_id); if ( status != OS_SUCCESS ) { OS_printf("TASK 1: Error calling OS_CountSemGive 2\n"); } else { OS_printf("TASK 1: Counting Sem Give 2 complete\n"); } } }