Changeset da1bafb in mainline for kernel/arch/ia32/src/drivers/i8254.c


Ignore:
Timestamp:
2010-05-24T18:57:31Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

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

    r666f492 rda1bafb  
    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
     59#define CLK_CONST     1193180
     60#define MAGIC_NUMBER  1194
     61
     62#define LOOPS  150000
     63#define SHIFT  11
    6164
    6265static irq_t i8254_irq;
     
    7578         * lock. We just release it, call clock() and then reacquire it again.
    7679         */
    77         spinlock_unlock(&irq->lock);
     80        irq_spinlock_unlock(&irq->lock, false);
    7881        clock();
    79         spinlock_lock(&irq->lock);
     82        irq_spinlock_lock(&irq->lock, false);
    8083}
    8184
     
    102105}
    103106
    104 #define LOOPS 150000
    105 #define SHIFT 11
    106107void i8254_calibrate_delay_loop(void)
    107108{
    108         uint64_t clk1, clk2;
    109         uint32_t t1, t2, o1, o2;
    110         uint8_t not_ok;
    111 
    112 
    113109        /*
    114110         * One-shot timer. Count-down from 0xffff at 1193180Hz
     
    118114        pio_write_8(CLK_PORT1, 0xff);
    119115        pio_write_8(CLK_PORT1, 0xff);
    120 
     116       
     117        uint8_t not_ok;
     118        uint32_t t1;
     119        uint32_t t2;
     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         o1 = pio_read_8(CLK_PORT1);
     139        uint32_t 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         o2 = pio_read_8(CLK_PORT1);
     145        uint32_t 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         clk1 = get_cycle();
     151       
     152        uint64_t clk1 = get_cycle();
    153153        delay(1 << SHIFT);
    154         clk2 = get_cycle();
     154        uint64_t 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.