Main Page | File List | Globals

sendc.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 void sendc(void) {
00034 
00035     // 3 second timeout
00036     // 8MHz / 1024 = 7813 Hz
00037     // 7813 Hz = 128 us
00038     // 3 seconds / 128 us = 23438
00039     // 65536 - 23438 = 42098 = a472
00040     // interrupt on ffff to 0000 transition
00041     TCNT1 = 0xA472;
00042     TCCR1B = 0x00; // disable timer/counter 1 clock
00043 
00044     // enable entry into while loops
00045     gl.buffer_status = empty;
00046     gl.t1_timed_out = FALSE;
00047     gl.recv_error = FALSE; // checked in validate_packet for framing or overruns
00048 
00049     // send character 'C' until we get a packet from the sender
00050     while (!gl.buffer_status)
00051     {
00052         // tell sender CRC mode
00053         while (!(UCSR0A & 0x20)); // wait till Data register is empty
00054         UDR0 = CRCCHR; // signal transmitter that I'm ready in CRC mode ... 128 byte packets
00055         TCCR1B = 0x05; // timer/counter 1 clock / 1024
00056 
00057         // wait for timeout or recv buffer to fill
00058         while (!gl.t1_timed_out && !gl.buffer_status);
00059 
00060                                     // turn off timer
00061         TCCR1B = 0x00;              // disable timer/counter 1 clock
00062 
00063         if (gl.t1_timed_out)                  // start wait loop again
00064         {
00065             gl.t1_timed_out = FALSE;
00066             TCNT1 = 0xA472;           // load counter ... start over
00067         }
00068     }
00069 }

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