common.c revision 1.4
11.4Smatt/* $Id: common.c,v 1.4 2013/10/07 17:36:40 matt Exp $ */ 21.1Sjkunz 31.1Sjkunz/* 41.1Sjkunz * Copyright (c) 2012 The NetBSD Foundation, Inc. 51.1Sjkunz * All rights reserved. 61.1Sjkunz * 71.1Sjkunz * This code is derived from software contributed to The NetBSD Foundation 81.1Sjkunz * by Petri Laakso. 91.1Sjkunz * 101.1Sjkunz * Redistribution and use in source and binary forms, with or without 111.1Sjkunz * modification, are permitted provided that the following conditions 121.1Sjkunz * are met: 131.1Sjkunz * 1. Redistributions of source code must retain the above copyright 141.1Sjkunz * notice, this list of conditions and the following disclaimer. 151.1Sjkunz * 2. Redistributions in binary form must reproduce the above copyright 161.1Sjkunz * notice, this list of conditions and the following disclaimer in the 171.1Sjkunz * documentation and/or other materials provided with the distribution. 181.1Sjkunz * 191.1Sjkunz * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sjkunz * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sjkunz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sjkunz * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sjkunz * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sjkunz * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sjkunz * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sjkunz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sjkunz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sjkunz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sjkunz * POSSIBILITY OF SUCH DAMAGE. 301.1Sjkunz */ 311.1Sjkunz 321.1Sjkunz#include <sys/param.h> 331.2Sjkunz#include <sys/types.h> 341.1Sjkunz#include <sys/cdefs.h> 351.1Sjkunz 361.4Smatt#include <lib/libsa/stand.h> 371.4Smatt 381.1Sjkunz#include <arm/imx/imx23_digctlreg.h> 391.1Sjkunz#include <arm/imx/imx23_uartdbgreg.h> 401.1Sjkunz 411.1Sjkunz#include "common.h" 421.1Sjkunz 431.1Sjkunz/* 441.2Sjkunz * Delay us microseconds. 451.1Sjkunz */ 461.1Sjkunzvoid 471.2Sjkunzdelay(unsigned int us) 481.1Sjkunz{ 491.4Smatt volatile uint32_t *us_r; 501.1Sjkunz 511.4Smatt us_r = (uint32_t *)(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS); 521.1Sjkunz 531.4Smatt *us_r = 0; 541.4Smatt while (*us_r < us) 551.4Smatt ; 561.1Sjkunz 571.4Smatt return; 581.1Sjkunz} 591.1Sjkunz 601.1Sjkunz/* 611.4Smatt * Write character c to debug UART. 621.1Sjkunz */ 631.1Sjkunzvoid 641.4Smattputchar(int c) 651.1Sjkunz{ 661.4Smatt volatile uint8_t *fr_r, *dr_r; 671.4Smatt 681.4Smatt fr_r = (uint8_t *)(HW_UARTDBG_BASE + HW_UARTDBGFR); 691.4Smatt dr_r = (uint8_t *)(HW_UARTDBG_BASE + HW_UARTDBGDR); 701.1Sjkunz 711.4Smatt /* Wait until transmit FIFO has space for the new character. */ 721.4Smatt while (*fr_r & HW_UARTDBGFR_TXFF) 731.4Smatt ; 741.4Smatt 751.4Smatt *dr_r = c; 761.4Smatt#ifdef DIAGNOSTIC 771.1Sjkunz 781.2Sjkunz /* Flush: Wait until transmit FIFO contents are written to UART. */ 791.4Smatt while (!(*fr_r & HW_UARTDBGFR_TXFE)) 801.4Smatt ; 811.2Sjkunz#endif 821.1Sjkunz 831.1Sjkunz return; 841.1Sjkunz} 851.3Sjkunz 861.3Sjkunz/* 871.3Sjkunz * Read character from debug UART. 881.3Sjkunz */ 891.3Sjkunzint 901.3Sjkunzgetchar(void) 911.3Sjkunz{ 921.4Smatt volatile uint8_t *fr_r, *dr_r; 931.4Smatt 941.4Smatt fr_r = (uint8_t *)(HW_UARTDBG_BASE + HW_UARTDBGFR); 951.4Smatt dr_r = (uint8_t *)(HW_UARTDBG_BASE + HW_UARTDBGDR); 961.3Sjkunz 971.3Sjkunz /* Wait until receive FIFO has character(s) */ 981.4Smatt while (*fr_r & HW_UARTDBGFR_RXFE) 991.4Smatt ; 1001.3Sjkunz 1011.4Smatt return *dr_r; 1021.4Smatt} 1031.4Smatt 1041.4Smattvoid 1051.4Smattvpanic(const char *fmt, va_list ap) 1061.4Smatt{ 1071.4Smatt printf(fmt, ap); 1081.4Smatt for(;;); 1091.3Sjkunz 1101.4Smatt /* NOTREACHED */ 1111.3Sjkunz} 112