static int rcvr_datablock ( BYTE *buff, /* Data buffer to store received data */ UINT btr /* Byte count (must be multiple of 4) */ ) { BYTE token; BYTE wt = 200; do { /* Wait for data packet in timeout of 200ms */ token = xchg_spi(0xFF); if (token != 0xFF) break; delay_ms(1); } while (--wt); if (token != 0xFE) return 0; /* If not valid data token, retutn with error */ rcvr_spi_multi(buff, btr); /* Receive the data block into buffer */ xchg_spi(0xFF); /* Discard CRC */ xchg_spi(0xFF); return 1; /* Return with success */ }
static int rcvr_datablock ( /* 1:OK, 0:Error */ BYTE *buff, /* Data buffer */ UINT btr /* Data block length (byte) */ ) { BYTE token; //Timer1 = 200; set_timems(200); do { // Wait for DataStart token in timeout of 200ms token = TM_SPI_Send(FATFS_SPI, 0xFF); // This loop will take a time. Insert rot_rdq() here for multitask envilonment. } while ((token == 0xFF) && check_time()); if (token != 0xFE) { printf("rcvr_datablock: token != 0xFE"); return 0; // Function fails if invalid DataStart token or timeout } rcvr_spi_multi(buff, btr); // Store trailing data to the buffer TM_SPI_Send(FATFS_SPI, 0xFF); TM_SPI_Send(FATFS_SPI, 0xFF); // Discard CRC return 1; // Function succeeded }