/Designs/MRAKOMER4/SW/bootloader/bloader.PJT
36,7 → 36,7
2=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\bootloader\bloader.h
3=C:\Program Files\PICC\devices\16F88.h
4=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\bootloader\bloader.lst
5=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\bootloader\dbloader.c
5=
6=
7=
8=
/Designs/MRAKOMER4/SW/bootloader/bloader.c
1,4 → 1,4
/**** Bootloader ****/
/**** BootLoader ****/
#define VERSION "1.0"
#define ID "$Id$"
 
5,6 → 5,7
#CASE // Case sensitive compiler
 
#include "bloader.h"
#include <string.h>
 
#bit CREN = 0x18.4 // USART registers
#bit SPEN = 0x18.7
18,7 → 19,17
putchar(getc());
}
 
void welcome(void) // Welcome message
{
char REV[50]=ID; // Buffer for concatenate of a version string
char VER[4]=VERSION; // Buffer for concatenate of a version string
 
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0;
printf("\n\r\n\r# BLoader %s (C) 2007 KAKL\n\r",VER); // Welcome message
printf("#%s\n\r",&REV[4]);
}
 
 
/*-------------------------------- MAIN --------------------------------------*/
#SEPARATE
void real_main()
25,12 → 36,14
{
int8 i=0;
 
printf("/n/rBootloader/n/r");
welcome();
 
printf("# Boot Loader Test >>>\n\r# ");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
printf("|%u",i++);
printf("%u|",i++);
delay_ms(100);
}
}
59,7 → 72,7
real_main();
}
 
#ORG LOADER_RESERVED+FLASH_BLOCK_SIZE,getenv("PROGRAM_MEMORY")-125 auto=0 default
#ORG LOADER_RESERVED+FLASH_BLOCK_SIZE,getenv("PROGRAM_MEMORY")-130 auto=0 default
 
unsigned int atoi_b16(char *s) // Convert two hex characters to an int8
{
128,11 → 141,11
//---WDT
while (getc()!=':') restart_wdt(); // Only process data blocks that starts with ':'
 
buffidx = 0; // Read into the buffer until 'x' is received or buffer is full
buffidx = 0; // Read into the buffer until fill is received or buffer is full
do
{
buffer[buffidx] = getc();
} while ( (buffer[buffidx++] != 'x') && (buffidx < BUFFER_LEN_LOD) );
} while ( (buffer[buffidx++] < 'g') && (buffidx < BUFFER_LEN_LOD) );
assert(buffidx == BUFFER_LEN_LOD,1); // Error 1 - Buffer Overrun
 
//---WDT
195,8 → 208,8
}
else putchar('.');
//---WDT
restart_wdt();
CREN=0; CREN=1;
restart_wdt();
CREN=0; CREN=1; // Reinitialise USART
}
}
}
204,7 → 217,7
 
#ORG default
 
#ORG getenv("PROGRAM_MEMORY")-124,getenv("PROGRAM_MEMORY")-1 auto=0
#ORG getenv("PROGRAM_MEMORY")-129,getenv("PROGRAM_MEMORY")-1 auto=0
void main()
{
int8 timeout;
220,7 → 233,6
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC);
 
putchar('?');
for(timeout=0; timeout<255; timeout++) //cca 50s
{
if (kbhit())
233,6 → 245,7
}
}
else break;
putchar('u'); putchar('f'); putchar('?');
pause();
CREN=0; CREN=1; // Reinitialise USART
restart_wdt();
/Designs/MRAKOMER4/SW/dbloader.c
14,10 → 14,9
#ORG 6,FLASH_BLOCK_SIZE-1 {} // First Flash block is reserved
 
 
#ORG LOADER_RESERVED,getenv("PROGRAM_MEMORY")-12 auto=0
#ORG LOADER_RESERVED,getenv("PROGRAM_MEMORY")-1 auto=0
#SEPARATE
void dummy_main() // Main on the fix position
{
reset_cpu();
}
 
/Designs/MRAKOMER4/SW/irmrak4.PJT
37,9 → 37,11
3=C:\Program Files\PICC\devices\16F88.h
4=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\smb.c
5=C:\Program Files\PICC_old\drivers\string.h
6=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\bloader.c
7=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\irmrak4.lst
8=
6=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\irmrak4.lst
7=C:\Program Files\PICC_old\drivers\stddef.h
8=C:\Program Files\PICC_old\drivers\ctype.h
9=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\dbloader.c
10=
[Units]
Count=1
1=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\irmrak4.c (main)
/Designs/MRAKOMER4/SW/irmrak4.c
10,7 → 10,6
#bit FERR = 0x18.2
 
#include <string.h>
//!!! #include "bloader.c" // Boot Loader driver
 
#CASE // Case sensitive compiler
 
