/****************************************************************************** * @fn HalUARTInit * * @brief Initialize the UART * * @param none * * @return none *****************************************************************************/ void HalUARTInit(void) { #if (HAL_UART_DMA && HAL_UART_SPI) // When both are defined, port is run-time choice. if (HAL_UART_PORT) { HalUARTInitSPI(); } else { HalUARTInitDMA(); } #else #if HAL_UART_DMA HalUARTInitDMA(); #endif #if HAL_UART_ISR HalUARTInitISR(); #endif #if HAL_UART_SPI HalUARTInitSPI(); #endif #if HAL_UART_USB HalUARTInitUSB(); #endif #endif }
/************************************************************************************************** * @fn sblRun * * @brief Serial Boot run code for the SPI transport. * * input parameters * * None. * * output parameters * * None. * * @return None. */ static void sblRun(void) { halUARTCfg_t uartConfig; uartConfig.callBackFunc = sblRxCB; HAL_DMA_SET_ADDR_DESC1234(dmaCh1234); HalUARTInitSPI(); HalUARTOpenSPI(&uartConfig); while (1) { if (PxIFG & SPI_RDYIn_BIT) { spiRdyIn(); } HalUARTPollSPI(); if (HAL_DMA_CHECK_IRQ(HAL_SPI_CH_TX)) { HAL_DMA_CLEAR_IRQ(HAL_SPI_CH_TX); HalUART_DMAIsrSPI(); if (sblReset) { HAL_SYSTEM_RESET(); } } } }
/************************************************************************************************** * @fn sblExec * * @brief Infinite SBL execute loop that jumps upon receiving a code enable. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void sblExec(void) { halUARTCfg_t uartConfig; uartConfig.callBackFunc = sblRxCB; HalUARTInitSPI(); if (bootloaderCommunicationRequested() || (!sbImgValid())) { while (1) { /* Read , parse, and respond to incoming bytes*/ sblRxCB(0, 0); /* exit loop if image is successfully verified and enabled */ if (sblReset) { break; } } } /* Some delay to send final response to master */ for(uint32 i = 0; i < ENABLE_RSP_DELAY; i++) { ASM_NOP; } /* Some delay to send final response to master */ HalUARTUnInitSPI(); /* Jump to application image */ EnterNvmApplication((uint32)sbl_header_ptr->vectorTableAddress); }
/************************************************************************************************** * @fn sblInit * * @brief Initialization for SBL. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void sblInit(void) { HAL_BOARD_INIT(); vddWait(VDD_MIN_RUN); magicByte = SB_MAGIC_VALUE; /* This is in place of calling HalDmaInit() which would require init of the other 4 DMA * descriptors in addition to just Channel 0. */ HAL_DMA_SET_ADDR_DESC0(&dmaCh0); #if defined CC2530_MK znpCfg1 = ZNP_CFG1_SPI; #else znpCfg1 = P2_0; #endif if (znpCfg1 == ZNP_CFG1_SPI) { SRDY_CLR(); // Select general purpose on I/O pins. P0SEL &= ~(NP_RDYIn_BIT); // P0.3 MRDY - GPIO P0SEL &= ~(NP_RDYOut_BIT); // P0.4 SRDY - GPIO // Select GPIO direction. P0DIR &= ~NP_RDYIn_BIT; // P0.3 MRDY - IN P0DIR |= NP_RDYOut_BIT; // P0.4 SRDY - OUT P0INP &= ~NP_RDYIn_BIT; // Pullup/down enable of MRDY input. P2INP &= ~BV(5); // Pullup all P0 inputs. HalUARTInitSPI(); } else { halUARTCfg_t uartConfig; HalUARTInitISR(); uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 0; // CC2530 by #define - see hal_board_cfg.h uartConfig.rx.maxBufSize = 0; // CC2530 by #define - see hal_board_cfg.h uartConfig.tx.maxBufSize = 0; // CC2530 by #define - see hal_board_cfg.h uartConfig.idleTimeout = 0; // CC2530 by #define - see hal_board_cfg.h uartConfig.intEnable = TRUE; uartConfig.callBackFunc = NULL; HalUARTOpenISR(&uartConfig); } }