Files
@ 104a7b37e488
Branch filter:
Location: seniordesign-firmware/master/master/master.c
104a7b37e488
2.8 KiB
text/plain
Rewrote the serial parser to use a circular buffer and interrupt-based system, which is much more robust. Untested, serial interrupt not firing at the moment.
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 | /*
* Master Firmware
*
* Wireless Observational Modular Aerial Network
*
* Ethan Zonca
* Matthew Kanning
* Kyle Ripperger
* Matthew Kroening
*
*/
#include "config.h"
#include <avr/io.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <stdbool.h>
#include "lib/serial.h"
#include "lib/aprs.h"
#include "lib/afsk.h"
#include "lib/led.h"
#include "lib/logger.h"
#include "lib/watchdog.h"
#include "lib/sd/sd_raw_config.h"
#include "lib/looptime.h"
#include "lib/slavesensors.h"
#include "lib/serparser.h"
void micro_setup()
{
}
int main(void)
{
// Initialize libraries
time_setup();
micro_setup();
watchdog_setup();
led_setup();
serial0_setup();
serial1_setup();
slavesensors_setup();
logger_setup();
afsk_setup();
serial0_sendString("\r\n\r\n---------------------------------\r\n");
serial0_sendString("HAB Controller 1.0 - Initialized!\r\n");
serial0_sendString("---------------------------------\r\n\r\n");
led_on(POWER);
// Buffer for string operations
char logbuf[32];
const char* logBufPtr = logbuf;
// Software timers
uint32_t lastAprsBroadcast = 0;
uint32_t lastLog = 0;
// If we are currently processing sensor data
bool isProcessing = false;
// Result of last parser run
int parseResult = PARSERESULT_NODATA;
bool haveDataToHandle = false;
// Write CSV header to SD card
logger_log("ProgramTime,LastAprsBroadcast,LastLog\n");
while(1)
{
// Periodic: Logging
if(time_millis() - lastLog > LOGGER_RATE)
{
// TODO: Acquire data from daughterboards
// This will be complicated because we need timeouts / unreliable transmission, etc
//
// For each daughterboard...
// 1. Send request to daughterboard for sensor data
// 2. Wait for response from daughterboard (timeout!)
// 3. Put data into local variables for transmission / logging
led_on(STAT);
snprintf(logbuf, 32, "%lu,%lu,%lu,\r\n", time_millis(), lastAprsBroadcast,lastLog);
logger_log(logbuf);
serial0_sendString("SD Logger: ");
serial0_sendString(logBufPtr);
led_off(STAT);
lastLog = time_millis();
}
// Periodic: APRS transmission
if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD)
{
while(afsk_busy());
aprs_send(); // non-blocking
serial0_sendString("Initiating APRS transmission...\r\n");
// Start getting values for next transmission
isProcessing = true;
lastAprsBroadcast = time_millis();
}
parseResult = serparser_parse();
// TODO: If we receive a command, we should still process it even if we aren't isProcessing, right?
// Maybe we should isolate the received command handling ("Execution") and the issuing of requests.
if(isProcessing)
{
isProcessing = slavesensors_process(parseResult);
}
wdt_reset();
}
}
|