112 lines
1.9 KiB
C
112 lines
1.9 KiB
C
#include "board.h"
|
|
#include "lock_resource.h"
|
|
#include "openamp.h"
|
|
#include "string.h"
|
|
|
|
|
|
|
|
// 与a7通信的虚拟串口
|
|
// 系统启动的时候自动依次初始化,为了保证顺序
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
|
VIRT_UART_HandleTypeDef huart;
|
|
void (*irq_fun)(void *t,uint8_t d);
|
|
void *t;
|
|
void *mutex;
|
|
}self_def;
|
|
|
|
|
|
static self_def g_self[3];
|
|
|
|
|
|
static int vuart_init(void)
|
|
{
|
|
self_def *s=g_self;
|
|
|
|
log_info("Virtual UART0 OpenAMP-rpmsg channel creation\r\n");
|
|
if (VIRT_UART_Init(&s[0].huart) != VIRT_UART_OK) {
|
|
log_err("VIRT_UART_Init UART0 failed.\r\n");
|
|
}
|
|
|
|
log_info("Virtual UART1 OpenAMP-rpmsg channel creation\r\n");
|
|
if (VIRT_UART_Init(&s[1].huart) != VIRT_UART_OK) {
|
|
log_err("VIRT_UART_Init UART1 failed.\r\n");
|
|
}
|
|
|
|
log_info("Virtual UART2 OpenAMP-rpmsg channel creation\r\n");
|
|
if (VIRT_UART_Init(&s[2].huart) != VIRT_UART_OK) {
|
|
log_err("VIRT_UART_Init UART2 failed.\r\n");
|
|
}
|
|
}
|
|
|
|
app_init_export(vuart_init);
|
|
|
|
|
|
|
|
|
|
static int init(uart_def *u)
|
|
{
|
|
self_def *s=g_self;
|
|
if(strcmp(u->name,"vuart0")==0)
|
|
{
|
|
u->private_data=&s[0].huart;
|
|
}else if(strcmp(u->name,"vuart1")==0)
|
|
{
|
|
u->private_data=&s[1].huart;
|
|
}else if(strcmp(u->name,"vuart2")==0)
|
|
{
|
|
u->private_data=&s[2].huart;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int deinit(uart_def *u)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
static int set_irq(uart_def *u,void (*irq)(void *t,uint8_t d),void *t)
|
|
{
|
|
param_check(u);
|
|
param_check(u->private_data);
|
|
self_def *self=u->private_data;
|
|
irq_disable();
|
|
self->irq_fun=irq;
|
|
|
|
|
|
self->t=t;
|
|
irq_enable();
|
|
return 0;
|
|
}
|
|
static int read(uart_def *u,uint8_t *b,int len)
|
|
{
|
|
param_check(u);
|
|
param_check(u->private_data);
|
|
return 0;
|
|
}
|
|
static int write(uart_def *u,const uint8_t *b,int len)
|
|
{
|
|
param_check(u);
|
|
param_check(u->private_data);
|
|
self_def *self=u->private_data;
|
|
rt_mutex_take(self->mutex,RT_WAITING_FOREVER);
|
|
VIRT_UART_Transmit(&self->huart, (uint8_t *)b, len);
|
|
rt_mutex_release(self->mutex);
|
|
return len;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|