add KPU driver and resource in XiZi for edu-riscv64
This commit is contained in:
@@ -48,6 +48,7 @@ Modification:
|
||||
#include "connect_w5500.h"
|
||||
#include "connect_wdt.h"
|
||||
#include "connect_dvp.h"
|
||||
#include "connect_kpu.h"
|
||||
#include "dmac.h"
|
||||
#include "encoding.h"
|
||||
#include "fpioa.h"
|
||||
@@ -71,6 +72,7 @@ extern int HwSpiInit(void);
|
||||
extern int HwSoftSPIInit(void);
|
||||
extern int HwWiznetInit(void);
|
||||
extern int HwDvpInit(void);
|
||||
extern int HwKpuInit(void);
|
||||
|
||||
#include <iot-vfs.h>
|
||||
#ifdef MOUNT_USB
|
||||
@@ -221,6 +223,9 @@ struct InitSequenceDesc _board_init[] = {
|
||||
#endif
|
||||
#ifdef BSP_USING_CAMERA
|
||||
{"hw_camera", HwDvpInit },
|
||||
#endif
|
||||
#ifdef BSP_USING_KPU
|
||||
{"hw_kpu", HwKpuInit },
|
||||
#endif
|
||||
{ " NONE ",NONE },
|
||||
};
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file connect_dvp.h
|
||||
* @brief define edu-riscv64-board DVP init function
|
||||
* @version 2.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-11-21
|
||||
*/
|
||||
#ifndef CONNECT_DVP_H
|
||||
#define CONNECT_DVP_H
|
||||
#include <device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *buffer;
|
||||
size_t length;
|
||||
}KpuOutputBuffer;
|
||||
|
||||
|
||||
int HwKpuInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1 +1,15 @@
|
||||
if BSP_USING_KPU
|
||||
config KPU_DMA_CH
|
||||
int "KPU DMA channel number"
|
||||
default 5
|
||||
|
||||
config KPU_BUS_NAME
|
||||
string "kpu bus name"
|
||||
default "kpu"
|
||||
config KPU_DRV_NAME
|
||||
string "kpu driver name"
|
||||
default "kpu_drv"
|
||||
config KPU_DEVICE_NAME
|
||||
string "kpu device name"
|
||||
default "kpu_dev"
|
||||
endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
SRC_FILES := kpu.c
|
||||
SRC_FILES := kpu.c connect_kpu.c
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
#include <connect_kpu.h>
|
||||
#include <kpu.h>
|
||||
#include <board.h>
|
||||
#include "bsp.h"
|
||||
|
||||
#define LOAD_KMODEL 0xA0
|
||||
#define RUN_KMODEL 0xA1
|
||||
#define GET_OUTPUT 0xA2
|
||||
#define WAIT_FLAG 0xA3
|
||||
|
||||
static kpu_model_context_t kpu_task;
|
||||
static int g_ai_done_flag = 0;
|
||||
|
||||
// irq interrupt function
|
||||
static void ai_done(void *ctx)
|
||||
{
|
||||
g_ai_done_flag = 1;
|
||||
}
|
||||
|
||||
struct KpuRegConfigureInfo
|
||||
{
|
||||
uint8_t device_addr;
|
||||
uint16_t reg_addr;
|
||||
uint8_t reg_value;
|
||||
};
|
||||
|
||||
static uint32 KpuDrvInit(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32 KpuOpen(void *dev)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
KpuDrvInit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32 KpuClose(void *dev)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32 KpuDrvConfigure(void *drv, struct BusConfigureInfo *args)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
int cmd_type = args->configure_cmd;
|
||||
KpuOutputBuffer* output_data;
|
||||
switch (cmd_type)
|
||||
{
|
||||
case OPE_INT:
|
||||
break;
|
||||
case OPE_CFG:
|
||||
break;
|
||||
case LOAD_KMODEL:
|
||||
kpu_load_kmodel(&kpu_task, args->private_data);
|
||||
break;
|
||||
case RUN_KMODEL:
|
||||
g_ai_done_flag=0;
|
||||
kpu_run_kmodel(&kpu_task, args->private_data, KPU_DMA_CH, ai_done, NULL);
|
||||
break;
|
||||
case GET_OUTPUT:
|
||||
output_data = (KpuOutputBuffer*)args->private_data;
|
||||
kpu_get_output(&kpu_task, 0, (uint8_t **)&(output_data->buffer), &(output_data->length));
|
||||
break;
|
||||
case WAIT_FLAG:
|
||||
*((uint8_t*)(args->private_data)) = g_ai_done_flag;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*manage the kpu device operations*/
|
||||
static const struct KpuDevDone kpu_dev_done =
|
||||
{
|
||||
.dev_open = KpuOpen,
|
||||
.dev_close = KpuClose,
|
||||
.dev_write = NONE,
|
||||
.dev_read = NONE,
|
||||
};
|
||||
|
||||
/*Init kpu bus*/
|
||||
static int BoardKpuBusInit(struct KpuBus *kpu_bus, struct KpuDriver *kpu_driver)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
||||
/*Init the kpu bus */
|
||||
kpu_bus->private_data = (void *)&kpu_dev_done;
|
||||
ret = KpuBusInit(kpu_bus, KPU_BUS_NAME);
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_init KpuBusInit error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*Init the kpu driver*/
|
||||
kpu_driver->private_data = (void *)&kpu_dev_done;
|
||||
ret = KpuDriverInit(kpu_driver, KPU_DRV_NAME);
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_init KpuDriverInit error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*Attach the kpu driver to the kpu bus*/
|
||||
ret = KpuDriverAttachToBus(KPU_DRV_NAME, KPU_BUS_NAME);
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_init KpuDriverAttachToBus error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Attach the kpu device to the kpu bus*/
|
||||
static int BoardKpuDevBend(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
static struct KpuHardwareDevice kpu_device;
|
||||
memset(&kpu_device, 0, sizeof(struct KpuHardwareDevice));
|
||||
|
||||
kpu_device.kpu_dev_done = &kpu_dev_done;
|
||||
|
||||
ret = KpuDeviceRegister(&kpu_device, NONE, KPU_DEVICE_NAME);
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_init KpuDeviceInit device %s error %d\n", KPU_DEVICE_NAME, ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = KpuDeviceAttachToBus(KPU_DEVICE_NAME, KPU_BUS_NAME);
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_init KpuDeviceAttachToBus device %s error %d\n", KPU_DEVICE_NAME, ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HwKpuInit(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
static struct KpuBus kpu_bus;
|
||||
memset(&kpu_bus, 0, sizeof(struct KpuBus));
|
||||
|
||||
static struct KpuDriver kpu_driver;
|
||||
memset(&kpu_driver, 0, sizeof(struct KpuDriver));
|
||||
|
||||
kpu_driver.configure = KpuDrvConfigure;
|
||||
ret = BoardKpuBusInit(&kpu_bus, &kpu_driver);
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_Init error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = BoardKpuDevBend();
|
||||
if (EOK != ret)
|
||||
{
|
||||
KPrintf("board_kpu_Init error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user