一、控制台重映射函数
void rt_hw_console_output(const char *str)
{
rt_enter_critical();
while(*str!='\0')
{
if(*str=='\n')
{
usart_data_transmit(USART0,'\r');
while(usart_flag_get(USART0,USART_FLAG_TBE)==RESET);
}
usart_data_transmit(USART0,*str++);
while(usart_flag_get(USART0,USART_FLAG_TBE)==RESET);
}
rt_exit_critical();
}
二、主函数
#include "board.h"
#include "rtthread.h"
static rt_thread_t led1_thread=RT_NULL;
//static rt_thread_t usart_thread=RT_NULL;
static void led1_thread_entry(void *parameter);
//static void usart_thread_entry(void *parameter);
int main(void)
{
led1_thread=rt_thread_create("led1",led1_thread_entry,RT_NULL,512,3,20);
if(led1_thread!=RT_NULL)
{
rt_thread_startup(led1_thread);
}
else
{
return -1;
}
// usart_thread=rt_thread_create("usart0",usart_thread_entry,RT_NULL,512,2,20);
// if(usart_thread!=RT_NULL)
// {
// rt_thread_startup(usart_thread);
// }
// else
// {
// return -1;
// }
}
static void led1_thread_entry(void *parameter)
{
while(1)
{
led1=1;
rt_thread_delay(1500);
rt_kprintf("led1_thread is running,LED1_ON\r\n");
led1=0;
rt_thread_delay(1500);
rt_kprintf("led1_thread is running,LED1_OFF\r\n");
}
}
//static void usart_thread_entry(void *parameter)
//{
// while(1)
// {
// usart_data_transmit(USART0,0x01);
// rt_thread_delay(500);
// }
//}
三、结果
|