void cmdPoll() { #if defined CFG_PRINTF_UART while (uartRxBufferDataPending()) { uint8_t c = uartRxBufferRead(); cmdRx(c); } #endif #if defined CFG_PRINTF_USBCDC int numBytesToRead, numBytesRead, numAvailByte; CDC_OutBufAvailChar (&numAvailByte); if (numAvailByte > 0) { numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte; numBytesRead = CDC_RdOutBuf (&usbcdcBuf[0], &numBytesToRead); int i; for (i = 0; i < numBytesRead; i++) { cmdRx(usbcdcBuf[i]); } } #endif }
void cmdPoll() { #if defined CFG_PRINTF_UART while (uartRxBufferDataPending()) { uint8_t c = uartRxBufferRead(); cmdRx(c); } #endif }
void cliPoll() { #if defined CFG_BSP_PRINTF_UART while (uartRxBufferDataPending()) { uint8_t c = uartRxBufferRead(); cliRx(c); } #endif #if defined(CFG_LIB_USB) && defined(CFG_LIB_PRINTF_USBCDC) if (usb_isConfigured()) { uint8_t c; while(usb_cdc_getc(&c)) { cliRx(c); } } #endif }
pn532_error_t pn532_bus_SendCommand(const byte_t * pbtData, const size_t szData) { pn532_pcb_t *pn532 = pn532GetPCB(); // Check if we're busy if (pn532->state == PN532_STATE_BUSY) { return PN532_ERROR_BUSY; } // Flag the stack as busy pn532->state = PN532_STATE_BUSY; // Every packet must start with "00 00 ff" byte_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; size_t szFrame = 0; // Build the frame pn532_bus_BuildFrame (abtFrame, &szFrame, pbtData, szData); // Keep track of the last command that was sent pn532->lastCommand = pbtData[0]; // Output the frame data for debugging if requested #ifdef PN532_DEBUGMODE PN532_DEBUG("Sending (%02d): ", szFrame); pn532PrintHex(abtFrame, szFrame); #endif // Send data to the PN532 uartSend (abtFrame, szFrame); // Wait for ACK byte_t abtRxBuf[6]; uart_pcb_t *uart = uartGetPCB(); delay(10); // FIXME: How long should we wait for ACK? if (uart->rxfifo.len < 6) { // Unable to read ACK #ifdef PN532_DEBUGMODE PN532_DEBUG ("Unable to read ACK%s", CFG_PRINTF_NEWLINE); #endif pn532->state = PN532_STATE_READY; return PN532_ERROR_NOACK; } // Read ACK ... this will also remove it from the buffer const byte_t abtAck[6] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; abtRxBuf[0] = uartRxBufferRead(); abtRxBuf[1] = uartRxBufferRead(); abtRxBuf[2] = uartRxBufferRead(); abtRxBuf[3] = uartRxBufferRead(); abtRxBuf[4] = uartRxBufferRead(); abtRxBuf[5] = uartRxBufferRead(); // Make sure the received ACK matches the prototype if (0 != (memcmp (abtRxBuf, abtAck, 6))) { #ifdef PN532_DEBUGMODE PN532_DEBUG ("Invalid ACK: "); pn532PrintHex(abtRxBuf, 6); PN532_DEBUG("%s", CFG_PRINTF_NEWLINE); #endif pn532->state = PN532_STATE_READY; return PN532_ERROR_INVALIDACK; } pn532->state = PN532_STATE_READY; return PN532_ERROR_NONE; }