📄 serial.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>static usart_t *us=USARTB_BASE;#define USART_CLK (CFG_HZ * 128)void serial_setbrg(bd_t *bd, int baudrate) { us->brgr = baudrate ? (USART_CLK + 8 * baudrate)/(16 * baudrate) : 0;};void serial_init(bd_t *bd) { const char *baudrate; if ((baudrate = getenv(bd, "baudrate")) != 0) bd->bi_baudrate = simple_strtoul(baudrate, NULL, 10); serial_setbrg(bd, bd->bi_baudrate); us->cr=( RSTRX | RSTTX ); us->cr=( RXEN | TXEN ); us->mr=( USCLKS_ACLK | CHRL_EIGHT | PAR_NONE | NBSTOP_1 ); us->imr=~0ul;};void serial_putc(const char c) { if(c == '\n') serial_putc('\r'); while( (us->csr & TXRDY) == 0 ); us->thr=c;};int serial_getc() { while( (us->csr & RXRDY) == 0 ); return us->rhr & 0xff;};int serial_tstc(void) { return ((us->csr & RXRDY) == RXRDY);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -