Rev 403 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 403 | Rev 439 | ||
|---|---|---|---|
| Line 9... | Line 9... | ||
| 9 | #include <drivers/ir/receiver/irreceiver.h> |
9 | #include <drivers/ir/receiver/irreceiver.h> |
| 10 | 10 | ||
| 11 | #define APP_TYPE 0xf010 |
11 | #define APP_TYPE 0xf010 |
| 12 | #define APP_VERSION 0x0001 |
12 | #define APP_VERSION 0x0001 |
| 13 | 13 | ||
| 14 | #define CAN_IR 0x12 |
14 | #define CAN_IR 0x12 |
| 15 | 15 | ||
| 16 | #define STATE_IDLE 0 |
16 | #define STATE_IDLE 0 |
| 17 | #define STATE_IR_REPEAT 1 |
17 | #define STATE_IR_REPEAT 1 |
| - | 18 | ||
| 18 | 19 | ||
| 19 | // A simple message "queue", with space for one message only. |
20 | // A simple message "queue", with space for one message only. |
| 20 | // These are declared volatile to tell the compiler not to optimize away accesses. |
21 | // These are declared volatile to tell the compiler not to optimize away accesses. |
| 21 | volatile Can_Message_t rxMsg; // Message storage |
22 | volatile Can_Message_t rxMsg; // Message storage |
| 22 | volatile uint8_t rxMsgFull; // Synchronization flag |
23 | volatile uint8_t rxMsgFull; // Synchronization flag |
| Line 32... | Line 33... | ||
| 32 | 33 | ||
| 33 | int main(void) |
34 | int main(void) |
| 34 | { |
35 | { |
| 35 | // Enable interrupts as early as possible |
36 | // Enable interrupts as early as possible |
| 36 | sei(); |
37 | sei(); |
| 37 | 38 | ||
| 38 | Timebase_Init(); |
39 | Timebase_Init(); |
| 39 | //Serial_Init(); |
40 | //Serial_Init(); |
| 40 | 41 | ||
| 41 | Can_Message_t txMsg; |
42 | Can_Message_t txMsg; |
| 42 | txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID); |
43 | txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID); |
| Line 48... | Line 49... | ||
| 48 | 49 | ||
| 49 | // Set up callback for CAN reception, this is optional if only sending is required. |
50 | // Set up callback for CAN reception, this is optional if only sending is required. |
| 50 | BIOS_CanCallback = &can_receive; |
51 | BIOS_CanCallback = &can_receive; |
| 51 | // Send CAN_NMT_APP_START |
52 | // Send CAN_NMT_APP_START |
| 52 | BIOS_CanSend(&txMsg); |
53 | BIOS_CanSend(&txMsg); |
| - | 54 | ||
| - | 55 | txMsg.Id = CAN_ID_SNS_IRDATA; // ((CAN_SNS << CAN_SHIFT_CLASS) | (NODE_ID << CAN_SHIFT_SNS_SID)) |
|
| 53 | 56 | ||
| 54 | //printf("AVR Test Application\n"); |
57 | //printf("AVR Test Application\n"); |
| 55 | //printf("Using AVR BIOS version %x\n", BIOS_VERSION); |
58 | //printf("Using AVR BIOS version %x\n", BIOS_VERSION); |
| 56 | 59 | ||
| 57 | txMsg.Id = CAN_ID_SNS_IRDATA; // ((CAN_SNS << CAN_SHIFT_CLASS) | (NODE_ID << CAN_SHIFT_SNS_SID)) |
- | |
| 58 | //txMsg.Id = (CAN_SNS << CAN_SHIFT_CLASS) | ((CAN_IR & CAN_MASK_SNS_FUNCC) << CAN_SHIFT_SNS_FUNCC) | (NODE_ID << CAN_SHIFT_SNS_SID); |
60 | //txMsg.Id = (CAN_SNS << CAN_SHIFT_CLASS) | ((CAN_IR & CAN_MASK_SNS_FUNCC) << CAN_SHIFT_SNS_FUNCC) | (NODE_ID << CAN_SHIFT_SNS_SID); |
| 59 | //txMsg.Data.dwords[0] = 0x01020304; |
61 | //txMsg.Data.dwords[0] = 0x01020304; |
| 60 | //txMsg.DataLength = 4; |
62 | //txMsg.DataLength = 4; |
| 61 | 63 | ||
| 62 | IRDDR &= ~(1<<IRBIT); |
64 | IRDDR &= ~(1<<IRBIT); |
| Line 90... | Line 92... | ||
| 90 | if (checkIrIdle() == IR_OK) { //funktion som borde finnas i irreceiver.c |
92 | if (checkIrIdle() == IR_OK) { //funktion som borde finnas i irreceiver.c |
| 91 | irTimeoutTime = Timebase_CurrentTime(); |
93 | irTimeoutTime = Timebase_CurrentTime(); |
| 92 | } |
94 | } |
| 93 | } |
95 | } |
| 94 | 96 | ||
| 95 | - | ||
| 96 | - | ||
| 97 | /*if ((time - time1) >= 2000) { |
- | |
| 98 | time1 = time; |
- | |
| 99 | // Send a CAN message |
- | |
| 100 | txMsg.Data.dwords[1] = time; |
- | |
| 101 | BIOS_CanSend(&txMsg); |
- | |
| 102 | printf("Two seconds passed, time is now %ld.\n", time); |
- | |
| 103 | }*/ |
- | |
| 104 | 97 | ||
| 105 | if (rxMsgFull) { |
98 | if (rxMsgFull) { |
| 106 | // Flush the received message |
99 | // Flush the received message |
| 107 | rxMsgFull = 0; // |
100 | rxMsgFull = 0; // |
| 108 | } |
101 | } |