iPXE
pit8254.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <assert.h>
00027 #include <ipxe/io.h>
00028 #include <ipxe/pit8254.h>
00029 
00030 /** @file
00031  *
00032  * 8254 Programmable Interval Timer
00033  *
00034  */
00035 
00036 /**
00037  * Delay for a fixed number of timer ticks using the speaker channel
00038  *
00039  * @v ticks             Number of timer ticks for which to delay
00040  */
00041 void pit8254_speaker_delay ( unsigned int ticks ) {
00042         uint8_t spkr;
00043         uint8_t cmd;
00044         uint8_t low;
00045         uint8_t high;
00046 
00047         /* Sanity check */
00048         assert ( ticks <= 0xffff );
00049 
00050         /* Disable speaker, set speaker channel gate input high */
00051         spkr = inb ( PIT8254_SPKR );
00052         spkr &= ~PIT8254_SPKR_ENABLE;
00053         spkr |= PIT8254_SPKR_GATE;
00054         outb ( spkr, PIT8254_SPKR );
00055 
00056         /* Program speaker channel to "interrupt" on terminal count */
00057         cmd = ( PIT8254_CMD_CHANNEL ( PIT8254_CH_SPKR ) |
00058                 PIT8254_CMD_ACCESS_LOHI | PIT8254_CMD_OP_TERMINAL |
00059                 PIT8254_CMD_BINARY );
00060         low = ( ( ticks >> 0 ) & 0xff );
00061         high = ( ( ticks >> 8 ) & 0xff );
00062         outb ( cmd, PIT8254_CMD );
00063         outb ( low, PIT8254_DATA ( PIT8254_CH_SPKR ) );
00064         outb ( high, PIT8254_DATA ( PIT8254_CH_SPKR ) );
00065 
00066         /* Wait for channel to "interrupt" */
00067         do {
00068                 spkr = inb ( PIT8254_SPKR );
00069         } while ( ! ( spkr & PIT8254_SPKR_OUT ) );
00070 }