📄 rs232down.c
字号:
rsData2FlashBuff((UINT8 *)&flashData, 1);
#else
if(rsData2FlashBuff((UINT8 *)&flashData, 2)!=OK)
// if(DataFlush2Ram( (UINT8 *)wPtr, (UINT8 *)&flashData, 2)!=OK)
{
// DBG_MSG("\nflash memory program failed");
return ERROR;
}
#endif
numFlashData = 0;
// wPtr +=2;
totalBytes +=2;
}
n = (n+1)%64; /* Bump packet number */
return('F'); /* Go back to Receive File state */
case 'E': /* Error packet received */
Prerrpkt(recpkt); /* Print it out and */
return('A'); /* abort */
case FALSE: /* Didn't get packet */
Spack('N',n,0,0); /* Return a NAK */
return(state); /* Keep trying */
default: return('A'); /* Some other packet, "abort" */
}
}
/******************************************************************************
* Function: Spack
*
* Description: Send a Packet
*
* Inputs: char type - type of packet
* int num - seqence number of packet
* int len - length of data
* char* data - base address of packet data
*
* Outputs: None
*
* Returns: None
*
* Note: (optional section giving special considerations about the function)
******************************************************************************/
static void Spack( char type, int num, int len, char *data)
{
int i; /* Character loop counter */
char chksum, buffer[100]; /* Checksum, packet buffer */
register char *bufp; /* Buffer pointer */
bufp = buffer; /* Set up buffer pointer */
for (i=1; i<=pad; i++) ChannelSet( padchar ); /* Issue any padding */
*bufp++ = SOH; /* Packet marker, ASCII 1 (SOH) */
*bufp++ = tochar(len+3); /* Send the character count */
chksum = tochar(len+3); /* Initialize the checksum */
*bufp++ = tochar(num); /* Packet number */
chksum += tochar(num); /* Update checksum */
*bufp++ = type; /* Packet type */
chksum += type; /* Update checksum */
for (i=0; i<len; i++) /* Loop for all data characters */
{
*bufp++ = data[i]; /* Get a character */
chksum += data[i]; /* Update checksum */
}
chksum = (((chksum&0300) >> 6)+chksum)&077; /* Compute final checksum */
*bufp++ = tochar(chksum); /* Put it in the packet */
*bufp = eol; /* Extra-packet line terminator */
/* Send the packet */
for( i = 0; i < bufp-buffer+1; i++ )
{
ChannelSet( buffer[ i ] );
}
}
/******************************************************************************
* Function: Rpack
*
* Description: Read a Packet
*
* Inputs: int* len - the location where the length of packet data
* will be stored
* int* num - the location where the seqence number of the
* packet will be stored
* char* data - the base address where the packet data will be
* stored from
*
* Outputs: int* len - after the function is completed, *len is the
* length of the packet data in bytes
* int* num - after the function is completed, *num is the
* seqence number of the packet
* char* data - after the function is completed, packet data is
* stored from the address of "data"
*
* Returns: char - packet type
*
* Note: (optional section giving special considerations about the function)
******************************************************************************/
static char Rpack( int *len, int *num, char *data )
{
int i, done; /* Data character number, loop exit */
char t, /* Current input character */
type=0, /* Packet type */
cchksum=0, /* Our (computed) checksum */
rchksum=0; /* Checksum received from other host */
/* NOTE: no timeout */
while (t != SOH) /* Wait for packet header */
{
ChannelGet( &t );
t &= 0x7f; /* Handle parity */
}
done = FALSE; /* Got SOH, init loop */
while (!done) /* Loop to get a packet */
{
ChannelGet( &t ); /* Get character */
if (!image) t &= 0x7f; /* Handle parity */
if (t == SOH) continue; /* Resynchronize if SOH */
cchksum = t; /* Start the checksum */
*len = unchar(t)-3; /* Character count */
ChannelGet( &t ); /* Get character */
if (!image) t &= 0x7f; /* Handle parity */
if (t == SOH) continue; /* Resynchronize if SOH */
cchksum = cchksum + t; /* Update checksum */
*num = unchar(t); /* Packet number */
ChannelGet( &t ); /* Get character */
if (!image) t &= 0x7f; /* Handle parity */
if (t == SOH) continue; /* Resynchronize if SOH */
cchksum = cchksum + t; /* Update checksum */
type = t; /* Packet type */
for (i=0; i<*len; i++) /* The data itself, if any */
{ /* Loop for character count */
ChannelGet( &t ); /* Get character */
if (!image) t &= 0x7f; /* Handle parity */
if (t == SOH) continue; /* Resynch if SOH */
cchksum = cchksum + t; /* Update checksum */
data[i] = t; /* Put it in the data buffer */
}
data[*len] = 0; /* Mark the end of the data */
ChannelGet( &t ); /* Get last character (checksum) */
if (!image) t &= 0x7f; /* Handle parity */
rchksum = unchar(t); /* Convert to numeric */
ChannelGet( &t ); /* get EOL character and toss it */
if (!image) t &= 0x7f; /* Handle parity */
if (t == SOH) continue; /* Resynchronize if SOH */
/* FIXME: continue? */
done = TRUE; /* Got checksum, done */
}
/* Fold in bits 7,8 to compute */
cchksum = (((cchksum&0300) >> 6)+cchksum)&077; /* final checksum */
if (cchksum != rchksum) return(FALSE);
return(type); /* All OK, return packet type */
}
/******************************************************************************
* Function: Spar
*
* Description: Fill the data array with my send-init parameters
*
* Inputs: char[] data - the data array to be filled
*
* Outputs: char[] data - data array filled with my send-init
* parameters
*
* Returns: None
*
* Note: (optional section giving special considerations about the function)
******************************************************************************/
static void Spar( char data[] )
{
data[0] = tochar(MAXPACKSIZ); /* Biggest packet I can receive */
data[1] = tochar(MYTIME); /* When I want to be timed out */
data[2] = tochar(MYPAD); /* How much padding I need */
data[3] = ctl(MYPCHAR); /* Padding character I want */
data[4] = tochar(MYEOL); /* End-Of-Line character I want */
data[5] = MYQUOTE; /* Control-Quote character I send */
}
/******************************************************************************
* Function: Rpar
*
* Description: Get the other host's send-init parameters
*
* Inputs: char[] data - the data array which contains the other host's
* send-init parameters
*
* Outputs: None
*
* Returns: None
*
* Note: (optional section giving special considerations about the function)
******************************************************************************/
static void Rpar( char data[] )
{
spsiz = unchar(data[0]); /* Maximum send packet size */
timint = unchar(data[1]); /* When I should time out */
pad = unchar(data[2]); /* Number of pads to send */
padchar = ctl(data[3]); /* Padding character to send */
eol = unchar(data[4]); /* EOL character I must send */
quote = data[5]; /* Incoming data quote character */
}
/******************************************************************************
* Function: Bufemp
*
* Description: Put data which is gotten from an incoming packet into a Flash
*
* Inputs: char[] buffer - data buffer
* int len - the length of data buffer
*
* Outputs: None
*
* Returns: None
*
* Note: (optional section giving special considerations about the function)
******************************************************************************/
static void Bufemp( char buffer[], int len)
{
int i; /* Counter */
char t; /* Character holder */
for (i=0; i<len; i++) /* Loop thru the data field */
{
t = buffer[i]; /* Get character */
if (t == MYQUOTE) /* Control quote? */
{ /* Yes */
t = buffer[++i]; /* Get the quoted character */
if ((t & 0x7f) != MYQUOTE) /* Low order bits match quote char? */
t = ctl(t); /* No, uncontrollify it */
}
if (t==CR && !image) /* Don't pass CR if in image mode */
continue;
flashDataPtr[ numFlashData++ ] = t;
if( numFlashData == 2 )
{
#if 1
rsData2FlashBuff((UINT8 *)&flashData, 2);
#else
if(DataFlush2Ram( (UINT8 *)wPtr, (UINT8 *)&flashData, 2)!=OK)
{
// DBG_MSG("FlashWrite() failed ");
// /* FIXME: handle this error * /
}
#endif
// wPtr += 2;
totalBytes += 2;
numFlashData = 0;
}
}
}
static void Prerrpkt( char *msg )
{
// DBG_MSG("Kermit aborting with error from remote host");
}
static void DBG_MSG(UINT8 *msg)
{
//UINT8* data;
// for(data=msg; *data!='\0';data++)
// ChannelSet( *data );
}
#if 0
/*****************************************************************************
** Function: void DBG_puthex (int val)
**
** Send an integer to the UART port as a hex string.
**
**
**
** Inputs: val -- integer value
** Outputs: none
** return: none
**
*/
static void DBG_puthex(UINT32 val)
{
/*
UINT32 val1, val2;
int shift;
for(shift = 28; shift>=0; shift-=4)
{
val1 = val >> shift;
val1 = val1 & 0xf;
val2 = val1 + 0x30;
if(val1 > 9)
val2 = val2 + 7;
ChannelSet(val2);
}
*/
}
/*******************************************************************************
*
* copyLongs - copy one buffer to another a long at a time
*
* This routine copies the first <nlongs> longs from <source> to <destination>.
*/
static void copyLongs (UINT32* source, UINT32* destination, UINT32 nlongs)
{
UINT32 *dstend = destination + nlongs;
while (destination < dstend)
*destination++ = *source++;
}
#endif
#if 1
static int mUartErrFlag;
static BOOL rs_getbyte(UINT8* bPtr)
{
register volatile unsigned int status;
/* fetch status */
status = *(CSSR);
/* check if character has arrived */
/* Here we only check the status of RDRF bit, but
maybe we'll have to check ORER, FER, PER bits for
possible error conditions in the future. HsuTC, 2000/09/13 */
if (status & RDRF)
{
/* receive character */
*bPtr =(BYTE) (*(CRDR) & 0xFF);
/* clear RDR full, ORER, frame error, parity error;
this will also deactivate CSCI interrupt signal.
HsuTC, 2000/09/13 */
*(CSSR) = *(CSSR) & (~(RDRF|ORER|FER|PER));
mUartErrFlag = 0;
return OK;
}
else
{
// c = *(CRDR) & 0xFF;
*bPtr =(BYTE) (*(CRDR) & 0xFF);
if((status & ORER) || (status & FER) || (status & PER))
{
*(CSSR) = *(CSSR) & (~(RDRF|ORER|FER|PER));
mUartErrFlag = status;
}
// *bPtr = c;
return ERROR;
}
}
static WORD UartCommDetect(void)
{
unsigned char tmp_uch;
unsigned char Rcvd_char;
WORD ret_val;
mUartErrFlag =0;
if(rs_getbyte(&tmp_uch)==OK)
{
Rcvd_char = tmp_uch;
if(Rcvd_char == 'R' || Rcvd_char == 'r')
ret_val =OK;
else
ret_val=NODETECT;
}
else if(mUartErrFlag)
{
ret_val =(WORD) (COMERROR|(mUartErrFlag&0x00ff));
}
else
ret_val=NODATA;
return ret_val;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -