%%{
    let Common      = system.getScript(`/driverlib/Common.js`);
    let soc         = system.getScript(`/driverlib/soc/drivers_${Common.getDeviceName().toLowerCase()}`);
    let hsm_soc     = system.getScript(`/driverlib/hsmclient/soc/hsmclient_${Common.getDeviceName().toLowerCase()}`);
    let driverVer   = soc.getDriverVer("hsmclient");
    let module      = system.modules['/driverlib/hsmclient/hsmclient'];
    let instance    = module.$instances[0];
    let config      = module.getInstanceConfig(instance);
%%}
/*
 * HSM Client
 */

/* memory assigned for each C29 <-> HSM channel */
uint8_t gQueue_HsmToSecureHost[SIPC_NUM_SEC_HOST_CORES][SIPC_QUEUE_LENGTH*SIPC_MSG_SIZE] __attribute__((aligned(8),section(".bss.sipc_hsm_queue_mem")));
uint8_t gQueue_SecureHostToHsm[SIPC_NUM_SEC_HOST_CORES][SIPC_QUEUE_LENGTH*SIPC_MSG_SIZE] __attribute__((aligned(8),section(".bss.sipc_secure_host_queue_mem")));
HsmClient_t gHSMClient ;

void HsmClient_config(void)
{
    SIPC_Params sipcParams;
    int32_t status;

    /* initialize parameters to default */
    SIPC_Params_init(&sipcParams);

    sipcParams.ipcQueue_eleSize_inBytes = SIPC_MSG_SIZE;
    sipcParams.ipcQueue_length = SIPC_QUEUE_LENGTH ;
    /* list the cores that will do SIPC communication with this core
    * Make sure to NOT list 'self' core in the list below
    */
    sipcParams.numCores = 1;
    sipcParams.coreIdList[0] = CORE_INDEX_HSM;

    /* specify the priority of SIPC Notify interrupt */
    sipcParams.intrPriority = `instance.intrPriority`U;

    %if(config.sec_core_option == "secure_host_id_0"){

    /* This is HSM -> C29 queue */
    sipcParams.tx_SipcQueues[CORE_INDEX_HSM] = (uintptr_t)gQueue_SecureHostToHsm[0] ;
    sipcParams.rx_SipcQueues[CORE_INDEX_HSM] = (uintptr_t)gQueue_HsmToSecureHost[0] ;
    sipcParams.secHostCoreId[CORE_INDEX_SEC_MASTER_0] = CORE_ID_`hsm_soc.getSelfCoreId().toUpperCase()`;
    %}
    %if(config.sec_core_option == "secure_host_id_1"){
    /* This is HSM -> C29 queue */
    sipcParams.tx_SipcQueues[CORE_INDEX_HSM] = (uintptr_t)gQueue_SecureHostToHsm[1] ;

    /* This will be C29 -> HSM queue */
    sipcParams.rx_SipcQueues[CORE_INDEX_HSM] = (uintptr_t)gQueue_HsmToSecureHost[1] ;
    sipcParams.secHostCoreId[CORE_INDEX_SEC_MASTER_1] = CORE_ID_`hsm_soc.getSelfCoreId().toUpperCase()`;
    %}

    /* initialize the HsmClient module */
    status = HsmClient_init(&sipcParams);
    DebugP_assert(status==SystemP_SUCCESS);

    /* register a hsm client to detect bootnotify message and keyring import from HSM */
    status = HsmClient_register(&gHSMClient, HSM_BOOT_NOTIFY_CLIENT_ID);
    DebugP_assert(status==SystemP_SUCCESS);
}

void HsmClient_unRegister(void)
{
     /* Unregister bootnotify client */
    HsmClient_unregister(&gHSMClient, HSM_BOOT_NOTIFY_CLIENT_ID);
}
