diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/config.mk b/Ubiquitous/XiZi_IIoT/board/ch569w/config.mk index 6db9c93c7..d87b3d1d1 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/config.mk +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/config.mk @@ -14,5 +14,6 @@ export DEFINES := -DDEBUG=1 export ARCH = risc-v export MCU = CH569W - - +ifeq ($(CONFIG_BSP_USING_SERDES), y) +export LINK_BOARD += $(KERNEL_ROOT)/board/ch569w/third_party_driver/serdes/libSERDES.a +endif diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig index ccc8dac9c..0b8a591b2 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig @@ -13,6 +13,13 @@ menuconfig BSP_USING_SPI source "$BSP_DIR/third_party_driver/spi/Kconfig" endif +menuconfig BSP_USING_SERDES + bool "Using serdes device" + default y + if BSP_USING_SERDES + source "$BSP_DIR/third_party_driver/serdes/Kconfig" + endif + menuconfig BSP_USING_WDT bool "Using watchdog timer device" - default y + default n diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile index b4644627d..6cc73d828 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile @@ -10,6 +10,10 @@ ifeq ($(CONFIG_BSP_USING_SPI),y) SRC_DIR += spi endif +ifeq ($(CONFIG_BSP_USING_SPI),y) + SRC_DIR += serdes +endif + ifeq ($(CONFIG_BSP_USING_WDT),y) SRC_DIR += wdt endif diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/include/connect_serdes.h b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/include/connect_serdes.h new file mode 100644 index 000000000..4d125cc3b --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/include/connect_serdes.h @@ -0,0 +1,196 @@ + +#ifndef __CONNECT_SERDES_H__ +#define __CONNECT_SERDES_H__ + + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CH56xSFR.h" +#include "core_riscv.h" + +# + +#define SDS_ALIGN_EN (1<<18) +#define SDS_CONT_EN (1<<17) +#define SDS_POWR_UP (1<<16) +#define SDS_TX_PU (1<<15) +#define SDS_RX_PU (1<<14) +#define SDS_PLL_PU (1<<13) +#define SDS_PLL_DIV (18<<8) // 60*(DIV+2)MHz +#define SDS_PLL_1_2G (18<<8) // 60*(18+2)MHz +#define SDS_PLL_900M (13<<8) // 60*(13+2)MHz +#define SDS_PLL_600M ( 8<<8) // 60*(8+2)MHz + +#define SDS_DMA_EN 1<<7 +#define SDS_TX_EN 1<<6 +#define SDS_RX_EN 1<<5 +#define SDS_RX_POLAR 1<<4 +#define SDS_INT_BUSY_EN 1<<3 +#define PHY_RESET 1<<2 +#define LINK_RESET 1<<1 +#define SDS_ALL_CLR 1<<0 + +#define SDS_LINK_INIT 1<<16 +#define SDS_TX_START ((uint32_t)1<<17) +#define SDS_BUF_MODE 1<<18 + +#define SDS_PHY_RDY_EN 1<<0 +#define SDS_TX_INT_EN 1<<1 +#define SDS_RX_ERR_EN 1<<1 +#define SDS_RX_INT_EN 1<<2 +#define SDS_FIFO_OV_EN 1<<3 +#define SDS_COMMA_INT_EN 1<<5 +#define ALL_INT_TYPE 47 + +#define SDS_PHY_RDY_FLG 1<<0 +#define SDS_TX_INT_FLG 1<<1 +#define SDS_RX_INT_FLG 1<<2 +#define SDS_FIFO_OV_FLG 1<<3 +#define SDS_COMMA_INT_FLG 1<<5 +#define ALL_INT_FLG 47 + +#define SDS_SEQ_MATCH 1<<17 +#define SDS_RX_CRC_OK 1<<18 +#define SDS_PLL_READY 1<<19 +#define SDS_TX_READY 1<<20 + +#define SDS_RX_BUF 1<<24 +#define SDS_TX_BUF 1<<28 + +#define SDS_TX_NUMP_1 1<<20 +#define SDS_TX_NUMP_2 2<<20 +#define SDS_TX_NUMP_3 3<<20 +#define SDS_TX_NUMP_4 4<<20 + +/******************************************************************************* +* Function Name : Serdes_Tx_Init +* Description : Serdes configuration of hardware in Tx mode +* Input : None +* Return : None +*******************************************************************************/ +extern void Serdes_Tx_Init(void); + +/******************************************************************************* +* Function Name : Serdes_Rx_init +* Description : Serdes configuration of hardware in Rx mode +* Input : None +* Return : None +*******************************************************************************/ +extern UINT8 Serdes_Rx_Init(UINT32 cnt); + +/******************************************************************************* +* Function Name : DMA_Tx_CFG +* Description : Configure DMA transmitting mode +* Input : DMAaddr: DMA starting address +* Tx_len : length of transmitting data once +* custom_number: customized data using for data checking +* Return : None +*******************************************************************************/ +extern void DMA_Tx_CFG( UINT32 DMAaddr, UINT32 Tx_len, UINT32 custom_number); + +/******************************************************************************* +* Function Name : DoubleDMA_Rx_CFG +* Description : Configure double DMA receiving mode +* Input : DMA0_addr: DMA0 starting address + DMA1_addr: DMA1 starting address +* Return : None +*******************************************************************************/ +extern void DoubleDMA_Rx_CFG( UINT32 DMA0_addr , UINT32 DMA1_addr ); + +/******************************************************************************* +* Function Name : DMA_Tx +* Description : DMA start sending data +* Input : None +* Return : None +*******************************************************************************/ +extern void DMA_Tx(void); + +/******************************************************************************* +* Function Name : DMA_Rx_check +* Description : double DMA receiving data +* Input : DMA0_addr--DMA0 address + DMA1_addr--DMA1 address + custom_number: customized data using for data checking, + consistent with the transmitting one +* Return : None +*******************************************************************************/ +extern void DMA_Rx_check( UINT32 DMA0_addr, UINT32 DMA1_addr, UINT32 custom_number); + +/******************************************************************************* +* Function Name : ClearITFlag +* Description : Clear interruption flag +* Input : ITFlag: + 1.SDS_PHY_RDY_FLG + 2.SDS_TX_INT_FLG + 3.SDS_RX_INT_FLG + 4.SDS_FIFO_OV_FLG + 5.SDS_COMMA_INT_FLG + 6.ALL_INT_FLG +* Return : None +*******************************************************************************/ +extern void ClearITFlag( UINT16 ITFlag); + +/******************************************************************************* +* Function Name : EnableIT +* Description : Enable Interrupt +* Input : ITType: + 1.SDS_PHY_RDY_EN + 2(1).SDS_TX_INT_EN (Tx mode) + 2(2).SDS_RX_ERR_EN (Rx mode) + 3.SDS_RX_INT_EN + 4.SDS_FIFO_OV_EN + 5.SDS_COMMA_INT_EN + 6.ALL_INT_TYPE +* Return : None +*******************************************************************************/ +extern void EnableIT( UINT16 ITType); + +/******************************************************************************* +* Function Name : Wait_Txdone +* Description : waiting for Tx done +* Input : None +* Return : None +*******************************************************************************/ +extern void Wait_Txdone(void); + +/******************************************************************************* +* Function Name : Wait_commadone +* Description : waiting for Rx COMMA done +* Input : None +* Return : None +*******************************************************************************/ +extern UINT8 Wait_commadone(UINT32 cnt); + +/******************************************************************************* +* Function Name : ReadRxFlagBit +* Description : read Rx IT status +* Input : None +* Return : None +*******************************************************************************/ +extern UINT32 ReadITFlagBit(UINT16 ITFlag); + +/******************************************************************************* +* Function Name : ReadCOMMAFlagBit +* Description : read COMMA IT status +* Input : None +* Return : None +*******************************************************************************/ +extern UINT32 ReadCOMMAFlagBit(void); + +/******************************************************************************* +* Function Name : serdes_Rx_init +* Description : receiver module initialization +* Input : None +* Return : None +*******************************************************************************/ +extern void serdes_Rx_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/Kconfig b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/Kconfig new file mode 100644 index 000000000..47ea6f04b --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/Kconfig @@ -0,0 +1,7 @@ +config SERDES_TRANS + bool "Config serdes transmit mode." + default y + +config SERIAL_RECEI + bool "Config serdes receive mode." + default y \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/Makefile b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/Makefile new file mode 100644 index 000000000..2b985267c --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := connect_serdes.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/connect_serdes.c b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/connect_serdes.c new file mode 100644 index 000000000..06d6b68e1 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/connect_serdes.c @@ -0,0 +1,154 @@ +/* + * 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_usart.c + * @brief support ch569 uart function and register to bus framework + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2025-04-07 + */ + +#include "CH56x_common.h" +#include "xizi.h" +#include "board.h" +#include "shell.h" +#include "connect_serdes.h" + + +//#define Trans 1 +//#define Recei 1 + +//UINT32 Tx_DMAaddr = 0x20020000; +//UINT32 RX_DMA0_addr = 0x20033330; +//UINT32 RX_DMA1_addr = 0x20034330; +UINT32 Tx_DMAaddr[512] __attribute__((aligned(16))) = {0}; +UINT32 RX_DMA0_addr[512] __attribute__((aligned(16))) = {0}; +UINT32 RX_DMA1_addr[512] __attribute__((aligned(16))) = {0}; + +volatile UINT32 i=0; +volatile UINT32 k=0; +/******************************************************************************* +* Function Name : __attribute__((interrupt())) +* Description : SERDES_IRQHandler hard push +* Input : baudrate: UART1 communication baud rate. +* Return : None +*******************************************************************************/ +void SERDES_IRQHandler (void) __attribute__((interrupt())); + +/******************************************************************************* +* Function Name : SerdesTxTest +* Description : SerdesTxTest program. +* Input : None +* Return : None +*******************************************************************************/ +int SerdesTxTest(void) +{ + UINT32 *p32_txdma = (UINT32 *)Tx_DMAaddr; + UINT32 n=0; + UINT32 data=0; + + KPrintf("SerdesTxTest start\r\n"); + KPrintf("SerdesTxTest Tx_DMAaddr=0x%08x\r\n", (UINT32)Tx_DMAaddr); + +#ifdef SERDES_TRANS //Serdes query sent. + Serdes_Tx_Init(); + + do + { + *p32_txdma++ = data; + data += 0x01010101; + n++; + }while(n!=512); + mDelaymS(500); + + DMA_Tx_CFG( (UINT32)Tx_DMAaddr,2048,0x555555); //512 address spaces 2048 bytes + + while(1) + { + KPrintf("SerdesTxTest DMA_Tx\r\n"); + DMA_Tx(); + Wait_Txdone(); + ClearITFlag(SDS_TX_INT_FLG); + mDelaymS(5000); + } +#endif + +} + +/******************************************************************************* +* Function Name : SerdesRxTest +* Description : SerdesRxTest program. +* Input : None +* Return : None +*******************************************************************************/ +int SerdesRxTest(void) +{ + KPrintf("SerdesRxTest start\r\n"); + KPrintf("SerdesRxTest RX_DMA0_addr=0x%08x RX_DMA1_addr=0x%08x\r\n", (UINT32)RX_DMA0_addr, (UINT32)RX_DMA1_addr); + +#ifdef SERIAL_RECEI // Serdes interrupt reception. + PFIC_EnableIRQ(INT_ID_SERDES); + + DoubleDMA_Rx_CFG((UINT32)RX_DMA0_addr , (UINT32)RX_DMA1_addr ); + Serdes_Rx_Init(10*1000*1000); + Wait_commadone(10*1000*1000); + Serdes_Rx_Init(10*1000*1000); + EnableIT(SDS_RX_INT_EN|SDS_COMMA_INT_EN); + + KPrintf("SerdesRxTest init OK\r\n"); + while(1) + { + if(k==2) // After each completion of the double-buffered reception, print the received data. + { + for(i=0;i<512;i++) + { + KPrintf("%x\r\n",*(UINT32 *)(0x20033330+4*i)); + KPrintf("%x\r\n",*(UINT32 *)(0x20034330+4*i)); + } + k=0; + } + } +#endif +} + +/******************************************************************************* +* Function Name : SERDES_IRQHandler +* Description : Interruption function +* Input : None +* Return : None +*******************************************************************************/ +void SERDES_IRQHandler (void) +{ + if(ReadITFlagBit(SDS_RX_INT_FLG)) + { + ClearITFlag(SDS_RX_INT_FLG); + k++; + DMA_Rx_check((UINT32)RX_DMA0_addr, (UINT32)RX_DMA1_addr, 0x555555); + KPrintf("\nbuffer received ....... !\n"); + } + if(ReadITFlagBit(SDS_COMMA_INT_FLG)) + { + KPrintf("\nreceive COMMA, init....... !\n"); + Serdes_Rx_Init( 1000*30 ); + i = 0; + mDelaymS(50); + ClearITFlag(SDS_COMMA_INT_FLG); + } +} + + +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + SerdesTxTest, SerdesTxTest, test serdes tx); + +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + SerdesRxTest, SerdesRxTest, test serdes rx); diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/libSERDES.a b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/libSERDES.a new file mode 100644 index 000000000..1d9b91a31 Binary files /dev/null and b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/serdes/libSERDES.a differ diff --git a/Ubiquitous/XiZi_IIoT/link.mk b/Ubiquitous/XiZi_IIoT/link.mk index fa76da46c..00e8eb95b 100644 --- a/Ubiquitous/XiZi_IIoT/link.mk +++ b/Ubiquitous/XiZi_IIoT/link.mk @@ -3,7 +3,7 @@ OBJS := $(shell cat make.obj) $(TARGET): $(OBJS) @echo ------------------------------------------------ @echo link $(TARGET) - @$(CROSS_COMPILE)g++ -o $@ $($(LINK_FLAGS)) $(OBJS) $(LINK_LWIP) $(LINK_MUSLLIB) $(LINK_MONGOOSE) $(LINK_WCH_NET) $(LIBCC) $(LINK_WCH_BLE) + @$(CROSS_COMPILE)g++ -o $@ $($(LINK_FLAGS)) $(OBJS) $(LINK_LWIP) $(LINK_MUSLLIB) $(LINK_MONGOOSE) $(LINK_WCH_NET) $(LIBCC) $(LINK_WCH_BLE) $(LINK_BOARD) @echo ------------------------------------------------ @$(CROSS_COMPILE)objcopy -O binary $@ XiZi-$(BOARD)$(COMPILE_TYPE).bin @$(CROSS_COMPILE)objdump -S $@ > XiZi-$(BOARD)$(COMPILE_TYPE).asm