Embedded System Design 2 - Project
interrupt.h File Reference

Interrupt functionality. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

void initGPIOwakeup (void)
 Initialize GPIO wake-up functionality. More...
 
bool BTN_getTriggered (uint8_t number)
 Getter for the PB0_triggered and PB1_triggered variables. More...
 
void BTN_setTriggered (uint8_t number, bool value)
 Setter for the PB0_triggered and PB1_triggered variable. More...
 

Detailed Description

Interrupt functionality.

Version
3.1
Author
Brecht Van Eeckhoudt

License

Copyright (C) 2019 - Brecht Van Eeckhoudt

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the GNU General Public License can be found in the LICENSE file along with this source code.


Some methods use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.

Definition in file interrupt.h.

Function Documentation

◆ BTN_getTriggered()

bool BTN_getTriggered ( uint8_t  number)

Getter for the PB0_triggered and PB1_triggered variables.

Parameters
[in]number
  • 0 - PB0_triggered selected.
  • 1 - PB1_triggered selected.
Returns
The value of PB0_triggered or PB1_triggered.

Definition at line 145 of file interrupt.c.

146 {
147  if (number == 0) return (PB0_triggered);
148  else if (number == 1) return (PB1_triggered);
149  else
150  {
151 
152 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
153  dbcrit("Non-existing button selected!");
154 #endif /* DEBUG_DBPRINT */
155 
156  error(18);
157 
158  return (false);
159  }
160 }
volatile bool PB0_triggered
Definition: interrupt.c:79
volatile bool PB1_triggered
Definition: interrupt.c:80
void error(uint8_t number)
Error method.
Definition: util.c:131
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ BTN_setTriggered()

void BTN_setTriggered ( uint8_t  number,
bool  value 
)

Setter for the PB0_triggered and PB1_triggered variable.

Parameters
[in]number
  • 0 - PB0_triggered selected.
  • 1 - PB1_triggered selected.
[in]valueThe boolean value to set to the selected variable.

Definition at line 174 of file interrupt.c.

175 {
176  if (number == 0) PB0_triggered = value;
177  else if (number == 1) PB1_triggered = value;
178  else
179  {
180 
181 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
182  dbcrit("Non-existing button selected!");
183 #endif /* DEBUG_DBPRINT */
184 
185  error(19);
186  }
187 }
volatile bool PB0_triggered
Definition: interrupt.c:79
volatile bool PB1_triggered
Definition: interrupt.c:80
void error(uint8_t number)
Error method.
Definition: util.c:131
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ initGPIOwakeup()

void initGPIOwakeup ( void  )

Initialize GPIO wake-up functionality.

Initialize buttons PB0 and PB1 on falling-edge interrupts and ADXL_INT1 on rising-edge interrupts.

Definition at line 91 of file interrupt.c.

92 {
93  /* Enable necessary clocks (just in case) */
94  CMU_ClockEnable(cmuClock_HFPER, true); /* GPIO is a High Frequency Peripheral */
95  CMU_ClockEnable(cmuClock_GPIO, true);
96 
97  /* Configure PB0 and PB1 as input with glitch filter enabled, last argument sets pull direction */
98  GPIO_PinModeSet(PB0_PORT, PB0_PIN, gpioModeInputPullFilter, 1);
99  GPIO_PinModeSet(PB1_PORT, PB1_PIN, gpioModeInputPullFilter, 1);
100 
101  /* Configure ADXL_INT1 as input, the last argument enables the filter */
102  GPIO_PinModeSet(ADXL_INT1_PORT, ADXL_INT1_PIN, gpioModeInput, 1);
103 
104  /* Clear all odd pin interrupt flags (just in case)
105  * NVIC_ClearPendingIRQ(GPIO_ODD_IRQn); would also work but is less "readable" */
106  GPIO_IntClear(0xAAAA);
107 
108  /* Clear all even pin interrupt flags (just in case)
109  * NVIC_ClearPendingIRQ(GPIO_EVEN_IRQn); would also work but is less "readable" */
110  GPIO_IntClear(0x5555);
111 
112  /* All pending interrupts can be cleared with GPIO_IntClear(0xFFFF); */
113 
114  /* Enable IRQ for even numbered GPIO pins */
115  NVIC_EnableIRQ(GPIO_EVEN_IRQn);
116 
117  /* Enable IRQ for odd numbered GPIO pins */
118  NVIC_EnableIRQ(GPIO_ODD_IRQn);
119 
120  /* Enable falling-edge interrupts for PB pins */
121  GPIO_ExtIntConfig(PB0_PORT, PB0_PIN, PB0_PIN, false, true, true);
122  GPIO_ExtIntConfig(PB1_PORT, PB1_PIN, PB1_PIN, false, true, true);
123 
124  /* Enable rising-edge interrupts for ADXL_INT1 */
125  GPIO_ExtIntConfig(ADXL_INT1_PORT, ADXL_INT1_PIN, ADXL_INT1_PIN, true, false, true);
126 
127 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
128  dbinfo("GPIO wake-up initialized");
129 #endif /* DEBUG_DBPRINT */
130 
131 }
#define ADXL_INT1_PORT
Definition: pin_mapping.h:77
#define PB0_PIN
Definition: pin_mapping.h:90
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
#define PB1_PORT
Definition: pin_mapping.h:91
#define PB0_PORT
Definition: pin_mapping.h:89
#define PB1_PIN
Definition: pin_mapping.h:92
#define ADXL_INT1_PIN
Definition: pin_mapping.h:78