/*---------------------------------------------------------------------------* * Routine: RX62N_RTC_Set *---------------------------------------------------------------------------* * Description: * Set 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_Set(void *aWorkspace, const T_uezTimeDate *aTimeDate) { //T_RX62N_RTC_Workspace *p = (T_RX62N_RTC_Workspace *)aWorkspace; PARAM_NOT_USED(aWorkspace); // Stop RTC (disable and reset) RTC.RCR2.BIT.START = 0; RTC.RCR2.BIT.RESET = 1; // Update RTC registers RTC.RSECCNT.BYTE = IDecimalToBCD(aTimeDate->iTime.iSecond); RTC.RMINCNT.BYTE = IDecimalToBCD(aTimeDate->iTime.iMinute); RTC.RHRCNT.BYTE = IDecimalToBCD(aTimeDate->iTime.iHour); RTC.RDAYCNT.BYTE = IDecimalToBCD(aTimeDate->iDate.iDay); RTC.RMONCNT.BYTE = IDecimalToBCD(aTimeDate->iDate.iMonth); RTC.RYRCNT.WORD = IDecimalToBCD(aTimeDate->iDate.iYear); // Start RTC with external XTAL RTC.RCR2.BIT.START = 1; return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Internal Routine: RTC_PCF8563_Set *---------------------------------------------------------------------------* * Description: * Set the current RTC clock (without regard to semaphoring actions) * Inputs: * T_RTC_PCF8563_Workspace *p -- Workspace * const T_uezTimeDate *aTimeDate -- Time and date to set to * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ static T_uezError RTC_PCF8563_LowLevelSet( T_RTC_PCF8563_Workspace *p, const T_uezTimeDate *aTimeDate) { I2C_Request r; TUInt8 dataout[17]; TUInt8 *data = dataout+1; dataout[0] = 0x00; // Setup structure r.iAddr = PCF8563_I2C_ADDR; r.iSpeed = PCF8563_I2C_SPEED; r.iWriteData = dataout; // Write out the new configuration r.iWriteLength = 10; r.iWriteTimeout = UEZ_TIMEOUT_INFINITE; // wait until bus ready r.iReadData = 0; // no reading, just writing r.iReadLength = 0; r.iReadTimeout = 0; // Setup data to go out data[0] = 0x00; // controls with it running data[1] = 0x00; // reset all alarms data[2] = IDecimalToBCD(aTimeDate->iTime.iSecond); data[3] = IDecimalToBCD(aTimeDate->iTime.iMinute); data[4] = IDecimalToBCD(aTimeDate->iTime.iHour); data[5] = IDecimalToBCD(aTimeDate->iDate.iDay); data[6] = 0; // day of week not used data[7] = IDecimalToBCD(aTimeDate->iDate.iMonth); data[8] = IDecimalToBCD(aTimeDate->iDate.iYear-2000); // Do the I2C return (*p->iI2C)->ProcessRequest(p->iI2C, &r); }