• 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 <common/bk_err.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef enum {
24 	MAC_TYPE_BASE = 0,
25 	MAC_TYPE_STA,
26 	MAC_TYPE_AP,
27 	MAC_TYPE_BLE,
28 	MAC_MAX,
29 } mac_type_t;
30 
31 #define BK_ERR_INVALID_MAC_TYPE   (BK_ERR_MAC_BASE)
32 #define BK_ERR_ZERO_MAC           (BK_ERR_MAC_BASE - 1)
33 #define BK_ERR_GROUP_MAC          (BK_ERR_MAC_BASE - 2)
34 #define BK_ERR_INVALID_MAC        (BK_ERR_MAC_BASE - 3)
35 
36 #define BK_MAC_ADDR_LEN           6
37 
38 #define BK_IS_ZERO_MAC(m) (((m)[0] == 0) && ((m)[1] == 0) && ((m)[2] == 0) && ((m)[3] == 0)\
39 	&& ((m)[4] == 0) && ((m)[5] == 0))
40 #define BK_IS_GROUP_MAC(m) (((m)[0] & 0x01))
41 
42 /**
43  * @brief  Set the base MAC of the system
44  *
45  * The base MAC address is used to generate the MAC of other interfaces,
46  * such as WiFi STA, WiFi AP, BLE, BT etc.
47  *
48  * @return
49  *  - BK_OK: success
50  *  - BK_ERR_NULL_PARAM: mac is NULL
51  *  - BK_ERR_GROUP_MAC: mac is group address mac
52  *  - others: other failures
53  */
54 bk_err_t bk_set_base_mac(const uint8_t *mac);
55 
56 /**
57  * @brief  Get the MAC
58  *
59  * @return
60  *  - BK_OK: success
61  *  - BK_ERR_NULL_PARAM: parameter mac is NULL
62  *  - BK_ERR_INVALID_MAC_TYPE: mac is not supported
63  */
64 bk_err_t bk_get_mac(uint8_t *mac, mac_type_t type);
65 
66 
67 /**
68  * @brief  Reboot the system
69  *
70  * This function reset the system by triggering the interrupt watchdog.
71  */
72 void bk_reboot(void);
73 
74 int bk_tick_init(void);
75 int bk_tick_reload(uint32_t time_ms);
76 void bk_tick_handle(uint8_t arg);
77 int bk_update_tick(uint32_t tick);
78 uint64_t bk_get_tick(void);
79 uint32_t bk_get_second(void);
80 uint32_t bk_get_ms_per_tick(void);
81 uint32_t bk_get_ticks_per_second(void);
82 int bk_get_tick_timer_id(void);
83 void bk_printf(const char *fmt, ...);
84 void bk_null_printf(const char *fmt, ...);
85 int bk_printf_init(void);
86 int bk_printf_deinit(void);
87 void bk_set_printf_enable(uint8_t enable);
88 void bk_set_printf_sync(uint8_t enable);
89 int bk_get_printf_sync(void);
90 void bk_buf_printf_sync(char *buf, int buf_len);
91 void bk_printf_ex(int level, char * tag, const char *fmt, ...);
92 void bk_disable_mod_printf(char *mod_name, uint8_t disable);
93 char * bk_get_disable_mod(int * idx);
94 void bk_set_printf_port(uint8_t port_num);
95 int bk_get_printf_port(void);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100