nfm_base_mem.c 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  1. //#include "options.h"
  2. //#define FLASHCHIP_C
  3. //#include "drivers/flash/flashchip.h"
  4. #include "core/config.h"
  5. #include "crc32.h"
  6. #include "app/nfm/nfm_base_excls.h"
  7. #include "string.h"
  8. #include "drivers/flash/base/extmem_flash.h"
  9. //------------------------------------------------------------------------------
  10. #pragma location=".cache"
  11. static uint8_t g_RomBuffer [ CONFIG_FLASHMEM_CACHE_SIZE ];
  12. typedef enum
  13. {
  14. RomBufCache_undefined,
  15. RomBufCache_CommonHeader,
  16. RomBufCache_FactoryChrzHeader,
  17. RomBufCache_TCompHeader,
  18. RomBufCache_User1ChrzHeader,
  19. RomBufCache_User2ChrzHeader,
  20. RomBufCache_User3ChrzHeader,
  21. }
  22. eRomBufCache_t;
  23. static eRomBufCache_t g_RomBuffer_Cache = RomBufCache_undefined;
  24. //------------------------------------------------------------------------------
  25. //const sNFMMemory_ChrzTableMatrix_2Port_t tableMatrix_SC2543_2xPort_NFM_2543_v1 =
  26. //{
  27. // DECLARE_CHRZTABLETYPE_2PORT(14),
  28. //
  29. // .Single =
  30. // {
  31. // /* Port A */
  32. // .aArray[ ePortComb_A - ePortComb_MIN_SINGLE_2Port ] =
  33. // {
  34. // .aBaseIndex[ ePortStateId_Short - ePortStateId_MIN_SINGLE_2Port ] = 1, // Short
  35. // .aBaseIndex[ ePortStateId_Open - ePortStateId_MIN_SINGLE_2Port ] = 3, // Open
  36. // .aBaseIndex[ ePortStateId_Load - ePortStateId_MIN_SINGLE_2Port ] = 5, // Load
  37. // .aBaseIndex[ ePortStateId_Load2 - ePortStateId_MIN_SINGLE_2Port ] =15, // Load2
  38. // .aBaseIndex[ ePortStateId_Open2 - ePortStateId_MIN_SINGLE_2Port ] =17, // Open2
  39. // },
  40. //
  41. // /* Port B */
  42. // .aArray[ ePortComb_B - ePortComb_MIN_SINGLE_2Port ] =
  43. // {
  44. // .aBaseIndex[ ePortStateId_Short - ePortStateId_MIN_SINGLE_2Port ] = 2, // Short
  45. // .aBaseIndex[ ePortStateId_Open - ePortStateId_MIN_SINGLE_2Port ] = 4, // Open
  46. // .aBaseIndex[ ePortStateId_Load - ePortStateId_MIN_SINGLE_2Port ] = 6, // Load
  47. // .aBaseIndex[ ePortStateId_Load2 - ePortStateId_MIN_SINGLE_2Port ] =16, // Load2
  48. // .aBaseIndex[ ePortStateId_Open2 - ePortStateId_MIN_SINGLE_2Port ] =18, // Open2
  49. // },
  50. // },
  51. //
  52. // .Thru =
  53. // {
  54. // /* Thru A-B */
  55. // .aArrays[ ePortComb_AB - ePortComb_MIN_THRU_2Port ] = // Thru AB
  56. // {
  57. // .aBaseIndex[ ePortStateId_S11 - ePortStateId_MIN_THRU_2Port ] = 7, // S11
  58. // .aBaseIndex[ ePortStateId_S21 - ePortStateId_MIN_THRU_2Port ] = 8, // S21
  59. // .aBaseIndex[ ePortStateId_S12 - ePortStateId_MIN_THRU_2Port ] = 9, // S12
  60. // .aBaseIndex[ ePortStateId_S22 - ePortStateId_MIN_THRU_2Port ] = 10, // S22
  61. // },
  62. // },
  63. //
  64. // .Check =
  65. // {
  66. // .sArray = // Check State
  67. // {
  68. // .aBaseIndex[ ePortStateId_S11 - ePortStateId_MIN_CHECK_2Port ] = 11, // S11
  69. // .aBaseIndex[ ePortStateId_S21 - ePortStateId_MIN_CHECK_2Port ] = 12, // S21
  70. // .aBaseIndex[ ePortStateId_S12 - ePortStateId_MIN_CHECK_2Port ] = 13, // S12
  71. // .aBaseIndex[ ePortStateId_S22 - ePortStateId_MIN_CHECK_2Port ] = 14, // S22
  72. // }
  73. // },
  74. //};
  75. //
  76. //const sNFMMemory_ChrzTableMatrix_2Port_t tableMatrix_SC2543_2xPort_NFM_2543_v2 =
  77. //{
  78. // DECLARE_CHRZTABLETYPE_2PORT(14),
  79. //
  80. // .Single =
  81. // {
  82. // /* Port A */
  83. // .aArray[ ePortComb_A - ePortComb_MIN_SINGLE_2Port ] =
  84. // {
  85. // .aBaseIndex[ ePortStateId_Short - ePortStateId_MIN_SINGLE_2Port ] = 1, // Short
  86. // .aBaseIndex[ ePortStateId_Open - ePortStateId_MIN_SINGLE_2Port ] = 3, // Open
  87. // .aBaseIndex[ ePortStateId_Load - ePortStateId_MIN_SINGLE_2Port ] = 5, // Load
  88. // .aBaseIndex[ ePortStateId_Load2 - ePortStateId_MIN_SINGLE_2Port ] =15, // Load2
  89. // .aBaseIndex[ ePortStateId_Open2 - ePortStateId_MIN_SINGLE_2Port ] =17, // Open2
  90. // },
  91. //
  92. // /* Port B */
  93. // .aArray[ ePortComb_B - ePortComb_MIN_SINGLE_2Port ] =
  94. // {
  95. // .aBaseIndex[ ePortStateId_Short - ePortStateId_MIN_SINGLE_2Port ] = 2, // Short
  96. // .aBaseIndex[ ePortStateId_Open - ePortStateId_MIN_SINGLE_2Port ] = 4, // Open
  97. // .aBaseIndex[ ePortStateId_Load - ePortStateId_MIN_SINGLE_2Port ] = 6, // Load
  98. // .aBaseIndex[ ePortStateId_Load2 - ePortStateId_MIN_SINGLE_2Port ] =16, // Load2
  99. // .aBaseIndex[ ePortStateId_Open2 - ePortStateId_MIN_SINGLE_2Port ] =18, // Open2
  100. // },
  101. // },
  102. //
  103. // .Thru =
  104. // {
  105. // /* Thru A-B */
  106. // .aArrays[ ePortComb_AB - ePortComb_MIN_THRU_2Port ] = // Thru AB
  107. // {
  108. // .aBaseIndex[ ePortStateId_S11 - ePortStateId_MIN_THRU_2Port ] = 7, // S11
  109. // .aBaseIndex[ ePortStateId_S21 - ePortStateId_MIN_THRU_2Port ] = 8, // S21
  110. // .aBaseIndex[ ePortStateId_S12 - ePortStateId_MIN_THRU_2Port ] = 9, // S12
  111. // .aBaseIndex[ ePortStateId_S22 - ePortStateId_MIN_THRU_2Port ] = 10, // S22
  112. // },
  113. // },
  114. //
  115. // .Check =
  116. // {
  117. // .sArray = // Check State
  118. // {
  119. // .aBaseIndex[ ePortStateId_S11 - ePortStateId_MIN_CHECK_2Port ] = 11, // S11
  120. // .aBaseIndex[ ePortStateId_S21 - ePortStateId_MIN_CHECK_2Port ] = 12, // S21
  121. // .aBaseIndex[ ePortStateId_S12 - ePortStateId_MIN_CHECK_2Port ] = 13, // S12
  122. // .aBaseIndex[ ePortStateId_S22 - ePortStateId_MIN_CHECK_2Port ] = 14, // S22
  123. // }
  124. // },
  125. //};
  126. #define NFMBASE_FLASH_MAKEADDRESS_USERBANK0( addr ) ( 0x00000000 | (addr) ) // (addr + AT45FLASH_MINIMUM_ADDRESS)
  127. #define NFMBASE_FLASH_MAKEADDRESS_USERBANK1( addr ) ( 0x80000000 | (addr) ) // (addr - FLASH_USERBANK_0_SIZE)
  128. #define NFMBASE_FLASH_USERBANK0_CHECK( addr ) (!(0x80000000 & (addr) ))
  129. #define NFMBASE_FLASH_USERBANK1_CHECK( addr ) (( 0x80000000 & (addr) ))
  130. #define NFMBASE_FLASH_MIN_ADDRESS ( ExtMemHandle.pFlashProperties->minAddress )
  131. #define NFMBASE_FLASH_MAX_ADDRESS ( ExtMemHandle.pFlashProperties->maxAddress )
  132. #define NFMBASE_FLASH_BANK0_SIZE ( ExtMemHandle.pBanksProperties->factoryBankSize )
  133. #define NFMBASE_FLASH_BANK1_SIZE ( ExtMemHandle.pBanksProperties->userBankSize )
  134. #define NFMBASE_FLASH_BANK0_ADDRESS ( NFMBASE_FLASH_MIN_ADDRESS )
  135. #define NFMBASE_FLASH_BANK1_ADDRESS ( NFMBASE_FLASH_BANK0_ADDRESS + NFMBASE_FLASH_BANK0_SIZE )
  136. #define NFMBASE_FLASH_USERBANK0_MAKEREALADDRESS( addr ) (( (addr) & 0x7FFFFFFF ) + NFMBASE_FLASH_BANK0_ADDRESS )
  137. #define NFMBASE_FLASH_USERBANK1_MAKEREALADDRESS( addr ) (( (addr) & 0x7FFFFFFF ) + NFMBASE_FLASH_BANK1_ADDRESS )
  138. #define NFMBASE_FLASH_MAKEREALADDRESS( addr ) (\
  139. (NFMBASE_FLASH_USERBANK0_CHECK(addr))\
  140. ?(\
  141. NFMBASE_FLASH_USERBANK0_MAKEREALADDRESS(addr)\
  142. ):(\
  143. (NFMBASE_FLASH_USERBANK1_CHECK(addr))\
  144. ?(\
  145. NFMBASE_FLASH_USERBANK1_MAKEREALADDRESS(addr)\
  146. ):(\
  147. 0\
  148. )\
  149. ))
  150. //const sNFMMemoryProfile_t memProfile_SC2543v1_ADRF_NFM2543_v1 =
  151. //{
  152. // .BaseAddr_TComp = NFMBASE_FLASH_MAKEADDRESS_USERBANK0(MEMORY_OFFSET_BLOCK_THERMHEADER_SC2543),
  153. // .BaseAddr_Chrz[ eChFactory ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK0(MEMORY_OFFSET_BLOCK_DATAHEADER_SC2543),
  154. // .BaseAddr_Chrz[ eChUser1 ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER1DATA_SC2543),
  155. // .BaseAddr_Chrz[ eChUser2 ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER2DATA_SC2543),
  156. // .BaseAddr_Chrz[ eChUser3 ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER3DATA_SC2543),
  157. // .BaseAddr_Settings = SETTINGS_ADDR_SC2543,
  158. // .Size_Settings = SETTINGS_SIZE_SC2543,
  159. // .tbls_2Port = &tableMatrix_SC2543_2xPort_NFM_2543_v1
  160. //};
  161. //const sNFMMemoryProfile_t memProfile_NFM =
  162. //{
  163. // .BaseAddr_TComp = NFMBASE_FLASH_MAKEADDRESS_USERBANK0(MEMORY_OFFSET_BLOCK_THERMHEADER_SC2543),
  164. // .BaseAddr_Chrz[ eChFactory ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK0(MEMORY_OFFSET_BLOCK_DATAHEADER_SC2543),
  165. // .BaseAddr_Chrz[ eChUser1 ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER1DATA_SC2543),
  166. // .BaseAddr_Chrz[ eChUser2 ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER2DATA_SC2543),
  167. // .BaseAddr_Chrz[ eChUser3 ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER3DATA_SC2543),
  168. // .BaseAddr_Settings = SETTINGS_ADDR_SC2543,
  169. // .Size_Settings = SETTINGS_SIZE_SC2543,
  170. // .tbls_2Port = &tableMatrix_SC2543_2xPort_NFM_2543_v2
  171. //};
  172. const sSwitchMemoryProfile_t memProfile_SW =
  173. {
  174. .BaseAddr_SwTable = NFMBASE_FLASH_MAKEADDRESS_USERBANK0(MEMORY_OFFSET_BLOCK_THERMHEADER_SC2543),
  175. .BaseAddr_Table[ eChValues ] = NFMBASE_FLASH_MAKEADDRESS_USERBANK1(MEMORY_OFFSET_BLOCK_USER1DATA_SC2543),
  176. .BaseAddr_Settings = SETTINGS_ADDR_SC2543,
  177. .Size_Settings = SETTINGS_SIZE_SC2543,
  178. };
  179. //------------------------------------------------------------------------------
  180. // Set Flash Memory Bank0 Write-Protection
  181. bool NFM_ROM_SetMemoryProtectStatus_Bank0( bool desiredStatus )
  182. {
  183. return ExtMemHandle.BankProtect( extmem_bank_factory, desiredStatus );
  184. }
  185. //------------------------------------------------------------------------------
  186. // Get Flash Memory Bank0 Write-Protection status
  187. bool NFM_ROM_GetMemoryProtectStatus_Bank0()
  188. {
  189. bool status = false;
  190. if( ExtMemHandle.CheckBankProtect( extmem_bank_factory, &status ) )
  191. {
  192. return status; // report with the actual protection status
  193. }
  194. return false; // error, but report that bank is unprotected
  195. }
  196. //------------------------------------------------------------------------------
  197. static sEcalHeaderCRC_t * romGetCommonHeader( uint8_t * buffer, size_t size )
  198. {
  199. if( NULL == buffer || size < sizeof(sEcalHeaderCRC_t) )
  200. return NULL;
  201. /*
  202. size_t baseAddr = FLASH_USERBANK_0_ADDR;
  203. baseAddr += MEMORY_OFFSET_BLOCK_COMMON;
  204. */
  205. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMBASE_FLASH_MAKEADDRESS_USERBANK0( MEMORY_OFFSET_BLOCK_COMMON ) );
  206. if( FLASH_SUCCESS( flash_read( baseAddr, buffer, sizeof(sEcalHeaderCRC_t) ) ) )
  207. {
  208. return (sEcalHeaderCRC_t*)buffer;
  209. }
  210. return NULL;
  211. }
  212. // ------------------------------------------------------------------------------
  213. const sEcalHeader_t * NFM_ROM_GetCommonHeader( uint8_t * buffer, size_t size )
  214. {
  215. sEcalHeaderCRC_t * hdrcrc;
  216. TCRC crc;
  217. bool cacheUsed = false;
  218. if( NULL == buffer )
  219. {
  220. cacheUsed = true;
  221. if( RomBufCache_CommonHeader == g_RomBuffer_Cache )
  222. {
  223. hdrcrc = (sEcalHeaderCRC_t*)g_RomBuffer;
  224. goto L_NFM_ROM_GetCommonHeader_AlreadyCached;
  225. }
  226. buffer = (uint8_t*)g_RomBuffer;
  227. size = sizeof(g_RomBuffer);
  228. }
  229. if( NULL == buffer || size < sizeof(sEcalHeaderCRC_t) )
  230. {
  231. return NULL;
  232. }
  233. if( cacheUsed )
  234. {
  235. g_RomBuffer_Cache = RomBufCache_undefined;
  236. }
  237. hdrcrc = romGetCommonHeader( buffer, size );
  238. if( NULL == hdrcrc )
  239. {
  240. return NULL;
  241. }
  242. crc = ICRC32;
  243. crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sEcalHeader_t) );
  244. if( crc != hdrcrc->CRCValue )
  245. {
  246. return NULL;
  247. }
  248. if( cacheUsed )
  249. {
  250. g_RomBuffer_Cache = RomBufCache_CommonHeader;
  251. }
  252. L_NFM_ROM_GetCommonHeader_AlreadyCached:
  253. return (sEcalHeader_t *)hdrcrc;
  254. }
  255. //const sTableHeader_t * SW_ROM_GetCommonHeader( uint8_t * buffer, size_t size )
  256. //{
  257. // sTableHeaderCRC_t * hdrcrc;
  258. // TCRC crc;
  259. // bool cacheUsed = false;
  260. //
  261. // if( NULL == buffer )
  262. // {
  263. // cacheUsed = true;
  264. //
  265. // if( RomBufCache_CommonHeader == g_RomBuffer_Cache )
  266. // {
  267. // hdrcrc = (sTableHeaderCRC_t*)g_RomBuffer;
  268. // goto L_SW_ROM_GetCommonHeader_AlreadyCached;
  269. // }
  270. //
  271. // buffer = (uint8_t*)g_RomBuffer;
  272. // size = sizeof(g_RomBuffer);
  273. // }
  274. //
  275. // if( NULL == buffer || size < sizeof(sTableHeaderCRC_t) )
  276. // {
  277. // return NULL;
  278. // }
  279. //
  280. // if( cacheUsed )
  281. // {
  282. // g_RomBuffer_Cache = RomBufCache_undefined;
  283. // }
  284. //
  285. // hdrcrc = romSwGetCommonHeader( buffer, size );
  286. //
  287. // if( NULL == hdrcrc )
  288. // {
  289. // return NULL;
  290. // }
  291. //
  292. // crc = ICRC32;
  293. //
  294. // crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sTableHeader_t) );
  295. //
  296. // if( crc != hdrcrc->CRCValue )
  297. // {
  298. // return NULL;
  299. // }
  300. //
  301. // if( cacheUsed )
  302. // {
  303. // g_RomBuffer_Cache = RomBufCache_CommonHeader;
  304. // }
  305. //
  306. //L_SW_ROM_GetCommonHeader_AlreadyCached:
  307. //
  308. // return (sTableHeader_t *)hdrcrc;
  309. //}
  310. // ------------------------------------------------------------------------------
  311. // ------------------------------------------------------------------------------
  312. // ------------------------------------------------------------------------------
  313. static sEcalDataHeaderCRC_t * romGetDataHeader( size_t baseAddr, uint8_t * buffer, size_t size )
  314. {
  315. if( NULL == buffer || size < sizeof(sEcalDataHeaderCRC_t) )
  316. return NULL;
  317. if( FLASH_SUCCESS( flash_read( baseAddr, buffer, sizeof(sEcalDataHeaderCRC_t) ) ) )
  318. {
  319. return (sEcalDataHeaderCRC_t*)buffer;
  320. }
  321. return NULL;
  322. }
  323. static sTableTablePoint_t * romGetDataPoint( size_t baseAddr, uint8_t * buffer, size_t size )
  324. {
  325. if( NULL == buffer || size < sizeof(sTableTablePoint_t) )
  326. return NULL;
  327. if( FLASH_SUCCESS( flash_read( baseAddr, buffer, sizeof(sTableTablePoint_t) ) ) )
  328. {
  329. return (sTableTablePoint_t*)buffer;
  330. }
  331. return NULL;
  332. }
  333. static bool romSetDataPoint( size_t baseAddr, uint8_t * buffer, size_t size )
  334. {
  335. if( NULL == buffer || size < sizeof(sTableTablePoint_t) )
  336. return NULL;
  337. NFMClass->methods.xMemoryProtection.disable();
  338. if( FLASH_SUCCESS( flash_write( baseAddr, buffer, sizeof(sTableTablePoint_t), fwm_safewrite ) ) )
  339. {
  340. NFMClass->methods.xMemoryProtection.enable();
  341. return true;
  342. }
  343. NFMClass->methods.xMemoryProtection.enable();
  344. return NULL;
  345. }
  346. // ------------------------------------------------------------------------------
  347. const sEcalDataHeader_t * NFM_ROM_GetDataHeader( eChrz_t tableId, uint8_t * buffer, size_t size )
  348. {
  349. extern NFMClassEx_t * NFMClassExtended;
  350. sEcalDataHeaderCRC_t * hdrcrc;
  351. hdrcrc = (sEcalDataHeaderCRC_t*)g_RomBuffer;
  352. //TCRC crc;
  353. //bool cacheUsed = false;
  354. //size_t baseAddr = 0;
  355. // eRomBufCache_t cacheId = RomBufCache_undefined;
  356. //
  357. // switch( tableId )
  358. // {
  359. // case eChFactory : cacheId = RomBufCache_FactoryChrzHeader; break;
  360. // case eChUser1 : cacheId = RomBufCache_User1ChrzHeader ; break;
  361. // case eChUser2 : cacheId = RomBufCache_User2ChrzHeader ; break;
  362. // case eChUser3 : cacheId = RomBufCache_User3ChrzHeader ; break;
  363. // }
  364. //
  365. // if( NULL == buffer )
  366. // {
  367. // cacheUsed = true;
  368. //
  369. // if( cacheId == g_RomBuffer_Cache && RomBufCache_undefined != g_RomBuffer_Cache )
  370. // {
  371. // hdrcrc = (sEcalDataHeaderCRC_t*)g_RomBuffer;
  372. // goto L_NFM_ROM_GetDataHeader_AlreadyCached;
  373. // }
  374. //
  375. // buffer = (uint8_t*)g_RomBuffer;
  376. // size = sizeof(g_RomBuffer);
  377. // }
  378. //
  379. // if( NULL == NFMClassExtended->private.properties.memProfile )
  380. // {
  381. // return NULL;
  382. // }
  383. //
  384. // baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  385. // private.properties.memProfile->
  386. // BaseAddr_Chrz[ (tableId%eCh_MAX) ] );
  387. //
  388. // if( NULL == buffer || size < sizeof(sEcalDataHeaderCRC_t) )
  389. // {
  390. // return NULL;
  391. // }
  392. //
  393. // if( cacheUsed )
  394. // {
  395. // g_RomBuffer_Cache = RomBufCache_undefined;
  396. // }
  397. //
  398. // hdrcrc = romGetDataHeader( baseAddr, buffer, size );
  399. //
  400. // if( NULL == hdrcrc )
  401. // {
  402. // return NULL;
  403. // }
  404. //
  405. // crc = ICRC32;
  406. //
  407. // crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sEcalDataHeader_t) );
  408. //
  409. // if( crc != hdrcrc->CRCValue )
  410. // {
  411. // return NULL;
  412. // }
  413. //
  414. // if( cacheUsed )
  415. // {
  416. // g_RomBuffer_Cache = cacheId;
  417. // }
  418. //
  419. //L_NFM_ROM_GetDataHeader_AlreadyCached:
  420. //
  421. return (sEcalDataHeader_t *)hdrcrc;
  422. }
  423. // ------------------------------------------------------------------------------
  424. // -Table Header functions ------------------------------------------------------
  425. // ------------------------------------------------------------------------------
  426. static sTableHeaderCRC_t * romSetTableHeader( uint8_t * buffer, size_t size )
  427. {
  428. if( NULL == buffer || size < sizeof(sTableHeaderCRC_t) )
  429. return NULL;
  430. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMBASE_FLASH_MAKEADDRESS_USERBANK0( MEMORY_OFFSET_BLOCK_THERMHEADER_SC2543 ) );
  431. NFMClass->methods.xMemoryProtection.disable();
  432. if( FLASH_SUCCESS( flash_write( baseAddr, buffer, sizeof(sTableHeaderCRC_t), fwm_safewrite ) ) )
  433. {
  434. NFMClass->methods.xMemoryProtection.enable();
  435. return (sTableHeaderCRC_t*)buffer;
  436. }
  437. NFMClass->methods.xMemoryProtection.enable();
  438. return NULL;
  439. }
  440. static sTableHeaderCRC_t * romGetTableHeader( uint8_t * buffer, size_t size )
  441. {
  442. if( NULL == buffer || size < sizeof(sTableHeaderCRC_t) )
  443. return NULL;
  444. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMBASE_FLASH_MAKEADDRESS_USERBANK0( MEMORY_OFFSET_BLOCK_THERMHEADER_SC2543 ) );
  445. if( FLASH_SUCCESS( flash_read( baseAddr, buffer, sizeof(sTableHeaderCRC_t) ) ) )
  446. {
  447. return (sTableHeaderCRC_t*)buffer;
  448. }
  449. return NULL;
  450. }
  451. static bool SW_Validate_Table_Header_CRC ( sTableHeaderCRC_t * hdrcrc )
  452. {
  453. TCRC crc;
  454. crc = ICRC32;
  455. crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sTableHeader_t) );
  456. return hdrcrc->CRCValue == crc ;
  457. }
  458. sTableHeaderCRC_t * SW_ROM_GetTableHeader()
  459. {
  460. uint8_t * buffer = (uint8_t*)g_RomBuffer;
  461. size_t size = sizeof(g_RomBuffer);
  462. if( NULL == buffer || size < sizeof(sTableHeaderCRC_t) )
  463. {
  464. return false;
  465. }
  466. g_RomBuffer_Cache = RomBufCache_undefined;
  467. return romGetTableHeader( buffer, size );
  468. }
  469. bool SW_ROM_ChangeTableHeader( sTableHeaderCRC_t * hdrcrc )
  470. {
  471. extern NFMClassEx_t * NFMClassExtended;
  472. if(hdrcrc == NULL) return false;
  473. uint8_t * buffer = (uint8_t*)g_RomBuffer;
  474. size_t size = sizeof(g_RomBuffer);
  475. if( NULL == buffer || size < sizeof(sTableHeaderCRC_t) )
  476. {
  477. return false;
  478. }
  479. g_RomBuffer_Cache = RomBufCache_undefined;
  480. // Ïîñ÷èòàòü crc äàííûõ â òàáëèöå
  481. TCRC dataCrc;
  482. dataCrc = ICRC32;
  483. for(int i = 0; i < hdrcrc->Hdr.blocks; i++)
  484. {
  485. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  486. private.properties.memProfile->
  487. BaseAddr_Table[ (eChValues%eChValues_MAX) ] + i * hdrcrc->Hdr.size );
  488. sTableTablePoint_t TablePoint;
  489. romGetDataPoint( baseAddr, (uint8_t *)&TablePoint, sizeof(sTableTablePoint_t) );
  490. dataCrc = CRC32( dataCrc, (const unsigned char*)&TablePoint, sizeof(sTableTablePoint_t) );
  491. }
  492. // Ñ÷èòàåì crc õèäåðà
  493. TCRC crc;
  494. crc = ICRC32;
  495. crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sTableHeader_t) );
  496. hdrcrc->CRCValue = crc;
  497. hdrcrc = romSetTableHeader( (uint8_t *)hdrcrc, sizeof(sTableHeaderCRC_t) );
  498. if( !SW_Validate_Table_Header_CRC( hdrcrc ) )
  499. {
  500. // invalid common header
  501. // so, create new common header
  502. hdrcrc = (sTableHeaderCRC_t*)buffer;
  503. memset(hdrcrc, 0x00, sizeof(sTableHeaderCRC_t));
  504. return false;
  505. }
  506. return true;
  507. }
  508. uint16_t SW_ROM_GetNumberOfPoints()
  509. {
  510. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  511. if( NULL == TableHeader)
  512. {
  513. return 0;
  514. }
  515. return SW_Validate_Table_Header_CRC( TableHeader ) ? TableHeader->Hdr.blocks : 0;
  516. }
  517. // ------------------------------------------------------------------------------
  518. // - Table Data functions -------------------------------------------------------
  519. // ------------------------------------------------------------------------------
  520. // ------------------------------------------------------------------------------
  521. bool SW_ROM_SetDataPoint ( eChunks_t tableId, sTableTablePoint_t * TablePoint )
  522. {
  523. extern NFMClassEx_t * NFMClassExtended;
  524. if(NULL == TablePoint ||
  525. NULL == NFMClassExtended->private.properties.memProfile)
  526. {
  527. return false;
  528. }
  529. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  530. if( NULL == TableHeader)
  531. {
  532. return false;
  533. }
  534. // if( !SW_Validate_Table_Header_CRC( TableHeader ) )
  535. // {
  536. // memset(TableHeader, 0x00, sizeof(sTableHeaderCRC_t));
  537. // SW_ROM_ChangeTableHeader( TableHeader );
  538. // return false;
  539. // }
  540. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  541. private.properties.memProfile->
  542. BaseAddr_Table[ (tableId%eChValues_MAX) ] + TableHeader->Hdr.size );
  543. romSetDataPoint( baseAddr, (uint8_t *)TablePoint, sizeof(sTableTablePoint_t) );
  544. TableHeader->Hdr.blocks++;
  545. TableHeader->Hdr.size = TableHeader->Hdr.blocks * sizeof(sTableTablePoint_t);
  546. if( !SW_ROM_ChangeTableHeader( TableHeader ) )
  547. {
  548. return false;
  549. }
  550. return true;
  551. }
  552. const bool SW_ROM_GetDataPoint( eChunks_t tableId, uint8_t point_number, uint8_t * buffer, size_t size )
  553. {
  554. extern NFMClassEx_t * NFMClassExtended;
  555. sTableTablePoint_t * TablePoint;
  556. bool cacheUsed = false;
  557. size_t baseAddr = 0;
  558. eRomBufCache_t cacheId = RomBufCache_undefined;
  559. if( NULL == buffer )
  560. {
  561. cacheUsed = true;
  562. if( cacheId == g_RomBuffer_Cache && RomBufCache_undefined != g_RomBuffer_Cache )
  563. {
  564. TablePoint = (sTableTablePoint_t*)g_RomBuffer;
  565. goto L_NFM_ROM_GetDataHeader_AlreadyCached;
  566. }
  567. buffer = (uint8_t*)g_RomBuffer;
  568. size = sizeof(g_RomBuffer);
  569. }
  570. if( NULL == NFMClassExtended->private.properties.memProfile )
  571. {
  572. return NULL;
  573. }
  574. baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  575. private.properties.memProfile->
  576. BaseAddr_Table[ (tableId%eChValues_MAX) ] + point_number * sizeof(sTableTablePoint_t) );
  577. if( NULL == buffer || size < sizeof(sTableTablePoint_t) )
  578. {
  579. return NULL;
  580. }
  581. if( cacheUsed )
  582. {
  583. g_RomBuffer_Cache = RomBufCache_undefined;
  584. }
  585. // Ïðîâåðêà íà äîñòóïíîñòü çíà÷åíèÿ âî flash
  586. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  587. if( point_number >= TableHeader->Hdr.blocks ||
  588. !SW_Validate_Table_Header_CRC( TableHeader ) )
  589. {
  590. memset(TableHeader, 0x00, sizeof(sTableHeaderCRC_t));
  591. SW_ROM_ChangeTableHeader( TableHeader );
  592. return false;
  593. }
  594. if( NULL == TableHeader ||
  595. point_number >= TableHeader->Hdr.blocks)
  596. {
  597. return false;
  598. }
  599. TablePoint = romGetDataPoint( baseAddr, buffer, size );
  600. if( NULL == TablePoint )
  601. {
  602. return NULL;
  603. }
  604. if( cacheUsed )
  605. {
  606. g_RomBuffer_Cache = cacheId;
  607. }
  608. L_NFM_ROM_GetDataHeader_AlreadyCached:
  609. return true;
  610. }
  611. uint32_t SW_ROM_Get_Table_crc( eChunks_t tableId )
  612. {
  613. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  614. if( NULL == TableHeader)
  615. {
  616. return NULL;
  617. }
  618. TCRC crc;
  619. crc = ICRC32;
  620. sTableTablePoint_t TablePoint;
  621. for(int i = 0; i < TableHeader->Hdr.blocks; i++)
  622. {
  623. SW_ROM_GetDataPoint( tableId, i, (uint8_t *)&TablePoint, sizeof(sTableTablePoint_t) );
  624. crc = CRC32( crc, (const unsigned char*)&TablePoint, sizeof(sTableTablePoint_t) );
  625. }
  626. return crc;
  627. }
  628. bool SW_ROM_Set_Table_crc ( uint32_t crc )
  629. {
  630. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  631. if( NULL == TableHeader)
  632. {
  633. return false;
  634. }
  635. TableHeader->table_crc = crc;
  636. TableHeader = romSetTableHeader( (uint8_t *)TableHeader, sizeof(sTableHeaderCRC_t) );
  637. if( NULL == TableHeader)
  638. {
  639. return false;
  640. }
  641. return true;
  642. }
  643. bool SW_ROM_Check_Table_crc()
  644. {
  645. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  646. if( NULL == TableHeader)
  647. {
  648. return NULL;
  649. }
  650. uint32_t crc = SW_ROM_Get_Table_crc( eChValues );
  651. return TableHeader->table_crc == crc;
  652. }
  653. bool SW_ROM_Table_Clear()
  654. {
  655. sTableHeaderCRC_t * TableHeader = SW_ROM_GetTableHeader();
  656. if( NULL == TableHeader)
  657. {
  658. return false;
  659. }
  660. memset(TableHeader, 0x00, sizeof(sTableHeaderCRC_t) );
  661. TableHeader = romSetTableHeader( (uint8_t *)TableHeader, sizeof(sTableHeaderCRC_t) );
  662. if( NULL == TableHeader)
  663. {
  664. return false;
  665. }
  666. return true;
  667. }
  668. // ------------------------------------------------------------------------------
  669. // ------------------------------------------------------------------------------
  670. // ------------------------------------------------------------------------------
  671. static sEcalHeaderCRC_t * romSetCommonHeader( uint8_t * buffer, size_t size )
  672. {
  673. if( NULL == buffer || size < sizeof(sEcalHeaderCRC_t) )
  674. return NULL;
  675. /*
  676. size_t baseAddr = FLASH_USERBANK_0_ADDR;
  677. baseAddr += MEMORY_OFFSET_BLOCK_COMMON;
  678. */
  679. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMBASE_FLASH_MAKEADDRESS_USERBANK0( MEMORY_OFFSET_BLOCK_COMMON ) );
  680. if( FLASH_SUCCESS( flash_write( baseAddr, buffer, sizeof(sEcalHeaderCRC_t), fwm_safewrite ) ) )
  681. {
  682. return (sEcalHeaderCRC_t*)buffer;
  683. }
  684. return NULL;
  685. }
  686. // ------------------------------------------------------------------------------
  687. bool NFM_ROM_ChangeModel( eNFMModel_t modelId )
  688. {
  689. sEcalHeaderCRC_t * hdrcrc;
  690. TCRC crc;
  691. uint8_t * buffer = (uint8_t*)g_RomBuffer;
  692. size_t size = sizeof(g_RomBuffer);
  693. if( NULL == buffer || size < sizeof(sEcalHeaderCRC_t) )
  694. {
  695. return false;
  696. }
  697. g_RomBuffer_Cache = RomBufCache_undefined;
  698. hdrcrc = romGetCommonHeader( buffer, size );
  699. if( NULL == hdrcrc )
  700. {
  701. // invalid common header
  702. // so, create new common header
  703. hdrcrc = (sEcalHeaderCRC_t*)buffer;
  704. memset( hdrcrc->Hdr.SN, '0', sizeof(hdrcrc->Hdr.SN) );
  705. memset( hdrcrc->Hdr.Reserved1, 0, sizeof(hdrcrc->Hdr.Reserved1) );
  706. memset( hdrcrc->Hdr.Reserved2, 0, sizeof(hdrcrc->Hdr.Reserved2) );
  707. }
  708. hdrcrc->Hdr.DeviceID = (uint8_t)modelId;
  709. crc = ICRC32;
  710. crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sEcalHeader_t) );
  711. hdrcrc->CRCValue = crc;
  712. hdrcrc = romSetCommonHeader( buffer, size );
  713. if( NULL == hdrcrc )
  714. {
  715. return false;
  716. }
  717. return true;
  718. }
  719. //// ------------------------------------------------------------------------------
  720. bool NFM_ROM_ChangeSerialNumber( const char * serial )
  721. {
  722. sEcalHeaderCRC_t * hdrcrc;
  723. TCRC crc;
  724. uint8_t * buffer = (uint8_t*)g_RomBuffer;
  725. size_t size = sizeof(g_RomBuffer);
  726. if( NULL == buffer || size < sizeof(sEcalHeaderCRC_t) )
  727. {
  728. return false;
  729. }
  730. g_RomBuffer_Cache = RomBufCache_undefined;
  731. hdrcrc = romGetCommonHeader( buffer, size );
  732. if( NULL == hdrcrc )
  733. {
  734. // invalid common header
  735. // so, create new common header
  736. hdrcrc = (sEcalHeaderCRC_t*)buffer;
  737. memset( hdrcrc->Hdr.SN, '0', sizeof(hdrcrc->Hdr.SN) );
  738. memset( hdrcrc->Hdr.Reserved1, 0, sizeof(hdrcrc->Hdr.Reserved1) );
  739. memset( hdrcrc->Hdr.Reserved2, 0, sizeof(hdrcrc->Hdr.Reserved2) );
  740. }
  741. memcpy(hdrcrc->Hdr.SN, serial, sizeof(hdrcrc->Hdr.SN));
  742. crc = ICRC32;
  743. crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sEcalHeader_t) );
  744. hdrcrc->CRCValue = crc;
  745. hdrcrc = romSetCommonHeader( buffer, size );
  746. if( NULL == hdrcrc )
  747. {
  748. return false;
  749. }
  750. return true;
  751. }
  752. // ------------------------------------------------------------------------------
  753. // ------------------------------------------------------------------------------
  754. // ------------------------------------------------------------------------------
  755. static sEcalTCompHeaderCRC_t * romGetTCompHeader( uint8_t * buffer, size_t size )
  756. {
  757. extern NFMClassEx_t * NFMClassExtended;
  758. if( NULL == buffer || size < sizeof(sEcalTCompHeaderCRC_t) )
  759. return NULL;
  760. if( NULL == NFMClassExtended->private.properties.memProfile )
  761. return NULL;
  762. // size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->private.properties.memProfile->BaseAddr_TComp );
  763. //
  764. // if( FLASH_SUCCESS( flash_read( baseAddr, buffer, sizeof(sEcalTCompHeaderCRC_t) ) ) )
  765. // {
  766. // return (sEcalTCompHeaderCRC_t*)buffer;
  767. // }
  768. return NULL;
  769. }
  770. // ------------------------------------------------------------------------------
  771. const sEcalTCompHeader_t * NFM_ROM_GetTCompHeader( uint8_t * buffer, size_t size )
  772. {
  773. sEcalTCompHeaderCRC_t * hdrcrc;
  774. TCRC crc;
  775. bool cacheUsed = false;
  776. if( NULL == buffer )
  777. {
  778. cacheUsed = true;
  779. if( RomBufCache_TCompHeader == g_RomBuffer_Cache )
  780. {
  781. hdrcrc = (sEcalTCompHeaderCRC_t*)g_RomBuffer;
  782. goto L_NFM_ROM_GetTCompHeader_AlreadyCached;
  783. }
  784. buffer = (uint8_t*)g_RomBuffer;
  785. size = sizeof(g_RomBuffer);
  786. }
  787. if( NULL == buffer || size < sizeof(sEcalTCompHeaderCRC_t) )
  788. {
  789. return NULL;
  790. }
  791. if( cacheUsed )
  792. {
  793. g_RomBuffer_Cache = RomBufCache_undefined;
  794. }
  795. hdrcrc = romGetTCompHeader( buffer, size );
  796. if( NULL == hdrcrc )
  797. {
  798. return NULL;
  799. }
  800. crc = ICRC32;
  801. crc = CRC32( crc, (const unsigned char*)hdrcrc, sizeof(sEcalTCompHeader_t) );
  802. if( crc != hdrcrc->CRCValue )
  803. {
  804. return NULL;
  805. }
  806. if( cacheUsed )
  807. {
  808. g_RomBuffer_Cache = RomBufCache_TCompHeader;
  809. }
  810. L_NFM_ROM_GetTCompHeader_AlreadyCached:
  811. return (sEcalTCompHeader_t *)hdrcrc;
  812. }
  813. // ------------------------------------------------------------------------------
  814. // ------------------------------------------------------------------------------
  815. // ------------------------------------------------------------------------------
  816. size_t NFM_ROM_GetChrzTableIndex( ePortComb_t portCombination, ePortStateId_t portState )
  817. {
  818. // extern NFMClassEx_t * NFMClassExtended;
  819. //
  820. // if( ePortComb_MAX <= portCombination
  821. // || ePortComb_UNDEFINED == portCombination
  822. // || ePortStateId_MAX <= portState
  823. // || ePortStateId_UNDEFINED == portState
  824. // )
  825. // {
  826. // return (NFM_CHRZ_TABLEIDX_INVALID);
  827. // }
  828. //
  829. // if(
  830. // NULL == NFMClassExtended->private.properties.memProfile
  831. // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw )
  832. // {
  833. // return (NFM_CHRZ_TABLEIDX_INVALID);
  834. // }
  835. //
  836. // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile_XPort = NFMClassExtended->private.properties.memProfile->tbls_raw;
  837. // const sNFMMemory_ChrzTableMatrix_2Port_t * tableProfile_2Port = NFMClassExtended->private.properties.memProfile->tbls_2Port;
  838. // const sNFMMemory_ChrzTableMatrix_4Port_t * tableProfile_4Port = NFMClassExtended->private.properties.memProfile->tbls_4Port;
  839. //
  840. // if( ePortComb_MIN_SINGLE_XPort <= portCombination
  841. // && ePortComb_MAX_SINGLE_XPort >= portCombination )
  842. // {
  843. // switch(tableProfile_XPort->Header.ChrzTableType.eType)
  844. // {
  845. // case eNfmChrzTable2Port:
  846. // {
  847. // if( ePortComb_MIN_SINGLE_2Port <= portCombination
  848. // && ePortComb_MAX_SINGLE_2Port >= portCombination )
  849. // {
  850. // if( ePortStateId_MIN_SINGLE_2Port <= portState
  851. // && ePortStateId_MAX_SINGLE_2Port >= portState )
  852. // {
  853. // return tableProfile_2Port->Single.aArray[
  854. // (size_t)(portCombination - ePortComb_MIN_SINGLE_2Port)
  855. // ].aBaseIndex [
  856. // (size_t)(portState - ePortStateId_MIN_SINGLE_2Port)
  857. // ];
  858. // }
  859. // }
  860. // }
  861. // break;
  862. // case eNfmChrzTable4Port:
  863. // {
  864. // if( ePortComb_MIN_SINGLE_4Port <= portCombination
  865. // && ePortComb_MAX_SINGLE_4Port >= portCombination )
  866. // {
  867. // if( ePortStateId_MIN_SINGLE_4Port <= portState
  868. // && ePortStateId_MAX_SINGLE_4Port >= portState )
  869. // {
  870. // return tableProfile_4Port->Single.aArray[
  871. // (size_t)(portCombination - ePortComb_MIN_SINGLE_4Port)
  872. // ].aBaseIndex [
  873. // (size_t)(portState - ePortStateId_MIN_SINGLE_4Port)
  874. // ];
  875. // }
  876. // }
  877. // }
  878. // break;
  879. // }
  880. //
  881. // return 0; // unsupported characterization table type
  882. // }
  883. // else
  884. // if( ePortComb_MIN_THRU_XPort <= portCombination
  885. // && ePortComb_MAX_THRU_XPort >= portCombination )
  886. // {
  887. // switch(tableProfile_XPort->Header.ChrzTableType.eType)
  888. // {
  889. // case eNfmChrzTable2Port:
  890. // {
  891. // if( ePortComb_MIN_THRU_2Port <= portCombination
  892. // && ePortComb_MAX_THRU_2Port >= portCombination )
  893. // {
  894. // if( ePortStateId_MIN_THRU_2Port <= portState
  895. // && ePortStateId_MAX_THRU_2Port >= portState )
  896. // {
  897. // return tableProfile_2Port->Thru.aArrays[
  898. // (size_t)(portCombination - ePortComb_MIN_THRU_2Port)
  899. // ].aBaseIndex [
  900. // (size_t)(portState - ePortStateId_MIN_THRU_2Port)
  901. // ];
  902. // }
  903. // }
  904. // }
  905. // break;
  906. // case eNfmChrzTable4Port:
  907. // {
  908. // if( ePortComb_MIN_THRU_4Port <= portCombination
  909. // && ePortComb_MAX_THRU_4Port >= portCombination )
  910. // {
  911. // if( ePortStateId_MIN_THRU_4Port <= portState
  912. // && ePortStateId_MAX_THRU_4Port >= portState )
  913. // {
  914. // return tableProfile_4Port->Thru.aArrays[
  915. // (size_t)(portCombination - ePortComb_MIN_THRU_4Port)
  916. // ].aBaseIndex [
  917. // (size_t)(portState - ePortStateId_MIN_THRU_4Port)
  918. // ];
  919. // }
  920. // }
  921. // }
  922. // break;
  923. // }
  924. //
  925. // return 0; // unsupported characterization table type
  926. // }
  927. // else
  928. // if( ePortComb_CHECK == portCombination )
  929. // {
  930. // if( ePortStateId_MIN_CHECK_XPort <= portState
  931. // && ePortStateId_MAX_CHECK_XPort >= portState )
  932. // {
  933. // switch(tableProfile_XPort->Header.ChrzTableType.eType)
  934. // {
  935. // case eNfmChrzTable2Port:
  936. // {
  937. // if( ePortStateId_MIN_CHECK_2Port <= portState
  938. // && ePortStateId_MAX_CHECK_2Port >= portState )
  939. // {
  940. // return tableProfile_2Port->Check.sArray
  941. // .aBaseIndex[
  942. // (size_t)(portState - ePortStateId_MIN_CHECK_2Port)
  943. // ];
  944. // }
  945. // }
  946. // break;
  947. // case eNfmChrzTable4Port:
  948. // {
  949. // if( ePortStateId_MIN_CHECK_4Port <= portState
  950. // && ePortStateId_MAX_CHECK_4Port >= portState )
  951. // {
  952. // return tableProfile_4Port->Check.sArray
  953. // .aBaseIndex[
  954. // (size_t)(portState - ePortStateId_MIN_CHECK_4Port)
  955. // ];
  956. // }
  957. // }
  958. // break;
  959. // }
  960. //
  961. // return 0; // unsupported characterization table type
  962. // }
  963. // }
  964. return (NFM_CHRZ_TABLEIDX_INVALID);
  965. }
  966. size_t NFM_ROM_GetTCompTableIndex( ePortComb_t portCombination, ePortStateId_t portState )
  967. {
  968. extern NFMClassEx_t * NFMClassExtended;
  969. return NFMClassExtended->private.methods.memory.getChrzTableIndex( portCombination, portState );
  970. }
  971. // ------------------------------------------------------------------------------
  972. // ------------------------------------------------------------------------------
  973. // ------------------------------------------------------------------------------
  974. // NFM_ROM_ReadChrzTableHeader:
  975. // Reads the characterization table header by port combination (e.g. A,B, CD, CHECK),
  976. // the port state (LOAD, SHORT, S11...), amount of points in the table (@nPoints) and
  977. // the sector identifier (@sectorId).
  978. // The amount of points must be retrieved before the call and passed into the function.
  979. // You can use NFM_ROM_GetDataHeader() for this purpose.
  980. // The table will be validated by calculating CRC.
  981. // The function returns the base address of the table only in case
  982. // all the conditions listed below are valid:
  983. // - current device model has valid memory profile;
  984. // - tableIdx is valid and not exceed the maximum table index for current memory profile;
  985. // - nPoints is non-zero;
  986. // - pHeader is non-NULL;
  987. // - talbe has valid CRC;
  988. // Otherwise, the function returns 0.
  989. size_t NFM_ROM_ReadChrzTableHeader( eChrz_t sectorId,
  990. ePortComb_t portCombination,
  991. ePortStateId_t portState,
  992. size_t nPoints, // @nPoints = amount of points in the table
  993. sEcalChrzTableHeader_t * pHeader,
  994. unsigned int * pErrCode
  995. )
  996. {
  997. extern NFMClassEx_t * NFMClassExtended;
  998. // size_t tableIdx = NFM_CHRZ_TABLEIDX_INVALID;
  999. //
  1000. // if(
  1001. // NULL == NFMClassExtended->private.properties.memProfile
  1002. // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw
  1003. // || NULL == pHeader
  1004. // || 0 == nPoints
  1005. // || NULL == pErrCode
  1006. // )
  1007. // {
  1008. // if( NULL != pErrCode )
  1009. // *pErrCode = ERR_NFMGETPOINTS_INVAL;
  1010. //
  1011. // // Invalid parameters or model properties
  1012. // return 0;
  1013. // }
  1014. //
  1015. // /*
  1016. // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile = NFMClassExtended->private.properties->memProfile->tbls_raw;
  1017. //
  1018. // if( tableIdx > tableProfile->Header.maxTableIdx )
  1019. // {
  1020. // // invalid table index
  1021. // return 0;
  1022. // }
  1023. // */
  1024. //
  1025. // // Validate the combination of @portCombination, @portState and
  1026. // // validate the @portCombination and @portState itself.
  1027. // // Retrieve the table index (ordered index)
  1028. // tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portCombination, portState );
  1029. //
  1030. // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  1031. // {
  1032. // *pErrCode = ERR_NFMGETPOINTS_INVAL;
  1033. //
  1034. // // Invalid combination or value
  1035. // return 0;
  1036. // }
  1037. //
  1038. // // Retireve the table index offset
  1039. // size_t tableOffset = NFM_CHRZ_TABLEIDX_2_OFFSET( tableIdx );
  1040. //
  1041. // // Calculate the table offset
  1042. // tableOffset *= SIZE_CHRZ_TABLE( nPoints );
  1043. //
  1044. // // shift the offset by the characterization main header
  1045. // tableOffset += SIZE_CHRZ_HEADER;
  1046. //
  1047. // // add the base address of characterization sector to the table offset
  1048. // // to get absolute address
  1049. // tableOffset += NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  1050. // private.properties.memProfile->
  1051. // BaseAddr_Chrz[ (sectorId%eCh_MAX) ] );
  1052. //
  1053. // // Validate the table
  1054. // {
  1055. // // use internal buffer
  1056. // g_RomBuffer_Cache = RomBufCache_undefined;
  1057. //
  1058. // size_t nBytes = SIZE_CHRZ_TABLE( nPoints ) - SIZE_CHRZ_TCRC;
  1059. // size_t baseAddr = tableOffset;
  1060. //
  1061. // uint8_t * buffer = g_RomBuffer;
  1062. // size_t bufferSize = sizeof(g_RomBuffer);
  1063. //
  1064. // TCRC crc = ICRC32;
  1065. //
  1066. // while( nBytes > 0 )
  1067. // {
  1068. // if( bufferSize > nBytes )
  1069. // {
  1070. // bufferSize = nBytes;
  1071. // }
  1072. //
  1073. // if( ! FLASH_SUCCESS( flash_read( baseAddr, buffer, bufferSize ) ) )
  1074. // {
  1075. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1076. //
  1077. // // i/o error
  1078. // return 0;
  1079. // }
  1080. //
  1081. // baseAddr += bufferSize;
  1082. // nBytes -= bufferSize;
  1083. //
  1084. // crc = CRC32( crc, buffer, bufferSize );
  1085. // }
  1086. //
  1087. // if( ! FLASH_SUCCESS( flash_read( baseAddr, buffer, SIZE_CHRZ_TCRC ) ) )
  1088. // {
  1089. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1090. //
  1091. // // i/o error
  1092. // return 0;
  1093. // }
  1094. // else if( *((TCRC*)buffer) != crc )
  1095. // {
  1096. // *pErrCode = ERR_NFMGETPOINTS_INVTBL;
  1097. //
  1098. // // crc error
  1099. // return 0;
  1100. // }
  1101. // }
  1102. //
  1103. // // actually read the header
  1104. // if( ! FLASH_SUCCESS( flash_read( tableOffset, (uint8_t*)pHeader, SIZE_CHRZ_THDR ) ) )
  1105. // {
  1106. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1107. //
  1108. // // i/o error
  1109. // return 0;
  1110. // }
  1111. //
  1112. // *pErrCode = ERR_NFMGETPOINTS_NOERR;
  1113. //
  1114. // return tableOffset;
  1115. return 0;
  1116. }
  1117. // ------------------------------------------------------------------------------
  1118. // ------------------------------------------------------------------------------
  1119. // ------------------------------------------------------------------------------
  1120. // NFM_ROM_ReadChrzTablePoints:
  1121. // Loads the characterization data points from the memory.
  1122. // The input parameters - only @pContext, which contains all required information:
  1123. // - @.TableAddress = depends on the selected memory segment and the selected table
  1124. // - @.nCount = amount of points to load
  1125. // - @.nStartPoint = the offset in "points" of starting point
  1126. // - @.pDataArray = the memory buffer to fill with the data
  1127. // Note: this structure must be initialized firstly by @NFM_ROM_ReadChrzTableHeader()
  1128. // call (aka @NFMClassExtended->private.methods.memory.getChrzTableHeader() )
  1129. size_t NFM_ROM_ReadChrzTablePoints( /*const*/ sNFMGetPoints_t * pContext )
  1130. {
  1131. // check the input parameters
  1132. if( NULL == pContext
  1133. || 0 == pContext->in.nCount
  1134. || NULL == pContext->in.pDataArray
  1135. || 0 == pContext->out.nPoints
  1136. || 0 == pContext->out.TableAddress )
  1137. {
  1138. if( NULL != pContext )
  1139. pContext->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1140. return 0; // error
  1141. }
  1142. // initialize the first requested point offset
  1143. size_t
  1144. // by the table address
  1145. pointOffset = pContext->out.TableAddress;
  1146. // and shift it by the table header size
  1147. pointOffset += SIZE_CHRZ_THDR;
  1148. // and shift it by the size of skipped points
  1149. pointOffset += pContext->in.nStartPoint * SIZE_CHRZ_TPNT;
  1150. // use internal buffer
  1151. g_RomBuffer_Cache = RomBufCache_undefined;
  1152. // read the points contineously
  1153. for( size_t n = 0; n < pContext->in.nCount; (void)n )
  1154. {
  1155. // calculate amount of points available to be cached
  1156. size_t nPointsRead = sizeof(g_RomBuffer) / SIZE_CHRZ_TPNT;
  1157. // limit amount of points to be read by the number of required points
  1158. if( nPointsRead > (pContext->in.nCount-n) )
  1159. {
  1160. nPointsRead = (pContext->in.nCount-n);
  1161. }
  1162. // actually read the points
  1163. if( ! FLASH_SUCCESS( flash_read( // Read the points
  1164. pointOffset, // with the specified offset of current point
  1165. g_RomBuffer, // into the internal buffer,
  1166. nPointsRead * SIZE_CHRZ_TPNT // and read only @nPointsRead points
  1167. ))
  1168. )
  1169. {
  1170. pContext->svc.errCode = ERR_NFMGETPOINTS_IO;
  1171. // i/o error
  1172. return 0;
  1173. }
  1174. // cast the buffer @g_RomBuffer to the [sEcalChrzTablePoint_t] array
  1175. const sEcalChrzTablePoint_t * pComplexPoints = (sEcalChrzTablePoint_t*)g_RomBuffer;
  1176. // Convert each of @nPointsRead data points from 24-bit format into the double format
  1177. for( size_t iPoint = 0; iPoint < nPointsRead; ++iPoint )
  1178. {
  1179. // magnitude
  1180. {
  1181. int32_t data24bit; // 24-bit value in the memory is signed value
  1182. {
  1183. uint32_t U_data24bit;
  1184. // Retrieve the 24-bit data of magnitude
  1185. U_data24bit = ((uint32_t)pComplexPoints[iPoint].Magn) << 0; // low 16-bits
  1186. U_data24bit |= ((uint32_t)pComplexPoints[iPoint].Magn2) << 16; // high 8-bits
  1187. // check the sign bit
  1188. if( U_data24bit & (1<<23) )
  1189. {
  1190. // negative value
  1191. U_data24bit ^= 0xFFFFFF;
  1192. U_data24bit += 0x000001;
  1193. // convert to signed variable
  1194. data24bit = -((int32_t)U_data24bit);
  1195. }
  1196. else
  1197. {
  1198. // positive value
  1199. // convert to signed variable
  1200. data24bit = ((int32_t)U_data24bit);
  1201. }
  1202. }
  1203. // Convert the 24-bit data into the double
  1204. // 24-bit data is amount of descrettes of ((max-min)/16777215)
  1205. // where @min and @max is a magintude value in 0.01dB discrettes
  1206. //#define MAGN24_2_DOUBLE(data24bit,min,max) (((data24bit) / (double)16777215.0f) * ((double)( (max) - (min) ) / (double)100.0f))
  1207. #define MAGN24_2_DOUBLE(data24bit,min,max) ( (data24bit) * ((((double)( (max) - (min) )) / ((double)100.0)) / (double)16777215.0) + (((double)( (max) + (min) )) / 200.0))
  1208. // store the result into the output double array
  1209. pContext->in.pDataArray[ n + iPoint ].magn = MAGN24_2_DOUBLE( data24bit, pContext->out.min, pContext->out.max );
  1210. }
  1211. // phase
  1212. {
  1213. int32_t data24bit = 0; // 24-bit value in the memory is signed value
  1214. {
  1215. uint32_t U_data24bit;
  1216. // Retrieve the 24-bit data of phase
  1217. U_data24bit = ((uint32_t)pComplexPoints[iPoint].Angle) << 0; // low 16-bits
  1218. U_data24bit |= ((uint32_t)pComplexPoints[iPoint].Angle2) << 16; // high 8-bits
  1219. // check the sign bit
  1220. if( U_data24bit & (1<<23) )
  1221. {
  1222. // negative value
  1223. U_data24bit ^= 0xFFFFFF;
  1224. U_data24bit += 0x000001;
  1225. // convert to signed variable
  1226. data24bit = -((int32_t)U_data24bit);
  1227. }
  1228. else
  1229. {
  1230. // positive value
  1231. // convert to signed variable
  1232. data24bit = ((int32_t)U_data24bit);
  1233. }
  1234. }
  1235. // Convert the 24-bit data into the double
  1236. // 24-bit data is amount of descrettes of (PI/0x7FFFFF)
  1237. #define PI (3.141592653589793238462643)
  1238. #define R2D (180.0/PI)
  1239. #define PHAS24_2_DOUBLE(data24bit) (((data24bit) / (double)8388607.0f) * (double)(PI))
  1240. #define PHAS_RAD_2_DEG( rad ) ((rad)*(R2D))
  1241. // store the result into the output double array
  1242. pContext->in.pDataArray[ n + iPoint ].phase = PHAS_RAD_2_DEG(PHAS24_2_DOUBLE( data24bit ));
  1243. }
  1244. }
  1245. // decrease amount of points to read
  1246. n += nPointsRead;
  1247. // shift the address
  1248. pointOffset += nPointsRead * SIZE_CHRZ_TPNT;
  1249. }
  1250. pContext->svc.errCode = ERR_NFMGETPOINTS_NOERR;
  1251. // return amount of points
  1252. return pContext->in.nCount;
  1253. }
  1254. // ------------------------------------------------------------------------------
  1255. // ------------------------------------------------------------------------------
  1256. // ------------------------------------------------------------------------------
  1257. // NFM_ROM_GetTCompMagnTableHeader:
  1258. // Reads the thermocompensation magnitude table header by port combination (e.g. A,B, CD, CHECK),
  1259. // the port state (LOAD, SHORT, S11...), amount of points in the table (@nPoints) and
  1260. // the sector identifier (@sectorId).
  1261. // The amount of points must be retrieved before the call and passed into the function.
  1262. // You can use NFM_ROM_GetTCompHeader() for this purpose.
  1263. // The table will be validated by calculating CRC.
  1264. // The function returns the base address of the table only in case
  1265. // all the conditions listed below are valid:
  1266. // - current device model has valid memory profile;
  1267. // - tableIdx is valid and not exceed the maximum table index for current memory profile;
  1268. // - nPoints is non-zero;
  1269. // - pHeader is non-NULL;
  1270. // - talbe has valid CRC;
  1271. // Otherwise, the function returns 0.
  1272. size_t NFM_ROM_GetTCompMagnTableHeader( ePortComb_t portCombination, ePortStateId_t portState,
  1273. size_t nPoints, sEcalTCompTableMagnHeader_t * pHeader,
  1274. unsigned int * pErrCode
  1275. )
  1276. {
  1277. extern NFMClassEx_t * NFMClassExtended;
  1278. return 0;
  1279. // size_t tableIdx = NFM_CHRZ_TABLEIDX_INVALID;
  1280. //
  1281. // if(
  1282. // NULL == NFMClassExtended->private.properties.memProfile
  1283. // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw
  1284. // || NULL == pHeader
  1285. // || 0 == nPoints )
  1286. // {
  1287. // if( NULL != pErrCode )
  1288. // *pErrCode = ERR_NFMGETPOINTS_INVAL;
  1289. //
  1290. // // Invalid parameters or model properties
  1291. // return 0;
  1292. // }
  1293. //
  1294. // /*
  1295. // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile = NFMClassExtended->private.properties->memProfile->tbls_raw;
  1296. //
  1297. // if( tableIdx > tableProfile->Header.maxTableIdx )
  1298. // {
  1299. // // invalid table index
  1300. // return 0;
  1301. // }
  1302. // */
  1303. //
  1304. // // Validate the combination of @portCombination, @portState and
  1305. // // validate the @portCombination and @portState itself.
  1306. // // Retrieve the table index (ordered index)
  1307. // tableIdx = NFMClassExtended->private.methods.memory.getTCompTableIndex( portCombination, portState );
  1308. //
  1309. // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  1310. // {
  1311. // *pErrCode = ERR_NFMGETPOINTS_INVAL;
  1312. //
  1313. // // Invalid combination or value
  1314. // return 0;
  1315. // }
  1316. //
  1317. // // Retireve the table index offset
  1318. // size_t tableOffset = NFM_TCOMP_MAGN_TABLEIDX_2_OFFSET( tableIdx );
  1319. //
  1320. // // Calculate the table offset
  1321. // tableOffset *= SIZE_TCOMP_MAGN_TABLE( nPoints );
  1322. //
  1323. // // shift the offset by the thermocompensation main header
  1324. // tableOffset += SIZE_TCOMP_HEADER;
  1325. //
  1326. // // add the base address of thermocompensation sector to the table offset
  1327. // // to get absolute address
  1328. // tableOffset += NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  1329. // private.properties.memProfile->
  1330. // BaseAddr_TComp );
  1331. //
  1332. // // Validate the table
  1333. // {
  1334. // // use internal buffer
  1335. // g_RomBuffer_Cache = RomBufCache_undefined;
  1336. //
  1337. // size_t nBytes = SIZE_TCOMP_MAGN_TABLE( nPoints ) - SIZE_TCOMP_TCRC;
  1338. // size_t baseAddr = tableOffset;
  1339. //
  1340. // uint8_t * buffer = g_RomBuffer;
  1341. // size_t bufferSize = sizeof(g_RomBuffer);
  1342. //
  1343. // TCRC crc = ICRC32;
  1344. //
  1345. // while( nBytes > 0 )
  1346. // {
  1347. // if( bufferSize > nBytes )
  1348. // {
  1349. // bufferSize = nBytes;
  1350. // }
  1351. //
  1352. // if( ! FLASH_SUCCESS( flash_read( baseAddr, buffer, bufferSize ) ) )
  1353. // {
  1354. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1355. //
  1356. // // i/o error
  1357. // return 0;
  1358. // }
  1359. //
  1360. // baseAddr += bufferSize;
  1361. // nBytes -= bufferSize;
  1362. //
  1363. // crc = CRC32( crc, buffer, bufferSize );
  1364. // }
  1365. //
  1366. // if( ! FLASH_SUCCESS( flash_read( baseAddr, buffer, SIZE_TCOMP_TCRC ) ) )
  1367. // {
  1368. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1369. //
  1370. // // i/o error
  1371. // return 0;
  1372. // }
  1373. // else if( *((TCRC*)buffer) != crc )
  1374. // {
  1375. // *pErrCode = ERR_NFMGETPOINTS_INVTBL;
  1376. //
  1377. // // crc error
  1378. // return 0;
  1379. // }
  1380. // }
  1381. //
  1382. // // actually read the header
  1383. // if( ! FLASH_SUCCESS( flash_read( tableOffset, (uint8_t*)pHeader, SIZE_TCOMP_MAGN_THDR ) ) )
  1384. // {
  1385. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1386. //
  1387. // // i/o error
  1388. // return 0;
  1389. // }
  1390. //
  1391. // *pErrCode = ERR_NFMGETPOINTS_NOERR;
  1392. //
  1393. // return tableOffset;
  1394. }
  1395. // NFM_ROM_GetTCompPhaseTableHeader:
  1396. // Reads the thermocompensation phase table header by port combination (e.g. A,B, CD, CHECK),
  1397. // the port state (LOAD, SHORT, S11...), amount of points in the table (@nPoints) and
  1398. // the sector identifier (@sectorId).
  1399. // The amount of points must be retrieved before the call and passed into the function.
  1400. // You can use NFM_ROM_GetTCompHeader() for this purpose.
  1401. // The table will be validated by calculating CRC.
  1402. // The function returns the base address of the table only in case
  1403. // all the conditions listed below are valid:
  1404. // - current device model has valid memory profile;
  1405. // - tableIdx is valid and not exceed the maximum table index for current memory profile;
  1406. // - nPoints is non-zero;
  1407. // - pHeader is non-NULL;
  1408. // - talbe has valid CRC;
  1409. // Otherwise, the function returns 0.
  1410. size_t NFM_ROM_GetTCompPhaseTableHeader( ePortComb_t portCombination, ePortStateId_t portState,
  1411. size_t nPoints, sEcalTCompTablePhaseHeader_t * pHeader,
  1412. unsigned int * pErrCode
  1413. )
  1414. {
  1415. extern NFMClassEx_t * NFMClassExtended;
  1416. // size_t tableIdx = NFM_CHRZ_TABLEIDX_INVALID;
  1417. //
  1418. // if(
  1419. // NULL == NFMClassExtended->private.properties.memProfile
  1420. // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw
  1421. // || NULL == pHeader
  1422. // || 0 == nPoints
  1423. // || NULL == pErrCode
  1424. // )
  1425. // {
  1426. // if( NULL != pErrCode )
  1427. // *pErrCode = ERR_NFMGETPOINTS_INVAL;
  1428. //
  1429. // // Invalid parameters or model properties
  1430. // return 0;
  1431. // }
  1432. //
  1433. // /*
  1434. // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile = NFMClassExtended->private.properties->memProfile->tbls_raw;
  1435. //
  1436. // if( tableIdx > tableProfile->Header.maxTableIdx )
  1437. // {
  1438. // // invalid table index
  1439. // return 0;
  1440. // }
  1441. // */
  1442. //
  1443. // // Validate the combination of @portCombination, @portState and
  1444. // // validate the @portCombination and @portState itself.
  1445. // // Retrieve the table index (ordered index)
  1446. // tableIdx = NFMClassExtended->private.methods.memory.getTCompTableIndex( portCombination, portState );
  1447. //
  1448. // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  1449. // {
  1450. // *pErrCode = ERR_NFMGETPOINTS_INVAL;
  1451. //
  1452. // // Invalid combination or value
  1453. // return 0;
  1454. // }
  1455. //
  1456. // // Retireve the table index offset
  1457. // size_t tableOffset = NFM_TCOMP_PHASE_TABLEIDX_2_OFFSET( tableIdx );
  1458. //
  1459. // // Calculate the table offset
  1460. // tableOffset *= SIZE_TCOMP_PHASE_TABLE( nPoints );
  1461. //
  1462. // // shift the offset by the thermocompensation main header
  1463. // tableOffset += SIZE_TCOMP_HEADER;
  1464. //
  1465. // // add the base address of thermocompensation sector to the table offset
  1466. // // to get absolute address
  1467. // tableOffset += NFMBASE_FLASH_MAKEREALADDRESS( NFMClassExtended->
  1468. // private.properties.memProfile->
  1469. // BaseAddr_TComp );
  1470. //
  1471. // // Validate the table
  1472. // {
  1473. // // use internal buffer
  1474. // g_RomBuffer_Cache = RomBufCache_undefined;
  1475. //
  1476. // size_t nBytes = SIZE_TCOMP_PHASE_TABLE( nPoints ) - SIZE_TCOMP_TCRC;
  1477. // size_t baseAddr = tableOffset;
  1478. //
  1479. // uint8_t * buffer = g_RomBuffer;
  1480. // size_t bufferSize = sizeof(g_RomBuffer);
  1481. //
  1482. // TCRC crc = ICRC32;
  1483. //
  1484. // while( nBytes > 0 )
  1485. // {
  1486. // if( bufferSize > nBytes )
  1487. // {
  1488. // bufferSize = nBytes;
  1489. // }
  1490. //
  1491. // if( ! FLASH_SUCCESS( flash_read( baseAddr, buffer, bufferSize ) ) )
  1492. // {
  1493. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1494. //
  1495. // // i/o error
  1496. // return 0;
  1497. // }
  1498. //
  1499. // baseAddr += bufferSize;
  1500. // nBytes -= bufferSize;
  1501. //
  1502. // crc = CRC32( crc, buffer, bufferSize );
  1503. // }
  1504. //
  1505. // if( ! FLASH_SUCCESS( flash_read( baseAddr, buffer, SIZE_TCOMP_TCRC ) ) )
  1506. // {
  1507. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1508. //
  1509. // // i/o error
  1510. // return 0;
  1511. // }
  1512. // else if( *((TCRC*)buffer) != crc )
  1513. // {
  1514. // *pErrCode = ERR_NFMGETPOINTS_INVTBL;
  1515. //
  1516. // // crc error
  1517. // return 0;
  1518. // }
  1519. // }
  1520. //
  1521. // // actually read the header
  1522. // if( ! FLASH_SUCCESS( flash_read( tableOffset, (uint8_t*)pHeader, SIZE_TCOMP_PHASE_THDR ) ) )
  1523. // {
  1524. // *pErrCode = ERR_NFMGETPOINTS_IO;
  1525. //
  1526. // // i/o error
  1527. // return 0;
  1528. // }
  1529. //
  1530. // *pErrCode = ERR_NFMGETPOINTS_NOERR;
  1531. //
  1532. // return tableOffset;
  1533. return 0;
  1534. }
  1535. size_t NFM_ROM_GetTCompMagnPoints( /*const*/ sNFMGetPoints_t * pContext )
  1536. {
  1537. // check the input parameters
  1538. if( NULL == pContext
  1539. || 0 == pContext->in.nCount
  1540. || NULL == pContext->in.pDataArray
  1541. || 0 == pContext->out.nPoints
  1542. || 0 == pContext->out.TableAddress )
  1543. {
  1544. if( NULL != pContext )
  1545. pContext->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1546. return 0; // error
  1547. }
  1548. // initialize the first requested point offset
  1549. size_t
  1550. // by the table address
  1551. pointOffset = pContext->out.TableAddress;
  1552. // and shift it by the table header size
  1553. pointOffset += SIZE_TCOMP_MAGN_THDR;
  1554. // and shift it by the size of skipped points
  1555. pointOffset += pContext->in.nStartPoint * SIZE_TCOMP_MAGN_TPNT;
  1556. // use internal buffer
  1557. g_RomBuffer_Cache = RomBufCache_undefined;
  1558. // read the points contineously
  1559. for( size_t n = 0; n < pContext->in.nCount; (void)n )
  1560. {
  1561. // calculate amount of points available to be cached
  1562. size_t nPointsRead = sizeof(g_RomBuffer) / SIZE_TCOMP_MAGN_TPNT;
  1563. // limit amount of points to be read by the number of required points
  1564. if( nPointsRead > (pContext->in.nCount-n) )
  1565. {
  1566. nPointsRead = (pContext->in.nCount-n);
  1567. }
  1568. // actually read the points
  1569. if( ! FLASH_SUCCESS( flash_read( // Read the points
  1570. pointOffset, // with the specified offset of current point
  1571. g_RomBuffer, // into the internal buffer,
  1572. nPointsRead * SIZE_TCOMP_MAGN_TPNT // and read only @nPointsRead points
  1573. ))
  1574. )
  1575. {
  1576. pContext->svc.errCode = ERR_NFMGETPOINTS_IO;
  1577. // i/o error
  1578. return 0;
  1579. }
  1580. // cast the buffer @g_RomBuffer to the [sEcalChrzTablePoint_t] array
  1581. const sEcalTCompTableMagnPoint_t * pComplexPoints = (sEcalTCompTableMagnPoint_t*)g_RomBuffer;
  1582. // Convert each of @nPointsRead data points from 24-bit format into the double format
  1583. for( size_t iPoint = 0; iPoint < nPointsRead; ++iPoint )
  1584. {
  1585. // thermocompensation magnitude
  1586. {
  1587. // Convert the 16-bit data into the double
  1588. // 16-bit data is amount of descrettes of ((max-min)/65536)
  1589. // where @min and @max is a magintude value in 0.01dB/C discrettes
  1590. double max = (double)(pContext->out.max) / 100.0;
  1591. double min = (double)(pContext->out.min) / 100.0;
  1592. double mean = (min + max) / 2.0;
  1593. // Note: each point is signed 16-bit integer
  1594. // store the result into the output double array
  1595. pContext->in.pDataArray[ n + iPoint ].phase = 0; // not used
  1596. pContext->in.pDataArray[ n + iPoint ].magn
  1597. = mean + (double)pComplexPoints[iPoint].Magn * (max - min) / 65535.0;
  1598. }
  1599. /*
  1600. {
  1601. // Convert the 16-bit data into the double
  1602. // 16-bit data is amount of descrettes of ((max-min)/65536)
  1603. // where @min and @max is a magintude value in 0.01dB/C discrettes
  1604. #define MAGN16_DISCRETTE(min,max) ((( (double)(max) - (double)(min) )) / ((double)6553500.0))
  1605. #define MAGN16_MEAN(min,max) ((( (double)(max) + (double)(min) )) / ((double)200.0))
  1606. // Note: each point is signed 16-bit integer
  1607. // store the result into the output double array
  1608. pContext->in.pDataArray[ n + iPoint ].phase = 0; // not used
  1609. pContext->in.pDataArray[ n + iPoint ].magn =
  1610. MAGN16_MEAN( pContext->out.min, pContext->out.max ) +
  1611. ((double)(pComplexPoints[iPoint].Magn)) *
  1612. MAGN16_DISCRETTE( pContext->out.min, pContext->out.max );
  1613. }
  1614. */
  1615. }
  1616. // decrease amount of points to read
  1617. n += nPointsRead;
  1618. // shift the address
  1619. pointOffset += nPointsRead * SIZE_TCOMP_MAGN_TPNT;
  1620. }
  1621. pContext->svc.errCode = ERR_NFMGETPOINTS_NOERR;
  1622. // return amount of points
  1623. return pContext->in.nCount;
  1624. }
  1625. size_t NFM_ROM_GetTCompPhasePoints( /*const*/ sNFMGetPoints_t * pContext )
  1626. {
  1627. // check the input parameters
  1628. if( NULL == pContext
  1629. || 0 == pContext->in.nCount
  1630. || NULL == pContext->in.pDataArray
  1631. || 0 == pContext->out.nPoints
  1632. || 0 == pContext->out.TableAddress )
  1633. {
  1634. if( NULL != pContext )
  1635. pContext->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1636. return 0; // error
  1637. }
  1638. // initialize the first requested point offset
  1639. size_t
  1640. // by the table address
  1641. pointOffset = pContext->out.TableAddress;
  1642. // and shift it by the table header size
  1643. pointOffset += SIZE_TCOMP_PHASE_THDR;
  1644. // and shift it by the size of skipped points
  1645. pointOffset += pContext->in.nStartPoint * SIZE_TCOMP_PHASE_TPNT;
  1646. // use internal buffer
  1647. g_RomBuffer_Cache = RomBufCache_undefined;
  1648. // read the points contineously
  1649. for( size_t n = 0; n < pContext->in.nCount; (void)n )
  1650. {
  1651. // calculate amount of points available to be cached
  1652. size_t nPointsRead = sizeof(g_RomBuffer) / SIZE_TCOMP_PHASE_TPNT;
  1653. // limit amount of points to be read by the number of required points
  1654. if( nPointsRead > (pContext->in.nCount-n) )
  1655. {
  1656. nPointsRead = (pContext->in.nCount-n);
  1657. }
  1658. // actually read the points
  1659. if( ! FLASH_SUCCESS( flash_read( // Read the points
  1660. pointOffset, // with the specified offset of current point
  1661. g_RomBuffer, // into the internal buffer,
  1662. nPointsRead * SIZE_TCOMP_PHASE_TPNT // and read only @nPointsRead points
  1663. ))
  1664. )
  1665. {
  1666. pContext->svc.errCode = ERR_NFMGETPOINTS_IO;
  1667. // i/o error
  1668. return 0;
  1669. }
  1670. // cast the buffer @g_RomBuffer to the [sEcalChrzTablePoint_t] array
  1671. const sEcalTCompTablePhasePoint_t * pComplexPoints = (sEcalTCompTablePhasePoint_t*)g_RomBuffer;
  1672. // Convert each of @nPointsRead data points from 16-bit format into the double format
  1673. for( size_t iPoint = 0; iPoint < nPointsRead; ++iPoint )
  1674. {
  1675. // thermocompensation phase
  1676. {
  1677. // Convert the 16-bit data into the double
  1678. // 16-bit data is amount of descrettes of ((max-min)/65536)
  1679. // where @min and @max is a magintude value in 0.01deg/C discrettes
  1680. double max = (double)(pContext->out.max) / 100.0;
  1681. double min = (double)(pContext->out.min) / 100.0;
  1682. double mean = (min + max) / 2.0;
  1683. // Note: each point is signed 16-bit integer
  1684. // store the result into the output double array
  1685. pContext->in.pDataArray[ n + iPoint ].magn = 0; // not used
  1686. pContext->in.pDataArray[ n + iPoint ].phase
  1687. = mean + (double)(pComplexPoints[iPoint].Phase) * (max - min) / 65535.0;
  1688. }
  1689. /*
  1690. {
  1691. // Convert the 16-bit data into the double
  1692. // 16-bit data is amount of descrettes of ((max-min)/65536)
  1693. // where @min and @max is a magintude value in 0.01deg/C discrettes
  1694. //#define PHASE16_DISCRETTE(min,max) (((double)( (max) - (min) )) / ((double)6553500.0))
  1695. //#define PHASE16_MEAN(min,max) (((double)( (max) + (min) )) / ((double)200.0))
  1696. #define PHASE16_DISCRETTE(min,max) ((( (double)(max) - (double)(min) )) / ((double)6553500.0))
  1697. #define PHASE16_MEAN(min,max) ((( (double)(max) + (double)(min) )) / ((double)200.0))
  1698. // Note: each point is signed 16-bit integer
  1699. // store the result into the output double array
  1700. pContext->in.pDataArray[ n + iPoint ].magn = 0; // not used
  1701. pContext->in.pDataArray[ n + iPoint ].phase =
  1702. PHASE16_MEAN( pContext->out.min, pContext->out.max ) +
  1703. ((double)(pComplexPoints[iPoint].Phase)) *
  1704. PHASE16_DISCRETTE( pContext->out.min, pContext->out.max );
  1705. }
  1706. */
  1707. }
  1708. // decrease amount of points to read
  1709. n += nPointsRead;
  1710. // shift the address
  1711. pointOffset += nPointsRead * SIZE_TCOMP_PHASE_TPNT;
  1712. }
  1713. pContext->svc.errCode = ERR_NFMGETPOINTS_NOERR;
  1714. // return amount of points
  1715. return pContext->in.nCount;
  1716. }
  1717. size_t NFM_ROM_ReadDeviceSettings( uint8_t * buffer, size_t nOffset, size_t nBytesToRead )
  1718. {
  1719. extern NFMClassEx_t * NFMClassExtended;
  1720. const sSwitchMemoryProfile_t * memProfile = NFMClassExtended->private.properties.memProfile;
  1721. if( NULL != NFMClassExtended->private.properties.memProfile )
  1722. if( 0 < memProfile->Size_Settings )
  1723. {
  1724. if( (NULL != buffer) && (nOffset < memProfile->Size_Settings) && (0 < nBytesToRead) )
  1725. {
  1726. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( (nOffset) + NFMClassExtended->private.properties.memProfile->BaseAddr_Settings );
  1727. if( FLASH_SUCCESS( flash_read( baseAddr, buffer, nBytesToRead ) ) )
  1728. {
  1729. return nBytesToRead;
  1730. }
  1731. }
  1732. }
  1733. return 0; // failed
  1734. }
  1735. size_t NFM_ROM_GetDeviceSettingsSize()
  1736. {
  1737. extern NFMClassEx_t * NFMClassExtended;
  1738. const sSwitchMemoryProfile_t * memProfile = NFMClassExtended->private.properties.memProfile;
  1739. if( NULL != NFMClassExtended->private.properties.memProfile )
  1740. {
  1741. return memProfile->Size_Settings;
  1742. }
  1743. return 0; // failed
  1744. }
  1745. bool NFM_ROM_ValidateUserSettings()
  1746. {
  1747. if( sizeof(sNFMSettingsBlockCrc_t) == NFM_ROM_GetDeviceSettingsSize() )
  1748. {
  1749. sNFMSettingsBlockCrc_t sSettingsBlock;
  1750. if( NFM_ROM_ReadDeviceSettings( (uint8_t*)&sSettingsBlock,
  1751. 0,
  1752. sizeof(sSettingsBlock) ) )
  1753. {
  1754. TCRC crc = ICRC32;
  1755. crc = CRC32( crc, (uint8_t *)&sSettingsBlock.settings, sizeof(sSettingsBlock.settings));
  1756. if(crc != sSettingsBlock.CRCValue)
  1757. {
  1758. return false;
  1759. }
  1760. }
  1761. }
  1762. else
  1763. return false;
  1764. return true;
  1765. }
  1766. size_t NFM_ROM_WriteDeviceSettings( uint8_t * buffer, size_t nOffset, size_t nBytesToWrite )
  1767. {
  1768. extern NFMClassEx_t * NFMClassExtended;
  1769. const sSwitchMemoryProfile_t * memProfile = NFMClassExtended->private.properties.memProfile;
  1770. if( NULL != NFMClassExtended->private.properties.memProfile )
  1771. if( 0 < memProfile->Size_Settings )
  1772. {
  1773. if( (NULL != buffer) && (nOffset < memProfile->Size_Settings) && (0 < nBytesToWrite) )
  1774. {
  1775. size_t baseAddr = NFMBASE_FLASH_MAKEREALADDRESS( (nOffset) + NFMClassExtended->private.properties.memProfile->BaseAddr_Settings );
  1776. if( FLASH_SUCCESS( flash_write( baseAddr, buffer, nBytesToWrite, fwm_safewrite ) ) )
  1777. {
  1778. return nBytesToWrite;
  1779. }
  1780. }
  1781. }
  1782. return 0; // failed
  1783. }
  1784. //////
  1785. //////TECALTCOMPHEADERCRC * __ROM_GetTermHeader( char * buffer, unsigned int buffersize, unsigned int address )
  1786. //////{
  1787. ////// if( buffer == NULL || buffersize < sizeof(TECALTCOMPHEADERCRC) ) return NULL;
  1788. //////
  1789. ////// //read_flash( address, buffer, sizeof(TECALTCOMPHEADERCRC) );
  1790. ////// BREAKPOINT;
  1791. //////
  1792. ////// return (TECALTCOMPHEADERCRC*)buffer;
  1793. //////}
  1794. //////
  1795. //////// ------------------------------------------------------------------------------ ------
  1796. //////
  1797. //////TECALTCOMPHEADER * ROM_GetTermHeader( char * buffer, unsigned int buffersize )
  1798. //////{
  1799. ////// char * recievebuffer = buffer;
  1800. //////
  1801. ////// //---------------------------------
  1802. ////// if( LastReadAddress != ROM_TERM_COMP_ADDR ) // ���� ��������� ����� ������ �� ����� �������� ������ ������
  1803. ////// BufferChached = 0; // ����� ����������� �� ��������������
  1804. ////// else
  1805. ////// BufferChached = 1; // ����� ����� �������������� ��� ��� ROM SPI
  1806. ////// //---------------------------------
  1807. ////// if( recievebuffer == NULL ) { // ���� ������������ ROMHeaderBuffer
  1808. ////// recievebuffer = (char*)&ROMHeaderBuffer;
  1809. ////// buffersize = SPIROMHeaderBufferSize; // !!! �������� ������� ������ ������� ��� �������� TECALTCOMPHEADERCRC !!!
  1810. ////// LastReadAddress = ROM_TERM_COMP_ADDR;
  1811. ////// }
  1812. ////// else
  1813. ////// { BufferChached = 0; // ������������ ������, ������� ������, �� ����� ROMHeaderBuffer
  1814. ////// if( INT(recievebuffer)%sizeof(unsigned int) ) return NULL; // not aligment .
  1815. ////// }
  1816. ////// //---------------------------------
  1817. ////// /*- RET -*/if( recievebuffer == NULL || buffersize < sizeof(/*CRC*/TECALTCOMPHEADERCRC/*CRC*/) ) return NULL;
  1818. ////// //---------------------------------
  1819. ////// TECALTCOMPHEADERCRC * hdrcrc;
  1820. ////// if( BufferChached != 1 ) hdrcrc = __ROM_GetTermHeader(recievebuffer, buffersize, ROM_TERM_COMP_ADDR);
  1821. ////// else hdrcrc = (TECALTCOMPHEADERCRC *)recievebuffer; // !!! ������������ ������ ��� � ������ � �������� ������ !!!
  1822. ////// //---------------------------------
  1823. ////// /*- RET -*/if(hdrcrc == NULL) return NULL;
  1824. ////// //---------------------------------
  1825. ////// TCRC crc = ICRC32; // �������������� CRC32
  1826. ////// //---------------------------------
  1827. ////// crc = CRC32( crc, (unsigned char const *)hdrcrc, sizeof(TECALTCOMPHEADER));
  1828. ////// //---------------------------------
  1829. ////// if( crc == hdrcrc->CRCValue ) return (TECALTCOMPHEADER *)hdrcrc;
  1830. ////// else
  1831. ////// { if(BufferChached == 1) // �������� � RAM ����� �����������
  1832. ////// { LastReadAddress = 0xffffffff;
  1833. ////// return ROM_GetTermHeader( /*!!!*/buffer/*!!!*/, buffersize); // ������ ��� ���, �� ��� �����������
  1834. ////// } else return NULL;
  1835. ////// }
  1836. ////// //---------------------------------
  1837. //////}
  1838. //////
  1839. //////// ------------------------------------------------------------------------------
  1840. //////char * ROM_GetConnectorString( unsigned int ID )
  1841. //////{
  1842. ////// if(ID<=12)
  1843. ////// return (char*)Connector[ID];
  1844. ////// else
  1845. ////// return NULL;
  1846. //////}
  1847. //////
  1848. //////
  1849. //////TECALDATAHEADERCRC * __ROM_GetHeader( char * buffer, unsigned int buffersize, unsigned int address )
  1850. //////{
  1851. ////// if( buffer == NULL || buffersize < sizeof(TECALDATAHEADERCRC) ) return NULL;
  1852. //////
  1853. ////// flash_read( address, buffer, sizeof(TECALDATAHEADERCRC) );
  1854. //////
  1855. ////// return (TECALDATAHEADERCRC*)buffer;
  1856. //////}
  1857. //////
  1858. //////// ------- ------
  1859. //////
  1860. //////TECALDATAHEADER * ROM_GetHeader( char * buffer, unsigned int buffersize, EROMHEADER HeaderID )
  1861. //////{
  1862. ////// char * recievebuffer = buffer;
  1863. //////
  1864. ////// if( ! ( HeaderID <= 5 ) ) return NULL;
  1865. //////
  1866. ////// //---------------------------------
  1867. ////// if( LastReadAddress != ROM_MAP[HeaderID] ) // ���� ��������� ����� ������ �� ����� �������� ������ ������
  1868. ////// BufferChached = 0; // ����� ����������� �� ��������������
  1869. ////// else
  1870. ////// BufferChached = 1; // ����� ����� �������������� ��� ��� ROM SPI
  1871. ////// //---------------------------------
  1872. ////// if( recievebuffer == NULL ) { // ���� ������������ ROMHeaderBuffer
  1873. ////// recievebuffer = (char*)&ROMHeaderBuffer;
  1874. ////// buffersize = SPIROMHeaderBufferSize; // !!! �������� ������� ������ ������� ��� �������� TECALDATAHEADERCRC !!!
  1875. ////// LastReadAddress = ROM_MAP[HeaderID];
  1876. ////// }
  1877. ////// else
  1878. ////// { BufferChached = 0; // ������������ ������, ������� ������, �� ����� ROMHeaderBuffer
  1879. ////// if( INT(recievebuffer)%sizeof(unsigned int) ) return NULL; // not aligment .
  1880. ////// }
  1881. ////// //---------------------------------
  1882. ////// /*- RET -*/if( recievebuffer == NULL || buffersize < sizeof(/*CRC*/TECALDATAHEADERCRC/*CRC*/) ) return NULL;
  1883. ////// //---------------------------------
  1884. ////// TECALDATAHEADERCRC * hdrcrc;
  1885. ////// if( BufferChached != 1 ) hdrcrc = __ROM_GetHeader(recievebuffer, buffersize, ROM_MAP[HeaderID]);
  1886. ////// else hdrcrc = (TECALDATAHEADERCRC *)recievebuffer; // !!! ������������ ������ ��� � ������ � �������� ������ !!!
  1887. ////// //---------------------------------
  1888. ////// /*- RET -*/if(hdrcrc == NULL) return NULL;
  1889. ////// //---------------------------------
  1890. ////// TCRC crc = ICRC32; // �������������� CRC32
  1891. ////// //---------------------------------
  1892. ////// crc = CRC32( crc, (unsigned char const *)hdrcrc, sizeof(TECALDATAHEADER));
  1893. ////// //---------------------------------
  1894. ////// if( crc == hdrcrc->CRCValue ) return (TECALDATAHEADER *)hdrcrc;
  1895. ////// else
  1896. ////// { if(BufferChached == 1) // �������� � RAM ����� �����������
  1897. ////// { LastReadAddress = 0xffffffff;
  1898. ////// return ROM_GetHeader( /*!!!*/buffer/*!!!*/, buffersize, HeaderID); // ������ ��� ���, �� ��� �����������
  1899. ////// } else return NULL;
  1900. ////// }
  1901. ////// //---------------------------------
  1902. //////}
  1903. ////////
  1904. //////
  1905. //////
  1906. //////// ######################################################################################################################################
  1907. //////// ######################################################################################################################################
  1908. //////unsigned int ROM_GetStartAddress( EROMHEADER HeaderID )
  1909. //////{
  1910. ////// return ROM_MAP[HeaderID] + sizeof(TECALDATAHEADERCRC);
  1911. //////}
  1912. //////
  1913. //////BOOL ROM_GetArray( TGETARRAYIN * stGetArrayParameters, TGETARRAYOUT * stoutArrayParams )
  1914. //////{
  1915. ////////
  1916. ////////(dwStartAddress)
  1917. ////////*----------->| (CHARACTERIZATION_)
  1918. //////// | /
  1919. //////// --->|--------|<--+
  1920. //////// | |
  1921. //////// +-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
  1922. //////// | BLOCK | BLOCK | | | | | | | | | | |
  1923. //////// | HEADER | CRC | SH_A | SH_B | OP_A | OP_B | LD_A | LD_B | T_11 | T_21 | T_12 | T_22 |
  1924. //////// | F/U1/../U5| F/./U5 | | | | | | | | | | |
  1925. //////// +-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
  1926. //////// / \
  1927. //////// / \
  1928. //////// / \
  1929. //////// / \
  1930. //////// / \
  1931. //////// / \
  1932. //////// / \
  1933. //////// / -ARRAY- \
  1934. //////// / \
  1935. //////// +-------+------------+-------+
  1936. //////// | mindB | N | |
  1937. //////// | |...POINTS...| CRC |
  1938. //////// | maxdB | |ARRAY |
  1939. //////// +-------+------------+-------+
  1940. ////////
  1941. //////
  1942. //////// IN: TGETARRAYIN OUT: TGETARRAYOUT
  1943. ///////*char * buffer;
  1944. ////// unsigned int buffersize; FIRSTPOINT FirstPoint;
  1945. ////// // -------------------- --------------------
  1946. ////// unsigned int nMaxPoints; unsigned int dwPointsAddress;
  1947. ////// // --------------------- unsigned int dwArrayCRC;
  1948. ////// unsigned int Version; void * pPoints;
  1949. ////// // ---------------------
  1950. ////// EPORT port;
  1951. ////// ESTATE state;
  1952. ////// // ---------------------
  1953. ////// unsigned int startaddress;*/
  1954. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  1955. ////// if( stGetArrayParameters == NULL || stoutArrayParams == NULL) return NULL;
  1956. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  1957. ////// unsigned int ps;
  1958. ////// unsigned int as;
  1959. ////// unsigned int of/*, rd*/;
  1960. ////// unsigned int adr_crc;
  1961. ////// unsigned int adr_points;
  1962. ////// unsigned int adr_minmax;
  1963. ////// char * data = stGetArrayParameters->buffer;
  1964. //////
  1965. ////// if( (stGetArrayParameters->cFlags & (1<<0)) == 0 ) // get characterization array
  1966. ////// {
  1967. ////// ps = POINTSIZE;
  1968. ///////*
  1969. ////// as = CHARACTERIZATION_ARRAY_SIZE(stGetArrayParameters->nMaxPoints,ps);
  1970. //////*/
  1971. ////// as = CHARACTERIZATION_TABLE_SIZE( stGetArrayParameters->nMaxPoints );
  1972. //////
  1973. ////// } else {
  1974. //////
  1975. ////// as = TERMCOMPENSATION_ARRAY_SIZE(stGetArrayParameters->nMaxPoints );
  1976. //////
  1977. ////// ps = sizeof(struct TEtermPoint);
  1978. //////
  1979. ////// }
  1980. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  1981. ////// if( stGetArrayParameters->buffer == NULL || stGetArrayParameters->buffersize < ps ) return NULL;
  1982. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  1983. ////// // �������� ������������ �������� ������ � ��������� ������
  1984. ////// if( !( ( stGetArrayParameters->state == eSTATE_SHORT ||
  1985. ////// stGetArrayParameters->state == eSTATE_LOAD ||
  1986. ////// stGetArrayParameters->state == eSTATE_OPEN ||
  1987. ////// stGetArrayParameters->state == eSTATE_T11 ||
  1988. ////// stGetArrayParameters->state == eSTATE_T12 ||
  1989. ////// stGetArrayParameters->state == eSTATE_T21 ||
  1990. ////// stGetArrayParameters->state == eSTATE_T22 ||
  1991. ////// stGetArrayParameters->state == eSTATE_LOAD2 ||
  1992. ////// stGetArrayParameters->state == eSTATE_OPEN2 ||
  1993. ////// stGetArrayParameters->state == eSTATE_A11 ||
  1994. ////// stGetArrayParameters->state == eSTATE_A12 ||
  1995. ////// stGetArrayParameters->state == eSTATE_A21 ||
  1996. ////// stGetArrayParameters->state == eSTATE_A22
  1997. //////
  1998. ////// )
  1999. ////// &&
  2000. ////// ( stGetArrayParameters->port == ePORT_A ||
  2001. ////// stGetArrayParameters->port == ePORT_B ||
  2002. ////// stGetArrayParameters->port == ePORT_AB
  2003. ////// )
  2004. ////// )
  2005. ////// ) return FALSE;
  2006. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  2007. ////// // �������� ������������ �������� ����� (A/B) ��� ���������� SH/LD/OP/LD2/OP2
  2008. ////// if( ( ( stGetArrayParameters->state == eSTATE_SHORT ||
  2009. ////// stGetArrayParameters->state == eSTATE_LOAD ||
  2010. ////// stGetArrayParameters->state == eSTATE_OPEN ||
  2011. ////// stGetArrayParameters->state == eSTATE_LOAD2 ||
  2012. ////// stGetArrayParameters->state == eSTATE_OPEN2
  2013. ////// )
  2014. ////// &&
  2015. ////// ( stGetArrayParameters->port != ePORT_A &&
  2016. ////// stGetArrayParameters->port != ePORT_B
  2017. ////// )
  2018. ////// )
  2019. ////// ) return FALSE;
  2020. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  2021. ////// // �������� ������������ �������� ����� (AB) ��� ���������� T11/T12/T21/T22
  2022. ////// if( ( ( stGetArrayParameters->state == eSTATE_T11 ||
  2023. ////// stGetArrayParameters->state == eSTATE_T12 ||
  2024. ////// stGetArrayParameters->state == eSTATE_T21 ||
  2025. ////// stGetArrayParameters->state == eSTATE_T22
  2026. ////// )
  2027. ////// &&
  2028. ////// ( stGetArrayParameters->port != ePORT_AB
  2029. ////// )
  2030. ////// )
  2031. ////// ) return FALSE;
  2032. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  2033. ////// // �������� ������������ �������� ����� (AB) ��� ���������� A11/A12/A21/A22
  2034. ////// if( ( ( stGetArrayParameters->state == eSTATE_A11 ||
  2035. ////// stGetArrayParameters->state == eSTATE_A12 ||
  2036. ////// stGetArrayParameters->state == eSTATE_A21 ||
  2037. ////// stGetArrayParameters->state == eSTATE_A22
  2038. ////// )
  2039. ////// &&
  2040. ////// ( stGetArrayParameters->port != ePORT_AB
  2041. ////// )
  2042. ////// )
  2043. ////// ) return FALSE;
  2044. ////// //---------------------------------------------------------------------------------------------------------------------------------------
  2045. ////// // ���������� ������ �������
  2046. //////
  2047. //////if( (stGetArrayParameters->cFlags & (1<<0)) == 0 ) // get characterization array
  2048. //////{
  2049. //////
  2050. ////// // *============================ ������ �������������� ==================================
  2051. //////
  2052. ////// // ���� ������� SH,OP,LD. �� ��� ����� � ������� SH * 2, OP * 2, LD * 2.
  2053. ////// // ������ A ���� ������ B SHA,SHB,OPA,OPB,LDA,LDB
  2054. ////// if( stGetArrayParameters->state == eSTATE_SHORT || stGetArrayParameters->state == eSTATE_LOAD || stGetArrayParameters->state == eSTATE_OPEN )
  2055. ////// {
  2056. ////// if( stGetArrayParameters->state == eSTATE_SHORT ) of = 0;
  2057. ////// if( stGetArrayParameters->state == eSTATE_OPEN ) of = 2;
  2058. ////// if( stGetArrayParameters->state == eSTATE_LOAD ) of = 4;
  2059. //////
  2060. ////// if( stGetArrayParameters->port == ePORT_A ) of += 0;
  2061. ////// if( stGetArrayParameters->port == ePORT_B ) of += 1;
  2062. //////
  2063. ////// } else
  2064. ////// if( stGetArrayParameters->state == eSTATE_T11 || stGetArrayParameters->state == eSTATE_T12 || stGetArrayParameters->state == eSTATE_T21 || stGetArrayParameters->state == eSTATE_T22)
  2065. ////// {
  2066. ////// of = 6;
  2067. ////// if( stGetArrayParameters->state == eSTATE_T11 ) of += 0;
  2068. ////// if( stGetArrayParameters->state == eSTATE_T21 ) of += 1;
  2069. ////// if( stGetArrayParameters->state == eSTATE_T12 ) of += 2;
  2070. ////// if( stGetArrayParameters->state == eSTATE_T22 ) of += 3;
  2071. ////// }
  2072. ////// else
  2073. ////// if( stGetArrayParameters->state == eSTATE_A11 || stGetArrayParameters->state == eSTATE_A12 || stGetArrayParameters->state == eSTATE_A21 || stGetArrayParameters->state == eSTATE_A22)
  2074. ////// {
  2075. ////// of = 10;
  2076. ////// if( stGetArrayParameters->state == eSTATE_A11 ) of += 0;
  2077. ////// if( stGetArrayParameters->state == eSTATE_A21 ) of += 1;
  2078. ////// if( stGetArrayParameters->state == eSTATE_A12 ) of += 2;
  2079. ////// if( stGetArrayParameters->state == eSTATE_A22 ) of += 3;
  2080. //////
  2081. ////// }
  2082. ////// else
  2083. ////// if( stGetArrayParameters->state == eSTATE_LOAD2 || stGetArrayParameters->state == eSTATE_OPEN2 )
  2084. ////// {
  2085. ////// of =14; /*28*/
  2086. ////// if( stGetArrayParameters->state == eSTATE_LOAD2 ) of += 0;
  2087. ////// if( stGetArrayParameters->state == eSTATE_OPEN2 ) of += 2; /*4*/
  2088. //////
  2089. ////// if( stGetArrayParameters->port == ePORT_A ) of += 0;
  2090. ////// if( stGetArrayParameters->port == ePORT_B ) of += 1; /*2*/
  2091. ////// /* ��� �� �� ����������������, ��� ��� PHASE
  2092. ////// if( stGetArrayParameters->tca_type == eTCA_MAGN ) of += 0;
  2093. ////// if( stGetArrayParameters->tca_type == eTCA_PHASE ) of += 1;*/
  2094. ////// }
  2095. //////
  2096. ////// // *====================================================================================
  2097. //////
  2098. //////} else /// get termo compensation array
  2099. //////{
  2100. //////// +---------+------------+-------+
  2101. //////// | minRAD | N | |
  2102. //////// | ------- |...POINTS...| CRC |
  2103. //////// | maxRAD | | ARRAY |
  2104. //////// +---------+------------+-------+
  2105. //////// \ /
  2106. //////// \ /
  2107. //////// \ /
  2108. //////// \ /
  2109. //////// \ - PHASE ARRAY - /
  2110. //////// \ /
  2111. //////// \ /
  2112. //////// \ /
  2113. //////// \ /
  2114. //////// \ /
  2115. //////// \ /
  2116. //////// +-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
  2117. //////// | BLOCK | TERMO | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
  2118. //////// | HEADER | COMPEN | SH_A | SH_A | SH_B | SH_B | OP_A | OP_A | OP_B | OP_B | LD_A | LD_A | LD_B | LD_B | T_11 | T_11 | T_21 | T_21 | T_12 | T_12 | T_22 | T_22 | A_11 | A_11 | A_21 | A_21 | A_12 | A_12 | A_22 | A_22 | LD2A | LD2A | LD2B | LD2B | OP_A | OP_A | OP_B | OP_B |
  2119. //////// | TERMOCOMP | CRC | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE | MAGN | PHASE |
  2120. //////// +-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
  2121. //////// / \
  2122. //////// / \
  2123. //////// / \
  2124. //////// / \
  2125. //////// / \
  2126. //////// / \
  2127. //////// / \
  2128. //////// / - MAGNITUDE ARRAY - \
  2129. //////// / \
  2130. //////// +-------+------------+-------+
  2131. //////// | mindB | N | |
  2132. //////// | ----- |...POINTS...| CRC |
  2133. //////// | maxdB | |ARRAY |
  2134. //////// +-------+------------+-------+
  2135. //////
  2136. //////
  2137. ////// // * ============================ ������ ���������������� =====================================
  2138. //////
  2139. ////// if( stGetArrayParameters->state == eSTATE_SHORT || stGetArrayParameters->state == eSTATE_LOAD || stGetArrayParameters->state == eSTATE_OPEN || stGetArrayParameters->state == eSTATE_LOAD2 || stGetArrayParameters->state == eSTATE_OPEN2 )
  2140. ////// {
  2141. ////// if( stGetArrayParameters->state == eSTATE_SHORT ) of = 0;
  2142. ////// if( stGetArrayParameters->state == eSTATE_OPEN ) of = 4;
  2143. ////// if( stGetArrayParameters->state == eSTATE_LOAD ) of = 8;
  2144. //////
  2145. ////// if( stGetArrayParameters->state == eSTATE_OPEN2 ) of = 32;
  2146. ////// if( stGetArrayParameters->state == eSTATE_LOAD2 ) of = 28;
  2147. //////
  2148. ////// if( stGetArrayParameters->port == ePORT_A ) of += 0;
  2149. ////// if( stGetArrayParameters->port == ePORT_B ) of += 2;
  2150. //////
  2151. ////// if( stGetArrayParameters->tca_type == eTCA_MAGN ) of += 0;
  2152. ////// if( stGetArrayParameters->tca_type == eTCA_PHASE ) of += 1;
  2153. //////
  2154. ////// } else
  2155. ////// if( stGetArrayParameters->state == eSTATE_T11 || stGetArrayParameters->state == eSTATE_T12 || stGetArrayParameters->state == eSTATE_T21 || stGetArrayParameters->state == eSTATE_T22
  2156. ////// ||
  2157. ////// stGetArrayParameters->state == eSTATE_A11 || stGetArrayParameters->state == eSTATE_A12 || stGetArrayParameters->state == eSTATE_A21 || stGetArrayParameters->state == eSTATE_A22 )
  2158. ////// {
  2159. ////// of = 12;
  2160. //////
  2161. ////// if( stGetArrayParameters->state == eSTATE_T11 ) of += 0;
  2162. ////// if( stGetArrayParameters->state == eSTATE_T21 ) of += 2;
  2163. ////// if( stGetArrayParameters->state == eSTATE_T12 ) of += 4;
  2164. ////// if( stGetArrayParameters->state == eSTATE_T22 ) of += 6;
  2165. //////
  2166. ////// if( stGetArrayParameters->state == eSTATE_A11 ) of += 8;
  2167. ////// if( stGetArrayParameters->state == eSTATE_A21 ) of += 10;
  2168. ////// if( stGetArrayParameters->state == eSTATE_A12 ) of += 12;
  2169. ////// if( stGetArrayParameters->state == eSTATE_A22 ) of += 14;
  2170. //////
  2171. ////// if( stGetArrayParameters->tca_type == eTCA_MAGN ) of += 0;
  2172. ////// if( stGetArrayParameters->tca_type == eTCA_PHASE ) of += 1;
  2173. //////
  2174. ////// }
  2175. //////
  2176. ////// // * ====================================================================================
  2177. //////
  2178. //////}
  2179. ////// // ------------------------------
  2180. ////// // of �������� � ������� �������
  2181. ////// of *= as;
  2182. ////// // of �������� � ������
  2183. ////// // ------------------------------
  2184. //////
  2185. ////// // -----------------------------------------------------
  2186. ////// // ���������� � of ��������� ����� ������ ��������
  2187. ////// // (����� ����� ��������� ������ FACT / US1 / ... / US5)
  2188. ////// of += stGetArrayParameters->dwStartAddress;
  2189. ////// // -----------------------------------------------------
  2190. ////// //
  2191. ////// adr_minmax = of;
  2192. ////// adr_points = adr_minmax + sizeof(FIRSTPOINT);
  2193. ////// adr_crc = adr_points + stGetArrayParameters->nMaxPoints * ps;
  2194. ////// stoutArrayParams->dwPointsAddress = adr_points;
  2195. ////// //
  2196. ////// // -----------------------------------------------
  2197. ////// // of ��������� �� ������ ������� (����� min/max )
  2198. ////// // -----------------------------------------------
  2199. ////// //read_flash( adr_minmax, (char*)&stoutArrayParams->FirstPoint, sizeof(FIRSTPOINT) ); // ������ FirstPoint (MindB / MaxdB)
  2200. ////// //read_flash( adr_crc , (char*)&stoutArrayParams->dwArrayCRC, sizeof(unsigned int)); // ������ CRC
  2201. ////// BREAKPOINT;
  2202. ////// // -----------------------------------------------
  2203. ////// (void)(adr_crc);
  2204. //////
  2205. ////// // -----------------------------------------------
  2206. ////// TCRC crc = ICRC32; // �������������� CRC32
  2207. ////// unsigned int maxread = stGetArrayParameters->buffersize - stGetArrayParameters->buffersize%ps;
  2208. ////// unsigned int pointsbytes = as - sizeof(unsigned int); //-crc
  2209. ////// unsigned int bytes = maxread;
  2210. ////// // -----------------------------------------------
  2211. ////// unsigned int address = adr_minmax;
  2212. ////// unsigned int readcnt = 0;
  2213. //////
  2214. ////// while(readcnt < pointsbytes)
  2215. ////// {
  2216. ////// bytes = pointsbytes - readcnt;
  2217. ////// if(bytes > maxread) bytes = maxread;
  2218. //////
  2219. ////// //read_flash( address, (char*)data, bytes );
  2220. ////// BREAKPOINT;
  2221. //////
  2222. ////// crc = CRC32( crc, (unsigned char const *)data, bytes);
  2223. //////
  2224. ////// address += bytes;
  2225. ////// readcnt += bytes;
  2226. ////// }//0xA9D5BE5A
  2227. ////// // -----------------------------------------------
  2228. ////// if((stoutArrayParams->dwArrayCRC != crc)) stoutArrayParams->dwPointsAddress = 0;
  2229. ////// // -----------------------------------------------
  2230. ////// return (stoutArrayParams->dwArrayCRC==crc)?(TRUE):(FALSE);
  2231. //////}
  2232. //////// ######################################################################################################################################
  2233. //////// ######################################################################################################################################
  2234. //////// -------------------------------------------------------------------------------------------------------------
  2235. //////
  2236. //////
  2237. //////
  2238. //////
  2239. //////
  2240. //////
  2241. //////
  2242. //////
  2243. //////
  2244. //////
  2245. //////
  2246. //////
  2247. //////
  2248. //////
  2249. //////
  2250. //////
  2251. //////
  2252. //////
  2253. //////
  2254. //////
  2255. //////
  2256. //////
  2257. //////
  2258. //////TECALPOINT2 * ROM_ReadPoints( char * buffer, unsigned int buffersize, unsigned int address, unsigned int length )
  2259. //////{
  2260. ////// if( length > buffersize || buffer == NULL ) return NULL;
  2261. //////
  2262. ////// //read_flash( address, buffer, length );
  2263. ////// BREAKPOINT;
  2264. //////
  2265. ////// return (TECALPOINT2 *)buffer;
  2266. //////}
  2267. //////// ------------------------------------------------------------------------------
  2268. ///////*
  2269. //////TECALPOINT * ROM_GetPoints( char * buffer, unsigned int buffersize, EROMHEADER HeaderID, unsigned int dwPointsStart, unsigned int dwPointsCount )
  2270. //////{
  2271. //////
  2272. ////// TECALPOINT * pPoints;
  2273. ////// char * recievebuffer = buffer;
  2274. ////// if( ! ( HeaderID >= 0 && HeaderID <= 5 ) ) return NULL;
  2275. ////// //---------------------------------
  2276. ////// unsigned int address;
  2277. ////// if(address > MAX_POINTS_MEMORY_SECTOR) return NULL;
  2278. ////// address+= ROM_MAP[HeaderID];
  2279. ////// //---------------------------------
  2280. ////// if( LastReadAddress != address ) // ���� ��������� ����� ������ �� ����� �������� ������ ������
  2281. ////// BufferChached = 0; // ����� ����������� �� ��������������
  2282. ////// else
  2283. ////// BufferChached = 1; // ����� ����� �������������� ��� ��� ROM SPI
  2284. ////// //---------------------------------
  2285. ////// if( recievebuffer == NULL ) { // ���� ������������ ROMHeaderBuffer
  2286. ////// recievebuffer = (char*)&ROMHeaderBuffer;
  2287. ////// buffersize = SPIROMHeaderBufferSize; // !!! �������� ������� ������ ������� ��� �������� TECALDATAHEADERCRC !!!
  2288. ////// LastReadAddress = address;
  2289. ////// }
  2290. ////// else
  2291. ////// {
  2292. ////// BufferChached = 0; // ������������ ������, ������� ������, �� ����� ROMHeaderBuffer
  2293. ////// if( INT(recievebuffer)%sizeof(unsigned int) ) return NULL; // not aligment .
  2294. ////// }
  2295. ////// //---------------------------------
  2296. ////// if( dwPointsCount > buffersize / sizeof(TECALPOINT) ) return NULL;
  2297. ////// //---------------------------------
  2298. ////// if( BufferChached != 1 ) pPoints = ROM_ReadPoints( recievebuffer, buffersize, address, dwPointsCount*sizeof(TECALPOINT));
  2299. ////// else pPoints = (TECALPOINT *)recievebuffer; // !!! ������������ ������ ��� � ������ � �������� ������ !!!
  2300. //////
  2301. ////// return pPoints;
  2302. //////}
  2303. //////// ------------------------------------------------------------------------------
  2304. //////*/