Uart part of arduino wrapper done

This commit is contained in:
Sebastian 2016-11-21 12:48:29 +01:00
parent d79ddb8ee7
commit 8d5fc18076
4 changed files with 109 additions and 1 deletions

View File

@ -0,0 +1,4 @@
-I../sss7core
-I/usr/avr/include
-D__AVR_ATmega2560__
-DF_CPU=16000000

View File

@ -0,0 +1,71 @@
#include "ardusss7.h"
#include <avr/io.h>
#include <avr/interrupt.h>
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

View File

@ -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

View File

@ -1,7 +1,7 @@
#ifndef _SSS7_H_
#define _SSS7_H_
#include "stdint.h"
#include <stdint.h>
enum sss7State {
SSS7_IDLE,