fix: USB serial ZLP, shell locking and wrap-safe button repeat

- ChibiOS: send a zero length packet after any multiple of the bulk IN
  packet size (backport from ChibiOS 21.11)
- halconf.h: name the serial buffer settings the way this ChibiOS fork
  reads them (values equal to the defaults in use)
- shell_reset_console(): call the I-class queue functions locked
- VNAShell_executeLine(): enqueue the shell thread locked and only while
  the command is still pending
- btn_wait_release(): wrap-safe repeat timing

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
main
erikkaashoek 3 days ago
parent dda6f4ac8f
commit e580d23593

@ -1 +1 @@
Subproject commit ade76dea89cd093650552328e881252a06486094 Subproject commit 0cfe7f528599d634c7e77b27984b24b9ad0c4d4c

@ -302,11 +302,14 @@
* @brief Serial buffers size. * @brief Serial buffers size.
* @details Configuration parameter, you can change the depth of the queue * @details Configuration parameter, you can change the depth of the queue
* buffers depending on the requirements of your application. * buffers depending on the requirements of your application.
* @note The default is 64 bytes for both the transmission and receive * @note The default is 16 bytes for both the transmission and receive
* buffers. * buffers.
*/ */
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__) #if !defined(SERIAL_RX_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_BUFFERS_SIZE 64 #define SERIAL_RX_BUFFERS_SIZE 16
#endif
#if !defined(SERIAL_TX_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_TX_BUFFERS_SIZE 16
#endif #endif
/*===========================================================================*/ /*===========================================================================*/
@ -317,23 +320,25 @@
* @brief Serial over USB buffers size. * @brief Serial over USB buffers size.
* @details Configuration parameter, the buffer size must be a multiple of * @details Configuration parameter, the buffer size must be a multiple of
* the USB data endpoint maximum packet size. * the USB data endpoint maximum packet size.
* @note The default is 64 bytes for both the transmission and receive * @note The default is 256 bytes for both the transmission and receive
* buffers. * buffers.
*/ */
#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) #if !defined(SERIAL_USB_RX_BUFFERS_SIZE) || defined(__DOXYGEN__)
#ifdef TINYSA4 #define SERIAL_USB_RX_BUFFERS_SIZE 256
#define SERIAL_USB_BUFFERS_SIZE 128
#else
#define SERIAL_USB_BUFFERS_SIZE 128
#endif #endif
#if !defined(SERIAL_USB_TX_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_USB_TX_BUFFERS_SIZE 256
#endif #endif
/** /**
* @brief Serial over USB number of buffers. * @brief Serial over USB number of buffers.
* @note The default is 2 buffers. * @note The default is 2 buffers.
*/ */
#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__) #if !defined(SERIAL_USB_RX_BUFFERS_NUMBER) || defined(__DOXYGEN__)
#define SERIAL_USB_BUFFERS_NUMBER 2 #define SERIAL_USB_RX_BUFFERS_NUMBER 2
#endif
#if !defined(SERIAL_USB_TX_BUFFERS_NUMBER) || defined(__DOXYGEN__)
#define SERIAL_USB_TX_BUFFERS_NUMBER 2
#endif #endif
/*===========================================================================*/ /*===========================================================================*/

@ -2708,6 +2708,7 @@ void shell_update_speed(void){
} }
void shell_reset_console(void){ void shell_reset_console(void){
osalSysLock(); // I-class calls below, must run locked
// Reset I/O queue over USB (for USB need also connect/disconnect) // Reset I/O queue over USB (for USB need also connect/disconnect)
if (usb_IsActive()){ if (usb_IsActive()){
if (config._mode & _MODE_SERIAL) if (config._mode & _MODE_SERIAL)
@ -2720,7 +2721,8 @@ void shell_reset_console(void){
// iqResetI(&SD1.iqueue); // iqResetI(&SD1.iqueue);
qResetI(&SD1.oqueue); qResetI(&SD1.oqueue);
qResetI(&SD1.iqueue); qResetI(&SD1.iqueue);
osalOsRescheduleS();
osalSysUnlock();
} }
@ -2901,7 +2903,12 @@ static void VNAShell_executeLine(char *line)
int timeout_count = 0; int timeout_count = 0;
msg_t result; msg_t result;
do { do {
result = osalThreadEnqueueTimeoutS(&shell_thread, MS2ST(5000)); // 5 second timeout chSysLock(); // S-class call, must run locked
if (shell_function)
result = osalThreadEnqueueTimeoutS(&shell_thread, MS2ST(5000)); // 5 second timeout
else
result = MSG_OK;
chSysUnlock();
if (result == MSG_TIMEOUT) { if (result == MSG_TIMEOUT) {
timeout_count++; timeout_count++;
if (timeout_count > 3) { if (timeout_count > 3) {

@ -269,13 +269,13 @@ static int btn_wait_release(void)
} }
if (dt > BUTTON_DOWN_LONG_TICKS && if (dt > BUTTON_DOWN_LONG_TICKS &&
ticks > last_button_repeat_ticks) { ticks - last_button_repeat_ticks > BUTTON_REPEAT_TICKS) { // elapsed time, wrap safe
int status = 0; int status = 0;
if (cur_button & (1<<BIT_DOWN1)) if (cur_button & (1<<BIT_DOWN1))
status |= (config.flip ? EVT_UP: EVT_DOWN) | EVT_REPEAT; status |= (config.flip ? EVT_UP: EVT_DOWN) | EVT_REPEAT;
if (cur_button & (1<<BIT_UP1)) if (cur_button & (1<<BIT_UP1))
status |= (config.flip ? EVT_DOWN:EVT_UP) | EVT_REPEAT; status |= (config.flip ? EVT_DOWN:EVT_UP) | EVT_REPEAT;
last_button_repeat_ticks = ticks + BUTTON_REPEAT_TICKS; last_button_repeat_ticks = ticks;
return status; return status;
} }
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.