diff --git a/freertos/cvitek/driver/rtos_cmdqu/include/rtos_cmdqu.h b/freertos/cvitek/driver/rtos_cmdqu/include/rtos_cmdqu.h index 5d329e11de..93a5e8e417 100644 --- a/freertos/cvitek/driver/rtos_cmdqu/include/rtos_cmdqu.h +++ b/freertos/cvitek/driver/rtos_cmdqu/include/rtos_cmdqu.h @@ -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; diff --git a/freertos/cvitek/task/comm/src/riscv64/comm_main.c b/freertos/cvitek/task/comm/src/riscv64/comm_main.c index c90889ae38..502f5f7a16 100644 --- a/freertos/cvitek/task/comm/src/riscv64/comm_main.c +++ b/freertos/cvitek/task/comm/src/riscv64/comm_main.c @@ -18,6 +18,8 @@ #include "comm.h" #include "cvi_spinlock.h" +/* Milk-V Duo */ +#include "milkv_duo_io.h" // #define __DEBUG__ #ifdef __DEBUG__ @@ -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 @@ -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*/ diff --git a/freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.c b/freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.c new file mode 100644 index 0000000000..882500f57c --- /dev/null +++ b/freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.c @@ -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; + } +} diff --git a/freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.h b/freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.h new file mode 100644 index 0000000000..595b1416e5 --- /dev/null +++ b/freertos/cvitek/task/comm/src/riscv64/milkv_duo_io.h @@ -0,0 +1,14 @@ +#include +/* + * 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); diff --git a/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/Makefile b/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/Makefile index c87f9994e3..d3d3677072 100644 --- a/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/Makefile +++ b/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/Makefile @@ -3,3 +3,4 @@ cvi_mbox-y := rtos_cmdqu.o \ cvi_spinlock.o ccflags-y += -I$(srctree)/$(src)/ +ccflags-$(CONFIG_DYNAMIC_DEBUG) += -DDEBUG diff --git a/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/rtos_cmdqu.h b/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/rtos_cmdqu.h index 6281da79a7..236a753c68 100644 --- a/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/rtos_cmdqu.h +++ b/linux_5.10/drivers/soc/cvitek/rtos_cmdqu/rtos_cmdqu.h @@ -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)