Main Page | File List | Globals

receive.c

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation.
00023 #include "xmodem.h"
00024 
00025 extern struct global
00026 {
00027   volatile unsigned char *recv_ptr;
00028   volatile unsigned char buffer_status;
00029   volatile unsigned char recv_error;
00030   volatile unsigned char t1_timed_out;
00031 } gl;
00032 
00033 
00034 void receive(volatile unsigned char *bufptr1)
00035 {
00036   unsigned char packet = 0;    // status flag
00037   unsigned char packet_number; // represents 'last successfully received packet'
00038 
00039   packet_number = 0x00;        // initialise to first xmodem packet number - 1
00040   gl.recv_ptr = bufptr1;       // point to recv buffer
00041 
00042   sendc();                     // send a 'c' until the buffer gets full
00043 
00044   while (packet != end)        // get remainder of file
00045   {
00046     recv_wait();               // wait for error or buffer full
00047     packet = validate_packet((unsigned char*)bufptr1,&packet_number);  // validate the packet
00048     gl.recv_ptr = bufptr1;     // re-initialize buffer pointer before acknowledging
00049     switch(packet)
00050     {
00051       case good:
00052         // insert a data handler here,
00053         // for example, write buffer to a flash device
00054         break;
00055       case dup:
00056         // a counter for duplicate packets could be added here, to enable a
00057         // for example, exit gracefully if too many consecutive duplicates,
00058         // otherwise do nothing, we will just ack this
00059         break;
00060       case end:
00061         // do nothing, we will exit
00062         break;
00063       default:
00064         // bad, timeout or error -
00065         // if required, insert an error handler of some description,
00066         // for example, exit gracefully if too many errors
00067         break; // statement just to eliminate compiler warning
00068     }
00069     respond(packet);                  // ack or nak
00070   }// end of file transmission
00071 }

Generated on Tue Aug 23 13:47:52 2005 for Atmel AVR Application Note by  doxygen 1.4.4