uint32_t HAL_PRCM_GetLFClock(void) { uint32_t val = HAL_GET_BIT(PRCM->SYS_LFCLK_CTRL, PRCM_LFCLK_SRC_MASK); if (val == PRCM_LFCLK_SRC_INTER32K && HAL_GET_BIT(PRCM->SYS_RCOSC_CALIB_CTRL, PRCM_RCOSC_CALIB_EN_BIT)) { return HAL_PRCM_GetInter32KFreq(); } else { return SYS_LFCLOCK; } }
uint32_t HAL_PRCM_GetLDOEnableFlags(void) { return HAL_GET_BIT(PRCM->SYS_LDO_SW_CTRL, PRCM_LDO1_EN_BIT | PRCM_PLL_LDO_EN_BIT | PRCM_SRAM_LDO_EN_BIT); }
/** * @brief Gets the CSI moudle status. * @param None. * @retval CSI_Status: The status of CSI. */ CSI_Status HAL_CSI_Status() { CSI_Status sta; sta.luminance = HAL_GET_BIT(CSI->CSI_BUF_STA_REG, LUM_STATIS) >> 8; sta.still_Mode = HAL_GET_BIT(CSI->CSI_BUF_STA_REG, HAL_BIT(1)) >> 1; sta.video_Mode = HAL_GET_BIT(CSI->CSI_BUF_STA_REG, HAL_BIT(0)); return sta; }
/** * @brief Cached data length of FIFO. * @param None * @retval CSI_FIFO_Data_Len: The data length of CSI_FIFO_A and CSI_FIFO_B. * @arg FIFO_0_A_Data_Len: The data length of CSI_FIFO_A. * @arg FIFO_0_B_Data_Len: The data length of CSI_FIFO_B. */ __nonxip_text CSI_FIFO_Data_Len HAL_CSI_FIFO_Data_Len() { CSI_FIFO_Data_Len len; len.FIFO_0_B_Data_Len = HAL_GET_BIT(CSI->CSI_TRUE_DATA_NUM, (CSI_VALID_DATA_LEN << 16)) >> 16; len.FIFO_0_A_Data_Len = HAL_GET_BIT(CSI->CSI_TRUE_DATA_NUM, CSI_VALID_DATA_LEN); return len; }
/** * @brief Get interrupt mode of the specified ADC channel * @param[in] chan The specified ADC channel * @retval HAL_Status, HAL_OK on success */ ADC_IRQState HAL_ADC_GetIRQState(ADC_Channel chan) { ADC_ASSERT_CHANNEL(chan); if (HAL_GET_BIT(gADCPrivate.dataPending, HAL_BIT(chan)) && ADC_GetChanDataIRQ(chan)) { if (HAL_GET_BIT(gADCPrivate.lowPending, HAL_BIT(chan)) && ADC_GetChanLowIRQ(chan)) return ADC_LOW_DATA_IRQ; if (HAL_GET_BIT(gADCPrivate.highPending, HAL_BIT(chan)) && ADC_GetChanHighIRQ(chan)) return ADC_HIGH_DATA_IRQ; else return ADC_DATA_IRQ; } else { if (HAL_GET_BIT(gADCPrivate.lowPending, HAL_BIT(chan)) && ADC_GetChanLowIRQ(chan)) return ADC_LOW_IRQ; if (HAL_GET_BIT(gADCPrivate.highPending, HAL_BIT(chan)) && ADC_GetChanHighIRQ(chan)) return ADC_HIGH_IRQ; else return ADC_NO_IRQ; } }
uint32_t HAL_PRCM_GetSysPowerEnableFlags(void) { return HAL_GET_BIT(PRCM->SYS_LDO_SW_CTRL, PRCM_SYS1_PWR1_EN_BIT | PRCM_SYS1_PWR2_EN_BIT | PRCM_SYS2_PWR3_EN_BIT | PRCM_SYS3_PWR4_EN_BIT | PRCM_SYS3_PWR5_EN_BIT | PRCM_SYS1_SRAM_PWR1_EN_BIT | PRCM_SYS2_SRAM_PWR2_EN_BIT | PRCM_SYS3_SRAM_PWR3_EN_BIT); }
__nonxip_text void GPADC_IRQHandler(void) { if(gADCPrivate.mode == ADC_BURST_CONV) { uint32_t i; uint32_t fifoverunPending, fifodataPending; fifoverunPending = ADC_GetFifoOverunPending(); fifodataPending = ADC_GetFifodataPending(); ADC_ClrFifoPending(fifoverunPending); ADC_ClrFifoPending(fifodataPending); if(fifodataPending) { for (i = ADC_CHANNEL_0; i < ADC_CHANNEL_NUM; i++) { if (ADC_GetChanPinMux(i) && (gADCPrivate.IRQCallback[i])) gADCPrivate.IRQCallback[i](gADCPrivate.arg[i]); } } } else { uint32_t i; gADCPrivate.lowPending = ADC_GetLowPending(); gADCPrivate.highPending = ADC_GetHighPending(); gADCPrivate.dataPending = ADC_GetDataPending(); ADC_ClrLowPending(gADCPrivate.lowPending); ADC_ClrHighPending(gADCPrivate.highPending); ADC_ClrDataPending(gADCPrivate.dataPending); for (i = ADC_CHANNEL_0; i < ADC_CHANNEL_NUM; i++) { if (((HAL_GET_BIT(gADCPrivate.dataPending, HAL_BIT(i)) && ADC_GetChanDataIRQ(i)) || (HAL_GET_BIT(gADCPrivate.lowPending, HAL_BIT(i)) && ADC_GetChanLowIRQ(i)) || (HAL_GET_BIT(gADCPrivate.highPending, HAL_BIT(i)) && ADC_GetChanHighIRQ(i))) && (gADCPrivate.IRQCallback[i])) { gADCPrivate.IRQCallback[i](gADCPrivate.arg[i]); } } } }
__STATIC_INLINE uint32_t ADC_GetValue(ADC_Channel chan) { return HAL_GET_BIT(ADC->DATA[chan], ADC_DATA_MASK); }
__STATIC_INLINE void ADC_SetLowValue(ADC_Channel chan, uint32_t value) { HAL_MODIFY_REG(ADC->CMP_DATA[chan], ADC_LOW_DATA_MASK, HAL_GET_BIT(value << ADC_LOW_DATA_SHIFT, ADC_LOW_DATA_MASK)); }
__nonxip_text static __always_inline uint32_t ADC_GetDataPending(void) { return HAL_GET_BIT(ADC->DATA_STATUS, ADC_DATA_PENDING_MASK); }
__nonxip_text static __always_inline uint8_t I2C_IsMemMode(I2C_Private *priv) { return !!HAL_GET_BIT(priv->ctrl, I2C_MEM_MODE_BIT); }
__nonxip_text static __always_inline uint8_t ADC_GetChanPinMux(ADC_Channel chan) { return !!HAL_GET_BIT(gADCPrivate.chanPinMux, HAL_BIT(chan)); }
static __always_inline uint8_t I2C_IsInitState(I2C_Private *priv) { return !!HAL_GET_BIT(priv->ctrl, I2C_INIT_STATE_BIT); }
__nonxip_text static __always_inline uint8_t ADC_GetChanDataIRQ(ADC_Channel chan) { return !!HAL_GET_BIT(ADC->DATA_CONFIG, HAL_BIT(chan)); }
/** * @brief The specified ADC channel convert once in polling mode * @param[in] chan The specified ADC channel * @param[in] data Pointer to the output data * @param[in] msec Timeout value in millisecond of conversion * HAL_WAIT_FOREVER for no timeout * @retval HAL_Status, HAL_OK on success */ HAL_Status HAL_ADC_Conv_Polling(ADC_Channel chan, uint32_t *data, uint32_t msec) { unsigned long flags; ADC_Private *priv; uint32_t stopTime; uint8_t isTimeout; ADC_ASSERT_CHANNEL(chan); flags = HAL_EnterCriticalSection(); priv = &gADCPrivate; if (priv->state == ADC_STATE_READY) priv->state = ADC_STATE_BUSY; else priv = NULL; HAL_ExitCriticalSection(flags); if (priv == NULL) { HAL_WRN("ADC state: %d\n", gADCPrivate.state); return HAL_ERROR; } if ((!ADC_GetChanPinMux(chan)) && (chan != ADC_CHANNEL_8)) { HAL_BoardIoctl(HAL_BIR_PINMUX_INIT, HAL_MKDEV(HAL_DEV_MAJOR_ADC, chan), 0); ADC_SetChanPinMux(chan); } ADC_DisableAllChanSel(); ADC_DisableAllChanCmp(); ADC_DisableAllChanIRQ(); if (chan == ADC_CHANNEL_8) ADC_EnableVbatDetec(); ADC_EnableChanSel(chan); if (msec == HAL_WAIT_FOREVER) stopTime = 0xFFFFFFFF; else stopTime = HAL_TicksToMSecs(HAL_Ticks()) + msec; if (stopTime < msec) { HAL_ERR("stopTime overflow.\n"); return HAL_ERROR; } isTimeout = 1; ADC_EnableADC(); while (HAL_TicksToMSecs(HAL_Ticks()) <= stopTime) { if (HAL_GET_BIT(ADC_GetDataPending(), HAL_BIT(chan))) { *data = ADC_GetValue(chan); ADC_ClrDataPending(ADC_GetDataPending()); isTimeout = 0; break; } } ADC_DisableADC(); ADC_DisableChanSel(chan); if (chan == ADC_CHANNEL_8) ADC_DisableVbatDetec(); if (ADC_GetChanPinMux(chan) && (chan != ADC_CHANNEL_8)) { HAL_BoardIoctl(HAL_BIR_PINMUX_DEINIT, HAL_MKDEV(HAL_DEV_MAJOR_ADC, chan), 0); ADC_ClrChanPinMux(chan); } flags = HAL_EnterCriticalSection(); priv->state = ADC_STATE_READY; HAL_ExitCriticalSection(flags); if (isTimeout) { HAL_WRN("ADC timeout.\n"); return HAL_TIMEOUT; } else { return HAL_OK; } }
__STATIC_INLINE uint32_t ADC_GetCalibState(void) { return !!HAL_GET_BIT(ADC->CTRL, ADC_CALIB_EN_BIT); }
__STATIC_INLINE void ADC_SetWorkMode(ADC_WorkMode workMode) { HAL_MODIFY_REG(ADC->CTRL, ADC_WORK_MODE_MASK, HAL_GET_BIT(workMode << ADC_WORK_MODE_SHIFT, ADC_WORK_MODE_MASK)); }
__STATIC_INLINE void ADC_SetOPBias(uint32_t opBias) { HAL_MODIFY_REG(ADC->CTRL, ADC_OP_BIAS_MASK, HAL_GET_BIT(opBias << ADC_OP_BIAS_SHIFT, ADC_OP_BIAS_MASK)); }
__STATIC_INLINE void ADC_SetFirstDelay(uint32_t firstDelay) { HAL_MODIFY_REG(ADC->CTRL, ADC_FIRST_DELAY_MASK, HAL_GET_BIT(firstDelay << ADC_FIRST_DELAY_SHIFT, ADC_FIRST_DELAY_MASK)); }
__STATIC_INLINE void ADC_SetSampleRate(uint32_t fsDiv, uint32_t tAcq) { ADC->SAMPLE_RATE = (HAL_GET_BIT(fsDiv << ADC_FS_DIV_SHIFT, ADC_FS_DIV_MASK) | HAL_GET_BIT(tAcq << ADC_TACQ_SHIFT, ADC_TACQ_MASK)); }
__STATIC_INLINE void ADC_SetFifoLevel(uint8_t level) { HAL_MODIFY_REG(ADC->FIFO_CTRL, ADC_FIFO_LEVEL_MASK, HAL_GET_BIT((level - 1) << ADC_FIFO_LEVEL_SHIFT, ADC_FIFO_LEVEL_MASK)); }
/* * @brief */ __SPI_STATIC_INLINE__ bool SPI_ClearInt(SPI_T *spi, SPI_Int_Type type) { HAL_SET_BIT(spi->STA, type); return HAL_GET_BIT(spi->STA, type); }
/* * @brief */ __SPI_STATIC_INLINE__ bool SPI_IntState(SPI_T *spi, SPI_Int_Type type) { return !!HAL_GET_BIT(spi->STA, type); }
__nonxip_text static __always_inline uint32_t ADC_GetFifoOverunPending(void) { return HAL_GET_BIT(ADC->FIFO_STATUS, ADC_FIFO_OVERUN_PENDING_MASK); }
/* * @brief */ __SPI_STATIC_INLINE__ void SPI_ResetRxFifo(SPI_T *spi) { HAL_SET_BIT(spi->FCTL, SPI_FCTL_RF_RST_MASK); while (HAL_GET_BIT(spi->FCTL, SPI_FCTL_RF_RST_MASK) != 0); }
__STATIC_INLINE uint32_t ADC_GetFifoData(void) { return HAL_GET_BIT(ADC->FIFO_DATA, ADC_FIFO_DATA_MASK); }
__nonxip_text static __always_inline uint8_t I2C_Is7BitAddrMode(I2C_Private *priv) { return !!HAL_GET_BIT(priv->ctrl, I2C_7BIT_ADDR_BIT); }
__nonxip_text static __always_inline uint32_t ADC_GetLowPending(void) { return HAL_GET_BIT(ADC->LOW_STATUS, ADC_LOW_PENDING_MASK); }
__nonxip_text static __always_inline uint8_t I2C_IsRestart(I2C_Private *priv) { return !!HAL_GET_BIT(priv->ctrl, I2C_RESTART_BIT); }
__nonxip_text static __always_inline uint32_t ADC_GetHighPending(void) { return HAL_GET_BIT(ADC->HIGH_STATUS, ADC_HIGH_PENDING_MASK); }