初始提交

This commit is contained in:
2024-09-28 14:24:04 +08:00
commit c756587541
5564 changed files with 2413077 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
# OUTPUT type
# 1 - .out
# 2 - .a
# 3 - .so
OUTPUT_TYPE = 1
OUTPUT_NAME = dma_device_test
SUB_DIRS =
# .h files dir
ADD_INCLUDE += $(TOPDIR)/plc/halphy/inc $(TOPDIR)/inc/compiler/gcc $(TOPDIR)/inc $(TOPDIR)/inc/io_lib $(TOPDIR)/inc/driver $(TOPDIR)/inc/uart $(TOPDIR)/inc/plc_lib $(TOPDIR)/inc/ipc $(TOPDIR)/inc/os_shim $(TOPDIR)/inc/pkt $(TOPDIR)/inc/utils $(TOPDIR)/plc/inc $(TOPDIR)/inc/cli $(TOPDIR)/cli/communicator $(TOPDIR)/inc/dbglog $(TOPDIR)/inc/ftm $(TOPDIR)/plc/halmac/inc $(TOPDIR)/plc/halmac/hw/inc/desc $(TOPDIR)/driver/inc
# predefined macro
PRE_MARCO =
ifeq ($(gcc), arm)
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/ARM_CM3
else
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/RISCV
endif
ifeq ($(gcc),arm)
ADD_LIB = cm3
ADD_LIBDIR = $(TOPDIR)/startup/cm3
else
ifeq ($(target), kunlun2)
ADD_LIB = riscv
ADD_LIBDIR =$(TOPDIR)/startup/riscv2
ADD_INCLUDE += $(TOPDIR)/driver/src/hw2/inc
else
ADD_LIB = riscv
ADD_LIBDIR =$(TOPDIR)/startup/riscv
ADD_INCLUDE += $(TOPDIR)/driver/src/hw/inc
endif
endif
# lib dir
ADD_LIBDIR += $(TOPDIR)/plc $(TOPDIR)/driver $(TOPDIR)/common $(TOPDIR)/os
# lib need to ld together
ADD_LIB += os plc driver common
#####################################################
ifdef TOPDIR
include $(TOPDIR)/build/makefile.cfg
else
include $(CURDIR)/build/makefile.cfg
TOPDIR = $(CURDIR)
export TOPDIR
endif
dump:
$(OBJDUMP) -D -S -l $(OUTPUT_FULL_NAME) > $(OUTPUT_FULL_NAME).dump
# display the obj files and output name
debug:
@echo TOPDIR=$(TOPDIR)
@echo OUTPUT_LIB=$(OUTPUT_FULL_NAME)
@echo DEPS=$(DEPS)
@echo OBJECTS=$(OBJECTS)
@echo SRCS=$(SRCS)
@echo OBJECTS folder=$(foreach dirname, $(SUB_DIRS), $(addprefix $(BIN_DIR)/, $(dirname)))
@echo output_name=$(OUTPUT_FULL_NAME)

View File

