Subversion Repositories HomeAutomation

Rev

Rev 261 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 261 Rev 264
Line 89... Line 89...
89
}
89
}
90
 
90
 
91
void Can_Process(Can_Message_t* msg) {
91
void Can_Process(Can_Message_t* msg) {
92
    if (!(msg->ExtendedFlag)) return;
92
    if (!(msg->ExtendedFlag)) return;
93
   
93
   
94
    //applikationen ska bara ta hand om paket som inte är nmt så else:et nedan kommer om det inte är nmt enbart
-
 
95
    if ((msg->Id & CAN_MASK_CLASS) == ((uint32_t)CAN_NMT << CAN_SHIFT_CLASS)) {
94
    if ((msg->Id & CAN_MASK_CLASS) == ((uint32_t)CAN_NMT << CAN_SHIFT_CLASS)) {
96
        if ((msg->Id & CAN_MASK_NMT_RID) == ((uint32_t)NODE_ID << CAN_SHIFT_NMT_RID)) {
95
        if ((msg->Id & CAN_MASK_NMT_RID) == ((uint32_t)NODE_ID << CAN_SHIFT_NMT_RID)) {
97
            //printf("BIOS received msg!\n");
96
            //printf("BIOS received msg!\n");
98
            if ((msg->Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE == CAN_NMT_RESET) {
97
            if ((msg->Id & CAN_MASK_NMT_TYPE)>>CAN_SHIFT_NMT_TYPE == CAN_NMT_RESET) {
99
                reset();
98
                reset();
Line 103... Line 102...
103
            // started, bios_msg_full is never reset to 0 so the check fails and all
102
            // started, bios_msg_full is never reset to 0 so the check fails and all
104
            // NMT communication except reset is ignored. 
103
            // NMT communication except reset is ignored. 
105
            if (!(bios_msg_full)) {
104
            if (!(bios_msg_full)) {
106
                memcpy(bios_msg_ptr, msg, sizeof(Can_Message_t));
105
                memcpy(bios_msg_ptr, msg, sizeof(Can_Message_t));
107
                bios_msg_full = 1;
106
                bios_msg_full = 1;
-
 
107
            }
108
            }      
108
        }      
109
        } else if (bios->can_callback) {
109
    } else if (bios->can_callback) {
110
            //printf("Calling app callback.\n");
110
        //printf("Calling app callback.\n");
111
            bios->can_callback(msg);
111
        bios->can_callback(msg);
112
        }
-
 
113
    }
112
    }
114
}
113
}
115
 
114
 
116
#define BIOS_APP    1
115
#define BIOS_APP    1
117
#define BIOS_NOAPP  2
116
#define BIOS_NOAPP  2
Line 166... Line 165...
166
    } else {
165
    } else {
167
        // Application exists
166
        // Application exists
168
        //send CAN_NMT_BIOS_START(BIOS_VERSION, 1)
167
        //send CAN_NMT_BIOS_START(BIOS_VERSION, 1)
169
        tx_msg.Data.bytes[2] = 1;
168
        tx_msg.Data.bytes[2] = 1;
170
        bios_state = BIOS_APP;
169
        bios_state = BIOS_APP;
171
    }
170
    }
172
   
171
   
173
    while (Can_Send(&tx_msg) != CAN_OK);
172
    while (Can_Send(&tx_msg) != CAN_OK);
174
 
173
 
175
    tx_msg.DataLength = 2;
174
    tx_msg.DataLength = 2;
176
   
175
   
177
    // main loop
176
    // main loop
178
    while (1) {
177
    while (1) {
Line 193... Line 192...
193
                flash_init();
192
                flash_init();
194
                //send CAN_NMT_PGM_ACK(offset)
193
                //send CAN_NMT_PGM_ACK(offset)
195
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
194
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
196
                tx_msg.Data.words[0] = base_addr;
195
                tx_msg.Data.words[0] = base_addr;
197
                bios_state = BIOS_PGM;
196
                bios_state = BIOS_PGM;
198
                while (Can_Send(&tx_msg) != CAN_OK);
-
 
199
            }
197
            }
200
            break;
198
            break;
201
        case BIOS_PGM:
199
        case BIOS_PGM:
202
            if (nmt_type == CAN_NMT_PGM_DATA) {
200
            if (nmt_type == CAN_NMT_PGM_DATA) {
203
                // Set address = base address + offset
201
                // Set address = base address + offset
Line 216... Line 214...
216
                    //update crc
214
                    //update crc
217
                    //send CAN_NMT_PGM_ACK(offset)
215
                    //send CAN_NMT_PGM_ACK(offset)
218
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
216
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
219
                } else {
217
                } else {
220
                    //send CAN_NMT_PGM_NACK(offset)
218
                    //send CAN_NMT_PGM_NACK(offset)
221
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
219
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
222
                }
220
                }
223
            }
221
            }
224
            if (nmt_type == CAN_NMT_PGM_END) {
222
            if (nmt_type == CAN_NMT_PGM_END) {
225
                flash_flush_buffer();
223
                flash_flush_buffer();
226
                //check crc
224
                //check crc
227
                //tx_msg.Data.words[0] = crc;
225
                //tx_msg.Data.words[0] = crc;
Line 229... Line 227...
229
                    //send CAN_NMT_PGM_ACK(crc)
227
                    //send CAN_NMT_PGM_ACK(crc)
230
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
228
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
231
                } else {
229
                } else {
232
                    //send CAN_NMT_PGM_NACK(crc)
230
                    //send CAN_NMT_PGM_NACK(crc)
233
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
231
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
234
                }
232
                }
235
                bios_state = BIOS_NOAPP;
233
                bios_state = BIOS_NOAPP;
-
 
234
            }
236
            }
235
        }
237
            while (Can_Send(&tx_msg) != CAN_OK);
236
        while (Can_Send(&tx_msg) != CAN_OK);
238
        }
-
 
239
 
237
 
240
        bios_msg_full = 0; // We're done with this message, ready for the next.
238
        bios_msg_full = 0; // We're done with this message, ready for the next.
241
    }
239
    }
242
 
240
 
243
    return 0;
241
    return 0;