1 // Copyright (C) 2022 Beken Corporation
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 #include <stdio.h>
15 #include "cmsis_os2.h"
16 #include "platform.h"
17 #include "bk_cli.h"
18
HalIrqDisable(uint32 irq_no)19 void HalIrqDisable(uint32 irq_no)
20 {
21 clear_csr(NDS_MIE, (1<<irq_no));
22 }
HalIrqEnable(uint32 irq_no)23 void HalIrqEnable(uint32 irq_no)
24 {
25 set_csr(NDS_MIE, (1<<irq_no));
26 }
27
bk_wrap__ctype_ptr__(void)28 void bk_wrap__ctype_ptr__(void)
29 {
30 }
HAL_NVIC_SystemReset(void)31 void HAL_NVIC_SystemReset(void)
32 {
33 }
34
35 #define vprintf_buf_len 128
bk_wrap_vprintf(const char * fmt,va_list ap)36 int bk_wrap_vprintf(const char *fmt, va_list ap)
37 {
38 int len;
39 char string[vprintf_buf_len];
40
41 len = __wrap_vsnprintf(string, sizeof(string) - 1, fmt, ap);
42 string[vprintf_buf_len-1] = 0;
43 uart_write_string(CONFIG_UART_PRINT_PORT, string);
44
45 return len;
46 }
47
48 __attribute__((section(".interrupt.HalTrapVector.text")))
HalSetLocalInterPri(UINT32 interPriNum,UINT16 prior)49 void HalSetLocalInterPri(UINT32 interPriNum, UINT16 prior)
50 {
51 __nds__plic_set_priority(interPriNum, prior);
52 }
53
54 static int hdf_log_default_level = 4;
55
hal_trace_printf(int attr,const char * fmt,...)56 int hal_trace_printf(int attr, const char *fmt, ...)
57 {
58 if (attr <= hdf_log_default_level) {
59 va_list ap;
60 int len;
61 char string[vprintf_buf_len];
62
63 va_start(ap, fmt);
64 len = __wrap_vsnprintf(string, sizeof(string) - 1, fmt, ap);
65 string[sizeof(string)-1] = 0;
66 uart_write_string(CONFIG_UART_PRINT_PORT, string);
67 va_end(ap);
68 }
69 }
70
_write(int filedes,const void * buf,size_t nbytes)71 ssize_t _write(int filedes, const void *buf, size_t nbytes)
72 {
73 return 0;
74 }
75
__atomic_fetch_add_4(void)76 void __atomic_fetch_add_4(void)
77 {
78 }
79
__atomic_fetch_sub_4(void)80 void __atomic_fetch_sub_4(void)
81 {
82 }
83