projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Attempt to fix the BeRTOS Wizard running directory-related issue.
[bertos.git]
/
bertos
/
net
/
xmodem.c
diff --git
a/bertos/net/xmodem.c
b/bertos/net/xmodem.c
index d6653a49d6c37d635a87af142685063599e20e23..35da28366b921c8b559571170c89bbf89f8eeb03 100644
(file)
--- a/
bertos/net/xmodem.c
+++ b/
bertos/net/xmodem.c
@@
-27,9
+27,10
@@
* the GNU General Public License.
*
* Copyright 2004, 2005, 2006, 2007 Develer S.r.l. (http://www.develer.com/)
* the GNU General Public License.
*
* Copyright 2004, 2005, 2006, 2007 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999, 2001 Bern
ardo Innocenti <bernie@develer.com
>
+ * Copyright 1999, 2001 Bern
ie Innocenti <bernie@codewiz.org
>
*
* -->
*
* -->
+ *
* \brief X-Modem serial transmission protocol (implementation)
*
* Supports the CRC-16 and 1K-blocks variants of the standard.
* \brief X-Modem serial transmission protocol (implementation)
*
* Supports the CRC-16 and 1K-blocks variants of the standard.
@@
-38,21
+39,20
@@
* \todo Break xmodem_send() and xmodem_recv() in smaller functions.
*
* \version $Id$
* \todo Break xmodem_send() and xmodem_recv() in smaller functions.
*
* \version $Id$
- * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \author Bernie Innocenti <bernie@codewiz.org>
* \author Francesco Sacchi <batt@develer.com>
*/
#include "xmodem.h"
* \author Francesco Sacchi <batt@develer.com>
*/
#include "xmodem.h"
-#include <appconfig.h>
-#include <string.h> /* for memset() */
-#include <drv/ser.h>
-#include <algo/crc.h>
+#include "cfg/cfg_xmodem.h"
#include <cfg/debug.h>
#include <cfg/debug.h>
+#include <algo/crc.h>
-
+#include <string.h> /* for memset() */
/**
* \name Protocol control codes
/**
* \name Protocol control codes
@@
-67,9
+67,6
@@
#define XM_CAN 0x18 /**< CANcel transmission */
/*\}*/
#define XM_CAN 0x18 /**< CANcel transmission */
/*\}*/
-#define XM_MAXRETRIES 15 /**< Max retries before giving up */
-#define XM_MAXCRCRETRIES 7 /**< Max retries before switching to BCC */
-
#if CONFIG_XMODEM_1KCRC == 1
#define XM_BUFSIZE 1024 /**< 1024 bytes of block buffer */
#else
#if CONFIG_XMODEM_1KCRC == 1
#define XM_BUFSIZE 1024 /**< 1024 bytes of block buffer */
#else
@@
-81,12
+78,12
@@
/**
* \brief Receive a file using the XModem protocol.
*
/**
* \brief Receive a file using the XModem protocol.
*
- * \param
port Serial port
to use for transfer
+ * \param
ch Channel
to use for transfer
* \param fd Destination file
*
* \note This function allocates a large amount of stack (\see XM_BUFSIZE).
*/
* \param fd Destination file
*
* \note This function allocates a large amount of stack (\see XM_BUFSIZE).
*/
-bool xmodem_recv(
struct KFileSerial *port
, KFile *fd)
+bool xmodem_recv(
KFile *ch
, KFile *fd)
{
char block_buffer[XM_BUFSIZE]; /* Buffer to hold a block of data */
int c, i, blocksize;
{
char block_buffer[XM_BUFSIZE]; /* Buffer to hold a block of data */
int c, i, blocksize;
@@
-100,15
+97,15
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
XMODEM_PROGRESS("Starting Transfer...\n");
purge = true;
XMODEM_PROGRESS("Starting Transfer...\n");
purge = true;
-
ser_clearerr(port
);
+
kfile_clearerr(ch
);
/* Send initial NAK to start transmission */
for(;;)
{
if (XMODEM_CHECK_ABORT)
{
/* Send initial NAK to start transmission */
for(;;)
{
if (XMODEM_CHECK_ABORT)
{
- kfile_putc(XM_CAN,
&port->fd
);
- kfile_putc(XM_CAN,
&port->fd
);
+ kfile_putc(XM_CAN,
ch
);
+ kfile_putc(XM_CAN,
ch
);
XMODEM_PROGRESS("Transfer aborted\n");
return false;
}
XMODEM_PROGRESS("Transfer aborted\n");
return false;
}
@@
-121,16
+118,16
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
{
purge = false;
{
purge = false;
- if (kfile_error(
&port->fd
))
+ if (kfile_error(
ch
))
XMODEM_PROGRESS("Retries %d\n", retries);
XMODEM_PROGRESS("Retries %d\n", retries);
-
ser_resync(port
, 200);
+
kfile_resync(ch
, 200);
retries++;
retries++;
- if (retries >=
X
M_MAXRETRIES)
+ if (retries >=
CONFIG_XMODE
M_MAXRETRIES)
{
{
- kfile_putc(XM_CAN,
&port->fd
);
- kfile_putc(XM_CAN,
&port->fd
);
+ kfile_putc(XM_CAN,
ch
);
+ kfile_putc(XM_CAN,
ch
);
XMODEM_PROGRESS("Transfer aborted\n");
return false;
}
XMODEM_PROGRESS("Transfer aborted\n");
return false;
}
@@
-138,24
+135,24
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
/* Transmission start? */
if (blocknr == 0)
{
/* Transmission start? */
if (blocknr == 0)
{
- if (retries <
X
M_MAXCRCRETRIES)
+ if (retries <
CONFIG_XMODE
M_MAXCRCRETRIES)
{
XMODEM_PROGRESS("Request Tx (CRC)\n");
{
XMODEM_PROGRESS("Request Tx (CRC)\n");
- kfile_putc(XM_C,
&port->fd
);
+ kfile_putc(XM_C,
ch
);
}
else
{
/* Give up with CRC and fall back to checksum */
usecrc = false;
XMODEM_PROGRESS("Request Tx (BCC)\n");
}
else
{
/* Give up with CRC and fall back to checksum */
usecrc = false;
XMODEM_PROGRESS("Request Tx (BCC)\n");
- kfile_putc(XM_NAK,
&port->fd
);
+ kfile_putc(XM_NAK,
ch
);
}
}
else
}
}
else
- kfile_putc(XM_NAK,
&port->fd
);
+ kfile_putc(XM_NAK,
ch
);
}
}
- switch (kfile_getc(
&port->fd
))
+ switch (kfile_getc(
ch
))
{
#if XM_BUFSIZE >= 1024
case XM_STX: /* Start of header (1024-byte block) */
{
#if XM_BUFSIZE >= 1024
case XM_STX: /* Start of header (1024-byte block) */
@@
-169,10
+166,10
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
getblock:
/* Get block number */
getblock:
/* Get block number */
- c = kfile_getc(
&port->fd
);
+ c = kfile_getc(
ch
);
/* Check complemented block number */
/* Check complemented block number */
- if ((~c & 0xff) != kfile_getc(
&port->fd
))
+ if ((~c & 0xff) != kfile_getc(
ch
))
{
XMODEM_PROGRESS("Bad blk (%d)\n", c);
purge = true;
{
XMODEM_PROGRESS("Bad blk (%d)\n", c);
purge = true;
@@
-199,7
+196,7
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
crc = 0;
for (i = 0; i < blocksize; i++)
{
crc = 0;
for (i = 0; i < blocksize; i++)
{
- if ((c = kfile_getc(
&port->fd
)) == EOF)
+ if ((c = kfile_getc(
ch
)) == EOF)
{
purge = true;
break;
{
purge = true;
break;
@@
-219,7
+216,7
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
break;
/* Get the checksum byte or the CRC-16 MSB */
break;
/* Get the checksum byte or the CRC-16 MSB */
- if ((c = kfile_getc(
&port->fd
)) == EOF)
+ if ((c = kfile_getc(
ch
)) == EOF)
{
purge = true;
break;
{
purge = true;
break;
@@
-230,7
+227,7
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
crc = UPDCRC16(c, crc);
/* Get CRC-16 LSB */
crc = UPDCRC16(c, crc);
/* Get CRC-16 LSB */
- if ((c = kfile_getc(
&port->fd
)) == EOF)
+ if ((c = kfile_getc(
ch
)) == EOF)
{
purge = true;
break;
{
purge = true;
break;
@@
-264,21
+261,21
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
if (kfile_write(fd, block_buffer, blocksize))
{
/* Acknowledge block and clear error counter */
if (kfile_write(fd, block_buffer, blocksize))
{
/* Acknowledge block and clear error counter */
- kfile_putc(XM_ACK,
&port->fd
);
+ kfile_putc(XM_ACK,
ch
);
retries = 0;
last_block_done = blocknr;
}
else
{
/* User callback failed: abort transfer immediately */
retries = 0;
last_block_done = blocknr;
}
else
{
/* User callback failed: abort transfer immediately */
- retries =
X
M_MAXRETRIES;
+ retries =
CONFIG_XMODE
M_MAXRETRIES;
purge = true;
}
}
break;
case XM_EOT: /* End of transmission */
purge = true;
}
}
break;
case XM_EOT: /* End of transmission */
- kfile_putc
har(XM_ACK, &port->fd
);
+ kfile_putc
(XM_ACK, ch
);
XMODEM_PROGRESS("Transfer completed\n");
return true;
XMODEM_PROGRESS("Transfer completed\n");
return true;
@@
-300,13
+297,13
@@
bool xmodem_recv(struct KFileSerial *port, KFile *fd)
/**
* \brief Transmit some data using the XModem protocol.
*
/**
* \brief Transmit some data using the XModem protocol.
*
- * \param
port Serial port
to use for transfer
+ * \param
ch Channel
to use for transfer
* \param fd Source file
*
* \note This function allocates a large amount of stack for
* the XModem transfer buffer (\see XM_BUFSIZE).
*/
* \param fd Source file
*
* \note This function allocates a large amount of stack for
* the XModem transfer buffer (\see XM_BUFSIZE).
*/
-bool xmodem_send(
struct KFileSerial *port
, KFile *fd)
+bool xmodem_send(
KFile *ch
, KFile *fd)
{
char block_buffer[XM_BUFSIZE]; /* Buffer to hold a block of data */
size_t size = -1;
{
char block_buffer[XM_BUFSIZE]; /* Buffer to hold a block of data */
size_t size = -1;
@@
-324,8
+321,7
@@
bool xmodem_send(struct KFileSerial *port, KFile *fd)
*/
size = kfile_read(fd, block_buffer, XM_BUFSIZE);
*/
size = kfile_read(fd, block_buffer, XM_BUFSIZE);
- kfile_clearerr(&port->fd);
- ser_purge(port);
+ kfile_clearerr(ch);
XMODEM_PROGRESS("Wait remote host\n");
for(;;)
XMODEM_PROGRESS("Wait remote host\n");
for(;;)
@@
-336,7
+332,7
@@
bool xmodem_send(struct KFileSerial *port, KFile *fd)
if (XMODEM_CHECK_ABORT)
return false;
if (XMODEM_CHECK_ABORT)
return false;
- switch (c = kfile_getc(
&port->fd
))
+ switch (c = kfile_getc(
ch
))
{
case XM_NAK:
XMODEM_PROGRESS("Resend blk %d\n", blocknr);
{
case XM_NAK:
XMODEM_PROGRESS("Resend blk %d\n", blocknr);
@@
-369,10
+365,10
@@
bool xmodem_send(struct KFileSerial *port, KFile *fd)
break;
case EOF:
break;
case EOF:
- kfile_clearerr(
&port->fd
);
+ kfile_clearerr(
ch
);
retries++;
XMODEM_PROGRESS("Retries %d\n", retries);
retries++;
XMODEM_PROGRESS("Retries %d\n", retries);
- if (retries <=
X
M_MAXRETRIES)
+ if (retries <=
CONFIG_XMODE
M_MAXRETRIES)
break;
/* falling through! */
break;
/* falling through! */
@@
-389,7
+385,7
@@
bool xmodem_send(struct KFileSerial *port, KFile *fd)
if (!size)
{
if (!size)
{
- kfile_putc(XM_EOT,
&port->fd
);
+ kfile_putc(XM_EOT,
ch
);
continue;
}
continue;
}
@@
-398,19
+394,19
@@
bool xmodem_send(struct KFileSerial *port, KFile *fd)
/* Send block header (STX, blocknr, ~blocknr) */
#if XM_BUFSIZE == 128
/* Send block header (STX, blocknr, ~blocknr) */
#if XM_BUFSIZE == 128
- kfile_putc(XM_SOH,
&port->fd
);
+ kfile_putc(XM_SOH,
ch
);
#else
#else
- kfile_putc(XM_STX,
&port->fd
);
+ kfile_putc(XM_STX,
ch
);
#endif
#endif
- kfile_putc(blocknr & 0xFF,
&port->fd
);
- kfile_putc(~blocknr & 0xFF,
&port->fd
);
+ kfile_putc(blocknr & 0xFF,
ch
);
+ kfile_putc(~blocknr & 0xFF,
ch
);
/* Send block and compute its CRC/checksum */
sum = 0;
crc = 0;
for (i = 0; i < XM_BUFSIZE; i++)
{
/* Send block and compute its CRC/checksum */
sum = 0;
crc = 0;
for (i = 0; i < XM_BUFSIZE; i++)
{
- kfile_putc(block_buffer[i],
&port->fd
);
+ kfile_putc(block_buffer[i],
ch
);
crc = UPDCRC16(block_buffer[i], crc);
sum += block_buffer[i];
}
crc = UPDCRC16(block_buffer[i], crc);
sum += block_buffer[i];
}
@@
-420,11
+416,11
@@
bool xmodem_send(struct KFileSerial *port, KFile *fd)
{
crc = UPDCRC16(0, crc);
crc = UPDCRC16(0, crc);
{
crc = UPDCRC16(0, crc);
crc = UPDCRC16(0, crc);
-
ser_putchar(crc >> 8, port
);
-
ser_putchar(crc & 0xFF, port
);
+
kfile_putc(crc >> 8, ch
);
+
kfile_putc(crc & 0xFF, ch
);
}
else
}
else
- kfile_putc(sum,
&port->fd
);
+ kfile_putc(sum,
ch
);
}
}
#endif
}
}
#endif