Skip to content

Commit

Permalink
feat: add demo for shared memory communication
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Martins <[email protected]>
  • Loading branch information
josecm committed Feb 5, 2023
1 parent fb27436 commit 4010db4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ NAME:=baremetal
ROOT_DIR:=$(realpath .)
BUILD_DIR:=$(ROOT_DIR)/build/$(PLATFORM)

ifneq ($(DEMO_IPC),)
CPPFLAGS+=-DDEMO_IPC
endif

# Setup baremetal-runtime build
include $(ROOT_DIR)/setup.mk

Expand Down
42 changes: 41 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <core.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cpu.h>
#include <wfi.h>
#include <spinlock.h>
Expand All @@ -29,9 +30,44 @@

spinlock_t print_lock = SPINLOCK_INITVAL;

#ifdef DEMO_IPC

#define SHMEM_IRQ_ID (52)

char* const baremetal_message = (char*)0x70000000;
char* const zephyr_message = (char*)0x70002000;
const size_t shmem_channel_size = 0x2000;

void shmem_update_msg(int irq_count) {
sprintf(baremetal_message, "Bao baremetal guest received %d uart interrupts!\n",
irq_count);
}

void shmem_handler() {
zephyr_message[shmem_channel_size-1] = '\0';
char* end = strchr(zephyr_message, '\n');
*end = '\0';
printf("message from zephyr: %s\n", zephyr_message);
}

void shmem_init() {
memset(baremetal_message, 0, shmem_channel_size);
memset(zephyr_message, 0, shmem_channel_size);
shmem_update_msg(0);
irq_set_handler(SHMEM_IRQ_ID, shmem_handler);
irq_set_prio(SHMEM_IRQ_ID, IRQ_MAX_PRIO);
irq_enable(SHMEM_IRQ_ID);
}

#endif

void uart_rx_handler(){
printf("cpu%d: %s\n",get_cpuid(), __func__);
static int irq_count = 0;
printf("cpu%d: %s %d\n",get_cpuid(), __func__, ++irq_count);
uart_clear_rxirq();
#ifdef DEMO_IPC
shmem_update_msg(irq_count);
#endif
}

void ipi_handler(){
Expand Down Expand Up @@ -64,6 +100,10 @@ void main(void){
irq_enable(TIMER_IRQ_ID);
irq_set_prio(TIMER_IRQ_ID, IRQ_MAX_PRIO);

#ifdef DEMO_IPC
shmem_init();
#endif

master_done = true;
}

Expand Down

0 comments on commit 4010db4

Please sign in to comment.