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.

What module is in XDC Assert_isTrue description?

Hi,

When I search answers to Assert_isTrue in the example GPIO 1294 LaunchPad project:

void GPIO_clearInt(unsigned int index)
{
    PinConfig *config = (PinConfig *) &GPIOTiva_config.pinConfigs[index];

    Assert_isTrue(initCalled && index < GPIOTiva_config.numberOfPinConfigs,
        NULL);

I trace down to XDC user manual and other sources. They give similar answers and a new question to me. In the following except, I am not clear about "that is not in a module". What module does it talk about?

Example 1: The following C code adds an assert to application code that is that is not in a module. This assert does not have an assert identifier (the second argument is NULL); This makes it an internal assert. /* file.c */ #include Assert_isTrue(count > 0, NULL);

Thanks

  • After I read the following description, I still don't understand the text having underline mark.

    Could you give a little explanation about this example?

    Thanks,

    Example 1: The following C code adds an assert to application code that is
    that is not in a module. This assert does not have an assert identifier (the
    second argument is NULL); This makes it an internal assert.
    /* file.c */
    #include <xdc/runtime/Assert.h>
    Assert_isTrue(count > 0, NULL);
    The following XDC configuration statements set both the ASSERT and
    INTERNAL bits in the diagnostics mask to enable the internal assert created
    in the previous C code. Since the C code is not in a module, you must set the
    bits in the diagnostics mask of the xdc.runtime.Main module. The Main
    module is used to control all Log and Assert statements that are not part of
    the implementation of a module; for example, top-level application code or
    any existing sources that simply call the Log or Assert methods.
    /* program.cfg */
    var Assert = xdc.useModule('xdc.runtime.Assert');
    var Diags = xdc.useModule('xdc.runtime.Diags');
    var Main = xdc.useModule('xdc.runtime.Main');
    Main.common$.diags_ASSERT = Diags.ALWAYS_ON;
    Main.common$.diags_INTERNAL = Diags.ALWAYS_ON;

  • The kernel is composed of multiple modules (e.g. Task, Hwi, System, HeapMem, etc.). These modules are "XDC" (or some say "RTSC") modules. To make a long story short and simplified...the corresponding .xdc files (e.g. Task.xdc, etc.) spec out things that will get auto generated. One of these things is the ability for the module to specify Assert_Ids.

    For example in HeapMem.xdc (note: A_align because HeapMem_A_align in a generated header file).

        /*!
         *  ======== A_align ========
         *  Assert raised when the requested alignment is not a power of 2
         */
        config xdc.runtime.Assert.Id A_align =
            {msg: "A_align: Requested align is not a power of 2"};

    In HeapMem_alloc, there is a check to make sure the alignment request is a power of 2.

    Ptr HeapMem_alloc(HeapMem_Object *obj, SizeT reqSize,
                        SizeT reqAlign, Error_Block *eb)
    {
        ....

        /* Assert that requested align is a power of 2 */
        Assert_isTrue(((reqAlign & (reqAlign - 1)) == 0), HeapMem_A_align);

    Having the module spec it in the .xdc file allows some good things (e.g. consistency, easy language substitution, etc.). If the above assert files, the text string in the .xdc file is printed out.

    For non-XDC modules (e.g. everything customers write), they can still call Assert_isTrue, but since they did not define a specific Assert_Id, they use NULL in the call.

    Todd

  • A follow on question on assert is here. In gpio.c, there are ASSERT used as shown below. I don't see any header files having such definitions. What is the origin, or the declaration of ASSERT?

    Thanks.

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_gpio.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_sysctl.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    
    ...
    void
    GPIODirModeSet(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32PinIO)
    {
        //
        // Check the arguments.
        //
        ASSERT(_GPIOBaseValid(ui32Port));

  • TivaWare defines this in driverlib\debug.h.

    #ifdef DEBUG

    #define ASSERT(expr) do                                                       \

                        {                                                        \

                            if(!(expr))                                          \

                            {                                                    \

                                __error__(__FILE__, __LINE__);                   \

                            }                                                    \

                        }                                                        \

                        while(0)

    #else

    #define ASSERT(expr)

    #endif

  • Thanks found it in debug.h.