1 //=============================================================================
3 //=============================================================================
4 // FILE-NAME: serialdownload.hpp
5 // FUNCTION: Serial download interface.
7 // AUTHOR: Juergen Messerer, Peter Voser
8 // CREAT.-DATE: 01.04.2001 (dd.mm.yy)
12 //=============================================================================
14 #ifndef __SERIAL_DOWNLOAD
15 #define __SERIAL_DOWNLOAD
25 const unsigned char STX = 2;
26 const unsigned char ETX = 3;
27 const unsigned char BEL = 7;
28 const unsigned char ACK_BD = 11;
29 const unsigned char ACK_OK = 6;
30 const unsigned char ACK_NOK = 15;
31 const unsigned char FILLER = 0xff;
38 //=============================================================================
39 // PURPOSE: Opening a serial port.
42 // portDev: (IN) port device to open.
43 // errorNumber: (OUT) error number determined with
46 // serialPort: Filedescriptor of opened serial port.
47 // If the function fails, it returns -1.
50 //=============================================================================
51 int openSerialPort(const char* portDev, int &errorNumber);
53 //=============================================================================
54 // PURPOSE: Loading file with a image
57 // fileName: (IN) name of file to open
58 // buffer: (OUT) pointer to loaded image file.
59 // numberOfBytes: (OUT) size of file.
63 // -1: specified file not found
64 // -2: not enough memory to load file
65 // -3: cannot read file
68 //=============================================================================
69 int loadFile(const char *fileName, char *&buffer, int &numberOfBytes);
71 //=============================================================================
72 // PURPOSE: Connecting to the SIMpad.
75 // fastBaudRate: (IN) value of fast baud rate.
76 // errorNumber: (OUT) error number errno
80 // -1: switching to connection baud rate 38400baud failed.
81 // -2: writing to serial port failed.
82 // -3: switching to fast baud rate failed.
83 // -4: writing to serial port with fast baud rate failed.
85 // COMMENTS: The connection is set up according to the bootloader's
86 // serial download protocoll.
87 //=============================================================================
88 int connectToSimpad(const int fastBaudRate,
91 //=============================================================================
92 // PURPOSE: Sending a block of 512byte.
95 // b: (IN) pointer to the beginning of the 512byte buffer.
96 // len: (IN) length of the buffer.
97 // errorNumber: (OUT) error number determined with
101 // FALSE: error. See errorNumber for the reason.
103 // COMMENTS: The block, which is sent, is always 512byte long. If the
104 // buffer counts less than 512byte, the block is filled with
105 // the FILLER pattern.
106 //=============================================================================
107 bool sendBlock(const char *b,
111 //=============================================================================
112 // PURPOSE: Waiting for the end of burning.
119 //=============================================================================
120 void waitForEndOfBurning(void);
123 // File descriptor of open serial port.
126 //=============================================================================
127 // PURPOSE: Changing baud rate.
130 // newBaudRate: (IN) new baud rate to switch to.
131 // errorNumber: (OUT) error number determined with
136 // FALSE: error. See errorNumber for the reason.
139 //=============================================================================
140 bool changeBaudRate(const int newBaudRate,
143 //=============================================================================
144 // PURPOSE: Waiting for control character.
147 // transparent: (IN) 0 = received characters are sent to
151 // c: control character.
154 //=============================================================================
155 unsigned char waitForReply(const int transparent);
158 #endif // __SERIAL_DOWNLOAD