Subversion Repositories HomeAutomation

Rev

Rev 1483 | Rev 1487 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1483 Rev 1484
Line 8... Line 8...
8
    uint16_t            *rxbuf;
8
    uint16_t            *rxbuf;
9
    uint8_t             rxlen;
9
    uint8_t             rxlen;
10
    uint8_t             timerNum;
10
    uint8_t             timerNum;
11
    Ir_Protocol_Data_t  proto;
11
    Ir_Protocol_Data_t  proto;
12
} irRxChannel[sns_irTransceive_SUPPORTED_NUM_CHANNELS];
12
} irRxChannel[sns_irTransceive_SUPPORTED_NUM_CHANNELS];
-
 
13
#endif
-
 
14
 
-
 
15
#if IR_TX_ENABLE==1
-
 
16
struct {
-
 
17
    uint8_t             state;
-
 
18
    uint8_t             sendComplete;
-
 
19
    uint16_t            *txbuf;
-
 
20
    uint8_t             txlen;
-
 
21
    uint8_t             timerNum;
-
 
22
    Ir_Protocol_Data_t  proto;
-
 
23
} irTxChannel[sns_irTransceive_SUPPORTED_NUM_CHANNELS];
13
#endif
24
#endif
14
 
25
 
15
uint16_t    buf0[MAX_NR_TIMES];
26
uint16_t    buf0[MAX_NR_TIMES];
16
uint16_t    buf1[MAX_NR_TIMES];
27
uint16_t    buf1[MAX_NR_TIMES];
17
uint16_t    buf2[MAX_NR_TIMES];
28
//uint16_t  buf2[MAX_NR_TIMES];
18
 
-
 
19
 
29
 
20
StdCan_Msg_t        irTxMsg;
30
StdCan_Msg_t        irTxMsg;
21
 
31
 
22
#if (sns_irTransceive_SEND_DEBUG==1)
32
#if (sns_irTransceive_SEND_DEBUG==1)
23
void send_debug(uint16_t *buffer, uint8_t len) {
33
void send_debug(uint16_t *buffer, uint8_t len) {
Line 73... Line 83...
73
}
83
}
74
#endif
84
#endif
75
 
85
 
76
void sns_irTransceive_TX_done_callback(uint8_t channel)
86
void sns_irTransceive_TX_done_callback(uint8_t channel)
77
{
87
{
-
 
88
    if (channel < sns_irTransceive_SUPPORTED_NUM_CHANNELS)
-
 
89
    {
-
 
90
        irTxChannel[channel].sendComplete == TRUE;
78
 
91
    }
79
}
92
}
80
 
93
 
81
void sns_irTransceive_Init(void)
94
void sns_irTransceive_Init(void)
82
{
95
{
83
gpio_set_out(EXP_A);
96
gpio_set_out(EXP_A);
Line 98... Line 111...
98
        irRxChannel[i].proto.timeout=0;
111
        irRxChannel[i].proto.timeout=0;
99
        irRxChannel[i].proto.data=0;
112
        irRxChannel[i].proto.data=0;
100
        irRxChannel[i].proto.repeats=0;
113
        irRxChannel[i].proto.repeats=0;
101
        irRxChannel[i].proto.protocol=0;
114
        irRxChannel[i].proto.protocol=0;
102
#endif
115
#endif
-
 
116
 
-
 
117
#if IR_TX_ENABLE==1
-
 
118
        irTxChannel[i].state = sns_irTransceive_STATE_IDLE;
-
 
119
        irTxChannel[i].sendComplete = FALSE;
-
 
120
        irTxChannel[i].txlen = 0;
-
 
121
        irTxChannel[i].proto.timeout=0;
-
 
122
        irTxChannel[i].proto.data=0;
-
 
123
        irTxChannel[i].proto.repeats=0;
-
 
124
        irTxChannel[i].proto.protocol=0;
-
 
125
#endif
103
    }
126
    }
104
   
127
   
105
#if IR_RX_ENABLE==1
128
#if IR_RX_ENABLE==1
106
    irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER;
129
    irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER;
107
    irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER;
130
    irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER;
108
    irRxChannel[2].timerNum=sns_irTransceive_RX2_REPEATE_TIMER;
131
    irRxChannel[2].timerNum=sns_irTransceive_RX2_REPEATE_TIMER;
-
 
132
#endif
-
 
133
 
-
 
134
#if IR_TX_ENABLE==1
-
 
