Files
@ ba937cd712de
Branch filter:
Location: seniordesign-firmware/slave/slave/slave.c
ba937cd712de
3.7 KiB
text/plain
merge
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | /*
* Slave Firmware
*
* Wireless Observational Modular Aerial Network
*
* Kyle Ripperger
* Ethan Zonca
* Matthew Kanning
* Matthew Kroening
*
*/
#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
#include <avr/io.h>
#include <compat/twi.h>
#include <util/delay.h>
#include <avr/cpufunc.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include "modules.h"
#include "lib/serial.h"
#include "lib/serparser.h"
#include "lib/led.h"
#include "lib/inputOutput.h"
#include "lib/i2c.h"
#include "lib/spi.h"
#include "lib/geiger.h"
#include "lib/sensors.h"
#include "lib/cameras.h"
#include "lib/loopTimer.h"
#include "lib/masterComm.h"
#include "lib/watchdog.h"
bool WDTreset = false;
void micro_setup()
{
// Generic microcontroller config options
WDTreset = ((MCUSR & 0b00001000) > 0); // Check if WDT reset occured
MCUSR = 0; // Clear reset flags
wdt_disable(); // Disable WDT
_delay_ms(20); // Power debounce
sei(); // Enable interrupts
}
int main(void)
{
// Initialize
micro_setup(); // Generic microcontroller config options
time_setup(); // Setup loop timer and interrupts (TIMER0)
watchdog_setup(); // Setup watchdog timer
led_configure(); // Configure ports and registers for LED operation
io_configure(); // Configure IO ports and registers
i2c_init(); // Setup I2C
serial0_setup(); // Config serial port 0
serial1_setup(); // Config serial port 1
_delay_ms(50); // Setup hold delay
if(WDTreset) led_on(1); // Turn on LED if WDT reset has occurred
io_readModuleId();
modules_setup(io_getModuleId()); // Run setup functions for specific module
uint32_t lastLoop = 0; // Time in ms when last loop occurred
// Serial output //DEBUG
char buff[128]; //Buffer for serial output //DEBUG
serial1_sendString("Starting Slave\r\n"); //DEBUG
while(1)
{
wdt_reset(); // Resets WDT (to prevent restart)
// Master communication
masterComm_checkParser(); //Checks parser for data requests from master
// Main slave operations
if ((time_millis() - lastLoop) > SENSOR_LOOP) // Uses program timer to run every so often. Time interval defined in config.h
{
led_on(0);
sensors_readBatt(); // Read Battery level
sensors_readBoardTemp(); // Read board temperature sensor (Common on all slaves) (Data Read)
modules_run(io_getModuleId()); // Runs specific module functions (like data reading)
io_regulateTemp(); // Gets board temperature and enables heater if below threshold
snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //DEBUG
serial1_sendString(buff); //DEBUG
led_off(0);
lastLoop = time_millis();
// Writes ID to EEPROM, change for all modules and delete after programming
// 0 is for generic setup, 1 is for sensors, 2 is for Geiger, 3 is for cameras
//i2c_write(EEPROM_ADDR, 0x05, 0x03);
}
}
return 0;
}
/********Examples of data reading and getting******************
x = geiger_getCpm(); //Data get
x = sensors_getSpiTemp(); //Data get
x = sensors_getBoardTemp(); //Data get
sensors_readSpiTemp(); //Data Read
sensors_readBoardTemp(); //Data Read
led_output(0xFF); //Output value to LED array
i2c_write(RTC_ADDR, 0x05, 0x3A); //i2c Write Example
PORTA &= ~(1 << PA1); //OFF
PORTA |= (1 << PA1); //ON
PORTB ^= (1 << PB0); //Toggle
sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
serial0_sendString(buff);
**************************************************************/
|