Software Drivers

xttcps.h File Reference

#include "xttcps_hw.h"
#include "xstatus.h"

Classes

struct  XTtcPs_Config
struct  XTtcPs

Defines

#define XTTCPS_H
#define InstReadReg(InstancePtr, RegOffset)   (Xil_In32(((InstancePtr)->Config.BaseAddress) + (RegOffset)))
#define InstWriteReg(InstancePtr, RegOffset, Data)   (Xil_Out32(((InstancePtr)->Config.BaseAddress) + (RegOffset), (Data)))
#define XTtcPs_Start(InstancePtr)
#define XTtcPs_Stop(InstancePtr)
#define XTtcPs_IsStarted(InstancePtr)
#define XTtcPs_GetCounterValue(InstancePtr)   (u16)InstReadReg((InstancePtr), XTTCPS_COUNT_VALUE_OFFSET)
#define XTtcPs_SetInterval(InstancePtr, Value)   InstWriteReg((InstancePtr), XTTCPS_INTERVAL_VAL_OFFSET, (Value))
#define XTtcPs_GetInterval(InstancePtr)   (u16)InstReadReg((InstancePtr), XTTCPS_INTERVAL_VAL_OFFSET)
#define XTtcPs_ResetCounterValue(InstancePtr)
#define XTtcPs_EnableInterrupts(InstancePtr, InterruptMask)
#define XTtcPs_DisableInterrupts(InstancePtr, InterruptMask)
#define XTtcPs_GetInterruptStatus(InstancePtr)   InstReadReg((InstancePtr), XTTCPS_ISR_OFFSET)
#define XTtcPs_ClearInterruptStatus(InstancePtr, InterruptMask)
Configuration options

Options for the device. Each of the options is bit field, so more than one options can be specified.



#define XTTCPS_OPTION_EXTERNAL_CLK   0x0001
#define XTTCPS_OPTION_CLK_EDGE_NEG   0x0002
#define XTTCPS_OPTION_INTERVAL_MODE   0x0004
#define XTTCPS_OPTION_DECREMENT   0x0008
#define XTTCPS_OPTION_MATCH_MODE   0x0010
#define XTTCPS_OPTION_WAVE_DISABLE   0x0020
#define XTTCPS_OPTION_WAVE_POLARITY   0x0040

Functions

XTtcPs_ConfigXTtcPs_LookupConfig (u16 DeviceId)
int XTtcPs_CfgInitialize (XTtcPs *InstancePtr, XTtcPs_Config *ConfigPtr, u32 EffectiveAddr)
void XTtcPs_SetMatchValue (XTtcPs *InstancePtr, u8 MatchIndex, u16 Value)
u16 XTtcPs_GetMatchValue (XTtcPs *InstancePtr, u8 MatchIndex)
void XTtcPs_SetPrescaler (XTtcPs *InstancePtr, u8 PrescalerValue)
u8 XTtcPs_GetPrescaler (XTtcPs *InstancePtr)
void XTtcPs_CalcIntervalFromFreq (XTtcPs *InstancePtr, u32 Freq, u16 *Interval, u8 *Prescaler)
int XTtcPs_SetOptions (XTtcPs *InstancePtr, u32 Options)
u32 XTtcPs_GetOptions (XTtcPs *InstancePtr)
int XTtcPs_SelfTest (XTtcPs *InstancePtr)

Detailed Description


Define Documentation

#define InstReadReg ( InstancePtr,
RegOffset   )     (Xil_In32(((InstancePtr)->Config.BaseAddress) + (RegOffset)))
#define InstWriteReg ( InstancePtr,
RegOffset,
Data   )     (Xil_Out32(((InstancePtr)->Config.BaseAddress) + (RegOffset), (Data)))
#define XTtcPs_ClearInterruptStatus ( InstancePtr,
InterruptMask   ) 
Value:
InstWriteReg((InstancePtr), XTTCPS_ISR_OFFSET, \
                 (InterruptMask))

This function clears the interrupt status.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
InterruptMask defines which interrupt should be cleared. Constants are defined in xttcps_hw.h as XTTCPS_IXR_*. This is a bit mask, all set bits will be cleared, cleared bits will not be cleared.
Returns:
None.
Note:
C-style signature: void XTtcPs_ClearInterruptStatus(XTtcPs *InstancePtr, u32 InterruptMask)
#define XTtcPs_DisableInterrupts ( InstancePtr,
InterruptMask   ) 
Value:
InstWriteReg((InstancePtr), XTTCPS_IER_OFFSET,  \
                (InstReadReg((InstancePtr), XTTCPS_IER_OFFSET) &        \
                 ~(InterruptMask)))

