Rev 1923 | Rev 1931 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1923 | Rev 1927 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | #include "sns_rfTransceive.h" |
2 | #include "sns_rfTransceive.h" |
| 3 | 3 | ||
| 4 | StdCan_Msg_t rfTxMsg; |
4 | StdCan_Msg_t rfTxMsg; |
| 5 | 5 | ||
| - | 6 | #if IR_RX_ENABLE==1 |
|
| 6 | uint8_t rfRxChannel_newData; |
7 | uint8_t rfRxChannel_newData; |
| 7 | uint8_t rfRxChannel_rxlen; |
8 | uint8_t rfRxChannel_rxlen; |
| 8 | uint8_t rfRxChannel_state; |
9 | uint8_t rfRxChannel_state; |
| 9 | Ir_Protocol_Data_t rfRxChannel_proto; |
10 | Ir_Protocol_Data_t rfRxChannel_proto; |
| 10 | uint16_t |
11 | uint16_t rfRxChannel_buf[MAX_NR_TIMES]; |
| 11 | - | ||
| 12 | uint8_t rfTxChannel_sendComplete; |
- | |
| 13 | uint8_t rfTxChannel_state; |
- | |
| 14 | uint8_t rfTxChannel_txlen; |
- | |
| 15 | Ir_Protocol_Data_t rfTxChannel_proto; |
- | |
| 16 | uint16_t rfTxChannel_rxbuf[MAX_NR_TIMES]; |
- | |
| 17 | uint8_t rfTxChannel_repeatCount; |
- | |
| 18 | - | ||
| 19 | 12 | ||
| 20 | #if IR_RX_ENABLE==1 |
- | |
| 21 | void sns_rfTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len) |
13 | void sns_rfTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len) |
| 22 | { |
14 | { |
| 23 | rfRxChannel_newData = TRUE; |
15 | rfRxChannel_newData = TRUE; |
| 24 | rfRxChannel_rxlen = len; |
16 | rfRxChannel_rxlen = len; |
| 25 | } |
17 | } |
| 26 | #endif |
18 | #endif |
| 27 | 19 | ||
| 28 | 20 | ||
| 29 | #if IR_TX_ENABLE==1 |
21 | #if IR_TX_ENABLE==1 |
| - | 22 | uint8_t rfTxChannel_sendComplete; |
|
| - | 23 | uint8_t rfTxChannel_state; |
|
| - | 24 | uint8_t rfTxChannel_txlen; |
|
| - | 25 | Ir_Protocol_Data_t rfTxChannel_proto; |
|
| - | 26 | uint16_t rfTxChannel_buf[MAX_NR_TIMES]; |
|
| - | 27 | uint8_t rfTxChannel_repeatCount; |
|
| - | 28 | uint8_t rfTxChannel_stopSend; |
|
| - | 29 | ||
| 30 | void sns_rfTransceive_TX_done_callback(uint8_t channel) |
30 | void sns_rfTransceive_TX_done_callback(uint8_t channel) |
| 31 | { |
31 | { |
| 32 | rfTxChannel_sendComplete = TRUE; |
32 | rfTxChannel_sendComplete = TRUE; |
| 33 | } |
33 | } |
| 34 | #endif |
34 | #endif |
| Line 39... | Line 39... | ||
| 39 | StdCan_Set_direction(rfTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
39 | StdCan_Set_direction(rfTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 40 | rfTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFTRANSCEIVE; |
40 | rfTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFTRANSCEIVE; |
| 41 | rfTxMsg.Header.ModuleId = sns_rfTransceive_ID; |
41 | rfTxMsg.Header.ModuleId = sns_rfTransceive_ID; |
| 42 | rfTxMsg.Length = 8; |
42 | rfTxMsg.Length = 8; |
| 43 | 43 | ||
| 44 | 44 | #if IR_RX_ENABLE==1 |
|
| 45 | rfRxChannel_newData = FALSE; |
45 | rfRxChannel_newData = FALSE; |
| 46 | rfRxChannel_rxlen = 0; |
46 | rfRxChannel_rxlen = 0; |
| 47 | rfRxChannel_proto.timeout=0; |
47 | rfRxChannel_proto.timeout=0; |
| 48 | rfRxChannel_proto.data=0; |
48 | rfRxChannel_proto.data=0; |
| 49 | rfRxChannel_proto.repeats=0; |
49 | rfRxChannel_proto.repeats=0; |
| 50 | rfRxChannel_proto.protocol=0; |
50 | rfRxChannel_proto.protocol=0; |
| - | 51 | #endif |
|
| 51 | 52 | ||
| - | 53 | #if IR_TX_ENABLE==1 |
|
| 52 | rfTxChannel_sendComplete = FALSE; |
54 | rfTxChannel_sendComplete = FALSE; |
| 53 | rfTxChannel_txlen = 0; |
55 | rfTxChannel_txlen = 0; |
| 54 | rfTxChannel_proto.data=0; |
56 | rfTxChannel_proto.data=0; |
| 55 | rfTxChannel_proto.repeats=0; |
57 | rfTxChannel_proto.repeats=0; |
| 56 | rfTxChannel_proto.framecnt=0; |
58 | rfTxChannel_proto.framecnt=0; |
| 57 | rfTxChannel_proto.protocol=0; |
59 | rfTxChannel_proto.protocol=0; |
| 58 | rfTxChannel_repeatCount = 0; |
60 | rfTxChannel_repeatCount = 0; |
| - | 61 | #endif |
|
| 59 | 62 | ||
| 60 | IrTransceiver_Init(); |
63 | IrTransceiver_Init(); |
| 61 | /* TX-pin must be set in case transmitter is nexa */ |
64 | /* TX-pin must be set in case transmitter is nexa */ |
| 62 | gpio_set_out(sns_rfTransceive_TX_PIN); |
65 | gpio_set_out(sns_rfTransceive_TX_PIN); |
| 63 | #if IR_TX_ACTIVE_LOW==1 |
66 | #if IR_TX_ACTIVE_LOW==1 |
| 64 | gpio_set_pin(sns_rfTransceive_TX_PIN); |
67 | gpio_set_pin(sns_rfTransceive_TX_PIN); |
| 65 | #else |
68 | #else |
| 66 | gpio_clr_pin(sns_rfTransceive_TX_PIN); |
69 | gpio_clr_pin(sns_rfTransceive_TX_PIN); |
| 67 | #endif |
70 | #endif |
| 68 | 71 | ||
| 69 | #if IR_RX_ENABLE==1 |
72 | #if IR_RX_ENABLE==1 |
| 70 | IrTransceiver_InitRxChannel(0, |
73 | IrTransceiver_InitRxChannel(0, rfRxChannel_buf, sns_rfTransceive_RX_done_callback, sns_rfTransceive_RX_PCINT, sns_rfTransceive_RX_PIN); |
| 71 | rfRxChannel_state = sns_rfTransceive_STATE_RECEIVING; |
74 | rfRxChannel_state = sns_rfTransceive_STATE_RECEIVING; |
| 72 | #endif |
75 | #endif |
| 73 | 76 | ||
| 74 | #if IR_TX_ENABLE==1 |
77 | #if IR_TX_ENABLE==1 |
| 75 | IrTransceiver_InitTxChannel(0, sns_rfTransceive_TX_done_callback, sns_rfTransceive_TX_PIN); |
78 | IrTransceiver_InitTxChannel(0, sns_rfTransceive_TX_done_callback, sns_rfTransceive_TX_PIN); |
| 76 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
79 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
| 77 | #endif |
80 | #endif |
| 78 | } |
81 | } |
| 79 | 82 | ||
| 80 | void sns_rfTransceive_Process(void) |
83 | void sns_rfTransceive_Process(void) |
| 81 | { |
84 | { |
| 82 | #if IR_RX_ENABLE==1 |
85 | #if IR_RX_ENABLE==1 |
| 83 | switch (rfRxChannel_state) |
86 | switch (rfRxChannel_state) |
| 84 | { |
87 | { |
| 85 | case sns_rfTransceive_STATE_IDLE: |
88 | case sns_rfTransceive_STATE_IDLE: |
| 86 | { |
89 | { |
| 87 | if ( |
90 | if (rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) { |
| 88 | /* Send button release command on CAN */ |
91 | /* Send button release command on CAN */ |
| 89 | rfTxMsg.Header.Command = CAN_MODULE_CMD_RFTRANSCEIVE_DATASTOP; |
92 | rfTxMsg.Header.Command = CAN_MODULE_CMD_RFTRANSCEIVE_DATASTOP; |
| 90 | rfTxMsg.Data[0] = 0; |
93 | rfTxMsg.Data[0] = 0; |
| 91 | rfTxMsg.Data[1] = rfRxChannel_proto.protocol; |
94 | rfTxMsg.Data[1] = rfRxChannel_proto.protocol; |
| 92 | rfTxMsg.Data[2] = (rfRxChannel_proto.data>>40)&0xff; |
95 | rfTxMsg.Data[2] = (rfRxChannel_proto.data>>40)&0xff; |
| 93 | rfTxMsg.Data[3] = (rfRxChannel_proto.data>>32)&0xff; |
96 | rfTxMsg.Data[3] = (rfRxChannel_proto.data>>32)&0xff; |
| 94 | rfTxMsg.Data[4] = (rfRxChannel_proto.data>>24)&0xff; |
97 | rfTxMsg.Data[4] = (rfRxChannel_proto.data>>24)&0xff; |
| 95 | rfTxMsg.Data[5] = (rfRxChannel_proto.data>>16)&0xff; |
98 | rfTxMsg.Data[5] = (rfRxChannel_proto.data>>16)&0xff; |
| 96 | rfTxMsg.Data[6] = (rfRxChannel_proto.data>>8)&0xff; |
99 | rfTxMsg.Data[6] = (rfRxChannel_proto.data>>8)&0xff; |
| 97 | rfTxMsg.Data[7] = rfRxChannel_proto.data&0xff; |
100 | rfTxMsg.Data[7] = rfRxChannel_proto.data&0xff; |
| 98 | 101 | ||
| 99 | StdCan_Put(&rfTxMsg); |
102 | StdCan_Put(&rfTxMsg); |
| 100 | } |
103 | } |
| 101 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
104 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 102 | break; |
105 | break; |
| 103 | } |
106 | } |
| 104 | 107 | ||
| 105 | case sns_rfTransceive_STATE_START_RECEIVE: |
108 | case sns_rfTransceive_STATE_START_RECEIVE: |
| 106 | cli(); |
109 | cli(); |
| 107 | rfRxChannel_newData = FALSE; |
110 | rfRxChannel_newData = FALSE; |
| Line 115... | Line 118... | ||
| 115 | cli(); |
118 | cli(); |
| 116 | rfRxChannel_newData = FALSE; |
119 | rfRxChannel_newData = FALSE; |
| 117 | sei(); |
120 | sei(); |
| 118 | 121 | ||
| 119 | /* Let protocol driver parse and then send on CAN */ |
122 | /* Let protocol driver parse and then send on CAN */ |
| 120 | uint8_t res2 = parseProtocol( |
123 | uint8_t res2 = parseProtocol(rfRxChannel_buf, rfRxChannel_rxlen, &rfRxChannel_proto); |
| 121 | if (res2 == IR_OK && rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) { |
124 | if (res2 == IR_OK && rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) { |
| 122 | rfTxMsg.Header.Command = CAN_MODULE_CMD_RFTRANSCEIVE_DATASTART; |
125 | rfTxMsg.Header.Command = CAN_MODULE_CMD_RFTRANSCEIVE_DATASTART; |
| 123 | rfTxMsg.Data[0] = 0; |
126 | rfTxMsg.Data[0] = 0; |
| 124 | rfTxMsg.Data[1] = rfRxChannel_proto.protocol; |
127 | rfTxMsg.Data[1] = rfRxChannel_proto.protocol; |
| 125 | rfTxMsg.Data[2] = (rfRxChannel_proto.data>>40)&0xff; |
128 | rfTxMsg.Data[2] = (rfRxChannel_proto.data>>40)&0xff; |
| Line 134... | Line 137... | ||
| 134 | rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
137 | rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
| 135 | } |
138 | } |
| 136 | else if (rfRxChannel_proto.protocol == IR_PROTO_UNKNOWN) |
139 | else if (rfRxChannel_proto.protocol == IR_PROTO_UNKNOWN) |
| 137 | { |
140 | { |
| 138 | #if (sns_rfTransceive_SEND_DEBUG==1) |
141 | #if (sns_rfTransceive_SEND_DEBUG==1) |
| 139 | //send_debug( |
142 | //send_debug(rfRxChannel_buf, rfRxChannel_rxlen); |
| 140 | //rfRxChannel_proto.timeout=300; |
143 | //rfRxChannel_proto.timeout=300; |
| 141 | #endif |
144 | #endif |
| 142 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
145 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 143 | } |
146 | } |
| 144 | } |
147 | } |
| Line 157... | Line 160... | ||
| 157 | IrTransceiver_ResetRx(0); //TODO?? |
160 | IrTransceiver_ResetRx(0); //TODO?? |
| 158 | rfRxChannel_newData = FALSE; |
161 | rfRxChannel_newData = FALSE; |
| 159 | sei(); |
162 | sei(); |
| 160 | 163 | ||
| 161 | Ir_Protocol_Data_t protoDummy; |
164 | Ir_Protocol_Data_t protoDummy; |
| 162 | if (parseProtocol( |
165 | if (parseProtocol(rfRxChannel_buf, rfRxChannel_rxlen, &protoDummy) == IR_OK) { |
| 163 | if (protoDummy.protocol == rfRxChannel_proto.protocol) { |
166 | if (protoDummy.protocol == rfRxChannel_proto.protocol) { |
| 164 | /* re-set timer so we can send release button event when no new RF is arriving */ |
167 | /* re-set timer so we can send release button event when no new RF is arriving */ |
| 165 | Timer_SetTimeout(sns_rfTransceive_RX_REPEATE_TIMER, rfRxChannel_proto.timeout, TimerTypeOneShot, 0); |
168 | Timer_SetTimeout(sns_rfTransceive_RX_REPEATE_TIMER, rfRxChannel_proto.timeout, TimerTypeOneShot, 0); |
| 166 | } |
169 | } |
| 167 | } |
170 | } |
| 168 | } |
171 | } |
| 169 | 172 | ||
| 170 | if (Timer_Expired(sns_rfTransceive_RX_REPEATE_TIMER)) { |
173 | if (Timer_Expired(sns_rfTransceive_RX_REPEATE_TIMER)) { |
| 171 | rfRxChannel_state = sns_rfTransceive_STATE_IDLE; |
174 | rfRxChannel_state = sns_rfTransceive_STATE_IDLE; |
| 172 | } |
175 | } |
| 173 | break; |
176 | break; |
| 174 | 177 | ||
| 175 | default: |
178 | default: |
| 176 | break; |
179 | break; |
| 177 | } |
180 | } |
| 178 | #endif |
181 | #endif |
| 179 | 182 | ||
| 180 | #if 0 |
- | |
| 181 |
|
183 | #if IR_TX_ENABLE==1 |
| 182 | switch ( |
184 | switch (rfTxChannel_state) |
| 183 | { |
185 | { |
| 184 | case |
186 | case sns_rfTransceive_STATE_IDLE: |
| 185 | { |
187 | { |
| 186 | /* transmission is started when a command is received on can */ |
188 | /* transmission is started when a command is received on can */ |
| 187 |
|
189 | rfTxChannel_stopSend = FALSE; |
| 188 |
|
190 | rfTxChannel_repeatCount = 0; |
| 189 |
|
191 | rfTxChannel_proto.framecnt = 0; |
| 190 | irTxChannel[channel].sendingPronto = FALSE; |
- | |
| 191 | break; |
192 | break; |
| 192 | } |
193 | } |
| 193 | 194 | ||
| 194 | case |
195 | case sns_rfTransceive_STATE_START_TRANSMIT: |
| 195 | { |
196 | { |
| 196 | /* Expand protocol. */ |
197 | /* Expand protocol. */ |
| 197 | if (expandProtocol( |
198 | if (expandProtocol(rfTxChannel_buf, &rfTxChannel_txlen, &rfTxChannel_proto) != IR_OK) { |
| 198 | /* Failed to expand protocol -> enter idle state. */ |
199 | /* Failed to expand protocol -> enter idle state. */ |
| 199 |
|
200 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
| 200 | break; |
- | |
| 201 | } |
- | |
| 202 | - | ||
| 203 | /* Start IR transmission. */ |
- | |
| 204 | /* TODO Send respone. Function call may fail when different modulation frequencies are used simultaneously. */ |
- | |
| 205 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen, irTxChannel[channel].proto.modfreq); |
- | |
| 206 | - | ||
| 207 | /* Enter transmitting state. */ |
- | |
| 208 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
- | |
| 209 | break; |
- | |
| 210 | } |
- | |
| 211 | - | ||
| 212 | case sns_irTransceive_STATE_START_TRANSMIT_PRONTO: |
- | |
| 213 | { |
- | |
| 214 | /* Start IR transmission. */ |
- | |
| 215 | if(IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].onceSeqLen - 1, irTxChannel[channel].proto.modfreq) < 0) { |
- | |
| 216 | /* Send error code. */ |
- | |
| 217 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_ABORTED); |
- | |
| 218 | - | ||
| 219 | /* Enter idle state. */ |
- | |
| 220 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
- | |
| 221 | break; |
201 | break; |
| 222 | } |
202 | } |
| - | 203 | ||
| - | 204 | /* Start RF transmission. */ |
|
| - | 205 | IrTransceiver_Transmit(0, rfTxChannel_buf, 0, rfTxChannel_txlen, rfTxChannel_proto.modfreq); |
|
| 223 | 206 | ||
| 224 | /* Enter transmitting state. */ |
207 | /* Enter transmitting state. */ |
| 225 | irTxChannel[channel].sendingPronto = TRUE; |
- | |
| 226 |
|
208 | rfTxChannel_state = sns_rfTransceive_STATE_TRANSMITTING; |
| 227 | break; |
209 | break; |
| 228 | } |
- | |
| 229 | - | ||
| 230 | case sns_irTransceive_STATE_PRONTO_REPEAT: |
- | |
| 231 | { |
- | |
| 232 | /* Check if done. */ |
- | |
| 233 | if ((irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats && irTxChannel[channel].proto.repeats != 0xFF) || irTxChannel[channel].stopSend) { |
- | |
| 234 | /* Pronto transmission was stopped/completed */ |
- | |
| 235 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_STOPPED); |
- | |
| 236 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
- | |
| 237 | break; |
- | |
| 238 | } |
- | |
| 239 | - | ||
| 240 | if (irTxChannel[channel].repeatCount < 255) { |
- | |
| 241 | irTxChannel[channel].repeatCount++; |
- | |
| 242 | } |
- | |
| 243 | - | ||
| 244 | /* Repeat sequence exists? */ |
- | |
| 245 | if (irTxChannel[channel].repSeqLen != 0) { |
- | |
| 246 | /* Use repeat seq */ |
- | |
| 247 | uint16_t offset = ((uint16_t)irTxChannel[channel].onceSeqLen); |
- | |
| 248 | /* Don't transmit last passive. last passive handled by timer */ |
- | |
| 249 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, offset, ((uint16_t)irTxChannel[channel].repSeqLen) - 1, irTxChannel[channel].proto.modfreq); |
- | |
| 250 | } |
- | |
| 251 | else { |
- | |
| 252 | /* Use once seq */ |
- | |
| 253 | /* Don't transmit last passive. last passive handled by timer */ |
- | |
| 254 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen - 1, irTxChannel[channel].proto.modfreq); |
- | |
| 255 | } |
- | |
| 256 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
- | |
| 257 | } |
210 | } |
| 258 | 211 | ||
| 259 | case |
212 | case sns_rfTransceive_STATE_TRANSMITTING: |
| 260 | { |
213 | { |
| 261 | if ( |
214 | if (rfTxChannel_sendComplete == TRUE) |
| 262 | { |
215 | { |
| 263 | cli(); |
216 | cli(); |
| 264 |
|
217 | rfTxChannel_sendComplete = FALSE; |
| 265 | sei(); |
218 | sei(); |
| 266 | 219 | ||
| 267 | if (irTxChannel[channel].sendingPronto) |
- | |
| 268 | { |
- | |
| 269 | /* First repeat, or no repeat sequence defined => use last passive time in once seq */ |
- | |
| 270 | if(irTxChannel[channel].repeatCount == 0 || irTxChannel[channel].repSeqLen == 0) |
- | |
| 271 | { |
- | |
| 272 | /* Use last passive time as timeout */ |
- | |
| 273 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].onceSeqLen - 1] / 1000; |
- | |
| 274 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
- | |
| 275 | } |
- | |
| 276 | /* Second, or later repeat => use last passive time in repeat seq */ |
- | |
| 277 | else |
- | |
| 278 | { |
- | |
| 279 | /* Use last passive time as timeout */ |
- | |
| 280 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] / 1000; |
- | |
| 281 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
- | |
| 282 | } |
- | |
| 283 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
- | |
| 284 | } |
- | |
| 285 | else |
- | |
| 286 | { |
- | |
| 287 |
|
220 | rfTxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
| 288 | } |
- | |
| 289 | } |
221 | } |
| 290 | break; |
222 | break; |
| 291 | } |
223 | } |
| 292 | 224 | ||
| 293 | case |
225 | case sns_rfTransceive_STATE_START_PAUSE: |
| 294 | { |
226 | { |
| 295 | if ( |
227 | if (rfTxChannel_repeatCount < rfTxChannel_proto.repeats) |
| 296 | { |
228 | { |
| 297 |
|
229 | rfTxChannel_repeatCount++; |
| 298 | } |
- | |
| 299 | - | ||
| 300 | Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0); |
- | |
| 301 | - | ||
| 302 | if (irTxChannel[channel].proto.framecnt != 255) |
- | |
| 303 | { |
- | |
| 304 | irTxChannel[channel].proto.framecnt++; |
- | |
| 305 | } |
- | |
| 306 | - | ||
| 307 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
- | |
| 308 | break; |
- | |
| 309 | } |
- | |
| 310 | - | ||
| 311 | case sns_irTransceive_STATE_PAUSING: |
- | |
| 312 | { |
- | |
| 313 | if (irTxChannel[channel].sendingPronto) |
- | |
| 314 | { |
- | |
| 315 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
- | |
| 316 | { |
- | |
| 317 | irTxChannel[channel].state = sns_irTransceive_STATE_PRONTO_REPEAT; |
- | |
| 318 | } |
- | |
| 319 | break; |
- | |
| 320 | } |
230 | } |
| 321 | 231 | ||
| - | 232 | Timer_SetTimeout(sns_rfTransceive_TX_REPEATE_TIMER, rfTxChannel_proto.timeout, TimerTypeOneShot, 0); |
|
| - | 233 | ||
| 322 | if ( |
234 | if (rfTxChannel_proto.framecnt != 255) |
| 323 | { |
235 | { |
| - | 236 | rfTxChannel_proto.framecnt++; |
|
| - | 237 | } |
|
| - | 238 | ||
| - | 239 | rfTxChannel_state = sns_rfTransceive_STATE_PAUSING; |
|
| - | 240 | break; |
|
| - | 241 | } |
|
| - | 242 | ||
| - | 243 | case sns_rfTransceive_STATE_PAUSING: |
|
| - | 244 | { |
|
| - | 245 | if (Timer_Expired(sns_rfTransceive_TX_REPEATE_TIMER)) |
|
| - | 246 | { |
|
| 324 |
|
247 | rfTxChannel_state = sns_rfTransceive_STATE_START_TRANSMIT; |
| 325 | } |
248 | } |
| 326 | 249 | ||
| 327 | /* Transmission is stopped when such command is recevied on can */ |
250 | /* Transmission is stopped when such command is recevied on can */ |
| 328 | if ( |
251 | if (rfTxChannel_stopSend == TRUE && rfTxChannel_repeatCount >= rfTxChannel_proto.repeats) |
| 329 | { |
252 | { |
| 330 | /* Non-pronto transmission was stopped/completed */ |
- | |
| 331 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_STOPPED); |
- | |
| 332 | - | ||
| 333 |
|
253 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
| 334 | } |
254 | } |
| 335 | break; |
255 | break; |
| 336 | } |
256 | } |
| 337 | default: |
257 | default: |
| 338 | break; |
258 | break; |
| 339 | } |
259 | } |
| 340 | #endif |
260 | #endif |
| 341 | } |
261 | } |
| 342 | 262 | ||
| 343 | void sns_rfTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
263 | void sns_rfTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
| 344 | { |
264 | { |
| 345 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS && |
265 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS && |
| 346 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
266 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
| 347 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_RFTRANSCEIVE && |
267 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_RFTRANSCEIVE && |
| 348 | rxMsg->Header.ModuleId == sns_rfTransceive_ID) |
268 | rxMsg->Header.ModuleId == sns_rfTransceive_ID) |
| 349 | { |
269 | { |
| 350 | switch (rxMsg->Header.Command) |
270 | switch (rxMsg->Header.Command) |
| 351 | { |
271 | { |
| 352 | #if IR_TX_ENABLE==1 |
272 | #if IR_TX_ENABLE==1 |
| - | 273 | case CAN_MODULE_CMD_RFTRANSCEIVE_DATABURST: |
|
| - | 274 | { |
|
| - | 275 | if (rfTxChannel_state == sns_rfTransceive_STATE_IDLE) |
|
| - | 276 | { |
|
| - | 277 | rfTxChannel_stopSend = TRUE; |
|
| - | 278 | } |
|
| - | 279 | } /* Fall through, no break */ |
|
| 353 | case CAN_MODULE_CMD_RFTRANSCEIVE_DATASTART: |
280 | case CAN_MODULE_CMD_RFTRANSCEIVE_DATASTART: |
| 354 | { |
281 | { |
| - | 282 | if (rfTxChannel_state == sns_rfTransceive_STATE_IDLE) |
|
| - | 283 | { |
|
| - | 284 | rfTxChannel_proto.protocol = rxMsg->Data[1]; |
|
| - | 285 | rfTxChannel_proto.data = rxMsg->Data[2]; |
|
| - | 286 | rfTxChannel_proto.data = rfTxChannel_proto.data<<8; |
|
| - | 287 | rfTxChannel_proto.data |= rxMsg->Data[3]; |
|
| - | 288 | rfTxChannel_proto.data = rfTxChannel_proto.data<<8; |
|
| - | 289 | rfTxChannel_proto.data |= rxMsg->Data[4]; |
|
| - | 290 | rfTxChannel_proto.data = rfTxChannel_proto.data<<8; |
|
| - | 291 | rfTxChannel_proto.data |= rxMsg->Data[5]; |
|
| - | 292 | rfTxChannel_proto.data = rfTxChannel_proto.data<<8; |
|
| - | 293 | rfTxChannel_proto.data |= rxMsg->Data[6]; |
|
| - | 294 | rfTxChannel_proto.data = rfTxChannel_proto.data<<8; |
|
| - | 295 | rfTxChannel_proto.data |= rxMsg->Data[7]; |
|
| - | 296 | ||
| - | 297 | rfTxChannel_state = sns_rfTransceive_STATE_START_TRANSMIT; |
|
| - | 298 | } |
|
| 355 | } |
299 | } |
| 356 | break; |
300 | break; |
| 357 | case CAN_MODULE_CMD_RFTRANSCEIVE_DATASTOP: |
301 | case CAN_MODULE_CMD_RFTRANSCEIVE_DATASTOP: |
| 358 | { |
302 | { |
| 359 | } |
- | |
| 360 | break; |
- | |
| 361 |
|
303 | rfTxChannel_stopSend = TRUE; |
| 362 | { |
- | |
| 363 | } |
304 | } |
| 364 | break; |
305 | break; |
| 365 | #endif |
306 | #endif |
| 366 | } |
307 | } |
| 367 | } |
308 | } |
| Line 376... | Line 317... | ||
| 376 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFTRANSCEIVE; |
317 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFTRANSCEIVE; |
| 377 | txMsg.Header.ModuleId = sns_rfTransceive_ID; |
318 | txMsg.Header.ModuleId = sns_rfTransceive_ID; |
| 378 | txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST; |
319 | txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST; |
| 379 | txMsg.Length = 6; |
320 | txMsg.Length = 6; |
| 380 | 321 | ||
| - | 322 | uint32_t HwId=BIOS_GetHwId(); |
|
| 381 | txMsg.Data[0] = |
323 | txMsg.Data[0] = HwId&0xff; |
| 382 | txMsg.Data[1] = |
324 | txMsg.Data[1] = (HwId>>8)&0xff; |
| 383 | txMsg.Data[2] = |
325 | txMsg.Data[2] = (HwId>>16)&0xff; |
| 384 | txMsg.Data[3] = |
326 | txMsg.Data[3] = (HwId>>24)&0xff; |
| 385 | 327 | ||
| 386 | txMsg.Data[4] = NUMBER_OF_MODULES; |
328 | txMsg.Data[4] = NUMBER_OF_MODULES; |
| 387 | txMsg.Data[5] = ModuleSequenceNumber; |
329 | txMsg.Data[5] = ModuleSequenceNumber; |
| 388 | 330 | ||
| 389 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |
331 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |