sama_secumod.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SAMA5D2x/sama_secumod.c
  15. * @brief SAMA SECUMOD support code.
  16. *
  17. * @addtogroup SAMA5D2x_SECUMOD
  18. * @{
  19. */
  20. #include "hal.h"
  21. #if SAMA_USE_SECUMOD || defined(__DOXYGEN__)
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver exported variables. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief SEC driver identifier.
  30. */
  31. SECDriver SECD0;
  32. /*===========================================================================*/
  33. /* Driver local types. */
  34. /*===========================================================================*/
  35. /*===========================================================================*/
  36. /* Driver local variables. */
  37. /*===========================================================================*/
  38. /*===========================================================================*/
  39. /* Driver constant */
  40. /*===========================================================================*/
  41. /*===========================================================================*/
  42. /* Driver interrupt handlers. */
  43. /*===========================================================================*/
  44. /**
  45. * @brief SECURAM interrupt handler.
  46. *
  47. * @isr
  48. */
  49. OSAL_IRQ_HANDLER(SAMA_SECURAM_HANDLER) {
  50. OSAL_IRQ_PROLOGUE();
  51. uint32_t ramaccsr, sr, sysr;
  52. uint32_t rwx;
  53. uint32_t i;
  54. ramaccsr = SECUMOD->SECUMOD_RAMACCSR;
  55. sr = SECUMOD->SECUMOD_SR;
  56. for (i = 0; i < SECUMOD_RAM_REGIONS; i++) {
  57. rwx = (ramaccsr >> (2 * i)) & 3;
  58. if (rwx != RAMACCSR_NO_VIOLATION && SECD0.config->securam_callback != NULL)
  59. SECD0.config->securam_callback(&SECD0);
  60. }
  61. /* process the end of erase signalling */
  62. do {
  63. sysr = SECUMOD->SECUMOD_SYSR;
  64. } while (sysr & SECUMOD_SYSR_ERASE_ON);
  65. if (SECUMOD_SYSR_ERASE_DONE == (sysr & SECUMOD_SYSR_ERASE_DONE)) {
  66. /* Clear the flag ERASE_DONE */
  67. SECUMOD->SECUMOD_SYSR = SECUMOD_SYSR_ERASE_DONE;
  68. if (SECD0.config->erased_callback != NULL)
  69. SECD0.config->erased_callback(&SECD0);
  70. }
  71. /* wait at least one slow clock */
  72. chSysPolledDelayX(SAMA_PCK / SAMA_SLOW_CLK);
  73. /* Clear RAM access violation flags */
  74. SECUMOD->SECUMOD_RAMACCSR = ramaccsr;
  75. /* Clear corresponding alarm flag bit */
  76. SECUMOD->SECUMOD_SCR = sr;
  77. aicAckInt();
  78. OSAL_IRQ_EPILOGUE();
  79. }
  80. /**
  81. * @brief SECUMOD interrupt handler.
  82. *
  83. * @isr
  84. */
  85. OSAL_IRQ_HANDLER(SAMA_SECUMOD_HANDLER) {
  86. OSAL_IRQ_PROLOGUE();
  87. uint32_t sr, nimpr;
  88. /* Read alarm status */
  89. sr = SECUMOD->SECUMOD_SR;
  90. nimpr = SECUMOD->SECUMOD_NIMPR;
  91. if ((sr & SECUMOD_SR_SHLDM) && (nimpr & SECUMOD_NIMPR_SHLDM)) {
  92. SECD0.secumod_callback(&SECD0, SEC_EVENT_SHLDM);
  93. }
  94. else if ((sr & SECUMOD_SR_DBLFM) && (nimpr & SECUMOD_NIMPR_DBLFM)) {
  95. SECD0.secumod_callback(&SECD0, SEC_EVENT_DBLFM);
  96. }
  97. else if ((sr & SECUMOD_SR_TST) && (nimpr & SECUMOD_NIMPR_TST)) {
  98. SECD0.secumod_callback(&SECD0, SEC_EVENT_TST);
  99. }
  100. else if ((sr & SECUMOD_SR_JTAG) && (nimpr & SECUMOD_NIMPR_JTAG)) {
  101. SECD0.secumod_callback(&SECD0, SEC_EVENT_JTAG);
  102. }
  103. else if ((sr & SECUMOD_SR_MCKM) && (nimpr & SECUMOD_NIMPR_MCKM)) {
  104. SECD0.secumod_callback(&SECD0, SEC_EVENT_MCKM);
  105. }
  106. else if ((sr & SECUMOD_SR_TPML) && (nimpr & SECUMOD_NIMPR_TPML)) {
  107. SECD0.secumod_callback(&SECD0, SEC_EVENT_TPML);
  108. }
  109. else if ((sr & SECUMOD_SR_TPMH) && (nimpr & SECUMOD_NIMPR_TPMH)) {
  110. SECD0.secumod_callback(&SECD0, SEC_EVENT_TPMH);
  111. }
  112. else if ((sr & SECUMOD_SR_VDDBUL) && (nimpr & SECUMOD_NIMPR_VDDBUL)) {
  113. SECD0.secumod_callback(&SECD0, SEC_EVENT_VDDBUL);
  114. }
  115. else if ((sr & SECUMOD_SR_VDDBUH) && (nimpr & SECUMOD_NIMPR_VDDBUH)) {
  116. SECD0.secumod_callback(&SECD0, SEC_EVENT_VDDBUH);
  117. }
  118. else if ((sr & SECUMOD_SR_VDDCOREL) && (nimpr & SECUMOD_NIMPR_VDDCOREL)) {
  119. SECD0.secumod_callback(&SECD0, SEC_EVENT_VDDCOREL);
  120. }
  121. else if ((sr & SECUMOD_SR_VDDCOREH) && (nimpr & SECUMOD_NIMPR_VDDCOREH)) {
  122. SECD0.secumod_callback(&SECD0, SEC_EVENT_VDDCOREH);
  123. }
  124. else if ((sr & SECUMOD_SR_DET0) && (nimpr & SECUMOD_NIMPR_DET0)) {
  125. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU0);
  126. }
  127. else if ((sr & SECUMOD_SR_DET1) && (nimpr & SECUMOD_NIMPR_DET1)) {
  128. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU1);
  129. }
  130. else if ((sr & SECUMOD_SR_DET2) && (nimpr & SECUMOD_NIMPR_DET2)) {
  131. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU2);
  132. }
  133. else if ((sr & SECUMOD_SR_DET3) && (nimpr & SECUMOD_NIMPR_DET3)) {
  134. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU3);
  135. }
  136. else if ((sr & SECUMOD_SR_DET4) && (nimpr & SECUMOD_NIMPR_DET4)) {
  137. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU4);
  138. }
  139. else if ((sr & SECUMOD_SR_DET5) && (nimpr & SECUMOD_NIMPR_DET5)) {
  140. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU5);
  141. }
  142. else if ((sr & SECUMOD_SR_DET6) && (nimpr & SECUMOD_NIMPR_DET6)) {
  143. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU6);
  144. }
  145. else if ((sr & SECUMOD_SR_DET7) && (nimpr & SECUMOD_NIMPR_DET7)) {
  146. SECD0.secumod_callback(&SECD0, SEC_EVENT_PIOBU7);
  147. }
  148. else {
  149. (void) 0;
  150. }
  151. /* wait at least one slow clock */
  152. chSysPolledDelayX(SAMA_PCK / SAMA_SLOW_CLK);
  153. /* Clear corresponding alarm flag bit */
  154. SECUMOD->SECUMOD_SCR = sr;
  155. aicAckInt();
  156. OSAL_IRQ_EPILOGUE();
  157. }
  158. /*===========================================================================*/
  159. /* Driver local functions. */
  160. /*===========================================================================*/
  161. /**
  162. * @brief Configures PIOBU pads according to configuration struct.
  163. *
  164. * @param[in] listp pointer to a PIOBUConfig array
  165. * @param[in] length length of array
  166. *
  167. * @notapi
  168. */
  169. void piobu_config(PIOBUConfig *listp, size_t length) {
  170. uint8_t i;
  171. uint32_t cfg;
  172. uint32_t index;
  173. PIOBUConfig *piobup;
  174. for (i = 0; i < length; i++) {
  175. index = listp[i].pinIndex;
  176. piobup = &listp[i];
  177. /* AFV and RFV fields must be set to 0 when dynamic intrusion is selected. */
  178. if (piobup->dynamic) {
  179. cfg = 0;
  180. } else {
  181. cfg = (piobup->afv << SECUMOD_PIOBU_AFV_Pos ) | (piobup->rfv << SECUMOD_PIOBU_RFV_Pos);
  182. }
  183. if (piobup->mode) {
  184. cfg |= SECUMOD_PIOBU_OUTPUT;
  185. if (piobup->outputLevel)
  186. cfg |= SECUMOD_PIOBU_PIO_SOD;
  187. }
  188. cfg |= piobup->pullUpState << SECUMOD_PIOBU_PULLUP_Pos;
  189. if (piobup->scheduled)
  190. cfg |= SECUMOD_PIOBU_SCHEDULE;
  191. if (piobup->inputDefaultLevel)
  192. cfg |= SECUMOD_PIOBU_SWITCH;
  193. /* FILTER3_5 and DYNSTAT fields exist only for even PIOBUs */
  194. if (0 == (index & 0x01)) {
  195. if (piobup->dynamic)
  196. cfg |= SECUMOD_PIOBU_DYNSTAT;
  197. if (piobup->filter3_5)
  198. cfg |= SECUMOD_PIOBU_FILTER3_5;
  199. }
  200. SECUMOD->SECUMOD_PIOBU[index] = cfg;
  201. }
  202. }
  203. /**
  204. * @brief Low level SEC driver initialization.
  205. *
  206. * @notapi
  207. */
  208. void sec_lld_init(void) {
  209. /* Driver initialization.*/
  210. secObjectInit(&SECD0);
  211. SECD0.sec = SECUMOD;
  212. }
  213. /**
  214. * @brief Configures and activates the SEC peripheral.
  215. *
  216. * @param[in] secp pointer to the @p SECDriver object
  217. *
  218. * @notapi
  219. */
  220. void sec_lld_start(SECDriver *secp) {
  221. uint8_t i;
  222. if (secp->state == SEC_STOP) {
  223. /* Clock activation. */
  224. pmcEnableSEC();
  225. /* Register Reset */
  226. secp->sec->SECUMOD_NIDPR = SECUMOD_NIDPR_ALL;
  227. secumodSetNormalModeProtections(~SECUMOD_NMPR_ALL);
  228. /*
  229. * Configure interrupts
  230. */
  231. aicSetIntSourceType(ID_SECUMOD, INT_LEVEL_SENSITIVE);
  232. aicSetSourcePriority(ID_SECUMOD, SAMA_SECUMOD_IRQ_PRIORITY);
  233. aicSetSourceHandler(ID_SECUMOD, SAMA_SECUMOD_HANDLER);
  234. aicSetIntSourceType(ID_SECURAM, INT_LEVEL_SENSITIVE);
  235. aicSetSourcePriority(ID_SECURAM, SAMA_SECURAM_IRQ_PRIORITY);
  236. aicSetSourceHandler(ID_SECURAM, SAMA_SECURAM_HANDLER);
  237. /* Enabling interrupt. */
  238. aicEnableInt(ID_SECUMOD);
  239. aicEnableInt(ID_SECURAM);
  240. }
  241. uint32_t ramacc_cfg = 0;
  242. /* Select mode normal or backup*/
  243. secp->sec->SECUMOD_CR = secp->config->cr;
  244. /* Configure JTAGCR */
  245. secp->sec->SECUMOD_JTAGCR = secp->config->jtagcr;
  246. /* Configure region rights. */
  247. for (i = 0; i < SECUMOD_RAM_REGIONS; i++) {
  248. ramacc_cfg |= (secp->config->region[i].mode & 0x3u) << (i * 2);
  249. }
  250. secp->sec->SECUMOD_RAMACC = ramacc_cfg;
  251. /* Configure PIOBU pads. */
  252. piobu_config(secp->config->list, secp->config->length);
  253. }
  254. /**
  255. * @brief Deactivates the SEC peripheral.
  256. *
  257. * @param[in] secp pointer to the @p SECDriver object
  258. *
  259. * @notapi
  260. */
  261. void sec_lld_stop(SECDriver *secp) {
  262. secp->sec->SECUMOD_NMPR &= ~(0xFF << 16);
  263. secp->sec->SECUMOD_NIDPR |= (0xFF << 16);
  264. aicDisableInt(ID_SECURAM);
  265. aicDisableInt(ID_SECUMOD);
  266. pmcDisableSEC();
  267. }
  268. /*===========================================================================*/
  269. /* Driver exported functions. */
  270. /*===========================================================================*/
  271. /**
  272. * @brief SEC Driver initialization.
  273. *
  274. * @init
  275. */
  276. void secInit(void) {
  277. sec_lld_init();
  278. }
  279. /**
  280. * @brief Initializes the standard part of a @p SECDriver structure.
  281. *
  282. * @param[out] secp pointer to a @p SECDriver object
  283. *
  284. * @init
  285. */
  286. void secObjectInit(SECDriver *secp) {
  287. secp->state = SEC_STOP;
  288. secp->config = NULL;
  289. }
  290. /**
  291. * @brief Configures and activates the SEC peripheral.
  292. *
  293. * @param[in] secp pointer to a @p SECDriver object
  294. * @param[in] config pointer to a @p SECConfig object
  295. *
  296. * @api
  297. */
  298. void secStart(SECDriver *secp, const SECConfig *config) {
  299. osalDbgCheck((secp != NULL) && (config != NULL));
  300. osalSysLock();
  301. osalDbgAssert((secp->state == SEC_STOP), "invalid state");
  302. secp->config = config;
  303. sec_lld_start(secp);
  304. secp->state = SEC_ACTIVE;
  305. osalSysUnlock();
  306. }
  307. /**
  308. * @brief Deactivates the SEC peripheral.
  309. *
  310. * @param[in] secp pointer to a @p SECDriver object
  311. *
  312. * @api
  313. */
  314. void secStop(SECDriver *secp) {
  315. osalDbgCheck(secp != NULL);
  316. osalSysLock();
  317. osalDbgAssert((secp->state == SEC_STOP) || (secp->state == SEC_ACTIVE),
  318. "invalid state");
  319. sec_lld_stop(secp);
  320. secp->config = NULL;
  321. secp->state = SEC_STOP;
  322. osalSysUnlock();
  323. }
  324. /**
  325. * @brief Enables or disables SECUMOD callbacks.
  326. * @details This function enables or disables callbacks, use a @p NULL pointer
  327. * in order to disable a callback.
  328. * @note The function can be called from any context.
  329. *
  330. * @param[in] secp pointer to SECUMOD driver structure
  331. * @param[in] sources Bitwise OR of protections.
  332. * @param[in] callback callback function pointer or @p NULL
  333. *
  334. * @api
  335. */
  336. void secSetCallback(SECDriver *secp, uint32_t sources, secumod_callback_t callback) {
  337. osalDbgCheck(secp != NULL);
  338. syssts_t sts;
  339. /* Entering a reentrant critical zone.*/
  340. sts = osalSysGetStatusAndLockX();
  341. if (callback != NULL) {
  342. /* IRQ sources enabled only after setting up the callback.*/
  343. secp->secumod_callback = callback;
  344. secp->sec->SECUMOD_NIEPR = sources;
  345. if (SECUMOD->SECUMOD_NIMPR != sources) {
  346. secumodToggleProtectionReg();
  347. secp->sec->SECUMOD_NIEPR = sources;
  348. }
  349. }
  350. else {
  351. secp->sec->SECUMOD_NIDPR = sources;
  352. /* Callback set to NULL only after disabling the IRQ sources.*/
  353. secp->secumod_callback = NULL;
  354. }
  355. /* Leaving a reentrant critical zone.*/
  356. osalSysRestoreStatusX(sts);
  357. }
  358. /**
  359. * @brief Set JTAG protection options of SECUMOD.
  360. *
  361. * @param[in] reset Whether preventing debug state and BSD (Boundary Scan Diagnostics) to work.
  362. * @param[in] permissions Debug permissions.
  363. * @param[in] ack Whether monitor the DBGACK signal.
  364. *
  365. * @api
  366. */
  367. void secumodSetJtagProtection(bool reset, uint8_t permissions,
  368. bool ack) {
  369. uint32_t jtagcr;
  370. jtagcr = permissions << SECUMOD_JTAGCR_CA5_DEBUG_MODE_Pos;
  371. if (reset)
  372. jtagcr |= SECUMOD_JTAGCR_FNTRST;
  373. if (ack)
  374. jtagcr |= SECUMOD_JTAGCR_CA5_DEBUG_MON;
  375. SECUMOD->SECUMOD_JTAGCR = jtagcr;
  376. }
  377. /**
  378. * @brief Tuning dynamic signatures by period and threshold.
  379. *
  380. * @param[in] period Signature Clock Period.
  381. * @param[in] detection_thr Error Detection Threshold.
  382. * @param[in] reset_thr Error Counter Reset Threshold.
  383. *
  384. * @api
  385. */
  386. void secumodDynamicSignaturesTuning(uint16_t period,
  387. uint8_t detectionThr, uint8_t resetThr) {
  388. uint32_t dystune;
  389. dystune = SECUMOD->SECUMOD_DYSTUNE & SECUMOD_DYSTUNE_NOPA;
  390. dystune |= SECUMOD_DYSTUNE_PERIOD(period);
  391. dystune |= SECUMOD_DYSTUNE_RX_ERROR_THRESHOLD(detectionThr);
  392. dystune |= SECUMOD_DYSTUNE_RX_OK_CORREL_NUMBER(resetThr);
  393. SECUMOD->SECUMOD_DYSTUNE = dystune;
  394. }
  395. /**
  396. * @brief Enable/Disable alarm regenerated periodically while intrusion is maintained.
  397. *
  398. * @param[in] enable periodic alarm while intrusion is maintained,
  399. * true: disable, false: enable.
  400. * @api
  401. */
  402. void secumodPeriodicAlarm(bool enable) {
  403. uint32_t tmp;
  404. tmp = SECUMOD->SECUMOD_DYSTUNE & ~SECUMOD_DYSTUNE_NOPA;
  405. if (!enable)
  406. tmp |= SECUMOD_DYSTUNE_NOPA;
  407. SECUMOD->SECUMOD_DYSTUNE = tmp;
  408. }
  409. /**
  410. * @brief Set access rights for secure RAM in SECUMOD.
  411. *
  412. * @param[in] region RAM region N,
  413. * for N = 0 ~ 5: RAM range (N)Kbyte ~ (N+1)Kbyte;
  414. * for N = 5: register bank 256bit.
  415. * @param rights 0: No access allowed;
  416. * 1: Only write access allowed;
  417. * 2: Only read access allowed;
  418. * 3: Read and write access allowed.
  419. * @api
  420. */
  421. void secumodSetRamAccessRights(uint32_t region, uint8_t rights) {
  422. uint32_t tmp;
  423. tmp = SECUMOD->SECUMOD_RAMACC & ~SECUMOD_RAMACC_RWx_Msk(region);
  424. SECUMOD->SECUMOD_RAMACC = tmp | (rights << SECUMOD_RAMACC_RWx_Pos(region));
  425. }
  426. /**
  427. * @brief Read the SECUMOD internal memory from the specified address
  428. *
  429. * @param[in] data Point to where the data read is stored
  430. * @param[in] addr memory address
  431. * @param[in] size The number of bytes to be read
  432. *
  433. * @return Bytes read
  434. *
  435. * @api
  436. */
  437. uint32_t secumodReadInternalMemory(uint8_t *data, uint32_t addr, uint32_t size) {
  438. uint32_t i;
  439. uint32_t region;
  440. uint32_t count;
  441. if (addr >= ((uint32_t)SECURAM))
  442. addr -= ((uint32_t)SECURAM);
  443. secumodMemReady();
  444. for (i = 0; i < size; i += count) {
  445. region = (addr + i) >> 10;
  446. if ((SECUMOD_RAMACC_RWx_NO_ACCESS(region) ==
  447. (SECUMOD->SECUMOD_RAMACC & SECUMOD_RAMACC_RWx_Msk(region))) ||
  448. (SECUMOD_RAMACC_RWx_WR_ACCESS(region) ==
  449. (SECUMOD->SECUMOD_RAMACC & SECUMOD_RAMACC_RWx_Msk(region)))) {
  450. break;
  451. }
  452. count = size;
  453. if (((region + 1) << 10 ) <= (addr + i + size)) {
  454. size = ((region + 1) << 10) - (addr + i);
  455. }
  456. memcpy(data + i, (uint8_t *)(((uint32_t)SECURAM) + addr + i), count);
  457. }
  458. return i;
  459. }
  460. /**
  461. * @brief Write data to the SECUMOD internal memory from the specified address
  462. *
  463. * @param[in] data Pointer to the data to be written
  464. * @param[in] addr memory address
  465. * @param[in] size The number of bytes to be be written
  466. *
  467. * @return Bytes written
  468. *
  469. * @api
  470. */
  471. uint32_t secumodWriteInternalMemory(uint8_t *data, uint32_t addr, uint32_t size) {
  472. uint32_t i;
  473. uint32_t region;
  474. uint32_t count;
  475. if (addr >= ((uint32_t)SECURAM))
  476. addr -= ((uint32_t)SECURAM);
  477. secumodMemReady();
  478. for (i = 0; i < size; i += count) {
  479. region = (addr + i) >> 10;
  480. if ((SECUMOD_RAMACC_RWx_NO_ACCESS(region) ==
  481. (SECUMOD->SECUMOD_RAMACC & SECUMOD_RAMACC_RWx_Msk(region))) ||
  482. (SECUMOD_RAMACC_RWx_RD_ACCESS(region) ==
  483. (SECUMOD->SECUMOD_RAMACC & SECUMOD_RAMACC_RWx_Msk(region)))) {
  484. break;
  485. }
  486. count = size;
  487. if (((region + 1) << 10 ) <= (addr + i + size)) {
  488. size = ((region + 1) << 10) - (addr + i);
  489. }
  490. memcpy((uint8_t *)(((uint32_t)SECURAM) + addr + i), data + i, count);
  491. }
  492. return i;
  493. }
  494. #endif /* SAMA_USE_SECUMOD */
  495. /** @} */