/******************************************************************************* * * * Copyright 2010 Rheinmetall Canada Inc. * * * * No part of this document may be reproduced, stored in * * a retrieval system, or transmitted, in any form or by any means, * * electronic, mechanical, photocopying, recording, or otherwise, * * without the prior written permission of Rheinmetall Canada Inc. * * * *******************************************************************************/ #include "define.h" #include "InternalUart.h" #include "FlashInterface.h" #include "BootloaderProtocol.h" #include "BootloaderStateMachine.h" #include "DigitalIO.h" //#pragma config FMIIEN = OFF, FSRSSEL = PRIORITY_7, FETHIO = ON //#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF //#pragma config POSCMOD = XT, FNOSC = PRIPLL, FPBDIV = DIV_1 //#pragma config ICESEL = ICS_PGx2, BWP = ON ////#pragma config FMIIEN = OFF, FSRSSEL = PRIORITY_7, FETHIO = ON ////#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF //#pragma config FPLLMUL = MUL_19, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF //#pragma config POSCMOD = XT, FNOSC = PRIPLL, FPBDIV = DIV_1 //#pragma config ICESEL = ICS_PGx1, BWP = ON #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF, WDTPS = PS128 #pragma config POSCMOD = EC, FNOSC = PRIPLL, FPBDIV = DIV_1 //#pragma config POSCMOD = XT, FNOSC = PRIPLL, FPBDIV = DIV_1 #pragma config ICESEL = ICS_PGx2, BWP = OFF //void _general_exception_handler(void); int main(void) { SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); //Use peripheral library to optimize configuration // INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);// configure for multi-vectored mode interrupts AD1PCFG = 0xFFFF; //Sart with I/O pins configured as digital I/O InternalUartInit(); InitFlashInterface(); ProtocolInit(); BootloaderSMInit(); InitDigitalIO(); OpenInternalPort(0,0,115200,INT_UART_ONE_STOP_BIT,INT_UART_NO_PARITY); ProtocolSendCmd(BOOTLOADER_READY_CMD,0,0); HEARTBEAT_LED_1_PIN = 0; char mbuf[30]; mbuf[0] = 'B'; mbuf[1] = 'o'; mbuf[2] = 'o'; mbuf[3] = 't'; mbuf[4] = 'l'; mbuf[5] = 'o'; mbuf[6] = 'a'; mbuf[7] = 'd'; mbuf[8] = 'e'; mbuf[9] = 'r'; mbuf[10] = ' '; mbuf[11] = 'V'; mbuf[12] = '0'; mbuf[13] = '.'; mbuf[14] = '0'; mbuf[15] = '1'; mbuf[16] = '\r'; SendInternalUartData(&mbuf[0],17); int i,j; i =0; j = 0; while(1) { if(ReadInternalUart() > 0) { // New Data arrived. // nothing special to do. // could flash a led HEARTBEAT_LED_2_PIN = !HEARTBEAT_LED_2_PIN; } if(e_CommandPending) { //Valid command received. ProtocolExecCmd(); e_CommandPending = false; } BootloaderSM(SM_TICK_EVENT,SM_NULL_DATA); if(++i >= 100000) { // if(++j >= 10000000) { HEARTBEAT_LED_1_PIN = ~HEARTBEAT_LED_1_PIN; i = 0; j = 0; } } } return true; } void _general_exception_handler(void) { char mbuf[30]; mbuf[0] = 'E'; mbuf[1] = 'x'; mbuf[2] = 'c'; mbuf[3] = 'e'; mbuf[4] = 'p'; mbuf[5] = 't'; mbuf[6] = 'i'; mbuf[7] = 'o'; mbuf[8] = 'n'; mbuf[9] = ' '; mbuf[10] = 'o'; mbuf[11] = 'c'; mbuf[12] = 'c'; mbuf[13] = 'u'; mbuf[14] = 'r'; mbuf[15] = 'r'; mbuf[16] = 'e'; mbuf[17] = 'd'; mbuf[18] = '\r'; SendInternalUartData(&mbuf[0],19); SoftReset(); } //EOF