/******************************************************************************* * Function Name: Timer_1_SaveConfig ******************************************************************************** * * Summary: * Save the current user configuration * * Parameters: * void * * Return: * void * * Global variables: * Timer_1_backup: Variables of this global structure are modified to * store the values of non retention configuration registers when Sleep() API is * called. * *******************************************************************************/ void Timer_1_SaveConfig(void) { #if (!Timer_1_UsingFixedFunction) /* Backup the UDB non-rentention registers for CY_UDB_V0 */ #if (CY_UDB_V0) Timer_1_backup.TimerUdb = Timer_1_ReadCounter(); Timer_1_backup.TimerPeriod = Timer_1_ReadPeriod(); Timer_1_backup.InterruptMaskValue = Timer_1_STATUS_MASK; #if (Timer_1_UsingHWCaptureCounter) Timer_1_backup.TimerCaptureCounter = Timer_1_ReadCaptureCount(); #endif /* Backup the UDB non-rentention register capture counter for CY_UDB_V0 */ #endif /* Backup the UDB non-rentention registers for CY_UDB_V0 */ #if (CY_UDB_V1) Timer_1_backup.TimerUdb = Timer_1_ReadCounter(); Timer_1_backup.InterruptMaskValue = Timer_1_STATUS_MASK; #if (Timer_1_UsingHWCaptureCounter) Timer_1_backup.TimerCaptureCounter = Timer_1_ReadCaptureCount(); #endif /* Back Up capture counter register */ #endif /* Backup non retention registers, interrupt mask and capture counter for CY_UDB_V1 */ #if(!Timer_1_ControlRegRemoved) Timer_1_backup.TimerControlRegister = Timer_1_ReadControlRegister(); #endif /* Backup the enable state of the Timer component */ #endif /* Backup non retention registers in UDB implementation. All fixed function registers are retention */ }
int rread(void) { SC0_SetDriveMode(PIN_DM_STRONG); SC0_Write(1); CyDelayUs(10); SC0_SetDriveMode(PIN_DM_DIG_HIZ); Timer_1_Start(); uint16_t start = Timer_1_ReadCounter(); uint16_t end = 0; while(!(Timer_1_ReadStatusRegister() & Timer_1_STATUS_TC)) { if(SC0_Read() == 0 && end == 0) { end = Timer_1_ReadCounter(); } } Timer_1_Stop(); return (start - end); }
/******************************************************************************* * Function Name: Timer_1_SaveConfig ******************************************************************************** * * Summary: * Save the current user configuration * * Parameters: * void * * Return: * void * * Global variables: * Timer_1_backup: Variables of this global structure are modified to * store the values of non retention configuration registers when Sleep() API is * called. * *******************************************************************************/ void Timer_1_SaveConfig(void) { #if (!Timer_1_UsingFixedFunction) Timer_1_backup.TimerUdb = Timer_1_ReadCounter(); Timer_1_backup.InterruptMaskValue = Timer_1_STATUS_MASK; #if (Timer_1_UsingHWCaptureCounter) Timer_1_backup.TimerCaptureCounter = Timer_1_ReadCaptureCount(); #endif /* Back Up capture counter register */ #if(!Timer_1_UDB_CONTROL_REG_REMOVED) Timer_1_backup.TimerControlRegister = Timer_1_ReadControlRegister(); #endif /* Backup the enable state of the Timer component */ #endif /* Backup non retention registers in UDB implementation. All fixed function registers are retention */ }
int main() { //initialization code TX_Start(); CyGlobalIntEnable; char str[10]; char strdouble[10]; float sum = sum_float(donothing_float, 1, 1000); double sum_d = sum_float(donothing_float, 1, 1000); sprintf(str, "%f", sum); sprintf(strdouble, "%f", sum_d); TX_PutString(str); TX_PutCRLF(); while (1) { sprintf(str, "%d", (int)Timer_1_ReadCounter()); TX_PutString(str); TX_PutCRLF(); CyDelay(10); } }