?? io_dm270.c
字號:
/* * File: io_dm270.c * * An implementation of a h/w io utility specific to the TI DM270 EVM * platform. This implementation, while vendor dependent, exposes the * vendor independent io.h interface allowing it to plug generically into * the bootloader. Please see io.h for more info. * * See Also * io.h * * Copyright (C) 2002 RidgeRun, Inc. * Author: RidgeRun, Inc <skranz@ridgerun.com> * - Derived from io_dsc21.c, 9/6/02, Gregory Nutt * - Derived from io_dsc25.c, 2/19/03, Gregory Nutt * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 675 Mass Ave, Cambridge, MA 02139, USA. * * Please report all bugs/problems to the author or <support@dsplinux.net> * * key: RRGPLCR (do not remove) * */#include "types.h"#include "io.h"#include "usb.h"#include "util.h"//#include "btldr_pi.h" /* for btldr_AddressIsInFlashSpace */#include "dm270-registers.h"#define LOOPS_PER_MSEC 400#define UART0_REGISTER_BASE 0x00030300 /* UART0 */static int CONSOLE_TYPE; // 0 = serial port device // 1 = parallel port device // 2 = USB port devicestatic int is_par_char();static void io_putchar_par(unsigned char c);/****************************** Routine: Description: ******************************/static unsigned short inreg_ser(unsigned int reg){ unsigned short val; val = *((volatile unsigned short *)(UART0_REGISTER_BASE + reg)); return val;}/****************************** Routine: Description: ******************************/static void outreg_ser(unsigned int reg, unsigned short val){ *((volatile unsigned short *)(UART0_REGISTER_BASE + reg)) = val;}/****************************** Routine: Description:******************************/static void uart_init(){//#if 0 // moved to hwinit_dm270.S if (SER == CONSOLE_TYPE) { outreg_ser(UART_RFCR,UART_CONST_FIFO_CLEAR); outreg_ser(UART_TFCR,UART_CONST_FIFO_CLEAR); outreg_ser(UART_LCR, 0x0000); outreg_ser(UART_RFCR,UART_TRIGGER_LEVEL_01); outreg_ser(UART_TFCR,UART_TRIGGER_LEVEL_16);// outreg_ser(UART_BRSR, UART_BAUD_38400); outreg_ser(UART_BRSR, UART_BAUD_115200); outreg_ser(UART_MSR, (UART_NOPARITY | \ UART_STOPBIT_1 | \ UART_DATABIT_8)); } else { // TBSL *debug* finish later. }//#endif}/****************************** Routine: Description: Note: See io.h for description. ******************************/static int is_ser_char(){ if (inreg_ser(UART_SR) & UART_RX_FIFO_NOEMPTY) { return TRUE; } else { return FALSE; }}/****************************** Routine: Description: ******************************/static void io_putchar_ser(unsigned char c){ if ('\n' == c) { io_putchar_ser('\r'); } while (0 == (inreg_ser(UART_SR) & UART_TX_FIFO_LEVEL)) {} outreg_ser(UART_DTRR, (unsigned short)c);}/****************************** Routine: Description: Note: See io.h for description. ******************************/unsigned char io_getchar_ser(void){ unsigned short ch_err_pair; unsigned char ch, err;//retry: while (!is_ser_char()){} ch_err_pair = inreg_ser(UART_DTRR); ch = ch_err_pair & 0x00FF; err = ch_err_pair >> 8; // if (!(UART_DATA_VALID & err)) goto retry; return ch;}/****************************** Routine: Description: Note: See io.h for description. ******************************/static int is_char(){ switch(CONSOLE_TYPE) { case PAR: return is_par_char(); case SER: return is_ser_char();#ifdef USE_USB case USB: return usb_is_char();#endif } return 0;}/****************************** Routine: Description: Note: See io.h for description. timeout_sec -1 -- wait indefinitely for a key press. 0 -- don't wait at all, if a key value is present now return it, otherwise return 0. t -- wait up to this long for a key press to return, otherwise give up and return 0. ******************************/unsigned char io_getc(int timeout_msec){ int time_remaining = LOOPS_PER_MSEC*timeout_msec; while (time_remaining--) { if (is_char()) { return io_getchar_con(); } } return 0;}/****************************** Routine: Description: Note: See io.h for description. ******************************/unsigned char io_getchar_con(){ switch(CONSOLE_TYPE) { case PAR: return io_getchar_par(); case SER: return io_getchar_ser();#ifdef USE_USB case USB: return usb_getchar();#endif } return 0;}/****************************** Routine: Description: Note: See io.h for description. ******************************/void io_putchar(unsigned char c){ switch(CONSOLE_TYPE) { case PAR: io_putchar_par(c); break; case SER: io_putchar_ser(c); break;#ifdef USE_USB case USB: usb_putchar(c); break;#endif }}/****************************** Routine: Description: Note: See io.h for description. ******************************/static int is_par_char(){ return FALSE; // TBSL *debug* temp.}/****************************** Routine: Description: ******************************/static void io_putchar_par(unsigned char c){ if ('\n' == c) { io_putchar_par('\r'); } // TBSL *debug* finish later.}/****************************** Routine: Description: Note: See io.h for description. ******************************/unsigned char io_getchar_par(void){ while (!is_par_char()) {} return 0; // *debug* temp, finish later.}/****************************** Routine: Description: Note: See io.h for description. ******************************/int io_getbootmode(void){ return 1; // *revisit-skranz* temp.}/****************************** Routine: Description: Note: See io.h for description. ******************************/void display_board_digit(unsigned char val){ // not applicable to this EVM}/****************************** Routine: Description: Note: See io.h for description. ******************************/void io_delay(int milliseconds){ volatile int i, j; for (i=0; i<milliseconds; i++) { for (j=0; j<LOOPS_PER_MSEC; j++) { } }}/****************************** Routine: Description: Note: See io.h for description. ******************************/void io_StartTimeElapse(int milliseconds){ // *revisit-skranz* not yet implemented // on this platform.}/****************************** Routine: Description: Note: See io.h for description. ******************************/int io_TimeElapseHasExpired(){ // *revisit-skranz* not yet implemented // on this platform. return 0;}/****************************** Routine: Description: Note: See io.h for description. TF: This routine should not be in io.h ******************************/int io_AddressIsInFlashSpace(unsigned int addr){ return( btldr_AddressIsInFlashSpace(addr) );}/****************************** Routine: Description:******************************/static void ether_init(){ // *revisit-skranz* to be implemented later.}/****************************** Routine: Description:******************************/static void flash__init(){ // not applicable to this EVM}/****************************** Routine: Description:******************************/static void misc_init(){ // not applicable to this EVM}/****************************** Routine: Description: Note: See io.h for description. ******************************/void io_init(void){ CONSOLE_TYPE = SER; misc_init(); uart_init(); ether_init(); flash__init(); // usb_init();}/****************************** Routine: Description: Note: See io.h for description. ******************************/void io_change_con(new_con){ switch(new_con) { case SER: CONSOLE_TYPE = SER; break; case PAR: CONSOLE_TYPE = PAR; break;#ifdef USE_USB case USB: CONSOLE_TYPE = USB; break;#endif } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -