1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 6 /****************************************************************************** 7 * @file lib.c 8 * @brief source file for the lib 9 * @version V1.0 10 * @date 02. June 2017 11 ******************************************************************************/ 12 #include <csi_config.h> 13 #include <stdint.h> 14 #include <stdarg.h> 15 #include <stdio.h> 16 #include "soc.h" 17 #include "csi_core.h" //for test 18 #include "drv_usart.h" 19 20 extern uint64_t csi_coret_get_load(void); 21 extern uint64_t csi_coret_get_value(void); 22 extern uint32_t csi_coret_get_valueh(void); 23 24 extern int32_t csi_usart_putchar(usart_handle_t handle, uint8_t ch); 25 extern int32_t csi_usart_getchar(usart_handle_t handle, uint8_t *ch); 26 _mdelay(void)27static void _mdelay(void) 28 { 29 unsigned long long start, cur, delta; 30 uint32_t startl = csi_coret_get_value(); 31 uint32_t starth = csi_coret_get_valueh(); 32 uint32_t curl, curh; 33 uint32_t cnt = (drv_get_sys_freq() / 1000); 34 start = ((unsigned long long)starth << 32) | startl; 35 36 while (1) { 37 curl = csi_coret_get_value(); 38 curh = csi_coret_get_valueh(); 39 cur = ((unsigned long long)curh << 32) | curl; 40 delta = cur - start; 41 42 if (delta >= cnt) { 43 return; 44 } 45 } 46 } 47 mdelay(uint32_t ms)48void mdelay(uint32_t ms) 49 { 50 if (ms == 0) { 51 return; 52 } 53 54 while (ms--) { 55 _mdelay(); 56 } 57 } 58