diff --git a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/User/ch32v20x_it.c b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/User/ch32v20x_it.c index 7a161e5fd..bb3663c52 100644 --- a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/User/ch32v20x_it.c +++ b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/User/ch32v20x_it.c @@ -11,10 +11,15 @@ *******************************************************************************/ #include "ch32v20x_it.h" #include "board.h" +#include "ch32v20x_exti.h" +#include "ch32v20x_tim.h" +#include "eth_driver.h" #include void NMI_Handler(void) __attribute__((interrupt())); void HardFault_Handler(void) __attribute__((interrupt())); +void ETH_IRQHandler(void) __attribute__((interrupt())); +void TIM2_IRQHandler(void) __attribute__((interrupt())); /********************************************************************* * @fn NMI_Handler @@ -55,4 +60,43 @@ void HardFault_Handler(void) FREE_INT_SP(); } +/********************************************************************* + * @fn ETH_IRQHandler + * + * @brief This function handles ETH exception. + * + * @return none + */ +void ETH_IRQHandler(void) +{ + WCHNET_ETHIsr(); +} + +/********************************************************************* + * @fn TIM2_IRQHandler + * + * @brief This function handles TIM2 exception. + * + * @return none + */ +void TIM2_IRQHandler(void) +{ + // GET_INT_SP(); + // /* enter interrupt */ + // x_base level; + // level = DisableLocalInterrupt(); + // isrManager.done->incCounter(); + // EnableLocalInterrupt(level); + // WCHNET_TimeIsr(WCHNETTIMERPERIOD); + // TIM_ClearITPendingBit(TIM2, TIM_IT_Update); + // /* leave interrupt */ + // level = DisableLocalInterrupt(); + // isrManager.done->decCounter(); + // EnableLocalInterrupt(level); + // FREE_INT_SP(); + // KPrintf("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); + WCHNET_TimeIsr(WCHNETTIMERPERIOD); + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); +} + diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c index c8f27cb02..110a432b8 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c @@ -44,7 +44,7 @@ extern uint32_t SystemCoreClock; static uint32_t _SysTick_Config(uint32_t ticks) { // SystemCoreClockUpdate(); - NVIC_SetPriority(SysTicK_IRQn, 1); + NVIC_SetPriority(SysTicK_IRQn, 0x01); NVIC_SetPriority(Software_IRQn, 0xf0); NVIC_EnableIRQ(SysTicK_IRQn); NVIC_EnableIRQ(Software_IRQn); @@ -60,6 +60,7 @@ static uint32_t _SysTick_Config(uint32_t ticks) */ void InitBoardHardware() { + Delay_Init(); USART_Printf_Init(115200); /* System Tick Configuration */ _SysTick_Config(SystemCoreClock / TICK_PER_SECOND); @@ -68,19 +69,19 @@ void InitBoardHardware() InitHwUart(); InstallConsole("uart1", SERIAL_DRV_NAME_1, SERIAL_1_DEVICE_NAME_0); #ifdef BSP_USING_ETH - // InitHwEth(); + InitHwEth(); #endif KPrintf("consle init completed.\n"); KPrintf("board initialization......\n"); // KPrintf("memory address range: [0x%08x - 0x%08x], size: %d\n", (x_ubase) MEMORY_START_ADDRESS, (x_ubase) MEMORY_END_ADDRESS, gd32vf103_SRAM_SIZE); KPrintf("memory address range: [0x%08x - 0x%08x] SRAM_SIZE: %d, ssize: %d\n", (x_ubase) MEMORY_START_ADDRESS, (x_ubase) MEMORY_END_ADDRESS, SRAM_SIZE, __stack_size); /* initialize memory system */ - x_ubase dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)MEMORY_START_ADDRESS, MM_PAGE_SIZE); - x_ubase dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)MEMORY_END_ADDRESS, MM_PAGE_SIZE); - KPrintf("dynamic buddy address range: [0x%08x - 0x%08x]\n", dynamic_buddy_start, dynamic_buddy_end); + // x_ubase dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)MEMORY_START_ADDRESS, MM_PAGE_SIZE); + // x_ubase dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)MEMORY_END_ADDRESS, MM_PAGE_SIZE); + // KPrintf("dynamic buddy address range: [0x%08x - 0x%08x]\n", dynamic_buddy_start, dynamic_buddy_end); // memory address range: [0x20001440 - 0xcb0843e0] // dynamic buddy address range: [0x20002000 - 0xcb084000] - ShowMemory(); + // ShowMemory(); KPrintf("board init done.\n"); KPrintf("start okernel...\n"); } diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c index 0ee5fd80a..cd810a63b 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c @@ -240,13 +240,13 @@ uint8_t InitHwEth() KPrintf("version error.\n"); } - // WCHNET_GetMacAddr(MACAddr); // get the chip MAC address + WCHNET_GetMacAddr(MACAddr); // get the chip MAC address KPrintf("mac addr:"); for (i = 0; i < 6; i++) KPrintf("%x ", MACAddr[i]); KPrintf("\n"); - // TIM2_Init(); + TIM2_Init(); i = ETH_LibInit(IPAddr, GWIPAddr, IPMask, MACAddr); // Ethernet library initialize mStopIfError(i); @@ -263,7 +263,7 @@ uint8_t InitHwEth() } #endif -// memset(socket, 0xff, WCHNET_MAX_SOCKET_NUM); + memset(socket, 0xff, WCHNET_MAX_SOCKET_NUM); return i; } diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c index c6e95a9f7..f0d3aa08e 100755 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c @@ -702,7 +702,7 @@ void WCHNET_ETHIsr( void ) void ETH_Init( uint8_t *macAddr ) { ETH_LedConfiguration( ); - Delay_Ms(100); + // Delay_Ms(100); // there is a bug: the Systick register didn't restore original state, causing systick interrupt failing. ETH_Configuration( macAddr ); ETH_DMATxDescChainInit(DMATxDscrTab, MACTxBuf, ETH_TXBUFNB); ETH_DMARxDescChainInit(DMARxDscrTab, MACRxBuf, ETH_RXBUFNB);