Answered step by step
Verified Expert Solution
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 MSPPXX #include #define TASKSTACKSIZE Void clockHandlerUArg arg; Void taskUArg arg UArg arg; Void taskUArg arg UArg arg; Void taskUArg arg UArg arg; New task for temperature sampling TaskStruct taskStruct, taskStruct, taskStruct; Task structures Char taskStackTASKSTACKSIZE taskStackTASKSTACKSIZE taskStackTASKSTACKSIZE; Task stacks SemaphoreStruct semaStruct; SemaphoreHandle semaphoreHandle NULL; int main Init drivers Boardinit; srandtimeNULL; TaskParams taskParams; TaskParamsinit&taskParams; taskParams.stackSize TASKSTACKSIZE; Task taskParams.stack &taskStack; Taskconstruct&taskStruct, TaskFuncPtrtask &taskParams, NULL; Task taskParams.stack &taskStack; Taskconstruct&taskStruct, TaskFuncPtrtask &taskParams, NULL; Task for temperature sampling taskParams.stack &taskStack; Taskconstruct&taskStruct, TaskFuncPtrtask &taskParams, NULL; Construct a semaphore object SemaphoreParams semaParams; SemaphoreParamsinit&semaParams; Semaphoreconstruct&semaStruct, &semaParams; semaphoreHandle Semaphorehandle&semaStruct; ClockParams clockParams; ClockHandle myClk; ClockParamsinit&clockParams; clockParams.period ; clockParams.startFlag TRUE; Start immediately myClk ClockcreateClockFuncPtrclockHandler &clockParams, NULL; nd argument must be greater than if myClk NULL SystemabortClock create failed"; BIOSstart; Jump to the OS and won't return return; Void taskUArg arg UArg arg Task while printfTask ; SemaphorepostsemaphoreHandle; Signal semaphore Tasksleep; Delay for second Void taskUArg arg UArg arg Task printfTask ; MAPGPIOsetAsOutputPinGPIOPORTP GPIOPIN; MAPGPIOsetOutputLowOnPinGPIOPORTP GPIOPIN; while SemaphorependsemaphoreHandle BIOSWAITFOREVER; Wait for semaphore signal MAPGPIOtoggleOutputOnPinGPIOPORTP GPIOPIN; Toggle LED Void taskUArg arg UArg arg Task for temperature sampling while Trigger ADC conversion ADCtoggleConversionTriggerADCTRIGGERMANUAL; Wait for conversion to complete while ADCisBusy Get temperature reading uintt adcValue ADCgetResultADCMEM; double temperature adcValue ; Assuming V reference and bit resolution Send temperature reading to terminal printfTf temperature; Wait for next sampling period Tasksleep; Sampling period of ms Void clockHandlerUArg arg Taskyield; To force a task switch if needed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started