@@ -71,24 +71,37 @@ struct nrf_rpc_uart {
7171 struct k_mutex tx_lock ;
7272};
7373
74+ static void log_hexdump_dbg (const uint8_t * data , size_t length , const char * fmt , ...)
75+ {
76+ if (IS_ENABLED (CONFIG_NRF_RPC_TR_LOG_LEVEL_DBG )) {
77+ va_list ap ;
78+ char message [32 ];
79+
80+ va_start (ap , fmt );
81+ vsnprintk (message , sizeof (message ), fmt , ap );
82+ va_end (ap );
83+
84+ LOG_HEXDUMP_DBG (data , length , message );
85+ }
86+ }
87+
7488#define CRC_SIZE sizeof(uint16_t)
7589
7690static void send_byte (const struct device * dev , uint8_t byte );
7791
7892static void ack_rx (struct nrf_rpc_uart * uart_tr )
7993{
80- if (!IS_ENABLED (CONFIG_NRF_RPC_UART_RELIABLE )) {
81- return ;
82- }
83-
84- if (uart_tr -> rx_packet_len != CRC_SIZE ) {
94+ if (!IS_ENABLED (CONFIG_NRF_RPC_UART_RELIABLE ) || uart_tr -> rx_packet_len != CRC_SIZE ) {
95+ log_hexdump_dbg (uart_tr -> rx_packet , uart_tr -> rx_packet_len , ">>> RX invalid frame" );
8596 return ;
8697 }
8798
8899 uint16_t rx_ack = sys_get_le16 (uart_tr -> rx_packet );
89100
101+ LOG_DBG (">>> RX ack %04x" , rx_ack );
102+
90103 if (uart_tr -> ack_payload != rx_ack ) {
91- LOG_WRN ("Wrong ack. Expected: %#4x. Received: %#4x. " , uart_tr -> ack_payload , rx_ack );
104+ LOG_WRN ("Received ack %04x but expected %04x " , rx_ack , uart_tr -> ack_payload );
92105 return ;
93106 }
94107
@@ -106,7 +119,7 @@ static void ack_tx(struct nrf_rpc_uart *uart_tr, uint16_t ack_pld)
106119
107120 sys_put_le16 (ack_pld , ack );
108121 k_mutex_lock (& uart_tr -> ack_tx_lock , K_FOREVER );
109- LOG_HEXDUMP_DBG ( ack , sizeof ( ack ), "Tx ack" );
122+ LOG_DBG ( "<<< TX ack %04x" , ack_pld );
110123
111124 uart_poll_out (uart_tr -> uart , HDLC_CHAR_DELIMITER );
112125
@@ -182,7 +195,6 @@ static void hdlc_decode_byte(struct nrf_rpc_uart *uart_tr, uint8_t byte)
182195 }
183196
184197 if (uart_tr -> hdlc_state == HDLC_STATE_FRAME_FOUND ) {
185- LOG_HEXDUMP_DBG (uart_tr -> rx_packet , uart_tr -> rx_packet_len , "Received frame" );
186198 if (uart_tr -> rx_packet_len > CRC_SIZE ) {
187199 uart_tr -> rx_packet_len -= CRC_SIZE ;
188200 } else {
@@ -216,9 +228,13 @@ static void work_handler(struct k_work *work)
216228 crc_received = sys_get_le16 (uart_tr -> rx_packet + uart_tr -> rx_packet_len );
217229 crc_calculated =
218230 crc16_ccitt (0xffff , uart_tr -> rx_packet , uart_tr -> rx_packet_len );
231+
232+ log_hexdump_dbg (uart_tr -> rx_packet , uart_tr -> rx_packet_len ,
233+ ">>> RX packet %04x" , crc_received );
234+
219235 if (!crc_compare (crc_received , crc_calculated )) {
220- LOG_ERR ("Invalid CRC, calculated %4x received %4x" , crc_calculated ,
221- crc_received );
236+ LOG_ERR ("Invalid packet CRC: calculated %04x but received %04x" ,
237+ crc_calculated , crc_received );
222238 uart_tr -> rx_packet_len = 0 ;
223239 uart_tr -> hdlc_state = HDLC_STATE_UNSYNC ;
224240 continue ;
@@ -227,7 +243,7 @@ static void work_handler(struct k_work *work)
227243 ack_tx (uart_tr , crc_received );
228244
229245 if (rx_flip_check (uart_tr , crc_received )) {
230- LOG_WRN ("Duplicated frame was filtered (crc:%#4x) " , crc_received );
246+ LOG_WRN ("Duplicate packet %04x " , crc_received );
231247 } else {
232248 uart_tr -> receive_callback (transport , uart_tr -> rx_packet ,
233249 uart_tr -> rx_packet_len ,
@@ -240,7 +256,7 @@ static void work_handler(struct k_work *work)
240256
241257 ret = ring_buf_get_finish (& uart_tr -> rx_ringbuf , len );
242258 if (ret < 0 ) {
243- LOG_DBG ("Cannot flush ring buffer (%d) " , ret );
259+ LOG_DBG ("Cannot flush ring buffer: %d " , ret );
244260 }
245261 }
246262}
@@ -269,7 +285,7 @@ static void serial_cb(const struct device *uart, void *user_data)
269285 uint8_t dummy ;
270286
271287 /* No space in the ring buffer - consume byte. */
272- LOG_WRN ("RX ring buffer full. " );
288+ LOG_WRN ("RX ring buffer full" );
273289
274290 rx_len = uart_fifo_read (uart , & dummy , 1 );
275291 }
@@ -286,7 +302,6 @@ static int init(const struct nrf_rpc_tr *transport, nrf_rpc_tr_receive_handler_t
286302 struct nrf_rpc_uart * uart_tr = transport -> ctx ;
287303
288304 if (uart_tr -> transport != NULL ) {
289- LOG_DBG ("init not needed" );
290305 return 0 ;
291306 }
292307
@@ -295,7 +310,6 @@ static int init(const struct nrf_rpc_tr *transport, nrf_rpc_tr_receive_handler_t
295310 LOG_DBG ("init called" );
296311
297312 if (receive_cb == NULL ) {
298- LOG_ERR ("No transport receive callback" );
299313 return - NRF_EINVAL ;
300314 }
301315 uart_tr -> receive_callback = receive_cb ;
@@ -362,14 +376,13 @@ static int send(const struct nrf_rpc_tr *transport, const uint8_t *data, size_t
362376
363377 k_mutex_lock (& uart_tr -> tx_lock , K_FOREVER );
364378
365- LOG_HEXDUMP_DBG (data , length , "Sending frame" );
366-
367379 crc_val = crc16_ccitt (0xffff , data , length );
380+ crc_val = tx_flip (uart_tr , crc_val );
381+ log_hexdump_dbg (data , length , "<<< TX packet %04x" , crc_val );
368382
369383#if CONFIG_NRF_RPC_UART_RELIABLE
370384 int attempts = 0 ;
371385
372- crc_val = tx_flip (uart_tr , crc_val );
373386 uart_tr -> ack_payload = crc_val ;
374387 acked = false;
375388
@@ -396,9 +409,9 @@ static int send(const struct nrf_rpc_tr *transport, const uint8_t *data, size_t
396409 if (k_sem_take (& uart_tr -> ack_sem , K_MSEC (CONFIG_NRF_RPC_UART_ACK_WAITING_TIME )) ==
397410 0 ) {
398411 acked = true;
399- LOG_DBG ("Acked successfully. " );
412+ LOG_DBG ("Acked successfully" );
400413 } else {
401- LOG_WRN ("Ack timeout expired. " );
414+ LOG_WRN ("Ack timeout" );
402415 }
403416 } while (!acked && attempts < CONFIG_NRF_RPC_UART_TX_ATTEMPTS );
404417#endif /* CONFIG_NRF_RPC_UART_RELIABLE */
@@ -416,7 +429,7 @@ static void *tx_buf_alloc(const struct nrf_rpc_tr *transport, size_t *size)
416429
417430 data = k_malloc (* size );
418431 if (!data ) {
419- LOG_ERR ("Failed to allocate Tx buffer. " );
432+ LOG_ERR ("Failed to allocate TX buffer" );
420433 goto error ;
421434 }
422435
0 commit comments