Skip to content

Commit a171f29

Browse files
andreasmuellerrettichschnidi
authored andcommitted
[sg noup] ppp: yield in PPP driver
On the Zephyr RM gateway, when we receive a packet via Lemonbeat and it is sent over PPP, this previously blocked the lb_radio driver from sending a MAC ACK (this is independent of thread priorities if the PPP code never yields). This was previously addressed by a k_sleep(K_MSEC(50)) before handing over new packets from Lemonbeat to PPP in sg_ppp_bridge_process_pkt(), but yielding in ppp_send_flush() seems cleaner. Issue regarding upstreaming: zephyrproject-rtos#70696 Summary: Zephyr does not want this implementation upstreamed; suggestion is to rewrite PPP to use the interrupt-driver UART API. If/when this is done, we can potentially switch and drop this patch. (cherry picked from commit 1d77de7) (squashed commit 3a0993d)
1 parent 554cdf1 commit a171f29

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/net/ppp.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ LOG_MODULE_REGISTER(net_ppp, LOG_LEVEL);
3939
#define UART_BUF_LEN CONFIG_NET_PPP_UART_BUF_LEN
4040
#define UART_TX_BUF_LEN CONFIG_NET_PPP_ASYNC_UART_TX_BUF_LEN
4141

42+
/* yield control every N bytes so that higher-priority threads can run
43+
* (note: N=28 should be about 2 ms at 115200 bps)
44+
*/
45+
#define UART_YIELD_INTERVAL_BYTES 28
46+
47+
#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_ppp_uart), current_speed)
48+
BUILD_ASSERT(UART_YIELD_INTERVAL_BYTES * 8 * 1000 /
49+
DT_PROP(DT_CHOSEN(zephyr_ppp_uart), current_speed) <= 5,
50+
"current UART k_yield() interval & speed leads to blocking time > 5 ms");
51+
#endif
52+
4253
enum ppp_driver_state {
4354
STATE_HDLC_FRAME_START,
4455
STATE_HDLC_FRAME_ADDRESS,
@@ -403,6 +414,12 @@ static int ppp_send_flush(struct ppp_driver_context *ppp, int off)
403414
} else {
404415
while (off--) {
405416
uart_poll_out(ppp->dev, *buf++);
417+
static uint8_t counter = 0;
418+
counter++;
419+
if (counter % UART_YIELD_INTERVAL_BYTES == 0) {
420+
counter = 0;
421+
k_yield();
422+
}
406423
}
407424
}
408425

0 commit comments

Comments
 (0)