Rev 815 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 815 | Rev 884 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | #include <avr/interrupt.h> |
2 | #include <avr/interrupt.h> |
| 3 | #include <stdio.h> |
3 | #include <stdio.h> |
| 4 | #include <string.h> |
4 | #include <string.h> |
| 5 | #include <config.h> // All configuration parameters |
5 | #include <config.h> // All configuration parameters |
| 6 | #include <bios.h> // BIOS interface declarations, including CAN structure and ID defines. |
6 | #include <bios.h> // BIOS interface declarations, including CAN structure and ID defines. |
| 7 | #include <drivers/ |
7 | #include <drivers/DTMF/dtmf.h> |
| 8 |
|
8 | //#include <drivers/DTMF/mt8870/mt8870.h> |
| - | 9 | #include <drivers/timer/timer.h> |
|
| 9 | 10 | ||
| 10 | #define STATE_IDLE 0 |
11 | #define STATE_IDLE 0 |
| 11 | #define |
12 | #define STATE_COPYDATA 1 |
| 12 | #define STATE_START_WAIT 2 |
- | |
| 13 | #define STATE_WAIT |
13 | #define STATE_WAIT 2 |
| 14 | #define |
14 | #define STATE_SEND 3 |
| 15 | 15 | ||
| 16 | #define APP_TYPE 0xf001 |
16 | #define APP_TYPE 0xf001 |
| 17 | #define APP_VERSION |
17 | #define APP_VERSION 0x0003 |
| 18 | 18 | ||
| 19 | // A simple message "queue", with space for one message only. |
19 | // A simple message "queue", with space for one message only. |
| 20 | // These are declared volatile to tell the compiler not to optimize away accesses. |
20 | // These are declared volatile to tell the compiler not to optimize away accesses. |
| 21 | volatile Can_Message_t rxMsg; // Message storage |
21 | volatile Can_Message_t rxMsg; // Message storage |
| 22 | volatile uint8_t rxMsgFull; // Synchronization flag |
22 | volatile uint8_t rxMsgFull; // Synchronization flag |
| Line 33... | Line 33... | ||
| 33 | int main(void) |
33 | int main(void) |
| 34 | { |
34 | { |
| 35 | // Enable interrupts as early as possible |
35 | // Enable interrupts as early as possible |
| 36 | sei(); |
36 | sei(); |
| 37 | 37 | ||
| - | 38 | Timer_Init(); |
|
| - | 39 | ||
| 38 |
|
40 | DTMFin_Init(); |
| 39 | 41 | ||
| 40 | Can_Message_t txMsg; |
42 | Can_Message_t txMsg; |
| 41 | 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); |
| 42 | txMsg.DataLength = 4; |
44 | txMsg.DataLength = 4; |
| 43 | txMsg.RemoteFlag = 0; |
45 | txMsg.RemoteFlag = 0; |
| Line 48... | Line 50... | ||
| 48 | // 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. |
| 49 | BIOS_CanCallback = &can_receive; |
51 | BIOS_CanCallback = &can_receive; |
| 50 | // Send CAN_NMT_APP_START |
52 | // Send CAN_NMT_APP_START |
| 51 | BIOS_CanSend(&txMsg); |
53 | BIOS_CanSend(&txMsg); |
| 52 | 54 | ||
| 53 | DTMFin_Init(); |
- | |
| 54 | - | ||
| 55 | uint8_t rxbuffer[MAX_TONES]; |
- | |
| 56 | uint8_t state=0; |
- | |
| 57 | uint8_t rxlen=0; |
- | |
| 58 | 55 | ||
| - | 56 | uint8_t pollrxbuffer[MT_MAX_TONES]; |
|
| - | 57 | uint8_t pollrxlen=0; |
|
| - | 58 | uint8_t rxbuffer[MT_MAX_TONES]; |
|
| 59 |
|
59 | uint8_t rxlen=0; |
| - | 60 | uint8_t state=STATE_IDLE; |
|
| 60 | 61 | ||
| - | 62 | while (1) { |
|
| 61 | if (state == STATE_IDLE) { |
63 | if (state == STATE_IDLE) { |
| 62 |
|
64 | if (DTMFin_Pop(pollrxbuffer, &pollrxlen) == DTMF_Ret_Data_avail) { |
| 63 | state = |
65 | state = STATE_COPYDATA; |
| - | 66 | } else { |
|
| - | 67 | //go into sleep or something, incoming data from mt8870 is interrupted so we will wake up |
|
| - | 68 | } |
|
| 64 | } else if (state == |
69 | } else if (state == STATE_COPYDATA) { |
| 65 | state = STATE_WAIT; |
70 | state = STATE_WAIT; |
| - | 71 | for (uint8_t i=0; i<pollrxlen;i++) { |
|
| - | 72 | rxbuffer[rxlen++] = pollrxbuffer[i]; |
|
| - | 73 | if (rxlen >= MT_MAX_TONES) { |
|
| - | 74 | //overflow |
|
| - | 75 | rxlen = 0; |
|
| - | 76 | state = STATE_IDLE; |
|
| - | 77 | break; |
|
| - | 78 | } |
|
| - | 79 | } |
|
| - | 80 | Timer_SetTimeout(0, MT_DIAL_TIMEOUT, TimerTypeOneShot, 0); |
|
| 66 | } else if (state == STATE_WAIT) { |
81 | } else if (state == STATE_WAIT) { |
| - | 82 | if (Timer_Expired(0)) { |
|
| - | 83 | state = STATE_SEND; |
|
| - | 84 | } |
|
| - | 85 | ||
| 67 |
|
86 | DTMF_Ret_t retval = DTMFin_Pop(pollrxbuffer, &pollrxlen); |
| 68 | if (retval == |
87 | if (retval == DTMF_Ret_Data_avail) { |
| 69 | state = |
88 | state = STATE_COPYDATA; |
| 70 | } else if (retval == |
89 | } else if (retval == DTMF_Ret_Overflow) { |
| - | 90 | rxlen=0; |
|
| 71 | state = STATE_IDLE; |
91 | state = STATE_IDLE; |
| 72 | } |
92 | } |
| 73 | } else if (state == |
93 | } else if (state == STATE_SEND) { |
| 74 | //if ((rxbuffer[0] == 0xa || rxbuffer[0] == 0xb) && rxbuffer[rxlen-1] == 0xc) { |
94 | //if ((rxbuffer[0] == 0xa || rxbuffer[0] == 0xb) && rxbuffer[rxlen-1] == 0xc) { |
| 75 | for (uint8_t i = 0; i < 16; i=i+2) { |
95 | for (uint8_t i = 0; i < 16; i=i+2) { |
| 76 | txMsg.Data.bytes[i>>1] = rxbuffer[i]<<4; |
96 | txMsg.Data.bytes[i>>1] = rxbuffer[i]<<4; |
| 77 | if (i+1 < rxlen) { |
97 | if (i+1 < rxlen) { |
| 78 | txMsg.Data.bytes[i>>1] |= rxbuffer[i+1]; |
98 | txMsg.Data.bytes[i>>1] |= rxbuffer[i+1]; |
| Line 81... | Line 101... | ||
| 81 | txMsg.DataLength = (rxlen>>1)+(rxlen&1); |
101 | txMsg.DataLength = (rxlen>>1)+(rxlen&1); |
| 82 | txMsg.Id = ((CAN_SNS << CAN_SHIFT_CLASS) | (SNS_TYPE_PHONENR << CAN_SHIFT_SNS_TYPE) | (0<<CAN_SHIFT_SNS_ID) | (NODE_ID << CAN_SHIFT_SNS_SID)); |
102 | txMsg.Id = ((CAN_SNS << CAN_SHIFT_CLASS) | (SNS_TYPE_PHONENR << CAN_SHIFT_SNS_TYPE) | (0<<CAN_SHIFT_SNS_ID) | (NODE_ID << CAN_SHIFT_SNS_SID)); |
| 83 | BIOS_CanSend(&txMsg); |
103 | BIOS_CanSend(&txMsg); |
| 84 | 104 | ||
| 85 | //} |
105 | //} |
| - | 106 | rxlen = 0; |
|
| 86 | state = STATE_IDLE; |
107 | state = STATE_IDLE; |
| 87 | } |
108 | } |
| 88 | } |
109 | } |
| 89 | 110 | ||
| 90 | return 0; |
111 | return 0; |