@@ -0,0 +1,367 @@
/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
/* os shim includes */
#include "os_types.h"
#include "os_task.h"
#include "os_utils.h"
/* common includes */
#include "iot_io.h"
#include "iot_bitops.h"
#include "iot_pkt.h"
#include "iot_ipc.h"
#include "iot_dbglog_api.h"
#include "iot_config.h"
/* driver includes */
#include "iot_clock.h"
#include "iot_uart.h"
#include "uart.h"
#include "apb_dma.h"
#include "dma_hw.h"
/* cli includes */
#include "iot_cli.h"
#include "iot_uart_h.h"
/* debug includes*/
#include "dbg_io.h"
extern int platform_init();
os_task_h test_init_handle;
static const iot_pkt_config_t test_pkt_config =
{
{
{
256,
50,
PKT_OWNER_ALL,
},
{
600,
50,
PKT_OWNER_ALL,
},
{
1100,
15,
PKT_OWNER_ALL,
},
{
2200,
6,
PKT_OWNER_ALL,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
}
};
desc_t *pdesc_rx=NULL;
desc_t *pdesc_tx=NULL;
desc_t *pdesc_rx_end=NULL;
desc_t *pdesc_tx_end=NULL;
#define TEST_DESC_NUM 10 /* RX = TX = TEST_DESC_NUM */
#define TEST_BUF_SIZE 64 /* Each buffer has this size */
#define DMA_TEST_DEVICE DMA_DEV_UART0// DMA_DEV_SPI0
#if DMA_TEST_DEVICE == 4
#include "iot_spi_api.h"
#include "apb.h"
#include "gpio_mtx.h"
void dma_spi_gpio_config()
{
gpio_mtx_enable();
/* 10<->clk, 11<-> CS, 15<->MOSI, 12<->MISO */
gpio_sig_info_t info1 = {
4,
{
{IO_TYPE_OUT, 0, 10, 0xff, 20},
{IO_TYPE_OUT, 0, 11, 0xff, 21},
{IO_TYPE_OUT, 0, 15, 0xff, 22},
{IO_TYPE_IN, 0, 12, 16, 0xff}
}
};
gpio_module_pin_select(&info1);
gpio_module_sig_select(&info1, GPIO_MTX_MODE_MATRIX);
}
#endif
void dma_desc_tail_exchange(desc_t*desc0, desc_t*desc1)
{
volatile unsigned int tail;
tail = desc0->tail_lable[0];
desc0->tail_lable[0] = desc1->tail_lable[0];
desc1->tail_lable[0] = tail;
}
int int_stack[0x20];
void dma_uart_handler(int device, int status)
{
desc_t *st, *end, *pnt;
iot_pkt_t **pkt;
static int int_stack_index=0;
int_stack[(int_stack_index++)&0x1F] = status;
if(DMA_INT_IN_SUC_EOF&status)
{
end = st = pdesc_rx_end;
while((end->n_ptr != st) && (end->n_ptr->owner != DESC_OWNER_DMA)) end = end->n_ptr;
pdesc_rx_end = end->n_ptr;
pnt = pdesc_tx;
while(st != end->n_ptr)
{
/* prepare pkt before exchange */
pkt = (iot_pkt_t**)EXTEN_POINTER(st);
iot_pkt_set_tail(*pkt, (*pkt)->data + st->length);
pkt = (iot_pkt_t**)EXTEN_POINTER(pnt);
iot_pkt_set_data(*pkt, (*pkt)->head);
iot_pkt_set_tail(*pkt, (*pkt)->head);
dma_desc_tail_exchange(pnt, st);
pkt = (iot_pkt_t**)EXTEN_POINTER(st);
DMA_MAKE_DESC(st, (*pkt)->data, TEST_BUF_SIZE, 0, 0, 0, 0, DESC_OWNER_DMA);
/* send pkt recieved */
pkt = (iot_pkt_t**)EXTEN_POINTER(pnt);
DMA_MAKE_DESC(pnt, (*pkt)->data, TEST_BUF_SIZE, iot_pkt_block_len(*pkt, IOT_PKT_BLOCK_DATA),\
0, 0, 0, DESC_OWNER_DMA);
st = st->n_ptr;
pnt = pnt->n_ptr;
}
end = pnt->l_ptr;
end->n_ptr = NULL;
pdesc_tx_end->n_ptr = pdesc_tx;
if(DESC_OWNER_CPU == pdesc_tx_end->owner)
{
dma_hw_start_send(DMA_TEST_DEVICE, pdesc_tx);
}
pdesc_tx = pnt;
pdesc_tx_end = end;
}
return ;
}
void dma_test(void)
{
int cnt;
desc_t *rx, *tx;
iot_pkt_t **pkt;
dma_hw_init(NULL);
#if(DMA_TEST_DEVICE == 4)
sdma_cfg dma_cfg;
dma_spi_gpio_config();
(void)iot_spi_module_init(NULL);
dma_cfg.rx_enable =1;
dma_cfg.tx_enable =1;
dma_cfg.rx_datalevel = 8;
dma_cfg.tx_datalevel = 8;
(void)iot_spi_dev_register_detail(DEVICE_SPI0_MASTER, NULL, NULL,
&dma_cfg, NULL, 0x0);
#endif
const int desc_size = sizeof(desc_t) + sizeof(iot_pkt_t*);
#if 1
pdesc_rx = (desc_t*)os_mem_malloc(0, TEST_DESC_NUM*desc_size);
pdesc_tx = (desc_t*)os_mem_malloc(0, TEST_DESC_NUM*desc_size);
#endif
if(NULL == pdesc_tx
||NULL == pdesc_rx)
{
if(pdesc_tx)
os_mem_free(pdesc_tx);
pdesc_tx = NULL;
return ;
}
(void)dma_hw_open(DMA_TEST_DEVICE, (dma_int_handler)dma_uart_handler, NULL);
rx = pdesc_rx;
tx = pdesc_tx;
/* To fill descriptors */
for(cnt=0; cnt<TEST_DESC_NUM; cnt++)
{
/* for RX */
pkt = (iot_pkt_t**)EXTEN_POINTER(rx);
*pkt = iot_pkt_alloc(TEST_BUF_SIZE+4, IOT_DRIVER_MID);
DMA_MAKE_DESC(rx, (*pkt)->data, TEST_BUF_SIZE, 0, 0, 0, 0, DESC_OWNER_DMA);
os_mem_set((*pkt)->data, 'a'+cnt, TEST_BUF_SIZE);
rx->n_ptr = (desc_t*)((int)rx + desc_size);
rx->l_ptr = (desc_t*)((int)rx - desc_size);
/* for TX */
pkt = (iot_pkt_t**)EXTEN_POINTER(tx);
*pkt = iot_pkt_alloc(TEST_BUF_SIZE+4, IOT_DRIVER_MID);
DMA_MAKE_DESC(tx, (*pkt)->data, TEST_BUF_SIZE, TEST_BUF_SIZE, 0, 0, 0, DESC_OWNER_DMA);
DMA_INTR_ENA(tx);
os_mem_set((*pkt)->data, 'A'+cnt, TEST_BUF_SIZE);
tx->n_ptr = (desc_t*)((int)tx + desc_size);
tx->l_ptr = (desc_t*)((int)tx - desc_size);
rx = (desc_t*)((int)rx + desc_size);
tx = (desc_t*)((int)tx + desc_size);
}
rx = (desc_t*)((int)pdesc_rx + desc_size*(TEST_DESC_NUM-1));
tx = (desc_t*)((int)pdesc_tx + desc_size*(TEST_DESC_NUM-1));
pdesc_rx->l_ptr = rx;
rx->n_ptr = pdesc_rx;
pdesc_tx->l_ptr = tx;
tx->n_ptr = NULL;
pdesc_tx_end = tx;
pdesc_rx_end = pdesc_rx;
dma_hw_start_recieve(DMA_TEST_DEVICE, pdesc_rx);
dma_hw_start_send(DMA_TEST_DEVICE, pdesc_tx);
}
void test_init()
{
/* init common modules */
iot_bitops_init();
/* init os related modules and utilities */
os_utils_init();
/* init dbglog module */
iot_dbglog_init();
/* init pkt module */
iot_pkt_init(&test_pkt_config);
/* init ipc module */
//iot_ipc_init();
/*init uart module*/
iot_uart_init(1);
dma_test();
}
void iot_task_1(void *arg)
{
iot_printf("task 1 entry....\n");
for(;;) {
test_init();
os_delete_task(test_init_handle);
}
}
int32_t iot_task_init()
{
/* start plc lib task */
test_init_handle = os_create_task(iot_task_1, NULL, 9);
//create the tasks;
if(test_init_handle != NULL) {
iot_printf("task 1 init successfully...\n");
}
return 0;
}
int32_t iot_task_start()
{
//start the tasks;
os_start_kernel();
return 0;
}
static int32_t iot_platform_init()
{
/*platform intialization*/
platform_init();
//resource initializations;
system_clock_init();
system_uart_init();
dbg_uart_init();
dbg_uart_stage1_init();
return 0;
}
int32_t iot_module_init(void)
{
//platform intialization;
iot_platform_init();
//create all the tasks;
iot_task_init();
iot_printf("starting...\n");
return 0;
}
int32_t iot_module_start(void)
{
int32_t res = 0;
res = iot_task_start();
return res;
}
#include "apb_dma.h"
int main(void)
{
//module init;
iot_module_init();
iot_module_start();
return 0;
}