This function disables the interrupts.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
InterruptMask defines which interrupt should be disabled. Constants are defined in xttcps_hw.h as XTTCPS_IXR_*. This is a bit mask, all set bits will be disabled, cleared bits will not be disabled.
Returns:
None.
Note:
C-style signature: void XTtcPs_DisableInterrupts(XTtcPs *InstancePtr, u32 InterruptMask)
#define XTtcPs_EnableInterrupts ( InstancePtr,
InterruptMask   ) 
Value:
InstWriteReg((InstancePtr), XTTCPS_IER_OFFSET,          \
                (InstReadReg((InstancePtr), XTTCPS_IER_OFFSET) |        \
                 (InterruptMask)))

This function enables the interrupts.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
InterruptMask defines which interrupt should be enabled. Constants are defined in xttcps_hw.h as XTTCPS_IXR_*. This is a bit mask, all set bits will be enabled, cleared bits will not be disabled.
Returns:
None.
Note:
C-style signature: void XTtcPs_EnableInterrupts(XTtcPs *InstancePtr, u32 InterruptMask)
#define XTtcPs_GetCounterValue ( InstancePtr   )     (u16)InstReadReg((InstancePtr), XTTCPS_COUNT_VALUE_OFFSET)

This function returns the current 16-bit counter value. It may be called at any time.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
16-bit counter value.
Note:
C-style signature: u16 XTtcPs_GetCounterValue(XTtcPs *InstancePtr)
#define XTtcPs_GetInterruptStatus ( InstancePtr   )     InstReadReg((InstancePtr), XTTCPS_ISR_OFFSET)

This function reads the interrupt status.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
None.
Note:
C-style signature: u32 XTtcPs_GetInterruptStatus(XTtcPs *InstancePtr)
#define XTtcPs_GetInterval ( InstancePtr   )     (u16)InstReadReg((InstancePtr), XTTCPS_INTERVAL_VAL_OFFSET)

This function gets the interval value from the interval register.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
16-bit interval value
Note:
C-style signature: u16 XTtcPs_GetInterval(XTtcPs *InstancePtr)
#define XTTCPS_H
#define XTtcPs_IsStarted ( InstancePtr   ) 
Value:

This function checks whether the timer counter has already started.

Parameters:
InstancePtr is a pointer to the XTtcPs instance
Returns:
Non-zero if the device has started, '0' otherwise.
Note:
C-style signature: int XTtcPs_IsStarted(XTtcPs *InstancePtr)
#define XTTCPS_OPTION_CLK_EDGE_NEG   0x0002

Clock on trailing edge for external clock

#define XTTCPS_OPTION_DECREMENT   0x0008

Decrement the counter

#define XTTCPS_OPTION_EXTERNAL_CLK   0x0001

External clock source

#define XTTCPS_OPTION_INTERVAL_MODE   0x0004

Interval mode

#define XTTCPS_OPTION_MATCH_MODE   0x0010

Match mode

#define XTTCPS_OPTION_WAVE_DISABLE   0x0020

No waveform output

#define XTTCPS_OPTION_WAVE_POLARITY   0x0040

Waveform polarity

#define XTtcPs_ResetCounterValue ( InstancePtr   ) 
Value:

This macro resets the count register. It may be called at any time. The counter is reset to either 0 or 0xFFFF, or the interval value, depending on the increment/decrement mode. The state of the counter, as started or stopped, is not affected by calling reset.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
None
Note:
C-style signature: void XTtcPs_ResetCounterValue(XTtcPs *InstancePtr)
#define XTtcPs_SetInterval ( InstancePtr,
Value   )     InstWriteReg((InstancePtr), XTTCPS_INTERVAL_VAL_OFFSET, (Value))

This function sets the interval value to be used in interval mode.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Value is the 16-bit value to be set in the interval register.
Returns:
None
Note:
C-style signature: void XTtcPs_SetInterval(XTtcPs *InstancePtr, u16 Value)
#define XTtcPs_Start ( InstancePtr   ) 
Value:

This function starts the counter/timer without resetting the counter value.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
None
Note:
C-style signature: void XTtcPs_Start(XTtcPs *InstancePtr)
#define XTtcPs_Stop ( InstancePtr   ) 
Value:

This function stops the counter/timer. This macro may be called at any time to stop the counter. The counter holds the last value until it is reset, restarted or enabled.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
None
Note:
C-style signature: void XTtcPs_Stop(XTtcPs *InstancePtr)

Function Documentation

void XTtcPs_CalcIntervalFromFreq ( XTtcPs InstancePtr,
u32  Freq,
u16 *  Interval,
u8 *  Prescaler 
)

