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.

RTC Usage in Custom Driver



Hi,

We are working on custom board based on DM8148. our requirement is to read the data from ADC periodically so for this we want to generate an interrupt using RTC for every 10 Milli second in our custom driver.

Can any one tell how we to achieve it with the custom driver and how to register the rtc handler. also how to set RTC period time.

Regards,

Vimal

  • Hi Vimal,

    The RTC module support interrupt request towards the Cortex-A8 ARM / C674x DSP / Cortex-M3 ARM. Refer to the DM814x TRM, 1.7 Device Interrupts and EDMA Events and 20 Real-Time Clock (RTC).

    You can also examine and reuse the RTC starerWare code:

    http://processors.wiki.ti.com/index.php/StarterWare_RTC

    See also the below resources:

    linux-psp/drivers/rtc/rtc-omap.c

    linux-psp/Documentation/rtc.txt

    http://e2e.ti.com/support/arm/sitara_arm/f/791/t/307866.aspx

    http://e2e.ti.com/support/arm/sitara_arm/f/791/t/327404.aspx

    http://www.makelinux.net/books/lkd2/ch06lev1sec4 - A Real-Life Interrupt Handler

    Regards,
    Pavel

  • I don't think you can use the RTC for periodic interrupt every 10 millseconds. The RTC has a resolution of seconds. Much too large. Also, tt is difficult to schedule an alarm relative to the current time as the RTC takes absolute time. For example, it takes quite a bit of code to add 42 seconds to 2014-07-10 12:34:56 to arrive at an alarm time. The calculation must take into account leap year and carry. TI as never documented the RTC algorithm for leap years and seconds, etc. It would be a guess.

    I think you need to use the Timer module. Never used this processor. I would not know where to look for examples. The AM335x almost has the same registers as the DM8148. The AM335X StarterWare has an example for using timer. The IRQ handling would be different though. Maybe try the u-boot source.

    EDIT: spelling

  • The RTC is meant purely for keeping track of the current date and time.  It is incapable of generating interrupts every 10 milliseconds: the shortest interval configurable for the periodic interrupt is 1 second.

    If you are running under linux then getting a periodic callback is available as a kernel API.  The same probably holds for any other OS.

    If you are doing baremetal programming, the DM814x has 8 general-purpose timers available capable of generating interrupts to the cortex-A8 and DSP (and all except timer 8 also to media controller and EDMA).  These timers are documented in chapter 23 of the TRM.  The clock signal used for these timers is configurable in the DMTIMER_CLKSRC register inside PLLSS and defaults for all of them to the 20 MHz devosc input.  With this default, if you leave the prescaler disabled and program TLDR to (uint32_t)(-20000000/100) you will get a 10 millisecond (100 Hz) timer period, see section 23.2.1.6 for more info.

  • Norman Wong said:
    Also, tt is difficult to schedule an alarm relative to the current time as the RTC takes absolute time.

    The RTC actually has a periodic IRQ output in addition to the alarm IRQ.  However, you only have four choices as interval for the periodic interrupt: 1 second, 1 minute, 1 hour, and 1 day.

  • Matthijs van Duin said:

    The RTC actually has a periodic IRQ output in addition to the alarm IRQ.  However, you only have four choices as interval for the periodic interrupt: 1 second, 1 minute, 1 hour, and 1 day.

    You are right. Forgot about those. My task at the time was to schedule an RTC interrupt to get me out of deep sleep. The limited number of periods did not quite fit my requirements. Every minute seemed too short and every hour seemed to long. In hindsight, I guess I could have awoken and went back to sleep until enough desired time has past. Uses more power though.

  • Norman Wong said:
    The AM335x almost has the same registers as the DM8148. The AM335X StarterWare has an example for using timer. The IRQ handling would be different though.

    Actually, timers 2-7 have the same IRQ number and same memory address on DM814x and AM335x.  So apart from the PRCM differences, exactly the same code would work on both if you use one of those.

    In general, AM335x and DM814x are much more closely related than you'd expect at first glance given their different feature sets / target applications.  (This is also one of two reasons the AM335x memory map looks like swiss cheese: every peripheral available on the DM814x but not the AM335x is unallocated space there.)

  • Thanks for reply

    Now am looking for GP timer to generate 10msec interrupt in linux kernel PSP 4.01.00.07 linux. but in DM814X 4.01.00.07- PSP  there is no support for GT timers. can any one help us ,how to add clock domain and power init and IRQ settings in linux level  for any one of the GPtimer on DM8148 .

    please share code or guide us in proper way.

    Thanks & regards

    vimal  gupta

  • You could probably just use linux kernel high-resolution timers for this, but I'm also not sure why you're saying the PSP has no support for the hardware timers since the PSP Porting Guide actually has a section explaining how to use a timer from a kernel module.