Real time clock

Hello,
i’m trying to get a tick (with a timebase resolution in 20µs range) in my
user application using the RTC-Chip.
i got the following code:

  1. Is there any other possibility to get a “tick” in the user

application,

apart from using the QNX timers together with the standard timebase?



Yes, use the RTC (IRQ8).



Here is the code for the RTC handling:



const struct sigevent *

IRQ8handler(void *area, int id)

{



InterruptDisable();

(void) out8(CMOS_ADDR, 0x0c); // Prepare to read register C

(void) in8(CMOS_DATA); // Read register C to clear interrupts

InterruptEnable();



return (&TimerEvent); // TimerEvent triggers the application …

}





/*

  • Setup the RTC

*/



void SetupRTC( unsigned short tr )

{

int reg ;



InterruptDisable(); // hopefully no NMIs …

(void) out8( CMOS_ADDR, 0x0A ) ; /* init to read RTC status

register A */

reg = in8( CMOS_DATA ) ; /* Read RTC status register

A */

InterruptEnable();



reg &= CMOS_ADDR; /* save bit 6… bit 4 of status register A */

reg |= tr; /*tr 3 = 122us */

/* 4 = 244us */

/* 5 = 488us */

/* 6 = 976us */

/* 7 =1953us */

/* 8 =3906us */



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0A ); /* init to update RTC status

register A */

(void) out8( CMOS_DATA, reg ) ; /* set tick intervall */

InterruptEnable();



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0B ) ;/* init to read register B */

reg = in8( CMOS_DATA ) ; /* Read it */

InterruptEnable();



reg |= 0x40 ; /* enable IRQ 8 */



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0B ) ;/* init to update register B */

(void) out8( CMOS_DATA, reg ) ; /* Update register B */

InterruptEnable();



/*

  • On some machines there may be dangling interrupts following

  • the POST test. Clear any dangling interrupts here.

*/



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0c ) ;/* Prepare to read register C */

(void) in8( CMOS_DATA ) ; /* Read register C to clear

interrupts */

InterruptEnable();



}





/*

  • RestoreRTC()

*/



void RestoreRTC( void )

{

int reg ;



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0B ) ;/* init to read register B */

reg = in8( CMOS_DATA ) ; /* Read register B */

InterruptEnable();



reg &= 0xBF ; /* Clear interrupt enable bit of IRQ 8*/



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0B ) ;/* init to update register B */

(void) out8( CMOS_DATA, reg ) ;/* Update register B */

InterruptEnable();



InterruptDisable();

(void) out8( CMOS_ADDR, 0x0C ) ;/* init to read register C */

(void) in8( CMOS_DATA ) ; /* Read reg. C to clear any

interrupts */

InterruptEnable();



}

beofre using the funtion in8() out8() , we must map the base address of the
RTC-Chip with the function mmap_device_io().

1- How can i find out this base address?

2-Were can i get informations more about this RTC-Chip and its functions.

Thanks for your help

best regards

Dadji

“dadji” <ydadji@hotmail.com> wrote in message
news:ecmded$ihf$1@inn.qnx.com

Hello,
i’m trying to get a tick (with a timebase resolution in 20µs range) in my
user application using the RTC-Chip.

That’s 50000 interrupts a seconds, you’d better have a fast CPU.


beofre using the funtion in8() out8() , we must map the base address of
the
RTC-Chip with the function mmap_device_io().

1- How can i find out this base address?

It’s everywhere on internet :wink:

2-Were can i get informations more about this RTC-Chip and its functions.

It’s everywhere on internet :wink:

Thanks for your help

best regards

Dadji

dadji wrote:

Hello,
i’m trying to get a tick (with a timebase resolution in 20µs range) in my
user application using the RTC-Chip.
i got the following code:

20us will kill the OS :slight_smile: It will produce too much overhead …

[ clip ]

beofre using the funtion in8() out8() , we must map the base address of the
RTC-Chip with the function mmap_device_io().

1- How can i find out this base address?

#define CMOS_ADDR 0x70
#define CMOS_DATA 0x71

2-Were can i get informations more about this RTC-Chip and its functions.

standard PC hardware documentation …

–Armin

Armin Steinhoff wrote:

dadji wrote:

Hello,
i’m trying to get a tick (with a timebase resolution in 20µs range) in my
user application using the RTC-Chip.
i got the following code:


20us will kill the OS > :slight_smile: > It will produce too much overhead …

It might just survive since this is not IRQ#0 so has nothing else other than dadji’s code to deal with. However, since the RTC can’t produce such a high rate of interrupts we will never know. :stuck_out_tongue:


Evan

“Armin Steinhoff” <a-steinhoff@web.de> wrote in message
news:ecsfmc$lf6$1@inn.qnx.com

dadji wrote:
Hello,
i’m trying to get a tick (with a timebase resolution in 20µs range) in my
user application using the RTC-Chip.
i got the following code:

20us will kill the OS > :slight_smile: > It will produce too much overhead …

I’ve seen a P4 2.4 handle interrupt #3 (highest priority) 15us (QNX4) and
the machine was running fine, but it was sluggist.

I use a PowerQuiccIII 833MHz CPU with 48kHz interrupt rate (21 µs)
running QNX 6.3.0 SP2. Everything works fine but overhead is big of course:

  • 1 µs interrupt latency (5% CPU time)
  • 2 µs of processing in the interrupt handler (10% CPU time)
  • about 1 µs to switch back to the interrupted thread (5% CPU time)

This means, I have a 20% constant CPU load just for this interrupt. No
problem here since it is part of the design.

Armand

Mario Charest wrote:

“Armin Steinhoff” <> a-steinhoff@web.de> > wrote in message
news:ecsfmc$lf6$> 1@inn.qnx.com> …
dadji wrote:
Hello,
i’m trying to get a tick (with a timebase resolution in 20µs range) in my
user application using the RTC-Chip.
i got the following code:
20us will kill the OS > :slight_smile: > It will produce too much overhead …

I’ve seen a P4 2.4 handle interrupt #3 (highest priority) 15us (QNX4) and
the machine was running fine, but it was sluggist.