Indented.

This commit is contained in:
skarg
2007-12-07 20:15:56 +00:00
parent eb72c8cb64
commit 32457a68c0
15 changed files with 691 additions and 581 deletions
+83 -54
View File
@@ -33,54 +33,80 @@ static volatile int SilenceTime;
/* counts ticks */
volatile unsigned long Timer_Milliseconds;
#define RTC_CMD_ADDR 0x70 // RTC internal register offset goes here
#define RTC_DAT_ADDR 0x71 // RTC internal register R/W access here
#define RTC_CMD_ADDR 0x70 // RTC internal register offset goes here
#define RTC_DAT_ADDR 0x71 // RTC internal register R/W access here
static uint8_t RTC_RS_Convert(
uint16_t hertz)
{
uint8_t RS = 0;
/* from DS12887A datasheet
SELECT BITS tPI PERIODIC
REGISTER A INTERRUPT SQW OUTPUT
RS3 RS2 RS1 RS0 RATE FREQUENCY
--- --- --- --- ------------ ----------
0 0 0 0 None 0Hz
0 0 0 1 3.90625ms 256Hz
0 0 1 0 7.8125ms 128Hz
0 0 1 1 122.070µs 8192Hz
0 1 0 0 244.141µs 4096Hz
0 1 0 1 488.281µs 2048Hz
0 1 1 0 976.5625µs 1024Hz
0 1 1 1 1.953125ms 512Hz
1 0 0 0 3.90625ms 256Hz
1 0 0 1 7.8125ms 128Hz
1 0 1 0 15.625ms 64Hz
1 0 1 1 31.25ms 32Hz
1 1 0 0 62.5ms 16Hz
1 1 0 1 125ms 8Hz
1 1 1 0 250ms 4Hz
1 1 1 1 500ms 2Hz
*/
SELECT BITS tPI PERIODIC
REGISTER A INTERRUPT SQW OUTPUT
RS3 RS2 RS1 RS0 RATE FREQUENCY
--- --- --- --- ------------ ----------
0 0 0 0 None 0Hz
0 0 0 1 3.90625ms 256Hz
0 0 1 0 7.8125ms 128Hz
0 0 1 1 122.070µs 8192Hz
0 1 0 0 244.141µs 4096Hz
0 1 0 1 488.281µs 2048Hz
0 1 1 0 976.5625µs 1024Hz
0 1 1 1 1.953125ms 512Hz
1 0 0 0 3.90625ms 256Hz
1 0 0 1 7.8125ms 128Hz
1 0 1 0 15.625ms 64Hz
1 0 1 1 31.25ms 32Hz
1 1 0 0 62.5ms 16Hz
1 1 0 1 125ms 8Hz
1 1 1 0 250ms 4Hz
1 1 1 1 500ms 2Hz
*/
/* FIXME: create a clever formula to replace switch */
switch (hertz) {
case 8192: RS = 3; break;
case 4096: RS = 4; break;
case 2048: RS = 5; break;
case 1024: RS = 6; break;
case 512: RS = 7; break;
case 256: RS = 8; break;
case 128: RS = 9; break;
case 64: RS = 10; break;
case 32: RS = 11; break;
case 16: RS = 12; break;
case 8: RS = 13; break;
case 4: RS = 14; break;
case 2: RS = 15; break;
case 8192:
RS = 3;
break;
case 4096:
RS = 4;
break;
case 2048:
RS = 5;
break;
case 1024:
RS = 6;
break;
case 512:
RS = 7;
break;
case 256:
RS = 8;
break;
case 128:
RS = 9;
break;
case 64:
RS = 10;
break;
case 32:
RS = 11;
break;
case 16:
RS = 12;
break;
case 8:
RS = 13;
break;
case 4:
RS = 14;
break;
case 2:
RS = 15;
break;
default:
break;
}
return RS;
}
@@ -98,7 +124,7 @@ static void interrupt Timer_Interrupt_Handler(
uint8_t temp_reg;
Timer_Ticks++;
milliseconds = (Timer_Ticks * 1000)/INT_FREQ;
milliseconds = (Timer_Ticks * 1000) / INT_FREQ;
diff = milliseconds - Elapsed_Milliseconds;
if (diff >= 1) {
Elapsed_Milliseconds = milliseconds;
@@ -112,40 +138,43 @@ static void interrupt Timer_Interrupt_Handler(
Elapsed_Milliseconds = 0;
}
/* clear interrupt */
outportb( RTC_CMD_ADDR, 0x0C ); // select RTC register C
temp_reg = inportb( RTC_DAT_ADDR ); // read RTC register C
/* clear interrupt */
outportb(RTC_CMD_ADDR, 0x0C); // select RTC register C
temp_reg = inportb(RTC_DAT_ADDR); // read RTC register C
/* signal end of interrupt to slave PIC */
outportb( 0xA0, 0x20 );
outportb(0xA0, 0x20);
/* signal end of interrupt to master PIC */
outportb( 0x20, 0x20 );
outportb(0x20, 0x20);
}
/* previous interrrupt vector */
static void interrupt(*OldVector)();
static void interrupt(
*OldVector) (
);
void Timer_Cleanup(void)
void Timer_Cleanup(
void)
{
setvect(0x70,OldVector);
setvect(0x70, OldVector);
}
void Timer_Init(
void)
{
uint8_t RC = RTC_RS_Convert(INT_FREQ);
/* get old interrupt vector to re-install on exit */
OldVector = getvect(0x70);
OldVector = getvect(0x70);
/* disable interrupts */
disable();
/* set RTC int. vector for our routine */
setvect(0x70,Timer_Interrupt_Handler);
setvect(0x70, Timer_Interrupt_Handler);
/* set register B with PIE enabled */
outportb( RTC_CMD_ADDR, 0x0B );
outportb( RTC_DAT_ADDR, 0x42 );
outportb(RTC_CMD_ADDR, 0x0B);
outportb(RTC_DAT_ADDR, 0x42);
/* set register A to our frequency */
outportb( RTC_CMD_ADDR, 0x0A );
outportb( RTC_DAT_ADDR, (0x20 | (RC & 0x0F)) );
outportb(RTC_CMD_ADDR, 0x0A);
outportb(RTC_DAT_ADDR, (0x20 | (RC & 0x0F)));
/* re-enable system interrupts */
enable();
atexit(Timer_Cleanup);
@@ -155,7 +184,7 @@ int Timer_Silence(
void)
{
uint16_t time_value;
disable();
time_value = SilenceTime;
enable();