/*! @brief Enable an External Interrupt @details Enables and sets the triggering mode for the given external interrupt. Applications may register a callback using the #adi_xint_RegisterCallback API to get a notification when the interrupt occurs. To get the external interrupt working application has to enable the input (using the GPIO driver API \a adi_gpio_InputEnable) for the corresponding GPIO pin. Please refer the GPIO chapter pin-muxing section of the Hardware Reference Manual to see the GPIO pin that is mapped to the required external interrupt. @param[in] eEvent Event which needs to be enabled. @param[in] eMode Interrupt trigger mode for the external interrupt. @return Status - #ADI_XINT_SUCCESS If successfully enabled the external interrupt. - #ADI_XINT_NOT_INITIALIZED [D] If external interrupt driver not yet initialized. @sa adi_xint_DisableIRQ @sa adi_xint_RegisterCallback */ ADI_XINT_RESULT adi_xint_EnableIRQ(const ADI_XINT_EVENT eEvent, const ADI_XINT_IRQ_MODE eMode) { uint32_t Mask; /* mask to manipulate the register */ uint32_t Pattern; /* bit pattern that will be written into the register */ uint32_t CfgReg; /* interrupt config register value */ IRQn_Type XintIrq; ADI_INT_STATUS_ALLOC(); #ifdef ADI_DEBUG /* make sure we're initialized */ if (NULL == gpCallbackTable) { return (ADI_XINT_NOT_INITIALIZED); } #endif /* create the mask we'll use to clear the relevant bits in the config register */ Mask = (BITM_XINT_CFG0_IRQ0MDE | BITM_XINT_CFG0_IRQ0EN) << (ADI_XINT_CFG_BITS * (uint32_t)eEvent); /* The Pattern has to be created differently for UART RX wakeup and other events as the mode and enable bits are flipped in case of UART RX */ /* Based on the event figure out the interrupt it is mapped to */ if(eEvent == ADI_XINT_EVENT_UART_RX) { /* create the bit pattern we're going to write into the configuration register */ Pattern = (BITM_XINT_CFG0_UART_RX_EN | ((uint32_t)eMode << BITP_XINT_CFG0_UART_RX_MDE)); XintIrq = XINT_EVT3_IRQn; } else { /* create the bit pattern we're going to write into the configuration register */ Pattern = (BITM_XINT_CFG0_IRQ0EN | eMode) << (ADI_XINT_CFG_BITS * (uint32_t)eEvent); XintIrq = (IRQn_Type)((uint32_t)XINT_EVT0_IRQn + (uint32_t)eEvent); } ADI_ENTER_CRITICAL_REGION(); /* read/modify/write the appropriate bits in the register */ CfgReg = pADI_XINT0->CFG0; CfgReg &= ~Mask; CfgReg |= Pattern; pADI_XINT0->CFG0 = CfgReg; ADI_EXIT_CRITICAL_REGION(); /* enable the interrupt */ NVIC_EnableIRQ(XintIrq); return (ADI_XINT_SUCCESS); }
/*! * @brief WDT Enable * * @details Enables/disables the WDT with the paramters supplied in adi_wdt_config.h * * @param [in] bEnable : True to turn WDT on, false to turn it off * * @param [in] pfCallback : If interrupt mode is enabled, specify application callback function, * otherwise simply pass NULL for the argument. * * @return ADI_WDT_RESULT * - #ADI_WDT_FAILURE_LOCKED WDT has already been initialized * - #ADI_WDT_SUCCESS Function call completed successfully */ ADI_WDT_RESULT adi_wdt_Enable(bool const bEnable, ADI_CALLBACK const pfCallback) { /* IF(Device is enabled, application can't modify it) */ if ((pADI_WDT0->STAT & ((uint16_t) BITM_WDT_STAT_LOCKED)) != ((uint16_t) 0x0u)) { return ADI_WDT_FAILURE_LOCKED; } /* ENDIF */ /* Setup interrupts if we are in interrupt mode */ #if (ADI_WDT_CONTROL_TIMEOUT_MODE == 1u) gAppCallback = pfCallback; /* IF(We are enabling the WDT) */ if (bEnable == true) { NVIC_EnableIRQ (WDT_EXP_IRQn); /* ELSE (We are disabling the WDT, this might not be necessary, depends on startup config) */ } else { NVIC_DisableIRQ(WDT_EXP_IRQn); } /* ENDIF */ #endif /* WHILE(Bus sync is underway) */ while((pADI_WDT0->STAT & ADI_WDT_SYNC_BITS) != 0u) { ; } /* ENDWHILE */ ADI_INT_STATUS_ALLOC(); ADI_ENTER_CRITICAL_REGION(); pADI_WDT0->LOAD = ADI_WDT_LOAD_VALUE; /* IF(Turning the WDT on) */ if (bEnable == true) { pADI_WDT0->CTL = (ADI_WDT_CONTROL_TIMER_MODE << BITP_WDT_CTL_MODE) | (0x1u << BITP_WDT_CTL_EN ) | (ADI_WDT_CONTROL_CLOCK_PRESCALER << BITP_WDT_CTL_PRE ) | (ADI_WDT_CONTROL_TIMEOUT_MODE << BITP_WDT_CTL_IRQ ) | (ADI_WDT_CONTROL_POWER_MODE << 0u ); /* ELSE(Turning the WDT off) */ } else { pADI_WDT0->CTL = (ADI_WDT_CONTROL_TIMER_MODE << BITP_WDT_CTL_MODE) | (0x0u << BITP_WDT_CTL_EN ) | (ADI_WDT_CONTROL_CLOCK_PRESCALER << BITP_WDT_CTL_PRE ) | (ADI_WDT_CONTROL_TIMEOUT_MODE << BITP_WDT_CTL_IRQ ) | (ADI_WDT_CONTROL_POWER_MODE << 0u ); } /* ENDIF */ ADI_EXIT_CRITICAL_REGION(); return ADI_WDT_SUCCESS; }
/*! @brief Set GP Timer to operate in Free Running Mode @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid */ ADI_GPT_RESULT_TYPE adi_GPT_SetFreeRunningMode(ADI_GPT_HANDLE hDevice) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } #endif // clear mod bit for free-running mode ADI_ENTER_CRITICAL_REGION(); hDevice->pTmr->CON &= ~TCON_MOD; ADI_EXIT_CRITICAL_REGION(); return ADI_GPT_SUCCESS; }
/*! @brief GP Set Count Mode Timers can be configured to either count up or count down. @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init @param[in] Mode ADI_GPT_COUNT_MODE_TYPE @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid */ ADI_GPT_RESULT_TYPE adi_GPT_SetCountMode(ADI_GPT_HANDLE hDevice, ADI_GPT_COUNT_MODE_TYPE Mode) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } #endif ADI_ENTER_CRITICAL_REGION(); hDevice->pTmr->CON &= ~TCON_UP; hDevice->pTmr->CON |= Mode; ADI_EXIT_CRITICAL_REGION(); return ADI_GPT_SUCCESS; }
/*! @brief GP Clock Select Selects the clock source for a GP Timer @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init(). @param[in] ClockSelect Selection is made from one of the following clock sources: UCLK/PCLK, according to target processor PCLK/Internal HF 16 MHz oscillator, according to target processor Internal LF 32 kHz oscillator External LF 32 kHz crystal (requires external crystal oscillator circuit enable) @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid - #ADI_GPT_ERR_PARAM_OUT_OF_RANGE [D] if param is invalid @note If selecting the external clock source, #ADI_GPT_CLOCK_SELECT_EXTERNAL_CLOCK, the external crystal oscillator circuit must be separetly enabled via the Power Device Driver. If and when disabeling the "External Clock" source, make sure it is not also being used (as a system clock mutplixer input) by some other system resource. @sa adi_PWR_SetLFXTALOscEnable(). */ ADI_GPT_RESULT_TYPE adi_GPT_SetClockSelect(ADI_GPT_HANDLE hDevice, ADI_GPT_CLOCK_SELECT_TYPE ClockSelect) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } if (ClockSelect != (ClockSelect & TCON_CLK_MSK)) return ADI_GPT_ERR_PARAM_OUT_OF_RANGE; #endif ADI_ENTER_CRITICAL_REGION(); hDevice->pTmr->CON &= ~TCON_CLK_MSK; hDevice->pTmr->CON |= ClockSelect; ADI_EXIT_CRITICAL_REGION(); return ADI_GPT_SUCCESS; }
/*! @brief Enable/Disable the GP Timer @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init @param[in] bEnable True: Enable the timer False: Disable and reset the timer, including the GPTVAL register @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid */ ADI_GPT_RESULT_TYPE adi_GPT_SetTimerEnable(ADI_GPT_HANDLE hDevice, bool_t bEnable) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } #endif ADI_ENTER_CRITICAL_REGION(); if (bEnable) { hDevice->pTmr->CON |= TCON_ENABLE; } else { hDevice->pTmr->CON &= ~TCON_ENABLE; } ADI_EXIT_CRITICAL_REGION(); return ADI_GPT_SUCCESS; }
/*! @brief GP Timer set prescaler Timer can be configured with various prescaler values. @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init @param[in] preScaler Prescaler emum value for clock scaling @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid - #ADI_GPT_ERR_PARAM_OUT_OF_RANGE [D] if param is invalid */ ADI_GPT_RESULT_TYPE adi_GPT_SetPrescaler(ADI_GPT_HANDLE hDevice, ADI_GPT_PRESCALER_TYPE preScaler) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } if (preScaler != (preScaler & TCON_PRE_MSK)) return ADI_GPT_ERR_PARAM_OUT_OF_RANGE; #endif ADI_ENTER_CRITICAL_REGION(); hDevice->pTmr->CON &= ~TCON_PRE_MSK; hDevice->pTmr->CON |= preScaler; ADI_EXIT_CRITICAL_REGION(); return ADI_GPT_SUCCESS; }
/*! @brief GP Timer Set Event to Capture Each timer can be configured to capture one of various events. @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init @param[in] Event @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid - #ADI_GPT_ERR_PARAM_OUT_OF_RANGE [D] if param is invalid */ ADI_GPT_RESULT_TYPE adi_GPT_SetEventToCapture(ADI_GPT_HANDLE hDevice, ADI_GPT_CAPTURE_EVENTS_TYPE Event) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } if (Event != (Event & TCON_EVENT_MSK)) return ADI_GPT_ERR_PARAM_OUT_OF_RANGE; #endif ADI_ENTER_CRITICAL_REGION(); hDevice->pTmr->CON &= ~TCON_EVENT_MSK; hDevice->pTmr->CON |= Event; ADI_EXIT_CRITICAL_REGION(); return ADI_GPT_SUCCESS; }
/*! @brief Register or unregister an application callback function for external pin interrupts. @details Applications may register a callback function that will be called when an external interrupt occurs. In addition to registering the interrupt, the application should call the #adi_xint_EnableIRQ API to enable the external pin interrupt. The driver dispatches calls to registered callback functions when the properly configured pin(s) latches an external interrupt input on the XINT pin(s). The callback is dispatched with the following parameters, respectively: - application-provided callback parameter (\a pCBParam), - the interrupt ID (#ADI_XINT_EVENT) that initiated the interrupt, - NULL. @param[in] eEvent The interrupt for which the callback is being registered. @param[in] pfCallback Pointer to the callback function. This can be passed as NULL to unregister the callback. @param[in] pCBParam Callback parameter which will be passed back to the application when the callback is called.. @return Status - #ADI_XINT_SUCCESS If successfully registered the callback. - #ADI_XINT_NOT_INITIALIZED [D] If external interrupt driver is not yet initialized. @sa adi_xint_EnableIRQ @sa adi_xint_DisableIRQ */ ADI_XINT_RESULT adi_xint_RegisterCallback (const ADI_XINT_EVENT eEvent, ADI_CALLBACK const pfCallback, void *const pCBParam ) { ADI_INT_STATUS_ALLOC(); #ifdef ADI_DEBUG /* make sure we're initialized */ if (NULL == gpCallbackTable) { return (ADI_XINT_NOT_INITIALIZED); } #endif ADI_ENTER_CRITICAL_REGION(); gpCallbackTable[eEvent].pfCallback = pfCallback; gpCallbackTable[eEvent].pCBParam = pCBParam; ADI_EXIT_CRITICAL_REGION(); /* return the status */ return (ADI_XINT_SUCCESS); }
/*! @brief Disable an External Interrupt @details Disables an external interrupt @param[in] eEvent External Interrupt event that should be disabled. @return Status - #ADI_XINT_SUCCESS If successfully disabled the external interrupt. - #ADI_XINT_NOT_INITIALIZED [D] If external interrupt driver is not yet initialized. @sa adi_xint_EnableIRQ @sa adi_xint_RegisterCallback */ ADI_XINT_RESULT adi_xint_DisableIRQ(const ADI_XINT_EVENT eEvent) { uint32_t Mask; /* mask to manipulate the register */ uint32_t CfgReg; /* interrupt config register value */ IRQn_Type XintIrq; /* External interrupt IRQ the event is mapped to */ ADI_INT_STATUS_ALLOC(); #ifdef ADI_DEBUG /* make sure we're initialized */ if (NULL == gpCallbackTable) { return (ADI_XINT_NOT_INITIALIZED); } #endif /* Based on the event figure out the interrupt it is mapped to */ if(eEvent == ADI_XINT_EVENT_UART_RX) { XintIrq = XINT_EVT3_IRQn; } else { XintIrq = (IRQn_Type)((uint32_t)XINT_EVT0_IRQn + (uint32_t)eEvent); } /* disable the interrupt */ NVIC_DisableIRQ(XintIrq); /* create the mask we'll use to clear the relevant bits in the config register */ Mask = (BITM_XINT_CFG0_IRQ0MDE | BITM_XINT_CFG0_IRQ0EN) << (ADI_XINT_CFG_BITS * (uint32_t)eEvent); ADI_ENTER_CRITICAL_REGION(); /* read/modify/write the appropriate bits in the register */ CfgReg = pADI_XINT0->CFG0; CfgReg &= ~Mask; pADI_XINT0->CFG0 = CfgReg; ADI_EXIT_CRITICAL_REGION(); return (ADI_XINT_SUCCESS); }
/*! @brief Place GP Timer in/out of Perodic Mode and set the reload value load value will be changed on a write to TxCLRI (The load value will also be set on a timeout) Timer can be configured to be periodic. @param[in] hDevice Handle to the GP Timer intance as returned by adi_GPT_Init @param[in] bMod True: Enable periodic mode False: Disable periodic mode @param[in] reloadValue used to set TxLD @return Status - #ADI_GPT_SUCCESS if successful - #ADI_GPT_ERR_BAD_DEV_HANDLE [D] if device handle is invalid */ ADI_GPT_RESULT_TYPE adi_GPT_SetPeriodicMode(ADI_GPT_HANDLE hDevice, bool_t bMod, uint16_t reloadValue) { #ifdef ADI_DEBUG if (ADI_GPT_INVALID_HANDLE(hDevice)) { return ADI_GPT_ERR_BAD_DEV_HANDLE; } #endif ADI_ENTER_CRITICAL_REGION(); if (bMod) { hDevice->pTmr->CON |= TCON_MOD; } else { hDevice->pTmr->CON &= ~TCON_MOD; } ADI_EXIT_CRITICAL_REGION(); hDevice->pTmr->LD = reloadValue; return ADI_GPT_SUCCESS; }
/*! * @brief Register or unregister callback function. * * Application can register a callback function with the driver which will be called back to notify * events when an interrupt occurs. For example when a frame boundary interrupt occurs, it will be * notified to the application via the registered callback with the event type #ADI_LCD_EVENT_FRAME_BOUNDARY. * * @param[in] hDevice Device handle obtained from adi_LCD_Init(). * @param[in] pfCallback Pointer to the callback function. It can be set to NULL to unregister a previously * registered callback. * @param[in] pCBParam Callback parameter which will be passed back to the application when the callback * is called. * @return Status * - #ADI_LCD_ERR_BAD_DEVICE_HANDLE [D] Invalid device handle parameter. * - #ADI_LCD_ERR_NULL_POINTER [D] The given pointer to status flag is pointing to NULL. * - #ADI_LCD_SUCCESS Call completed successfully. */ ADI_LCD_RESULT_TYPE adi_LCD_RegisterCallback(ADI_LCD_DEV_HANDLE const hDevice, ADI_CALLBACK pfCallback, void *pCBParam) { #ifdef ADI_DEBUG if (ADI_LCD_SUCCESS != ValidateDeviceHandle(hDevice)) return ADI_LCD_ERR_BAD_DEVICE_HANDLE; if (ADI_LCD_STATE_UNINITIALIZED == hDevice->initState) return ADI_LCD_ERR_NOT_INITIALIZED; #endif ADI_ENTER_CRITICAL_REGION(); /* Save the given callback and callback parameters */ hDevice->pfCallback = pfCallback; hDevice->pCBParam = pCBParam; ADI_EXIT_CRITICAL_REGION(); return ADI_LCD_SUCCESS; }