@@ -67,6 +67,16 @@ enum uart_host_command_state {
67
67
UART_HOST_CMD_RX_OVERRUN ,
68
68
};
69
69
70
+ static const char * const state_name [] = {
71
+ [UART_HOST_CMD_STATE_DISABLED ] = "DISABLED" ,
72
+ [UART_HOST_CMD_READY_TO_RX ] = "READY_TO_RX" ,
73
+ [UART_HOST_CMD_RECEIVING ] = "RECEIVING" ,
74
+ [UART_HOST_CMD_PROCESSING ] = "PROCESSING" ,
75
+ [UART_HOST_CMD_SENDING ] = "SENDING" ,
76
+ [UART_HOST_CMD_RX_BAD ] = "RX_BAD" ,
77
+ [UART_HOST_CMD_RX_OVERRUN ] = "RX_OVERRUN" ,
78
+ };
79
+
70
80
struct ec_host_cmd_uart_ctx {
71
81
const struct device * uart_dev ;
72
82
struct ec_host_cmd_rx_ctx * rx_ctx ;
@@ -115,27 +125,7 @@ static void rx_timeout(struct k_work *work)
115
125
CONTAINER_OF (dwork , struct ec_host_cmd_uart_ctx , timeout_work );
116
126
int res ;
117
127
118
- switch (hc_uart -> state ) {
119
- case UART_HOST_CMD_RECEIVING :
120
- /* If state is receiving then timeout was hit due to underrun */
121
- LOG_ERR ("Request underrun detected" );
122
- break ;
123
- case UART_HOST_CMD_RX_OVERRUN :
124
- /* If state is rx_overrun then timeout was hit because
125
- * process request was cancelled and extra rx bytes were
126
- * dropped
127
- */
128
- LOG_ERR ("Request overrun detected" );
129
- break ;
130
- case UART_HOST_CMD_RX_BAD :
131
- /* If state is rx_bad then packet header was bad and process
132
- * request was cancelled to drop all incoming bytes.
133
- */
134
- LOG_ERR ("Bad packet header detected" );
135
- break ;
136
- default :
137
- LOG_ERR ("Request timeout mishandled, state: %d" , hc_uart -> state );
138
- }
128
+ LOG_ERR ("Request error in state: %s" , state_name [hc_uart -> state ]);
139
129
140
130
res = uart_rx_disable (hc_uart -> uart_dev );
141
131
res = uart_rx_enable (hc_uart -> uart_dev , hc_uart -> rx_ctx -> buf , hc_uart -> rx_buf_size , 0 );
@@ -157,7 +147,7 @@ static void uart_callback(const struct device *dev, struct uart_event *evt, void
157
147
K_MSEC (CONFIG_EC_HOST_CMD_BACKEND_UART_TIMEOUT ));
158
148
} else if (hc_uart -> state == UART_HOST_CMD_PROCESSING ||
159
149
hc_uart -> state == UART_HOST_CMD_SENDING ) {
160
- LOG_ERR ("UART HOST CMD ERROR: Received data while processing or sending" );
150
+ LOG_ERR ("Received data while in state: %s" , state_name [ hc_uart -> state ] );
161
151
return ;
162
152
} else if (hc_uart -> state == UART_HOST_CMD_RX_BAD ||
163
153
hc_uart -> state == UART_HOST_CMD_RX_OVERRUN ) {
@@ -215,13 +205,13 @@ static void uart_callback(const struct device *dev, struct uart_event *evt, void
215
205
break ;
216
206
case UART_TX_DONE :
217
207
if (hc_uart -> state != UART_HOST_CMD_SENDING ) {
218
- LOG_ERR ("UART HOST CMD ERROR: unexpected end of sending" );
208
+ LOG_ERR ("Unexpected end of sending" );
219
209
}
220
210
/* Receiving is already enabled in the send function. */
221
211
hc_uart -> state = UART_HOST_CMD_READY_TO_RX ;
222
212
break ;
223
213
case UART_RX_STOPPED :
224
- LOG_ERR ("UART HOST CMD ERROR: Receiving data stopped" );
214
+ LOG_ERR ("Receiving data stopped" );
225
215
break ;
226
216
default :
227
217
break ;
@@ -271,7 +261,7 @@ static int ec_host_cmd_uart_send(const struct ec_host_cmd_backend *backend)
271
261
int ret ;
272
262
273
263
if (hc_uart -> state != UART_HOST_CMD_PROCESSING ) {
274
- LOG_ERR ("UART HOST CMD ERROR: unexpected state while sending" );
264
+ LOG_ERR ("Unexpected state while sending" );
275
265
}
276
266
277
267
/* The state is changed to UART_HOST_CMD_READY_TO_RX in the UART_TX_DONE event */
@@ -291,7 +281,7 @@ static int ec_host_cmd_uart_send(const struct ec_host_cmd_backend *backend)
291
281
/* If sending fails, reset the state */
292
282
if (ret ) {
293
283
hc_uart -> state = UART_HOST_CMD_READY_TO_RX ;
294
- LOG_ERR ("UART HOST CMD ERROR: sending failed" );
284
+ LOG_ERR ("Sending failed" );
295
285
}
296
286
297
287
return ret ;
0 commit comments