93,7 → 92,7
 
 
/*-------------------------------- MAIN --------------------------------------*/
void real_main()
void main()
{
unsigned int16 seq, temp, tempa;
signed int16 ta, to;
185,7 → 184,7
break;
 
case 'u':
// load_program(); // Update firmware
reset_cpu(); // Update firmware
}
}
// while(kbhit()) getc(); // Flush USART buffer
231,163 → 230,4
}
 
 
/*------------------- BOOT LOADER --------------------------------------------*/
#define LOADER_RESERVED getenv("PROGRAM_MEMORY")-getenv("FLASH_ERASE_SIZE")-800
#define BUFFER_LEN_LOD 46
 
#ORG LOADER_RESERVED,getenv("PROGRAM_MEMORY")-201 auto=0 default
 
unsigned int atoi_b16(char *s) { // Convert two hex characters to a int8
unsigned int result = 0;
int i;
 
for (i=0; i<2; i++,s++) {
if (*s >= 'A')
result = 16*result + (*s) - 'A' + 10;
else
result = 16*result + (*s) - '0';
}
 
return(result);
}
 
void assert(int1 Condition, int8 ErrorCode)
{
if(Condition)
{
putchar('E');
putchar(ErrorCode+'1');
reset_cpu();
}
}
 
void pause()
{
int16 timeout;
 
for(timeout=0; timeout<65535; timeout++); // Delay cca 300ms
}
 
boot_loader()
{
int buffidx;
char buffer[BUFFER_LEN_LOD];
 
int8 checksum, line_type;
int16 l_addr,h_addr=0;
int32 addr;
#if getenv("FLASH_ERASE_SIZE")>2
int32 next_addr;
#endif
 
//!!! #error ble getenv("FLASH_ERASE_SIZE") getenv("FLASH_WRITE_SIZE")
 
int8 dataidx, i, count;
union program_data {
int8 i8[16];
int16 i16[8];
} data;
 
putchar('@');
 
//!!!nesmaze obsluhu preruseni
for(i=getenv("FLASH_ERASE_SIZE")+1;i<LOADER_RESERVED;i+=getenv("FLASH_ERASE_SIZE"))
erase_program_eeprom(i);
 
putchar('@');
 
while(TRUE)
{
//---WDT
//!!! musi fungovat watchdog
while (getc()!=':') restart_wdt(); // Only process data blocks that starts with ':'
 
buffidx = 0; // Read into the buffer until 'x' is received or buffer is full
do
{
buffer[buffidx] = getc();
} while ( (buffer[buffidx++] != 'x') && (buffidx < BUFFER_LEN_LOD) );
assert(buffidx == BUFFER_LEN_LOD,1); // Overrun buffer?
 
//---WDT
restart_wdt();
 
checksum = 0; // Sum the bytes to find the check sum value
for (i=0; i<(buffidx-3); i+=2)
checksum += atoi_b16 (&buffer[i]);
checksum = 0xFF - checksum + 1;
assert(checksum != atoi_b16 (&buffer[buffidx-3]),2); // Bad CheckSum?
 
count = atoi_b16 (&buffer[0]); // Get the number of bytes from the buffer
 
// Get the lower 16 bits of address
l_addr = make16(atoi_b16(&buffer[2]),atoi_b16(&buffer[4]));
 
line_type = atoi_b16 (&buffer[6]);
 
addr = make32(h_addr,l_addr);
 
addr /= 2; // PIC16 uses word addresses
 
// If the line type is 1, then data is done being sent
if (line_type == 1)
{
putchar('#');
reset_cpu();
}
 
assert (line_type == 4,4);
 
 
//!!! pozor, nevypalilo by to obsluhu preruseni
if (addr > 3 || addr < LOADER_RESERVED)
{
 
if (line_type == 0)
{
for (i=0,next_addr=addr;i<8;i++)
data.i16[i]=read_program_eeprom(next_addr++);
// Loops through all of the data and stores it in data
// The last 2 bytes are the check sum, hence buffidx-3
for (i=8,dataidx=0; i < buffidx-3; i += 2)
data.i8[dataidx++]=atoi_b16(&buffer[i]);
 
write_program_memory(addr, data.i8, count);
}
putchar('*');
}
}
}
 
#ORG default
 
#ORG getenv("PROGRAM_MEMORY")-200,getenv("PROGRAM_MEMORY")-1
void main()
{
int8 timeout;
 
disable_interrupts(GLOBAL);
setup_wdt(WDT_2304MS); // Setup Watch Dog
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC);
 
/*
for(timeout=0; timeout<(3*20); timeout++) //cca 20s
if (kbhit())
{
if (getc()=='u') if (getc()=='f') boot_loader(); // Update Firmware starter
pause();
CREN=0; CREN=1;
restart_wdt();
};
*/
real_main();
}
 
#include "dbloader.c"
#include "dbloader.c" // Space reservation for the BootLoader