diff --git a/software/Arduino/.clang_complete b/software/Arduino/.clang_complete new file mode 100644 index 0000000..be23e0c --- /dev/null +++ b/software/Arduino/.clang_complete @@ -0,0 +1,4 @@ +-I../sss7core +-I/usr/avr/include +-D__AVR_ATmega2560__ +-DF_CPU=16000000 diff --git a/software/Arduino/ardusss7.cpp b/software/Arduino/ardusss7.cpp new file mode 100644 index 0000000..cd13535 --- /dev/null +++ b/software/Arduino/ardusss7.cpp @@ -0,0 +1,71 @@ +#include "ardusss7.h" + +#include +#include + +SSS7Wrapper SSS7; + +SSS7Wrapper::SSS7Wrapper() { + sss7_init(); + + this->setupUart(); + this->setupTimer(); +} + +uint8_t SSS7Wrapper::canSend() { + return sss7_can_send(); +} + +void SSS7Wrapper::send(uint8_t msg[SSS7_PAYLOAD_SIZE]) { + return sss7_send(msg); +} + +uint8_t SSS7Wrapper::sendFailed() { + return sss7_send_failed(); +} +uint8_t SSS7Wrapper::hasReceived() { + return sss7_has_received(); +} + +void SSS7Wrapper::getReceived(uint8_t msg[SSS7_PAYLOAD_SIZE]) { + sss7_get_received(msg); +} + + +void SSS7Wrapper::setupUart() { + UBRR1H = UBRR_VAL >> 8; // Setting baudrate + UBRR1L = UBRR_VAL & 0xFF; + + UCSR1B = (1 << TXEN1) | (1 << RXEN1); // Enable TX and RX + UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); // Asynchronous 8N1 + + // flush UDR + do + { + UDR1; + } + while (UCSR1A & (1 << RXC1)); + + // reset tx and rx complete flags + UCSR1A = (1 << RXC1) | (1 << TXC1); + + UCSR1B |= (1 << TXCIE1) | (1 << RXCIE1); // enable tx and rx interrupts +} + +void uart_put_byte(uint8_t byte) { + UDR1 = byte; +} + +uint8_t uart_get_byte() { + return UDR1; +} + +ISR(USART_RXC1_vect) { + sss7_process_rx(); +} + +ISR(USART_TXC1_vect) { + sss7_process_tx(); +} + +//TODO: Setup Timer diff --git a/software/Arduino/ardusss7.h b/software/Arduino/ardusss7.h new file mode 100644 index 0000000..404e6e0 --- /dev/null +++ b/software/Arduino/ardusss7.h @@ -0,0 +1,33 @@ +#ifndef _ARDUSSS7_H_ +#define _ARDUSSS7_H_ + +#include "sss7.h" + +class SSS7Wrapper { + public: + SSS7Wrapper(); + uint8_t canSend(); + void send(uint8_t msg[SSS7_PAYLOAD_SIZE]); + uint8_t sendFailed(); + uint8_t hasReceived(); + void getReceived(uint8_t msg[SSS7_PAYLOAD_SIZE]); + + private: + void setupUart(); + void setupTimer(); +} + +extern SSS7Wrapper SSS7; + +#define BAUD 9600UL + +// Some calculations ... +#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) // Rounding magic +#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) // Real baudrate +#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD) // Error in 0.1% + +#if ((BAUD_ERROR<950) || (BAUD_ERROR>1050)) // Make sure our UBRR_VAL will work + #error Baudrate error is bigger then 1% ! +#endif + +#endif diff --git a/software/sss7core/sss7.h b/software/sss7core/sss7.h index 7e82f8e..f92e33b 100644 --- a/software/sss7core/sss7.h +++ b/software/sss7core/sss7.h @@ -1,7 +1,7 @@ #ifndef _SSS7_H_ #define _SSS7_H_ -#include "stdint.h" +#include enum sss7State { SSS7_IDLE,