11//============================================================================
22// Product: "Low-Power" example, EK-TM4C123GXL board, QK kernel
3- // Last updated for version 7.3.0
4- // Last updated on 2023-07-23
53//
64// Q u a n t u m L e a P s
75// ------------------------
86// Modern Embedded Software
97//
10- // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
8+ // Copyright (C) 2005 Quantum Leaps, LLC. <state-machine.com>
119//
1210// This program is open source software: you can redistribute it and/or
1311// modify it under the terms of the GNU General Public License as published
3129// <www.state-machine.com/licensing>
32303331//============================================================================
34- #include "qpc.h"
35- #include "low_power.h"
36- #include "bsp.h"
32+ #include "qpc.h" // QP/C real-time event framework
33+ #include "low_power.h" // this application interface
34+ #include "bsp.h" // Board Support Package
3735
38- #include "TM4C123GH6PM.h" // the device specific header (TI)
39- #include "rom.h" // the built-in ROM functions (TI)
40- #include "sysctl.h" // system control driver (TI)
41- #include "gpio.h" // GPIO driver (TI)
36+ #include "TM4C123GH6PM.h" // the device specific header (TI)
37+ #include "sysctl.h" // system control driver (TI)
38+ #include "gpio.h" // GPIO driver (TI)
4239// add other drivers if necessary...
4340
4441//Q_DEFINE_THIS_FILE
4744 #error The low-power example does not provide Spy build configuration
4845#endif
4946
50- // ISRs defined in this BSP ------------------------------------------------
47+ // ISRs defined in this BSP --------------------------------------------------
5148void SysTick_Handler (void );
5249void GPIOPortA_IRQHandler (void );
5350
54- // Local-scope objects -----------------------------------------------------
51+ // Local-scope objects -------------------------------------------------------
5552
5653// bitmask of active sub-systems needed for low-power operation.
5754// NOTE: shared between the idle thread application, see NOTE1
7269
7370#define XTAL_HZ 16000000U
7471
75- // ISRs used in this project ===============================================
72+ // ISRs used in this project =================================================
7673void SysTick_Handler (void ) {
7774 QK_ISR_ENTRY (); // inform QK about entering an ISR
7875 QTIMEEVT_TICK_X (0U , (void * )0 ); // process time events for rate 0
@@ -98,28 +95,26 @@ void GPIOPortF_IRQHandler(void) {
9895
9996// BSP functions ===========================================================
10097void BSP_init (void ) {
101- // Set the clocking to run directly from the crystal
102- ROM_SysCtlClockSet (SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
103- SYSCTL_XTAL_16MHZ );
104- SystemCoreClock = XTAL_HZ ;
105-
10698 // NOTE The VFP (Floating Point Unit) unit is configured by QK-port
10799
108- // configure Timer0, but don't enable the interrupt just yet
109- SYSCTL -> RCGCTIMER |= (1U << 0 ); // enable Run mode for Timer0
100+ // enable clock for to the peripherals used by this application...
101+ SYSCTL -> RCGCGPIO |= (1U << 5U ); // enable Run mode for GPIOF
102+ SYSCTL -> RCGCTIMER |= (1U << 0U ); // enable Run mode for Timer0
103+
104+ // configure the Timers
110105 TIMER0 -> CTL &= ~(1U << 0 ); // disable Timer0 before any changes
111106 TIMER0 -> CFG = 0U ;
112107 TIMER0 -> TAMR |= (0x2 << 0 ); // Timer0A
113108 TIMER0 -> TAMR &= ~(1U << 4 );
114109 TIMER0 -> TAILR = XTAL_HZ / BSP_TICKS1_PER_SEC ;
115110 TIMER0 -> IMR &= ~(1U << 0 ); // disable timer interrupt for now
116- SYSCTL -> RCGCTIMER &= ~(1U << 0 ); // disable Run mode for Timer0
111+ SYSCTL -> RCGCTIMER &= ~(1U << 0 ); // disable Run mode for Timer0
117112
118113 // configure the LEDs and push buttons
119114 SYSCTL -> RCGCGPIO |= (1U << 5 ); // enable Run mode for GPIOF
120- GPIOF -> DIR |= (LED_RED | LED_GREEN | LED_BLUE );// set direction: output
115+ GPIOF -> DIR |= (LED_RED | LED_GREEN | LED_BLUE ); // direction: output
121116 GPIOF -> DEN |= (LED_RED | LED_GREEN | LED_BLUE ); // digital enable
122- GPIOF -> DATA_Bits [LED_RED | LED_GREEN | LED_BLUE ] = 0U ; // turn off
117+ GPIOF -> DATA_Bits [LED_RED | LED_GREEN | LED_BLUE ] = 0U ; // turn off
123118
124119 // configure the button SW1
125120 GPIOF -> DIR &= ~BTN_SW1 ; // input
@@ -185,6 +180,9 @@ void QF_onStartup(void) {
185180 // enable IRQs in the NVIC...
186181 NVIC_EnableIRQ (GPIOF_IRQn );
187182 NVIC_EnableIRQ (TIMER0A_IRQn );
183+
184+ // enable interrupts in hardware
185+ GPIOF -> IM |= BTN_SW1 ; // enable GPIOF interrupt for SW1
188186}
189187//............................................................................
190188void QF_onCleanup (void ) {
@@ -204,8 +202,8 @@ void QK_onIdle(void) {
204202 && QTimeEvt_noActive (1U )) // no time events at rate-1?
205203 {
206204 // safe to disable Timer0 and interrupt
207- TIMER0 -> CTL &= ~(1U << 0 ); // disable Timer0
208- TIMER0 -> IMR &= ~(1U << 0 ); // disable timer interrupt
205+ TIMER0 -> CTL &= ~(1U << 0U ); // disable Timer0
206+ TIMER0 -> IMR &= ~(1U << 0U ); // disable timer interrupt
209207 l_activeSet &= ~(1U << TIMER0_ACTIVE ); // mark rate-1 as disabled
210208 }
211209 QF_INT_ENABLE ();
@@ -222,15 +220,18 @@ Q_NORETURN Q_onError(char const * const module, int_t const id) {
222220 //
223221 Q_UNUSED_PAR (module );
224222 Q_UNUSED_PAR (id );
223+ QS_ASSERTION (module , id , 10000U ); // report assertion to QS
225224
226225#ifndef NDEBUG
227- // for debugging, hang on in an endless loop toggling the RED LED...
228- while (GPIOF -> DATA_Bits [BTN_SW1 ] != 0 ) {
229- GPIOF -> DATA = LED_RED ;
230- GPIOF -> DATA = 0U ;
226+ // light up all LEDs
227+ GPIOF -> DATA_Bits [LED_GREEN | LED_RED | LED_BLUE ] = 0xFFU ;
228+ for (;;) { // for debugging, hang on in an endless loop...
231229 }
232- #endif
230+ #else
233231 NVIC_SystemReset ();
232+ for (;;) { // explicitly "no-return"
233+ }
234+ #endif
234235}
235236//............................................................................
236237void assert_failed (char const * const module , int_t const id ); // prototype
0 commit comments