Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/drivers/i8254.c

    rda1bafb rd99c1d2  
    5454#include <ddi/device.h>
    5555
    56 #define CLK_PORT1  ((ioport8_t *) 0x40)
    57 #define CLK_PORT4  ((ioport8_t *) 0x43)
     56#define CLK_PORT1       ((ioport8_t *)0x40)
     57#define CLK_PORT4       ((ioport8_t *)0x43)
    5858
    59 #define CLK_CONST     1193180
    60 #define MAGIC_NUMBER  1194
    61 
    62 #define LOOPS  150000
    63 #define SHIFT  11
     59#define CLK_CONST       1193180
     60#define MAGIC_NUMBER    1194
    6461
    6562static irq_t i8254_irq;
     
    7875         * lock. We just release it, call clock() and then reacquire it again.
    7976         */
    80         irq_spinlock_unlock(&irq->lock, false);
     77        spinlock_unlock(&irq->lock);
    8178        clock();
    82         irq_spinlock_lock(&irq->lock, false);
     79        spinlock_lock(&irq->lock);
    8380}
    8481
     
    105102}
    106103
     104#define LOOPS 150000
     105#define SHIFT 11
    107106void i8254_calibrate_delay_loop(void)
    108107{
     108        uint64_t clk1, clk2;
     109        uint32_t t1, t2, o1, o2;
     110        uint8_t not_ok;
     111
     112
    109113        /*
    110114         * One-shot timer. Count-down from 0xffff at 1193180Hz
     
    114118        pio_write_8(CLK_PORT1, 0xff);
    115119        pio_write_8(CLK_PORT1, 0xff);
    116        
    117         uint8_t not_ok;
    118         uint32_t t1;
    119         uint32_t t2;
    120        
     120
    121121        do {
    122122                /* will read both status and count */
     
    126126                t1 |= pio_read_8(CLK_PORT1) << 8;
    127127        } while (not_ok);
    128        
     128
    129129        asm_delay_loop(LOOPS);
    130        
     130
    131131        pio_write_8(CLK_PORT4, 0xd2);
    132132        t2 = pio_read_8(CLK_PORT1);
    133133        t2 |= pio_read_8(CLK_PORT1) << 8;
    134        
     134
    135135        /*
    136136         * We want to determine the overhead of the calibrating mechanism.
    137137         */
    138138        pio_write_8(CLK_PORT4, 0xd2);
    139         uint32_t o1 = pio_read_8(CLK_PORT1);
     139        o1 = pio_read_8(CLK_PORT1);
    140140        o1 |= pio_read_8(CLK_PORT1) << 8;
    141        
     141
    142142        asm_fake_loop(LOOPS);
    143        
     143
    144144        pio_write_8(CLK_PORT4, 0xd2);
    145         uint32_t o2 = pio_read_8(CLK_PORT1);
     145        o2 = pio_read_8(CLK_PORT1);
    146146        o2 |= pio_read_8(CLK_PORT1) << 8;
    147        
     147
    148148        CPU->delay_loop_const =
    149149            ((MAGIC_NUMBER * LOOPS) / 1000) / ((t1 - t2) - (o1 - o2)) +
    150150            (((MAGIC_NUMBER * LOOPS) / 1000) % ((t1 - t2) - (o1 - o2)) ? 1 : 0);
    151        
    152         uint64_t clk1 = get_cycle();
     151
     152        clk1 = get_cycle();
    153153        delay(1 << SHIFT);
    154         uint64_t clk2 = get_cycle();
     154        clk2 = get_cycle();
    155155       
    156156        CPU->frequency_mhz = (clk2 - clk1) >> SHIFT;
    157        
     157
    158158        return;
    159159}
Note: See TracChangeset for help on using the changeset viewer.