]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/simpad-utilities/serload/serialdownload.h
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / simpad-utilities / serload / serialdownload.h
1 //=============================================================================
2 // Project:      SIMpad
3 //=============================================================================
4 // FILE-NAME:    serialdownload.hpp
5 // FUNCTION:     Serial download interface.
6 //
7 // AUTHOR:       Juergen Messerer, Peter Voser
8 // CREAT.-DATE:  01.04.2001 (dd.mm.yy)
9 //
10 // NOTES:        -
11 //               
12 //=============================================================================
13
14 #ifndef __SERIAL_DOWNLOAD
15 #define __SERIAL_DOWNLOAD
16
17 #include <errno.h> 
18 #include <fcntl.h>
19 #include <poll.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <termios.h>
23 #include <unistd.h>
24
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;
32
33 class SerialDownload
34 {
35 public:
36   SerialDownload();
37   ~SerialDownload();
38 //=============================================================================
39 //  PURPOSE:      Opening a serial port.
40 //
41 //  PARAMETERS: 
42 //                portDev: (IN) port device to open.
43 //                errorNumber: (OUT) error number determined with 
44 //                             GetLastError().
45 //  RETURN VALUE: 
46 //                serialPort: Filedescriptor of opened serial port. 
47 //                If the function fails, it returns -1. 
48 //
49 //  COMMENTS:     -
50 //=============================================================================
51   int openSerialPort(const char* portDev, int &errorNumber);
52   
53 //=============================================================================
54 //  PURPOSE:      Loading file with a image 
55 //
56 //  PARAMETERS: 
57 //                fileName: (IN) name of file to open
58 //                buffer: (OUT) pointer to loaded image file.
59 //                numberOfBytes: (OUT) size of file.
60 //
61 //  RETURN VALUE: 
62 //                 0: success
63 //                -1: specified file not found
64 //                -2: not enough memory to load file
65 //                -3: cannot read file
66 //
67 //  COMMENTS:     -
68 //=============================================================================
69   int loadFile(const char *fileName, char *&buffer, int &numberOfBytes);
70
71 //=============================================================================
72 //  PURPOSE:      Connecting to the SIMpad.
73 //
74 //  PARAMETERS:
75 //                fastBaudRate: (IN) value of fast baud rate. 
76 //                errorNumber: (OUT) error number errno
77 //
78 //  RETURN VALUE: 
79 //                0: success
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. 
84 //
85 //  COMMENTS:     The connection is set up according to the bootloader's 
86 //                serial download protocoll.
87 //=============================================================================
88   int connectToSimpad(const int fastBaudRate, 
89                       int& errorNumber);
90
91 //=============================================================================
92 //  PURPOSE:      Sending a block of 512byte.
93 //
94 //  PARAMETERS: 
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 
98 //                             GetLastError().
99 //  RETURN VALUE: 
100 //                TRUE: success
101 //                FALSE: error. See errorNumber for the reason.
102 //
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, 
108                  const int len,  
109                  int& errorNumber);
110
111 //=============================================================================
112 //  PURPOSE:      Waiting for the end of burning.
113 //
114 //  PARAMETERS:   -
115 //
116 //  RETURN VALUE: -
117 //
118 //  COMMENTS:     -
119 //=============================================================================
120   void waitForEndOfBurning(void);
121
122 private:
123   // File descriptor of open serial port.
124   int _serialPort;
125
126 //=============================================================================
127 //  PURPOSE:      Changing baud rate.
128 //
129 //  PARAMETERS:
130 //                newBaudRate: (IN) new baud rate to switch to.
131 //                errorNumber: (OUT) error number determined with 
132 //                             GetLastError().
133 //
134 //  RETURN VALUE: 
135 //                TRUE: success
136 //                FALSE: error. See errorNumber for the reason.
137 //
138 //  serialMENTS:     -
139 //=============================================================================
140   bool changeBaudRate(const int newBaudRate, 
141                       int &errorNumber);
142
143 //=============================================================================
144 //  PURPOSE:      Waiting for control character.
145 //
146 //  PARAMETERS: 
147 //                transparent: (IN) 0 = received characters are sent to 
148 //                                  stdout.
149 //
150 //  RETURN VALUE: 
151 //                c: control character.
152 //
153 //  COMMENTS:     -
154 //=============================================================================
155   unsigned char waitForReply(const int transparent);
156
157 };
158 #endif // __SERIAL_DOWNLOAD