Wing Guest
|
Problem on revise function to operate many commands once |
Posted: Thu Jan 14, 2010 1:47 pm |
|
|
Code: | void receive_packet()
{
int8 pn, pos, checksum, num_bytes, save_bytes;
num_bytes=read_usb();//get the number of bytes
buffer[0]=num_bytes;
save_bytes = num_bytes;//save a copy
pos=1;
while(num_bytes--)
buffer[pos++]=read_usb();
checksum=0;
for(pn=0; pn<save_bytes+1; pn++)
checksum ^= (int8)buffer[pn];
if(read_usb() == checksum)//if checksums match
{
delay_us(100);
if(input(RXF)==0)//if more data in FIFO
{
delay_ms(5);//still have data in the FIFO but not exceed 100 bytes, read out. Or error!
while(input(RXF)==0)//clear the FIFO
{
delay_ms(5);
read_usb();
}
send(0xAb);//error!
packet_ready=0;
}
else
for(num_bytes=0; num_bytes++; num_bytes=60000)
{
if(num_bytes<=100)
{
send(0x55);//no error
delay_us(100);
packet_ready=1;
}
}
else//checksum failed
{
send(0xaa);//error!
packet_ready=0;
}
strobe_SND();//send now
}
|
I have a problem of writing the function 'receive_packet'. This function can only operate one command (several lines) at once. But as I want it to read many commands and operate once, I tried to revise the code. After compiling, no results came out, either the only one command. The code above is what I revised. Could you help me with this? Thank you very much! The code below is the original code for one command.
Code: |
if(read_usb() == checksum)//if checksums match
{
delay_us(100);
if(input(RXF)==0)//if more data in FIFO
{
//still have data in the FIFO -- ERROR!
delay_ms(5);
while(input(RXF)==0)//clear the FIFO
{
delay_ms(5);
read_usb();
}
send(0xAb);//error!
packet_ready=0;
}
else
{
send(0x55);//no error
delay_us(100);
packet_ready=1;
}
}
else//checksum failed
{
send(0xaa);//error!
packet_ready=0;
}
strobe_SND();//send now
} |
|
|