Thanks for the quick reply Kerry. Correct, I am trying to avoid the blocking code in "DCP_WaitForChannelComplete".
I have looked into enabling interrupt functionality and still no luck. Here are my series of steps,
- Enable DCP IRQ in NVIC (EnableIRQ(DCP_VMI_IRQn), EnableIRQ(DCP_IRQn))
- Enable Ch0 interrupt in DCP config
- Call DCP_AES_EncryptEcbNonBlocking
- Wait on blocking loop for flag to be set in DCP_IRQHandler or DCP_VMI_IRQHandler
Can you please see if there is anything I am missing or doing wrong? FYI, I am waiting on approval to RT1064 Security Reference Manual.
/*
* Copyright 2017 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*******************************************************************************
* Includes
******************************************************************************/
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_dcp.h"
dcp_work_packet_t work_packet;
volatile bool encrypt_in_progress = false;
#define DCP_IRQ_HANDLER_FUNC DCP_IRQHandler
#define DCP_VMI_IRQ_HANDLER_FUNC DCP_VMI_IRQHandler
/*******************************************************************************
* Definitions
******************************************************************************/
#define TEST_ASSERT(a) \
if (!(a)) \
{ \
PRINTF("error\r\n"); \
do \
{ \
} while (1); \
}
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
void TestAesEcb(void)
{
/* Input data for DCP like IV, key and plaintext should be handled properly
* when DCACHE is used (e.g. Clean&Invalidate, use non-cached memory)
*/
static const uint8_t keyAes128[] __attribute__((aligned)) = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
static const uint8_t plainAes128[] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
static const uint8_t cipherAes128[] = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97};
AT_NONCACHEABLE_SECTION_INIT(static uint8_t cipher[16]);
AT_NONCACHEABLE_SECTION_INIT(static uint8_t output[16]);
status_t status;
dcp_handle_t m_handle;
m_handle.channel = kDCP_Channel0;
m_handle.swapConfig = kDCP_NoSwap;
m_handle.keySlot = kDCP_KeySlot0;
status = DCP_AES_SetKey(DCP, &m_handle, keyAes128, 16);
TEST_ASSERT(kStatus_Success == status);
//DCP_AES_EncryptEcb(DCP, &m_handle, plainAes128, cipher, 16);
encrypt_in_progress = true;
DCP_AES_EncryptEcbNonBlocking(DCP, &m_handle, &work_packet, plainAes128, cipher, 16);
while(encrypt_in_progress);
// for(uint16_t i = 0; i<100; i++)
// {
// bool status = DCP_CheckChannelComplete(DCP, &m_handle);
// PRINTF("%d\r\n", status);
// }
TEST_ASSERT(memcmp(cipher, cipherAes128, 16) == 0);
DCP_AES_DecryptEcb(DCP, &m_handle, cipher, output, 16);
TEST_ASSERT(memcmp(output, plainAes128, 16) == 0);
PRINTF("AES ECB Test pass\r\n");
}
/*!
* @brief Main function
*/
int main(void)
{
dcp_config_t dcpConfig;
/* Init hardware*/
BOARD_ConfigMPU();
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Note: When DCACHE is enabled input and output buffers should be in non-cached memory
* or handled properly (DCACHE Clean and Invalidate).
* Disable DCHACHE by calling SCB_DisableDCache();
*/
/* Enable at the NVIC. */
EnableIRQ(DCP_VMI_IRQn);
EnableIRQ(DCP_IRQn);
PRINTF("DCP Driver Example\r\n\r\n");
/* Initialize DCP */
DCP_GetDefaultConfig(&dcpConfig);
dcpConfig.enableChannelInterrupt = kDCP_ch0IntEnable;
/* Reset and initialize DCP */
DCP_Init(DCP, &dcpConfig);
/* Call DCP APIs */
TestAesEcb();
/* Deinitialize DCP */
DCP_Deinit(DCP);
while (1)
{
}
}
void DCP_IRQ_HANDLER_FUNC()
{
encrypt_in_progress = false;
}
void DCP_VMI_IRQ_HANDLER_FUNC()
{
encrypt_in_progress = false;
}