How to use user callback from CAAM driver

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use user callback from CAAM driver

1,111 Views
jslota13245
Contributor III

There is:

/*! @brief CAAM handle
* Specifies jobRing and optionally the user callback function.
* The user callback functions is invoked only if jobRing interrupt has been enabled by the user.
* By default the jobRing interrupt is disabled (default job complete test is polling CAAM output ring).
*/
typedef struct _caam_handle_t
{
caam_job_ring_t jobRing;

/* Callback functions */
caam_job_callback_t callback; /*!< Callback function */
void *userData; /*!< Parameter for CAAM job complete callback */
} caam_handle_t;

So i wrote a callback and mapped it to caam_handle_t* handle

static void xpnd_CAAM_job_ring_1_complete_clb(void* args) {
BaseType_t pxHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(sem[ITF_1],
&pxHigherPriorityTaskWoken);
DisableIRQ(CAAM_IRQ1_IRQn);
}

At the very end i tried:

EnableIRQ(CAAM_IRQ1_IRQn);

drv_res = CAAM_RNG_GetRandomDataNonBlocking(
base, handle, kCAAM_RngStateHandle0, desc, data, dataSize,
kCAAM_RngDataAny, NULL);

if (drv_res == kStatus_Success) {
if (pdTRUE != xSemaphoreTake(sem[ITF_1], MS_TIMEOUT)) {
PRINTF("CAAM operation failed\r\n");
return ST_FAILURE;
}
} else {
PRINTF("Failed to setup driver operation, res %d\r\n", drv_res);
return ST_FAILURE;
}

The program crashes after short time i think - because it didn't report an error from semaphore.

Do i need to do something else?

In assembly startup_mimxrt1176 there is CAAM_IRQ0_IRQHandler prototyped but i think it might be not defined - might this be the case?

Also in the driver code i don't see where is the custom callback is called.

Tags (3)
0 Kudos
Reply
2 Replies

1,052 Views
mayliu1
NXP Employee
NXP Employee

Hi @jslota13245 ,

Thank you so much for your interest in our products and for using our community.

I find your code is based on FreeRTOS.
I suggest first testing with the NXP SDK demo " evkbmimxrt1170_caam_cm4".  This demo project is a demonstration program that uses the KSDK software to encrypt plain text and decrypt it back using AES algorithm. CBC and GCM modes are demonstrated. The symmetric key is generated at random, using CAAM's random number generator.
 
Please try running this demo to check whether the issue is caused by your API usage or by the FreeRTOS integration. 
 
Best Regards
MayLiu
0 Kudos
Reply

1,048 Views
jslota13245
Contributor III

Dear @mayliu1 , 

the demo doesn't demonstrate on how to use the user callback - or any interrupt in fact.

