void zb_sniffer_logic_iteration() { #ifndef ZB_SNIFFER_USB_TRACE zb_uint8_t nbytes = bufNumBytes(&rbTxBuf); if (bufNumBytes(&rbTxBuf) && !SER_CTX().tx_in_progress) { ZB_SET_SERIAL_TRANSMIT_FLAG(); } else { ZB_GO_IDLE(); } #else usbUartProcess(); #endif }
/*********************************************************************************** * @fn usbOutProcess * * @brief Handle traffic flow from USB to RF. * * @param none * * @return none */ static void usbOutProcess(void) { uint8 length, nToSend; // If new packet is ready in USB FIFO halIntOff(); oldEndpoint = USBFW_GET_SELECTED_ENDPOINT(); USBFW_SELECT_ENDPOINT(4); if (USBFW_OUT_ENDPOINT_DISARMED() ) { // Get length of USB packet, this operation must not be interrupted. length = USBFW_GET_OUT_ENDPOINT_COUNT_LOW(); length+= (int)(USBFW_GET_OUT_ENDPOINT_COUNT_HIGH()) >> 8; // Calculate number of bytes available in RF buffer; and the number // of bytes we may transfer in this operation. nToSend= MIN(BUF_SIZE - bufNumBytes(&rbRxBuf), length); // Space available in UART RX buffer ? if (nToSend>0) { // Read from USB FIFO usbfwReadFifo(&USBF4, nToSend, buffer); // Write to radio TX buffer bufPut(&rbRxBuf,buffer,nToSend); // If entire USB packet is read from buffer if (length == nToSend) { USBFW_SELECT_ENDPOINT(4); USBFW_ARM_OUT_ENDPOINT(); } } } USBFW_SELECT_ENDPOINT(oldEndpoint); halIntOn(); }
/*********************************************************************************** * @fn usbInProcess * * @brief Handle traffic flow from RF to USB. * * @param none * * @return none */ static void usbInProcess(void) { uint8 length; // USB ready to accept new IN packet halIntOff(); oldEndpoint = USBFW_GET_SELECTED_ENDPOINT(); USBFW_SELECT_ENDPOINT(4); // The IN endpoint is ready to accept data if ( USBFW_IN_ENDPOINT_DISARMED() ) { // Number of bytes present in RF buffer length= bufNumBytes(&rbTxBuf); if (length>0) { // Limit the size if (length > USB_MAX_PACKET_SIZE) { length = USB_MAX_PACKET_SIZE; } // Read from UART TX buffer bufGet(&rbTxBuf,buffer,length); // Write to USB FIFO usbfwWriteFifo(&USBF4, length, buffer); // Flag USB IN buffer as not ready (disarming EP4) USBFW_SELECT_ENDPOINT(4); USBFW_ARM_IN_ENDPOINT(); // Send data to the host } } USBFW_SELECT_ENDPOINT(oldEndpoint); halIntOn(); }
/************************************************************************************ * @fn halUartGetNumRxBytes * * @brief Returns number of bytes in RX buffer * * @param none * * @return uint8 */ uint16 halUartGetNumRxBytes(void) { return bufNumBytes(&rbRxBuf); }