iPXE
pit8254.h
Go to the documentation of this file.
00001 #ifndef _IPXE_PIT8254_H
00002 #define _IPXE_PIT8254_H
00003 
00004 /** @file
00005  *
00006  * 8254 Programmable Interval Timer
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 /** IRQ0 channel */
00013 #define PIT8254_CH_IRQ0 0
00014 
00015 /** PC speaker channel */
00016 #define PIT8254_CH_SPKR 2
00017 
00018 /** Timer frequency (1.193182MHz) */
00019 #define PIT8254_HZ 1193182UL
00020 
00021 /** Data port */
00022 #define PIT8254_DATA(channel) ( 0x40 + (channel) )
00023 
00024 /** Mode/command register */
00025 #define PIT8254_CMD 0x43
00026 
00027 /** Select channel */
00028 #define PIT8254_CMD_CHANNEL(channel) ( (channel) << 6 )
00029 
00030 /** Access modes */
00031 #define PIT8254_CMD_ACCESS_LATCH 0x00   /**< Latch count value command */
00032 #define PIT8254_CMD_ACCESS_LO   0x10    /**< Low byte only */
00033 #define PIT8254_CMD_ACCESS_HI   0x20    /**< High byte only */
00034 #define PIT8254_CMD_ACCESS_LOHI 0x30    /**< Low-byte, high-byte pair */
00035 
00036 /* Operating modes */
00037 #define PIT8254_CMD_OP_TERMINAL 0x00    /**< Interrupt on terminal count */
00038 #define PIT8254_CMD_OP_ONESHOT  0x02    /**< Hardware re-triggerable one-shot */
00039 #define PIT8254_CMD_OP_RATE     0x04    /**< Rate generator */
00040 #define PIT8254_CMD_OP_SQUARE   0x06    /**< Square wave generator */
00041 #define PIT8254_CMD_OP_SWSTROBE 0x08    /**< Software triggered strobe */
00042 #define PIT8254_CMD_OP_HWSTROBE 0x0a    /**< Hardware triggered strobe */
00043 #define PIT8254_CMD_OP_RATE2    0x0c    /**< Rate generator (duplicate) */
00044 #define PIT8254_CMD_OP_SQUARE2  0x0e    /**< Square wave generator (duplicate)*/
00045 
00046 /** Binary mode */
00047 #define PIT8254_CMD_BINARY 0x00
00048 
00049 /** BCD mode */
00050 #define PIT8254_CMD_BCD 0x01
00051 
00052 /** PC speaker control register */
00053 #define PIT8254_SPKR 0x61
00054 
00055 /** PC speaker channel gate */
00056 #define PIT8254_SPKR_GATE 0x01
00057 
00058 /** PC speaker enabled */
00059 #define PIT8254_SPKR_ENABLE 0x02
00060 
00061 /** PC speaker channel output */
00062 #define PIT8254_SPKR_OUT 0x20
00063 
00064 extern void pit8254_speaker_delay ( unsigned int ticks );
00065 
00066 /**
00067  * Delay for a fixed number of microseconds
00068  *
00069  * @v usecs             Number of microseconds for which to delay
00070  */
00071 static inline __attribute__ (( always_inline )) void
00072 pit8254_udelay ( unsigned long usecs ) {
00073 
00074         /* Delays are invariably compile-time constants; force the
00075          * multiplication and division to take place at compilation
00076          * time rather than runtime.
00077          */
00078         pit8254_speaker_delay ( ( usecs * PIT8254_HZ ) / 1000000 );
00079 }
00080 
00081 #endif /* _IPXE_PIT8254_H */