Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include #include #include #include #include #include #include #include #include #define _ _ MSP 4 3 2 P 4 XX _ _

#include #include #include #include #include #include #include #include #include #include #include #include #include #define __MSP432P4XX__ #include #define TASKSTACKSIZE 2048 Void clockHandler1(UArg arg); Void task1(UArg arg0, UArg arg1); Void task2(UArg arg0, UArg arg1); Void task3(UArg arg0, UArg arg1); // New task for temperature sampling Task_Struct task1Struct, task2Struct, task3Struct; // Task structures Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE], task3Stack[TASKSTACKSIZE]; // Task stacks Semaphore_Struct semaStruct; Semaphore_Handle semaphoreHandle = NULL; int main(){// Init drivers Board_init(); srand(time(NULL)); Task_Params taskParams; Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; // Task 1 taskParams.stack = &task1Stack; Task_construct(&task1Struct, (Task_FuncPtr)task1, &taskParams, NULL); // Task 2 taskParams.stack = &task2Stack; Task_construct(&task2Struct, (Task_FuncPtr)task2, &taskParams, NULL); // Task 3 for temperature sampling taskParams.stack = &task3Stack; Task_construct(&task3Struct, (Task_FuncPtr)task3, &taskParams, NULL); // Construct a semaphore object Semaphore_Params semaParams; Semaphore_Params_init(&semaParams); Semaphore_construct(&semaStruct, 0, &semaParams); semaphoreHandle = Semaphore_handle(&semaStruct); Clock_Params clockParams; Clock_Handle myClk0; Clock_Params_init(&clockParams); clockParams.period =10; clockParams.startFlag = TRUE; // Start immediately myClk0= Clock_create((Clock_FuncPtr)clockHandler1,1, &clockParams, NULL); //2nd argument must be greater than 0 if (myClk0== NULL) System_abort("Clock0 create failed"); BIOS_start(); // Jump to the OS and won't return return(0); } Void task1(UArg arg0, UArg arg1)// Task 1{ while(1){ printf("Task 1"); Semaphore_post(semaphoreHandle); // Signal semaphore Task_sleep(1000); // Delay for 1 second }} Void task2(UArg arg0, UArg arg1)// Task 2{ printf("Task 2"); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); while(1){ Semaphore_pend(semaphoreHandle, BIOS_WAIT_FOREVER); // Wait for semaphore signal MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); // Toggle LED }} Void task3(UArg arg0, UArg arg1)// Task 3 for temperature sampling { while (1){/* Trigger ADC conversion */ ADC14_toggleConversionTrigger(ADC_TRIGGER_MANUAL); /* Wait for conversion to complete */ while (ADC14_isBusy()){}/* Get temperature reading */ uint32_t adcValue = ADC14_getResult(ADC_MEM0); double temperature =(adcValue *3.3)/16384*100; // Assuming 3.3V reference and 14-bit resolution /* Send temperature reading to terminal */ printf("T%.1f ", temperature); /* Wait for next sampling period */ Task_sleep(5000); // Sampling period of 5000 ms }} Void clockHandler1(UArg arg){ Task_yield(); // To force a task switch if needed }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What is the effect of word war second?

Answered: 1 week ago

Question

The Nature of Nonverbal Communication

Answered: 1 week ago

Question

Functions of Nonverbal Communication

Answered: 1 week ago

Question

Nonverbal Communication Codes

Answered: 1 week ago