![]() |
Energy Micro IEC60355 Library Example Project 1.0 (internal use only!) GCC-Version
Example project demonstrating POST and BIST library functions
|
00001 /***************************************************************************/ 00030 #include "iec60335_class_b.h" 00031 00045 #if defined (__ICCARM__) 00046 #pragma section="IEC60335_B_PCTestCodeA" 00047 #else 00048 __attribute__((section(".IEC60335_B_PCTestCodeA"))) 00049 #endif 00050 00051 IEC60335_B_PCTest_ReturnValues IEC60335_B_PCTest_A(Data_t *data) 00052 { 00053 data->number++; 00054 return VAL_A; 00055 } 00056 00066 #if defined (__ICCARM__) 00067 #pragma section="IEC60335_B_PCTestCodeB" 00068 #else 00069 __attribute__((section(".IEC60335_B_PCTestCodeB"))) 00070 #endif 00071 00072 IEC60335_B_PCTest_ReturnValues IEC60335_B_PCTest_B(Data_t *data) 00073 { 00074 data->number++; 00075 return VAL_B; 00076 } 00077 00087 #if defined (__ICCARM__) 00088 #pragma section="IEC60335_B_PCTestCodeC" 00089 #else 00090 __attribute__((section(".IEC60335_B_PCTestCodeC"))) 00091 #endif 00092 00093 IEC60335_B_PCTest_ReturnValues IEC60335_B_PCTest_C(Data_t *data) 00094 { 00095 data->number++; 00096 return VAL_C; 00097 } 00098 00108 #if defined (__ICCARM__) 00109 #pragma section="IEC60335_B_PCTestCodeD" 00110 #else 00111 __attribute__((section(".IEC60335_B_PCTestCodeD"))) 00112 #endif 00113 00114 IEC60335_B_PCTest_ReturnValues IEC60335_B_PCTest_D(Data_t *data) 00115 { 00116 data->number++; 00117 return VAL_D; 00118 } 00119 00129 #if defined (__ICCARM__) 00130 #pragma section="IEC60335_B_PCTestCodeE" 00131 #else 00132 __attribute__((section(".IEC60335_B_PCTestCodeE"), long_call)) 00133 #endif 00134 00135 IEC60335_B_PCTest_ReturnValues IEC60335_B_PCTest_E(Data_t *data) 00136 { 00137 data->number++; 00138 return VAL_E; 00139 } 00140 00150 #if defined (__ICCARM__) 00151 #pragma section="IEC60335_B_PCTestCodeF" 00152 #else 00153 __attribute__((section(".IEC60335_B_PCTestCodeF"), long_call)) 00154 #endif 00155 00156 IEC60335_B_PCTest_ReturnValues IEC60335_B_PCTest_F(Data_t *data) 00157 { 00158 data->number++; 00159 return VAL_F; 00160 } 00161 00166 #ifdef TESSY 00167 00168 Exec_t PCTest_funcTable[6] = { 00170 #else 00171 const Exec_t PCTest_funcTable[6] = { 00172 #endif 00173 (Exec_t) IEC60335_B_PCTest_A, 00174 (Exec_t) IEC60335_B_PCTest_B, 00175 (Exec_t) IEC60335_B_PCTest_C, 00176 (Exec_t) IEC60335_B_PCTest_D, 00177 (Exec_t) IEC60335_B_PCTest_E, 00178 (Exec_t) IEC60335_B_PCTest_F 00179 }; 00180 00185 #ifdef TESSY 00186 00187 IEC60335_B_PCTest_ReturnValues PCTest_resultTable[6] = { 00189 #else 00190 const IEC60335_B_PCTest_ReturnValues PCTest_resultTable[6] = { 00191 #endif 00192 VAL_A, 00193 VAL_B, 00194 VAL_C, 00195 VAL_D, 00196 VAL_E, 00197 VAL_F 00198 }; 00199 00201 #if defined (__ICCARM__) 00202 #pragma section="IEC60335_code" 00203 #else 00204 __attribute__((section(".IEC60335_code"))) 00205 #endif 00206 00208 #if defined (__CC_ARM) 00209 00210 __ASM testResult_t IEC60335_ClassB_PCTest_POST(const Exec_t *fTable, const IEC60335_B_PCTest_ReturnValues *rTable) 00211 { 00212 ;check input parameter 00213 CMP R0, #0 00214 BEQ param 00215 CMP R1, #0 00216 BEQ param 00217 ;save PCTest_funcTable 00218 MOV R8, R0 00219 ;save PCTest_resultTable 00220 MOV R9, R1 00221 ;loop 00222 LDR R4, =0x00 00223 ; LDR R5, =0x18 00224 ;result 00225 LDR R6, =0x00 00226 ;save the Link register 00227 MOV R7, R14 00228 ; calculate function table to execute 00229 loop 00230 ;load next action pointer 00231 MOV R0, R8 00232 ADD R0, R0, R4 00233 LDR R0, [R0] 00234 BLX R0 00235 ; check PCTest_resultTable value 00236 MOV R1, R9 00237 ADD R1, R1, R4 00238 LDR R1, [R1] 00239 ADD R4, R4, #4 00240 CMP R0, R1 00241 BNE err 00242 CMP R4, #24 00243 BNE loop 00244 ;good output 00245 LDR R6, =1 00246 B exit 00247 ;error output 00248 err 00249 LDR R6, =0 00250 exit 00251 ;restore the Link register 00252 MOV R14, R7 00253 MOV R0, R6 00254 param 00255 bx lr 00256 } 00258 #elif defined (__ICCARM__) 00259 00260 /* IAR iccarm specific functions */ 00261 #pragma diag_suppress=Pe940 00262 00263 testResult_t IEC60335_ClassB_PCTest_POST(const Exec_t *fTable, const IEC60335_B_PCTest_ReturnValues *rTable) 00264 { 00265 //;save PCTest_funcTable 00266 __ASM("CMP R0, #0 \n" /* check input parameter */ 00267 "BEQ.W param \n" 00268 "CMP R1, #0 \n" 00269 "BEQ.W param \n" 00270 "MOV R8, R0 \n" /* save PCTest_resultTable */ 00271 "MOV R9, R1 \n" 00272 00273 "MOV R4,#0 \n" /* loop */ 00274 /* LDR R5, =0x18 */ 00275 "MOV R6,#0 \n" /* prepare result */ 00276 "MOV R7, R14 \n" /* save the Link register */ 00277 00278 "loop: nop \n" /* calculate function table to execute */ 00279 "MOV R0, R8 \n" /* load next action pointer */ 00280 "ADD R0, R0, R4 \n" 00281 "LDR R0, [R0] \n" 00282 "BLX R0 \n" 00283 00284 "MOV R1, R9 \n" /* check PCTest_resultTable value */ 00285 "ADD R1, R1, R4 \n" 00286 "LDR R1, [R1] \n" 00287 "ADD R4, R4, #4 \n" 00288 "CMP R0, R1 \n" 00289 "BNE.W err \n" 00290 "CMP R4, #24 \n" 00291 "BNE.W loop \n" 00292 00293 "MOV R6, #1 \n" /* good output */ 00294 "B.W exit \n" 00295 00296 "err: nop \n" /* error output */ 00297 "MOV R6, #0 \n" 00298 "exit: nop \n" 00299 00300 "MOV R14, R7 \n" /* restore the Link register */ 00301 "MOV R0, R6 \n" 00302 "param: nop \n" 00303 "bx lr"); 00304 } 00305 #pragma diag_default=Pe940 00306 00307 #elif defined (__GNUC__) 00308 00309 testResult_t IEC60335_ClassB_PCTest_POST(const Exec_t *fTable, const IEC60335_B_PCTest_ReturnValues *rTable); 00310 00311 testResult_t IEC60335_ClassB_PCTest_POST(const Exec_t *fTable, const IEC60335_B_PCTest_ReturnValues *rTable) 00312 { 00313 #ifdef TESSY 00314 uint32_t result = 0; 00315 #else 00316 register uint32_t result; 00317 #endif 00318 __ASM volatile ("MOV R8, %0 \n" : : "r" (fTable)); 00319 __ASM volatile ("MOV R9, %0 \n" : : "r" (rTable)); 00320 __ASM volatile ("LDR R6, =0x00 \n" /* reset result */ 00321 "CMP R8, #0 \n" /* check input parameter */ 00322 "BEQ param \n" 00323 "CMP R9, #0 \n" 00324 "BEQ param \n" 00325 "LDR R4, =0x00 \n" /* reset counter */ 00326 "LDR R6, =0x00 \n" 00327 "MOV R10, R7 \n" 00328 "MOV R7, R14 \n" 00329 "loop: \n" /* start loop */ 00330 "MOV R0, R8 \n" /* generate next call address */ 00331 "ADD R0, R0, R4 \n" 00332 "LDR R0, [R0] \n" 00333 "BLX R0 \n" /* call subfunction */ 00334 "MOV R1, R9 \n" /* get expected result from table */ 00335 "ADD R1, R1, R4 \n" 00336 "LDR R1, [R1] \n" 00337 "ADD R4, R4, #4 \n" 00338 "CMP R0, R1 \n" /* compare results */ 00339 "BNE err \n" 00340 "CMP R4, #24 \n" 00341 "BNE loop \n" /* cont loop */ 00342 "LDR R6, =1 \n" 00343 "B exit \n" 00344 "err: \n" 00345 "LDR R6, =0 \n" 00346 "exit: \n" 00347 "MOV R14, R7 \n" 00348 "MOV R7, R10 \n" 00349 "param: \n" 00350 "MOV %0, R6 " : "=r" (result)); 00351 return(result); 00352 } 00354 #elif defined (__TASKING__) 00355 00356 #error "not implemented yet !" 00358 #endif 00359 00388 #if defined (__ICCARM__) 00389 #pragma section="IEC60335_code" 00390 #else 00391 __attribute__((section(".IEC60335_code"))) 00392 #endif 00393 00394 testResult_t IEC60335_ClassB_PCTest_BIST(void) 00395 { 00396 static uint8_t lastFunction = 0; 00397 testResult_t result = IEC60335_testFailed; 00398 Exec_t pfAction; 00399 Data_t data = { VAL_G, 100 }; 00400 00401 if ((PCTest_resultTable[0] == 0) || (PCTest_funcTable[0] == 0)) 00402 { 00403 return result; 00404 } 00405 if (lastFunction > 5) 00406 { 00407 lastFunction = 0; 00408 } 00409 00410 pfAction = PCTest_funcTable[lastFunction]; 00411 00412 if (PCTest_resultTable[lastFunction] == (uint32_t)(*pfAction)(&data)) 00413 { 00414 result = IEC60335_testPassed; 00415 lastFunction > 4 ? lastFunction = 0 : lastFunction++; 00416 } 00417 00418 return result; 00419 } 00420 00425 /************************************** EOF *********************************/