mootaccount
New Member
Hi,
I can't find the error in this code. Please help. The error messages are as follows:
ERROR (300) On line 185 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 187 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 242 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 242 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 245 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 245 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 248 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 248 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 249 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 251 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 251 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 251 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
Build completed.
Source code:
I can't find the error in this code. Please help. The error messages are as follows:
ERROR (300) On line 185 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 187 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 242 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 242 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 243 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 245 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 245 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 248 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 248 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 249 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 251 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 251 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
ERROR (300) On line 251 of "D:\PR\Z8ENCORE_PROJECT\XMODEM.C"
Error index out of range
Build completed.
Source code:
Code:
#include "boot.h"
#include <stdio.h>
#include <uart.h>
#include "boot_crc16.h"
/* xmodem-related */
int boot_error_decode;
int boot_error_nak;
int boot_error_in;
int boot_s_records;
int boot_x_records;
long boot_bytes;
long boot_max_adr;
extern MY_FIFO boot_fifo;
#define DLY_1S 1000
#define MAXRETRANS 25
#define SOH 0x01
#define STX 0x02
#define EOT 0x04
#define ACK 0x06
#define NAK 0x15
#define CAN 0x18
#define CTRLZ 0x1A
unsigned char boot_hex( unsigned char c ) {
return ( c < 0x3a ) ? (c & 15) : (( c & 15 ) + 9);
}
// process the resulting S records
int boot_process(void) {
unsigned char c;
static unsigned char len, byte, sum;
static unsigned long adr;
c=fifo_get();
switch (boot_fifo.state) {
case 0: // looking for an 'S'
if( c == 'S' ) boot_fifo.state++;
break;
case 1: // looking for an '2'
if( c != '2' ) boot_fifo.state = 0; // ignore all records but S2
else boot_fifo.state=3; // S2 has been found
break;
case 3: // first byte of byte count
boot_s_records++;
len = boot_hex(c); // save the partial result
boot_fifo.state++;
break;
case 4: // second byte of byte count
len = (len << 4) + boot_hex(c);
boot_fifo.state++;
sum = len; // len is first byte in sum check
break;
case 5: // first byte of address
adr = byte = boot_hex(c); // save the partial result
boot_fifo.state++;
break;
case 6: // second byte of address
case 8: // 4th byte of address
case 10: // 6th byte of address
c = boot_hex(c);
adr = (adr << 4) + c;
byte = (byte << 4) + c;
sum += byte; // on even bytes, add into sum check
boot_fifo.state++;
break;
case 7: // 3rd byte of address
case 9: // 5th byte of address
byte = boot_hex(c); // on odd bytes, save partial for sum check usage
adr = (adr << 4) + byte;
boot_fifo.state++;
break;
case 11: // first part of data byte or check sum
byte = boot_hex(c); // save the partial result
boot_fifo.state++;
if( len < 5 ) boot_fifo.state++; // if in sum check area skip over next step
break;
case 12: // second data byte
byte = (byte << 4) + boot_hex(c);
sum += byte;
*( boot_fifo.origin + adr ) = byte; // store the byte
if( adr > boot_max_adr ) boot_max_adr = adr;
boot_bytes++;
adr++;
len--;
boot_fifo.state--; // go back for another data byte
break;
case 13: // 2nd byte of sum check
byte = (byte << 4) + boot_hex(c);
sum += byte;
boot_fifo.state = 0;
if( sum != 255 ) {
boot_error_decode++;
return -4;
}
break;
}
return 0;
}
unsigned char get_test()
{
if ( kbhit() ) return 1;
else return 0;
}
//void delayms (unsigned int milliseconds)
//{
//unsigned int volatile current_ms;
// current_ms = 0;
// T0CTL &= 0x7F; // Disable T0
// T0H = 0x00 ; // Restart from 0
// T0L = 0x00 ;
// T0CTL |= 0x80 ; // Put On T0
// while (current_ms < milliseconds)
// ; // Delay loop
// T0CTL &= 0x7F; // Stop T0
//} /* delayms */
void delay(void) // Delay function
{
int i,j;
for(i=0;i<0xFF;i++)
for(j=0;j<0xFF;j++);
}
int boot_inbyte(unsigned short timeout) // Get a comm char with timeout
{
int cc = 0;
while( timeout-- ) {
if( get_test() )
//return getc();
return getch();
if( !fifo_empty() ) {
cc = boot_process();
if( cc < 0 ) return cc;
}
else
delay();
//delayms(1);
}
return -1;
}
static void flushinput(void)
{
while (boot_inbyte(((DLY_1S)*3)>>1) >= 0)
;
}
static int check(int crc, unsigned char *buf, int sz)
{
if (crc) {
unsigned short crc = crc16_ccitt(buf, sz);
unsigned short tcrc = (buf[sz]<<8)+buf[sz+1];
if (crc == tcrc)
return 1;
}
else {
int i;
unsigned char cks = 0;
for (i = 0; i < sz; ++i) {
cks += buf[i];
}
if (cks == buf[sz])
return 1;
}
return 0;
}
int boot_xmodemReceive(void)
{
unsigned char xbuff[1030]; /* 1024 for XModem 1k + 3 head chars + 2 crc + nul */
unsigned char *p;
int bufsz, crc = 0;
unsigned char trychar = 'C';
unsigned char packetno = 1;
int i, c;
int retry, retrans = MAXRETRANS;
for(;;) {
for( retry = 0; retry < 16; ++retry) {
//if (trychar) putc(trychar);
if (trychar) putch(trychar);
if ((c = boot_inbyte((DLY_1S)<<1)) >= 0) {
switch (c) {
case SOH:
bufsz = 128;
goto start_recv;
case STX:
bufsz = 1024;
goto start_recv;
case EOT:
flushinput();
//putc(ACK);
putch(ACK);
return 0; /* normal end */
case CAN:
if ((c = boot_inbyte(DLY_1S)) == CAN) {
flushinput();
//putc(ACK);
putch(ACK);
return -1; /* canceled by remote */
}
break;
default:
break;
}
}
}
if (trychar == 'C') { trychar = NAK; continue; }
flushinput();
//putc(CAN);
//putc(CAN);
//putc(CAN);
putch(CAN);
putch(CAN);
putch(CAN);
return -2; /* sync error */
start_recv:
if (trychar == 'C') crc = 1;
trychar = 0;
p = xbuff;
*p++ = c;
for (i = 0; i < (bufsz+(crc?1:0)+3); ++i) {
if ((c = boot_inbyte(DLY_1S)) < 0) {
boot_error_in++;
goto reject;
}
*p++ = c;
}
if (xbuff[1] == (unsigned char)(~xbuff[2]) &&
(xbuff[1] == packetno || xbuff[1] == (unsigned char)packetno-1) &&
check(crc, &xbuff[3], bufsz)) {
if (xbuff[1] == packetno) {
fifo_move( &xbuff[3], bufsz);
boot_x_records++;
++packetno;
retrans = MAXRETRANS+1;
}
if (--retrans <= 0) {
flushinput();
//putc(CAN);
//putc(CAN);
//putc(CAN);
putch(CAN);
putch(CAN);
putch(CAN);
return -3; /* too many retry error */
}
//putc(ACK);
putch(ACK);
continue;
}
boot_error_nak++;
reject:
flushinput();
//putc(NAK);
putch(NAK);
}
}
void boot_xmodem(unsigned char*org)
{
int st;
fifo_init(org);
boot_error_decode = 0; // sum check error on the S record
boot_error_nak = 0; // number of NAK's sent
boot_error_in = 0; // number of errors returned by boot_inbyte() once transfer starts
boot_s_records = 0; // number of S2 records received
boot_x_records = 0; // number of x records received
boot_bytes = 0; // number of bytes actually placed in RAM from S records
boot_max_adr = 0; // largest (relative) address stored into during xmodem download
printf("Send data using the xmodem protocol from your terminal emulator now...\r\n");
st = boot_xmodemReceive();
if( boot_error_decode > 0 ) st = -4;
printf("\r\n\nResults of download....\r\n");
printf("Number of X records = %d.\r\n", boot_x_records);
printf("Number of S records = %d.\r\n", boot_s_records);
printf("Number of Bytes = %ld.\r\n", boot_bytes);
printf("Decode errors = %d.\r\n", boot_error_decode);
printf("NAK errors = %d.\r\n", boot_error_nak);
if (st < 0) {
printf("The file was not successfully received, error code was: %d\r\n",st);
exit();
}
else {
printf("The file was successfully received\r\n");
}
return;
}