uint8_t FileBuf[1024];
uint16_t FileLen = 0;
//XModem回调
void XModemCallback(uint16_t number, uint8_t *pbuf)
{
if(pbuf != NULL)
{
memcpy(&FileBuf[FileLen], pbuf, 128);
FileLen += 128;
}
}
//XModem 发送接口
void XmodemSend(uint8_t cmd)
{
bHalUartSend(HAL_LOG_UART, &cmd, 1);
}
//串口接收空闲,需要接收空闲后喂数据
int UartIdleCallback(uint8_t *pbuf, uint16_t len)
{
bXmodem128Parse(pbuf, len);
return 0;
}
//建立串口接收实例
bUTIL_UART_INSTANCE(XmodemRec, 200, 50, UartIdleCallback);
int main()
{
...
bInit();
bXmodem128Init(XModemCallback, XmodemSend);
//开始传输
bXmodem128Start();
...
}
void USART1_IRQHandler()
{
uint8_t uart_dat = 0;
if (USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
uart_dat = USART_ReceiveData(USART1);
bUtilUartRxHandler(&XmodemRec, uart_dat);
}
}