diff --git a/slave/slave/lib/loopTimer.c b/slave/slave/lib/loopTimer.c new file mode 100644 --- /dev/null +++ b/slave/slave/lib/loopTimer.c @@ -0,0 +1,50 @@ +/* + * looptimer.c + * + * Created: 11/29/2012 3:35:18 PM + * Author: kripperger + */ + + +#include "../config.h" +#include +#include +#include +#include "loopTimer.h" + +volatile uint32_t millis = 0; // Milliseconds since initialization + + + +void time_setup() +{ + DDRA = 0xff; + + // Generic microcontroller config options + OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler + + TCCR0A |= (1 << WGM01) | (1 << WGM00); // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well) + TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64 + TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts + TIMSK0 |= (1 << TOIE0); // enable overflow interrupt +} + + +ISR(TIMER0_OVF_vect) +{ + millis = millis + 1; +} + +uint32_t time_millis() +{ + return millis; // meh accuracy, but that's OK +} + + + + + + + + + diff --git a/slave/slave/lib/loopTimer.h b/slave/slave/lib/loopTimer.h new file mode 100644 --- /dev/null +++ b/slave/slave/lib/loopTimer.h @@ -0,0 +1,19 @@ +/* + * loopTimer.h + * + * Created: 11/29/2012 3:35:34 PM + * Author: kripperger + */ + + +#ifndef LOOPTIMER_H_ +#define LOOPTIMER_H_ + + +void time_setup(); + +uint32_t time_millis(); + + + +#endif /* LOOPTIMER_H_ */ \ No newline at end of file diff --git a/slave/slave/lib/serial.c b/slave/slave/lib/serial.c new file mode 100644 --- /dev/null +++ b/slave/slave/lib/serial.c @@ -0,0 +1,85 @@ +/* + * serial.c + * + * Created: 10/25/2012 3:19:49 PM + * Author: ethanzonca + */ + +#include "serial.h" +#include "../config.h" +#include + + +void serial0_setup() { + /* Set baud rate */ + UBRR0H = (unsigned char)(USART0_BAUD_PRESCALE>>8); + UBRR0L = (unsigned char)USART0_BAUD_PRESCALE; + /* Enable receiver and transmitter */ + UCSR0B = (1<>8); + UBRR1L = (unsigned char)USART1_BAUD_PRESCALE; + /* Enable receiver and transmitter */ + UCSR1B = (1< + +#define USART0_BAUD_PRESCALE (((F_CPU / (USART0_BAUDRATE * 16UL))) -1 ) +#define USART1_BAUD_PRESCALE (((F_CPU / (USART1_BAUDRATE * 16UL))) -1 ) + +void serial0_sendChar( unsigned char byte ); +void serial1_sendChar( unsigned char byte ); + +void serial0_setup(); +void serial1_setup(); + +void serial0_sendString(char* stringPtr); +void serial1_sendString(char* stringPtr); + +void serial_sendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data ); +void serial_sendResponseData(); + + +#endif /* SERIAL_H_ */ \ No newline at end of file diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -47,7 +47,7 @@ int main(void) serial0_setup(); // Config serial port uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch - //moduleID=1; //DEBUG/////////////////////////////////////////////////////////////////////////////////////////// + moduleID=1; //DEBUG/////////////////////////////////////////////////////////////////////////////////////////// modules_setup(moduleID); // Run setup functions for specific module diff --git a/slave/slave/slave.cproj b/slave/slave/slave.cproj --- a/slave/slave/slave.cproj +++ b/slave/slave/slave.cproj @@ -144,6 +144,12 @@ compile + + compile + + + compile + compile