PERFORCE change 94926 for review
Warner Losh
imp at FreeBSD.org
Mon Apr 10 18:07:14 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=94926
Change 94926 by imp at imp_Speedy on 2006/04/10 18:06:39
Migrate towards using more standard interfaces. Use getc/getchar
and putc. This also happens to have a bunch of bytes off the size
of this unit. We're now at 1040 bytes.
Affected files ...
.. //depot/projects/arm/src/sys/arm/conf/KB920X#27 edit
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/Makefile#4 edit
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/at91rm9200_lowlevel.c#4 edit
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/debug_io.c#4 delete
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/debug_io.h#2 delete
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/lib.c#1 add
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/lib.h#1 add
.. //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/xmodem.c#3 edit
Differences ...
==== //depot/projects/arm/src/sys/arm/conf/KB920X#27 (text+ko) ====
==== //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/Makefile#4 (text+ko) ====
@@ -1,5 +1,5 @@
PROG=boot0
-SRCS=arm_init.s at91rm9200_lowlevel.c main.c debug_io.c xmodem.c
+SRCS=arm_init.s at91rm9200_lowlevel.c lib.c main.c xmodem.c
NO_MAN=
LDFLAGS=-e 0 -T linker.cfg
CFLAGS=-O2 -mcpu=arm9 -ffreestanding
==== //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/at91rm9200_lowlevel.c#4 (text+ko) ====
@@ -22,7 +22,6 @@
#include "AT91RM9200.h"
#include "at91rm9200_lowlevel.h"
-#include "debug_io.h"
#define BAUD 115200
==== //depot/projects/arm/src/sys/boot/arm/kb920x/boot0/xmodem.c#3 (text+ko) ====
@@ -1,29 +1,28 @@
-/*******************************************************************************
+/*-
+ * Copyright (c) 2006 M. Warner Losh. All rights reserved.
*
- * Filename: xmodem.c
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * Instantiation of simple x-modem support using debug uart channel.
- *
- * Revision information:
- *
- * 22AUG2004 kb_admin initial creation
- * 24AUG2004 kb_admin optimize for space, not quite as elegant. . .
- *
- * BEGIN_KBDD_BLOCK
- * No warranty, expressed or implied, is included with this software. It is
- * provided "AS IS" and no warranty of any kind including statutory or aspects
- * relating to merchantability or fitness for any purpose is provided. All
- * intellectual property rights of others is maintained with the respective
- * owners. This software is not copyrighted and is intended for reference
- * only.
- * END_BLOCK
- ******************************************************************************/
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
-#include "at91rm9200_lowlevel.h"
-
-/* ****************************** GLOBALS *************************************/
-
-/* ********************* PRIVATE FUNCTIONS/DATA/DEFINES ***********************/
+#include "lib.h"
#define PACKET_SIZE 128
@@ -34,15 +33,6 @@
#define CAN 0x18 /* Cancel */
#define EOT 0x04 /* end of text */
-enum {
- INVALID_STATE = 0,
- WAITING_START,
- WAIT_SOH,
- RX_PACKET,
- RX_EOT,
- SEND_NAK
-};
-
/*
* .KB_C_FN_DEFINITION_START
* int GetRecord(char , char *)
@@ -54,52 +44,48 @@
GetRecord(char blocknum, char *dest)
{
int size;
- char nextChar;
+ int ch;
unsigned chk, j;
chk = 0;
- if (!WaitForChar(&nextChar, 1))
+ if ((ch = getc(1)) == -1)
goto err;
- if (nextChar != blocknum)
+ if (ch != blocknum)
goto err;
- if (!WaitForChar(&nextChar, 1))
+ if ((ch = getc(1)) == -1)
goto err;
- if ((char)nextChar != (char)~blocknum)
+ if (ch != ~blocknum & 0xff)
goto err;
for (size = 0; size < PACKET_SIZE; ++size) {
- if (!WaitForChar(&nextChar, 1))
+ if ((ch = getc(1)) == -1)
goto err;
- chk = chk ^(int)nextChar << 8;
+ chk = chk ^ ch << 8;
for (j = 0; j < 8; ++j) {
if (chk & 0x8000)
chk = chk << 1 ^ 0x1021;
else
chk = chk << 1;
}
- *dest++ = nextChar;
+ *dest++ = ch;
}
chk &= 0xFFFF;
- if ((!WaitForChar(&nextChar, 1)) || (nextChar != ((chk >> 8) & 0xFF)))
+ if (((ch = getc(1)) == -1) || (ch & 0xff != ((chk >> 8) & 0xFF)))
goto err;
- if ((!WaitForChar(&nextChar, 1)) || (nextChar != (chk & 0xFF)))
+ if (((ch = getc(1)) == -1) || (ch & 0xff != (chk & 0xFF)))
goto err;
- DebugPutc(ACK);
+ putc(ACK);
return (1);
err:;
- DebugPutc(NAK);
+ putc(CAN);
// We should allow for resend, but we don't.
return (0);
}
-
-/* ************************** GLOBAL FUNCTIONS ********************************/
-
-
/*
* .KB_C_FN_DEFINITION_START
* int xmodem_rx(char *)
@@ -111,20 +97,19 @@
int
xmodem_rx(char *dest)
{
- int starting;
- char packetNumber, nextChar, *startAddress = dest;
+ int starting, ch;
+ char packetNumber, *startAddress = dest;
packetNumber = 1;
starting = 1;
while (1) {
if (starting)
- DebugPutc('C');
- if (!WaitForChar(&nextChar, 1) ||
- (nextChar != SOH && nextChar != EOT))
+ putc('C');
+ if (((ch = getc(1)) == -1) || (ch != SOH && ch != EOT))
continue;
- if (nextChar == EOT) {
- DebugPutc(ACK);
+ if (ch == EOT) {
+ putc(ACK);
return (dest - startAddress);
}
starting = 0;
More information about the p4-projects
mailing list