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

Utility functionality. More...

#include <stdint.h>
#include <stdbool.h>
#include "em_cmu.h"
#include "em_gpio.h"
#include "util.h"
#include "pin_mapping.h"
#include "debug_dbprint.h"
#include "delay.h"

Go to the source code of this file.

Functions

static void initGNDd (void)
 Initialize the initGNDd pin. More...
 
void gndd (bool enabled)
 Enable or disable the GNDd pin. More...
 
void error (uint8_t number)
 Error method. More...
 

Variables

uint8_t errorNumber = 0
 
bool GNDd_initialized = false
 

Detailed Description

Utility functionality.

Version
4.0
Author
Brecht Van Eeckhoudt

Versions

  • v1.0: Started with the code from https://github.com/Fescron/Project-LabEmbeddedDesign1/tree/master/code/SLSTK3400A_ADXL362
  • v1.1: Changed PinModeSet DOUT value to 0 in initLED.
  • v1.2: Removed unnecessary GPIO_PinOutClear line in initLED.
  • v1.3: Moved initRTCcomp method from main.c to here, added delay functionality which goes into EM1 or EM2.
  • v1.4: Moved delay functionality to specific header and source files.
  • v2.0: Changed Error() to error(), added a global variable to keep the error number and initialize the pin of the LED automatically.
  • v2.1: Changed initLED to be a static (~hidden) method and also made the global variables static.
  • v2.2: Added peripheral clock enable/disable functionality for energy saving purposes, only added necessary includes in header file, moved the others to the source file, updated documentation, replaced SysTick delay with RTCC delay, changed error delay length.
  • v2.3: Changed name of static variable, simplified some logic.
  • v2.4: Stopped disabling the GPIO clock.
  • v2.5: Moved documentation.
  • v2.6: Updated code with new DEFINE checks.
  • v2.7: Added functionality to send error values using LoRaWAN.
  • v2.8: Added the ability to enable/disable error forwarding to the cloud using a public definition and changed UART error color.
  • v3.0: Updated version number.
  • v3.1: Removed static before the local variables (not necessary).
  • v4.0: Changed functionality for new board type.

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 util.c.

Function Documentation

◆ error()

void error ( uint8_t  number)

Error method.

ERROR_FORWARDING == 0
The method flashes the LED, displays a UART message and holds the MCU forever in a loop until it gets reset. The error value gets stored in a global variable.

ERROR_FORWARDING == 1
The method sends the error value to the cloud using LoRaWAN if the error number doesn't correspond to LoRaWAN-related functionality (numbers 30 - 55).

Parameters
[in]numberThe number to indicate where in the code the error was thrown.

Definition at line 122 of file util.c.

123 {
124  /* Initialize GNDd if not already the case */
125  if (!GNDd_initialized) initGNDd();
126 
127  /* Save the given number in the global variable */
128  errorNumber = number;
129 
130 #if ERROR_FORWARDING == 0 /* ERROR_FORWARDING */
131 
132 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
133  dbprint_color(">>> Error (", 5);
134  dbprintInt(number);
135  dbprintln_color(")! Please reset MCU. <<<", 5);
136 #endif /* DEBUG_DBPRINT */
137 
138  while (1)
139  {
140  /* Nothing here */
141  }
142 
143 #else /* ERROR_FORWARDING */
144 
145  /* Check if the error number isn't called in BG96 functionality */
146  if ((number < 30) || (number > 55))
147  {
148 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
149  dbprint_color(">>> Error (", 5);
150  dbprintInt(number);
151  dbprintln_color(")! Sending the message to the cloud. <<<", 5);
152 #endif /* DEBUG_DBPRINT */
153 
154 // initLoRaWAN(); /* Initialize LoRaWAN functionality */
155 //
156 // sendStatus(number); /* Send the status value */
157 //
158 // disableLoRaWAN(); /* Disable RN2483 */
159  }
160  else
161  {
162 
163 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
164  dbprint_color(">>> Error in BG96 functionality (", 5);
165  dbprintInt(number);
166  dbprintln_color(")! <<<", 5);
167 #endif /* DEBUG_DBPRINT */
168 
169  }
170 
171 #endif /* ERROR_FORWARDING */
172 
173 }
bool GNDd_initialized
Definition: util.c:76
static void initGNDd(void)
Initialize the initGNDd pin.
Definition: util.c:184
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
Definition: dbprint.c:740
void dbprintln_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color and go to the next line.
Definition: dbprint.c:482
uint8_t errorNumber
Definition: util.c:75
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.
Definition: dbprint.c:423

◆ gndd()

void gndd ( bool  enabled)

Enable or disable the GNDd pin.

This method also initializes the pin-mode if necessary.

Parameters
[in]enabled
  • true - Enable GNDd.
  • false - Disable GNDd.

Definition at line 94 of file util.c.

95 {
96  /* Initialize GNDd if not already the case */
97  if (!GNDd_initialized) initGNDd();
98 
99  /* Set the selected state */
100  if (enabled) GPIO_PinOutSet(DBG_GNDD_PORT, DBG_GNDD_PIN);
101  else GPIO_PinOutClear(DBG_GNDD_PORT, DBG_GNDD_PIN);
102 }
bool GNDd_initialized
Definition: util.c:76
static void initGNDd(void)
Initialize the initGNDd pin.
Definition: util.c:184
#define DBG_GNDD_PORT
Definition: pin_mapping.h:95
#define DBG_GNDD_PIN
Definition: pin_mapping.h:96

◆ initGNDd()

static void initGNDd ( void  )
static

Initialize the initGNDd pin.

Note
This is a static method because it's only internally used in this file and called by other methods if necessary.

Definition at line 184 of file util.c.

185 {
186  /* Enable necessary clocks (just in case) */
187  CMU_ClockEnable(cmuClock_HFPER, true); /* GPIO is a High Frequency Peripheral */
188  CMU_ClockEnable(cmuClock_GPIO, true);
189 
190  /* In the case of gpioModePushPull, the last argument directly sets the pin state */
191  GPIO_PinModeSet(DBG_GNDD_PORT, DBG_GNDD_PIN, gpioModePushPull, 0);
192 
193 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
194  dbinfo("GNDd pin initialized");
195 #endif /* DEBUG_DBPRINT */
196 
197  GNDd_initialized = true;
198 }
bool GNDd_initialized
Definition: util.c:76
#define DBG_GNDD_PORT
Definition: pin_mapping.h:95
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:505
#define DBG_GNDD_PIN
Definition: pin_mapping.h:96

Variable Documentation

◆ errorNumber

uint8_t errorNumber = 0

Definition at line 75 of file util.c.

◆ GNDd_initialized

bool GNDd_initialized = false

Definition at line 76 of file util.c.