📄 xtmrctr.c
字号:
* 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).** @return None.** @note None.*******************************************************************************/void XTmrCtr_Stop(XTmrCtr * InstancePtr, u8 TmrCtrNumber){ u32 ControlStatusReg; XASSERT_VOID(InstancePtr != NULL); XASSERT_VOID(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); /* * Read the current register contents */ ControlStatusReg = XTimerCtr_mReadReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCSR_OFFSET); /* * Disable the timer counter such that it's not running */ ControlStatusReg &= ~(XTC_CSR_ENABLE_TMR_MASK); /* * Write out the updated value to the actual register. */ XTmrCtr_mWriteReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCSR_OFFSET, ControlStatusReg);}/*****************************************************************************//**** 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.** @param InstancePtr is a pointer to the XTmrCtr instance.* @param 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).** @return The current value for the timer counter.** @note None.*******************************************************************************/u32 XTmrCtr_GetValue(XTmrCtr * InstancePtr, u8 TmrCtrNumber){ XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); return XTimerCtr_mReadReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCR_OFFSET);}/*****************************************************************************//**** 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.** @param InstancePtr is a pointer to the XTmrCtr instance.* @param 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).* @param ResetValue contains the value to be used to reset the timer* counter.** @return None.** @note None.*******************************************************************************/void XTmrCtr_SetResetValue(XTmrCtr * InstancePtr, u8 TmrCtrNumber, u32 ResetValue){ XASSERT_VOID(InstancePtr != NULL); XASSERT_VOID(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); XTmrCtr_mWriteReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TLR_OFFSET, ResetValue);}/*****************************************************************************//**** Returns the timer counter value that was captured the last time the external* capture input was asserted.** @param InstancePtr is a pointer to the XTmrCtr instance.* @param 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).** @return The current capture value for the indicated timer counter.** @note None.********************************************************************************/u32 XTmrCtr_GetCaptureValue(XTmrCtr * InstancePtr, u8 TmrCtrNumber){ XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); return XTimerCtr_mReadReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TLR_OFFSET);}/*****************************************************************************//**** Resets the specified timer counter of the device. A reset causes the timer* counter to set it's value to the reset value.** @param InstancePtr is a pointer to the XTmrCtr instance.* @param 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).** @return None.** @note None.*******************************************************************************/void XTmrCtr_Reset(XTmrCtr * InstancePtr, u8 TmrCtrNumber){ u32 CounterControlReg; XASSERT_VOID(InstancePtr != NULL); XASSERT_VOID(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); /* * Read current contents of the register so it won't be destroyed */ CounterControlReg = XTimerCtr_mReadReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCSR_OFFSET); /* * Reset the timer by toggling the reset bit in the register */ XTmrCtr_mWriteReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCSR_OFFSET, CounterControlReg | XTC_CSR_LOAD_MASK); XTmrCtr_mWriteReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCSR_OFFSET, CounterControlReg);}/*****************************************************************************//**** 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.** @param InstancePtr is a pointer to the XTmrCtr instance.* @param 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).** @return TRUE if the timer has expired, and FALSE otherwise.** @note None.*******************************************************************************/int XTmrCtr_IsExpired(XTmrCtr * InstancePtr, u8 TmrCtrNumber){ u32 CounterControlReg; XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); /* * Check if timer is expired */ CounterControlReg = XTimerCtr_mReadReg(InstancePtr->BaseAddress, TmrCtrNumber, XTC_TCSR_OFFSET); return ((CounterControlReg & XTC_CSR_INT_OCCURED_MASK) == XTC_CSR_INT_OCCURED_MASK);}/******************************************************************************* Looks up the device configuration based on the unique device ID. The table* TmrCtrConfigTable contains the configuration info for each device in the* system.** @param DeviceId is the unique device ID to search for in the config* table.** @return A pointer to the configuration that matches the given device ID,* or NULL if no match is found.** @note None.*******************************************************************************/XTmrCtr_Config *XTmrCtr_LookupConfig(u16 DeviceId){ XTmrCtr_Config *CfgPtr = NULL; int i; for (i = 0; i < XPAR_XTMRCTR_NUM_INSTANCES; i++) { if (XTmrCtr_ConfigTable[i].DeviceId == DeviceId) { CfgPtr = &XTmrCtr_ConfigTable[i]; break; } } return CfgPtr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -