xmodem.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <arm/NXP/LPC17xx/LPC17xx.h>
  2. #include "config.h"
  3. #include "timer.h"
  4. #include "uart.h"
  5. #include "ff.h"
  6. #include "xmodem.h"
  7. void xmodem_rxfile(FIL* fil) {
  8. uint8_t rxbuf[XMODEM_BLKSIZE], sum=0/*, sender_sum*/;
  9. /* uint8_t blknum, blknum2;*/
  10. uint8_t count;
  11. uint32_t totalbytes = 0;
  12. uint32_t totalwritten = 0;
  13. UINT written;
  14. FRESULT res;
  15. uart_flush();
  16. do {
  17. delay_ms(3000);
  18. uart_putc(ASC_NAK);
  19. } while (uart_getc() != ASC_SOH);
  20. do {
  21. /*blknum=*/uart_getc();
  22. /*blknum2=*/uart_getc();
  23. for(count=0; count<XMODEM_BLKSIZE; count++) {
  24. sum += rxbuf[count] = uart_getc();
  25. totalbytes++;
  26. }
  27. /*sender_sum =*/ uart_getc();
  28. res=f_write(fil, rxbuf, XMODEM_BLKSIZE, &written);
  29. totalwritten += written;
  30. uart_putc(ASC_ACK);
  31. } while (uart_getc() != ASC_EOT);
  32. uart_putc(ASC_ACK);
  33. uart_flush();
  34. sleep_ms(1000);
  35. sender_sum = blknum + blknum2;
  36. printf("%x:%x:%x\n", blknum, blknum2, sender_sum);
  37. printf("received %ld bytes, wrote %ld bytes. last res = %d\n", totalbytes, totalwritten, res);
  38. }