diff --git a/newcode/fifo.c b/newcode/fifo.c deleted file mode 100644 index d637a41..0000000 --- a/newcode/fifo.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "fifo.h" - -uint8_t fifo_push(Fifo_t * fifo, uint8_t byte) -{ - //if (fifo.write >= FIFO_SIZE) - // fifo.write = 0; // erhöht sicherheit - - - if ( ( fifo->write + 1 == fifo->read ) || - ( fifo->read == 0 && fifo->write + 1 == FIFO_SIZE ) ) - return FIFO_FAIL; // voll - - fifo->data[fifo->write] = byte; - - fifo->write++; - if (fifo->write >= FIFO_SIZE) - fifo->write = 0; - - return FIFO_SUCCESS; -} - -uint8_t fifo_pop(Fifo_t * fifo, uint8_t *pByte) -{ - if (fifo->read == fifo->write){ - return FIFO_FAIL; - } - - *pByte = fifo->data[fifo->read]; - - fifo->read++; - if (fifo->read >= FIFO_SIZE) - fifo->read = 0; - - return FIFO_SUCCESS; -} - -uint8_t fifo_peek(Fifo_t * fifo){ - return fifo->data[fifo->read]; -} diff --git a/newcode/fifo.h b/newcode/fifo.h deleted file mode 100644 index e1ad9d1..0000000 --- a/newcode/fifo.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _FIFO_H_ -#define _FIFO_H_ - -#include - -#define FIFO_FAIL 0 -#define FIFO_SUCCESS 1 - -#define FIFO_SIZE 128 - -typedef struct { - uint8_t data[FIFO_SIZE]; - uint8_t read; // zeigt auf das Feld mit dem ältesten Inhalt - uint8_t write; // zeigt immer auf leeres Feld -} Fifo_t; - -uint8_t fifo_push(Fifo_t * fifo, uint8_t byte); -uint8_t fifo_pop(Fifo_t * fifo, uint8_t *pByte); - -#endif diff --git a/newcode/main.c b/newcode/main.c index ba9c0bd..1def553 100644 --- a/newcode/main.c +++ b/newcode/main.c @@ -14,7 +14,7 @@ #define ADC_0V_COUNT 170 #define ADC_MAX_VOLT 1.95 -volatile uint16_t adc_buffer[AVRG]; +uint16_t adc_buffer[AVRG]; volatile float ch_values[9]; void init_clk(void) @@ -114,7 +114,7 @@ void modbusGet(void) { { switch(rxbuffer[1]) { case fcReadHoldingRegisters: ; - modbusExchangeRegisters(ch_values, 0, 18); + modbusExchangeRegisters((uint16_t*)ch_values, 0, 18); break; default: modbusSendException(ecIllegalFunction); diff --git a/newcode/uart.c b/newcode/uart.c deleted file mode 100644 index 7c49b24..0000000 --- a/newcode/uart.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include "uart.h" -#include "fifo.h" - -Fifo_t uart0_rx_buffer = {{}, 0, 0}; -Fifo_t uart0_tx_buffer = {{}, 0, 0}; - -const uint16_t bsel = 208; -const int8_t bscale = 0; - -//FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); - -void init_uart(void){ - USARTD0_CTRLC= USART_CHSIZE0_bm | USART_CHSIZE1_bm; - //USARTD0_BAUDCTRLB = 0; - //USARTD0_BAUDCTRLA = 0; - USARTD0.BAUDCTRLA = bsel; - USARTD0.BAUDCTRLB = 0 | (bsel >> 8) | (bscale << USART_BSCALE0_bp); - USARTD0_CTRLB = USART_TXEN_bm | USART_RXEN_bm; - - //USARTD0_CTRLA=USART_RXCINTLVL0_bm; - - PORTD_OUTSET = PIN3_bm; - PORTD_DIRSET = PIN3_bm; - PORTD_OUTCLR = PIN2_bm; - PORTD_DIRCLR = PIN2_bm; - - //stdout = &uart_output; -} - -void uart_putchar(char c, FILE *stream) -{ - fifo_push(&uart0_tx_buffer, c); - USARTD0_CTRLA |= USART_DREINTLVL_LO_gc; -} - -//void puts(char * s){ -// while (*s) { -// putchar(*s++); -// } -//} - -char get_uart0_char(void) -{ - while(1){ - char buffer; - - while( !(USARTD0_STATUS & USART_RXCIF_bm) ); - buffer=USARTD0_DATA; - if ((USARTD0_STATUS & (USART_FERR_bm | USART_PERR_bm | USART_BUFOVF_bm))==0) - return buffer; - } -} - -ISR(USARTD0_RXC_vect) -{ - uint8_t tmp = get_uart0_char(); - putchar(tmp); - if(( tmp == 0x0D || tmp == 0x0A)) - printf("wurst\n\r"); - else - fifo_push(&uart0_rx_buffer, tmp); -} - -ISR(USARTD0_DRE_vect){ - uint8_t tmp; - if(fifo_pop(&uart0_tx_buffer, &tmp) == FIFO_SUCCESS){ - USARTD0_DATA = tmp; - } else { - USARTD0_CTRLA &= ~USART_DREINTLVL_LO_gc; - } -} diff --git a/newcode/uart.h b/newcode/uart.h deleted file mode 100644 index 82804f1..0000000 --- a/newcode/uart.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _UART_H_ -#define _UART_H_ - -#include -#include "fifo.h" - -extern Fifo_t uart0_rx_buffer; -extern Fifo_t uart0_tx_buffer; - - -void init_uart(void); -void uart_putchar(char c, FILE *stream); -char get_uart0_char(void); - -#endif