简介:
上一篇已经完成了基于共享内存的虚拟串口打印,将core1 的打印输出函数printf 通过ringbuffer 写入共享内存,然后 core0 读取共享内存的ringbuff 数据,通过物理串口打印输出。对应下图的绿色的数据流。

在此基础上继续实现红色的数据流,core0 将串口数据发送到共享内存,core1 读取共享内存数据并解析数据实现shell。
代码对应core1
core1 端的虚拟串口读取代码如下:
uint8_t uartgetchar(uint8_t* pdata)
{
uint8_t ret = 0;
while(MAILBOX_GetMutex(MAILBOX) == 0);
ret = RingBuffer_Read(&p_virtual_uart0->core0_tx_core1_rx,pdata,1);
MAILBOX_SetMutex(MAILBOX);
return ret;
}core1 测添加hello shell 命令
unsigned int hello(char argc,char ** argv)
{
printf("hello i am core1 \r\n");
return 0;
}
LTSH_FUNCTION_EXPORT(hello, "core1 hello");代码对应core0
在core0 运行的系统 RT-thread 中添加core1 命令将数据转发到共享内存。
static int core1(int argc, char *argv[])
{
uint8_t buff[80] = {0};
uint8_t len = 0;
if(argc > 1)
{
for(int i = 1;i < argc ;i++)
{
len += rt_sprintf((char *)buff,"%s ",argv[i]);
}
len += rt_sprintf((char *)&buff[len],"%s","\n");
while(MAILBOX_GetMutex(MAILBOX) == 0);
RingBuffer_Write(&virual_uart0.core0_tx_core1_rx,buff,len);
MAILBOX_SetMutex(MAILBOX);
}
return 0;
}
MSH_CMD_EXPORT(core1, send virual uart to core1);在core0 输入 “core1 hello” ,core1 已经接收到hello 字符串,并执行了对应的处理函数。

至此已经完成基于共享内存的虚拟串口的收发功能。
我要赚赏金
