⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial.c

📁 ZooBoot
💻 C
字号:
/*
 * (C) Copyright 2002
 * Lineo, Inc <www.lineo.com>
 * Bernhard Kuhn <bkuhn@lineo.com>
 *
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Marius Groeger <mgroeger@sysgo.de>
 *
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Alex Zuepke <azu@sysgo.de>
 *
 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
 *
 * 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 program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <zooboot.h>
#include <hardware.h>
//ggi thunder

usart_t *us   = (usart_t *)DBGU_BASE;
pio_t   *pioa = (pio_t *  )PIOA_BASE;

void serial_setbrg(bd_t *bd, int baudrate) {   
   us->brdiv = baudrate?((ARM_CLK/2/baudrate/16 - 1)*16+0):0;
}

void serial_init(bd_t *bd) {
const char *baudrate;
#ifdef CFG_HAS_DATAFLASH
char baudratestr[8];
dataflash_info_t * df_info;
#endif

	us    = (usart_t *)DBGU_BASE;

  if ((baudrate = getenv(bd, "baudrate")) != 0) {
#ifdef CFG_HAS_DATAFLASH
    if (df_info = addr2dataflash(baudrate)) {
       read_dataflash( df_info, baudrate, sizeof(baudratestr), baudratestr);
       bd->bi_baudrate = simple_strtoul(baudratestr, NULL, 10);
    } 
    else
#endif
    bd->bi_baudrate = simple_strtoul(baudrate, NULL, 10);
  }
  serial_setbrg(bd, bd->bi_baudrate);

  us->lcr=ULCON_WL8;
  us->cr=( UCON_RXM_INTREQ|UCON_TXM_INTREQ | UCON_RXSTAT_INT );
}

void serial_putc(const char c) {
  if(c == '\n') serial_putc('\r');
  while( (us->stat & UART_STAT_TX_COMPLET) == 0 );
  us->txbuf=c;
}

int serial_getc() {
  while( (us->stat & UART_STAT_RCV_READY) == 0 );
  return us->rxbuf & 0xff;
}

int serial_tstc(void) {
  return ((us->stat & UART_STAT_RCV_READY) == UART_STAT_RCV_READY);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -