Rev Author Line No. Line
2061 mija 1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
2 * File Name : STBLLIB.cpp
3 * Author : MCD Application Team
4 * Version : v2.2.0
5 * Date : 05/03/2010
6 * Description : Implements the System memory boot loader protocol interface
7 ********************************************************************************
8 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
12 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
14 *******************************************************************************/
15  
16  
17 #include <malloc.h>
18 #include "stdafx.h"
19 #include "STBLLIB.h"
20  
21  
22 /************************************************************************************/
23 /* Generic BL API types
24 /*
25 /*
26 /************************************************************************************/
27  
28 typedef BYTE virt_GetProgress(LPBYTE progress);
29 typedef BYTE virt_GetActivityTime(LPDWORD time);
30 typedef BYTE virt_SetActivityTime(DWORD time);
31 typedef BYTE virt_TARGET_GetFlashSize(DWORD Addr, LPWORD val);
32 typedef BYTE virt_TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val);
33 typedef BYTE virt_TARGET_GetRDPOptionByte(LPBYTE RDP);
34 typedef BYTE virt_TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
35 typedef BYTE virt_Send_RQ(LPSTBL_Request pRQ);
36 typedef BYTE virt_SetCOMSettings(int numPort, long speedInBaud, int nbBit, int parity, float nbStopBit);
37 typedef BYTE virt_COM_Open();
38 typedef BYTE virt_COM_Close();
39 typedef BYTE virt_STBL_SetSpeed(DWORD speed);
40 typedef BYTE virt_STBL_Init_BL();
41 typedef BYTE virt_STBL_GET(LPBYTE Version, LPCommands pCmds);
42 typedef BYTE virt_STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
43 typedef BYTE virt_STBL_GET_ID(LPBYTE size, LPBYTE pID);
44 typedef BYTE virt_STBL_READ(DWORD Address, BYTE Size, LPBYTE pData);
45 typedef BYTE virt_STBL_GO(DWORD Address);
46 typedef BYTE virt_STBL_WRITE(DWORD address, BYTE size, LPBYTE pData);
47 typedef BYTE virt_STBL_ERASE(WORD NbSectors, LPBYTE pSectors);
48 typedef BYTE virt_STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors);
49 typedef BYTE virt_STBL_WRITE_TEMP_UNPROTECT();
50 typedef BYTE virt_STBL_WRITE_PERM_UNPROTECT();
51 typedef BYTE virt_STBL_READOUT_PROTECT();
52 typedef BYTE virt_STBL_READOUT_TEMP_UNPROTECT();
53 typedef BYTE virt_STBL_READOUT_PERM_UNPROTECT();
54 typedef BYTE virt_STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length);
55 typedef BYTE virt_STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
56 typedef BYTE virt_STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
57 typedef BYTE virt_SetPaketSize(BYTE size);
58 typedef BYTE virt_GetPaketSize(LPBYTE size);
59 typedef ACKS virt_GetAckValue();
60 typedef BOOL virt_COM_is_Open();
61 typedef BYTE virt_SetTimeOut(DWORD vms);
62 typedef BYTE virt_TARGET_GetUserOptionByte(LPBYTE User);
63 typedef BYTE virt_TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1);
64 typedef BYTE virt_TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1, BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
65 typedef BYTE virt_TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1, LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
66 typedef BYTE virt_STBL_SetRts(BOOL Val);
67 typedef BYTE virt_STBL_SetDtr(BOOL Val);
68 typedef BYTE virt_STBL_setTxd(BOOL val);
69 typedef BYTE virt_STBL_getCts(BOOL* pval);
70 typedef BYTE virt_STBL_getDtr(BOOL* pval);
71 typedef BYTE virt_STBL_getRi(BOOL* pval);
72 typedef BYTE virt_STBL_getCd(BOOL* pval);
73 typedef BYTE virt_STBL_SetEcho(int val);
74 typedef BYTE virt_STBL_SetFlowControl(int Val);
75  
76 /************************************************************************************/
77 /* Generic BL API references
78 /*
79 /*
80 /************************************************************************************/
81  
82 virt_GetProgress *pt_GetProgress; //(LPBYTE progress);
83 virt_GetActivityTime *pt_GetActivityTime; //(LPDWORD time);
84 virt_SetActivityTime *pt_SetActivityTime; //(DWORD time);
85 virt_TARGET_GetFlashSize *pt_TARGET_GetFlashSize; //(DWORD Addr, LPWORD val);
86 virt_TARGET_GetMemoryAddress *pt_TARGET_GetMemoryAddress; //(DWORD Addr, LPWORD val);
87 virt_TARGET_GetRDPOptionByte *pt_TARGET_GetRDPOptionByte; //(LPBYTE RDP);
88 virt_TARGET_GetWRPOptionBytes *pt_TARGET_GetWRPOptionBytes; //(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
89 virt_Send_RQ *pt_Send_RQ; //(LPSTBL_Request pRQ);
90 virt_SetCOMSettings *pt_SetCOMSettings; //(int numPort, long speedInBaud, int nbBit, int parity, float nbStopBit);
91 virt_COM_Open *pt_COM_Open; //();
92 virt_COM_Close *pt_COM_Close; //();
93 virt_STBL_SetSpeed *pt_STBL_SetSpeed; //(DWORD speed);
94 virt_STBL_Init_BL *pt_STBL_Init_BL; //();
95 virt_STBL_GET *pt_STBL_GET; //(LPBYTE Version, LPCommands pCmds);
96 virt_STBL_GET_VER_ROPS *pt_STBL_GET_VER_ROPS; //(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
97 virt_STBL_GET_ID *pt_STBL_GET_ID; //(LPBYTE size, LPBYTE pID);
98 virt_STBL_READ *pt_STBL_READ; //(DWORD Address, BYTE Size, LPBYTE pData);
99 virt_STBL_GO *pt_STBL_GO; //(DWORD Address);
100 virt_STBL_WRITE *pt_STBL_WRITE; //(DWORD address, BYTE size, LPBYTE pData);
101 virt_STBL_ERASE *pt_STBL_ERASE; //(BYTE NbSectors, LPBYTE pSectors);
102 virt_STBL_WRITE_PROTECT *pt_STBL_WRITE_PROTECT; //(BYTE NbSectors, LPBYTE pSectors);
103 virt_STBL_WRITE_TEMP_UNPROTECT *pt_STBL_WRITE_TEMP_UNPROTECT; //();
104 virt_STBL_WRITE_PERM_UNPROTECT *pt_STBL_WRITE_PERM_UNPROTECT; //();
105 virt_STBL_READOUT_PROTECT *pt_STBL_READOUT_PROTECT; //();
106 virt_STBL_READOUT_TEMP_UNPROTECT *pt_STBL_READOUT_TEMP_UNPROTECT; //();
107 virt_STBL_READOUT_PERM_UNPROTECT *pt_STBL_READOUT_PERM_UNPROTECT; //();
108 virt_STBL_UPLOAD *pt_STBL_UPLOAD; //(DWORD Address, LPBYTE pData, DWORD Length);
109 virt_STBL_VERIFY *pt_STBL_VERIFY; //(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
110 virt_STBL_DNLOAD *pt_STBL_DNLOAD; //(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
111 virt_SetPaketSize *pt_SetPaketSize; //(BYTE size);
112 virt_GetPaketSize *pt_GetPaketSize; //(LPBYTE size);
113 virt_GetAckValue *pt_GetAckValue; //();
114 virt_COM_is_Open *pt_COM_is_Open; //();
115 virt_SetTimeOut *pt_SetTimeOut; //(DWORD vms);
116 virt_TARGET_GetUserOptionByte *pt_TARGET_GetUserOptionByte; //(LPBYTE User);
117 virt_TARGET_GetDataOptionByte *pt_TARGET_GetDataOptionByte; //(LPBYTE Data0, LPBYTE Data1);
118 virt_TARGET_SetSIFData *pt_TARGET_SetSIFData; //(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1, BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
119 virt_TARGET_GetSIFData *pt_TARGET_GetSIFData; //(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1, LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
120 virt_STBL_SetRts *pt_STBL_SetRts; //(BOOL val);
121 virt_STBL_SetDtr *pt_STBL_SetDtr; //(BOOL val);
122 virt_STBL_setTxd *pt_STBL_setTxd; //(BOOL val);
123 virt_STBL_getCts *pt_STBL_getCts; //(BOOL* pval);
124 virt_STBL_getDtr *pt_STBL_getDtr; //(BOOL* pval);
125 virt_STBL_getRi *pt_STBL_getRi; //(BOOL* pval);
126 virt_STBL_getCd *pt_STBL_getCd; //(BOOL* pval);
127 virt_STBL_SetEcho *pt_STBL_SetEcho ; //(int val);
128 virt_STBL_SetFlowControl *pt_STBL_SetFlowControl ; //(bool val);
129  
130  
131  
132  
133 DWORD MAX_DATA_SIZE = 0xFF; // Packet size(in byte)
134 BYTE ACK = 0x79;
135 BYTE NACK = 0x1F;
136  
137 ACKS ACK_VALUE = ST79;
138 LPTARGET_DESCRIPTOR Target;
139 CRS232 Cur_COM;
140 ACKS McuTarget;
141 DWORD Progress;
142 DWORD ActivityTime ;
143  
144 HINSTANCE ST_BL_Lib_Hdle = NULL;
145  
146  
147 BOOL APIENTRY DllMain( HANDLE hModule,
148 DWORD ul_reason_for_call,
149 LPVOID lpReserved
150 )
151 {
152 switch (ul_reason_for_call)
153 {
154 case DLL_PROCESS_ATTACH :{
155 McuTarget = UNDEFINED;
156 Target = (LPTARGET_DESCRIPTOR)malloc(sizeof(TARGET_DESCRIPTOR));
157  
158 Target->Version = 0x00;
159 Target->CmdCount = 0x00;
160 Target->PIDLen = 0x00;
161 Target->PID = (LPBYTE)malloc(1);
162 Target->ROPE = 0x00;
163 Target->ROPD = 0x00;
164  
165 Target->GET_CMD = FALSE ; //Get the version and the allowed commands supported by the current version of the boot loader
166 Target->GET_VER_ROPS_CMD = FALSE ; //Get the BL version and the Read Protection status of the NVM
167 Target->GET_ID_CMD = FALSE ; //Get the chip ID
168 Target->READ_CMD = FALSE ; //Read up to 256 bytes of memory starting from an address specified by the user
169 Target->GO_CMD = FALSE ; //Jump to an address specified by the user to execute (a loaded) code
170 Target->WRITE_CMD = FALSE ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
171 Target->ERASE_CMD = FALSE ; //Erase from one to all the NVM sectors
172 Target->ERASE_EXT_CMD = FALSE ; //Erase from one to all the NVM sectors
173 Target->WRITE_PROTECT_CMD = FALSE ; //Enable the write protection in a permanent way for some sectors
174 Target->WRITE_TEMP_UNPROTECT_CMD = FALSE ; //Disable the write protection in a temporary way for all NVM sectors
175 Target->WRITE_PERM_UNPROTECT_CMD = FALSE ; //Disable the write protection in a permanent way for all NVM sectors
176 Target->READOUT_PERM_PROTECT_CMD = FALSE ; //Enable the readout protection in a permanent way
177 Target->READOUT_TEMP_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a temporary way
178 Target->READOUT_PERM_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a permanent way
179 }break;
180 case DLL_THREAD_ATTACH :{
181 /*McuTarget = UNDEFINED;
182 Target = (LPTARGET_DESCRIPTOR)malloc(sizeof(TARGET_DESCRIPTOR));
183  
184 Target->Version = 0x00;
185 Target->CmdCount = 0x00;
186 Target->PIDLen = 0x00;
187 Target->PID = (LPBYTE)malloc(1);
188 Target->ROPE = 0x00;
189 Target->ROPD = 0x00;
190  
191 Target->GET_CMD = FALSE ; //Get the version and the allowed commands supported by the current version of the boot loader
192 Target->GET_VER_ROPS_CMD = FALSE ; //Get the BL version and the Read Protection status of the NVM
193 Target->GET_ID_CMD = FALSE ; //Get the chip ID
194 Target->READ_CMD = FALSE ; //Read up to 256 bytes of memory starting from an address specified by the user
195 Target->GO_CMD = FALSE ; //Jump to an address specified by the user to execute (a loaded) code
196 Target->WRITE_CMD = FALSE ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
197 Target->ERASE_CMD = FALSE ; //Erase from one to all the NVM sectors
198 Target->WRITE_PROTECT_CMD = FALSE ; //Enable the write protection in a permanent way for some sectors
199 Target->WRITE_TEMP_UNPROTECT_CMD = FALSE ; //Disable the write protection in a temporary way for all NVM sectors
200 Target->WRITE_PERM_UNPROTECT_CMD = FALSE ; //Disable the write protection in a permanent way for all NVM sectors
201 Target->READOUT_PERM_PROTECT_CMD = FALSE ; //Enable the readout protection in a permanent way
202 Target->READOUT_TEMP_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a temporary way
203 Target->READOUT_PERM_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a permanent way
204 */}break;
205 case DLL_THREAD_DETACH :{}break;
206 case DLL_PROCESS_DETACH :{}break;
207 }
208 return TRUE;
209 }
210  
211 /************************************************************************************/
212 /* SET COMMUNICATION INTERFACE TYPE
213 /* UART - CAN - ...
214 /*
215 /************************************************************************************/
216 STBLLIB_API BYTE TARGET_SetComIntType(BYTE com_int_type)
217 {
218 //com_int_type = 0; // This is reserved for Future, When the CANtoUSB Bridge will be available
219 // The CAN module and DLL should be used in com_int_type =1
220  
221 switch (com_int_type)
222 {
223 case 0:{
224 ST_BL_Lib_Hdle = GetModuleHandle("STUARTBLLIB");
225 if ( ST_BL_Lib_Hdle == NULL )
226 {
227 ST_BL_Lib_Hdle = LoadLibrary("STUARTBLLIB") ;
228 }
229 }break;
230 case 1:{
231 ST_BL_Lib_Hdle = GetModuleHandle("STCANBLLIB");
232 if ( ST_BL_Lib_Hdle == NULL )
233 {
234 ST_BL_Lib_Hdle = LoadLibrary("STCANBLLIB") ;
235 }
236 }break;
237 }
238  
239  
240 pt_GetProgress = (virt_GetProgress*)GetProcAddress(ST_BL_Lib_Hdle,"GetProgress");
241 pt_GetActivityTime = (virt_GetActivityTime*)GetProcAddress(ST_BL_Lib_Hdle,"GetActivityTime"); //(LPDWORD time);
242 pt_SetActivityTime = (virt_SetActivityTime*)GetProcAddress(ST_BL_Lib_Hdle,"SetActivityTime"); //(DWORD time);
243 pt_TARGET_GetFlashSize = (virt_TARGET_GetFlashSize*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetFlashSize");
244 pt_TARGET_GetMemoryAddress = (virt_TARGET_GetMemoryAddress*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetMemoryAddress");
245 pt_TARGET_GetRDPOptionByte = (virt_TARGET_GetRDPOptionByte*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetRDPOptionByte");
246 pt_TARGET_GetWRPOptionBytes = (virt_TARGET_GetWRPOptionBytes*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetWRPOptionBytes");
247 pt_Send_RQ = (virt_Send_RQ*)GetProcAddress(ST_BL_Lib_Hdle,"Send_RQ");
248 pt_SetCOMSettings = (virt_SetCOMSettings*)GetProcAddress(ST_BL_Lib_Hdle,"SetCOMSettings");
249 pt_COM_Open = (virt_COM_Open*)GetProcAddress(ST_BL_Lib_Hdle,"COM_Open");
250 pt_COM_Close = (virt_COM_Close*)GetProcAddress(ST_BL_Lib_Hdle,"COM_Close");
251 pt_STBL_SetSpeed = (virt_STBL_SetSpeed*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetSpeed");
252 pt_STBL_Init_BL = (virt_STBL_Init_BL*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_Init_BL");
253 pt_STBL_GET = (virt_STBL_GET*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GET");
254 pt_STBL_GET_VER_ROPS = (virt_STBL_GET_VER_ROPS*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GET_VER_ROPS");
255 pt_STBL_GET_ID = (virt_STBL_GET_ID*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GET_ID");
256 pt_STBL_READ = (virt_STBL_READ*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READ");
257 pt_STBL_GO = (virt_STBL_GO*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GO");
258 pt_STBL_WRITE = (virt_STBL_WRITE*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE");
259 pt_STBL_ERASE = (virt_STBL_ERASE*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_ERASE");
260 pt_STBL_WRITE_PROTECT = (virt_STBL_WRITE_PROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE_PROTECT");
261 pt_STBL_WRITE_TEMP_UNPROTECT = (virt_STBL_WRITE_TEMP_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE_TEMP_UNPROTECT");
262 pt_STBL_WRITE_PERM_UNPROTECT = (virt_STBL_WRITE_PERM_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE_PERM_UNPROTECT");
263 pt_STBL_READOUT_PROTECT = (virt_STBL_READOUT_PROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READOUT_PROTECT");
264 pt_STBL_READOUT_TEMP_UNPROTECT = (virt_STBL_READOUT_TEMP_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READOUT_TEMP_UNPROTECT");
265 pt_STBL_READOUT_PERM_UNPROTECT = (virt_STBL_READOUT_PERM_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READOUT_PERM_UNPROTECT");
266 pt_STBL_UPLOAD = (virt_STBL_UPLOAD*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_UPLOAD");
267 pt_STBL_VERIFY = (virt_STBL_VERIFY*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_VERIFY");
268 pt_STBL_DNLOAD = (virt_STBL_DNLOAD*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_DNLOAD");
269 pt_SetPaketSize = (virt_SetPaketSize*)GetProcAddress(ST_BL_Lib_Hdle,"SetPaketSize");
270 pt_GetPaketSize = (virt_GetPaketSize*)GetProcAddress(ST_BL_Lib_Hdle,"GetPaketSize");
271 pt_GetAckValue = (virt_GetAckValue*)GetProcAddress(ST_BL_Lib_Hdle,"GetAckValue");
272 pt_COM_is_Open = (virt_COM_is_Open*)GetProcAddress(ST_BL_Lib_Hdle,"COM_is_Open");
273 pt_SetTimeOut = (virt_SetTimeOut*)GetProcAddress(ST_BL_Lib_Hdle,"SetTimeOut");
274 pt_TARGET_GetUserOptionByte = (virt_TARGET_GetUserOptionByte*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetUserOptionByte");
275 pt_TARGET_GetDataOptionByte = (virt_TARGET_GetDataOptionByte*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetDataOptionByte");
276 pt_TARGET_SetSIFData = (virt_TARGET_SetSIFData*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_SetSIFData");
277 pt_TARGET_GetSIFData = (virt_TARGET_GetSIFData*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetSIFData");
278 pt_STBL_SetRts = (virt_STBL_SetRts*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetRts");
279 pt_STBL_SetDtr = (virt_STBL_SetDtr*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetDtr");
280 pt_STBL_setTxd = (virt_STBL_setTxd*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_setTxd");
281 pt_STBL_getCts = (virt_STBL_getCts*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getCts");
282 pt_STBL_getDtr = (virt_STBL_getDtr*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getDtr");
283 pt_STBL_getRi = (virt_STBL_getRi*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getRi");
284 pt_STBL_getCd = (virt_STBL_getCd*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getCd");
285 pt_STBL_SetEcho = (virt_STBL_SetEcho*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetEcho");
286 pt_STBL_SetFlowControl = (virt_STBL_SetFlowControl*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetFlowControl");
287 return 0;
288 }
289  
290 /************************************************************************************/
291 /*Set the communication settings for UART, CAN, ...
292 /* UART - numPort, speedInBaud, nbBit, parity, nbStopBit
293 /* CAN - only : speedInBaud
294 /************************************************************************************/
295 STBLLIB_API BYTE SetCOMSettings(int numPort, long speedInBaud, int nbBit,
296 int parity, float nbStopBit)
297 {
298 if(pt_SetCOMSettings)
299 return pt_SetCOMSettings(numPort, speedInBaud, nbBit, parity, nbStopBit);
300 else
301 return LIB_LOADING_ERROR;
302 }
303  
304 STBLLIB_API BYTE Send_RQ(LPSTBL_Request pRQ)
305 {
306 if(pt_Send_RQ)
307 return pt_Send_RQ(pRQ);
308 else
309 return LIB_LOADING_ERROR;
310 }
311  
312 STBLLIB_API BYTE COM_Open()
313 {
314 if(pt_COM_Open)
315 return pt_COM_Open();
316 else
317 return LIB_LOADING_ERROR;
318 }
319  
320 STBLLIB_API BYTE COM_Close()
321 {
322 if(pt_COM_Close)
323 return pt_COM_Close();
324 else
325 return LIB_LOADING_ERROR;
326 }
327  
328 STBLLIB_API BYTE STBL_SetSpeed(DWORD speed)
329 {
330 if(pt_STBL_SetSpeed)
331 return pt_STBL_SetSpeed(speed);
332 else
333 return LIB_LOADING_ERROR;
334 }
335  
336 STBLLIB_API BYTE STBL_Init_BL()
337 {
338 if(pt_STBL_Init_BL)
339 return pt_STBL_Init_BL();
340 else
341 return LIB_LOADING_ERROR;
342 }
343 /******************************************************************************************/
344 /* Boot Loader commands implementation
345 /******************************************************************************************/
346 STBLLIB_API BYTE STBL_GET(LPBYTE Version, LPCommands pCmds)
347 {
348 if(pt_STBL_GET)
349 return pt_STBL_GET(Version, pCmds);
350 else
351 return LIB_LOADING_ERROR;
352 }
353  
354 STBLLIB_API BYTE STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled)
355 {
356 if(pt_STBL_GET_VER_ROPS)
357 return pt_STBL_GET_VER_ROPS(Version, ROPEnabled, ROPDisabled);
358 else
359 return LIB_LOADING_ERROR;
360 }
361  
362 STBLLIB_API BYTE STBL_GET_ID(LPBYTE size, LPBYTE pID)
363 {
364 if(pt_STBL_GET_ID)
365 return pt_STBL_GET_ID(size, pID);
366 else
367 return LIB_LOADING_ERROR;
368 }
369  
370 STBLLIB_API BYTE STBL_READ(DWORD Address, BYTE Size, LPBYTE pData)
371 {
372 if(pt_STBL_READ)
373 return pt_STBL_READ(Address, Size, pData);
374 else
375 return LIB_LOADING_ERROR;
376 }
377  
378 STBLLIB_API BYTE STBL_GO(DWORD Address)
379 {
380 if(pt_STBL_GO)
381 return pt_STBL_GO(Address);
382 else
383 return LIB_LOADING_ERROR;
384 }
385  
386 STBLLIB_API BYTE STBL_WRITE(DWORD address, BYTE size, LPBYTE pData)
387 {
388 if(pt_STBL_WRITE)
389 return pt_STBL_WRITE(address, size, pData);
390 else
391 return LIB_LOADING_ERROR;
392 }
393  
394 STBLLIB_API BYTE STBL_ERASE(WORD NbSectors, LPBYTE pSectors)
395 {
396 if(pt_STBL_ERASE)
397 return pt_STBL_ERASE(NbSectors, pSectors);
398 else
399 return LIB_LOADING_ERROR;
400 }
401  
402  
403 STBLLIB_API BYTE STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors)
404 {
405 if(pt_STBL_WRITE_PROTECT)
406 return pt_STBL_WRITE_PROTECT(NbSectors, pSectors);
407 else
408 return LIB_LOADING_ERROR;
409 }
410  
411 STBLLIB_API BYTE STBL_WRITE_TEMP_UNPROTECT()
412 {
413 if(pt_STBL_WRITE_TEMP_UNPROTECT)
414 return pt_STBL_WRITE_TEMP_UNPROTECT();
415 else
416 return LIB_LOADING_ERROR;
417 }
418  
419 STBLLIB_API BYTE STBL_WRITE_PERM_UNPROTECT()
420 {
421 if(pt_STBL_WRITE_PERM_UNPROTECT)
422 return pt_STBL_WRITE_PERM_UNPROTECT();
423 else
424 return LIB_LOADING_ERROR;
425 }
426  
427 STBLLIB_API BYTE STBL_READOUT_PROTECT()
428 {
429 if(pt_STBL_READOUT_PROTECT)
430 return pt_STBL_READOUT_PROTECT();
431 else
432 return LIB_LOADING_ERROR;
433 }
434  
435 STBLLIB_API BYTE STBL_READOUT_TEMP_UNPROTECT()
436 {
437 if(pt_STBL_READOUT_TEMP_UNPROTECT)
438 return pt_STBL_READOUT_TEMP_UNPROTECT();
439 else
440 return LIB_LOADING_ERROR;
441 }
442  
443 /************************************************************************************/
444 /* READOUT_PERM_UNPROTECT
445 /*
446 /*
447 /************************************************************************************/
448 STBLLIB_API BYTE STBL_READOUT_PERM_UNPROTECT()
449 {
450 if(pt_STBL_READOUT_PERM_UNPROTECT)
451 return pt_STBL_READOUT_PERM_UNPROTECT();
452 else
453 return LIB_LOADING_ERROR;
454 }
455  
456 /************************************************************************************/
457 /* UPLOAD
458 /*
459 /*
460 /************************************************************************************/
461 STBLLIB_API BYTE STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length)
462 {
463 if(pt_STBL_UPLOAD)
464 return pt_STBL_UPLOAD(Address, pData, Length);
465 else
466 return LIB_LOADING_ERROR;
467 }
468  
469 /************************************************************************************/
470 /* VERIFY
471 /*
472 /*
473 /************************************************************************************/
474 STBLLIB_API BYTE STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad)
475 {
476 if(pt_STBL_VERIFY)
477 return pt_STBL_VERIFY(Address, pData, Length,bTruncateLeadFFForDnLoad);
478 else
479 return LIB_LOADING_ERROR;
480 }
481 /************************************************************************************/
482 /* DNLOAD - this command uses the STBL_WRITE function to download a big block of data
483 /*
484 /*
485 /************************************************************************************/
486 STBLLIB_API BYTE STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad)
487 {
488 if(pt_STBL_DNLOAD)
489 return pt_STBL_DNLOAD(Address, pData, Length,bTruncateLeadFFForDnLoad);
490 else
491 return LIB_LOADING_ERROR;
492 }
493 /************************************************************************************/
494 /* SET PACKET SIZE
495 /*
496 /*
497 /************************************************************************************/
498 STBLLIB_API BYTE SetPaketSize(BYTE size)
499 {
500 if(pt_SetPaketSize)
501 return pt_SetPaketSize(size);
502 else
503 return LIB_LOADING_ERROR;
504 }
505  
506 /************************************************************************************/
507 /* GET PACKET SIZE
508 /*
509 /*
510 /************************************************************************************/
511 STBLLIB_API BYTE GetPaketSize(LPBYTE size)
512 {
513 if(pt_GetPaketSize)
514 return pt_GetPaketSize(size);
515 else
516 return LIB_LOADING_ERROR;
517 }
518  
519 /************************************************************************************/
520 /* GetAckValue
521 /*
522 /*
523 /************************************************************************************/
524 STBLLIB_API ACKS GetAckValue()
525 {
526 if(pt_GetAckValue)
527 return pt_GetAckValue();
528 else
529 return UNDEFINED;
530 }
531  
532 /************************************************************************************/
533 /* IsConnected
534 /*
535 /*
536 /************************************************************************************/
537 STBLLIB_API BOOL COM_is_Open()
538 {
539 if(pt_COM_is_Open)
540 return pt_COM_is_Open();
541 else
542 return FALSE;
543 }
544  
545 /************************************************************************************/
546 /* SetTimeOut
547 /*
548 /*
549 /************************************************************************************/
550 STBLLIB_API BYTE SetTimeOut(DWORD vms)
551 {
552 if(pt_SetTimeOut)
553 return pt_SetTimeOut(vms);
554 else
555 return LIB_LOADING_ERROR;
556 }
557  
558 /************************************************************************************/
559 /* GetFlashSize
560 /*
561 /*
562 /************************************************************************************/
563 STBLLIB_API BYTE TARGET_GetFlashSize(DWORD Addr, LPWORD val)
564 {
565 if(pt_TARGET_GetFlashSize)
566 return pt_TARGET_GetFlashSize(Addr, val);
567 else
568 return LIB_LOADING_ERROR;
569 }
570  
571 /************************************************************************************/
572 /* GetMemoryAddress
573 /*
574 /*
575 /************************************************************************************/
576 STBLLIB_API BYTE TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val)
577 {
578 if(pt_TARGET_GetMemoryAddress)
579 return pt_TARGET_GetMemoryAddress(Addr, val);
580 else
581 return LIB_LOADING_ERROR;
582 }
583  
584  
585 /************************************************************************************/
586 /* GetRDPOptionByte
587 /*
588 /*
589 /************************************************************************************/
590 STBLLIB_API BYTE TARGET_GetRDPOptionByte(LPBYTE RDP)
591 {
592 if(pt_TARGET_GetRDPOptionByte)
593 return pt_TARGET_GetRDPOptionByte(RDP);
594 else
595 return LIB_LOADING_ERROR;
596 }
597  
598 /************************************************************************************/
599 /* GetWRPOptionBytes
600 /*
601 /*
602 /************************************************************************************/
603 STBLLIB_API BYTE TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3)
604 {
605 if(pt_TARGET_GetWRPOptionBytes)
606 return pt_TARGET_GetWRPOptionBytes(WRP0, WRP1, WRP2, WRP3);
607 else
608 return LIB_LOADING_ERROR;
609 }
610  
611 /************************************************************************************/
612 /* GetUserOptionByte
613 /*
614 /*
615 /************************************************************************************/
616 STBLLIB_API BYTE TARGET_GetUserOptionByte(LPBYTE User)
617 {
618 if(pt_TARGET_GetUserOptionByte)
619 return pt_TARGET_GetUserOptionByte(User);
620 else
621 return LIB_LOADING_ERROR;
622 }
623  
624 /************************************************************************************/
625 /* GetDataOptionByte
626 /*
627 /*
628 /************************************************************************************/
629 STBLLIB_API BYTE TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1)
630 {
631 if(pt_TARGET_GetDataOptionByte)
632 return pt_TARGET_GetDataOptionByte(Data0, Data1);
633 else
634 return LIB_LOADING_ERROR;
635 }
636  
637 /************************************************************************************/
638 /* SetSIFData
639 /*
640 /*
641 /************************************************************************************/
642 STBLLIB_API BYTE TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1,
643 BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3)
644 {
645 if(pt_TARGET_SetSIFData)
646 return pt_TARGET_SetSIFData(User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3);
647 else
648 return LIB_LOADING_ERROR;
649 }
650  
651 /************************************************************************************/
652 /* SetSIFData
653 /*
654 /*
655 /************************************************************************************/
656 STBLLIB_API BYTE TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1,
657 LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3)
658 {
659 if(pt_TARGET_GetSIFData)
660 return pt_TARGET_GetSIFData(User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3);
661 else
662 return LIB_LOADING_ERROR;
663 }
664  
665 /************************************************************************************/
666 /* GET PROGRESS STATE
667 /*
668 /*
669 /************************************************************************************/
670 STBLLIB_API BYTE GetProgress(LPBYTE progress)
671 {
672 if(pt_GetProgress)
673 return pt_GetProgress(progress);
674 else
675 return LIB_LOADING_ERROR;
676 }
677 /************************************************************************************/
678 /* Get activity time
679 /*
680 /*
681 /************************************************************************************/
682 STBLLIB_API BYTE GetActivityTime(LPDWORD time)
683 {
684 if(pt_GetActivityTime)
685 return pt_GetActivityTime(time);
686 else
687 return LIB_LOADING_ERROR;
688 }
689  
690 /************************************************************************************/
691 /* Set activity time
692 /*
693 /*
694 /************************************************************************************/
695 STBLLIB_API BYTE SetActivityTime(DWORD time)
696 {
697 if(pt_SetActivityTime)
698 return pt_SetActivityTime(time);
699 else
700 return LIB_LOADING_ERROR;
701 }
702  
703 /************************************************************************************/
704 /* Set Rts Line State
705 /* High = TRUE
706 /* Low = FALSE
707 /************************************************************************************/
708 STBLLIB_API BYTE STBL_SetRts(BOOL Val)
709 {
710 if(pt_STBL_SetRts)
711 return pt_STBL_SetRts(Val);
712 else
713 return LIB_LOADING_ERROR;
714 }
715  
716 /************************************************************************************/
717 /* Set Dtr Line State
718 /* High = TRUE
719 /* Low = FALSE
720 /************************************************************************************/
721 STBLLIB_API BYTE STBL_SetDtr(BOOL Val)
722 {
723 if(pt_Send_RQ)
724 return pt_STBL_SetDtr(Val);
725 else
726 return LIB_LOADING_ERROR;
727 }
728  
729 /************************************************************************************/
730 /* Set the state of TXD. Return: true if success.
731 /* High = TRUE
732 /* Low = FALSE
733 /************************************************************************************/
734 STBLLIB_API BYTE STBL_setTxd(BOOL val)
735 {
736 if(pt_STBL_setTxd)
737 return pt_STBL_setTxd(val);
738 else
739 return LIB_LOADING_ERROR;
740 }
741  
742 /************************************************************************************/
743 /* Return: The state of CTS.
744 /* High = TRUE
745 /* Low = FALSE
746 /************************************************************************************/
747 STBLLIB_API BYTE STBL_getCts(BOOL* pval)
748 {
749 if(pt_STBL_getCts)
750 return pt_STBL_getCts(pval);
751 else
752 return LIB_LOADING_ERROR;
753 }
754  
755 /************************************************************************************/
756 /* Return: The state of DTR.
757 /* High = TRUE
758 /* Low = FALSE
759 /************************************************************************************/
760 STBLLIB_API BYTE STBL_getDtr(BOOL* pval)
761 {
762 if(pt_STBL_getDtr)
763 return pt_STBL_getDtr(pval);
764 else
765 return LIB_LOADING_ERROR;
766 }
767  
768 /************************************************************************************/
769 /* Return: The state of RI.
770 /* High = TRUE
771 /* Low = FALSE
772 /************************************************************************************/
773 STBLLIB_API BYTE STBL_getRi(BOOL* pval)
774 {
775 if(pt_STBL_getRi)
776 return pt_STBL_getRi(pval);
777 else
778 return LIB_LOADING_ERROR;
779 }
780  
781 /************************************************************************************/
782 /* Return: The state of DTR.
783 /* High = TRUE
784 /* Low = FALSE
785 /************************************************************************************/
786 STBLLIB_API BYTE STBL_getCd(BOOL* pval)
787 {
788 if(pt_STBL_getCd)
789 return pt_STBL_getCd(pval);
790 else
791 return LIB_LOADING_ERROR;
792 }
793  
794  
795  
796 /************************************************************************************/
797 /* Set Echo back Mode
798 /* 0 = Echo Disabled
799 /* 1 = Echo Back Enabled
800 /* 2 = Listen Echo Enabled
801 /************************************************************************************/
802 STBLLIB_API BYTE STBL_SetEcho(int val)
803 {
804  
805 if(pt_STBL_SetEcho)
806 return pt_STBL_SetEcho(val);
807 else
808 return LIB_LOADING_ERROR;
809 }
810  
811  
812 /************************************************************************************/
813 /* SetFlowControl : Enable/Disable Flow Control of DTR and RTS
814 /* FALSE = Disabled
815 /* TRUE = Enabled
816 /************************************************************************************/
817 STBLLIB_API BYTE STBL_SetFlowControl(bool val)
818 {
819  
820 if(pt_STBL_SetFlowControl)
821 return pt_STBL_SetFlowControl(val);
822 else
823 return LIB_LOADING_ERROR;
824 }
825  
826 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
827