/*---------------------------------------------------------------------------* * Routine: RTC_PCF8563_Get *---------------------------------------------------------------------------* * Description: * Get the current RTC clock reading. * Inputs: * void *aW -- Workspace * T_uezTimeDate *aTimeDate -- Time and date returned * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError RTC_PCF8563_Get(void *aWorkspace, T_uezTimeDate *aTimeDate) { T_uezError error; T_RTC_PCF8563_Workspace *p = (T_RTC_PCF8563_Workspace *)aWorkspace; I2C_Request r; TUInt8 data[16]; TUInt8 reg0[1] = {0x00}; r.iAddr = PCF8563_I2C_ADDR; r.iSpeed = PCF8563_I2C_SPEED; r.iWriteData = reg0; r.iWriteLength = 1; r.iWriteTimeout = UEZ_TIMEOUT_INFINITE; r.iReadData = data; r.iReadLength = 16; r.iReadTimeout = UEZ_TIMEOUT_INFINITE; // wait until bus ready // Allow only one transfer at a time UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE); error = (*p->iI2C)->ProcessRequest(p->iI2C, &r); if (!error) { aTimeDate->iTime.iSecond = IBCDToDecimal(data[2] & 0x7F); aTimeDate->iTime.iMinute = IBCDToDecimal(data[3] & 0x7F); aTimeDate->iTime.iHour = IBCDToDecimal(data[4] & 0x3F); aTimeDate->iDate.iMonth = IBCDToDecimal(data[7] & 0x1F); aTimeDate->iDate.iDay = IBCDToDecimal(data[5] & 0x3F); aTimeDate->iDate.iYear = 2000+IBCDToDecimal(data[8] & 0xFF); } UEZSemaphoreRelease(p->iSem); return error; }
/*---------------------------------------------------------------------------* * Routine: RX62N_RTC_Get *---------------------------------------------------------------------------* * Description: * Get the current date and time. * Inputs: * void *aW -- RTC workspace * T_uezTimeDate *aTimeDate -- Time and date of the current time * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError RX62N_RTC_Get(void *aWorkspace, T_uezTimeDate *aTimeDate) { // Read the time and date, but check to see if it is just // changing. If it just changes, then read again. We don't // want to be caught reading between 11:59:59 and 0:00:00. do { // Clear the carry flag ICU.IR[IR_RTC_CUP].BIT.IR = 0; aTimeDate->iTime.iSecond = IBCDToDecimal(RTC.RSECCNT.BYTE); aTimeDate->iTime.iMinute = IBCDToDecimal(RTC.RMINCNT.BYTE); aTimeDate->iTime.iHour = IBCDToDecimal(RTC.RHRCNT.BYTE); aTimeDate->iDate.iDay = IBCDToDecimal(RTC.RDAYCNT.BYTE); aTimeDate->iDate.iMonth = IBCDToDecimal(RTC.RMONCNT.BYTE); aTimeDate->iDate.iYear = IBCDToDecimal(RTC.RYRCNT.WORD); } while (ICU.IR[IR_RTC_CUP].BIT.IR); // Now extract the consolidated registers into the structure // in a more useful form. return UEZ_ERROR_NONE; }