This function calculates the interval value as well as the prescaler value for a given frequency.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Freq is the requested output frequency for the device.
Interval is the interval value for the given frequency, it is the output value for this function.
Prescaler is the prescaler value for the given frequency, it is the output value for this function.
Returns:
None.
Note:
Upon successful calculation for the given frequency, Interval and Prescaler carry the settings for the timer counter; Upon unsuccessful calculation, Interval and Prescaler are set to 0xFF(FF) for their maximum values to signal the caller of failure. Therefore, caller needs to check the return interval or prescaler values for whether the function has succeeded.
int XTtcPs_CfgInitialize ( XTtcPs InstancePtr,
XTtcPs_Config ConfigPtr,
u32  EffectiveAddr 
)

Initializes a specific XTtcPs instance such that the driver is ready to use. This function initializes a single timer counter in the triple timer counter function block.

The state of the device after initialization is:

  • Overflow Mode
  • Internal (pclk) selected
  • Counter disabled
  • All Interrupts disabled
  • Output waveforms disabled
Parameters:
InstancePtr is a pointer to the XTtcPs instance.
ConfigPtr is a reference to a structure containing information about a specific TTC device.
EffectiveAddr is the device base address in the virtual memory address space. The caller is responsible for keeping the address mapping from EffectiveAddr to the device physical base address unchanged once this function is invoked. Unexpected errors may occur if the address mapping changes after this function is called. If address translation is not used, then use ConfigPtr->BaseAddress for this parameter, passing the physical address instead.
Returns:
  • XST_SUCCESS if the initialization is successful.
  • XST_DEVICE_IS_STARTED if the device is started. It must be stopped to re-initialize.
Note:
Device has to be stopped first to call this function to initialize it.
u16 XTtcPs_GetMatchValue ( XTtcPs InstancePtr,
u8  MatchIndex 
)

This function is used to get the value of the match registers. There are three match registers.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
MatchIndex is the index to the match register to be set. Valid values are 0, 1, or 2.
Returns:
None
Note:
None
u32 XTtcPs_GetOptions ( XTtcPs InstancePtr  ) 

This function gets the settings for the options for the TTC device.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:

The return u32 contains the specified options that are set. This is a bit mask where a '1' means the option is on, and a'0' means the option is off. One or more bit values may be contained in the mask. See the bit definitions named XTTCPS_*_OPTION in the file xttcps.h.

Note:
None.
u8 XTtcPs_GetPrescaler ( XTtcPs InstancePtr  ) 

This function gets the input clock prescaler

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
 
Returns:
The value(n) from which the prescalar value is calculated as 2^(n+1). Some example values are given below :

Value Prescaler 0 2 1 4 N 2^(n+1) 15 65536 16 1

Note:
None.
XTtcPs_Config* XTtcPs_LookupConfig ( u16  DeviceId  ) 

Looks up the device configuration based on the unique device ID. A table contains the configuration info for each device in the system.

Parameters:
DeviceId contains the unique ID of the device
Returns:

A pointer to the configuration found or NULL if the specified device ID was not found. See xttcps.h for the definition of XTtcPs_Config.

Note:
None.
int XTtcPs_SelfTest ( XTtcPs InstancePtr  ) 

Runs a self-test on the driver/device.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Returns:
  • XST_SUCCESS if successful
  • XST_FAILURE indicates a register did not read or write correctly
Note:
This test fails if it is not called right after initialization.
void XTtcPs_SetMatchValue ( XTtcPs InstancePtr,
u8  MatchIndex,
u16  Value 
)

This function is used to set the match registers. There are three match registers.

The match 0 register is special. If the waveform output mode is enabled, the waveform will change polarity when the count matches the value in the match 0 register. The polarity of the waveform output can also be set using the XTtcPs_SetOptions() function.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
MatchIndex is the index to the match register to be set. Valid values are 0, 1, or 2.
Value is the 16-bit value to be set in the match register.
Returns:
None
Note:
None
int XTtcPs_SetOptions ( XTtcPs InstancePtr,
u32  Options 
)

This function sets the options for the TTC device.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
Options contains the specified options to be set. This is a bit mask where a 1 means to turn the option on, and a 0 means to turn the option off. One or more bit values may be contained in the mask. See the bit definitions named XTTCPS_*_OPTION in the file xttcps.h.
Returns:
  • XST_SUCCESS if options are successfully set.
  • XST_FAILURE if any of the options are unknown.
Note:
None
void XTtcPs_SetPrescaler ( XTtcPs InstancePtr,
u8  PrescalerValue 
)

This function sets the prescaler enable bit and if needed sets the prescaler bits in the control register.

Parameters:
InstancePtr is a pointer to the XTtcPs instance.
PrescalerValue is a number from 0-16 that sets the prescaler to use. If the parameter is 0 - 15, use a prescaler on the clock of 2^(PrescalerValue+1), or 2-65536. If the parameter is XTTCPS_CLK_CNTRL_PS_DISABLE, do not use a prescaler.
Returns:
None
Note:
None