xmodem.c 950 B

12345678910111213141516171819202122232425262728293031323334353637
  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. printf("received %ld bytes, wrote %ld bytes. last res = %d\n", totalbytes, totalwritten, res);
  36. }