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

Utility functionality. More...

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

Go to the source code of this file.

Macros

#define ERROR_FORWARDING   1
 

Functions

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

Detailed Description

Utility functionality.

Version
4.0
Author
Brecht Van Eeckhoudt

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.h.

Macro Definition Documentation

◆ ERROR_FORWARDING

#define ERROR_FORWARDING   1

Public definition to enable/disable the logic to send certain error call values (everything except 30 - 50) to the cloud using LoRaWAN.

  • 0 - Keep the MCU in a while(true) loop if the error method is called while flashing the LED and displaying a UART message.
  • 1 - Display a UART message when the error method is called but also forward the number to the cloud using LoRaWAN. Don't go in a while(true) loop.

Definition at line 49 of file util.h.

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