Skip to content

Commit

Permalink
mailbox: control LED through the little core
Browse files Browse the repository at this point in the history
  • Loading branch information
carbonfix committed Nov 30, 2023
1 parent 1bca506 commit 9426e0a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
8 changes: 7 additions & 1 deletion freertos/cvitek/driver/rtos_cmdqu/include/rtos_cmdqu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
#define NR_RTOS_CMD 127
#define NR_RTOS_IP IP_LIMIT


enum SYS_CMD_ID {
CMD_TEST_A = 0x10,
CMD_TEST_B,
CMD_TEST_C,
CMD_DUO_LED,
SYS_CMD_INFO_LIMIT,
};

enum DUO_LED_STATUS {
DUO_LED_ON = 0x02,
DUO_LED_OFF,
DUO_LED_DONE,
};

struct valid_t {
unsigned char linux_valid;
unsigned char rtos_valid;
Expand Down
16 changes: 15 additions & 1 deletion freertos/cvitek/task/comm/src/riscv64/comm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "comm.h"
#include "cvi_spinlock.h"

/* Milk-V Duo */
#include "milkv_duo_io.h"

// #define __DEBUG__
#ifdef __DEBUG__
Expand Down Expand Up @@ -94,7 +96,6 @@ void main_cvirtos(void)
/* Start the tasks and timer running. */
vTaskStartScheduler();


/* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then
there was either insufficient FreeRTOS heap memory available for the idle
Expand Down Expand Up @@ -158,6 +159,19 @@ void prvCmdQuRunTask(void *pvParameters)
rtos_cmdq.resv.valid.linux_valid = 0;
printf("recv cmd(%d) from C906B...send [0x%x] to C906B\n", rtos_cmdq.cmd_id, rtos_cmdq.param_ptr);
goto send_label;
case CMD_DUO_LED:
rtos_cmdq.cmd_id = CMD_DUO_LED;
printf("recv cmd(%d) from C906B, param_ptr [0x%x]\n", rtos_cmdq.cmd_id, rtos_cmdq.param_ptr);
if (rtos_cmdq.param_ptr == DUO_LED_ON) {
duo_led_control(1);
} else {
duo_led_control(0);
}
rtos_cmdq.param_ptr = DUO_LED_DONE;
rtos_cmdq.resv.valid.rtos_valid = 1;
rtos_cmdq.resv.valid.linux_valid = 0;
printf("recv cmd(%d) from C906B...send [0x%x] to C906B\n", rtos_cmdq.cmd_id, rtos_cmdq.param_ptr);
goto send_label;
default:
send_label:
/* used to send command to linux*/
Expand Down
12 changes: 12 additions & 0 deletions freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "milkv_duo_io.h"

void duo_led_control(int enable)
{
*(uint32_t*)(GPIO2 | GPIO_SWPORTA_DDR) = 1 << 24;

if (enable) {
*(uint32_t*)(GPIO2 | GPIO_SWPORTA_DR) = 1 << 24;
} else {
*(uint32_t*)(GPIO2 | GPIO_SWPORTA_DR) = 0;
}
}
14 changes: 14 additions & 0 deletions freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>
/*
* The blue LED on Duo is GPIOC24.
* The datasheet page 536 says:
* Configure register GPIO_SWPORTA_DDR and set GPIO as input or output.
* When the output pin is configured, write the output value to the
* GPIO_SWPORTA_DR register to control the GPIO output level.
*/

#define GPIO2 0x03022000
#define GPIO_SWPORTA_DR 0x000
#define GPIO_SWPORTA_DDR 0x004

void duo_led_control(int enable);
1 change: 1 addition & 0 deletions linux_5.10/drivers/soc/cvitek/rtos_cmdqu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cvi_mbox-y := rtos_cmdqu.o \
cvi_spinlock.o

ccflags-y += -I$(srctree)/$(src)/
ccflags-$(CONFIG_DYNAMIC_DEBUG) += -DDEBUG
7 changes: 0 additions & 7 deletions linux_5.10/drivers/soc/cvitek/rtos_cmdqu/rtos_cmdqu.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ enum SYSTEM_CMD_TYPE {
CMDQU_SYSTEM_LIMIT = NR_SYSTEM_CMD,
};

enum SYS_CMD_ID {
CMD_TEST_A = 0x10,
CMD_TEST_B,
CMD_TEST_C,
SYS_CMD_INFO_LIMIT,
};

#define RTOS_CMDQU_DEV_NAME "cvi-rtos-cmdqu"
#define RTOS_CMDQU_SEND _IOW('r', CMDQU_SEND, unsigned long)
#define RTOS_CMDQU_SEND_WAIT _IOW('r', CMDQU_SEND_WAIT, unsigned long)
Expand Down

0 comments on commit 9426e0a

Please sign in to comment.