Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Logic for blinking the SOS signal or changing the state of the LEDs in a specific pattern. CS3220S board is used Current code works to

Logic for blinking the SOS signal or changing the state of the LEDs in a specific pattern.

CS3220S board is used Current code works to only switch the lights on the board.

I need logic to make the pattern light SOS - 3 red blinks, 3 green blinks, 3 red blinks

#include #include

/* Driver Header files */ #include #include

/* Driver configuration */ #include "ti_drivers_config.h"

#define DOT_DURATION 500000 // 500ms #define DASH_DURATION 1500000 // 1500ms #define CHAR_GAP_DURATION (3 * DOT_DURATION) // 3*500ms #define WORD_GAP_DURATION (7 * DOT_DURATION) // 7*500ms

enum State {DOT, DASH, PAUSE_BETWEEN_CHARACTERS, PAUSE_BETWEEN_WORDS, SOS}; enum State currentState = DOT; int sosCount = 0;

Timer_Handle timer0;

void timerCallback(Timer_Handle myHandle, int_fast16_t status) {

switch (currentState) { case DOT: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON); currentState = PAUSE_BETWEEN_CHARACTERS; break; case DASH: GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_ON); currentState = PAUSE_BETWEEN_CHARACTERS; break; case PAUSE_BETWEEN_CHARACTERS: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); if (sosCount < 3) { currentState = DOT; sosCount++; } else { currentState = PAUSE_BETWEEN_WORDS; sosCount = 0; } break; case PAUSE_BETWEEN_WORDS: GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF); } }

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. */ void gpioButtonFxn0(uint_least8_t index) { /* Toggle an LED */ GPIO_toggle(CONFIG_GPIO_LED_0); }

/* * ======== gpioButtonFxn1 ======== * Callback function for the GPIO interrupt on CONFIG_GPIO_BUTTON_1. * This may not be used for all boards. * * Note: GPIO interrupts are cleared prior to invoking callbacks. */ void gpioButtonFxn1(uint_least8_t index) { /* Toggle an LED */ GPIO_toggle(CONFIG_GPIO_LED_1); }

/* * ======== 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, gpioButtonFxn1); GPIO_enableInt(CONFIG_GPIO_BUTTON_1); }

return (NULL); }

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

Understand how people development is used to retain talent.

Answered: 1 week ago

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago