Rev 980 | Rev 1909 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 980 | Rev 1205 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | #include <bios.h> |
4 | #include <bios.h> |
| 5 | #define Can_Send BIOS_CanSend |
5 | #define Can_Send BIOS_CanSend |
| 6 | #else |
6 | #else |
| 7 | #include <drivers/can/mcp2515/mcp2515.h> |
7 | #include <drivers/can/mcp2515/mcp2515.h> |
| 8 | #endif |
8 | #endif |
| - | 9 | ||
| - | 10 | #include <avr/interrupt.h> |
|
| 9 | 11 | ||
| 10 | #if (STDCAN_TX_QUEUE_SIZE > 1) |
12 | #if (STDCAN_TX_QUEUE_SIZE > 1) |
| 11 | #error StdCan: Tx queue size longer than one msg not yet implemented. |
13 | #error StdCan: Tx queue size longer than one msg not yet implemented. |
| 12 | #endif |
14 | #endif |
| 13 | 15 | ||
| Line 57... | Line 59... | ||
| 57 | /* Try to match each filter in turn. */ |
59 | /* Try to match each filter in turn. */ |
| 58 | for (n = 0; n < STDCAN_NUM_FILTERS; n++) { |
60 | for (n = 0; n < STDCAN_NUM_FILTERS; n++) { |
| 59 | if (RxFilters[n].Active && !((msg->Id ^ RxFilters[n].Id) & RxFilters[n].Mask)) { |
61 | if (RxFilters[n].Active && !((msg->Id ^ RxFilters[n].Id) & RxFilters[n].Mask)) { |
| 60 | RxQ[RxQ_Wr_idx].Match = n; |
62 | RxQ[RxQ_Wr_idx].Match = n; |
| 61 | break; |
63 | break; |
| 62 | } |
64 | } |
| 63 | } |
65 | } |
| 64 | 66 | ||
| 65 | if (n == STDCAN_NUM_FILTERS) return; // No match found, discard message. |
67 | if (n == STDCAN_NUM_FILTERS) return; // No match found, discard message. |
| 66 | #endif |
68 | #endif |
| 67 | /* Copy the message from lower layer into the queue. */ |
69 | /* Copy the message from lower layer into the queue. */ |
| 68 | RxQ[RxQ_Wr_idx].Id = msg->Id; |
70 | RxQ[RxQ_Wr_idx].Id = msg->Id; |
| Line 146... | Line 148... | ||
| 146 | } |
148 | } |
| 147 | 149 | ||
| 148 | StdCan_Ret_t StdCan_Get(StdCan_Msg_t* msg) |
150 | StdCan_Ret_t StdCan_Get(StdCan_Msg_t* msg) |
| 149 | { |
151 | { |
| 150 | unsigned char n; |
152 | unsigned char n; |
| 151 | 153 | cli(); |
|
| 152 | /* Check if there's a message waiting. */ |
154 | /* Check if there's a message waiting. */ |
| 153 | if (RxQ_Len) { |
155 | if (RxQ_Len) { |
| 154 | 156 | ||
| 155 | /* Copy message to user buffer. */ |
157 | /* Copy message to user buffer. */ |
| 156 | msg->Id = RxQ[RxQ_Rd_idx].Id; |
158 | msg->Id = RxQ[RxQ_Rd_idx].Id; |
| Line 162... | Line 164... | ||
| 162 | 164 | ||
| 163 | /* Increment read index and decrease queue length. */ |
165 | /* Increment read index and decrease queue length. */ |
| 164 | if (++RxQ_Rd_idx >= STDCAN_RX_QUEUE_SIZE) RxQ_Rd_idx = 0; |
166 | if (++RxQ_Rd_idx >= STDCAN_RX_QUEUE_SIZE) RxQ_Rd_idx = 0; |
| 165 | RxQ_Len--; |
167 | RxQ_Len--; |
| 166 | 168 | ||
| - | 169 | sei(); |
|
| 167 | return StdCan_Ret_OK; |
170 | return StdCan_Ret_OK; |
| 168 | } else { |
171 | } else { |
| 169 | /* Queue is empty. */ |
172 | /* Queue is empty. */ |
| - | 173 | sei(); |
|
| 170 | return StdCan_Ret_Empty; |
174 | return StdCan_Ret_Empty; |
| 171 | } |
175 | } |
| 172 | } |
176 | } |
| 173 | 177 | ||
| 174 | unsigned char StdCan_Get_Pending(void) |
178 | unsigned char StdCan_Get_Pending(void) |