Skip to content

Commit 0b0505a

Browse files
Damian-Nordicrlubos
authored andcommitted
samples: nrf_rpc: ps_server: RPC alive LED
1. Add nrf_rpc_uart_initialized_hook() that is called when an nRF RPC UART transport instance gets ready to receive packets. 2. Use the hook in the PS server sample to toggle the LED selected with /alias/rpc-alive-led DTS property when the RPC transport is ready. Signed-off-by: Damian Krolik <[email protected]>
1 parent f7e5433 commit 0b0505a

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

include/nrf_rpc/nrf_rpc_uart.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ extern "C" {
3131
*/
3232
#define NRF_RPC_UART_TRANSPORT(node_id) _CONCAT(nrf_rpc_tr_, DT_DEP_ORD(node_id))
3333

34+
/**
35+
* @brief Notifies that nRF RPC UART transport is ready to receive packets.
36+
*
37+
* This function is called by the nRF RPC UART transport implementation as soon as
38+
* a transport instance is initialized and ready to receive nRF RPC packets.
39+
*
40+
* @note The nRF RPC transport implementation provides an empty, weak definition of this
41+
* function, which the application can override if needed.
42+
*
43+
* @param uart_dev The UART device for which the transport has just been initialized.
44+
*/
45+
extern void nrf_rpc_uart_initialized_hook(const struct device *uart_dev);
46+
3447
/**
3548
* @}
3649
*/

samples/nrf_rpc/protocols_serialization/server/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ config NRF_PS_SERVER_FATAL_ERROR_TRIGGER
1515
provides an RPC client with access to the crash log stored in the retained
1616
RAM partition.
1717

18+
config NRF_PS_SERVER_RPC_ALIVE_LED
19+
bool "RPC alive LED"
20+
default y
21+
depends on $(dt_alias_enabled,rpc-alive-led)
22+
help
23+
Turns on the LED selected with "/alias/rpc-alive-led" DTS property when
24+
the UART transport is alive and ready to receive nRF RPC packets.
25+
1826
module = NRF_PS_SERVER
1927
module-str = nrf_ps_server
2028
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

samples/nrf_rpc/protocols_serialization/server/boards/nrf52840dk_nrf52840.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
chosen {
88
nordic,rpc-uart = &uart1;
99
};
10+
11+
aliases {
12+
rpc-alive-led = &led0;
13+
};
1014
};
1115

1216
&uart1 {

samples/nrf_rpc/protocols_serialization/server/boards/nrf54l15dk_nrf54l15_cpuapp.overlay

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
nordic,rpc-uart = &uart21;
99
};
1010

11-
/* delete all buttons except button0 to free GPIO pins assigned to uart21 below */
1211
aliases {
12+
rpc-alive-led = &led0;
13+
14+
/* delete all buttons except button0 to free GPIO pins assigned to uart21 below */
1315
/delete-property/ sw1;
1416
/delete-property/ sw2;
1517
/delete-property/ sw3;

samples/nrf_rpc/protocols_serialization/server/src/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include <zephyr/drivers/gpio.h>
78
#include <zephyr/logging/log.h>
89

910
#include <nrf_rpc.h>
@@ -15,6 +16,21 @@ static void err_handler(const struct nrf_rpc_err_report *report)
1516
LOG_ERR("nRF RPC error %d ocurred. See nRF RPC logs for more details", report->code);
1617
}
1718

19+
#ifdef CONFIG_NRF_PS_SERVER_RPC_ALIVE_LED
20+
void nrf_rpc_uart_initialized_hook(const struct device *uart_dev)
21+
{
22+
const struct gpio_dt_spec alive_gpio = GPIO_DT_SPEC_GET(DT_ALIAS(rpc_alive_led), gpios);
23+
int ret;
24+
25+
__ASSERT_NO_MSG(uart_dev == DEVICE_DT_GET(DT_CHOSEN(nordic_rpc_uart)));
26+
ret = gpio_pin_configure_dt(&alive_gpio, GPIO_OUTPUT_ACTIVE);
27+
28+
if (ret) {
29+
LOG_ERR("Failed to configure RPC alive GPIO: %d", ret);
30+
}
31+
}
32+
#endif
33+
1834
int main(void)
1935
{
2036
int ret;

subsys/nrf_rpc/nrf_rpc_uart.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ static int init(const struct nrf_rpc_tr *transport, nrf_rpc_tr_receive_handler_t
353353
uart_tr->hdlc_state = HDLC_STATE_UNSYNC;
354354
uart_tr->rx_packet_len = 0;
355355
uart_irq_rx_enable(uart_tr->uart);
356+
nrf_rpc_uart_initialized_hook(uart_tr->uart);
356357

357358
return 0;
358359
}
@@ -449,6 +450,10 @@ static void tx_buf_free(const struct nrf_rpc_tr *transport, void *buf)
449450
k_free(buf);
450451
}
451452

453+
__weak void nrf_rpc_uart_initialized_hook(const struct device *uart_dev)
454+
{
455+
}
456+
452457
const struct nrf_rpc_tr_api nrf_rpc_uart_service_api = {
453458
.init = init,
454459
.send = send,

0 commit comments

Comments
 (0)