This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

tps6591x rtc WEC7 OALIoCtlHalInitRTC problem

Hello everyone,

I'm trying to use the external RTC on the AM335x EVM (WEC 7), using the TPS6591x, but I've got some troubles initializing it. What does have to be done in the OALIoCtlHalInitRTC function ? How to check at init if the RTC has been rested or if it's running normally ?

Regards,
Thomas

  • Thomas,

    You need to do the complete initilization of the RTC in the OALIoCtlHalInitRTC function. Initlialiaze interrupt, control registers and set the RTC to run state.  With this your RTC should start. You can read the status register to check whether its running or not. From the application you can use the GetSystemTime function and verify whether its running.

    Regards,

    Ganesh Karanth

  • Ganesh, Thanks for your answer.

    I have tried many ways to do my init, even trying to backport a Linux driver, but still not working.

    My RTC is running, and I can set and get time. Just init failed ...

    Here is my code :

    BOOL
    OALIoCtlHalInitRTC(
        UINT32 code,
        VOID *pInBuffer,
        UINT32 inSize,
        VOID *pOutBuffer,
        UINT32 outSize,
        UINT32 *pOutSize
        )
    {
        BOOL            rc = FALSE;
        SYSTEMTIME      *pGivenTime = (LPSYSTEMTIME) pInBuffer;
    //    UCHAR           bcdTime[6];
        UCHAR           status = 0;
    //    UCHAR           secure = 0;
        UCHAR            interrupts = 0;
    //    UCHAR            save_control;
        UCHAR            rtc_control = 0;

        UNREFERENCED_PARAMETER(pOutSize);
        UNREFERENCED_PARAMETER(outSize);
        UNREFERENCED_PARAMETER(pOutBuffer);
        UNREFERENCED_PARAMETER(inSize);
        UNREFERENCED_PARAMETER(code);

        OALMSG(OAL_TIMER && OAL_FUNC, (L"+OALIoCtlHalInitRTC()\r\n"));

        // Initialize RTC critical section
        if (!s_rtc.initialized)
        {
            // Initialize RTC critical section
            InitializeCriticalSection(&s_rtc.cs);
        }

        // First read RTC status from Triton
        s_rtc.hTWL = TWLOpen();
        if (s_rtc.hTWL == NULL)
        {
            OALMSG(OAL_ERROR, (L" OALIoCtlHalInitRTC(): Failed to open Triton\r\n"));
            goto cleanUp;
        }
        
        // Clear ALARM Status Register
        TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_STATUS_REG, PMIC_RTC_STATUS_ALARM);

        // Init Interrupt
        interrupts = PMIC_RTC_INTERRUPTS_ALARM | PMIC_RTC_INTERRUPTS_EVERY_SEC;
        TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_INTERRUPTS_REG, interrupts);

        // Configure Control Register
        rtc_control = PMIC_RTC_CTRL_RUN | PMIC_RTC_CTRL_MODE_12_24;
        TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_CTRL_REG, rtc_control);
        
        // Get Status
        TWLReadByteReg(s_rtc.hTWL, PMIC_RTC_STATUS_REG, &status);
        if(status & PMIC_RTC_STATUS_POWER_UP)
        {
            TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_STATUS_REG, PMIC_RTC_STATUS_POWER_UP|PMIC_RTC_STATUS_ALARM);
            RETAILMSG(1, ( TEXT(" OALIoCtlHalInitRTC() ===> A RESET OCCURED !") ) );
            rc = OEMSetRealTime(pGivenTime);
        }
        else
        {
            UCHAR save_control;
            UCHAR rtc_control;
            UCHAR bcdTime[6];
            DWORD       delta;
            ULONGLONG   time;
            WCHAR buffer1[64];
            
            if (g_ResumeRTC)
            {
                // suspend/resume occured, sync RTC
                OALIoCtlHalRtcTime(0, NULL, 0, NULL, 0, NULL);
                g_ResumeRTC = FALSE;
            }
            delta = OEMGetTickCount() - s_rtc.baseTickCount;
            time = s_rtc.baseFiletime + s_rtc.baseOffset + ((ULONGLONG)delta) * 10000;

            // Make sure PMIC_RTC_CTRL_GET_TIME is clear
            TWLReadByteReg(s_rtc.hTWL, PMIC_RTC_CTRL_REG, &save_control);
            if(save_control & PMIC_RTC_CTRL_GET_TIME)
            {
                save_control &= ~PMIC_RTC_CTRL_GET_TIME;
                TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_CTRL_REG, save_control);
            }
            
            // Copy RTC counting registers to static registers or latches
            rtc_control = save_control | PMIC_RTC_CTRL_GET_TIME;

            // Enable read access to static shadowed registers
            rtc_control |= PMIC_RTC_CTRL_RTC_V_OPT;
            TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_CTRL_REG, rtc_control);

            //  Get date and time from RTC
            TWLReadByteReg(s_rtc.hTWL, PMIC_YEARS_REG,          &bcdTime[5]);
            TWLReadByteReg(s_rtc.hTWL, PMIC_MONTHS_REG,      &bcdTime[4]);
            TWLReadByteReg(s_rtc.hTWL, PMIC_DAYS_REG,             &bcdTime[3]);
            TWLReadByteReg(s_rtc.hTWL, PMIC_HOURS_REG,        &bcdTime[2]);
            TWLReadByteReg(s_rtc.hTWL, PMIC_MINUTES_REG,     &bcdTime[1]);
            TWLReadByteReg(s_rtc.hTWL, PMIC_SECONDS_REG,   &bcdTime[0]);

            // Restore original state of rtc control register
            TWLWriteByteReg(s_rtc.hTWL, PMIC_RTC_CTRL_REG, save_control);

            //  Convert current RTC date/time to FILETIME
            pGivenTime->wYear    = BCD2BIN(bcdTime[5]) + RTC_BASE_YEAR_MIN;
            pGivenTime->wMonth   = BCD2BIN(bcdTime[4]);
            pGivenTime->wDay     = BCD2BIN(bcdTime[3]);
            pGivenTime->wHour    = BCD2BIN(bcdTime[2]);
            pGivenTime->wMinute  = BCD2BIN(bcdTime[1]);
            pGivenTime->wSecond  = BCD2BIN(bcdTime[0]);
            pGivenTime->wMilliseconds = 0;

            //NKFileTimeToSystemTime((FILETIME*)&time, pGivenTime);
            RETAILMSG(1, (TEXT("-OALIoCtlHalInitRTC() = %s\r\n"), SystemTimeToString(pGivenTime,buffer1,64)));
        }

        rc = TRUE;
        s_rtc.initialized = TRUE;

        
    cleanUp:
        OALMSG(OAL_TIMER && OAL_FUNC, (L"-OALIoCtlHalInitRTC() rc = %d\r\n", rc));
        return rc;
    }

    When my RTC isn't initialized, i do a OEMSetRealTime and that works, but when it's initialized, it failed : my read return all to 0, so I get the date time 2000.00.00 00:00:00.000

    And then a process do a SetRealTime to 1601.01.01 00:00:23.000

    I'm am lost, I think it's just a little thing but what ?

    Thanks for your help

    Regards,

    Thomas

  • Thomas, I am little confused here . Are you saying if you do not call the OALIoCtlHalInitRTC your RTC is functioning properly ? Or you are calling the OALIoCtlHalInitRTC but it is failing to initialize. If you are saying without initializing it runs properly I wondor where was it initilaized ?

    Regards,

    Ganesh Karanth