Path: blob/main/sys/contrib/ncsw/inc/Peripherals/fm_rtc_ext.h
48375 views
/*1* Copyright 2008-2012 Freescale Semiconductor Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/**************************************************************************//**34@File fm_rtc_ext.h3536@Description External definitions and API for FM RTC IEEE1588 Timer Module.3738@Cautions None.39*//***************************************************************************/4041#ifndef __FM_RTC_EXT_H__42#define __FM_RTC_EXT_H__434445#include "error_ext.h"46#include "std_ext.h"47#include "fsl_fman_rtc.h"4849/**************************************************************************//**5051@Group FM_grp Frame Manager API5253@Description FM API functions, definitions and enums5455@{56*//***************************************************************************/5758/**************************************************************************//**59@Group fm_rtc_grp FM RTC6061@Description FM RTC functions, definitions and enums.6263@{64*//***************************************************************************/6566/**************************************************************************//**67@Group fm_rtc_init_grp FM RTC Initialization Unit6869@Description FM RTC initialization API.7071@{72*//***************************************************************************/7374/**************************************************************************//**75@Description FM RTC Alarm Polarity Options.76*//***************************************************************************/77typedef enum e_FmRtcAlarmPolarity78{79e_FM_RTC_ALARM_POLARITY_ACTIVE_HIGH = E_FMAN_RTC_ALARM_POLARITY_ACTIVE_HIGH, /**< Active-high output polarity */80e_FM_RTC_ALARM_POLARITY_ACTIVE_LOW = E_FMAN_RTC_ALARM_POLARITY_ACTIVE_LOW /**< Active-low output polarity */81} e_FmRtcAlarmPolarity;8283/**************************************************************************//**84@Description FM RTC Trigger Polarity Options.85*//***************************************************************************/86typedef enum e_FmRtcTriggerPolarity87{88e_FM_RTC_TRIGGER_ON_RISING_EDGE = E_FMAN_RTC_TRIGGER_ON_RISING_EDGE, /**< Trigger on rising edge */89e_FM_RTC_TRIGGER_ON_FALLING_EDGE = E_FMAN_RTC_TRIGGER_ON_FALLING_EDGE /**< Trigger on falling edge */90} e_FmRtcTriggerPolarity;9192/**************************************************************************//**93@Description IEEE1588 Timer Module FM RTC Optional Clock Sources.94*//***************************************************************************/95typedef enum e_FmSrcClock96{97e_FM_RTC_SOURCE_CLOCK_EXTERNAL = E_FMAN_RTC_SOURCE_CLOCK_EXTERNAL, /**< external high precision timer reference clock */98e_FM_RTC_SOURCE_CLOCK_SYSTEM = E_FMAN_RTC_SOURCE_CLOCK_SYSTEM, /**< MAC system clock */99e_FM_RTC_SOURCE_CLOCK_OSCILATOR = E_FMAN_RTC_SOURCE_CLOCK_OSCILATOR /**< RTC clock oscilator */100}e_FmSrcClk;101102/**************************************************************************//**103@Description FM RTC configuration parameters structure.104105This structure should be passed to FM_RTC_Config().106*//***************************************************************************/107typedef struct t_FmRtcParams108{109t_Handle h_Fm; /**< FM Handle*/110uintptr_t baseAddress; /**< Base address of FM RTC registers */111t_Handle h_App; /**< A handle to an application layer object; This handle will112be passed by the driver upon calling the above callbacks */113} t_FmRtcParams;114115116/**************************************************************************//**117@Function FM_RTC_Config118119@Description Configures the FM RTC module according to user's parameters.120121The driver assigns default values to some FM RTC parameters.122These parameters can be overwritten using the advanced123configuration routines.124125@Param[in] p_FmRtcParam - FM RTC configuration parameters.126127@Return Handle to the new FM RTC object; NULL pointer on failure.128129@Cautions None130*//***************************************************************************/131t_Handle FM_RTC_Config(t_FmRtcParams *p_FmRtcParam);132133/**************************************************************************//**134@Function FM_RTC_Init135136@Description Initializes the FM RTC driver and hardware.137138@Param[in] h_FmRtc - Handle to FM RTC object.139140@Return E_OK on success; Error code otherwise.141142@Cautions h_FmRtc must have been previously created using FM_RTC_Config().143*//***************************************************************************/144t_Error FM_RTC_Init(t_Handle h_FmRtc);145146/**************************************************************************//**147@Function FM_RTC_Free148149@Description Frees the FM RTC object and all allocated resources.150151@Param[in] h_FmRtc - Handle to FM RTC object.152153@Return E_OK on success; Error code otherwise.154155@Cautions h_FmRtc must have been previously created using FM_RTC_Config().156*//***************************************************************************/157t_Error FM_RTC_Free(t_Handle h_FmRtc);158159160/**************************************************************************//**161@Group fm_rtc_adv_config_grp FM RTC Advanced Configuration Unit162163@Description FM RTC advanced configuration functions.164165@{166*//***************************************************************************/167168/**************************************************************************//**169@Function FM_RTC_ConfigPeriod170171@Description Configures the period of the timestamp if different than172default [DEFAULT_clockPeriod].173174@Param[in] h_FmRtc - Handle to FM RTC object.175@Param[in] period - Period in nano-seconds.176177@Return E_OK on success; Error code otherwise.178179@Cautions h_FmRtc must have been previously created using FM_RTC_Config().180*//***************************************************************************/181t_Error FM_RTC_ConfigPeriod(t_Handle h_FmRtc, uint32_t period);182183/**************************************************************************//**184@Function FM_RTC_ConfigSourceClock185186@Description Configures the source clock of the RTC.187188@Param[in] h_FmRtc - Handle to FM RTC object.189@Param[in] srcClk - Source clock selection.190@Param[in] freqInMhz - the source-clock frequency (in MHz).191192@Return E_OK on success; Error code otherwise.193194@Cautions h_FmRtc must have been previously created using FM_RTC_Config().195*//***************************************************************************/196t_Error FM_RTC_ConfigSourceClock(t_Handle h_FmRtc,197e_FmSrcClk srcClk,198uint32_t freqInMhz);199200/**************************************************************************//**201@Function FM_RTC_ConfigPulseRealignment202203@Description Configures the RTC to automatic FIPER pulse realignment in204response to timer adjustments [DEFAULT_pulseRealign]205206In this mode, the RTC clock is identical to the source clock.207This feature can be useful when the system contains an external208RTC with inherent frequency compensation.209210@Param[in] h_FmRtc - Handle to FM RTC object.211@Param[in] enable - TRUE to enable automatic realignment.212213@Return E_OK on success; Error code otherwise.214215@Cautions h_FmRtc must have been previously created using FM_RTC_Config().216*//***************************************************************************/217t_Error FM_RTC_ConfigPulseRealignment(t_Handle h_FmRtc, bool enable);218219/**************************************************************************//**220@Function FM_RTC_ConfigFrequencyBypass221222@Description Configures the RTC to bypass the frequency compensation223mechanism. [DEFAULT_bypass]224225In this mode, the RTC clock is identical to the source clock.226This feature can be useful when the system contains an external227RTC with inherent frequency compensation.228229@Param[in] h_FmRtc - Handle to FM RTC object.230@Param[in] enabled - TRUE to bypass frequency compensation;231FALSE otherwise.232233@Return E_OK on success; Error code otherwise.234235@Cautions h_FmRtc must have been previously created using FM_RTC_Config().236*//***************************************************************************/237t_Error FM_RTC_ConfigFrequencyBypass(t_Handle h_FmRtc, bool enabled);238239/**************************************************************************//**240@Function FM_RTC_ConfigInvertedInputClockPhase241242@Description Configures the RTC to invert the source clock phase on input.243[DEFAULT_invertInputClkPhase]244245@Param[in] h_FmRtc - Handle to FM RTC object.246@Param[in] inverted - TRUE to invert the source clock phase on input.247FALSE otherwise.248249@Return E_OK on success; Error code otherwise.250251@Cautions h_FmRtc must have been previously created using FM_RTC_Config().252*//***************************************************************************/253t_Error FM_RTC_ConfigInvertedInputClockPhase(t_Handle h_FmRtc, bool inverted);254255/**************************************************************************//**256@Function FM_RTC_ConfigInvertedOutputClockPhase257258@Description Configures the RTC to invert the output clock phase.259[DEFAULT_invertOutputClkPhase]260261@Param[in] h_FmRtc - Handle to FM RTC object.262@Param[in] inverted - TRUE to invert the output clock phase.263FALSE otherwise.264265@Return E_OK on success; Error code otherwise.266267@Cautions h_FmRtc must have been previously created using FM_RTC_Config().268*//***************************************************************************/269t_Error FM_RTC_ConfigInvertedOutputClockPhase(t_Handle h_FmRtc, bool inverted);270271/**************************************************************************//**272@Function FM_RTC_ConfigOutputClockDivisor273274@Description Configures the divisor for generating the output clock from275the RTC clock. [DEFAULT_outputClockDivisor]276277@Param[in] h_FmRtc - Handle to FM RTC object.278@Param[in] divisor - Divisor for generation of the output clock.279280@Return E_OK on success; Error code otherwise.281282@Cautions h_FmRtc must have been previously created using FM_RTC_Config().283*//***************************************************************************/284t_Error FM_RTC_ConfigOutputClockDivisor(t_Handle h_FmRtc, uint16_t divisor);285286/**************************************************************************//**287@Function FM_RTC_ConfigAlarmPolarity288289@Description Configures the polarity (active-high/active-low) of a specific290alarm signal. [DEFAULT_alarmPolarity]291292@Param[in] h_FmRtc - Handle to FM RTC object.293@Param[in] alarmId - Alarm ID.294@Param[in] alarmPolarity - Alarm polarity.295296@Return E_OK on success; Error code otherwise.297298@Cautions h_FmRtc must have been previously created using FM_RTC_Config().299*//***************************************************************************/300t_Error FM_RTC_ConfigAlarmPolarity(t_Handle h_FmRtc,301uint8_t alarmId,302e_FmRtcAlarmPolarity alarmPolarity);303304/**************************************************************************//**305@Function FM_RTC_ConfigExternalTriggerPolarity306307@Description Configures the polarity (rising/falling edge) of a specific308external trigger signal. [DEFAULT_triggerPolarity]309310@Param[in] h_FmRtc - Handle to FM RTC object.311@Param[in] triggerId - Trigger ID.312@Param[in] triggerPolarity - Trigger polarity.313314@Return E_OK on success; Error code otherwise.315316@Cautions h_FmRtc must have been previously created using FM_RTC_Config().317*//***************************************************************************/318t_Error FM_RTC_ConfigExternalTriggerPolarity(t_Handle h_FmRtc,319uint8_t triggerId,320e_FmRtcTriggerPolarity triggerPolarity);321322/** @} */ /* end of fm_rtc_adv_config_grp */323/** @} */ /* end of fm_rtc_init_grp */324325326/**************************************************************************//**327@Group fm_rtc_control_grp FM RTC Control Unit328329@Description FM RTC runtime control API.330331@{332*//***************************************************************************/333334/**************************************************************************//**335@Function t_FmRtcExceptionsCallback336337@Description Exceptions user callback routine, used for RTC different mechanisms.338339@Param[in] h_App - User's application descriptor.340@Param[in] id - source id.341*//***************************************************************************/342typedef void (t_FmRtcExceptionsCallback) ( t_Handle h_App, uint8_t id);343344/**************************************************************************//**345@Description FM RTC alarm parameters.346*//***************************************************************************/347typedef struct t_FmRtcAlarmParams {348uint8_t alarmId; /**< 0 or 1 */349uint64_t alarmTime; /**< In nanoseconds, the time when the alarm350should go off - must be a multiple of351the RTC period */352t_FmRtcExceptionsCallback *f_AlarmCallback; /**< This routine will be called when RTC353reaches alarmTime */354bool clearOnExpiration; /**< TRUE to turn off the alarm once expired. */355} t_FmRtcAlarmParams;356357/**************************************************************************//**358@Description FM RTC Periodic Pulse parameters.359*//***************************************************************************/360typedef struct t_FmRtcPeriodicPulseParams {361uint8_t periodicPulseId; /**< 0 or 1 */362uint64_t periodicPulsePeriod; /**< In Nanoseconds. Must be363a multiple of the RTC period */364t_FmRtcExceptionsCallback *f_PeriodicPulseCallback; /**< This routine will be called every365periodicPulsePeriod. */366} t_FmRtcPeriodicPulseParams;367368/**************************************************************************//**369@Description FM RTC Periodic Pulse parameters.370*//***************************************************************************/371typedef struct t_FmRtcExternalTriggerParams {372uint8_t externalTriggerId; /**< 0 or 1 */373bool usePulseAsInput; /**< Use the pulse interrupt instead of374an external signal */375t_FmRtcExceptionsCallback *f_ExternalTriggerCallback; /**< This routine will be called every376periodicPulsePeriod. */377} t_FmRtcExternalTriggerParams;378379380/**************************************************************************//**381@Function FM_RTC_Enable382383@Description Enable the RTC (time count is started).384385The user can select to resume the time count from previous386point, or to restart the time count.387388@Param[in] h_FmRtc - Handle to FM RTC object.389@Param[in] resetClock - Restart the time count from zero.390391@Return E_OK on success; Error code otherwise.392393@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().394*//***************************************************************************/395t_Error FM_RTC_Enable(t_Handle h_FmRtc, bool resetClock);396397/**************************************************************************//**398@Function FM_RTC_Disable399400@Description Disables the RTC (time count is stopped).401402@Param[in] h_FmRtc - Handle to FM RTC object.403404@Return E_OK on success; Error code otherwise.405406@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().407*//***************************************************************************/408t_Error FM_RTC_Disable(t_Handle h_FmRtc);409410/**************************************************************************//**411@Function FM_RTC_SetClockOffset412413@Description Sets the clock offset (usually relative to another clock).414415The user can pass a negative offset value.416417@Param[in] h_FmRtc - Handle to FM RTC object.418@Param[in] offset - New clock offset (in nanoseconds).419420@Return E_OK on success; Error code otherwise.421422@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().423*//***************************************************************************/424t_Error FM_RTC_SetClockOffset(t_Handle h_FmRtc, int64_t offset);425426/**************************************************************************//**427@Function FM_RTC_SetAlarm428429@Description Schedules an alarm event to a given RTC time.430431@Param[in] h_FmRtc - Handle to FM RTC object.432@Param[in] p_FmRtcAlarmParams - Alarm parameters.433434@Return E_OK on success; Error code otherwise.435436@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().437Must be called only prior to FM_RTC_Enable().438*//***************************************************************************/439t_Error FM_RTC_SetAlarm(t_Handle h_FmRtc, t_FmRtcAlarmParams *p_FmRtcAlarmParams);440441/**************************************************************************//**442@Function FM_RTC_SetPeriodicPulse443444@Description Sets a periodic pulse.445446@Param[in] h_FmRtc - Handle to FM RTC object.447@Param[in] p_FmRtcPeriodicPulseParams - Periodic pulse parameters.448449@Return E_OK on success; Error code otherwise.450451@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().452Must be called only prior to FM_RTC_Enable().453*//***************************************************************************/454t_Error FM_RTC_SetPeriodicPulse(t_Handle h_FmRtc, t_FmRtcPeriodicPulseParams *p_FmRtcPeriodicPulseParams);455456/**************************************************************************//**457@Function FM_RTC_ClearPeriodicPulse458459@Description Clears a periodic pulse.460461@Param[in] h_FmRtc - Handle to FM RTC object.462@Param[in] periodicPulseId - Periodic pulse id.463464@Return E_OK on success; Error code otherwise.465466@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().467*//***************************************************************************/468t_Error FM_RTC_ClearPeriodicPulse(t_Handle h_FmRtc, uint8_t periodicPulseId);469470/**************************************************************************//**471@Function FM_RTC_SetExternalTrigger472473@Description Sets an external trigger indication and define a callback474routine to be called on such event.475476@Param[in] h_FmRtc - Handle to FM RTC object.477@Param[in] p_FmRtcExternalTriggerParams - External Trigger parameters.478479@Return E_OK on success; Error code otherwise.480481@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().482*//***************************************************************************/483t_Error FM_RTC_SetExternalTrigger(t_Handle h_FmRtc, t_FmRtcExternalTriggerParams *p_FmRtcExternalTriggerParams);484485/**************************************************************************//**486@Function FM_RTC_ClearExternalTrigger487488@Description Clears external trigger indication.489490@Param[in] h_FmRtc - Handle to FM RTC object.491@Param[in] id - External Trigger id.492493@Return E_OK on success; Error code otherwise.494495@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().496*//***************************************************************************/497t_Error FM_RTC_ClearExternalTrigger(t_Handle h_FmRtc, uint8_t id);498499/**************************************************************************//**500@Function FM_RTC_GetExternalTriggerTimeStamp501502@Description Reads the External Trigger TimeStamp.503504@Param[in] h_FmRtc - Handle to FM RTC object.505@Param[in] triggerId - External Trigger id.506@Param[out] p_TimeStamp - External Trigger timestamp (in nanoseconds).507508@Return E_OK on success; Error code otherwise.509510@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().511*//***************************************************************************/512t_Error FM_RTC_GetExternalTriggerTimeStamp(t_Handle h_FmRtc,513uint8_t triggerId,514uint64_t *p_TimeStamp);515516/**************************************************************************//**517@Function FM_RTC_GetCurrentTime518519@Description Returns the current RTC time.520521@Param[in] h_FmRtc - Handle to FM RTC object.522@Param[out] p_Ts - returned time stamp (in nanoseconds).523524@Return E_OK on success; Error code otherwise.525526@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().527*//***************************************************************************/528t_Error FM_RTC_GetCurrentTime(t_Handle h_FmRtc, uint64_t *p_Ts);529530/**************************************************************************//**531@Function FM_RTC_SetCurrentTime532533@Description Sets the current RTC time.534535@Param[in] h_FmRtc - Handle to FM RTC object.536@Param[in] ts - The new time stamp (in nanoseconds).537538@Return E_OK on success; Error code otherwise.539540@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().541*//***************************************************************************/542t_Error FM_RTC_SetCurrentTime(t_Handle h_FmRtc, uint64_t ts);543544/**************************************************************************//**545@Function FM_RTC_GetFreqCompensation546547@Description Retrieves the frequency compensation value548549@Param[in] h_FmRtc - Handle to FM RTC object.550@Param[out] p_Compensation - A pointer to the returned value of compensation.551552@Return E_OK on success; Error code otherwise.553554@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().555*//***************************************************************************/556t_Error FM_RTC_GetFreqCompensation(t_Handle h_FmRtc, uint32_t *p_Compensation);557558/**************************************************************************//**559@Function FM_RTC_SetFreqCompensation560561@Description Sets a new frequency compensation value.562563@Param[in] h_FmRtc - Handle to FM RTC object.564@Param[in] freqCompensation - The new frequency compensation value to set.565566@Return E_OK on success; Error code otherwise.567568@Cautions h_FmRtc must have been previously initialized using FM_RTC_Init().569*//***************************************************************************/570t_Error FM_RTC_SetFreqCompensation(t_Handle h_FmRtc, uint32_t freqCompensation);571572#ifdef CONFIG_PTP_1588_CLOCK_DPAA573/**************************************************************************//**574*@Function FM_RTC_EnableInterrupt575*576*@Description Enable interrupt of FM RTC.577*578*@Param[in] h_FmRtc - Handle to FM RTC object.579*@Param[in] events - Interrupt events.580*581*@Return E_OK on success; Error code otherwise.582*//***************************************************************************/583t_Error FM_RTC_EnableInterrupt(t_Handle h_FmRtc, uint32_t events);584585/**************************************************************************//**586*@Function FM_RTC_DisableInterrupt587*588*@Description Disable interrupt of FM RTC.589*590*@Param[in] h_FmRtc - Handle to FM RTC object.591*@Param[in] events - Interrupt events.592*593*@Return E_OK on success; Error code otherwise.594*//***************************************************************************/595t_Error FM_RTC_DisableInterrupt(t_Handle h_FmRtc, uint32_t events);596#endif597598#if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0))599/**************************************************************************//**600@Function FM_RTC_DumpRegs601602@Description Dumps all FM registers603604@Param[in] h_FmRtc A handle to an FM RTC Module.605606@Return E_OK on success;607608@Cautions Allowed only FM_Init().609*//***************************************************************************/610t_Error FM_RTC_DumpRegs(t_Handle h_FmRtc);611#endif /* (defined(DEBUG_ERRORS) && ... */612613/** @} */ /* end of fm_rtc_control_grp */614/** @} */ /* end of fm_rtc_grp */615/** @} */ /* end of FM_grp group */616617618#endif /* __FM_RTC_EXT_H__ */619620621