Rev 1208 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1208 | Rev 1210 | ||
|---|---|---|---|
| Line 7... | Line 7... | ||
| 7 | #include <drivers/uart/serial.h> |
7 | #include <drivers/uart/serial.h> |
| 8 | #include <drivers/uart/uart.h> |
8 | #include <drivers/uart/uart.h> |
| 9 | #include <drivers/timer/timer.h> |
9 | #include <drivers/timer/timer.h> |
| 10 | #include <drivers/timer/timebase.h> |
10 | #include <drivers/timer/timebase.h> |
| 11 | #include <drivers/can/can.h> |
11 | #include <drivers/can/can.h> |
| - | 12 | #include <drivers/can/mcp2515/mcp2515.h> |
|
| 12 | 13 | ||
| 13 | #define APP_TYPE CAN_APPTYPES_SERIALTRANSCEIVER |
14 | #define APP_TYPE CAN_APPTYPES_SERIALTRANSCEIVER |
| 14 | #define APP_VERSION 0x0001 |
15 | #define APP_VERSION 0x0001 |
| 15 | 16 | ||
| 16 | //Note: Erik Calissendorff, 2009-03-29 |
17 | //Note: Erik Calissendorff, 2009-03-29 |
| Line 77... | Line 78... | ||
| 77 | //Used to allow multiple bytes to be send in the same package |
78 | //Used to allow multiple bytes to be send in the same package |
| 78 | uint32_t time = Timebase_CurrentTime(); |
79 | uint32_t time = Timebase_CurrentTime(); |
| 79 | 80 | ||
| 80 | //Check if we got some data from the serial port |
81 | //Check if we got some data from the serial port |
| 81 | uint8_t got_received_data=0; |
82 | uint8_t got_received_data=0; |
| 82 | 83 | ||
| 83 | while (1) { |
84 | while (1) { |
| 84 | 85 | ||
| 85 | if (rxMsgFull) { |
86 | if (rxMsgFull) { |
| 86 | if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT && ((uint16_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE) == ACT_TYPE_SERIAL)) { |
87 | if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT && ((uint16_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE) == ACT_TYPE_SERIAL)) { |
| 87 | //Unused uint8_t actid = (uint8_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID); |
88 | //Unused uint8_t actid = (uint8_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID); |
| 88 | 89 | ||
| 89 | for(i=0;i<rxMsg.DataLength;i++) |
90 | for(i=0;i<rxMsg.DataLength;i++) |
| 90 | { |
91 | { |
| 91 | uart_putc(rxMsg.Data.bytes[i]); |
92 | uart_putc(rxMsg.Data.bytes[i]); |
| 92 | } |
93 | } |
| 93 | } |
94 | } |
| 94 | 95 | ||
| 95 | // Flush the received message |
96 | // Flush the received message |
| 96 | rxMsgFull = 0; // |
97 | rxMsgFull = 0; // |
| 97 | } |
98 | } |
| 98 | 99 | ||
| 99 | //Receiver |
100 | //Receiver |
| 100 | 101 | ||
| 101 | //Timer for how long we will wait for for more data before sending our packages |
102 | //Timer for how long we will wait for for more data before sending our packages |
| 102 | time = Timebase_CurrentTime(); |
103 | time = Timebase_CurrentTime(); |
| 103 | 104 | ||
| 104 | //We don't like to wait for the time out unless we get some data. |
105 | //We don't like to wait for the time out unless we get some data. |
| 105 | got_received_data=0; |
106 | got_received_data=0; |
| Line 113... | Line 114... | ||
| 113 | //Error handling should be added to inform us of problems with the serial link |
114 | //Error handling should be added to inform us of problems with the serial link |
| 114 | 115 | ||
| 115 | rxBuffer[received_size++]=(uint8_t)(received_data & 0x00ff); |
116 | rxBuffer[received_size++]=(uint8_t)(received_data & 0x00ff); |
| 116 | } |
117 | } |
| 117 | } while(received_size<maxReceiveData && got_received_data==1 && Timebase_CurrentTime()-time < RECEIVE_WAIT_TIME_MS); |
118 | } while(received_size<maxReceiveData && got_received_data==1 && Timebase_CurrentTime()-time < RECEIVE_WAIT_TIME_MS); |
| 118 | 119 | ||
| 119 | if(received_size > 0) |
120 | if(received_size > 0) |
| 120 | { |
121 | { |
| 121 | //TODO: Erik Calissendorff, 2009-03-29 |
122 | //TODO: Erik Calissendorff, 2009-03-29 |
| 122 | //We like to be able to accept more then one CAN package of data at a time |
123 | //We like to be able to accept more then one CAN package of data at a time |
| 123 | 124 | ||
| Line 125... | Line 126... | ||
| 125 | for(i=0;i<received_size;i++) |
126 | for(i=0;i<received_size;i++) |
| 126 | { |
127 | { |
| 127 | txMsg.Data.bytes[i]=rxBuffer[i]; |
128 | txMsg.Data.bytes[i]=rxBuffer[i]; |
| 128 | } |
129 | } |
| 129 | txMsg.DataLength = received_size; |
130 | txMsg.DataLength = received_size; |
| 130 | 131 | ||
| 131 | BIOS_CanSend(&txMsg); |
132 | BIOS_CanSend(&txMsg); |
| 132 | } |
133 | } |
| 133 | //Ensure we are reseting the counter |
134 | //Ensure we are reseting the counter |
| 134 | received_size=0; |
135 | received_size=0; |
| 135 | } |
136 | } |