Update of /cvsroot/blob/blob/src/lib In directory usw-pr-cvs1:/tmp/cvs-serv26965/lib Modified Files: Makefile.am Added Files: command.c error.c help.c icache.c init.c led.c serial.c terminal.c time.c util.c Log Message: Move all files to either blob/ or lib/ --- NEW FILE: command.c --- /*------------------------------------------------------------------------- * Filename: command.c * Version: $Id: command.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * Copyright: Copyright (C) 1999, Erik Mouw * Author: Erik Mouw <J.A...@it...> * Description: Command line functions for blob * Created at: Sun Aug 29 17:23:40 1999 * Modified by: Erik Mouw <J.A...@it...> * Modified at: Sun Oct 3 21:08:27 1999 *-----------------------------------------------------------------------*/ /* * command.c: Command line functions for blob * * Copyright (C) 1999 2000 2001 Erik Mouw (J.A...@it...) * * 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 * */ #ident "$Id: command.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "command.h" #include "errno.h" #include "init.h" #include "serial.h" #include "time.h" #include "types.h" #include "util.h" /* command list start and end. filled in by the linker */ extern u32 __commandlist_start; extern u32 __commandlist_end; /* the first command */ commandlist_t *commands; static void init_commands(void) { commandlist_t *lastcommand; commandlist_t *cmd, *next_cmd; commands = (commandlist_t *) &__commandlist_start; lastcommand = (commandlist_t *) &__commandlist_end; /* make a list */ /* FIXME: should sort the list in alphabetical order over here */ cmd = next_cmd = commands; next_cmd++; while(next_cmd < lastcommand) { cmd->next = next_cmd; cmd++; next_cmd++; } } __initlist(init_commands, INIT_LEVEL_OTHER_STUFF); #define STATE_WHITESPACE (0) #define STATE_WORD (1) void parse_args(char *cmdline, int *argc, char **argv) { char *c; int state = STATE_WHITESPACE; int i; *argc = 0; if(strlen(cmdline) == 0) return; /* convert all tabs into single spaces */ c = cmdline; while(*c != '\0') { if(*c == '\t') *c = ' '; c++; } c = cmdline; i = 0; /* now find all words on the command line */ while(*c != '\0') { if(state == STATE_WHITESPACE) { if(*c != ' ') { argv[i] = c; i++; state = STATE_WORD; } } else { /* state == STATE_WORD */ if(*c == ' ') { *c = '\0'; state = STATE_WHITESPACE; } } c++; } *argc = i; #ifdef BLOB_DEBUG for(i = 0; i < *argc; i++) { printerrprefix(); SerialOutputString("argv["); SerialOutputDec(i); SerialOutputString("] = "); SerialOutputString(argv[i]); SerialOutputByte('\n'); } #endif } int parse_command(char *cmdline) { commandlist_t *cmd; int argc; char *argv[MAX_ARGS]; parse_args(cmdline, &argc, argv); /* only whitespace */ if(argc == 0) return 0; for(cmd = commands; cmd != NULL; cmd = cmd->next) { if(cmd->magic != COMMAND_MAGIC) { #ifdef BLOB_DEBUG printerrprefix(); SerialOutputString("Address = 0x"); SerialOutputHex((u32)cmd); SerialOutputString("!\n"); #endif return -EMAGIC; } if(strcmp(cmd->name, cmdline) == 0) { /* call function */ return cmd->callback(argc, argv); } } return -ECOMMAND; } /* display a prompt, or the standard prompt if prompt == NULL */ void DisplayPrompt(char *prompt) { if(prompt == NULL) { SerialOutputString(PACKAGE "> "); } else { SerialOutputString(prompt); } } /* more or less like SerialInputString(), but with echo and backspace */ int GetCommand(char *command, int len, int timeout) { u32 startTime, currentTime; char c; int i; int numRead; int maxRead = len - 1; TimerClearOverflow(); startTime = TimerGetTime(); for(numRead = 0, i = 0; numRead < maxRead;) { /* try to get a byte from the serial port */ while(!SerialInputByte(&c)) { currentTime = TimerGetTime(); /* check timeout value */ if((currentTime - startTime) > (timeout * TICKS_PER_SECOND)) { /* timeout */ command[i++] = '\0'; return(numRead); } } if((c == '\r') || (c == '\n')) { command[i++] = '\0'; /* print newline */ SerialOutputByte('\n'); return(numRead); } else if(c == '\b') { /* FIXME: is this backspace? */ if(i > 0) { i--; numRead--; /* cursor one position back. */ SerialOutputString("\b \b"); } } else { command[i++] = c; numRead++; /* print character */ SerialOutputByte(c); } } return(numRead); } --- NEW FILE: error.c --- /* * error.c: error handling functions * * Copyright (C) 2001 Erik Mouw (J.A...@it...) * * $Id: error.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * * 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 * */ #ident "$Id: error.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "errno.h" #include "error.h" #include "serial.h" #include "types.h" typedef struct { int errno; char *string; } error_t; static error_t errors[] = { { ENOERROR, "no error" }, { EINVAL, "invalid argument" }, { ENOPARAMS, "not enough parameters" }, { EMAGIC, "magic value failed" }, { ECOMMAND, "invalid command" }, { ENAN, "not a number" }, { EALIGN, "alignment error" }, { ERANGE, "out of range" }, { ETIMEOUT, "timeout exceeded" }, { ETOOSHORT, "short file" }, { ETOOLONG, "long file" }, }; static char *unknown = "unknown error"; static char *errprefix = "*** "; char *strerror(int errnum) { int i; int num = sizeof(errors) / sizeof(error_t); /* make positive if it is negative */ if(errnum < 0) errnum = -errnum; for(i = 0; i < num; i++) if(errors[i].errno == errnum) return errors[i].string; return unknown; } void printerrprefix(void) { SerialOutputString(errprefix); } void printerror(int errnum, char *s) { printerrprefix(); SerialOutputString(strerror(errnum)); if(s != NULL) { SerialOutputString(": "); SerialOutputString(s); } SerialOutputByte('\n'); } --- NEW FILE: help.c --- /* * help.c: Help for commands * * Copyright (C) 2001 Erik Mouw (J.A...@it...) * * $Id: help.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * * 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 * */ #ident "$Id: help.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "command.h" #include "errno.h" #include "error.h" #include "serial.h" #include "util.h" static int help(int argc, char *argv[]) { commandlist_t *cmd; /* help on a command? */ if(argc >= 2) { for(cmd = commands; cmd != NULL; cmd = cmd->next) { if(strcmp(cmd->name, argv[1]) == 0) { SerialOutputString("Help for '"); SerialOutputString(argv[1]); SerialOutputString("':\n\nUsage: "); SerialOutputString(cmd->help); return 0; } } printerror(EINVAL, argv[1]); return 0; } /* generic help */ SerialOutputString("Help for " PACKAGE " " VERSION ", the bootloader\n"); SerialOutputString("The following commands are supported:"); for(cmd = commands; cmd != NULL; cmd = cmd->next) { SerialOutputString("\n* "); SerialOutputString(cmd->name); } SerialOutputString("\nUse \"help command\" to get help on a specific command\n"); return 0; } static char helphelp[] = "help\n" "Get this help\n"; __commandlist(help, "help", helphelp); --- NEW FILE: icache.c --- /* * icache.c: i-cache handling * * Copyright (C) 2001 Russ Dill <Rus...@as...> * * $Id: icache.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * * 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 * */ #ident "$Id: icache.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "init.h" #include "types.h" static void enable_icache(void) { register u32 i; /* read control register */ asm ("mrc p15, 0, %0, c1, c0, 0": "=r" (i)); /* set i-cache */ i |= 0x1000; /* write back to control register */ asm ("mcr p15, 0, %0, c1, c0, 0": : "r" (i)); } static void disable_icache(void) { register u32 i; /* read control register */ asm ("mrc p15, 0, %0, c1, c0, 0": "=r" (i)); /* clear i-cache */ i &= ~0x1000; /* write back to control register */ asm ("mcr p15, 0, %0, c1, c0, 0": : "r" (i)); /* flush i-cache */ asm ("mcr p15, 0, %0, c7, c5, 0": : "r" (i)); } /* init and exit calls */ __initlist(enable_icache, INIT_LEVEL_INITIAL_HARDWARE); __exitlist(disable_icache, INIT_LEVEL_INITIAL_HARDWARE); --- NEW FILE: init.c --- /* * init.c: Support for init and exit lists * * Copyright (C) 2001 Erik Mouw (J.A...@it...) * * $Id: init.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * * 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 * */ #ident "$Id: init.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "errno.h" #include "error.h" #include "init.h" #include "serial.h" #include "types.h" /* int and exit list start and end. filled in by the linker */ extern u32 __initlist_start; extern u32 __initlist_end; extern u32 __exitlist_start; extern u32 __exitlist_end; static void call_funcs(initlist_t *start, initlist_t *end, u32 magic, int level) { initlist_t *item; for(item = start; item != end; item++) { if(item->magic != magic) { printerror(EMAGIC, NULL); #ifdef BLOB_DEBUG printerrprefix(); SerialOutputString("Address = 0x"); SerialOutputHex((u32)item); SerialOutputByte('\n'); #endif return; } if(item->level == level) { /* call function */ item->callback(); } } } void init_subsystems(void) { int i; /* call all subsystem init functions */ for(i = INIT_LEVEL_MIN; i <= INIT_LEVEL_MAX; i++) call_funcs((initlist_t *)&__initlist_start, (initlist_t *)&__initlist_end, INIT_MAGIC, i); } void exit_subsystems(void) { int i; /* call all subsystem exit functions */ for(i = INIT_LEVEL_MAX; i >= INIT_LEVEL_MIN; i--) call_funcs((initlist_t *)&__exitlist_start, (initlist_t *)&__exitlist_end, EXIT_MAGIC, i); } --- NEW FILE: led.c --- /*------------------------------------------------------------------------- * Filename: led.c * Version: $Id: led.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * Copyright: Copyright (C) 1999, Erik Mouw * Author: Erik Mouw <J.A...@it...> * Description: * Created at: Mon Aug 16 15:39:12 1999 * Modified by: Erik Mouw <J.A...@it...> * Modified at: Mon Aug 16 16:55:21 1999 *-----------------------------------------------------------------------*/ /* * led.c: simple LED control functions * * Copyright (C) 1999 2001 Erik Mouw (J.A...@it...) * * 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 * */ /* * All functions assume that the LED is properly initialised by the code * in ledasm.S. * */ #ident "$Id: led.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "led.h" #include "sa1100.h" #include "init.h" static int led_state; void led_on(void) { GPSR = LED_GPIO; led_state = 1; } void led_off(void) { GPCR = LED_GPIO; led_state = 0; } void led_toggle(void) { if(led_state) led_off(); else led_on(); } /* init and exit calls */ __initlist(led_on, INIT_LEVEL_INITIAL_HARDWARE); __exitlist(led_off, INIT_LEVEL_INITIAL_HARDWARE); --- NEW FILE: serial.c --- /*------------------------------------------------------------------------- * Filename: serial.c * Version: $Id: serial.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * Copyright: Copyright (C) 1999, Erik Mouw * Author: Erik Mouw <J.A...@it...> * Description: Serial utilities for blob * Created at: Tue Aug 24 20:25:00 1999 * Modified by: Erik Mouw <J.A...@it...> * Modified at: Mon Oct 4 20:11:14 1999 *-----------------------------------------------------------------------*/ /* * serial.c: Serial utilities for blob * * Copyright (C) 1999 2000 2001 Erik Mouw (J.A...@it...) * * 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 * */ #ident "$Id: serial.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "init.h" #include "led.h" #include "sa1100.h" #include "serial.h" #include "time.h" /* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. * */ void SerialInit(eBauds baudrate) { /* Theory of operations: * - Flush the output buffer * - switch receiver and transmitter off * - clear all sticky bits in control register 3 * - set the port to sensible defaults (no break, no interrupts, * no parity, 8 databits, 1 stopbit, transmitter and receiver * enabled * - set the baudrate to the requested value * - turn the receiver and transmitter back on */ #if defined USE_SERIAL1 /* select UART use for serial port 1 */ Ser1SDCR0 = SDCR0_UART; while(Ser1UTSR1 & UTSR1_TBY) { } Ser1UTCR3 = 0x00; Ser1UTSR0 = 0xff; Ser1UTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData ); Ser1UTCR1 = 0; Ser1UTCR2 = (u32)baudrate; Ser1UTCR3 = ( UTCR3_RXE | UTCR3_TXE ); #elif defined USE_SERIAL3 while(Ser3UTSR1 & UTSR1_TBY) { } Ser3UTCR3 = 0x00; Ser3UTSR0 = 0xff; Ser3UTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData ); Ser3UTCR1 = 0; Ser3UTCR2 = (u32)baudrate; Ser3UTCR3 = ( UTCR3_RXE | UTCR3_TXE ); #else #error "Configuration error: No serial port used at all!" #endif } /* * Output a single byte to the serial port. */ void SerialOutputByte(const char c) { #if defined USE_SERIAL1 /* wait for room in the tx FIFO */ while((Ser1UTSR0 & UTSR0_TFS) == 0) ; Ser1UTDR = c; #elif defined USE_SERIAL3 /* wait for room in the tx FIFO */ while((Ser3UTSR0 & UTSR0_TFS) == 0) ; Ser3UTDR = c; #else #error "Configuration error: No serial port used at all!" #endif /* If \n, also do \r */ if(c == '\n') SerialOutputByte('\r'); } /* * Write a null terminated string to the serial port. */ void SerialOutputString(const char *s) { while(*s != 0) SerialOutputByte(*s++); } /* SerialOutputString */ /* * Write the argument of the function in hexadecimal to the serial * port. If you want "0x" in front of it, you'll have to add it * yourself. */ void SerialOutputHex(const u32 h) { char c; int i; for(i = NIBBLES_PER_WORD - 1; i >= 0; i--) { c = (char)((h >> (i * 4)) & 0x0f); if(c > 9) c += ('a' - 10); else c += '0'; SerialOutputByte(c); } } /* * Write the argument of the function in decimal to the serial port. * We just assume that each argument is positive (i.e. unsigned). */ void SerialOutputDec(const u32 d) { int leading_zero = 1; u32 divisor, result, remainder; remainder = d; for(divisor = 1000000000; divisor > 0; divisor /= 10) { result = remainder / divisor; remainder %= divisor; if(result != 0 || divisor == 1) leading_zero = 0; if(leading_zero == 0) SerialOutputByte((char)(result) + '0'); } } /* * Write a block of data to the serial port. Similar to * SerialOutputString(), but this function just writes the number of * characters indicated by bufsize and doesn't look at termination * characters. */ void SerialOutputBlock(const char *buf, int bufsize) { while(bufsize--) SerialOutputByte(*buf++); } /* * Read a single byte from the serial port. Returns 1 on success, 0 * otherwise. When the function is succesfull, the character read is * written into its argument c. */ int SerialInputByte(char *c) { #if defined USE_SERIAL1 if(Ser1UTSR1 & UTSR1_RNE) { int err = Ser1UTSR1 & (UTSR1_PRE | UTSR1_FRE | UTSR1_ROR); *c = (char)Ser1UTDR; #elif defined USE_SERIAL3 if(Ser3UTSR1 & UTSR1_RNE) { int err = Ser3UTSR1 & (UTSR1_PRE | UTSR1_FRE | UTSR1_ROR); *c = (char)Ser3UTDR; #else #error "Configuration error: No serial port at all" #endif /* If you're lucky, you should be able to use this as * debug information ;-) -- Erik */ if(err & UTSR1_PRE) SerialOutputByte('@'); else if(err & UTSR1_FRE) SerialOutputByte('#'); else if(err & UTSR1_ROR) SerialOutputByte('$'); /* We currently only care about framing and parity errors */ if((err & (UTSR1_PRE | UTSR1_FRE)) != 0) { return SerialInputByte(c); } else { led_toggle(); return(1); } } else { /* no bit ready */ return(0); } } /* SerialInputByte */ /* * read a string with maximum length len from the serial port * using a timeout of timeout seconds * * len is the length of array s _including_ the trailing zero, * the function returns the number of bytes read _excluding_ * the trailing zero */ int SerialInputString(char *s, const int len, const int timeout) { u32 startTime, currentTime; char c; int i; int numRead; int skipNewline = 1; int maxRead = len - 1; startTime = TimerGetTime(); for(numRead = 0, i = 0; numRead < maxRead;) { /* try to get a byte from the serial port */ while(!SerialInputByte(&c)) { currentTime = TimerGetTime(); /* check timeout value */ if((currentTime - startTime) > (timeout * TICKS_PER_SECOND)) { /* timeout */ s[i++] = '\0'; return(numRead); } } /* eat newline characters at start of string */ if((skipNewline == 1) && (c != '\r') && (c != '\n')) skipNewline = 0; if(skipNewline == 0) { if((c == '\r') || (c == '\n')) { s[i++] = '\0'; return(numRead); } else { s[i++] = c; numRead++; } } } return(numRead); } /* * SerialInputBlock(): almost the same as SerialInputString(), but * this one just reads a block of characters without looking at * special characters. */ int SerialInputBlock(char *buf, int bufsize, const int timeout) { u32 startTime, currentTime; char c; int i; int numRead; int maxRead = bufsize; startTime = TimerGetTime(); for(numRead = 0, i = 0; numRead < maxRead;) { /* try to get a byte from the serial port */ while(!SerialInputByte(&c)) { currentTime = TimerGetTime(); /* check timeout value */ if((currentTime - startTime) > (timeout * TICKS_PER_SECOND)) { /* timeout! */ return(numRead); } } buf[i++] = c; numRead ++; } return(numRead); } /* default initialisation */ static void serial_default_init(void) { SerialInit(baud9k6); } __initlist(serial_default_init, INIT_LEVEL_INITIAL_HARDWARE); --- NEW FILE: terminal.c --- /* * terminal.c: terminal reset functions * * Copyright (C) 1999 2000 2001 Erik Mouw (J.A...@it...) * * $Id: terminal.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * * 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 * */ #ident "$Id: terminal.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "command.h" #include "main.h" #include "serial.h" static int reset_terminal(int argc, char *argv[]) { int i; SerialInit(blob_status.terminalSpeed); SerialOutputString(" c"); for(i = 0; i < 100; i++) SerialOutputByte('\n'); SerialOutputString("c"); return 0; } static char resethelp[] = "reset\n" "Reset terminal\n"; __commandlist(reset_terminal, "reset", resethelp); --- NEW FILE: time.c --- /*------------------------------------------------------------------------- * Filename: time.c * Version: $Id: time.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * Copyright: Copyright (C) 1999, Erik Mouw * Author: Erik Mouw <J.A...@it...> * Description: Some easy timer functions for blob * Created at: Tue Aug 24 21:08:25 1999 * Modified by: Erik Mouw <J.A...@it...> * Modified at: Sun Oct 3 21:10:21 1999 *-----------------------------------------------------------------------*/ /* * timer.c: Timer functions for blob * * Copyright (C) 1999 2000 2001 Erik Mouw (J.A...@it...) * * 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 * */ #ident "$Id: time.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "init.h" #include "led.h" #include "sa1100.h" #include "time.h" static int numOverflows; static void TimerInit(void) { /* clear counter */ OSCR = 0; /* we don't want to be interrupted */ OIER = 0; /* wait until OSCR > 0 */ while(OSCR == 0) ; /* clear match register 0 */ OSMR0 = 0; /* clear match bit for OSMR0 */ OSSR = OSSR_M0; numOverflows = 0; } __initlist(TimerInit, INIT_LEVEL_OTHER_HARDWARE); /* returns the time in 1/TICKS_PER_SECOND seconds */ u32 TimerGetTime(void) { /* turn LED always on after one second so the user knows that * the board is on */ if((OSCR % TICKS_PER_SECOND) < (TICKS_PER_SECOND >>7)) led_on(); return((u32) OSCR); } int TimerDetectOverflow(void) { return(OSSR & OSSR_M0); } void TimerClearOverflow(void) { if(TimerDetectOverflow()) numOverflows++; OSSR = OSSR_M0; } void msleep(unsigned int msec) { u32 ticks, start, end; int will_overflow = 0; int has_overflow = 0; int reached = 0; if(msec == 0) return; ticks = (TICKS_PER_SECOND * msec) / 1000; start = TimerGetTime(); /* this could overflow, but it nicely wraps around which is * exactly what we want */ end = start + ticks; /* detect the overflow */ if(end < start) { TimerClearOverflow(); will_overflow = 1; } do { if(will_overflow && !has_overflow) { if(TimerDetectOverflow()) has_overflow = 1; continue; } if(TimerGetTime() >= end) reached = 1; } while(!reached); } --- NEW FILE: util.c --- /*------------------------------------------------------------------------- * Filename: util.c * Version: $Id: util.c,v 1.1 2001/10/07 19:04:25 erikm Exp $ * Copyright: Copyright (C) 1999, Jan-Derk Bakker * Author: Jan-Derk Bakker <J.D...@it...> * Description: Simple utility functions for blob * Created at: Wed Aug 25 21:00:00 1999 * Modified by: Erik Mouw <J.A...@it...> * Modified at: Sun Oct 3 21:10:43 1999 *-----------------------------------------------------------------------*/ /* * util.c: Simple utility functions for blob * * Copyright (C) 1999 Jan-Derk Bakker (J.D...@it...) * * 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 * */ #ident "$Id: util.c,v 1.1 2001/10/07 19:04:25 erikm Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "types.h" #include "util.h" #include "serial.h" void MyMemCpy(u32 *dest, const u32 *src, int numWords) { #ifdef BLOB_DEBUG SerialOutputString("\n### Now copying 0x"); SerialOutputHex(numWords); SerialOutputString(" words from 0x"); SerialOutputHex((int)src); SerialOutputString(" to 0x"); SerialOutputHex((int)dest); SerialOutputByte('\n'); #endif while(numWords--) { if((numWords & 0xffff) == 0x0) SerialOutputByte('.'); *dest++ = *src++; } #ifdef BLOB_DEBUG SerialOutputString(" done\n"); #endif } /* MyMemCpy */ void MyMemCpyChar(char *dest, const char *src, int numBytes) { char *destLim = dest + numBytes; while(dest < destLim) *dest++ = *src++; } /* MyMemCpyChar */ void MyMemSet(u32 *dest, const u32 wordToWrite, int numWords) { u32 *limit = dest + numWords; while(dest < limit) *dest++ = wordToWrite; } /* MyMemSet */ int strncmp(const char *s1, const char *s2, int maxlen) { int i; for(i = 0; i < maxlen; i++) { if(s1[i] != s2[i]) return ((int) s1[i]) - ((int) s2[i]); if(s1[i] == 0) return 0; } return 0; } int strlen(const char *s) { int i = 0; for(;*s != '\0'; s++) i++; return i; } char *strcpy(char *dest, const char *src) { while(*src != '\0') *dest++ = *src++; *dest = '\0'; return dest; } /* test for a digit. return value if digit or -1 otherwise */ static int digitvalue(char isdigit) { if (isdigit >= '0' && isdigit <= '9' ) return isdigit - '0'; else return -1; } /* test for a hexidecimal digit. return value if digit or -1 otherwise */ static int xdigitvalue(char isdigit) { if (isdigit >= '0' && isdigit <= '9' ) return isdigit - '0'; if (isdigit >= 'a' && isdigit <= 'f') return 10 + isdigit - 'a'; return -1; } /* convert a string to an u32 value. if the string starts with 0x, it * is a hexidecimal string, otherwise we treat is as decimal. returns * the converted value on success, or -1 on failure. no, we don't care * about overflows if the string is too long. */ int strtoval(const char *str, u32 *value) { int i; *value = 0; if(strncmp(str, "0x", 2) == 0) { /* hexadecimal mode */ str += 2; while(*str != '\0') { if((i = xdigitvalue(*str)) < 0) return -1; *value = (*value << 4) | (u32)i; str++; } } else { /* decimal mode */ while(*str != '\0') { if((i = digitvalue(*str)) < 0) return -1; *value = (*value * 10) + (u32)i; str++; } } return 0; } Index: Makefile.am =================================================================== RCS file: /cvsroot/blob/blob/src/lib/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.am 2001/10/07 15:07:13 1.1 +++ Makefile.am 2001/10/07 19:04:25 1.2 @@ -0,0 +1,50 @@ +# -*- makefile -*- +# +# Makefile.am +# +# Copyright (C) 2001 Erik Mouw (J.A...@it...) +# +# $Id$ +# +# 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 +# + +noinst_LIBRARIES = \ + libblob.a + + +libblob_a_SOURCES = \ + command.c \ + error.c \ + help.c \ + icache.c \ + init.c \ + led.c \ + serial.c \ + terminal.c \ + time.c \ + util.c + + +INCLUDES += \ + -I${top_builddir}/include \ + -I${top_srcdir}/include + + + +CLEANFILES = ${srcdir}/*~ + + +DISTCLEANFILES = ${builddir}/.deps/*.P |