Files
@ cd11bb83de3a
Branch filter:
Location: seniordesign-firmware/slave/slave/slave.c
cd11bb83de3a
2.7 KiB
text/plain
Created functions for operating LEDs and Heater as well as a temperature control structure. Additionally timer loop for main operation was optemized.
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 | /*
* Slave Firmware
*
* Wireless Observational Modular Aerial Network
*
* Kyle Ripperger
* Ethan Zonca
* Matthew Kanning
* Matthew Kroening
*
*/
#include "config.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 "modules.h"
#include "lib/serial.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"
void micro_setup()
{
// Generic microcontroller config options
sei(); // Enable interrupts
}
int main(void)
{
// Initialize
micro_setup(); // Generic microcontroller config options
time_setup(); // Setup loop timer and interrupts (TIMER0)
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
uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch
modules_setup(moduleID); // Run setup functions for specific module
//uint8_t test; //Debug
//uint8_t test2; //Debug
// Serial output //DEBUG
char buff[64]; //Buffer for serial output //DEBUG
serial0_sendString("Starting\r\n");
while(1)
{
if ((time_millis() % SENSOR_LOOP) == 0) // Uses program timer to run every so often. Time interval defined in config.h
{
sensors_readBoardTemp(); // Read board temperature sensor (Common on all slaves) (Data Read)
modules_run(moduleID); // Runs specific module functions (like data reading)
io_regulateTemp(); // Gets board temperature and enables heater if below threshold
snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu\r\n",moduleID,sensors_getBoardTemp(),time_millis()); //DEBUG
serial0_sendString(buff); //DEBUG
led_toggle(0); // Toggle LED0(Blue) to show loop running
}
}
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
sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
serial0_sendString(buff);
**************************************************************/
|