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:
- 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