1 | #include <avr/io.h>
|
2 | #include <stdlib.h>
|
3 | #include "UART.h"
|
4 | #include <util/delay.h>
|
5 | #include "regs.h"
|
6 | #include "spi.h"
|
7 | #include "can2515.h"
|
8 | #include <stdint.h>
|
9 | #include <avr/interrupt.h>
|
10 |
|
11 |
|
12 | int main(){
|
13 |
|
14 | init_USART();
|
15 | sei();
|
16 | sendUSART("Started CAN-UART Gateway!\n\r");
|
17 |
|
18 | DDRC &= ~(1<<PC4);
|
19 | PORTC |= (1<<PC4);
|
20 |
|
21 | init_spi();
|
22 | controller_reset();
|
23 | init_bittiming();
|
24 | init_receiver();
|
25 | controller_normal_mode();
|
26 |
|
27 | modify_register(BFPCTRL, 0b00101010, 0b00101000);
|
28 | while(1==1){
|
29 | if((PINC & (1<<PC4)) == 0){
|
30 | modify_register(BFPCTRL, 0b00101010, 0b00001000);
|
31 | Message *message;
|
32 | handle_interrupt(message);
|
33 | modify_register(BFPCTRL, 0b00101010, 0b00101000);
|
34 | }
|
35 | unsigned int rec = uart_getc();
|
36 | if(rec & UART_NO_DATA){
|
37 | //
|
38 | }else{
|
39 | if(rec & UART_BUFFER_OVERFLOW){
|
40 | sendUSART("Buffer Overflow!\n\r");
|
41 | }else{
|
42 | unsigned char tmp = ((unsigned char)rec);
|
43 | write_message_to_can(0b1, 1, &tmp);
|
44 | uart_putc_buffert(XOFF);
|
45 | uart_putc_buffert((unsigned char)rec);
|
46 | uart_putc_buffert(XON);
|
47 | }
|
48 |
|
49 |
|
50 | }
|
51 |
|
52 |
|
53 | }
|
54 |
|
55 | return 0;
|
56 |
|
57 | }
|