Subversion Repositories HomeAutomation

Rev

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

Rev 1465 Rev 1467
Line 13... Line 13...
13
#include <config.h>
13
#include <config.h>
14
#include <drivers/ir/transceiver/irtransceiverMulti.h>
14
#include <drivers/ir/transceiver/irtransceiverMulti.h>
15
#include <drivers/ir/protocols.h>
15
#include <drivers/ir/protocols.h>
16
#include <avr/io.h>
16
#include <avr/io.h>
17
#include <avr/interrupt.h>
17
#include <avr/interrupt.h>
-
 
18
#include <drivers/mcu/pcint.h>
18
 
19
 
19
/*-----------------------------------------------------------------------------
20
/*-----------------------------------------------------------------------------
20
 * Globals
21
 * Globals
21
 *---------------------------------------------------------------------------*/
22
 *---------------------------------------------------------------------------*/
22
#if IR_RX_ENABLE==1
23
#if IR_RX_ENABLE==1
23
uint16_t *rxbuf;
24
uint16_t *rxbuf;
24
uint8_t rxlen;
25
uint8_t rxlen;
-
 
26
 
-
 
27
/*struct {
-
 
28
    uint8_t     dataReceived;
-
 
29
    uint16_t    timeout;
-
 
30
    uint8_t     timeoutEnable;
-
 
31
    uint16_t    *rxbuf;
-
 
32
    uint8_t     rxlen;
-
 
33
    uint8_t     storeEnable;
-
 
34
} irRxChannel[3];
-
 
35
*/
-
 
36
 
25
#endif
37
#endif
26
#if IR_TX_ENABLE==1
38
#if IR_TX_ENABLE==1
27
uint16_t *txbuf;
39
uint16_t *txbuf;
28
uint8_t txlen;
40
uint8_t txlen;
29
#endif
41
#endif
Line 33... Line 45...
33
#endif
45
#endif
34
volatile uint8_t data_received;
46
volatile uint8_t data_received;
35
volatile uint8_t data_transmitted;
47
volatile uint8_t data_transmitted;
36
//uint8_t detect_edge;
48
//uint8_t detect_edge;
37
uint8_t store;
49
uint8_t store;
38
uint8_t gPinB;
-
 
39
uint8_t gPinC;
-
 
40
uint8_t gPinD;
-
 
41
 
50
 
42
 
51
 
43
/*-----------------------------------------------------------------------------
52
/*-----------------------------------------------------------------------------
44
 * Prerequisites
53
 * Prerequisites
45
 *---------------------------------------------------------------------------*/
54
 *---------------------------------------------------------------------------*/
Line 104... Line 113...
104
//TODO: how to handle more than one transmitter on one compare interrupt, spara en array med tider och nån enableflagga för varje kanal
113
//TODO: how to handle more than one transmitter on one compare interrupt, spara en array med tider och nån enableflagga för varje kanal
105
*/
114
*/
106
 
115
 
107
#if IR_TX_ENABLE==1
116
#if IR_TX_ENABLE==1
108
ISR(IR_COMPARE_VECTOR)
117
ISR(IR_COMPARE_VECTOR)
109
{
118
{
110
    if ((bufIndex&1) == 1) {        /* if odd, ir-pause */
119
    if ((bufIndex&1) == 1) {        /* if odd, ir-pause */
111
        IR_OUTP_LOW();
120
        IR_OUTP_LOW();
112
    } else {
121
    } else {
113
        IR_OUTP_HIGH();
122
        IR_OUTP_HIGH();
114
    }
123
    }
Line 151... Line 160...
151
    }
160
    }
152
    store = 0;
161
    store = 0;
153
}
162
}
154
#endif
163
#endif
155
 
164
 
156
#if IR_RX_ENABLE==1
165
#if 0
157
 
166
 
