IoT-MBBR (masterthesis)
Masterthesis upgrading a Moving Bed BioReactor with extra sensors and cloud connectivity.
interrupt.c File Reference

Interrupt functionality. More...

#include <stdint.h>
#include <stdbool.h>
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_rtc.h"
#include "interrupt.h"
#include "pin_mapping.h"
#include "debug_dbprint.h"
#include "util.h"

Go to the source code of this file.

Functions

void initGPIOwakeup (void)
 Initialize GPIO wake-up functionality. More...
 
bool BTN_getTriggered (void)
 Getter for the BTN_triggered variable. More...
 
void BTN_setTriggered (bool value)
 Setter for the BTN_triggered variable. More...
 
bool PULSE_getTriggered (uint8_t number)
 Getter for the PULSE0/1_triggered variable. More...
 
void PULSE_setTriggered (uint8_t number, bool value)
 Setter for the PULSE0/1_triggered variable. More...
 
void GPIO_EVEN_IRQHandler (void)
 GPIO Even IRQ for even-numbered pins. More...
 
void GPIO_ODD_IRQHandler (void)
 GPIO Odd IRQ for odd-numbered pins. More...
 

Variables

volatile bool BTN_triggered = false
 
volatile bool PULSE0_triggered = false
 
volatile bool PULSE1_triggered = false
 

Detailed Description

Interrupt functionality.

Version
4.0
Author
Brecht Van Eeckhoudt

Versions

  • v1.0: Started from https://github.com/Fescron/Project-LabEmbeddedDesign1
  • v1.1: Added dbprintln(""); above dbinfo statements in IRQ handlers to fix overwriting of text.
  • v1.2: Disabled the RTC counter if GPIO handlers are called, only added necessary includes in header file, moved the others to the source file, updated documentation.
  • v1.3: Started using set method for the static variable ADXL_triggered, added GPIO wakeup initialization method here, renamed file.
  • v1.4: Stopped disabling the GPIO clock.
  • v1.5: Started using getters/setters to indicate an interrupt to main.c.
  • v1.6: Moved IRQ handler of RTC to this delay.c.
  • v1.7: Updated clear pending interrupt logic.
  • v1.8: Updated code with new DEFINE checks.
  • v1.9: Removed error calls for "unknown" pins and added flag check for custom Happy Gecko board pinout.
  • v2.0: Stopped disabling the RTC counter on pin interrupts.
  • v2.1: Disabled the RTC counter on a button push because it confused delays called in LoRaWAN code.
  • v2.2: Changed error numbering.
  • v3.0: Updated version number.
  • v3.1: Removed static before the local variables (not necessary).
  • v4.0: Changed functionality for new board type.

Note
Other interrupt handlers can be found in delay.c and adc.c.

License

Copyright (C) 2020 - 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.c.

Function Documentation

◆ BTN_getTriggered()

bool BTN_getTriggered ( void  )

Getter for the BTN_triggered variable.

Returns
The value of BTN_triggered.

Definition at line 137 of file interrupt.c.

138 {
139  return (BTN_triggered);
140 }
volatile bool BTN_triggered
Definition: interrupt.c:79

◆ BTN_setTriggered()

void BTN_setTriggered ( bool  value)

Setter for the BTN_triggered variable.

Parameters
[in]valueThe boolean value to set to the selected variable.

Definition at line 150 of file interrupt.c.

151 {
152  BTN_triggered = value;
153 }
volatile bool BTN_triggered
Definition: interrupt.c:79

◆ GPIO_EVEN_IRQHandler()

void GPIO_EVEN_IRQHandler ( void  )

GPIO Even IRQ for even-numbered pins.

The RTC is also disabled on a button press (manual wake-up)

Note
The weak definition for this method is located in system_efm32hg.h.

Definition at line 204 of file interrupt.c.

205 {
206  /* Read interrupt flags */
207  uint32_t flags = GPIO_IntGet();
208 
209  /* Check if BTN is pushed */
210  if (flags == 0x0004)
211  {
212  /* Disable the counter (manual wakeup) */
213  RTC_Enable(false);
214 
215  BTN_triggered = true;
216  }
217 
218  /* Check if P2 (PULSE1) is triggered */
219  if (flags == 0x4000) PULSE1_triggered = true;
220 
221  /* Clear all even pin interrupt flags */
222  GPIO_IntClear(0x5555);
223 }
volatile bool BTN_triggered
Definition: interrupt.c:79
volatile bool PULSE1_triggered
Definition: interrupt.c:81
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:78

◆ GPIO_ODD_IRQHandler()