I need to have an interrupt from CAAM hardware on completion. Could you help me with that?

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2291862%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20to%20use%20user%20callback%20from%20CAAM%20driver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291862%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThere%20is%3A%3C%2FP%3E%3CP%3E%2F*!%20%40brief%20CAAM%20handle%3CBR%20%2F%3E*%20Specifies%20jobRing%20and%20optionally%20the%20user%20callback%20function.%3CBR%20%2F%3E*%20The%20user%20callback%20functions%20is%20invoked%20only%20if%20jobRing%20interrupt%20has%20been%20enabled%20by%20the%20user.%3CBR%20%2F%3E*%20By%20default%20the%20jobRing%20interrupt%20is%20disabled%20(default%20job%20complete%20test%20is%20polling%20CAAM%20output%20ring).%3CBR%20%2F%3E*%2F%3CBR%20%2F%3Etypedef%20struct%20_caam_handle_t%3CBR%20%2F%3E%7B%3CBR%20%2F%3Ecaam_job_ring_t%20jobRing%3B%3C%2FP%3E%3CP%3E%2F*%20Callback%20functions%20*%2F%3CBR%20%2F%3Ecaam_job_callback_t%20callback%3B%20%2F*!%26lt%3B%20Callback%20function%20*%2F%3CBR%20%2F%3Evoid%20*userData%3B%20%2F*!%26lt%3B%20Parameter%20for%20CAAM%20job%20complete%20callback%20*%2F%3CBR%20%2F%3E%7D%20caam_handle_t%3B%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20i%20wrote%20a%20callback%20and%20mapped%20it%20to%26nbsp%3Bcaam_handle_t*%20handle%3C%2FP%3E%3CP%3Estatic%20void%20xpnd_CAAM_job_ring_1_complete_clb(void*%20args)%20%7B%3CBR%20%2F%3EBaseType_t%20pxHigherPriorityTaskWoken%20%3D%20pdFALSE%3B%3CBR%20%2F%3ExSemaphoreGiveFromISR(sem%5BITF_1%5D%2C%3CBR%20%2F%3E%26amp%3BpxHigherPriorityTaskWoken)%3B%3CBR%20%2F%3EDisableIRQ(CAAM_IRQ1_IRQn)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EAt%20the%20very%20end%20i%20tried%3A%3C%2FP%3E%3CDIV%3EEnableIRQ(CAAM_IRQ1_IRQn)%3B%3C%2FDIV%3E%3CP%3Edrv_res%20%3D%20CAAM_RNG_GetRandomDataNonBlocking(%3CBR%20%2F%3Ebase%2C%20handle%2C%20kCAAM_RngStateHandle0%2C%20desc%2C%20data%2C%20dataSize%2C%3CBR%20%2F%3EkCAAM_RngDataAny%2C%20NULL)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3Eif%20(drv_res%20%3D%3D%20kStatus_Success)%20%7B%3CBR%20%2F%3Eif%20(pdTRUE%20!%3D%20xSemaphoreTake(sem%5BITF_1%5D%2C%20MS_TIMEOUT))%20%7B%3CBR%20%2F%3EPRINTF(%22CAAM%20operation%20failed%5Cr%5Cn%22)%3B%3CBR%20%2F%3Ereturn%20ST_FAILURE%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%20else%20%7B%3CBR%20%2F%3EPRINTF(%22Failed%20to%20setup%20driver%20operation%2C%20res%20%25d%5Cr%5Cn%22%2C%20drv_res)%3B%3CBR%20%2F%3Ereturn%20ST_FAILURE%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20program%20crashes%20after%20short%20time%20i%20think%20-%20because%20it%20didn't%20report%20an%20error%20from%20semaphore.%3CBR%20%2F%3E%3CBR%20%2F%3EDo%20i%20need%20to%20do%20something%20else%3F%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20assembly%20startup_mimxrt1176%20there%20is%20CAAM_IRQ0_IRQHandler%20prototyped%20but%20i%20think%20it%20might%20be%20not%20defined%20-%20might%20this%20be%20the%20case%3F%3CBR%20%2F%3E%3CBR%20%2F%3EAlso%20in%20the%20driver%20code%20i%20don't%20see%20where%20is%20the%20custom%20callback%20is%20called.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2292450%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20use%20user%20callback%20from%20CAAM%20driver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292450%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251438%22%20target%3D%22_blank%22%3E%40jslota13245%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3EThank%20you%20so%20much%20for%20your%20interest%20in%20our%20products%20and%20for%20using%20our%20community.%3C%2FP%3E%0A%3CDIV%3EI%20find%20your%20code%20is%20based%20on%20FreeRTOS.%3C%2FDIV%3E%0A%3CDIV%3EI%20suggest%20first%20testing%20with%20the%20NXP%20SDK%20demo%20%22%20evkbmimxrt1170_caam_cm4%22.%26nbsp%3B%20This%20demo%26nbsp%3B%3CSPAN%3Eproject%20is%20a%20demonstration%20program%20that%20uses%20the%20KSDK%20software%20to%20encrypt%20plain%20text%20and%20decrypt%20it%20back%20using%20AES%20algorithm.%20CBC%20and%20GCM%20modes%20are%20demonstrated.%20The%20symmetric%20key%20is%20generated%20at%20random%2C%20using%20CAAM's%20random%20number%20generator.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%0A%3CDIV%3EPlease%20try%20running%20this%20demo%20to%20check%20whether%20the%20issue%20is%20caused%20by%20your%20API%20usage%20or%20by%20the%20FreeRTOS%20integration.%26nbsp%3B%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EBest%20Regards%3C%2FDIV%3E%0A%3CDIV%3EMayLiu%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2292462%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20use%20user%20callback%20from%20CAAM%20driver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292462%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EDear%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F239163%22%20target%3D%22_blank%22%3E%40mayliu1%3C%2FA%3E%26nbsp%3B%2C%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3Ethe%20demo%20doesn't%20demonstrate%20on%20how%20to%20use%20the%20user%20callback%20-%20or%20any%20interrupt%20in%20fact.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20need%20to%20have%20an%20interrupt%20from%20CAAM%20hardware%20on%20completion.%20Could%20you%20help%20me%20with%20that%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E