1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 6 /****************************************************************************** 7 * @file minilibc_port.c 8 * @brief minilibc port 9 * @version V1.0 10 * @date 26. Dec 2017 11 ******************************************************************************/ 12 13 #include <stdio.h> 14 #include <csi_config.h> 15 #ifndef CONFIG_KERNEL_NONE 16 #include <csi_kernel.h> 17 #endif 18 19 #include <drv_usart.h> 20 21 usart_handle_t console_handle = NULL; 22 write(int __fd,__const void * __buf,int __n)23__attribute__((weak)) int write(int __fd, __const void *__buf, int __n) 24 { 25 return 0; 26 } 27 fputc(int ch,FILE * stream)28int fputc(int ch, FILE *stream) 29 { 30 (void)stream; 31 32 if (console_handle == NULL) { 33 return -1; 34 } 35 36 if (ch == '\n') { 37 csi_usart_putchar(console_handle, '\r'); 38 } 39 40 csi_usart_putchar(console_handle, ch); 41 42 return 0; 43 } 44 fgetc(FILE * stream)45int fgetc(FILE *stream) 46 { 47 uint8_t ch; 48 (void)stream; 49 50 if (console_handle == NULL) { 51 return -1; 52 } 53 54 csi_usart_getchar(console_handle, &ch); 55 56 return ch; 57 } 58 os_critical_enter(unsigned int * lock)59int os_critical_enter(unsigned int *lock) 60 { 61 (void)lock; 62 #ifndef CONFIG_KERNEL_NONE 63 csi_kernel_sched_suspend(); 64 #endif 65 66 return 0; 67 } 68 os_critical_exit(unsigned int * lock)69int os_critical_exit(unsigned int *lock) 70 { 71 (void)lock; 72 #ifndef CONFIG_KERNEL_NONE 73 csi_kernel_sched_resume(0); 74 #endif 75 76 return 0; 77 } 78