1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and
 * its subsidiaries and affiliates (collectly called MKSEMI).
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into an MKSEMI
 *    integrated circuit in a product or a software update for such product,
 *    must reproduce the above copyright notice, this list of conditions and
 *    the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of MKSEMI nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    MKSEMI integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be
 *    reverse engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY MKSEMI "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL MKSEMI OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
#ifndef BOARD_H_
#define BOARD_H_
 
#include "mk_common.h"
#include "mk_trace.h"
#include "mk_gpio.h"
 
/*   LGA                CSP
IO00 - UART1 RX         - UART1 RX
IO01 - UART1 TX         - UART1 TX (trace port)
IO02 - Ranging Role     - Ranging Role
IO03 -                  - ISP_EN
IO04 -                  - UCI Handshake S->H
IO05 - UART0_TX         - UART0_TX | SPI_MISO
IO06 - UART0_RX         - UART0_RX | SPI_MOSI
IO07 - LED              - LED      | SPI_CLK
IO08 - LED              - LED      | SPI_CS
IO09 -                  - EXT Flash
IO10 -                  - EXT Flash
IO11 - SPI_MOSI         - EXT Flash
IO12 - SPI_MISO         - EXT Flash
IO13 - SPI_CLK          - EXT Flash
IO14 - SPI_CS           - EXT Flash
IO15 - SWDIO            - SWDIO
IO16 - SWDCLK           - SWDCLK
IO17 - Button           - UCI Handshake H->S
*/
 
/* Evaluation Kit */
#define BOARD_TYPE MK8000_EVK
 
/* Board buttons */
#define BOARD_SW_1 IO_PIN_17
 
/* Board leds */
#define BOARD_LED_1 IO_PIN_7
#define BOARD_LED_2 IO_PIN_8
 
/** UCI handshake pin, from host to slave  */
#define HOST2SLAVE_HS_GPIO (IO_PIN_17)
 
/** UCI handshake pin, from slave to host */
#define SLAVE2HOST_HS_GPIO (IO_PIN_4)
 
#define CALIB_CH9 0
#define CALIB_CH5 1
#define CALIB_CH2 2
#define CALIB_CH_NUM 3
 
#define CALIB_CH(x) (x == 9 ? 0 : (x == 5 ? 1 : 2))
 
enum BOARD_NVM_ITEM_ID_T
{
    BOARD_LOAD_CAP = 1,
    BOARD_LOCAL_SHORT_ADDR = 2,
    BOARD_PEER_SHORT_ADDR = 3,
    BOARD_RANGING_SESSION_ID = 4,
    BOARD_TX_POWER_FCC_LEVEL = 5,
    BOARD_ANT_DELAYS = 6,
    BOARD_DEV_ROLE = 7,
    BOARD_DEV_ROLE_IDX = 8,
    BOARD_PDOA_DELAYS = 9,
    BOARD_PDOA_GAINS = 10,
    BOARD_PDOA_ANT_SPACE = 11,
    BOARD_PDOA_OFFSETS = 12,
    BOARD_X32K_LOAD_CAP = 13,
};
 
/* Board parameters */
struct BOARD_PARAM_T
{
    uint32_t flag;
    uint8_t load_cap;
    uint8_t tx_power_fcc[CALIB_CH_NUM]; // [CH9, CH5, CH2]
    uint16_t ranging_session_id;
    uint16_t local_short_addr;
    uint16_t peer_short_addr;
    int16_t ant_delays[CALIB_CH_NUM][4];  // [CH9, CH5, CH2][ANT0, ANT1, ANT2, ANT3], unit: 15.65ps
    int16_t pdoa_delays[CALIB_CH_NUM][4]; // [CH9, CH5, CH2][ANT0, ANT1, ANT2, ANT3], uint: ps
    int16_t pdoa_gains[CALIB_CH_NUM][4];  // [CH9, CH5, CH2][ANT0, ANT1, ANT2, ANT3]
    int16_t pdoa_ant_space;               // unit: 0.1mm
    int16_t pdoa_offsets[2];              // [azimuth, elevation], unit: 0.1degree
    uint8_t dev_role;
    uint8_t dev_role_idx;
    uint8_t x32k_load_cap;
};
 
#if defined(__cplusplus)
extern "C" {
#endif
 
extern struct BOARD_PARAM_T board_param;
 
/**
 * @brief Configure clock.
 *
 */
void board_clock_run(void);
 
/**
 * @brief Configure pin routing and optionally pin electrical features.
 *
 */
void board_pins_config(void);
 
/**
 * @brief Configure debug trace port.
 * @param[in] port      Trace port
 *
 */
void board_debug_console_open(enum TRACE_PORT_T port);
 
/**
 * @brief Load default calibration parameters.
 *
 */
void board_calibration_params_default(void);
 
/**
 * @brief Load calibration parameters from NVM.
 *
 */
void board_calibration_params_load(void);
 
/**
 * @brief Write calibration item into NVM.
 * @param[in] id            calibration item ID
 * @param[in] param         pointer of the parameter to be written
 * @param[in] param_len     parameter length
 * @return TRUE sucess or FALSE fail
 */
uint8_t board_calibration_param_write(uint8_t id, uint8_t *param, uint8_t param_len);
 
/**
 * @brief Correct ranging result, correction formula depends on the antenna design
 *
 * @param [inout] distance         Pointer of ranging distance result
 * @param [inout] azimuth          Pointer of azimuth result
 * @param [inout] elevation        Pointer of elevation result
 */
void board_ranging_result_correct(uint16_t *distance, int16_t *azimuth, int16_t *elevation);
 
/**
 * @brief Configure button GPIO.
 * @param[in] irq_handler       button interrupt process handler
 *
 */
void board_button_init(GPIO_IRQ_HANDLER_T irq_handler);
/**
 * @brief Configure button GPIO.
 * @param[in] irq_handler 5v input interrupt process handler
 *
 */
void board_5V_input_init(GPIO_IRQ_HANDLER_T irq_handler);
/**
 * @brief Configure LED GPIO.
 *
 */
void board_led_init(void);
 
/**
 * @brief LED on.
 * @param[in] idx       LED index
 *
 */
void board_led_on(enum IO_PIN_T idx);
 
/**
 * @brief LED off.
 * @param[in] idx       LED index
 *
 */
void board_led_off(enum IO_PIN_T idx);
 
/**
 * @brief LED toggle.
 * @param[in] idx       LED index
 *
 */
void board_led_toggle(enum IO_PIN_T idx);
 
/**
 * @brief Configure peripherals on board (for board function extension).
 *
 */
void board_configure(void);
 
/**
 * @brief Prepare to enter power down mode.
 *
 */
void board_prepare_for_power_down(void);
 
/**
 * @brief Restore board setting from power down mode.
 *
 */
void board_restore_from_power_down(void);
 
#if defined(__cplusplus)
}
#endif
 
#endif /* BOARD_H_ */