|
From: Erik M. <er...@us...> - 2001-09-18 19:55:32
|
Update of /cvsroot/blob/blob/src
In directory usw-pr-cvs1:/tmp/cvs-serv15081/src
Modified Files:
Makefile.am clock.c main.c
Log Message:
This patch really shows the elegancy of the new command line system:
clock.c is conditionally compiled and it doesn't need any #ifdef in the
rest of the code.
The changes:
- make clock.c compile conditionally
- get rid of clock.h, it's no longer needed
- cleanup the codestyle in clock.c
- large cleanup in clock.c getting rid of MyIsXDigit()
- remove Johan from the startup messages, his code is now conditionally
Index: Makefile.am
===================================================================
RCS file: /cvsroot/blob/blob/src/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile.am 2001/08/31 06:26:59 1.3
+++ Makefile.am 2001/09/18 19:55:29 1.4
@@ -46,11 +46,12 @@
# Now specify how to build the second stage loader
+# WARNING: trampoline.S *must* be the first file, otherwise the target
+# will be linked in the wrong order!
blob_rest_elf32_SOURCES = \
trampoline.S \
flashasm.S \
testmem2.S \
- clock.c \
command.c \
flash.c \
led.c \
@@ -63,12 +64,19 @@
util.c \
uucodec.c
+# conditionally compiled sources
+EXTRA_blob_rest_elf32_SOURCES = \
+ clock.c
+blob_rest_elf32_DEPENDENCIES = \
+ @CLOCK@
+
blob_rest_elf32_LDFLAGS += \
-Wl,-T,${top_srcdir}/src/rest-ld-script
blob_rest_elf32_LDADD += \
+ @CLOCK@ \
-lgcc
Index: clock.c
===================================================================
RCS file: /cvsroot/blob/blob/src/clock.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- clock.c 2001/09/16 15:44:00 1.3
+++ clock.c 2001/09/18 19:55:29 1.4
@@ -35,6 +35,7 @@
# include "config.h"
#endif
+#include "command.h"
#include "types.h"
#include "sa1100.h"
#include "serial.h"
@@ -42,11 +43,6 @@
#include "util.h"
-/* It should be possible to improve this function */
-/* Determine if the given character is a 0 to 9 or a to z,
- these characters can be converted to a hexidecimal number
-*/
-
/* Struct with the SA-1100 PLL + DRAM parameter registers */
enum {
SA_PPCR,
@@ -57,104 +53,80 @@
};
-int MyIsXDigit(char isdigit) {
- if ((isdigit >= '0' && isdigit <= '9' ) ||
- (isdigit >= 'a' && isdigit <= 'f'))
- return 1;
- else
- return 0;
-} /* MyIsXDigit */
-
-int MyXDigitValue(char isdigit) {
- if (isdigit >= '0' && isdigit <= '9' )
- return isdigit - '0';
- if (isdigit >= 'a' && isdigit <= 'f')
- return 10 + isdigit - 'a';
- return -1;
+static int MyXDigitValue(char isdigit)
+{
+ if (isdigit >= '0' && isdigit <= '9' )
+ return isdigit - '0';
+ if (isdigit >= 'a' && isdigit <= 'f')
+ return 10 + isdigit - 'a';
+ return -1;
} /* MyXDigitValue */
-/* Converts 8 characters 0-9a-f into a 4 byte hexadecimal value */
-char *GetHexValue(char *commandline,u32 *value) {
- int i;
-
- if(commandline[0] == '\0') {
- SerialOutputString(__FUNCTION__ ": zero length string\n");
- return(NULL);
- }
-
- *value=0x00;
- if (strncmp(commandline, " 0x", 3) == 0) {
- commandline += 3;
- } else if(commandline[0] == ' ') {
- commandline += 1;
- } else {
- SerialOutputString(__FUNCTION__ ":value not hexdecimal\n");
- return NULL;
- }
-
- SerialOutputString("char: ");
- SerialOutputString(commandline);
- SerialOutputByte(' ');
-
- for (i=0; i<8;i++) {
- if (*commandline == '\0') {
- SerialOutputString(__FUNCTION__ ":hex value not 32 bits\n");
- return NULL;
- } else {
- if (MyIsXDigit(*commandline) == 0) {
- SerialOutputString("hex value contains invalid characters\n");
- return NULL;
- } else {
- *value |= (u32) MyXDigitValue(*commandline) << ((7-i)*4);
- }
- }
-
- commandline++;
- }
-
- SerialOutputString("hex 0x");
- SerialOutputHex(*value);
- SerialOutputByte('\r');
- return commandline;
+/* Converts hex string into value. no, we don't care if the string is
+ too long */
+static int GetHexValue(char *str, u32 *value)
+{
+ int i;
+
+ /* skip any leading 0x */
+ if(strncmp(str, "0x", 2) == 0)
+ str += 2;
+
+ *value=0x00;
+
+ while(*str != '\0') {
+ if((i = MyXDigitValue(*str)) < 0)
+ return -1;
+
+ *value = *value << 4 | i;
+ }
+
+ return 0;
} /* GetHexValue */
+
-void SetClock(char *commandline) {
-int i;
-u32 regs[5];
-u32 startTime, currentTime;
-
- for(i = 0; i < 5; i++) {
- commandline = GetHexValue(commandline, ®s[i]);
-
-#warning "FIXME: GetHexValue() returns NULL after the fifth call..."
-
- if((commandline == NULL) && (i != 4)) {
- SerialOutputString(__FUNCTION__ ": can't get hex values\n");
- return;
- }
- }
-
-#if 0
- printf (" write %lx to %x \n",regs[SA_PPCR], _PPCR);
- printf (" write %lx to %x \n",regs[SA_MDCNFG], _MDCNFG);
- printf (" write %lx to %x \n",regs[SA_MDCAS0], _MDCAS0);
- printf (" write %lx to %x \n",regs[SA_MDCAS1], _MDCAS1);
- printf (" write %lx to %x \n",regs[SA_MDCAS2], _MDCAS2);
-#endif
- /* we go slower, so first set PLL register */
- PPCR = regs[SA_PPCR];
- MDCNFG = regs[SA_MDCNFG];
- MDCAS0 = regs[SA_MDCAS0];
- MDCAS1 = regs[SA_MDCAS1];
- MDCAS2 = regs[SA_MDCAS2];
-
- /* sleep for a second */
- startTime = TimerGetTime();
-
- for(;;) {
- currentTime = TimerGetTime();
- if((currentTime - startTime) > (u32)TICKS_PER_SECOND)
- return;
- }
+int SetClock(int argc, char *argv[])
+{
+ int i;
+ u32 regs[5];
+ u32 startTime, currentTime;
+
+ if(argc < 6) {
+ /* FIXME: command loop should print error messages */
+ SerialOutputString("*** not enough arguments\n");
+ return 0;
+ }
+
+ for(i = 0; i < 5; i++) {
+ if(GetHexValue(argv[i + 1], ®s[i]) < 0) {
+ SerialOutputString("*** not a hexidecimal number: ");
+ SerialOutputString(argv[i + 1]);
+ SerialOutputByte('\n');
+ return 0;
+ }
+ }
+
+ /* we go slower, so first set PLL register */
+ PPCR = regs[SA_PPCR];
+ MDCNFG = regs[SA_MDCNFG];
+ MDCAS0 = regs[SA_MDCAS0];
+ MDCAS1 = regs[SA_MDCAS1];
+ MDCAS2 = regs[SA_MDCAS2];
+
+ /* sleep for a second */
+ startTime = TimerGetTime();
+
+ for(;;) {
+ currentTime = TimerGetTime();
+ if((currentTime - startTime) > (u32)TICKS_PER_SECOND)
+ return 0;
+ }
} /* SetClock */
+
+
+static char clockhelp[] = "clock PPCR MDCNFG MDCAS0 MDCAS1 MDCAS2\n"
+"Set the SA1100 core clock and DRAM timings\n"
+"WARNING: dangerous command!\n";
+
+__commandlist(SetClock, "clock", clockhelp);
Index: main.c
===================================================================
RCS file: /cvsroot/blob/blob/src/main.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- main.c 2001/09/17 00:05:31 1.11
+++ main.c 2001/09/18 19:55:29 1.12
@@ -38,7 +38,6 @@
# include "config.h"
#endif
-#include "clock.h"
#include "command.h"
#include "flash.h"
#include "led.h"
@@ -109,9 +108,7 @@
SerialOutputString("\nConsider yourself LARTed!\n\n");
SerialOutputString(PACKAGE " version " VERSION "\n"
"Copyright (C) 1999 2000 2001 "
- "Jan-Derk Bakker and Erik Mouw\n"
- "Copyright (C) 2000 "
- "Johan Pouwelse\n");
+ "Jan-Derk Bakker and Erik Mouw\n");
SerialOutputString(PACKAGE " comes with ABSOLUTELY NO WARRANTY; "
"read the GNU GPL for details.\n");
SerialOutputString("This is free software, and you are welcome "
@@ -176,9 +173,7 @@
numRead = GetCommand(commandline, MAX_COMMANDLINE_LENGTH, 600);
if(numRead > 0) {
- if(strncmp(commandline, "clock", 5) == 0) {
- SetClock(commandline + 5);
- } else if(strncmp(commandline, "download ", 9) == 0) {
+ if(strncmp(commandline, "download ", 9) == 0) {
Download(commandline + 9);
} else if(strncmp(commandline, "flash ", 6) == 0) {
Flash(commandline + 6);
@@ -363,9 +358,6 @@
static int PrintHelp(int argc, char *argv[])
{
#if 0
- SerialOutputString("* clock PPCR MDCNFG MDCAS0 MDCAS1 MDCAS2\n");
- SerialOutputString(" Set the SA1100 core clock and DRAM timings\n");
- SerialOutputString(" (WARNING: dangerous command!)\n");
SerialOutputString("* download {blob|param|kernel|ramdisk} Download <argument> image to RAM\n");
SerialOutputString("* flash {blob|param|kernel|ramdisk} Copy <argument> from RAM to flash\n");
#endif
|