Subversion Repositories HomeAutomation

Rev

Rev 1631 | Rev 1868 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1631 Rev 1641
Line 1... Line 1...
1
/*
1
/*
2
 * $Id: bios.c 1631 2010-12-02 15:08:08Z linlun $
2
 * $Id: bios.c 1641 2010-12-05 22:37:37Z nattgris $
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 85... Line 85...
85
#if defined(AUTOSTART)
85
#if defined(AUTOSTART)
86
            autostart_cnt++;
86
            autostart_cnt++;
87
#endif
87
#endif
88
        }
88
        }
89
       
89
 
90
        if (((msg->Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE) == CAN_NMT_RESET && msg->DataLength == 4 &&
90
        if (((msg->Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE) == CAN_NMT_RESET
-
 
91
                && msg->DataLength == 4
-
 
92
                && msg->Data.bytes[0] == (hwid&0xff)
91
                msg->Data.bytes[0] == (hwid&0xff) && msg->Data.bytes[1] == ((hwid>>8)&0xff) &&
93
                && msg->Data.bytes[1] == ((hwid>>8)&0xff)
-
 
94
                && msg->Data.bytes[2] == ((hwid>>16)&0xff)
92
                msg->Data.bytes[2] == ((hwid>>16)&0xff) && msg->Data.bytes[3] == ((hwid>>24)&0xff) ) {
95
                && msg->Data.bytes[3] == ((hwid>>24)&0xff)) {
93
            BIOS_Reset();
96
            BIOS_Reset();
94
        }
97
        }
95
        // Copy message to bios buffer if bios is done with the previous message.
98
        // Copy message to bios buffer if bios is done with the previous message.
96
        // This is also a check to see if bios is still running. When app is
99
        // This is also a check to see if bios is still running. When app is
97
        // started, bios_msg_full is never reset to 0 so the check fails and all
100
        // started, bios_msg_full is never reset to 0 so the check fails and all
Line 179... Line 182...
179
        nmt_type = (bios_msg.Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE;
182
        nmt_type = (bios_msg.Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE;
180
       
183
 
181
        switch (bios_state) {
184
        switch (bios_state) {
182
        case BIOS_APP:
185
        case BIOS_APP:
183
            //if (nmt_type == CAN_NMT_START_APP) {
186
            //if (nmt_type == CAN_NMT_START_APP) {
184
            if (nmt_type == CAN_NMT_START_APP && bios_msg.DataLength == 4 &&
187
            if (nmt_type == CAN_NMT_START_APP
-
 
188
                    && bios_msg.DataLength == 4
-
 
189
                    && bios_msg.Data.bytes[0] == (hwid&0xff)
185
                    bios_msg.Data.bytes[0] == (hwid&0xff) && bios_msg.Data.bytes[1] == ((hwid>>8)&0xff) &&
190
                    && bios_msg.Data.bytes[1] == ((hwid>>8)&0xff)
-
 
191
                    && bios_msg.Data.bytes[2] == ((hwid>>16)&0xff)
186
                    bios_msg.Data.bytes[2] == ((hwid>>16)&0xff) && bios_msg.Data.bytes[3] == ((hwid>>24)&0xff) ) {
192
                    && bios_msg.Data.bytes[3] == ((hwid>>24)&0xff)) {
187
                app_reset(); // Will never return
193
                app_reset(); // Will never return
188
            }
194
            }
189
            // Fall through
195
            // Fall through
190
        case BIOS_NOAPP:
196
        case BIOS_NOAPP:
191
            //if (nmt_type == CAN_NMT_PGM_START) {
197
            //if (nmt_type == CAN_NMT_PGM_START) {
192
            if (nmt_type == CAN_NMT_PGM_START && bios_msg.DataLength == 8 &&
198
            if (nmt_type == CAN_NMT_PGM_START
-
 
199
                    && bios_msg.DataLength == 8
-
 
200
                    && bios_msg.Data.bytes[4] == (hwid&0xff)
193
                    bios_msg.Data.bytes[4] == (hwid&0xff) && bios_msg.Data.bytes[5] == ((hwid>>8)&0xff) &&
201
                    && bios_msg.Data.bytes[5] == ((hwid>>8)&0xff)
-
 
202
                    && bios_msg.Data.bytes[6] == ((hwid>>16)&0xff)
194
                    bios_msg.Data.bytes[6] == ((hwid>>16)&0xff) && bios_msg.Data.bytes[7] == ((hwid>>24)&0xff) ) {
203
                    && bios_msg.Data.bytes[7] == ((hwid>>24)&0xff)) {
195
                // Set base address
204
                // Set base address
196
                base_addr = bios_msg.Data.words[0];
205
                base_addr = bios_msg.Data.words[0];
197
                flash_init(pagebuf);
206
                flash_init(pagebuf);
198
                //send CAN_NMT_PGM_ACK(offset)
207
                //send CAN_NMT_PGM_ACK(offset)
199
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
208
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;