1 #include "board.h"
2 #include "aos/hal/uart.h"
3 #include "aos/hal/i2c.h"
4 #include "cmsis.h"
5 #include "cmsis_os.h"
6 #include "hal_gpio.h"
7 #include "hal_timer.h"
8 #include "hal_trace.h"
9 #include <k_api.h>
10 #if (RHINO_CONFIG_HW_COUNT > 0)
11 #include "haas1000.h"
12 #endif
13 #define SYSTICK_USE_FASTTIMER
14
15 uart_dev_t uart_0;
16 uint8_t g_haasedu_boardname = HAAS_EDU_K1C;
17
18 extern void haas_wifi_init();
19
20 #if (RHINO_CONFIG_HW_COUNT > 0)
soc_hw_timer_init(void)21 void soc_hw_timer_init(void)
22 {
23 /* Enable DWT */
24 CoreDebug->DEMCR |= ((1 << CoreDebug_DEMCR_TRCENA_Pos));
25 DWT->CYCCNT = 0;
26 /* Enable CPU cycle counter */
27 DWT->CTRL |= ((1 << DWT_CTRL_CYCCNTENA_Pos));
28 }
29
soc_hr_hw_cnt_get(void)30 hr_timer_t soc_hr_hw_cnt_get(void)
31 {
32 return DWT->CYCCNT;
33 }
34
soc_lr_hw_cnt_get(void)35 lr_timer_t soc_lr_hw_cnt_get(void)
36 {
37 return (lr_timer_t)hal_sys_timer_get();
38 }
39
soc_hr_hw_freq_mhz(void)40 float soc_hr_hw_freq_mhz(void)
41 {
42 return hal_sys_timer_calc_cpu_freq(5, 0) / 1000000;
43 }
44
45 #endif /* RHINO_CONFIG_HW_COUNT */
46
47 #if (RHINO_CONFIG_INTRPT_STACK_OVF_CHECK > 0)
soc_intrpt_stack_ovf_check(void)48 void soc_intrpt_stack_ovf_check(void) {}
49 #endif
50
51 #if (RHINO_CONFIG_DYNTICKLESS > 0)
soc_tick_interrupt_set(tick_t next_ticks,tick_t elapsed_ticks)52 void soc_tick_interrupt_set(tick_t next_ticks, tick_t elapsed_ticks) {}
53
soc_elapsed_ticks_get(void)54 tick_t soc_elapsed_ticks_get(void)
55 {
56 return 0;
57 }
58 #endif
59
60 #if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
61 #define RHINO_HEAP_BLK_SIZE (0x680000)
62 __SRAM_EXT_BSS uint32_t heap_blk0[RHINO_HEAP_BLK_SIZE / sizeof(uint32_t)] = {0};
63 // __SRAM_EXT_BSS uint32_t heap_blk1[RHINO_HEAP_BLK_SIZE/sizeof(uint32_t)] = {0};
64 k_mm_region_t g_mm_region[] = {
65 {(uint8_t *)heap_blk0, RHINO_HEAP_BLK_SIZE}
66 // {(uint8_t *)heap_blk1, RHINO_HEAP_BLK_SIZE}
67 };
68 int g_region_num = sizeof(g_mm_region) / sizeof(k_mm_region_t);
69
soc_sys_mem_init(void)70 void soc_sys_mem_init(void) {}
71 #endif
72
soc_err_proc(kstat_t err)73 void soc_err_proc(kstat_t err) {}
74
75 krhino_err_proc_t g_err_proc = soc_err_proc;
76
77 #define OS_CLOCK OS_CLOCK_NOMINAL
78
79 #define SYS_TICK_LOAD \
80 ((uint32_t)((((float)OS_CLOCK * (float)RHINO_CONFIG_TICKS_PER_SECOND)) / \
81 (float)1E6 + \
82 0.5f))
83
SysTick_Config_Alt(uint32_t ticks)84 __STATIC_INLINE uint32_t SysTick_Config_Alt(uint32_t ticks)
85 {
86 if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) {
87 return (1UL); /* Reload value impossible */
88 }
89
90 SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
91 NVIC_SetPriority(SysTick_IRQn,
92 (1UL << __NVIC_PRIO_BITS) -
93 1UL); /* set Priority for Systick Interrupt */
94 SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
95 SysTick->CTRL =
96 SysTick_CTRL_TICKINT_Msk |
97 SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
98 return (0UL); /* Function successful */
99 }
100
SysTick_Handler(void)101 void SysTick_Handler(void)
102 {
103 krhino_intrpt_enter();
104 krhino_tick_proc();
105 krhino_intrpt_exit();
106 }
107
soc_systick_init(void)108 void soc_systick_init(void)
109 {
110 #ifdef SYSTICK_USE_FASTTIMER
111 hal_systick_timer_open(RHINO_CONFIG_TICKS_PER_SECOND, SysTick_Handler);
112 #else
113 SysTick_Config_Alt(SYS_TICK_LOAD);
114 #endif
115 }
116
soc_systick_start(void)117 void soc_systick_start(void)
118 {
119 #ifdef SYSTICK_USE_FASTTIMER
120 hal_systick_timer_start();
121 #else
122 SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
123 #endif
124 }
125
soc_systick_stop(void)126 void soc_systick_stop(void)
127 {
128 #ifdef SYSTICK_USE_FASTTIMER
129 hal_systick_timer_stop();
130 #else
131 SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
132 #endif
133 }
134
board_stduart_init()135 void board_stduart_init()
136 {
137 uart_0.port = 0;
138 uart_0.config.baud_rate = 1500000;
139 uart_0.config.data_width = DATA_WIDTH_8BIT;
140 uart_0.config.flow_control = FLOW_CONTROL_DISABLED;
141 uart_0.config.mode = MODE_TX_RX;
142 uart_0.config.parity = NO_PARITY;
143 uart_0.config.stop_bits = STOP_BITS_1;
144
145 hal_uart_init(&uart_0);
146 }
147
haasedu_is_k1c()148 int haasedu_is_k1c()
149 {
150 int value = 0;
151 int len = 4;
152
153 if (0 == aos_kv_get("HAASEDU_NAME", &value, &len)) {
154 printf("HAASEDU_NAME is %d\r\n", value);
155 if (value == 1) {
156 printf("3333 is %d\r\n", value);
157 return 1;
158 } else {
159 return 0;
160 }
161 } else {
162 printf("HAASEDU_NAME is avild %d!\r\n", value);
163 return 0;
164 }
165 }
166
board_detect()167 void board_detect()
168 {
169 int re_value = 0;
170 int len = 4;
171 uint8_t chip_id = 0x00;
172
173 int32_t ret = sensor_i2c_open(1, 0x6b, I2C_BUS_BIT_RATES_100K, 0);
174 if (ret) {
175 printf("sensor i2c open failed, ret:%d\n", ret);
176 return;
177 }
178
179 FisImu_read_reg(0, &chip_id, 1);
180 aos_msleep(100);
181 sensor_i2c_close(1);
182
183 if (chip_id == 0xfc) {
184 g_haasedu_boardname = HAAS_EDU_K1C;
185 re_value = 1;
186 aos_kv_set("HAASEDU_NAME", &re_value, len, 1);
187 printf("haasedu name is K1C\n");
188 } else {
189 g_haasedu_boardname = HAAS_EDU_K1;
190 re_value = 0;
191 aos_kv_set("HAASEDU_NAME", &re_value, len, 1);
192 printf("haasedu name is K1\n");
193 }
194 printf("haasedu detected is %d\n", g_haasedu_boardname);
195
196 return;
197 }
198
board_dma_init()199 void board_dma_init() {}
200
board_gpio_init()201 void board_gpio_init() {}
202
board_tick_init()203 void board_tick_init() {}
204
board_kinit_init()205 void board_kinit_init() {}
206
board_flash_init()207 void board_flash_init() {}
208
board_network_init()209 void board_network_init()
210 {
211 haas_wifi_init();
212 }
213