fsl_ltc_edma.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2018 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_ltc_edma.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /* Component ID definition, used by tools. */
  39. #ifndef FSL_COMPONENT_ID
  40. #define FSL_COMPONENT_ID "platform.drivers.ltc_edma"
  41. #endif
  42. /*<! Structure definition for ltc_edma_private_handle_t. The structure is private. */
  43. typedef struct _ltc_edma_private_handle
  44. {
  45. LTC_Type *base;
  46. ltc_edma_handle_t *handle;
  47. } ltc_edma_private_handle_t;
  48. /*******************************************************************************
  49. * Variables
  50. ******************************************************************************/
  51. /*<! Private handle only used for internally. */
  52. static ltc_edma_private_handle_t s_edmaPrivateHandle[FSL_FEATURE_SOC_LTC_COUNT];
  53. /* Array of LTC peripheral base address. */
  54. static LTC_Type *const s_ltcBase[] = LTC_BASE_PTRS;
  55. /*******************************************************************************
  56. * Variables
  57. ******************************************************************************/
  58. /* State machine state.*/
  59. #define LTC_SM_STATE_START 0x0000u
  60. #define LTC_SM_STATE_FINISH 0xFFFFu
  61. #define LTC_FIFO_SZ_MAX_DOWN_ALGN (0xff0u)
  62. enum _ltc_md_dk_bit_shift
  63. {
  64. kLTC_ModeRegBitShiftDK = 12U,
  65. };
  66. /*******************************************************************************
  67. * Prototypes
  68. ******************************************************************************/
  69. static uint32_t LTC_GetInstance(LTC_Type *base);
  70. static void ltc_symmetric_process_EDMA(LTC_Type *base, uint32_t inSize, const uint8_t **inData, uint8_t **outData);
  71. static status_t ltc_process_message_in_sessions_EDMA(LTC_Type *base, ltc_edma_handle_t *handle);
  72. /*******************************************************************************
  73. * Code
  74. ******************************************************************************/
  75. /*******************************************************************************
  76. * LTC Common code static
  77. ******************************************************************************/
  78. /*!
  79. * @brief Splits the LTC job into sessions. Used for CBC, CTR, CFB, OFB cipher block modes.
  80. *
  81. * @param base LTC peripheral base address
  82. * @param inData Input data to process.
  83. * @param inSize Input size of the input buffer.
  84. * @param outData Output data buffer.
  85. */
  86. static status_t ltc_process_message_in_sessions_EDMA(LTC_Type *base, ltc_edma_handle_t *handle)
  87. {
  88. status_t retval;
  89. bool exit_sm = false;
  90. handle->modeReg = base->MD;
  91. retval = kStatus_Success;
  92. if ((!handle->inData) || (!handle->outData))
  93. {
  94. handle->state = LTC_SM_STATE_FINISH; /* END */
  95. retval = kStatus_InvalidArgument;
  96. }
  97. while (exit_sm == false)
  98. {
  99. switch (handle->state)
  100. {
  101. case LTC_SM_STATE_START:
  102. if (handle->size)
  103. {
  104. uint32_t sz;
  105. if (handle->size <= LTC_FIFO_SZ_MAX_DOWN_ALGN)
  106. {
  107. sz = handle->size;
  108. }
  109. else
  110. {
  111. sz = LTC_FIFO_SZ_MAX_DOWN_ALGN;
  112. }
  113. /* retval = ltc_symmetric_process_data_EDMA(base, handle->inData, sz, handle->outData); */
  114. {
  115. uint32_t lastSize;
  116. uint32_t inSize = sz;
  117. /* Write the data size. */
  118. base->DS = inSize;
  119. /* Split the inSize into full 16-byte chunks and last incomplete block due to LTC AES OFIFO
  120. * errata */
  121. if (inSize <= 16u)
  122. {
  123. lastSize = inSize;
  124. inSize = 0;
  125. }
  126. else
  127. {
  128. /* Process all 16-byte data chunks. */
  129. lastSize = inSize % 16u;
  130. if (lastSize == 0)
  131. {
  132. lastSize = 16;
  133. inSize -= 16;
  134. }
  135. else
  136. {
  137. inSize -=
  138. lastSize; /* inSize will be rounded down to 16 byte boundary. remaining bytes in
  139. lastSize */
  140. }
  141. }
  142. if (inSize)
  143. {
  144. handle->size -= inSize;
  145. ltc_symmetric_process_EDMA(base, inSize, &handle->inData, &handle->outData);
  146. exit_sm = true;
  147. }
  148. else if (lastSize)
  149. {
  150. ltc_symmetric_process(base, lastSize, &handle->inData, &handle->outData);
  151. retval = ltc_wait(base);
  152. handle->size -= lastSize;
  153. }
  154. else
  155. {
  156. }
  157. }
  158. }
  159. else
  160. {
  161. handle->state = LTC_SM_STATE_FINISH;
  162. }
  163. break;
  164. case LTC_SM_STATE_FINISH:
  165. default:
  166. base->MD = handle->modeReg;
  167. ltc_clear_all(base, false);
  168. if (handle->callback)
  169. {
  170. handle->callback(base, handle, retval, handle->userData);
  171. }
  172. exit_sm = true;
  173. break;
  174. }
  175. }
  176. return retval;
  177. }
  178. /*!
  179. * @brief Splits the LTC job into sessions. Used for CBC, CTR, CFB, OFB cipher block modes.
  180. *
  181. * @param base LTC peripheral base address
  182. * @param inData Input data to process.
  183. * @param inSize Input size of the input buffer.
  184. * @param outData Output data buffer.
  185. */
  186. static status_t ltc_process_message_in_sessions_ctr_EDMA(LTC_Type *base, ltc_edma_handle_t *handle)
  187. {
  188. status_t retval;
  189. bool exit_sm = false;
  190. handle->modeReg = base->MD;
  191. retval = kStatus_Success;
  192. if ((!handle->inData) || (!handle->outData))
  193. {
  194. handle->state = LTC_SM_STATE_FINISH;
  195. retval = kStatus_InvalidArgument;
  196. }
  197. while (exit_sm == false)
  198. {
  199. switch (handle->state)
  200. {
  201. case LTC_SM_STATE_START:
  202. if (handle->size)
  203. {
  204. uint32_t sz;
  205. if (handle->size <= LTC_FIFO_SZ_MAX_DOWN_ALGN)
  206. {
  207. sz = handle->size;
  208. }
  209. else
  210. {
  211. sz = LTC_FIFO_SZ_MAX_DOWN_ALGN;
  212. }
  213. /* retval = ltc_symmetric_process_data_EDMA(base, handle->inData, sz, handle->outData); */
  214. {
  215. uint32_t lastSize;
  216. uint32_t inSize = sz;
  217. /* Write the data size. */
  218. base->DS = inSize;
  219. /* Split the inSize into full 16-byte chunks and last incomplete block due to LTC AES OFIFO
  220. * errata */
  221. if (inSize <= 16u)
  222. {
  223. lastSize = inSize;
  224. inSize = 0;
  225. }
  226. else
  227. {
  228. /* Process all 16-byte data chunks. */
  229. lastSize = inSize % 16u;
  230. if (lastSize == 0)
  231. {
  232. lastSize = 16;
  233. inSize -= 16;
  234. }
  235. else
  236. {
  237. inSize -=
  238. lastSize; /* inSize will be rounded down to 16 byte boundary. remaining bytes in
  239. lastSize */
  240. }
  241. }
  242. if (inSize)
  243. {
  244. handle->size -= inSize;
  245. ltc_symmetric_process_EDMA(base, inSize, &handle->inData, &handle->outData);
  246. exit_sm = true;
  247. }
  248. else if (lastSize)
  249. {
  250. ltc_symmetric_process(base, lastSize, &handle->inData, &handle->outData);
  251. retval = ltc_wait(base);
  252. handle->size -= lastSize;
  253. }
  254. else
  255. {
  256. }
  257. }
  258. }
  259. else
  260. {
  261. handle->state = LTC_SM_STATE_FINISH;
  262. }
  263. break;
  264. case LTC_SM_STATE_FINISH:
  265. default:
  266. base->MD = handle->modeReg;
  267. /* CTR final phase.*/
  268. if (kStatus_Success == retval)
  269. {
  270. const uint8_t *input = handle->inData;
  271. uint8_t *output = handle->outData;
  272. if ((handle->counterlast != NULL) && (handle->lastSize))
  273. {
  274. uint8_t zeroes[16] = {0};
  275. ltc_mode_t modeReg;
  276. modeReg = (uint32_t)kLTC_AlgorithmAES | (uint32_t)kLTC_ModeCTR | (uint32_t)kLTC_ModeEncrypt;
  277. /* Write the mode register to the hardware. */
  278. base->MD = modeReg | (uint32_t)kLTC_ModeFinalize;
  279. /* context is re-used (CTRi) */
  280. /* Process data and return status. */
  281. retval = ltc_symmetric_process_data(base, input, handle->lastSize, output);
  282. if (kStatus_Success == retval)
  283. {
  284. if (handle->szLeft)
  285. {
  286. *handle->szLeft = 16U - handle->lastSize;
  287. }
  288. /* Initialize algorithm state. */
  289. base->MD = modeReg | (uint32_t)kLTC_ModeUpdate;
  290. /* context is re-used (CTRi) */
  291. /* Process data and return status. */
  292. retval = ltc_symmetric_process_data(base, zeroes, 16U, handle->counterlast);
  293. }
  294. }
  295. if (kStatus_Success == retval)
  296. {
  297. ltc_get_context(base, &handle->counter[0], 16U, 4U);
  298. ltc_clear_all(base, false);
  299. }
  300. }
  301. if (handle->callback)
  302. {
  303. handle->callback(base, handle, retval, handle->userData);
  304. }
  305. exit_sm = true;
  306. break;
  307. }
  308. }
  309. return retval;
  310. }
  311. /*******************************************************************************
  312. * AES Code public
  313. ******************************************************************************/
  314. status_t LTC_AES_EncryptEcbEDMA(LTC_Type *base,
  315. ltc_edma_handle_t *handle,
  316. const uint8_t *plaintext,
  317. uint8_t *ciphertext,
  318. uint32_t size,
  319. const uint8_t *key,
  320. uint32_t keySize)
  321. {
  322. status_t retval;
  323. if ((ltc_check_key_size(keySize) == 0) || (size < 16u) ||
  324. (size % 16u)) /* ECB mode, size must be 16-byte multiple */
  325. {
  326. if (handle->callback)
  327. {
  328. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  329. }
  330. return kStatus_InvalidArgument;
  331. }
  332. /* Initialize algorithm state. */
  333. ltc_symmetric_update(base, key, keySize, kLTC_AlgorithmAES, kLTC_ModeECB, kLTC_ModeEncrypt);
  334. /* Process data and return status. */
  335. handle->inData = &plaintext[0];
  336. handle->outData = &ciphertext[0];
  337. handle->size = size;
  338. handle->state = LTC_SM_STATE_START;
  339. handle->state_machine = ltc_process_message_in_sessions_EDMA;
  340. retval = handle->state_machine(base, handle);
  341. return retval;
  342. }
  343. status_t LTC_AES_DecryptEcbEDMA(LTC_Type *base,
  344. ltc_edma_handle_t *handle,
  345. const uint8_t *ciphertext,
  346. uint8_t *plaintext,
  347. uint32_t size,
  348. const uint8_t *key,
  349. uint32_t keySize,
  350. ltc_aes_key_t keyType)
  351. {
  352. status_t status;
  353. if ((ltc_check_key_size(keySize) == 0) || (size < 16u) ||
  354. (size % 16u)) /* ECB mode, size must be 16-byte multiple */
  355. {
  356. if (handle->callback)
  357. {
  358. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  359. }
  360. return kStatus_InvalidArgument;
  361. }
  362. /* Initialize algorithm state. */
  363. ltc_symmetric_update(base, key, keySize, kLTC_AlgorithmAES, kLTC_ModeECB, kLTC_ModeDecrypt);
  364. /* set DK bit in the LTC Mode Register AAI field for directly loaded decrypt keys */
  365. if (keyType == kLTC_DecryptKey)
  366. {
  367. base->MD |= (1U << kLTC_ModeRegBitShiftDK);
  368. }
  369. /* Process data and return status. */
  370. handle->inData = &ciphertext[0];
  371. handle->outData = &plaintext[0];
  372. handle->size = size;
  373. handle->state = LTC_SM_STATE_START;
  374. handle->state_machine = ltc_process_message_in_sessions_EDMA;
  375. status = handle->state_machine(base, handle);
  376. return status;
  377. }
  378. status_t LTC_AES_EncryptCbcEDMA(LTC_Type *base,
  379. ltc_edma_handle_t *handle,
  380. const uint8_t *plaintext,
  381. uint8_t *ciphertext,
  382. uint32_t size,
  383. const uint8_t iv[LTC_AES_IV_SIZE],
  384. const uint8_t *key,
  385. uint32_t keySize)
  386. {
  387. status_t retval;
  388. if ((ltc_check_key_size(keySize) == 0) || (size < 16u) ||
  389. (size % 16u)) /* CBC mode, size must be 16-byte multiple */
  390. {
  391. if (handle->callback)
  392. {
  393. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  394. }
  395. return kStatus_InvalidArgument;
  396. }
  397. /* Initialize algorithm state. */
  398. ltc_symmetric_update(base, key, keySize, kLTC_AlgorithmAES, kLTC_ModeCBC, kLTC_ModeEncrypt);
  399. /* Write IV data to the context register. */
  400. ltc_set_context(base, &iv[0], LTC_AES_IV_SIZE, 0);
  401. /* Process data and return status. */
  402. handle->inData = &plaintext[0];
  403. handle->outData = &ciphertext[0];
  404. handle->size = size;
  405. handle->state = LTC_SM_STATE_START;
  406. handle->state_machine = ltc_process_message_in_sessions_EDMA;
  407. retval = handle->state_machine(base, handle);
  408. return retval;
  409. }
  410. status_t LTC_AES_DecryptCbcEDMA(LTC_Type *base,
  411. ltc_edma_handle_t *handle,
  412. const uint8_t *ciphertext,
  413. uint8_t *plaintext,
  414. uint32_t size,
  415. const uint8_t iv[LTC_AES_IV_SIZE],
  416. const uint8_t *key,
  417. uint32_t keySize,
  418. ltc_aes_key_t keyType)
  419. {
  420. status_t retval;
  421. if ((ltc_check_key_size(keySize) == 0) || (size < 16u) ||
  422. (size % 16u)) /* CBC mode, size must be 16-byte multiple */
  423. {
  424. if (handle->callback)
  425. {
  426. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  427. }
  428. return kStatus_InvalidArgument;
  429. }
  430. /* set DK bit in the LTC Mode Register AAI field for directly loaded decrypt keys */
  431. if (keyType == kLTC_DecryptKey)
  432. {
  433. base->MD |= (1U << kLTC_ModeRegBitShiftDK);
  434. }
  435. /* Initialize algorithm state. */
  436. ltc_symmetric_update(base, key, keySize, kLTC_AlgorithmAES, kLTC_ModeCBC, kLTC_ModeDecrypt);
  437. /* Write IV data to the context register. */
  438. ltc_set_context(base, &iv[0], LTC_AES_IV_SIZE, 0);
  439. /* Process data and return status. */
  440. handle->inData = &ciphertext[0];
  441. handle->outData = &plaintext[0];
  442. handle->size = size;
  443. handle->state = LTC_SM_STATE_START;
  444. handle->state_machine = ltc_process_message_in_sessions_EDMA;
  445. retval = handle->state_machine(base, handle);
  446. return retval;
  447. }
  448. status_t LTC_AES_CryptCtrEDMA(LTC_Type *base,
  449. ltc_edma_handle_t *handle,
  450. const uint8_t *input,
  451. uint8_t *output,
  452. uint32_t size,
  453. uint8_t counter[LTC_AES_BLOCK_SIZE],
  454. const uint8_t *key,
  455. uint32_t keySize,
  456. uint8_t counterlast[LTC_AES_BLOCK_SIZE],
  457. uint32_t *szLeft)
  458. {
  459. status_t retval;
  460. uint32_t lastSize;
  461. if (!ltc_check_key_size(keySize))
  462. {
  463. if (handle->callback)
  464. {
  465. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  466. }
  467. return kStatus_InvalidArgument;
  468. }
  469. lastSize = 0U;
  470. if (counterlast != NULL)
  471. {
  472. /* Split the size into full 16-byte chunks and last incomplete block due to LTC AES OFIFO errata */
  473. if (size <= 16U)
  474. {
  475. lastSize = size;
  476. size = 0U;
  477. }
  478. else
  479. {
  480. /* Process all 16-byte data chunks. */
  481. lastSize = size % 16U;
  482. if (lastSize == 0U)
  483. {
  484. lastSize = 16U;
  485. size -= 16U;
  486. }
  487. else
  488. {
  489. size -= lastSize; /* size will be rounded down to 16 byte boundary. remaining bytes in lastSize */
  490. }
  491. }
  492. }
  493. /* Initialize algorithm state. */
  494. ltc_symmetric_update(base, key, keySize, kLTC_AlgorithmAES, kLTC_ModeCTR, kLTC_ModeEncrypt);
  495. /* Write initial counter data to the context register.
  496. * NOTE the counter values start at 4-bytes offset into the context. */
  497. ltc_set_context(base, &counter[0], 16U, 4U);
  498. /* Process data and return status. */
  499. handle->inData = &input[0];
  500. handle->outData = &output[0];
  501. handle->size = size;
  502. handle->state = LTC_SM_STATE_START;
  503. handle->state_machine = ltc_process_message_in_sessions_ctr_EDMA;
  504. handle->counter = counter;
  505. handle->key = key;
  506. handle->keySize = keySize;
  507. handle->counterlast = counterlast;
  508. handle->szLeft = szLeft;
  509. handle->lastSize = lastSize;
  510. retval = handle->state_machine(base, handle);
  511. return retval;
  512. }
  513. #if defined(FSL_FEATURE_LTC_HAS_DES) && FSL_FEATURE_LTC_HAS_DES
  514. /*******************************************************************************
  515. * DES / 3DES Code static
  516. ******************************************************************************/
  517. static status_t ltc_des_process_EDMA(LTC_Type *base,
  518. ltc_edma_handle_t *handle,
  519. const uint8_t *input,
  520. uint8_t *output,
  521. uint32_t size,
  522. const uint8_t iv[LTC_DES_IV_SIZE],
  523. const uint8_t key[LTC_DES_KEY_SIZE],
  524. ltc_mode_symmetric_alg_t modeAs,
  525. ltc_mode_encrypt_t modeEnc)
  526. {
  527. status_t retval;
  528. /* all but OFB, size must be 8-byte multiple */
  529. if ((modeAs != kLTC_ModeOFB) && ((size < 8u) || (size % 8u)))
  530. {
  531. if (handle->callback)
  532. {
  533. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  534. }
  535. return kStatus_InvalidArgument;
  536. }
  537. /* Initialize algorithm state. */
  538. ltc_symmetric_update(base, &key[0], LTC_DES_KEY_SIZE, kLTC_AlgorithmDES, modeAs, modeEnc);
  539. if ((modeAs != kLTC_ModeECB))
  540. {
  541. ltc_set_context(base, iv, LTC_DES_IV_SIZE, 0);
  542. }
  543. /* Process data and return status. */
  544. handle->inData = input;
  545. handle->outData = output;
  546. handle->size = size;
  547. handle->state = LTC_SM_STATE_START;
  548. handle->state_machine = ltc_process_message_in_sessions_EDMA;
  549. retval = handle->state_machine(base, handle);
  550. return retval;
  551. }
  552. static status_t ltc_3des_process_EDMA(LTC_Type *base,
  553. ltc_edma_handle_t *handle,
  554. const uint8_t *input,
  555. uint8_t *output,
  556. uint32_t size,
  557. const uint8_t iv[LTC_DES_IV_SIZE],
  558. const uint8_t key1[LTC_DES_KEY_SIZE],
  559. const uint8_t key2[LTC_DES_KEY_SIZE],
  560. const uint8_t key3[LTC_DES_KEY_SIZE],
  561. ltc_mode_symmetric_alg_t modeAs,
  562. ltc_mode_encrypt_t modeEnc)
  563. {
  564. status_t retval;
  565. uint8_t key[LTC_DES_KEY_SIZE * 3];
  566. uint8_t keySize = LTC_DES_KEY_SIZE * 2;
  567. retval = ltc_3des_check_input_args(modeAs, size, key1, key2);
  568. if (kStatus_Success != retval)
  569. {
  570. if (handle->callback)
  571. {
  572. handle->callback(base, handle, kStatus_InvalidArgument, handle->userData);
  573. }
  574. return retval;
  575. }
  576. ltc_memcpy(&key[0], &key1[0], LTC_DES_KEY_SIZE);
  577. ltc_memcpy(&key[LTC_DES_KEY_SIZE], &key2[0], LTC_DES_KEY_SIZE);
  578. if (key3)
  579. {
  580. ltc_memcpy(&key[LTC_DES_KEY_SIZE * 2], &key3[0], LTC_DES_KEY_SIZE);
  581. keySize = sizeof(key);
  582. }
  583. /* Initialize algorithm state. */
  584. ltc_symmetric_update(base, &key[0], keySize, kLTC_Algorithm3DES, modeAs, modeEnc);
  585. if ((modeAs != kLTC_ModeECB))
  586. {
  587. ltc_set_context(base, iv, LTC_DES_IV_SIZE, 0);
  588. }
  589. /* Process data and return status. */
  590. handle->inData = input;
  591. handle->outData = output;
  592. handle->size = size;
  593. handle->state = LTC_SM_STATE_START;
  594. handle->state_machine = ltc_process_message_in_sessions_EDMA;
  595. retval = handle->state_machine(base, handle);
  596. return retval;
  597. }
  598. /*******************************************************************************
  599. * DES / 3DES Code public
  600. ******************************************************************************/
  601. status_t LTC_DES_EncryptEcbEDMA(LTC_Type *base,
  602. ltc_edma_handle_t *handle,
  603. const uint8_t *plaintext,
  604. uint8_t *ciphertext,
  605. uint32_t size,
  606. const uint8_t key[LTC_DES_KEY_SIZE])
  607. {
  608. return ltc_des_process_EDMA(base, handle, plaintext, ciphertext, size, NULL, key, kLTC_ModeECB, kLTC_ModeEncrypt);
  609. }
  610. status_t LTC_DES_DecryptEcbEDMA(LTC_Type *base,
  611. ltc_edma_handle_t *handle,
  612. const uint8_t *ciphertext,
  613. uint8_t *plaintext,
  614. uint32_t size,
  615. const uint8_t key[LTC_DES_KEY_SIZE])
  616. {
  617. return ltc_des_process_EDMA(base, handle, ciphertext, plaintext, size, NULL, key, kLTC_ModeECB, kLTC_ModeDecrypt);
  618. }
  619. status_t LTC_DES_EncryptCbcEDMA(LTC_Type *base,
  620. ltc_edma_handle_t *handle,
  621. const uint8_t *plaintext,
  622. uint8_t *ciphertext,
  623. uint32_t size,
  624. const uint8_t iv[LTC_DES_IV_SIZE],
  625. const uint8_t key[LTC_DES_KEY_SIZE])
  626. {
  627. return ltc_des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key, kLTC_ModeCBC, kLTC_ModeEncrypt);
  628. }
  629. status_t LTC_DES_DecryptCbcEDMA(LTC_Type *base,
  630. ltc_edma_handle_t *handle,
  631. const uint8_t *ciphertext,
  632. uint8_t *plaintext,
  633. uint32_t size,
  634. const uint8_t iv[LTC_DES_IV_SIZE],
  635. const uint8_t key[LTC_DES_KEY_SIZE])
  636. {
  637. return ltc_des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key, kLTC_ModeCBC, kLTC_ModeDecrypt);
  638. }
  639. status_t LTC_DES_EncryptCfbEDMA(LTC_Type *base,
  640. ltc_edma_handle_t *handle,
  641. const uint8_t *plaintext,
  642. uint8_t *ciphertext,
  643. uint32_t size,
  644. const uint8_t iv[LTC_DES_IV_SIZE],
  645. const uint8_t key[LTC_DES_KEY_SIZE])
  646. {
  647. return ltc_des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key, kLTC_ModeCFB, kLTC_ModeEncrypt);
  648. }
  649. status_t LTC_DES_DecryptCfbEDMA(LTC_Type *base,
  650. ltc_edma_handle_t *handle,
  651. const uint8_t *ciphertext,
  652. uint8_t *plaintext,
  653. uint32_t size,
  654. const uint8_t iv[LTC_DES_IV_SIZE],
  655. const uint8_t key[LTC_DES_KEY_SIZE])
  656. {
  657. return ltc_des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key, kLTC_ModeCFB, kLTC_ModeDecrypt);
  658. }
  659. status_t LTC_DES_EncryptOfbEDMA(LTC_Type *base,
  660. ltc_edma_handle_t *handle,
  661. const uint8_t *plaintext,
  662. uint8_t *ciphertext,
  663. uint32_t size,
  664. const uint8_t iv[LTC_DES_IV_SIZE],
  665. const uint8_t key[LTC_DES_KEY_SIZE])
  666. {
  667. return ltc_des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key, kLTC_ModeOFB, kLTC_ModeEncrypt);
  668. }
  669. status_t LTC_DES_DecryptOfbEDMA(LTC_Type *base,
  670. ltc_edma_handle_t *handle,
  671. const uint8_t *ciphertext,
  672. uint8_t *plaintext,
  673. uint32_t size,
  674. const uint8_t iv[LTC_DES_IV_SIZE],
  675. const uint8_t key[LTC_DES_KEY_SIZE])
  676. {
  677. return ltc_des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key, kLTC_ModeOFB, kLTC_ModeDecrypt);
  678. }
  679. status_t LTC_DES2_EncryptEcbEDMA(LTC_Type *base,
  680. ltc_edma_handle_t *handle,
  681. const uint8_t *plaintext,
  682. uint8_t *ciphertext,
  683. uint32_t size,
  684. const uint8_t key1[LTC_DES_KEY_SIZE],
  685. const uint8_t key2[LTC_DES_KEY_SIZE])
  686. {
  687. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, NULL, key1, key2, NULL, kLTC_ModeECB,
  688. kLTC_ModeEncrypt);
  689. }
  690. status_t LTC_DES3_EncryptEcbEDMA(LTC_Type *base,
  691. ltc_edma_handle_t *handle,
  692. const uint8_t *plaintext,
  693. uint8_t *ciphertext,
  694. uint32_t size,
  695. const uint8_t key1[LTC_DES_KEY_SIZE],
  696. const uint8_t key2[LTC_DES_KEY_SIZE],
  697. const uint8_t key3[LTC_DES_KEY_SIZE])
  698. {
  699. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, NULL, key1, key2, key3, kLTC_ModeECB,
  700. kLTC_ModeEncrypt);
  701. }
  702. status_t LTC_DES2_DecryptEcbEDMA(LTC_Type *base,
  703. ltc_edma_handle_t *handle,
  704. const uint8_t *ciphertext,
  705. uint8_t *plaintext,
  706. uint32_t size,
  707. const uint8_t key1[LTC_DES_KEY_SIZE],
  708. const uint8_t key2[LTC_DES_KEY_SIZE])
  709. {
  710. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, NULL, key1, key2, NULL, kLTC_ModeECB,
  711. kLTC_ModeDecrypt);
  712. }
  713. status_t LTC_DES3_DecryptEcbEDMA(LTC_Type *base,
  714. ltc_edma_handle_t *handle,
  715. const uint8_t *ciphertext,
  716. uint8_t *plaintext,
  717. uint32_t size,
  718. const uint8_t key1[LTC_DES_KEY_SIZE],
  719. const uint8_t key2[LTC_DES_KEY_SIZE],
  720. const uint8_t key3[LTC_DES_KEY_SIZE])
  721. {
  722. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, NULL, key1, key2, key3, kLTC_ModeECB,
  723. kLTC_ModeDecrypt);
  724. }
  725. status_t LTC_DES2_EncryptCbcEDMA(LTC_Type *base,
  726. ltc_edma_handle_t *handle,
  727. const uint8_t *plaintext,
  728. uint8_t *ciphertext,
  729. uint32_t size,
  730. const uint8_t iv[LTC_DES_IV_SIZE],
  731. const uint8_t key1[LTC_DES_KEY_SIZE],
  732. const uint8_t key2[LTC_DES_KEY_SIZE])
  733. {
  734. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key1, key2, NULL, kLTC_ModeCBC,
  735. kLTC_ModeEncrypt);
  736. }
  737. status_t LTC_DES3_EncryptCbcEDMA(LTC_Type *base,
  738. ltc_edma_handle_t *handle,
  739. const uint8_t *plaintext,
  740. uint8_t *ciphertext,
  741. uint32_t size,
  742. const uint8_t iv[LTC_DES_IV_SIZE],
  743. const uint8_t key1[LTC_DES_KEY_SIZE],
  744. const uint8_t key2[LTC_DES_KEY_SIZE],
  745. const uint8_t key3[LTC_DES_KEY_SIZE])
  746. {
  747. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key1, key2, key3, kLTC_ModeCBC,
  748. kLTC_ModeEncrypt);
  749. }
  750. status_t LTC_DES2_DecryptCbcEDMA(LTC_Type *base,
  751. ltc_edma_handle_t *handle,
  752. const uint8_t *ciphertext,
  753. uint8_t *plaintext,
  754. uint32_t size,
  755. const uint8_t iv[LTC_DES_IV_SIZE],
  756. const uint8_t key1[LTC_DES_KEY_SIZE],
  757. const uint8_t key2[LTC_DES_KEY_SIZE])
  758. {
  759. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key1, key2, NULL, kLTC_ModeCBC,
  760. kLTC_ModeDecrypt);
  761. }
  762. status_t LTC_DES3_DecryptCbcEDMA(LTC_Type *base,
  763. ltc_edma_handle_t *handle,
  764. const uint8_t *ciphertext,
  765. uint8_t *plaintext,
  766. uint32_t size,
  767. const uint8_t iv[LTC_DES_IV_SIZE],
  768. const uint8_t key1[LTC_DES_KEY_SIZE],
  769. const uint8_t key2[LTC_DES_KEY_SIZE],
  770. const uint8_t key3[LTC_DES_KEY_SIZE])
  771. {
  772. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key1, key2, key3, kLTC_ModeCBC,
  773. kLTC_ModeDecrypt);
  774. }
  775. status_t LTC_DES2_EncryptCfbEDMA(LTC_Type *base,
  776. ltc_edma_handle_t *handle,
  777. const uint8_t *plaintext,
  778. uint8_t *ciphertext,
  779. uint32_t size,
  780. const uint8_t iv[LTC_DES_IV_SIZE],
  781. const uint8_t key1[LTC_DES_KEY_SIZE],
  782. const uint8_t key2[LTC_DES_KEY_SIZE])
  783. {
  784. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key1, key2, NULL, kLTC_ModeCFB,
  785. kLTC_ModeEncrypt);
  786. }
  787. status_t LTC_DES3_EncryptCfbEDMA(LTC_Type *base,
  788. ltc_edma_handle_t *handle,
  789. const uint8_t *plaintext,
  790. uint8_t *ciphertext,
  791. uint32_t size,
  792. const uint8_t iv[LTC_DES_IV_SIZE],
  793. const uint8_t key1[LTC_DES_KEY_SIZE],
  794. const uint8_t key2[LTC_DES_KEY_SIZE],
  795. const uint8_t key3[LTC_DES_KEY_SIZE])
  796. {
  797. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key1, key2, key3, kLTC_ModeCFB,
  798. kLTC_ModeEncrypt);
  799. }
  800. status_t LTC_DES2_DecryptCfbEDMA(LTC_Type *base,
  801. ltc_edma_handle_t *handle,
  802. const uint8_t *ciphertext,
  803. uint8_t *plaintext,
  804. uint32_t size,
  805. const uint8_t iv[LTC_DES_IV_SIZE],
  806. const uint8_t key1[LTC_DES_KEY_SIZE],
  807. const uint8_t key2[LTC_DES_KEY_SIZE])
  808. {
  809. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key1, key2, NULL, kLTC_ModeCFB,
  810. kLTC_ModeDecrypt);
  811. }
  812. status_t LTC_DES3_DecryptCfbEDMA(LTC_Type *base,
  813. ltc_edma_handle_t *handle,
  814. const uint8_t *ciphertext,
  815. uint8_t *plaintext,
  816. uint32_t size,
  817. const uint8_t iv[LTC_DES_IV_SIZE],
  818. const uint8_t key1[LTC_DES_KEY_SIZE],
  819. const uint8_t key2[LTC_DES_KEY_SIZE],
  820. const uint8_t key3[LTC_DES_KEY_SIZE])
  821. {
  822. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key1, key2, key3, kLTC_ModeCFB,
  823. kLTC_ModeDecrypt);
  824. }
  825. status_t LTC_DES2_EncryptOfbEDMA(LTC_Type *base,
  826. ltc_edma_handle_t *handle,
  827. const uint8_t *plaintext,
  828. uint8_t *ciphertext,
  829. uint32_t size,
  830. const uint8_t iv[LTC_DES_IV_SIZE],
  831. const uint8_t key1[LTC_DES_KEY_SIZE],
  832. const uint8_t key2[LTC_DES_KEY_SIZE])
  833. {
  834. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key1, key2, NULL, kLTC_ModeOFB,
  835. kLTC_ModeEncrypt);
  836. }
  837. status_t LTC_DES3_EncryptOfbEDMA(LTC_Type *base,
  838. ltc_edma_handle_t *handle,
  839. const uint8_t *plaintext,
  840. uint8_t *ciphertext,
  841. uint32_t size,
  842. const uint8_t iv[LTC_DES_IV_SIZE],
  843. const uint8_t key1[LTC_DES_KEY_SIZE],
  844. const uint8_t key2[LTC_DES_KEY_SIZE],
  845. const uint8_t key3[LTC_DES_KEY_SIZE])
  846. {
  847. return ltc_3des_process_EDMA(base, handle, plaintext, ciphertext, size, iv, key1, key2, key3, kLTC_ModeOFB,
  848. kLTC_ModeEncrypt);
  849. }
  850. status_t LTC_DES2_DecryptOfbEDMA(LTC_Type *base,
  851. ltc_edma_handle_t *handle,
  852. const uint8_t *ciphertext,
  853. uint8_t *plaintext,
  854. uint32_t size,
  855. const uint8_t iv[LTC_DES_IV_SIZE],
  856. const uint8_t key1[LTC_DES_KEY_SIZE],
  857. const uint8_t key2[LTC_DES_KEY_SIZE])
  858. {
  859. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key1, key2, NULL, kLTC_ModeOFB,
  860. kLTC_ModeDecrypt);
  861. }
  862. status_t LTC_DES3_DecryptOfbEDMA(LTC_Type *base,
  863. ltc_edma_handle_t *handle,
  864. const uint8_t *ciphertext,
  865. uint8_t *plaintext,
  866. uint32_t size,
  867. const uint8_t iv[LTC_DES_IV_SIZE],
  868. const uint8_t key1[LTC_DES_KEY_SIZE],
  869. const uint8_t key2[LTC_DES_KEY_SIZE],
  870. const uint8_t key3[LTC_DES_KEY_SIZE])
  871. {
  872. return ltc_3des_process_EDMA(base, handle, ciphertext, plaintext, size, iv, key1, key2, key3, kLTC_ModeOFB,
  873. kLTC_ModeDecrypt);
  874. }
  875. #endif /* FSL_FEATURE_LTC_HAS_DES */
  876. /*********************** LTC EDMA tools ***************************************/
  877. static uint32_t LTC_GetInstance(LTC_Type *base)
  878. {
  879. uint32_t instance = 0;
  880. uint32_t i;
  881. for (i = 0; i < FSL_FEATURE_SOC_LTC_COUNT; i++)
  882. {
  883. if (s_ltcBase[instance] == base)
  884. {
  885. instance = i;
  886. break;
  887. }
  888. }
  889. return instance;
  890. }
  891. /*!
  892. * @brief Enable or disable LTC Input FIFO DMA request.
  893. *
  894. * This function enables or disables DMA request and done signals for Input FIFO.
  895. *
  896. * @param base LTC peripheral base address.
  897. * @param enable True to enable, false to disable.
  898. */
  899. static inline void LTC_EnableInputFifoDMA(LTC_Type *base, bool enable)
  900. {
  901. if (enable)
  902. {
  903. base->CTL |= LTC_CTL_IFE_MASK;
  904. }
  905. else
  906. {
  907. base->CTL &= ~LTC_CTL_IFE_MASK;
  908. }
  909. }
  910. /*!
  911. * @brief Enable or disable LTC Output FIFO DMA request.
  912. *
  913. * This function enables or disables DMA request and done signals for Output FIFO.
  914. *
  915. * @param base LTC peripheral base address.
  916. * @param enable True to enable, false to disable.
  917. */
  918. static inline void LTC_EnableOutputFifoDMA(LTC_Type *base, bool enable)
  919. {
  920. if (enable)
  921. {
  922. base->CTL |= LTC_CTL_OFE_MASK;
  923. }
  924. else
  925. {
  926. base->CTL &= ~LTC_CTL_OFE_MASK;
  927. }
  928. }
  929. static void LTC_InputFifoEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
  930. {
  931. ltc_edma_private_handle_t *ltcPrivateHandle = (ltc_edma_private_handle_t *)param;
  932. /* Avoid the warning for unused variables. */
  933. handle = handle;
  934. tcds = tcds;
  935. if (transferDone)
  936. {
  937. /* Stop DMA channel. */
  938. EDMA_StopTransfer(ltcPrivateHandle->handle->inputFifoEdmaHandle);
  939. /* Disable Input Fifo DMA */
  940. LTC_EnableInputFifoDMA(ltcPrivateHandle->base, false);
  941. }
  942. }
  943. static void LTC_OutputFifoEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
  944. {
  945. ltc_edma_private_handle_t *ltcPrivateHandle = (ltc_edma_private_handle_t *)param;
  946. /* Avoid the warning for unused variables. */
  947. handle = handle;
  948. tcds = tcds;
  949. if (transferDone)
  950. {
  951. /* Stop DMA channel. */
  952. EDMA_StopTransfer(ltcPrivateHandle->handle->outputFifoEdmaHandle);
  953. /* Disable Output Fifo DMA */
  954. LTC_EnableOutputFifoDMA(ltcPrivateHandle->base, false);
  955. if (ltcPrivateHandle->handle->state_machine)
  956. {
  957. ltcPrivateHandle->handle->state_machine(ltcPrivateHandle->base, ltcPrivateHandle->handle);
  958. }
  959. }
  960. }
  961. /* @brief Copy data to Input FIFO and reading from Ouput FIFO using eDMA. */
  962. static void ltc_symmetric_process_EDMA(LTC_Type *base, uint32_t inSize, const uint8_t **inData, uint8_t **outData)
  963. {
  964. const uint8_t *in = *inData;
  965. uint8_t *out = *outData;
  966. uint32_t instance = LTC_GetInstance(base);
  967. uint32_t entry_number = inSize / sizeof(uint32_t);
  968. const uint8_t *inputBuffer = *inData;
  969. uint8_t *outputBuffer = *outData;
  970. edma_transfer_config_t config;
  971. if (entry_number)
  972. {
  973. /* =========== Init Input FIFO DMA ======================*/
  974. memset(&config, 0, sizeof(config));
  975. /* Prepare transfer. */
  976. EDMA_PrepareTransfer(&config, (void *)(uintptr_t)inputBuffer, 1, (void *)(uintptr_t)(&base->IFIFO), 4U, 4U, entry_number * 4,
  977. kEDMA_MemoryToPeripheral);
  978. /* Submit transfer. */
  979. EDMA_SubmitTransfer(s_edmaPrivateHandle[instance].handle->inputFifoEdmaHandle, &config);
  980. /* Set request size.*/
  981. base->CTL &= ~LTC_CTL_IFR_MASK; /* 1 entry */
  982. /* Enable Input Fifo DMA */
  983. LTC_EnableInputFifoDMA(base, true);
  984. /* Start the DMA channel */
  985. EDMA_StartTransfer(s_edmaPrivateHandle[instance].handle->inputFifoEdmaHandle);
  986. /* =========== Init Output FIFO DMA ======================*/
  987. memset(&config, 0, sizeof(config));
  988. /* Prepare transfer. */
  989. EDMA_PrepareTransfer(&config, (void *)(uintptr_t)(&base->OFIFO), 4U, (void *)outputBuffer, 1U, 4U,
  990. entry_number * 4, kEDMA_PeripheralToMemory);
  991. /* Submit transfer. */
  992. EDMA_SubmitTransfer(s_edmaPrivateHandle[instance].handle->outputFifoEdmaHandle, &config);
  993. /* Set request size.*/
  994. base->CTL &= ~LTC_CTL_OFR_MASK; /* 1 entry */
  995. /* Enable Output Fifo DMA */
  996. LTC_EnableOutputFifoDMA(base, true);
  997. /* Start the DMA channel */
  998. EDMA_StartTransfer(s_edmaPrivateHandle[instance].handle->outputFifoEdmaHandle);
  999. { /* Dummy read of LTC register. Do not delete.*/
  1000. volatile uint32_t status_reg;
  1001. status_reg = (base)->STA;
  1002. (void)status_reg;
  1003. }
  1004. out += entry_number * sizeof(uint32_t);
  1005. in += entry_number * sizeof(uint32_t);
  1006. *inData = in;
  1007. *outData = out;
  1008. }
  1009. }
  1010. void LTC_CreateHandleEDMA(LTC_Type *base,
  1011. ltc_edma_handle_t *handle,
  1012. ltc_edma_callback_t callback,
  1013. void *userData,
  1014. edma_handle_t *inputFifoEdmaHandle,
  1015. edma_handle_t *outputFifoEdmaHandle)
  1016. {
  1017. assert(handle);
  1018. assert(inputFifoEdmaHandle);
  1019. assert(outputFifoEdmaHandle);
  1020. uint32_t instance = LTC_GetInstance(base);
  1021. s_edmaPrivateHandle[instance].base = base;
  1022. s_edmaPrivateHandle[instance].handle = handle;
  1023. memset(handle, 0, sizeof(*handle));
  1024. handle->inputFifoEdmaHandle = inputFifoEdmaHandle;
  1025. handle->outputFifoEdmaHandle = outputFifoEdmaHandle;
  1026. handle->callback = callback;
  1027. handle->userData = userData;
  1028. /* Register DMA callback functions */
  1029. EDMA_SetCallback(handle->inputFifoEdmaHandle, LTC_InputFifoEDMACallback, &s_edmaPrivateHandle[instance]);
  1030. EDMA_SetCallback(handle->outputFifoEdmaHandle, LTC_OutputFifoEDMACallback, &s_edmaPrivateHandle[instance]);
  1031. /* Set request size. DMA request size is 1 entry.*/
  1032. base->CTL &= ~LTC_CTL_IFR_MASK;
  1033. base->CTL &= ~LTC_CTL_OFR_MASK;
  1034. }