• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <driver/hal/hal_uart_types.h>
18 #include <components/log.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 typedef struct {
25 	uint32_t size;
26 	uint32_t in;
27 	uint32_t out;
28 	uint32_t last_value;
29 	uint32_t put_cnt;
30 	uint32_t full_cnt;
31 	uint32_t empty_cnt;
32 } uart_statis_kfifo_t;
33 
34 typedef struct {
35 	uint32_t uart_isr_cnt;
36 	uint32_t rx_isr_cnt;
37 	uint32_t rx_fifo_cnt;
38 	uint32_t recv_timeout_cnt;
39 	uart_statis_kfifo_t kfifo_status;
40 } uart_statis_t;
41 
42 #if CONFIG_UART_STATIS
43 
44 #define UART_STATIS_DEC()  uart_statis_t* uart_statis = NULL
45 #define UART_STATIS_GET(_statis, _id) (_statis) = uart_statis_get_statis((_id))
46 
47 #define UART_STATIS_SET(_statis, _v) do{\
48 		(_statis) = (_v);\
49 	} while(0)
50 
51 #define UART_STATIS_ADD(_statis, _v) do{\
52 		(_statis) += (_v);\
53 	} while(0)
54 
55 bk_err_t uart_statis_init(void);
56 bk_err_t uart_statis_id_init(uart_id_t id);
57 uart_statis_t* uart_statis_get_statis(uart_id_t id);
58 void uart_statis_dump(uart_id_t id);
59 #else
60 #define UART_STATIS_DEC()
61 #define UART_STATIS_GET(_statis, _id)
62 #define UART_STATIS_SET(_id, _v)
63 #define UART_STATIS_ADD(_statis, _v)
64 #define uart_statis_init()
65 #define uart_statis_id_init(id)
66 #define uart_statis_get_statis(id) NULL
67 #define	uart_statis_dump(id)
68 #endif
69 
70 #define UART_STATIS_INC(_statis) UART_STATIS_ADD((_statis), 1)
71 
72 #ifdef __cplusplus
73 }
74 #endif
75