Question
This is what I have to do and I have really been struggling with this. This is creating a state machine for CC3220S LaunchPad. The
This is what I have to do and I have really been struggling with this. This is creating a state machine for CC3220S LaunchPad. The last person really helped me a lot. I am still getting a lot of errors. One of them is LED_status is undefined. The below is the requirements.
15. Now it is time to modify gpiointerrupt.c and the code provided in step Your code will need to accomplish the following: Call your state machine every 500000 us. Continuously blink SOS in Morse code on the green and red LEDs. If a button is pushed, toggle the message between SOS and OK. Pushing the button in the middle of a message should NOT change the message until it is complete. For example, if you push the button while the 'O' in SOS is being blinked out, the message will not change to OK until after the SOS message is completed. Remember in a previous module your work with UART included an example of how to turn an LED on or off (as opposed to toggle).
16. You may wish to perform your own research on how Morse code works to help better inform your work. The following guidance will help provide a base for the functionality you are creating: Dot = red LED on for 500ms Dash = green LED on for 1500ms 3*500ms between characters (both LEDs off) 7*500ms between words (both LEDs off), for example SOS 3500ms SOS
Thank you for any help!
#include
/* Driver Header files */ #include
/* Driver configuration */ #include "ti_drivers_config.h" /* Driver configuration for timer */ #include
enum BUTTON_STATES{ SOS_MSG, OK_MSG }; enum BUTTON_STATES CurrentState = SOS_MSG; enum LED_status {OFF, DOT, DASH};
LED_status SOS_Message[] = {DOT, OFF, DOT, OFF, DOT, OFF, OFF, OFF, DASH, OFF, DASH, OFF, DASH, OFF, OFF, OFF, DOT, OFF, DOT, OFF, DOT, OFF };
LED_status OK_Message[] = {DASH, DASH, DASH, OFF, DASH, DASH, OFF, DASH, DASH, DASH, OFF, OFF, OFF, OFF };
unsigned char state = 6;
void timerCallback(Timer_Handle myHandle) { if (CurrentState == SOS_MSG || CurrentState == OK_MSG){ LED_status state; if (CurrentState == SOS_MSG) state = SOS_Message[i]; else// Current state = OK_Message[i]; switch(state){ case OFF: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); break; case DOT: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); break; case DASH: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); break; }
i++; if ((CurrentState == SOS_MSG && i= 22) || (CurrentState == OK_MSG && i ==13)){\ CurrentState = ButtonPressed; { i = 0; }
} } ifCurrentState == OK_MSG){ state = LED_status SOS_Message[i];
switch(state){ case 0: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); break; case 1: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); break; case 2: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); break; }
i++; if (i == 34) CurrentState = ButtonPressed; i = 0; } } }
//Driver Handles - Global Variables Timer_Handle timer0;
//Function to Initialize Timer void initTimer(void) { Timer_Handle timer0; Timer_Params params; Timer_init(); Timer_Params_init(ms); params.period = 1000000; params.periodUnits = Timer_PERIOD_US; params.timerMode = Timer_CONTINUOUS_CALLBACK; params.timerCallback = timerCallback;
timer0 = Timer_open(CONFIG_TIMER_0, ms); if (timer0 == NULL) { /* Failed to initialized timer */ while (1) {} } if (Timer_start(timer0) == Timer_STATUS_ERROR) { /* Failed to start timer */ while (1) {} } }
/* * ======== gpioButtonFxn0 ======== * Callback function for the GPIO interrupt on CONFIG_GPIO_BUTTON_0. * * Note: GPIO interrupts are cleared prior to invoking callbacks. */ char ButtonPressed = 0; void gpioButtonFxn0(uint_least8_t index) { /* Toggle an LED */ if (CurrentState == SOS_MSG || CurrentState == OK_MSG) { if (CurrentState == SOS_MSG) CurrentState = OK_MSG; else // CurrentState == OK_MSG CurrentState = SOS_MSG; } }
}
/* * ======== mainThread ======== */ void *mainThread(void *arg0) {
/* Call driver init functions */ GPIO_init();
/* Configure the LED and button pins */ GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_setConfig(CONFIG_GPIO_LED_1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_setConfig(CONFIG_GPIO_BUTTON_0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
/* Turn on user LED */ GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
/* Install Button callback */ GPIO_setCallback(CONFIG_GPIO_BUTTON_0, gpioButtonFxn0);
/* Enable interrupts */ GPIO_enableInt(CONFIG_GPIO_BUTTON_0);
/* * If more than one input pin is available for your device, interrupts * will be enabled on CONFIG_GPIO_BUTTON1. */ if (CONFIG_GPIO_BUTTON_0 != CONFIG_GPIO_BUTTON_1) { /* Configure BUTTON1 pin */ GPIO_setConfig(CONFIG_GPIO_BUTTON_1, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
/* Install Button callback */ GPIO_setCallback(CONFIG_GPIO_BUTTON_1, gpioButtonFxn0); GPIO_enableInt(CONFIG_GPIO_BUTTON_1); }
initTimer(); return (NULL); }
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