135
    irTxChannel[0].timerNum=sns_irTransceive_TX0_REPEATE_TIMER;
-
 
136
    irTxChannel[1].timerNum=sns_irTransceive_TX1_REPEATE_TIMER;
-
 
137
    irTxChannel[2].timerNum=sns_irTransceive_TX2_REPEATE_TIMER;
109
#endif
138
#endif
110
   
139
   
111
    IrTransceiver_Init();
140
    IrTransceiver_Init();
112
 
141
 
113
#if IR_RX_ENABLE==1
142
#if IR_RX_ENABLE==1
114
    irRxChannel[0].rxbuf = buf0;
143
    irRxChannel[0].rxbuf = buf0;
115
    IrTransceiver_InitRxChannel(0, irRxChannel[0].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
144
    IrTransceiver_InitRxChannel(0, irRxChannel[0].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
116
#endif
145
#endif
117
 
146
 
118
#if IR_TX_ENABLE==1
147
#if IR_TX_ENABLE==1
119
    IrTransceiver_InitTxChannel(0, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
148
    IrTransceiver_InitTxChannel(0, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
120
#endif
149
#endif
121
 
150
 
122
}
151
}
123
 
152
 
124
void sns_irTransceive_Process(void)
153
void sns_irTransceive_Process(void)
125
{
154
{
126
    uint8_t res;
-
 
127
   
-
 
128
    for (uint8_t channel=0; channel < sns_irTransceive_SUPPORTED_NUM_CHANNELS; channel++)
155
    for (uint8_t channel=0; channel < sns_irTransceive_SUPPORTED_NUM_CHANNELS; channel++)
129
    {
156
    {
130
//gpio_toggle_pin(EXP_A);
157
//gpio_toggle_pin(EXP_A);
131
 
158
 
132
#if IR_RX_ENABLE==1
159
#if IR_RX_ENABLE==1
Line 164... Line 191...
164
                    irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
191
                    irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
165
 
192
 
166
                    StdCan_Put(&irTxMsg);
193
                    StdCan_Put(&irTxMsg);
167
                }
194
                }
168
                else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN)
195
                else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN)
169
                {
196
                {
170
#if (sns_irTransceive_SEND_DEBUG==1)
197
#if (sns_irTransceive_SEND_DEBUG==1)
171
                    send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen);
198
                    send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen);
172
                    irRxChannel[channel].proto.timeout=300;
199
                    irRxChannel[channel].proto.timeout=300;
173
#endif
200
#endif
174
                }
201
                }
Line 216... Line 243...
216
            irRxChannel[channel].state = sns_irTransceive_STATE_IDLE;
243
            irRxChannel[channel].state = sns_irTransceive_STATE_IDLE;
217
            break;
244
            break;
218
        }
245
        }
219
#endif
246
#endif
220
 
247
 
-
 
248
#if IR_TX_ENABLE==1
-
 
249
        switch (irTxChannel[channel].state)
-
 
250
        {
-
 
251
        case sns_irTransceive_STATE_IDLE:
-
 
252
            break;
-
 
253
 
-
 
254
        case sns_irTransceive_STATE_START_TRANSMIT:
-
 
255
            if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK)
-
 
256
            {
-
 
257
                IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, irTxChannel[channel].txlen);
-
 
258
                irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING;
-
 
259
            }
-
 
260
            else
-
 
261
            {
-
 
262
                irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
-
 
263
            }
-
 
264
            break;
-
 
265
       
-
 
266
        case sns_irTransceive_STATE_TRANSMITTING:
-
 
267
            if (irTxChannel[channel].sendComplete == TRUE)
-
 
268
            {
-
 
269
                cli();
-
 
270
                irTxChannel[channel].sendComplete = FALSE;
-
 
271
                sei();
-
 
272
                irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
-
 
273
            }
-
 
274
            break;
-
 
275
 
-
 
276
        case sns_irTransceive_STATE_START_PAUSE:
-
 
277
            break;
-
 
278
 
-
 
279
        case sns_irTransceive_STATE_PAUSING:
-
 
280
            break;
-
 
281
 
-
 
282
        case sns_irTransceive_STATE_START_IDLE:
-
 
283
       
-
 
284
            irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
-
 
285
            break;
-
 
286
        }
-
 
287
#endif
221
 
288
 
222
    }
289
    }
223
}
290
}
224
 
291
 
225
void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
292
void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)