1 /*
2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3 */
4
5 #include <stdio.h>
6 #include <stdbool.h>
7 #include <string.h>
8
9 #include <k_api.h>
10 #include "ulog/ulog.h"
11
12 #include "aos/hal/uart.h"
13 #include "aos/hal/timer.h"
14
15 #include "board.h"
16 #include "diag.h"
17 #include "platform_stdlib.h"
18
19
20 #define TAG "hw"
21
22 #define us2tick(us) \
23 ((us * RHINO_CONFIG_TICKS_PER_SECOND + 999999) / 1000000)
24
25 uart_dev_t uart_0;
26 uart_dev_t uart_1;
27
28 extern int sys_reset();
29
hal_reboot(void)30 void hal_reboot(void)
31 {
32 sys_reset();
33 }
34 #if 0
35 static void _timer_cb(void *timer, void *arg)
36 {
37 timer_dev_t *tmr = arg;
38 tmr->config.cb(tmr->config.arg);
39 }
40
41 int32_t hal_timer_init(timer_dev_t *tim)
42 {
43 if (tim->config.reload_mode == TIMER_RELOAD_AUTO) {
44 krhino_timer_dyn_create((ktimer_t **)&tim->priv, "hwtmr", _timer_cb,
45 us2tick(tim->config.period), us2tick(tim->config.period), tim, 0);
46 }
47 else {
48 krhino_timer_dyn_create((ktimer_t **)&tim->priv, "hwtmr", _timer_cb,
49 us2tick(tim->config.period), 0, tim, 0);
50 }
51 return 0;
52 }
53
54 int32_t hal_timer_start(timer_dev_t *tmr)
55 {
56 return krhino_timer_start(tmr->priv);
57 }
58
59 void hal_timer_stop(timer_dev_t *tmr)
60 {
61 krhino_timer_stop(tmr->priv);
62 krhino_timer_dyn_del(tmr->priv);
63 tmr->priv = NULL;
64 }
65 #endif
66
hw_start_hal(void)67 void hw_start_hal(void)
68 {
69 printf("start hal-----------\n");
70
71 uart_0.port = MICO_UART_1;
72 uart_0.config.baud_rate = 115200;
73 uart_0.config.data_width = DATA_WIDTH_8BIT;
74 uart_0.config.parity = NO_PARITY;
75 uart_0.config.stop_bits = STOP_BITS_1;
76 uart_0.config.flow_control = FLOW_CONTROL_DISABLED;
77
78 hal_uart_init(&uart_0);
79 printf("hal init successed\n\r");
80 }
81
82