158
//ISR(IR_CAPTURE_VECTOR)
167
//ISR(IR_CAPTURE_VECTOR)
159
//TODO: skriv denna för multi receiver
168
//TODO: skriv denna för multi receiver
160
ISR(PCINT0_vect) {
169
ISR(PCINT0_vect) {
161
//  uint8_t p;
170
//  uint8_t p;
Line 179... Line 188...
179
/*-----------------------------------------------------------------------------
188
/*-----------------------------------------------------------------------------
180
 * Private Functions
189
 * Private Functions
181
 *---------------------------------------------------------------------------*/
190
 *---------------------------------------------------------------------------*/
182
 
191
 
183
#if IR_RX_ENABLE==1
192
#if IR_RX_ENABLE==1
-
 
193
void IrTransceiver_Store_ch0(uint8_t id, uint8_t status)
-
 
194
{
-
 
195
    IrTransceiver_Store(0);
-
 
196
}
-
 
197
void IrTransceiver_Store_ch1(uint8_t id, uint8_t status)
-
 
198
{
-
 
199
    IrTransceiver_Store(1);
-
 
200
}
-
 
201
void IrTransceiver_Store_ch2(uint8_t id, uint8_t status)
-
 
202
{
-
 
203
    IrTransceiver_Store(2);
-
 
204
}
-
 
205
 
184
void IrTransceiver_Store(uint8_t channel)
206
void IrTransceiver_Store(uint8_t channel)
185
{
207
{
186
    static uint16_t prev_time;
208
    static uint16_t prev_time;
187
    uint16_t pulsewidth;
209
    uint16_t pulsewidth;
188
 
210
 
189
    /* Read the measured transition time from the capture register. */
211
    /* Read the measured transition time from the capture register. */
190
    //uint16_t time = IR_CAPTURE_REG;
212
    //uint16_t time = IR_CAPTURE_REG;
191
    /* Read the timer counter register to get the current "time". */
213
    /* Read the timer counter register to get the current "time". */
192
    uint16_t time = IR_COUNT_REG;
214
    uint16_t time = IR_COUNT_REG;
193
   
-
 
194
    /* Toggle the edge detection. */
-
 
195
//  if (detect_edge == 0)
-
 
196
//  {
-
 
197
//      IR_CAPTURE_RISING();
-
 
198
//      detect_edge = 1;
-
 
199
//  }
-
 
200
//  else
-
 
201
//  {
-
 
202
//      IR_CAPTURE_FALLING();
-
 
203
//      detect_edge = 0;
-
 
204
//  }
-
 
205
   
215
       
206
    /* Subtract the current measurement from the previous to get the pulse
216
    /* Subtract the current measurement from the previous to get the pulse
207
     * width. */
217
     * width. */
208
    pulsewidth = time - prev_time;
218
    pulsewidth = time - prev_time;
209
    prev_time = time;
219
    prev_time = time;
Line 220... Line 230...
220
        //TODO: What to do in multi recevier?
230
        //TODO: What to do in multi recevier?
221
        //TODO: Report overflow to application
231
        //TODO: Report overflow to application
222
        if (rxlen == MAX_NR_TIMES)
232
        if (rxlen == MAX_NR_TIMES)
223
        {
233
        {
224
            //IR_MASK_CAPTURE();
234
            //IR_MASK_CAPTURE();
225
        }
235
        }
226
    }
236
    }
227
    else
237
    else
228
    {
238
    {
229
        /* The first edge of the pulse train has been detected. Enable the
239
        /* The first edge of the pulse train has been detected. Enable the
230
         * storage of the following pulsewidths. */
240
         * storage of the following pulsewidths. */
231
        store = 1;
241
        store = 1;
232
        /* Enable timeout interrupt for detection of the end of the pulse
242
        /* Enable timeout interrupt for detection of the end of the pulse
233
         * train. */
243
         * train. */
234
        IR_UNMASK_TIMEOUT();
244
        IR_UNMASK_TIMEOUT();
-
 
245
 
-
 
246
        //TODO: if buffer resource coordinator is implemented this is where a buffer should be assinged to this channel
235
    }
247
    }
236
}
248
}
237
#endif
249
#endif
238
 
250
 
239
 
251
 
240
/*-----------------------------------------------------------------------------
252
/*-----------------------------------------------------------------------------
241
 * Public Functions
253
 * Public Functions
242
 *---------------------------------------------------------------------------*/
254
 *---------------------------------------------------------------------------*/
243
 
255
 
244
/* call this function like this:
256
/* call this function like this:
245
    IrTransceiver_Init_TX_Channel(0, buffer, callback, GPIO_D6);
257
    IrTransceiver_Init_TX_Channel(0, buffer, callback, pcint-id, GPIO_D6);
246
    buffer is a memory location
258
    buffer is a memory location
247
    callback is a function to call when a receive/transmitt is complete
259
    callback is a function to call when a receive/transmitt is complete
248
    also call with IO port to use
260
    also call with IO port to use
249
   
261
   
250
    function to deactivate channel may later be needed
262
    function to deactivate channel may later be needed
251
*/
263
*/
252
/*
264
 
253
void IrTransceiver_Init_TX_Channel(uint8_t channel, uint16_t *buffer, irCallback_t callback, volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint)
265
void IrTransceiver_Init_TX_Channel(uint8_t channel, uint16_t *buffer, irCallback_t callback, uint8_t pcint_id, volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint)
-
 
266
{
-
 
267
    if (channel == 0)
-
 
268
    {
-
 
269
        Pcint_SetCallback(uint8_t pcint_id, uint8_t pcint, &IrTransceiver_Store_ch0);
-
 
270
    }
-
 
271
    else if (channel == 1)
-
 
272
    {
-
 
273
        Pcint_SetCallback(uint8_t pcint_id, uint8_t pcint, &IrTransceiver_Store_ch1);
-
 
274
    }
-
 
275
    else if (channel == 2)
254
{
276
    {
-
 
277
        Pcint_SetCallback(uint8_t pcint_id, uint8_t pcint, &IrTransceiver_Store_ch2);
255
   
278
    }
256
}
279
}
257
 
280
 
-
 
281
/*
258
void IrTransceiver_Init_RX_Channel(uint8_t channel, uint16_t *buffer, irCallback_t callback, volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint)
282
void IrTransceiver_Init_RX_Channel(uint8_t channel, uint16_t *buffer, irCallback_t callback, volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint)
259
{
283
{
260
   
284
   
261
}
285
}
262
*/
286
*/