This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM6421: Auto generated code from sysconfig tool

Part Number: AM6421
Other Parts Discussed in Thread: SYSCONFIG,

Hi TI team,

I am working on AM6421 on r5 core, so when i add peripheral & genrate the code, sysconfig tool generate system init & drivers open close code.

I have enabled 2 MCSPI but driver open & close functions are in same function. I ahve attached in below image

image.png 

Can we generate separte function like Driver_mcspi0Open() &Driver_mcspi1Open() from sysconfig tool so that i can use thos function anytime from diffenert modules

Regards

shradda

  • Hi ,

    If you do not require the one-time hardware initialization/setup, you can make these changes in the two functions. However, please note that for future builds, you will need to exclude the SysConfig-generated files; otherwise, the changes may be overwritten during regeneration

    int32_t App_mcspi0Open(void)
    {
        gMcspiHandle[CONFIG_MCSPI0] = MCSPI_open(CONFIG_MCSPI0, &gMcspiOpenParams[CONFIG_MCSPI0]);
        return (gMcspiHandle[CONFIG_MCSPI0] != NULL) ? SystemP_SUCCESS : SystemP_FAILURE;
    }
    
    int32_t App_mcspi1Open(void)
    {
        gMcspiHandle[CONFIG_MCSPI1] = MCSPI_open(CONFIG_MCSPI1, &gMcspiOpenParams[CONFIG_MCSPI1]);
        return (gMcspiHandle[CONFIG_MCSPI1] != NULL) ? SystemP_SUCCESS : SystemP_FAILURE;
    }


    If you make changes to these functions manually and later modify anything in SysConfig and rebuild the project, those changes will be lost because the SysConfig template will regenerate the files based on the original SDK template.
    Therefore, if you need to retain this functionality when rebuilding with SysConfig, you must update the corresponding template file in the SDK so that the generated code includes your changes.

    use this patch file for changing the sysconfig template 

    --- a/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_v0_open_close_config.c.xdt
    +++ b/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_v0_open_close_config.c.xdt
    @@ -200,49 +200,32 @@
    %}
    };

    -void Drivers_mcspiOpen(void)
    +% for(let i = 0; i < module.$instances.length; i++) {
    + % let instance = module.$instances[i];
    + % let instNameCamelCase = common.camelSentence(instance.$name);
    +/*
    + * `instance.$name` - individual open/close (replaces the combined Drivers_mcspiOpen/Close)
    + */
    +void Drivers_mcspiOpen`instNameCamelCase`(void)
    {
    - uint32_t instCnt;
    - int32_t status = SystemP_SUCCESS;
    -
    - for(instCnt = 0U; instCnt < CONFIG_MCSPI_NUM_INSTANCES; instCnt++)
    + gMcspiHandle[`i`] = MCSPI_open(`i`, &gMcspiOpenParams[`i`]);
    + if(NULL == gMcspiHandle[`i`])
    {
    - gMcspiHandle[instCnt] = NULL; /* Init to NULL so that we can exit gracefully */
    - }
    -
    - /* Open all instances */
    - for(instCnt = 0U; instCnt < CONFIG_MCSPI_NUM_INSTANCES; instCnt++)
    - {
    - gMcspiHandle[instCnt] = MCSPI_open(instCnt, &gMcspiOpenParams[instCnt]);
    - if(NULL == gMcspiHandle[instCnt])
    - {
    - DebugP_logError("MCSPI open failed for instance %d !!!\r\n", instCnt);
    - status = SystemP_FAILURE;
    - break;
    - }
    - }
    -
    - if(SystemP_FAILURE == status)
    - {
    - Drivers_mcspiClose(); /* Exit gracefully */
    + DebugP_logError("MCSPI open failed for instance `instance.$name` !!!\r\n");
    }

    return;
    }

    -void Drivers_mcspiClose(void)
    +void Drivers_mcspiClose`instNameCamelCase`(void)
    {
    - uint32_t instCnt;
    -
    - /* Close all instances that are open */
    - for(instCnt = 0U; instCnt < CONFIG_MCSPI_NUM_INSTANCES; instCnt++)
    + if(gMcspiHandle[`i`] != NULL)
    {
    - if(gMcspiHandle[instCnt] != NULL)
    - {
    - MCSPI_close(gMcspiHandle[instCnt]);
    - gMcspiHandle[instCnt] = NULL;
    - }
    + MCSPI_close(gMcspiHandle[`i`]);
    + gMcspiHandle[`i`] = NULL;
    }

    return;
    }
    +
    +% }
    --- a/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_v0_open_close.h.xdt
    +++ b/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_v0_open_close.h.xdt
    @@ -32,8 +32,11 @@
    extern MCSPI_UdmaChConfig g`instNameCamelCase`DmaChCfg[`instance.$name.toUpperCase()`_NUM_CH];
    % }
    % }
    -/* MCSPI Driver open/close - can be used by application when Driver_open() and
    - * Driver_close() is not used directly and app wants to control the various driver
    - * open/close sequences */
    -void Drivers_mcspiOpen(void);
    -void Drivers_mcspiClose(void);
    +/* MCSPI Driver open/close - one function per instance, call the one(s) you need
    + * individually instead of a combined Drivers_mcspiOpen()/Drivers_mcspiClose() */
    +% for(let i = 0; i < module.$instances.length; i++) {
    + % let instance = module.$instances[i];
    + % let instNameCamelCase = common.camelSentence(instance.$name);
    +void Drivers_mcspiOpen`instNameCamelCase`(void);
    +void Drivers_mcspiClose`instNameCamelCase`(void);
    +% }
    --- a/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_open.c.xdt
    +++ b/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_open.c.xdt
    @@ -1 +1 @@
    - Drivers_mcspiOpen();
    + /* MCSPI is opened individually per-instance now - call Drivers_mcspiOpen<Instance>() yourself */
    --- a/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_close.c.xdt
    +++ b/source/sysconfig/drivers/.meta/mcspi/templates/mcspi_close.c.xdt
    @@ -1 +1 @@
    - Drivers_mcspiClose();
    + /* MCSPI is closed individually per-instance now - call Drivers_mcspiClose<Instance>() yourself */

    Thanks,

    JOMY