get rid of OUT queue, caused missed frames

retry
Ondřej Hruška 6 years ago
parent 8efe91c8ed
commit 78137628ba
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      Inc/gex_gateway.h
  2. 13
      Src/gex_gateway.c
  3. 16
      Src/usbd_cdc_if.c

@ -7,5 +7,6 @@
#include "main.h" #include "main.h"
void gw_process(void); void gw_process(void);
void gw_handle_usb_out(uint8_t *buffer);
#endif //GEX_NRF_GEX_GATEWAY_H #endif //GEX_NRF_GEX_GATEWAY_H

@ -42,11 +42,8 @@ void start_slave_cmd(uint8_t slave_addr, uint16_t frame_len, uint8_t cksum)
msg4slave_cksum = cksum; msg4slave_cksum = cksum;
} }
/** called from the main loop, periodically */ void gw_handle_usb_out(uint8_t *buffer)
void gw_process(void)
{ {
static uint8_t buffer[MQ_SLOT_LEN];
while (mq_read(&usb_rxq, buffer)) { // greedy - handle as many as possible
dbg("Handling frame."); dbg("Handling frame.");
if (urx_state == URXS_IDLE) { if (urx_state == URXS_IDLE) {
PayloadParser pp = pp_start(buffer, MQ_SLOT_LEN, NULL); PayloadParser pp = pp_start(buffer, MQ_SLOT_LEN, NULL);
@ -111,5 +108,13 @@ void gw_process(void)
} }
} }
} }
/** called from the main loop, periodically */
void gw_process(void)
{
// static uint8_t buffer[MQ_SLOT_LEN];
// while (mq_read(&usb_rxq, buffer)) { // greedy - handle as many as possible
// gw_handle_usb_out(buffer);
// }
} }

@ -50,6 +50,7 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include <debug.h> #include <debug.h>
#include <msg_queue.h> #include <msg_queue.h>
#include <gex_gateway.h>
#include "usbd_cdc_if.h" #include "usbd_cdc_if.h"
/* USER CODE BEGIN INCLUDE */ /* USER CODE BEGIN INCLUDE */
@ -298,10 +299,15 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
// queue the frame // queue the frame
dbg("USB rx frame"); dbg("USB rx frame");
bool suc = mq_post(&usb_rxq, Buf, *Len); gw_handle_usb_out(Buf); // this expects full 64byte frames always starting with magic or useful data
if (!suc) {
dbg("USB rxq overrun!"); // handled immediately in the interrupt to block USB (NAK)
}
//
// bool suc = mq_post(&usb_rxq, Buf, *Len);
// if (!suc) {
// dbg("USB rxq overrun!");
// }
return (USBD_OK); return (USBD_OK);
/* USER CODE END 6 */ /* USER CODE END 6 */
@ -336,6 +342,8 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
// TODO add Tx Done notify
/** /**
* @} * @}
*/ */

Loading…
Cancel
Save