micro_climate/Drivers/Shell/shell_uart.c

106 lines
2.4 KiB
C
Raw Normal View History

2024-07-05 03:52:43 +00:00
#include "shell_uart.h"
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD>
void dev_uart_out_char(char c)
{
uart_putchar(TERM_UART_INDEX, c);
}
//<2F><>ȡһ<C8A1><D2BB><EFBFBD>ַ<EFBFBD>
char dev_uart_in_char()
{
uart_device_info *dev = (uart_device_info *)g_term_uart_handle;
//osSemaphoreWait(dev->sem_recv_one_byte_data,0);
osDelay(300);
return uart_dev_in_char(g_term_uart_handle);
}
#if 0
//shell<6C><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
__weak size_t __write(int handle, const unsigned char * buffer, size_t size)
{
size_t nChars = 0;
if (buffer == 0)
{
/* This means that we should flush internal buffers. Since we*/
/* don't we just return. (Remember, "handle" == -1 means that all*/
/* handles should be flushed.)*/
return 0;
}
/* This function only writes to "standard out" and "standard err",*/
/* for all other file handles it returns failure.*/
if ((handle != _LLIO_STDOUT) && (handle != _LLIO_STDERR))
{
return _LLIO_ERROR;
}
/* Send data.*/
while (size--)
{
dev_uart_out_char(*buffer++);
++nChars;
}
return nChars;
}
__weak size_t __read(int handle, unsigned char * buffer, size_t size)
{
size_t nChars = 0;
uint16_t ch = 0;
if (buffer == 0)
{
/* This means that we should flush internal buffers. Since we*/
/* don't we just return. (Remember, "handle" == -1 means that all*/
/* handles should be flushed.)*/
return 0;
}
/* This function only writes to "standard out" and "standard err",*/
/* for all other file handles it returns failure.*/
if ((handle != _LLIO_STDIN) && (handle != _LLIO_STDERR))
{
return _LLIO_ERROR;
}
/* read data.*/
while (size--)
{
ch=dev_uart_in_char();
*buffer++ = (char)ch & 0xFF;
++nChars;
}
return nChars;
}
/**
* \brief UART putchar function
* \attention <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* \param[in] instance UARTģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* \param[in] str ָ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* \retval None
*/
static void UART_putstr(UART_MemMapPtr instance, const char *str)
{
while(*str != '\0')
{
uart_putchar(UART1_BASE_PTR, *str++);
}
}
/**
* \brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
* \attention <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* \retval None
*/
static void printn(unsigned int n, unsigned int b)
{
static char *ntab = "0123456789ABCDEF";
unsigned int a, m;
if (n / b)
{
a = n / b;
printn(a, b);
}
m = n % b;
uart_putchar(UART1_BASE_PTR, ntab[m]);
}
#endif