Software Drivers

xtmrctr.h File Reference

#include "xil_types.h"
#include "xil_assert.h"
#include "xstatus.h"
#include "xtmrctr_l.h"

Classes

struct  XTmrCtr_Config
struct  XTmrCtrStats
struct  XTmrCtr

Defines

#define XTMRCTR_H
Configuration options

These options are used in XTmrCtr_SetOptions() and XTmrCtr_GetOptions()



#define XTC_CASCADE_MODE_OPTION   0x00000080UL
#define XTC_ENABLE_ALL_OPTION   0x00000040UL
#define XTC_DOWN_COUNT_OPTION   0x00000020UL
#define XTC_CAPTURE_MODE_OPTION   0x00000010UL
#define XTC_INT_MODE_OPTION   0x00000008UL
#define XTC_AUTO_RELOAD_OPTION   0x00000004UL
#define XTC_EXT_COMPARE_OPTION   0x00000002UL

Typedefs

typedef void(* XTmrCtr_Handler )(void *CallBackRef, u8 TmrCtrNumber)

Functions

int XTmrCtr_Initialize (XTmrCtr *InstancePtr, u16 DeviceId)
void XTmrCtr_Start (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
void XTmrCtr_Stop (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
u32 XTmrCtr_GetValue (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
void XTmrCtr_SetResetValue (XTmrCtr *InstancePtr, u8 TmrCtrNumber, u32 ResetValue)
u32 XTmrCtr_GetCaptureValue (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
int XTmrCtr_IsExpired (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
void XTmrCtr_Reset (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
XTmrCtr_ConfigXTmrCtr_LookupConfig (u16 DeviceId)
void XTmrCtr_SetOptions (XTmrCtr *InstancePtr, u8 TmrCtrNumber, u32 Options)
u32 XTmrCtr_GetOptions (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
void XTmrCtr_GetStats (XTmrCtr *InstancePtr, XTmrCtrStats *StatsPtr)
void XTmrCtr_ClearStats (XTmrCtr *InstancePtr)
int XTmrCtr_SelfTest (XTmrCtr *InstancePtr, u8 TmrCtrNumber)
void XTmrCtr_SetHandler (XTmrCtr *InstancePtr, XTmrCtr_Handler FuncPtr, void *CallBackRef)
void XTmrCtr_InterruptHandler (void *InstancePtr)

Detailed Description


Define Documentation

#define XTC_AUTO_RELOAD_OPTION   0x00000004UL
#define XTC_CAPTURE_MODE_OPTION   0x00000010UL
#define XTC_CASCADE_MODE_OPTION   0x00000080UL

Used to configure the timer counter device.

 XTC_CASCADE_MODE_OPTION	Enables the Cascade Mode only valid for TCSRO.
 XTC_ENABLE_ALL_OPTION	Enables all timer counters at once.
 XTC_DOWN_COUNT_OPTION	Configures the timer counter to count down from
				start value, the default is to count up.
 XTC_CAPTURE_MODE_OPTION	Configures the timer to capture the timer
				counter value when the external capture line is
				asserted. The default mode is compare mode.
 XTC_INT_MODE_OPTION		Enables the timer counter interrupt output.
 XTC_AUTO_RELOAD_OPTION	In compare mode, configures the timer counter to
				reload from the compare value. The default mode
				causes the timer counter to hold when the
				compare value is hit.
				In capture mode, configures the timer counter to
				not hold the previous capture value if a new
				event occurs. The default mode cause the timer
				counter to hold the capture value until
				recognized.
 XTC_EXT_COMPARE_OPTION	Enables the external compare output signal.
 
#define XTC_DOWN_COUNT_OPTION   0x00000020UL
#define XTC_ENABLE_ALL_OPTION   0x00000040UL
#define XTC_EXT_COMPARE_OPTION   0x00000002UL
#define XTC_INT_MODE_OPTION   0x00000008UL
#define XTMRCTR_H

Typedef Documentation

typedef void(* XTmrCtr_Handler)(void *CallBackRef, u8 TmrCtrNumber)

Signature for the callback function.

Parameters:
CallBackRef is a callback reference passed in by the upper layer when setting the callback functions, and passed back to the upper layer when the callback is invoked. Its type is unimportant to the driver, so it is a void pointer.
TmrCtrNumber is the number of the timer/counter within the device. The device typically contains at least two timer/counters. The timer number is a zero based number with a range of 0 to (XTC_DEVICE_TIMER_COUNT - 1).

Function Documentation

void XTmrCtr_ClearStats ( XTmrCtr InstancePtr  ) 

Clear the XTmrCtrStats structure for this driver.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
Returns:
None.
Note:
None.
u32 XTmrCtr_GetCaptureValue ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Returns the timer counter value that was captured the last time the external capture input was asserted.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
The current capture value for the indicated timer counter.
Note:
None.
u32 XTmrCtr_GetOptions ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Get the options for the specified timer counter.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:

The currently set options. An option which is set to a '1' is enabled and set to a '0' is disabled. The options are bit masks such that multiple options may be set or cleared. The options are described in xtmrctr.h.

Note:
None.
void XTmrCtr_GetStats ( XTmrCtr InstancePtr,
XTmrCtrStats StatsPtr 
)

Get a copy of the XTmrCtrStats structure, which contains the current statistics for this driver.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
StatsPtr is a pointer to a XTmrCtrStats structure which will get a copy of current statistics.
Returns:
None.
Note:
None.
u32 XTmrCtr_GetValue ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Get the current value of the specified timer counter. The timer counter may be either incrementing or decrementing based upon the current mode of operation.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
The current value for the timer counter.
Note:
None.
int XTmrCtr_Initialize ( XTmrCtr InstancePtr,
u16  DeviceId 
)

Initializes a specific timer/counter instance/driver. Initialize fields of the XTmrCtr structure, then reset the timer/counter.If a timer is already running then it is not initialized.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
DeviceId is the unique id of the device controlled by this XTmrCtr component. Passing in a device id associates the generic XTmrCtr component to a specific device, as chosen by the caller or application developer.
Returns:
  • XST_SUCCESS if initialization was successful
  • XST_DEVICE_IS_STARTED if the device has already been started
  • XST_DEVICE_NOT_FOUND if the device doesn't exist
Note:
None.
void XTmrCtr_InterruptHandler ( void *  InstancePtr  ) 

Interrupt Service Routine (ISR) for the driver. This function only performs processing for the device and does not save and restore the interrupt context.

Parameters:
InstancePtr contains a pointer to the timer/counter instance for the interrupt.
Returns:
None.
Note:
None.
int XTmrCtr_IsExpired ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Checks if the specified timer counter of the device has expired. In capture mode, expired is defined as a capture occurred. In compare mode, expired is defined as the timer counter rolled over/under for up/down counting.

When interrupts are enabled, the expiration causes an interrupt. This function is typically used to poll a timer counter to determine when it has expired.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
TRUE if the timer has expired, and FALSE otherwise.
Note:
None.
XTmrCtr_Config* XTmrCtr_LookupConfig ( u16  DeviceId  ) 
void XTmrCtr_Reset ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Resets the specified timer counter of the device. A reset causes the timer counter to set it's value to the reset value.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
None.
Note:
None.
int XTmrCtr_SelfTest ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Runs a self-test on the driver/device. This test verifies that the specified timer counter of the device can be enabled and increments.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
  • XST_SUCCESS if self-test was successful
  • XST_FAILURE if the timer is not incrementing.
Note:

This is a destructive test using the provided timer. The current settings of the timer are returned to the initialized values and all settings at the time this function is called are overwritten.

void XTmrCtr_SetHandler ( XTmrCtr InstancePtr,
XTmrCtr_Handler  FuncPtr,
void *  CallBackRef 
)

Sets the timer callback function, which the driver calls when the specified timer times out.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance .
CallBackRef is the upper layer callback reference passed back when the callback function is invoked.
FuncPtr is the pointer to the callback function.
Returns:
None.
Note:

The handler is called within interrupt context so the function that is called should either be short or pass the more extensive processing off to another task to allow the interrupt to return and normal processing to continue.

void XTmrCtr_SetOptions ( XTmrCtr InstancePtr,
u8  TmrCtrNumber,
u32  Options 
)

Enables the specified options for the specified timer counter. This function sets the options without regard to the current options of the driver. To prevent a loss of the current options, the user should call XTmrCtr_GetOptions() prior to this function and modify the retrieved options to pass into this function to prevent loss of the current options.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Options contains the desired options to be set or cleared. Setting the option to '1' enables the option, clearing the to '0' disables the option. The options are bit masks such that multiple options may be set or cleared. The options are described in xtmrctr.h.
Returns:
None.
Note:
None.
void XTmrCtr_SetResetValue ( XTmrCtr InstancePtr,
u8  TmrCtrNumber,
u32  ResetValue 
)

Set the reset value for the specified timer counter. This is the value that is loaded into the timer counter when it is reset. This value is also loaded when the timer counter is started.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
ResetValue contains the value to be used to reset the timer counter.
Returns:
None.
Note:
None.
void XTmrCtr_Start ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Starts the specified timer counter of the device such that it starts running. The timer counter is reset before it is started and the reset value is loaded into the timer counter.

If interrupt mode is specified in the options, it is necessary for the caller to connect the interrupt handler of the timer/counter to the interrupt source, typically an interrupt controller, and enable the interrupt within the interrupt controller.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
None.
Note:
None.
void XTmrCtr_Stop ( XTmrCtr InstancePtr,
u8  TmrCtrNumber 
)

Stops the timer counter by disabling it.

It is the callers' responsibility to disconnect the interrupt handler of the timer_counter from the interrupt source, typically an interrupt controller, and disable the interrupt within the interrupt controller.

Parameters:
InstancePtr is a pointer to the XTmrCtr instance.
TmrCtrNumber is the timer counter of the device to operate on. Each device may contain multiple timer counters. The timer number is a zero based number with a range of 0 - (XTC_DEVICE_TIMER_COUNT - 1).
Returns:
None.
Note:
None.