Rev 563 | Rev 769 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 563 | Rev 585 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /* |
1 | /* |
| 2 | * $Id: bios.c |
2 | * $Id: bios.c 585 2007-08-06 17:44:46Z arune $ |
| 3 | */ |
3 | */ |
| 4 | 4 | ||
| 5 | #include <inttypes.h> |
5 | #include <inttypes.h> |
| 6 | #include <avr/io.h> |
6 | #include <avr/io.h> |
| 7 | #include <avr/interrupt.h> |
7 | #include <avr/interrupt.h> |
| Line 20... | Line 20... | ||
| 20 | #define IVSEL_REG GICR |
20 | #define IVSEL_REG GICR |
| 21 | #elif defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) |
21 | #elif defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) |
| 22 | #define IVSEL_REG MCUCR |
22 | #define IVSEL_REG MCUCR |
| 23 | #else |
23 | #else |
| 24 | #error AVR device not supported! |
24 | #error AVR device not supported! |
| - | 25 | #endif |
|
| - | 26 | ||
| - | 27 | #if defined(AUTOSTART) |
|
| - | 28 | #if AUTOSTART == 0 |
|
| - | 29 | #error Please choose a higher AUTOSTART value in bios.inc, the nod will cease to work, and you can only reflash node with ISP |
|
| - | 30 | #endif |
|
| - | 31 | #if AUTOSTART == 1 |
|
| - | 32 | #error Please choose a higher AUTOSTART value in bios.inc, there might be problems with updating software on node |
|
| - | 33 | #endif |
|
| 25 | #endif |
34 | #endif |
| 26 | 35 | ||
| 27 | //--------------------------------------------------------------------------- |
36 | //--------------------------------------------------------------------------- |
| 28 | // Private declarations |
37 | // Private declarations |
| 29 | 38 | ||
| 30 | volatile uint8_t bios_msg_full; |
39 | volatile uint8_t bios_msg_full; |
| 31 | Can_Message_t* bios_msg_ptr; // only a pointer to main-local structure to save .bss space |
40 | Can_Message_t* bios_msg_ptr; // only a pointer to main-local structure to save .bss space |
| 32 | extern void __bios_start; // Start of BIOS area in flash, from ld-script. |
41 | extern void __bios_start; // Start of BIOS area in flash, from ld-script. |
| - | 42 | ||
| - | 43 | #if defined(AUTOSTART) |
|
| - | 44 | uint8_t autostart_cnt; |
|
| - | 45 | #endif |
|
| 33 | 46 | ||
| 34 | #define BIOS_APP 1 |
47 | #define BIOS_APP 1 |
| 35 | #define BIOS_NOAPP 2 |
48 | #define BIOS_NOAPP 2 |
| 36 | #define BIOS_PGM 3 |
49 | #define BIOS_PGM 3 |
| 37 | 50 | ||
| Line 47... | Line 60... | ||
| 47 | // Reset watchdog as long as time messages from the master node |
60 | // Reset watchdog as long as time messages from the master node |
| 48 | // are received periodically. If anything hangs the CAN communication |
61 | // are received periodically. If anything hangs the CAN communication |
| 49 | // or the master node is not up, the node will be reset. |
62 | // or the master node is not up, the node will be reset. |
| 50 | wdt_reset(); |
63 | wdt_reset(); |
| 51 | //TODO: Don't care about time right now... Figure out what to do with it. |
64 | //TODO: Don't care about time right now... Figure out what to do with it. |
| - | 65 | #if defined(AUTOSTART) |
|
| - | 66 | autostart_cnt++; |
|
| - | 67 | #endif |
|
| 52 | } |
68 | } |
| 53 | 69 | ||
| 54 | if ((msg->Id & CAN_MASK_NMT_RID)>>CAN_SHIFT_NMT_RID == NODE_ID) { |
70 | if ((msg->Id & CAN_MASK_NMT_RID)>>CAN_SHIFT_NMT_RID == NODE_ID) { |
| 55 | 71 | ||
| 56 | if ((msg->Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE == CAN_NMT_RESET) { |
72 | if ((msg->Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE == CAN_NMT_RESET) { |
| Line 84... | Line 100... | ||
| 84 | uint16_t data; |
100 | uint16_t data; |
| 85 | uint8_t send_msg = 0; |
101 | uint8_t send_msg = 0; |
| 86 | Can_Message_t tx_msg; |
102 | Can_Message_t tx_msg; |
| 87 | Can_Message_t bios_msg; |
103 | Can_Message_t bios_msg; |
| 88 | bios_msg_ptr = &bios_msg; |
104 | bios_msg_ptr = &bios_msg; |
| - | 105 | ||
| - | 106 | #if defined(AUTOSTART) |
|
| - | 107 | autostart_cnt = 0; |
|
| - | 108 | #endif |
|
| 89 | 109 | ||
| 90 | // Enable watchdog timer to protect against an application locking the |
110 | // Enable watchdog timer to protect against an application locking the |
| 91 | // node by leaving interrupts disabled. |
111 | // node by leaving interrupts disabled. |
| 92 | wdt_enable(WDTO_2S); |
112 | wdt_enable(WDTO_2S); |
| 93 | 113 | ||
| Line 121... | Line 141... | ||
| 121 | tx_msg.DataLength = 2; // All msg sent after BIOS_START are length 2 so set it once. |
141 | tx_msg.DataLength = 2; // All msg sent after BIOS_START are length 2 so set it once. |
| 122 | 142 | ||
| 123 | // Main loop |
143 | // Main loop |
| 124 | while (1) { |
144 | while (1) { |
| 125 | // Wait for message |
145 | // Wait for message |
| 126 | while (!bios_msg_full) |
146 | while (!bios_msg_full) { |
| - | 147 | #if defined(AUTOSTART) |
|
| - | 148 | if (bios_state == BIOS_APP && autostart_cnt == AUTOSTART) { |
|
| - | 149 | app_reset(); |
|
| - | 150 | } |
|
| - | 151 | #endif |
|
| - | 152 | } |
|
| 127 | 153 | ||
| 128 | nmt_type = (bios_msg.Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE; |
154 | nmt_type = (bios_msg.Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE; |
| 129 | 155 | ||
| 130 | switch (bios_state) { |
156 | switch (bios_state) { |
| 131 | case BIOS_APP: |
157 | case BIOS_APP: |