Rev 322 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 322 | Rev 350 | ||
|---|---|---|---|
| 1 | /** |
1 | /** |
| 2 | * CanIRreceive |
2 | * CanIRreceive |
| 3 | * Receives IR data and sends packages to CAN |
3 | * Receives IR data and sends packages to CAN |
| 4 | * |
4 | * |
| 5 | * @date 2006-11-21 |
5 | * @date 2006-11-21 |
| 6 | * @author Jimmy Myhrman, Anders Runeson |
6 | * @author Jimmy Myhrman, Anders Runeson |
| 7 | * Converted to BIOS version by Erik Larsson 2007-02-12 |
7 | * Converted to BIOS version by Erik Larsson 2007-02-12 |
| 8 | * |
8 | * |
| 9 | */ |
9 | */ |
| 10 | 10 | ||
| 11 | /*----------------------------------------------------------------------------- |
11 | /*----------------------------------------------------------------------------- |
| 12 | * Includes |
12 | * Includes |
| 13 | *---------------------------------------------------------------------------*/ |
13 | *---------------------------------------------------------------------------*/ |
| 14 | /* system files */ |
14 | /* system files */ |
| 15 | #include <avr/io.h> |
15 | #include <avr/io.h> |
| 16 | #include <avr/interrupt.h> |
16 | #include <avr/interrupt.h> |
| 17 | #include <stdio.h> |
17 | #include <stdio.h> |
| 18 | /* lib files */ |
18 | /* lib files */ |
| 19 | #include <bios.h> |
19 | #include <bios.h> |
| 20 | #include <irreceiver.h> |
20 | #include <irreceiver.h> |
| 21 | #include < |
21 | #include <funcdefs.h> |
| 22 | 22 | ||
| 23 | #define STATE_IDLE 0 |
23 | #define STATE_IDLE 0 |
| 24 | #define STATE_IR_REPEAT 1 |
24 | #define STATE_IR_REPEAT 1 |
| 25 | 25 | ||
| 26 | /*----------------------------------------------------------------------------- |
26 | /*----------------------------------------------------------------------------- |
| 27 | * Main Program |
27 | * Main Program |
| 28 | *---------------------------------------------------------------------------*/ |
28 | *---------------------------------------------------------------------------*/ |
| 29 | int main(void) { |
29 | int main(void) { |
| 30 | 30 | ||
| 31 | sei(); |
31 | sei(); |
| 32 | 32 | ||
| 33 | IRDDR &= ~(1<<IRBIT); |
33 | IRDDR &= ~(1<<IRBIT); |
| 34 | 34 | ||
| 35 | uint32_t timeStamp = 0; |
35 | uint32_t timeStamp = 0; |
| 36 | uint32_t irTimeoutTimeStamp = 0; |
36 | uint32_t irTimeoutTimeStamp = 0; |
| 37 | 37 | ||
| 38 | Can_Message_t txMsg; |
38 | Can_Message_t txMsg; |
| 39 | Can_Message_t rxMsg; |
39 | Can_Message_t rxMsg; |
| 40 | txMsg.Id = (CLASS_SNS << CLASS_MASK_BITS)|(SNS_IR_RECEIVE << TYPE_MASK_BITS)|(NODE_ID); |
40 | txMsg.Id = (CLASS_SNS << CLASS_MASK_BITS)|(SNS_IR_RECEIVE << TYPE_MASK_BITS)|(NODE_ID); |
| 41 | 41 | ||
| 42 | uint8_t ir_protocol, ir_address, ir_command; |
42 | uint8_t ir_protocol, ir_address, ir_command; |
| 43 | uint8_t state = STATE_IDLE; |
43 | uint8_t state = STATE_IDLE; |
| 44 | 44 | ||
| 45 | /* main loop */ |
45 | /* main loop */ |
| 46 | while (1) { |
46 | while (1) { |
| 47 | if (state == STATE_IDLE) { |
47 | if (state == STATE_IDLE) { |
| 48 | if (checkIr(&ir_protocol, &ir_address, &ir_command) == IR_OK) { |
48 | if (checkIr(&ir_protocol, &ir_address, &ir_command) == IR_OK) { |
| 49 | txMsg.Data.bytes[0] = 0x00; |
49 | txMsg.Data.bytes[0] = 0x00; |
| 50 | txMsg.Data.bytes[1] = ir_protocol; |
50 | txMsg.Data.bytes[1] = ir_protocol; |
| 51 | txMsg.Data.bytes[2] = ir_address; |
51 | txMsg.Data.bytes[2] = ir_address; |
| 52 | txMsg.Data.bytes[3] = ir_command; |
52 | txMsg.Data.bytes[3] = ir_command; |
| 53 | txMsg.DataLength = 4; |
53 | txMsg.DataLength = 4; |
| 54 | bios->can_send(&txMsg); |
54 | bios->can_send(&txMsg); |
| 55 | irTimeoutTimeStamp = bios->timebase_get(); |
55 | irTimeoutTimeStamp = bios->timebase_get(); |
| 56 | state = STATE_IR_REPEAT; |
56 | state = STATE_IR_REPEAT; |
| 57 | } |
57 | } |
| 58 | } else if (state == STATE_IR_REPEAT) { |
58 | } else if (state == STATE_IR_REPEAT) { |
| 59 | //kolla efter ny ir, om ingen ny ir och timeout så sätt state till IDLE |
59 | //kolla efter ny ir, om ingen ny ir och timeout så sätt state till IDLE |
| 60 | if (bios->timebase_get() - irTimeoutTimeStamp >= 105) { //getLastProtoTimeout() |
60 | if (bios->timebase_get() - irTimeoutTimeStamp >= 105) { //getLastProtoTimeout() |
| 61 | state = STATE_IDLE; |
61 | state = STATE_IDLE; |
| 62 | txMsg.Data.bytes[0] = 0x0f; |
62 | txMsg.Data.bytes[0] = 0x0f; |
| 63 | bios->can_send(&txMsg); |
63 | bios->can_send(&txMsg); |
| 64 | } |
64 | } |
| 65 | if (checkIrIdle() == IR_OK) { //funktion som borde finnas i irreceiver.c |
65 | if (checkIrIdle() == IR_OK) { //funktion som borde finnas i irreceiver.c |
| 66 | irTimeoutTimeStamp = bios->timebase_get(); |
66 | irTimeoutTimeStamp = bios->timebase_get(); |
| 67 | } |
67 | } |
| 68 | } |
68 | } |
| 69 | } |
69 | } |
| 70 | 70 | ||
| 71 | return 0; |
71 | return 0; |
| 72 | } |
72 | } |
| 73 | 73 | ||