The main file for Project 2 from Embedded System Design 2 - Lab.
- Version
- 5.2
- Author
- Brecht Van Eeckhoudt
Versions
Please check https://github.com/Fescron/Project-LabEmbeddedDesign2/tree/master/software to find the latest version!
- v1.0: Started from https://github.com/Fescron/Project-LabEmbeddedDesign1 and added code for the DS18B20 temperature sensor and the selfmade link breakage sensor. Reformatted some of these imported methods.
- v1.1: Removed unused files, add cable-checking method.
- v1.2: Moved initRTCcomp method to "util.c".
- v1.3: Stopped using deprecated function "GPIO_IntConfig".
- v1.4: Started using get/set method for the static variable "ADXL_triggered".
- v1.5: Reworked the code a lot (stopped disabling cmuClock_GPIO, ...).
- v1.6: Moved all documentation above source files to this file.
- v1.7: Updated documentation, started using a state-machine.
- v1.8: Moved checkCable method to "other.c" and started using readVBAT method.
- v1.9: Cleaned up documentation and TODO's.
- v2.0: Updated code with new DEFINE checks.
- v2.1: Updated code with new ADC functionality.
- v2.2: Started using working temperature sensor code.
- v2.3: Started using working cable checking code and added "SEND"
mcu_state
.
- v2.4: Started using a struct to keep the measurements in, added line to disable the RN2483.
- v2.5: Started using custom enum types for the accelerometer settings.
- v2.6: Added ADXL testing functionality.
- v2.7: Removed USTIMER logic from this file.
- v2.8: Added functionality to detect a storm.
- v2.9: Started adding LoRaWAN functionality, added more wake-up/sleep functionality.
- v3.0: Started using updated LoRaWAN send methods.
- v3.1: Added functionality to enable/disable the LED blinking when measuring/sending data.
- v3.2: Fixed button wake-up when sleeping for WAKE_UP_PERIOD_S/2.
- v3.3: Moved
data.index
reset to LoRaWAN sending functionality and updated documentation.
- v3.4: Moved
data.index
reset back to main.c
.
- v3.5: Added functionality to go back to the remaining sleep time on an accelerometer wake-up.
- v3.6: Updated code to handle underlying changes.
- v4.0: Updated documentation and version number.
- v4.1: Added definitions to easily change the accelerometer's configuration settings.
- v5.0: Updated sleep logic when waking up using the accelerometer.
- v5.1: Added extra ISR handlers.
- v5.2: Removed
static
before a local variable (not necessary).
- Todo:
- Optimalisations:
- Change LoRaWAN Spreading Factor and send power, and check the effect on the power usage.
- Add some time to the
while
increment escape counters?
- Check power usage effect of disabling
PM_SENS_EXT
.
- Check difference between absolute/referenced mode for the accelerometer.
- Change mode to release.
- Todo:
- Future improvements:
- Use IAR toolchain instead of GCC, see section Optimizing code in
documentation.h
- Sleep for some time in while loops instead of just incrementing the escape-counter.
- First separate
ULFRCO
definition in `delay.c
- Try to shorten delays (for example: 40 ms power-up time for the RN2483...)
- Fix
sleepLoRaWAN
and wakeLoRaWAN
functionality (also see lora_wrappers.c
).
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 also 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.
- Attention
- See the file
documentation.h
for a lot of useful documentation about this project!
Errors
If in this project something unexpected occurs, an error
method gets called. What happens in this method can be selected in util.h
with the definition ERROR_FORWARDING
. If it's value is 0
the MCU displays (if dbprint
is enabled) a UART message and gets put in a while(true)
to flash the LED. If it's value is 1
then certain values (all values except 30 - 55 since these are errors in the LoRaWAN functionality itself) get forwarded to the cloud using LoRaWAN functionality and the MCU resumes it's code.
When calling an error
method, the following things were kept in mind:
- Values 0 - 9: Reserved for reset and other critical functionality.
- 1: Send once after a reset (
firstBoot == true
in main.c
)
- 9: Used in
sendTest(data);
method (lora_wrappers.c
)
- Values 10 - ... : Available to use for anything else.
Below is a list of values which correspond to certain functionality:
LoRaWAN sensor channels
LPP_VBAT_CHANNEL 0x10 // 16
LPP_TEMPERATURE_CHANNEL_INT 0x11 // 17
LPP_TEMPERATURE_CHANNEL_EXT 0x12 // 18
LPP_STORM_CHANNEL 0x13 // 19
LPP_CABLE_BROKEN_CHANNEL 0x14 // 20
LPP_STATUS_CHANNEL 0x15 // 21
Definition in file main.c.