Merged from external project:
[bertos.git] / bertos / net / xmodem.c
index dd1adebe5e3b2eebdde4bff588b1db41037a007c..ca59a99394e17604fa2c264b292bb29c9e405d1c 100644 (file)
@@ -27,7 +27,7 @@
  * the GNU General Public License.
  *
  * Copyright 2004, 2005, 2006, 2007 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999, 2001 Bernardo Innocenti <bernie@develer.com>
+ * Copyright 1999, 2001 Bernie Innocenti <bernie@codewiz.org>
  *
  * -->
  *
@@ -40,7 +40,7 @@
  *
  * \version $Id$
  *
- * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Bernie Innocenti <bernie@codewiz.org>
  * \author Francesco Sacchi <batt@develer.com>
  */
 
@@ -48,7 +48,7 @@
 #include "xmodem.h"
 
 #include <cfg/debug.h>
-#include <cfg/cfg_xmodem.h>
+#include "cfg/cfg_xmodem.h"
 
 #include <drv/ser.h>
 
@@ -69,9 +69,6 @@
 #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
@@ -88,7 +85,7 @@
  *
  * \note This function allocates a large amount of stack (\see XM_BUFSIZE).
  */
-bool xmodem_recv(struct KFileSerial *port, KFile *fd)
+bool xmodem_recv(struct Serial *port, KFile *fd)
 {
        char block_buffer[XM_BUFSIZE]; /* Buffer to hold a block of data */
        int c, i, blocksize;
@@ -129,7 +126,7 @@ bool xmodem_recv(struct KFileSerial *port, KFile *fd)
                        ser_resync(port, 200);
                        retries++;
 
-                       if (retries >= XM_MAXRETRIES)
+                       if (retries >= CONFIG_XMODEM_MAXRETRIES)
                        {
                                kfile_putc(XM_CAN, &port->fd);
                                kfile_putc(XM_CAN, &port->fd);
@@ -140,7 +137,7 @@ bool xmodem_recv(struct KFileSerial *port, KFile *fd)
                        /* Transmission start? */
                        if (blocknr == 0)
                        {
-                               if (retries < XM_MAXCRCRETRIES)
+                               if (retries < CONFIG_XMODEM_MAXCRCRETRIES)
                                {
                                        XMODEM_PROGRESS("Request Tx (CRC)\n");
                                        kfile_putc(XM_C, &port->fd);
@@ -273,7 +270,7 @@ bool xmodem_recv(struct KFileSerial *port, KFile *fd)
                                else
                                {
                                        /* User callback failed: abort transfer immediately */
-                                       retries = XM_MAXRETRIES;
+                                       retries = CONFIG_XMODEM_MAXRETRIES;
                                        purge = true;
                                }
                        }
@@ -308,7 +305,7 @@ bool xmodem_recv(struct KFileSerial *port, KFile *fd)
  * \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(struct Serial *port, KFile *fd)
 {
        char block_buffer[XM_BUFSIZE]; /* Buffer to hold a block of data */
        size_t size = -1;
@@ -374,7 +371,7 @@ bool xmodem_send(struct KFileSerial *port, KFile *fd)
                                kfile_clearerr(&port->fd);
                                retries++;
                                XMODEM_PROGRESS("Retries %d\n", retries);
-                               if (retries <= XM_MAXRETRIES)
+                               if (retries <= CONFIG_XMODEM_MAXRETRIES)
                                        break;
                                /* falling through! */