mirror of
https://github.com/Fishwaldo/bl808_coprocessor.git
synced 2025-03-15 11:21:28 +00:00
more rpmsg work.
This commit is contained in:
parent
644dc20d14
commit
d64b73f3f5
10 changed files with 151 additions and 28 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
m0/build/*
|
||||
*/build/*
|
||||
*~
|
|
@ -60,7 +60,7 @@ typedef enum {
|
|||
|
||||
|
||||
|
||||
int ipc_init();
|
||||
void rpmsg_task(void *unused);
|
||||
|
||||
int ipc_send_ping(GLB_CORE_ID_Type cpu);
|
||||
int ipc_send_pong(GLB_CORE_ID_Type cpu);
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include <bl808_ipc.h>
|
||||
#include <ring_buffer.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <rpmsg_lite.h>
|
||||
#include <rpmsg_ns.h>
|
||||
#include <rpmsg_queue.h>
|
||||
#include "ipc.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -12,6 +15,9 @@ typedef struct {
|
|||
ipc_status_t ipc_status;
|
||||
|
||||
struct rpmsg_lite_instance *ipc_rpmsg;
|
||||
struct rpmsg_lite_endpoint *ipc_rpmsg_default_endpoint;
|
||||
rpmsg_ns_handle ipc_rpmsg_ns;
|
||||
rpmsg_queue_handle ipc_rpmsg_queue;
|
||||
|
||||
static int ipc_send_cmd(GLB_CORE_ID_Type targetcpu, uint32_t cmd);
|
||||
|
||||
|
@ -45,7 +51,6 @@ void ipc_m0_callback(uint32_t src) {
|
|||
env_isr(ffs(src >> IPC_MSG_RPMSG0));
|
||||
break;
|
||||
}
|
||||
printf("unknown message\r\n");
|
||||
}
|
||||
|
||||
void ipc_d0_callback(uint32_t src) {
|
||||
|
@ -58,8 +63,26 @@ void ipc_d0_callback(uint32_t src) {
|
|||
case IPC_MSG_PONG:
|
||||
/* nothing todo */
|
||||
break;
|
||||
case IPC_MSG_RPMSG0:
|
||||
case IPC_MSG_RPMSG1:
|
||||
case IPC_MSG_RPMSG2:
|
||||
case IPC_MSG_RPMSG3:
|
||||
case IPC_MSG_RPMSG4:
|
||||
case IPC_MSG_RPMSG5:
|
||||
case IPC_MSG_RPMSG6:
|
||||
case IPC_MSG_RPMSG7:
|
||||
case IPC_MSG_RPMSG8:
|
||||
case IPC_MSG_RPMSG9:
|
||||
case IPC_MSG_RPMSG10:
|
||||
case IPC_MSG_RPMSG11:
|
||||
case IPC_MSG_RPMSG12:
|
||||
case IPC_MSG_RPMSG13:
|
||||
case IPC_MSG_RPMSG14:
|
||||
case IPC_MSG_RPMSG15:
|
||||
printf("RP Interrupt %d %d\r\n", src, ffs(src >> IPC_MSG_RPMSG0));
|
||||
env_isr(ffs(src >> IPC_MSG_RPMSG0));
|
||||
break;
|
||||
}
|
||||
printf("unknown message\r\n");
|
||||
}
|
||||
|
||||
void ipc_lp_callback(uint32_t src) {
|
||||
|
@ -72,33 +95,111 @@ void ipc_lp_callback(uint32_t src) {
|
|||
case IPC_MSG_PONG:
|
||||
/* nothing todo */
|
||||
break;
|
||||
case IPC_MSG_RPMSG0:
|
||||
case IPC_MSG_RPMSG1:
|
||||
case IPC_MSG_RPMSG2:
|
||||
case IPC_MSG_RPMSG3:
|
||||
case IPC_MSG_RPMSG4:
|
||||
case IPC_MSG_RPMSG5:
|
||||
case IPC_MSG_RPMSG6:
|
||||
case IPC_MSG_RPMSG7:
|
||||
case IPC_MSG_RPMSG8:
|
||||
case IPC_MSG_RPMSG9:
|
||||
case IPC_MSG_RPMSG10:
|
||||
case IPC_MSG_RPMSG11:
|
||||
case IPC_MSG_RPMSG12:
|
||||
case IPC_MSG_RPMSG13:
|
||||
case IPC_MSG_RPMSG14:
|
||||
case IPC_MSG_RPMSG15:
|
||||
printf("RP Interrupt %d %d\r\n", src, ffs(src >> IPC_MSG_RPMSG0));
|
||||
env_isr(ffs(src >> IPC_MSG_RPMSG0));
|
||||
break;
|
||||
}
|
||||
printf("unknown message\r\n");
|
||||
}
|
||||
|
||||
int ipc_init() {
|
||||
int32_t ipc_rpmsg_callback(void *payload, uint32_t payload_len, uint32_t src, void *priv) {
|
||||
printf("RPMSG Callback %d\r\n", src);
|
||||
return RL_SUCCESS;
|
||||
}
|
||||
|
||||
void ipc_rpmsg_ns_callback(uint32_t new_ept, const char *new_ept_name, uint32_t flags, void *user_data) {
|
||||
printf("RPMSG NS Callback %d %s %d\r\n", new_ept, new_ept_name, flags);
|
||||
}
|
||||
|
||||
|
||||
void rpmsg_task(void *unused) {
|
||||
|
||||
volatile uint32_t remote_addr;
|
||||
static char helloMsg[13];
|
||||
|
||||
#if defined(CPU_M0)
|
||||
uint32_t rbaddr = XRAM_RINGBUF_M0_ADDR;
|
||||
uint32_t rbsize = XRAM_RINGBUF_M0_SIZE;
|
||||
uintptr_t rbaddr = XRAM_RINGBUF_M0_ADDR;
|
||||
uintptr_t rbsize = XRAM_RINGBUF_M0_SIZE;
|
||||
IPC_M0_Init(/* lp callback*/ ipc_lp_callback, /* d0 callback */ ipc_d0_callback);
|
||||
IPC_M0_Int_Unmask_By_Word(IPC_MSG_MASK_ALL());
|
||||
ipc_rpmsg = rpmsg_lite_master_init((void *)rbaddr, rbsize, RL_PLATFORM_BL808_M0_LINK_ID, RL_NO_FLAGS);
|
||||
ipc_rpmsg = rpmsg_lite_master_init((uintptr_t *)rbaddr, rbsize, RL_PLATFORM_BL808_M0_LINK_ID, RL_NO_FLAGS);
|
||||
#elif defined(CPU_D0)
|
||||
uint32_t rbaddr = XRAM_RINGBUF_D0_ADDR;
|
||||
uint32_t rbsize = XRAM_RINGBUF_D0_SIZE;
|
||||
uintptr_t rbaddr = XRAM_RINGBUF_D0_ADDR;
|
||||
uintptr_t rbsize = XRAM_RINGBUF_D0_SIZE;
|
||||
IPC_D0_Init(/* lp callback*/ ipc_lp_callback, /* m0 callback */ ipc_m0_callback);
|
||||
IPC_D0_Int_Unmask_By_Word(IPC_MSG_MASK_ALL());
|
||||
ipc_rpmsg = rpmsg_lite_remote_init((void *)rbaddr, RL_PLATFORM_BL808_D0_LINK_ID, RL_NO_FLAGS);
|
||||
ipc_rpmsg = rpmsg_lite_remote_init((uintptr_t *)rbaddr, RL_PLATFORM_BL808_D0_LINK_ID, RL_NO_FLAGS);
|
||||
#elif defined(CPU_LP)
|
||||
uint32_t rbaddr = XRAM_RINGBUF_LP_ADDR;
|
||||
uint32_t rbsize = XRAM_RINGBUF_LP_SIZE;
|
||||
uintptr_t rbaddr = XRAM_RINGBUF_LP_ADDR;
|
||||
uintptr_t rbsize = XRAM_RINGBUF_LP_SIZE;
|
||||
IPC_LP_Init(/* m0 callback*/ ipc_m0_callback, /* d0 callback */ ipc_d0_callback);
|
||||
IPC_LP_Int_Unmask_By_Word(IPC_MSG_MASK_ALL());
|
||||
ipc_rpmsg = rpmsg_lite_remote_init((void *)rbaddr, RL_PLATFORM_BL808_LP_LINK_ID, RL_NO_FLAGS);
|
||||
ipc_rpmsg = rpmsg_lite_remote_init((uintptr_t *)rbaddr, RL_PLATFORM_BL808_LP_LINK_ID, RL_NO_FLAGS);
|
||||
#else
|
||||
#error "Unknown CPU"
|
||||
#endif
|
||||
return 1;
|
||||
while (0 == rpmsg_lite_is_link_up(ipc_rpmsg))
|
||||
{
|
||||
vTaskDelay(100/portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
ipc_rpmsg_queue = rpmsg_queue_create(ipc_rpmsg);
|
||||
|
||||
ipc_rpmsg_default_endpoint = rpmsg_lite_create_ept(ipc_rpmsg, RL_ADDR_ANY, rpmsg_queue_rx_cb, ipc_rpmsg_queue);
|
||||
if (ipc_rpmsg_default_endpoint == RL_NULL) {
|
||||
printf("Failed to create RPMSG endpoint\r\n");
|
||||
return;
|
||||
}
|
||||
ipc_rpmsg_ns = rpmsg_ns_bind(ipc_rpmsg, ipc_rpmsg_ns_callback, NULL);
|
||||
if (ipc_rpmsg_ns == RL_NULL) {
|
||||
printf("Failed to bind RPMSG NS\r\n");
|
||||
return;
|
||||
}
|
||||
vTaskDelay(100/portTICK_PERIOD_MS);
|
||||
|
||||
if (rpmsg_ns_announce(ipc_rpmsg, ipc_rpmsg_default_endpoint, "rpmsg-openamp-demo-channel", RL_NS_CREATE) != RL_SUCCESS) {
|
||||
printf("Failed to announce RPMSG NS\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// #ifdef RPMSG_LITE_MASTER_IS_LINUX
|
||||
/* Wait Hello handshake message from Remote Core. */
|
||||
(void)rpmsg_queue_recv(ipc_rpmsg, ipc_rpmsg_queue, (uint32_t *)&remote_addr, helloMsg, sizeof(helloMsg), ((void *)0),
|
||||
RL_BLOCK);
|
||||
// #endif /* RPMSG_LITE_MASTER_IS_LINUX */
|
||||
printf("Got Hello message from remote core: %s %d\r\n", helloMsg, remote_addr);
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint32_t size;
|
||||
void *rx_buffer;
|
||||
char rx_msg[64];
|
||||
memset( rx_msg, 0, 64 );
|
||||
|
||||
rpmsg_queue_recv_nocopy(ipc_rpmsg, ipc_rpmsg_queue, (uint32_t *)&remote_addr, (char **)&rx_buffer, &size, RL_BLOCK);
|
||||
|
||||
memcpy( rx_msg, rx_buffer, size );
|
||||
rpmsg_queue_nocopy_free( ipc_rpmsg, rx_buffer );
|
||||
|
||||
printf( "received %s!\r\n", rx_msg );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int ipc_send_cmd(GLB_CORE_ID_Type targetcpu, uint32_t cmd) {
|
||||
|
|
|
@ -37,6 +37,14 @@
|
|||
#define RL_PLATFORM_BL808_LP_LINK_ID (2U)
|
||||
#define RL_PLATFORM_HIGHEST_LINK_ID (2U)
|
||||
|
||||
#if __riscv_xlen == 32
|
||||
#define MCAUSE_INT 0x80000000UL
|
||||
#define MCAUSE_CAUSE 0x000003FFUL
|
||||
#else
|
||||
#define MCAUSE_INT 0x8000000000000000UL
|
||||
#define MCAUSE_CAUSE 0x00000000000003FFUL
|
||||
#endif
|
||||
|
||||
|
||||
/* platform interrupt related functions */
|
||||
int32_t platform_init_interrupt(uint32_t vector_id, void *isr_data);
|
||||
|
@ -54,7 +62,7 @@ void platform_map_mem_region(uint32_t vrt_addr, uint32_t phy_addr, uint32_t size
|
|||
void platform_cache_all_flush_invalidate(void);
|
||||
void platform_cache_disable(void);
|
||||
uint32_t platform_vatopa(void *addr);
|
||||
void *platform_patova(uint32_t addr);
|
||||
void *platform_patova(uintptr_t addr);
|
||||
|
||||
/* platform init/deinit */
|
||||
int32_t platform_init(void);
|
||||
|
|
|
@ -144,7 +144,7 @@ static inline void vring_init(struct vring *vr, uint32_t num, uint8_t *p, uint32
|
|||
vr->num = num;
|
||||
vr->desc = (struct vring_desc *)(void *)p;
|
||||
vr->avail = (struct vring_avail *)(void *)(p + num * sizeof(struct vring_desc));
|
||||
vr->used = (struct vring_used *)(((uint32_t)&vr->avail->ring[num] + align - 1UL) & ~(align - 1UL));
|
||||
vr->used = (struct vring_used *)(((uintptr_t)&vr->avail->ring[num] + align - 1UL) & ~(align - 1UL));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -131,8 +131,7 @@ void platform_time_delay(uint32_t num_msec)
|
|||
int32_t platform_in_isr(void)
|
||||
{
|
||||
printf("TODO RP: in isr\r\n");
|
||||
return false;
|
||||
// return (((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0UL) ? 1 : 0);
|
||||
return __get_MCAUSE() & MCAUSE_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,7 +225,7 @@ void platform_cache_disable(void)
|
|||
*/
|
||||
uint32_t platform_vatopa(void *addr)
|
||||
{
|
||||
return ((uint32_t)(char *)addr);
|
||||
return ((uintptr_t)(char *)addr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,7 +234,7 @@ uint32_t platform_vatopa(void *addr)
|
|||
* Dummy implementation
|
||||
*
|
||||
*/
|
||||
void *platform_patova(uint32_t addr)
|
||||
void *platform_patova(uintptr_t addr)
|
||||
{
|
||||
return ((void *)(char *)addr);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
set(CONFIG_PSRAM 1)
|
||||
set(CONFIG_SHELL 1)
|
||||
set(CONFIG_SHELL_DEFAULT_NAME "ox64")
|
||||
set(CONFIG_FREERTOS 0)
|
||||
set(CONFIG_FREERTOS 1)
|
||||
set(CONFIG_BFLOG 1)
|
||||
set(CONFIG_VLIBC 1)
|
||||
set(CONFIG_DEBUG 1)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include <bl808_glb.h>
|
||||
#include <bflb_mtimer.h>
|
||||
#include <bflb_flash.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#ifdef CONFIG_TLSF
|
||||
#include <bflb_tlsf.h>
|
||||
#endif
|
||||
|
@ -18,6 +20,8 @@
|
|||
extern uint32_t __start;
|
||||
int main(void)
|
||||
{
|
||||
TaskHandle_t rpmsg_task_handle = NULL;
|
||||
|
||||
board_init();
|
||||
#if 0
|
||||
/* setup JTAG for D0 */
|
||||
|
@ -40,9 +44,14 @@ int main(void)
|
|||
pt_table_set_flash_operation(bflb_flash_erase, bflb_flash_write, bflb_flash_read);
|
||||
pt_table_dump();
|
||||
#endif
|
||||
ipc_init();
|
||||
if (xTaskCreate(rpmsg_task, "RPMSG_TASK", 2048, NULL, tskIDLE_PRIORITY + 1U, &rpmsg_task_handle) != pdPASS)
|
||||
{
|
||||
printf("\r\nFailed to create rpmsg task\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// vTaskStartScheduler();
|
||||
|
||||
vTaskStartScheduler();
|
||||
/* we should never get here */
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ target_sources(app PRIVATE
|
|||
src/console.c
|
||||
src/partition.c
|
||||
src/softcrc.c
|
||||
src/bl808_ipc.c
|
||||
)
|
||||
|
||||
add_subdirectory(src/cmd)
|
||||
|
|
|
@ -31,6 +31,8 @@ extern void cdc_acm_multi_init(void);
|
|||
extern uint32_t __start;
|
||||
int main(void)
|
||||
{
|
||||
TaskHandle_t rpmsg_task_handle = NULL;
|
||||
|
||||
board_init();
|
||||
struct bflb_device_s *gpio = bflb_device_get_by_name("gpio");
|
||||
bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_ALTERNATE | GPIO_FUNC_JTAG_M0);
|
||||
|
@ -52,7 +54,11 @@ int main(void)
|
|||
pt_table_set_flash_operation(bflb_flash_erase, bflb_flash_write, bflb_flash_read);
|
||||
pt_table_dump();
|
||||
|
||||
ipc_init();
|
||||
if (xTaskCreate(rpmsg_task, "RPMSG_TASK", 2048, NULL, tskIDLE_PRIORITY + 1U, &rpmsg_task_handle) != pdPASS)
|
||||
{
|
||||
printf("\r\nFailed to create rpmsg task\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
vTaskStartScheduler();
|
||||
/* we should never get here */
|
||||
|
|
Loading…
Add table
Reference in a new issue