Java program using interrupt and 32-bit timer Call your state machine every 500000 us. Continuously blink SOS
Question:
Java program using interrupt and 32-bit timer
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).
The following guide 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
if a button is pushed at any time during a message, the new message will not start until the end of the 7*500ms gap between messages. The following example assumes the button is pushed during the first SOS and during the last 3500ms.
SOS 3500ms OK 3500ms OK 3500ms OK 3500ms SOS
=================================================================================
/* * Copyright (c) 2015-2020, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* * ======== gpiointerrupt.c ======== */ #include
/* Driver Header files */ #include
/* Driver configuration */ #include "ti_drivers_config.h"
/* * ======== 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); }
void timerCallback(Timer_Handle myHandle, int_fast16_t status) {} void initTimer(void) { Timer_Handle timer0; Timer_Params params; Timer_init(); Timer_Params_init(¶ms); params.period = 500; 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) {} } }
=================================================================================
Physics for Scientists and Engineers A Strategic Approach with Modern Physics
ISBN: 978-0133942651
4th edition
Authors: Randall D. Knight