Embedded System Design 2 - Project
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 led (bool enabled)
 Enable or disable the LED. More...
 
void error (uint8_t number)
 Error method. More...
 

Detailed Description

Utility 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 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 131 of file util.c.

132 {
133  /* Initialize LED if not already the case */
134  if (!LED_initialized) initLED();
135 
136  /* Save the given number in the global variable */
137  errorNumber = number;
138 
139 #if ERROR_FORWARDING == 0 /* ERROR_FORWARDING */
140 
141 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
142  dbprint_color(">>> Error (", 5);
143  dbprintInt(number);
144  dbprintln_color(")! Please reset MCU. <<<", 5);
145 #endif /* DEBUG_DBPRINT */
146 
147  while (1)
148  {
149  delay(100);
150  GPIO_PinOutToggle(LED_PORT, LED_PIN); /* Toggle LED */
151  }
152 
153 #else /* ERROR_FORWARDING */
154 
155  /* Check if the error number isn't called in LoRaWAN functionality */
156  if ((number < 30) || (number > 55))
157  {
158 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
159  dbprint_color(">>> Error (", 5);
160  dbprintInt(number);
161  dbprintln_color(")! Sending the message to the cloud. <<<", 5);
162 #endif /* DEBUG_DBPRINT */
163 
164  initLoRaWAN(); /* Initialize LoRaWAN functionality */
165 
166  sendStatus(number); /* Send the status value */
167 
168  disableLoRaWAN(); /* Disable RN2483 */
169  }
170  else
171  {
172 
173 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
174  dbprint_color(">>> Error in LoRaWAN functionality (", 5);
175  dbprintInt(number);
176  dbprintln_color(")! <<<", 5);
177 #endif /* DEBUG_DBPRINT */
178 
179  }
180 
181 #endif /* ERROR_FORWARDING */
182 
183 }
void disableLoRaWAN(void)
Disable LoRaWAN functionality.
void initLoRaWAN(void)
Initialize LoRaWAN functionality.
Definition: lora_wrappers.c:92
#define LED_PORT
Definition: pin_mapping.h:85
void sendStatus(uint8_t status)
Send a packet to indicate a status.
bool LED_initialized
Definition: util.c:85
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124
#define LED_PIN
Definition: pin_mapping.h:86
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
Definition: dbprint.c:738
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:480
uint8_t errorNumber
Definition: util.c:84
static void initLED(void)
Initialize the LED.
Definition: util.c:194
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.
Definition: dbprint.c:421

◆ led()

void led ( bool  enabled)

Enable or disable the LED.

This method also initializes the pin-mode if necessary.

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

Definition at line 103 of file util.c.

104 {
105  /* Initialize LED if not already the case */
106  if (!LED_initialized) initLED();
107 
108  /* Set the selected state */
109  if (enabled) GPIO_PinOutSet(LED_PORT, LED_PIN);
110  else GPIO_PinOutClear(LED_PORT, LED_PIN);
111 }
#define LED_PORT
Definition: pin_mapping.h:85
bool LED_initialized
Definition: util.c:85
#define LED_PIN
Definition: pin_mapping.h:86
static void initLED(void)
Initialize the LED.
Definition: util.c:194