All pastes #838888 Raw Edit

Laurence

public c v1 · immutable
#838888 ·published 2007-12-30 18:57 UTC
rendered paste body
#include <avr/interrupt.h>#include <stdio.h>#include <avr/io.h>#include <stdlib.h>#include <util/delay.h>#include <avr/pgmspace.h>#include "global.h"#include "uart.h"#include "buffer.h"#include "avrlibdefs.h"#include "avrlibtypes.h"#include "diskio.h"#include "tff.h"#include "integer.h"#define u08 unsigned charDWORD get_fattime(void);void die(FRESULT);int put_char0(char c, FILE *stream);int get_char0(FILE *stream); FILE mystdio0;int get_char0(FILE* stream){ int c=-1; while(c==-1) {c=uartGetByte();} //getchar gets the stream, loop until we get something return (u08) c;} int put_char0(char c, FILE *stream){   if(uartReadyTx || !uartBufferedTx ) //if buffer is empty or we arent buffered   {uartSendByte(c);                  //sends directly to uart	return 0;   }   else   {    //while(!bufferAddToEnd(Txbuff0,c));    //send the character to buffer    if(uartAddToTxBuffer(c))    {return 0;}    else    {return -1;}   }}DWORD get_fattime(void){return 0;                                            //no clock used to save code space}void die(FRESULT argument){printf("Error:%d\r\n",(int)argument);}int main(){char stringy[20];DDRB=0b00000010;int x;sbi(PORTB,1);_delay_ms(5);cbi(PORTB,1);_delay_ms(10);for(x=0;x<100;x++){_delay_ms(10);}cbi(PORTB,1);FILE mystdio0 = FDEV_SETUP_STREAM(put_char0, get_char0, _FDEV_SETUP_RW);  //so we can printf to the radioFATFS fs;            // Work area (file system object) for logical driveFIL fsrc, fdst;      // file objectsBYTE buffer[256];   // file copy bufferFRESULT res;         // FatFs function common result codeUINT br, bw;         // File R/W countDDRC=0x80;           // power to card outputstdout = &mystdio0; //set our stdio out functionstdin = &mystdio0; // set our stdio in funciton uartInit(); uartSetBaudRate(4800);sei();sbi(PORTB,1);for(x=0;x<100;x++){_delay_ms(10);}cbi(PORTB,1);printf("Danger, unplug the programming lines\r\n");scanf("%s",stringy);sbi(PORTB,1);for(x=0;x<100;x++){_delay_ms(10);}cbi(PORTB,1);   // Register a work area for logical drive 0  f_mount(0, &fs);    // Open source file  res = f_open(&fsrc, "srcfile.dat", FA_OPEN_EXISTING | FA_READ);  if (res) die(res);    // Create destination file  res = f_open(&fdst, "dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);  if (res) die(res);    // Copy source to destination    for (;;) {        res = f_read(&fsrc, buffer, sizeof(buffer), &br);        if (res || br == 0) break;   // error or eof        res = f_write(&fdst, buffer, br, &bw);        if (res || bw < br) break;   // error or disk full    }    // Close all files    f_close(&fsrc);    f_close(&fdst);    // Unregister a work area before discard it    f_mount(0, NULL);return 0;}