1 |
/**************************************************************************** |
2 |
/* F i l e D a t a |
3 |
/* |
4 |
/* Module : BasicSW |
5 |
/* C.I. No. : |
6 |
/* $Revision: 1.9 $ |
7 |
/* $Date: 2005/03/20 18:16:53 $ |
8 |
/* Belonging to : |
9 |
/* : |
10 |
/* $RCSfile: PD_PatchDumpManager_int.c,v $ |
11 |
/* Program Type : |
12 |
/* Sub-modules : |
13 |
/* |
14 |
/**************************************************************************** |
15 |
/* S W D e v e l o p m e n t E n v i r o n m e n t |
16 |
/* |
17 |
/* Host system : |
18 |
/* SW Compiler : |
19 |
/* $Author: sebastiani $ |
20 |
/* : |
21 |
/**************************************************************************** |
22 |
/* U p d a t i n g |
23 |
/* |
24 |
/* $Log: PD_PatchDumpManager_int.c,v $ |
25 |
/* Revision 1.9 2005/03/20 18:16:53 sebastiani |
26 |
/* avoided compilation warning |
27 |
/* |
28 |
/* Revision 1.8 2005/03/06 14:53:22 sebastiani |
29 |
/* fix check different value |
30 |
/* |
31 |
/* Revision 1.7 2005/02/21 08:58:28 sebastiani |
32 |
/* all log comments completed |
33 |
/* |
34 |
/* Revision 1.6 2005/02/19 10:16:17 sebastiani |
35 |
/* efficient write in EEPROM |
36 |
/* |
37 |
/* Revision 1.5 2004/09/28 15:36:17 sebastiani |
38 |
/* interrupt manager fix |
39 |
/* |
40 |
/* Revision 1.4 2004/09/17 15:01:00 faber |
41 |
/* LU_INFN_LOG flags fixing |
42 |
/* |
43 |
/* Revision 1.3 2003/11/18 09:01:14 alfarano |
44 |
/* laben patch fixes some problems |
45 |
/* |
46 |
/* Revision 1.2 2003/10/21 16:09:12 alfarano |
47 |
/* LU_LOG_INFN replacement for all remaining original log functions |
48 |
/* |
49 |
/* Revision 1.1.1.1 2003/08/04 09:40:21 sebastiani |
50 |
/* Imported sources laben rel. 19.06.2003 integrated with pam2 |
51 |
/* |
52 |
/* Revision 1.10 2002/09/11 15:33:39 zulia |
53 |
/* correct checkParameterValue |
54 |
/* (memory address was casted to UWORD) |
55 |
/* |
56 |
/* Revision 1.9 2002/08/06 12:08:27 zulia |
57 |
/* the Patch mcmd is refused if the number of data words not are multiply of 32 bits |
58 |
/* |
59 |
/* Revision 1.8 2002/08/05 14:25:35 zulia |
60 |
/* Fixed Patch & Dump |
61 |
/* |
62 |
/* Revision 1.7 2002/05/09 08:16:34 zulia |
63 |
/* * acceptance release |
64 |
/* |
65 |
/* |
66 |
/*****************************************************************************/ |
67 |
|
68 |
|
69 |
/*============================= Include File ================================*/ |
70 |
|
71 |
#include <src/BasicSW/PatchDumpManager/PD_PatchDumpManager_int.h> |
72 |
#include <src/HKManager/HistoryArea/HA_HistoryArea_p.h> |
73 |
#include <src/BasicSW/CrimeaDriver/CD_CrimeaDriver_p.h> |
74 |
|
75 |
#include <src/INFN/LU_SourceFileID_INFN.h> |
76 |
#define __FILEID__ _PD_PatchDumpManager_int__c |
77 |
#include <src/INFN/PRH_ParamHandler_INFN_auto.h> |
78 |
#include <src/INFN/PRH_ParamHandler_INFN.h> |
79 |
#include <src/INFN/LU_LogUtility_INFN.h> |
80 |
|
81 |
LU_DECL_MASK(); |
82 |
|
83 |
/*****************************************************************************/ |
84 |
/*============================= Object constant ============================*/ |
85 |
|
86 |
|
87 |
/*****************************************************************************/ |
88 |
/*============================= Object variables ============================*/ |
89 |
|
90 |
/*****************************************************************************/ |
91 |
|
92 |
/* P a t c h D u m p M a n a g e r O P E R A T I O N A L F U N C T I O N S */ |
93 |
|
94 |
|
95 |
/*****************************************************************************/ |
96 |
/* @Function: PD_ifPatch */ |
97 |
/* @Purpose : */ |
98 |
/* This function executes the Patch macrocommand performing the following */ |
99 |
/* actions: */ |
100 |
/* _ checks the number of words to be patched */ |
101 |
/* _ checks the supervisor memory selection */ |
102 |
/* _ checks if address is in the allowed range */ |
103 |
/* _ writes the patch at the correct address */ |
104 |
/* */ |
105 |
/* @@ */ |
106 |
/* @Parameter Name @Mode @Description */ |
107 |
/* PtrMcmd IN pointer to the macrocommand header structure */ |
108 |
/* PatchBuff IN pointer to the patch RAM area */ |
109 |
/* @@ */ |
110 |
/*****************************************************************************/ |
111 |
void PD_ifPatch(MA_HEADER_MCMD* PtrMcmd, UWORD* PatchBuff) |
112 |
{ |
113 |
UINT* memAddrToPatch; |
114 |
UWORD nWord16ToLoad; |
115 |
UWORD smsPatch; |
116 |
UWORD error; |
117 |
UWORD* pw; |
118 |
UINT timetagFlag; |
119 |
MsgTsk sndMsg; |
120 |
|
121 |
pw = (UWORD*)(PtrMcmd->PtrMCMD); |
122 |
|
123 |
/* retrieves the number of words to be patched from the |
124 |
macrocommand length (expressed in multiples of 16bit words) */ |
125 |
nWord16ToLoad = pw[2] & 0x0FFF; |
126 |
|
127 |
/* subtracts 8 words from Mcmd length (mcmd header+end identifier) */ |
128 |
if ( nWord16ToLoad > 8 ) |
129 |
{ |
130 |
nWord16ToLoad -= 8; |
131 |
} |
132 |
|
133 |
/* determinates if it is a RAM or EEPROM patch */ |
134 |
if( pw[5] & PD_PATCH_SMS_MASK ) |
135 |
{ |
136 |
if ( pw[5] & PD_EEPROM_BANK_SELECT ) |
137 |
{ |
138 |
memAddrToPatch = (UINT*)(PD_EEPROM_BANK1_ADDR_START + (((pw[5]&0x00FF)<<16) | pw[6])); |
139 |
smsPatch = PD_EEPROM_BANK1_PATCH; |
140 |
} |
141 |
else |
142 |
{ |
143 |
memAddrToPatch = (UINT*)(PD_EEPROM_BANK0_ADDR_START + (((pw[5]&0x00FF)<<16) | pw[6])); |
144 |
smsPatch = PD_EEPROM_BANK0_PATCH; |
145 |
} |
146 |
} |
147 |
else |
148 |
{ |
149 |
smsPatch = PD_RAM_PATCH; |
150 |
memAddrToPatch = (UINT*)(PD_RAM_ADDR_START + (((pw[5]&0x00FF)<<16) | pw[6])); |
151 |
} |
152 |
error = PD_ifCheckParamValues(memAddrToPatch, nWord16ToLoad>>1, smsPatch ); |
153 |
|
154 |
if ( nWord16ToLoad % 2) |
155 |
{ |
156 |
/* The number of word must be 32-bit multiply */ |
157 |
error = HA_E2_INVALID_LENGTH; |
158 |
} |
159 |
|
160 |
if ( error == PD_PARAM_VALUES_NO_ERROR ) |
161 |
{ |
162 |
/* copies into private buffer the data to be patched */ |
163 |
memcpy(PatchBuff, &pw[7], nWord16ToLoad<<1); |
164 |
} |
165 |
|
166 |
/* The function has been called by a MCMD, delete it from the partition */ |
167 |
timetagFlag = *(((unsigned short* )PtrMcmd->PtrMCMD)+1) & TIMETAG_MASK ? TIMETAG_MCMD : IMMEDIATE_MCMD; |
168 |
MA_piDelBufferMCMD(PtrMcmd->PtrMCMD, timetagFlag); |
169 |
|
170 |
if ( error == PD_PARAM_VALUES_NO_ERROR ) |
171 |
{ |
172 |
/* writes the patch */ |
173 |
if( smsPatch == PD_RAM_PATCH ) |
174 |
{ |
175 |
memcpy(memAddrToPatch, PatchBuff, nWord16ToLoad<<1); |
176 |
} |
177 |
else |
178 |
{ |
179 |
PD_ifEEPROMWrite(memAddrToPatch, PatchBuff, nWord16ToLoad>>1); |
180 |
} |
181 |
} |
182 |
/* log in History Area*/ |
183 |
// LOG_INFN HA_piLogHistoryEntry2(PtrMcmd->Type,error); |
184 |
/*@LOG Patch MCMD - error code */ |
185 |
LU_INFN_LOG(LU_NORMAL_TRACE | LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,error); |
186 |
} |
187 |
|
188 |
|
189 |
/*****************************************************************************/ |
190 |
/* @Function: PD_ifDump */ |
191 |
/* @Purpose : */ |
192 |
/* This function executes the Dump macrocommand performing the following */ |
193 |
/* actions: */ |
194 |
/* _ checks the number of words to be patched */ |
195 |
/* _ checks the supervisor memory selection */ |
196 |
/* _ checks if address is in the allowed range */ |
197 |
/* _ checks the append_next flag */ |
198 |
/* _ copies data into the dump buffer */ |
199 |
/* */ |
200 |
/* @@ */ |
201 |
/* @Parameter Name @Mode @Description */ |
202 |
/* PtrMcmd IN pointer to the macrocommand header structure */ |
203 |
/* DumpBuff IN pointer to the dump RAM area */ |
204 |
/* @@ */ |
205 |
/*****************************************************************************/ |
206 |
void PD_ifDump(MA_HEADER_MCMD* PtrMcmd, UWORD* DumpBuff,PD_INFO* DumpInfo) |
207 |
{ |
208 |
UINT* memAddrToDump; |
209 |
UWORD nWordsToDump; |
210 |
UWORD Append_Next; |
211 |
UWORD smsDump; |
212 |
UWORD eepromBankSel; |
213 |
UWORD error; |
214 |
UWORD* pw; |
215 |
UINT timetagFlag; |
216 |
MsgTsk sndMsg; |
217 |
|
218 |
/* The function has been called by a MCMD, delete it from the partition */ |
219 |
pw = (UWORD*)PtrMcmd->PtrMCMD; |
220 |
/* The parameter unit is 32 bit word, and is converted in byte unit */ |
221 |
nWordsToDump = (pw[5] & 0xFF00)>>6; |
222 |
Append_Next = pw[5] & 0x0001; |
223 |
smsDump = pw[5] & 0x0006; |
224 |
eepromBankSel = pw[5] & 0x0004; |
225 |
|
226 |
/* determinates if it is a RAM or EEPROM dump and computes the appropriate address */ |
227 |
if( smsDump == PD_RAM_DUMP ) |
228 |
memAddrToDump = (UINT*)( PD_RAM_ADDR_START + (((pw[6]&0x00FF)<<16) | pw[7]) ); |
229 |
else |
230 |
{ |
231 |
if (eepromBankSel == PD_EEPROM_BANK0_DUMP ) |
232 |
memAddrToDump = (UINT*)( PD_EEPROM_BANK0_ADDR_START + (((pw[6]&0x00FF)<<16) | pw[7]) ); |
233 |
else |
234 |
memAddrToDump = (UINT*)( PD_EEPROM_BANK1_ADDR_START + (((pw[6]&0x00FF)<<16) | pw[7]) ); |
235 |
} |
236 |
|
237 |
error = PD_ifCheckParamValues(memAddrToDump, nWordsToDump>>2, smsDump); |
238 |
|
239 |
timetagFlag = *(((unsigned short* )PtrMcmd->PtrMCMD)+1) & TIMETAG_MASK ? TIMETAG_MCMD : IMMEDIATE_MCMD; |
240 |
MA_piDelBufferMCMD(PtrMcmd->PtrMCMD, timetagFlag); |
241 |
|
242 |
if ( error == PD_PARAM_VALUES_NO_ERROR ) |
243 |
{ |
244 |
if( Append_Next ) |
245 |
{ |
246 |
/* (1): append */ |
247 |
if( DumpInfo->nWordsAvailable >= (nWordsToDump >> 1) ) |
248 |
{ |
249 |
/* appends the dump */ |
250 |
/* The number of words is stored into 32 bit word unit */ |
251 |
*DumpInfo->pAppend = (nWordsToDump<<6) | (pw[6]&0x00FF); |
252 |
*(++DumpInfo->pAppend) = pw[7]; |
253 |
memcpy(++DumpInfo->pAppend , memAddrToDump, nWordsToDump); |
254 |
DumpInfo->pAppend += (nWordsToDump>>1); |
255 |
DumpInfo->nWordsAvailable -= ((nWordsToDump >> 1)+2); |
256 |
} |
257 |
else |
258 |
{ |
259 |
error = HA_E2_DUMP_BUFFER_FULL; |
260 |
} |
261 |
} |
262 |
else /* (0): no append */ |
263 |
{ |
264 |
DumpInfo->pAppend = DumpBuff; |
265 |
DumpInfo->nWordsAvailable = PD_BUFFER_DUMP_MAX_SIZE; |
266 |
/* The number of words is stored into 32 bit word unit */ |
267 |
*DumpInfo->pAppend = (nWordsToDump<<6) | (pw[6]&0x00FF); |
268 |
*(++DumpInfo->pAppend) = pw[7]; |
269 |
memcpy(++DumpInfo->pAppend , memAddrToDump, nWordsToDump); |
270 |
DumpInfo->pAppend += (nWordsToDump>>1); |
271 |
DumpInfo->nWordsAvailable -= ((nWordsToDump >> 1)+2); |
272 |
} |
273 |
} |
274 |
/* log in History Area*/ |
275 |
// LOG_INFN HA_piLogHistoryEntry2(PtrMcmd->Type,error); |
276 |
/*@LOG Dump MCMD - error code */ |
277 |
LU_INFN_LOG(LU_NORMAL_TRACE | LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,error); |
278 |
} |
279 |
|
280 |
|
281 |
/*****************************************************************************/ |
282 |
/* @Function: PD_ifCheckParamValues */ |
283 |
/* @Purpose : */ |
284 |
/* This function checks that the requested patch/dump address is inside */ |
285 |
/* the allowed range, RAM EEPROM respectively */ |
286 |
/* */ |
287 |
/* @@ */ |
288 |
/* @Parameter Name @Mode @Description */ |
289 |
/* memAddrStart IN memory address from which to start patch */ |
290 |
/* or dump */ |
291 |
/* nWords IN number of words (32 bit) to patch/dump */ |
292 |
/* smsFlag IN Supervisor Memory Selection (RAM / EEPROM) */ |
293 |
/* status_code OUT Return code */ |
294 |
/* @@ */ |
295 |
/*****************************************************************************/ |
296 |
UWORD PD_ifCheckParamValues(UINT* memAddrStart, UWORD nWords, UWORD smsFlag) |
297 |
{ |
298 |
UWORD status; |
299 |
UINT addrNotAlignedflag; |
300 |
|
301 |
status = PD_PARAM_VALUES_NO_ERROR; |
302 |
|
303 |
if( smsFlag == PD_RAM_PATCH ) |
304 |
{ |
305 |
/* checks if address is inside RAM space and/or buffer overflow */ |
306 |
if( memAddrStart < (UINT*)PD_RAM_ADDR_START || |
307 |
memAddrStart > (UINT*)PD_RAM_ADDR_END ) |
308 |
{ |
309 |
status = HA_E2_INVALID_ADDRESS; |
310 |
} |
311 |
else if( nWords >= PD_BUFFER_PATCH_MAX_SIZE || |
312 |
memAddrStart + nWords - 1 > (UINT*)PD_RAM_ADDR_END ) |
313 |
{ |
314 |
status = HA_E2_INVALID_LENGTH; |
315 |
} |
316 |
} |
317 |
else if ( smsFlag == PD_EEPROM_BANK0_PATCH ) |
318 |
{ |
319 |
/* The address must be 32-bit aligned */ |
320 |
addrNotAlignedflag =((UINT)((UINT*)memAddrStart) & 0x00000003); |
321 |
/* checks if address is inside EEPROM space and/or buffer overflow */ |
322 |
if( memAddrStart < (UINT*)PD_EEPROM_BANK0_ADDR_START || |
323 |
memAddrStart > (UINT*)PD_EEPROM_BANK0_ADDR_END || |
324 |
/* The address must be 32-bit aligned */ |
325 |
addrNotAlignedflag ) |
326 |
{ |
327 |
status = HA_E2_INVALID_ADDRESS; |
328 |
} |
329 |
else if( nWords >= PD_BUFFER_PATCH_MAX_SIZE || |
330 |
memAddrStart + nWords - 1 > (UINT*)PD_EEPROM_BANK0_ADDR_END ) |
331 |
{ |
332 |
status = HA_E2_INVALID_LENGTH; |
333 |
} |
334 |
} |
335 |
else if ( smsFlag == PD_EEPROM_BANK1_PATCH ) |
336 |
{ |
337 |
/* The address must be 32-bit aligned */ |
338 |
addrNotAlignedflag =((UINT)((UINT*)memAddrStart) & 0x00000003); |
339 |
/* checks if address is inside EEPROM space and/or buffer overflow */ |
340 |
if( memAddrStart < (UINT*)PD_EEPROM_BANK1_ADDR_START || |
341 |
memAddrStart > (UINT*)PD_EEPROM_BANK1_ADDR_END || |
342 |
/* The address must be 32-bit aligned */ |
343 |
addrNotAlignedflag ) |
344 |
{ |
345 |
status = HA_E2_INVALID_ADDRESS; |
346 |
} |
347 |
else if( nWords >= PD_BUFFER_PATCH_MAX_SIZE || |
348 |
memAddrStart + nWords - 1 > (UINT*)PD_EEPROM_BANK1_ADDR_END ) |
349 |
{ |
350 |
status = HA_E2_INVALID_LENGTH; |
351 |
} |
352 |
} |
353 |
else |
354 |
status = HA_E2_INVALID_ADDRESS; |
355 |
|
356 |
return status; |
357 |
} |
358 |
|
359 |
|
360 |
/*****************************************************************************/ |
361 |
/* @Function: PD_ifEEPROMWrite */ |
362 |
/* @Purpose : */ |
363 |
/* This function writes a specified number of words from a source buffer */ |
364 |
/* to an EEPROM memory address. When a boundary is reached the process of */ |
365 |
/* writing is suspended for 10 milliseconds. */ |
366 |
/* */ |
367 |
/* @@ */ |
368 |
/* @Parameter Name @Mode @Description */ |
369 |
/* dstAddr IN write destination address */ |
370 |
/* sourceAddr IN read source address */ |
371 |
/* nWords32Bit IN number of words (32 bit) to be written */ |
372 |
/* @@ */ |
373 |
/*****************************************************************************/ |
374 |
void PD_ifEEPROMWrite(void* dstAddr, void* sourceAddr, UINT nWords32Bit ) |
375 |
{ |
376 |
unsigned int level; |
377 |
UINT boundaryFlag; |
378 |
UINT boundery; |
379 |
UINT i; |
380 |
|
381 |
/* Enable EEPROM writing by programming CRIMEA register */ |
382 |
CD_EEPROM_WRITE_ENABLE; |
383 |
while ( nWords32Bit > 0 ) |
384 |
{ |
385 |
|
386 |
boundaryFlag =FALSE; |
387 |
/* Find number of words until the boundary page */ |
388 |
for (i=0; i<PD_EEPROM_LENGHT && !boundaryFlag && nWords32Bit>0; i++) |
389 |
{ |
390 |
boundery =((UINT)((UINT*)dstAddr+i) & 0x000001FF); |
391 |
if (boundery == PD_BOUNDARY_EEPROM) |
392 |
{ |
393 |
boundaryFlag =TRUE; |
394 |
} |
395 |
nWords32Bit--; |
396 |
} |
397 |
/* Write specified number of words into EEPROM */ |
398 |
PD_ifCopyRamToEEprom((UINT*)sourceAddr,(UINT*)dstAddr,i); |
399 |
/* Increment destination and source address */ |
400 |
(UINT*)dstAddr +=i; |
401 |
(UINT*)sourceAddr +=i; |
402 |
} |
403 |
/* Disable EEPROM writing by programming CRIMEA register */ |
404 |
CD_EEPROM_WRITE_DISABLE; |
405 |
} |
406 |
|
407 |
|
408 |
|
409 |
|
410 |
/*****************************************************************************/ |
411 |
/* @Function: PD_ifCopyRamToEEprom */ |
412 |
/* @Purpose : */ |
413 |
/* This function writes a specified number of words from a source buffer */ |
414 |
/* a source buffer to an EEPROM memory address. The number of written words */ |
415 |
/* into the EEPROM must not exceed the page boundary. At the end of the */ |
416 |
/* writing procedure the task is suspended for 10 milliseconds. */ |
417 |
/* */ |
418 |
/* @@ */ |
419 |
/* @Parameter Name @Mode @Description */ |
420 |
/* Dest IN write destination address */ |
421 |
/* Source IN read source address */ |
422 |
/* Len IN number of words (32 bit) to be written */ |
423 |
/* @@ */ |
424 |
/*****************************************************************************/ |
425 |
void PD_ifCopyRamToEEprom(UINT* Source, UINT* Dest, UINT Len) |
426 |
{ |
427 |
unsigned int c; |
428 |
unsigned int level=0; |
429 |
UINT *ss=Source, *sd=Dest; |
430 |
|
431 |
/* added for safe: if the block is axactly the same, do nothing : */ |
432 |
for (c=0 ; c<Len && level==0; c++, Source++,Dest++) |
433 |
{ |
434 |
level += (*Dest != *Source); |
435 |
} |
436 |
if(level==0) |
437 |
return; |
438 |
|
439 |
Dest=sd; |
440 |
Source=ss; |
441 |
|
442 |
/* Disable interrupts in order to don't break off */ |
443 |
/* the EEPROM write procedure */ |
444 |
level =sparc_disable_interrupts(); |
445 |
/* Move data from source to destination */ |
446 |
for (c=0 ; c<Len; c++, Source++,Dest++) |
447 |
{ |
448 |
*Dest =*Source; |
449 |
} |
450 |
/* Enable interrupts */ |
451 |
sparc_enable_interrupts(level); |
452 |
/* Suspend task to starting internal EEPROM writing */ |
453 |
if(rtems_interrupt_is_in_progress()) |
454 |
CM_Suspend_Dummy_Loop(13); |
455 |
else |
456 |
OS_piTaskSuspend(12); |
457 |
} |
458 |
|