void GPIO_ODD_IRQHandler ( void  )

GPIO Odd IRQ for odd-numbered pins.

Note
The weak definition for this method is located in system_efm32hg.h.

Definition at line 233 of file interrupt.c.

234 {
235  /* Read interrupt flags */
236  uint32_t flags = GPIO_IntGet();
237 
238  /* Check if P1 (PULSE0) is triggered */
239  if (flags == 0x2000) PULSE0_triggered = true;
240 
241  /* Clear all odd pin interrupt flags */
242  GPIO_IntClear(0xAAAA);
243 }
volatile bool PULSE0_triggered
Definition: interrupt.c:80
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:78

◆ initGPIOwakeup()

void initGPIOwakeup ( void  )

Initialize GPIO wake-up functionality.

Initialize falling-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 inputs (external pull-up-resistors), the last argument enables the filter */
98  GPIO_PinModeSet(BTN_PORT, BTN_PIN, gpioModeInput, 1);
99  GPIO_PinModeSet(PULSE0_PORT, PULSE0_PIN, gpioModeInput, 1);
100  GPIO_PinModeSet(PULSE1_PORT, PULSE1_PIN, gpioModeInput, 1);
101 
102  /* Clear all odd pin interrupt flags (just in case)
103  * NVIC_ClearPendingIRQ(GPIO_ODD_IRQn); would also work but is less "readable" */
104  GPIO_IntClear(0xAAAA);
105 
106  /* Clear all even pin interrupt flags (just in case)
107  * NVIC_ClearPendingIRQ(GPIO_EVEN_IRQn); would also work but is less "readable" */
108  GPIO_IntClear(0x5555);
109 
110  /* All pending interrupts can be cleared with GPIO_IntClear(0xFFFF); */
111 
112  /* Enable IRQ for even numbered GPIO pins */
113  NVIC_EnableIRQ(GPIO_EVEN_IRQn);
114 
115  /* Enable IRQ for odd numbered GPIO pins */
116  NVIC_EnableIRQ(GPIO_ODD_IRQn);
117 
118  /* Enable falling-edge interrupts */
119  GPIO_ExtIntConfig(BTN_PORT, BTN_PIN, BTN_PIN, false, true, true);
120  GPIO_ExtIntConfig(PULSE0_PORT, PULSE0_PIN, PULSE0_PIN, false, true, true);
121  GPIO_ExtIntConfig(PULSE1_PORT, PULSE1_PIN, PULSE1_PIN, false, true, true);
122 
123 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
124  dbinfo("GPIO wake-up initialized");
125 #endif /* DEBUG_DBPRINT */
126 
127 }
#define BTN_PIN
Definition: pin_mapping.h:62
#define PULSE1_PIN
Definition: pin_mapping.h:112
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:505
#define PULSE0_PORT
Definition: pin_mapping.h:109
#define PULSE1_PORT
Definition: pin_mapping.h:111
#define BTN_PORT
Definition: pin_mapping.h:61
#define PULSE0_PIN
Definition: pin_mapping.h:110

◆ PULSE_getTriggered()

bool PULSE_getTriggered ( uint8_t  number)

Getter for the PULSE0/1_triggered variable.

Parameters
[in]number
  • 0 - PULSE0 selected.
  • 1 - PULSE1 selected.
Returns
The value of PULSE0/1_triggered.

Definition at line 167 of file interrupt.c.

168 {
169  if (number == 0) return (PULSE0_triggered);
170  else if (number == 1) return (PULSE1_triggered);
171 
172  return (false);
173 }
volatile bool PULSE0_triggered
Definition: interrupt.c:80
volatile bool PULSE1_triggered
Definition: interrupt.c:81

◆ PULSE_setTriggered()

void PULSE_setTriggered ( uint8_t  number,
bool  value 
)

Setter for the PULSE0/1_triggered variable.

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

Definition at line 187 of file interrupt.c.

188 {
189  if (number == 0) PULSE0_triggered = value;
190  else if (number == 1) PULSE1_triggered = value;
191 }
volatile bool PULSE0_triggered
Definition: interrupt.c:80
volatile bool PULSE1_triggered
Definition: interrupt.c:81

Variable Documentation

◆ BTN_triggered

volatile bool BTN_triggered = false

Definition at line 79 of file interrupt.c.

◆ PULSE0_triggered

volatile bool PULSE0_triggered = false

Definition at line 80 of file interrupt.c.

◆ PULSE1_triggered

volatile bool PULSE1_triggered = false

Definition at line 81 of file interrupt.c.