Rev 1558 | Rev 1560 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1558 | Rev 1559 | ||
|---|---|---|---|
| Line 15... | Line 15... | ||
| 15 | #endif |
15 | #endif |
| 16 | 16 | ||
| 17 | // internal variables |
17 | // internal variables |
| 18 | static uint32_t baudRate = 9600; |
18 | static uint32_t baudRate = 9600; |
| 19 | static uint16_t format = CAN_MODULE_ENUM_SERIAL_SERIALCONFIG_PHYSICALFORMAT_LOOPBACK; |
19 | static uint16_t format = CAN_MODULE_ENUM_SERIAL_SERIALCONFIG_PHYSICALFORMAT_LOOPBACK; |
| - | 20 | ||
| - | 21 | // prepare a new message, in case new data is available |
|
| - | 22 | static StdCan_Msg_t msg; |
|
| 20 | 23 | ||
| 21 | #define sns_Serial_DEBUG 0 |
24 | #define sns_Serial_DEBUG 0 |
| 22 | 25 | ||
| 23 | void sns_Serial_Init(void) |
26 | void sns_Serial_Init(void) |
| 24 | { |
27 | { |
| Line 26... | Line 29... | ||
| 26 | if (EEDATA_OK) { |
29 | if (EEDATA_OK) { |
| 27 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >=2)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
30 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >=2)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
| 28 | baudRate = eeprom_read_dword(EEDATA32.baudRate); |
31 | baudRate = eeprom_read_dword(EEDATA32.baudRate); |
| 29 | #else |
32 | #else |
| 30 | #warning This version of AVR-libc does not have support for eeprom read dword |
33 | #warning This version of AVR-libc does not have support for eeprom read dword |
| 31 | #endif |
34 | #endif |
| 32 | format = eeprom_read_word(EEDATA16.format); |
35 | format = eeprom_read_word(EEDATA16.format); |
| 33 | } |
36 | } |
| 34 | else { |
37 | else { |
| 35 | //The CRC of the EEPROM is not correct, store default values and update CRC |
38 | //The CRC of the EEPROM is not correct, store default values and update CRC |
| 36 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >=2)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
39 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >=2)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
| Line 64... | Line 67... | ||
| 64 | // Pcint_SetCallbackPin(sns_Serial_PCINT, EXP_C , &sns_Serial_pcint_callback); |
67 | // Pcint_SetCallbackPin(sns_Serial_PCINT, EXP_C , &sns_Serial_pcint_callback); |
| 65 | 68 | ||
| 66 | #if sns_Serial_DEBUG==1 |
69 | #if sns_Serial_DEBUG==1 |
| 67 | printf("Serial started!\n"); |
70 | printf("Serial started!\n"); |
| 68 | #endif |
71 | #endif |
| - | 72 | ||
| - | 73 | msg.Length = 0; // no data so far |
|
| 69 | } |
74 | } |
| - | 75 | ||
| - | 76 | //unsigned char sData[8]; |
|
| - | 77 | //uint8_t dataCnt=0; |
|
| 70 | 78 | ||
| 71 | void sns_Serial_Process(void) |
79 | void sns_Serial_Process(void) |
| 72 | { |
80 | { |
| 73 | // prepare a new message, in case new data is available |
- | |
| 74 | StdCan_Msg_t msg; |
- | |
| 75 | msg.Length = 0; // no data so far |
- | |
| 76 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
81 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
| 77 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_TO_OWNER); |
82 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_TO_OWNER); |
| 78 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_SERIAL; |
83 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_SERIAL; |
| 79 | msg.Header.ModuleId = sns_Serial_ID; |
84 | msg.Header.ModuleId = sns_Serial_ID; |
| 80 | msg.Header.Command = CAN_MODULE_CMD_SERIAL_SERIALDATA; |
85 | msg.Header.Command = CAN_MODULE_CMD_SERIAL_SERIALDATA; |
| Line 97... | Line 102... | ||
| 97 | printf("RX\n"); |
102 | printf("RX\n"); |
| 98 | #endif |
103 | #endif |
| 99 | // insert it into the message |
104 | // insert it into the message |
| 100 | msg.Data[(uint8_t)msg.Length] = c; |
105 | msg.Data[(uint8_t)msg.Length] = c; |
| 101 | msg.Length++; |
106 | msg.Length++; |
| - | 107 | ||
| - | 108 | Timer_SetTimeout(sns_Serial_FORCE_SEND_TIMER, sns_Serial_FORCE_SEND_TIME_MS , TimerTypeOneShot, 0); |
|
| 102 | } |
109 | } |
| 103 | // keep going until max data length reached, or until uart RXBUF is empty |
110 | // keep going until max data length reached, or until uart RXBUF is empty |
| 104 | } while (status == 0 && msg.Length < 8); |
111 | } while (status == 0 && msg.Length < 8); |
| 105 | 112 | ||
| 106 | // |
113 | // check if force send or send-frame full |
| 107 | if (msg.Length |
114 | if (Timer_Expired(sns_Serial_FORCE_SEND_TIMER) || msg.Length == 8) |
| 108 | { |
115 | { |
| 109 | // transmit this chunk of data (max 8 chars) |
116 | // transmit this chunk of data (max 8 chars) |
| 110 | while(StdCan_Put(&msg) != StdCan_Ret_OK); |
117 | while(StdCan_Put(&msg) != StdCan_Ret_OK); |
| - | 118 | msg.Length = 0; // no data so far |
|
| 111 | } |
119 | } |
| 112 | } |
120 | } |
| 113 | 121 | ||
| 114 | void sns_Serial_HandleMessage(StdCan_Msg_t *rxMsg) |
122 | void sns_Serial_HandleMessage(StdCan_Msg_t *rxMsg) |
| 115 | { |
123 | { |