You are here

C Structs and Callback Macros | Cypress Semiconductor

C Structs and Callback Macros

Summary: 5 Replies, Latest post by Bob Marlowe on 26 Oct 2016 02:37 AM PDT
Verified Answers: 1
Last post
Log in to post new comments.
nkli_1985396's picture
User
8 posts

Hello,

The code that I have written uses C structs and accesses the struct variables using the arrow operator. When I tried porting this code into Cypress and started debugging, I get stuck in an infinite loop in cm0Start.c . I tried to read up on callback macros but am unsure of how to go about this. Is it possible to use structs without having to go into the callback macro loop or is it better to not use structs? If not, could someone possibly explain the use of callback macros, please?

Thanks in advance.

user_1377889's picture
User
9572 posts

There is no limitation using structs. The infinite loop might be caused by using invalid pointers or a clobbered stack.

All this has nothing to do with the principle of callback macros.

Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

 

Bob

nkli_1985396's picture
User
8 posts

As soon as I try assigning a value to a variable in a struct, it goes into that loop.

 

e.g.

typedef struct Structures {

    uint8 somevariable;

} Structure;

Structure somestructure;

somestructure = (Structure*)malloc(sizeof(Structure));

somestructure->somevariable = 0;

 

Then the line above causes the debugger to go to Cm0Start.c:

 

/*******************************************************************************
* Function Name: IntDefaultHandler
****************************************************************************//**
*
*  This function is called for all interrupts, other than a reset that is called
*  before the system is setup.
*
*******************************************************************************/
CY_NORETURN
CY_ISR(IntDefaultHandler)
{
    /***************************************************************************
    * We must not get here. If we do, a serious problem occurs, so go into
    * an infinite loop.
    ***************************************************************************/

    #ifdef CY_BOOT_INT_DEFAULT_HANDLER_EXCEPTION_ENTRY_CALLBACK
        CyBoot_IntDefaultHandler_Exception_EntryCallback();
    #endif /* CY_BOOT_INT_DEFAULT_HANDLER_EXCEPTION_ENTRY_CALLBACK */

    while(1)
    {

    }
}

 

Would memory be a problem? I am using rather large structs and am programming on a 128KB flash.

user_1377889's picture
User
9572 posts

Your project does not contain a main.c.

somestructure is a struct, not a pointer to a struct.

You did not check if malloc() returned NULL

You should increase the heap size to have some ram to allocate.

 

Bib

nkli_1985396's picture
User
8 posts

I apologize for not posting the code.

 

Sorry, I meant that somestructure is a pointer:

Structure* somestructure;

 

But I tried changing everything in my code to only structs and not pointers and the problem disappeared. The problem now is that I wish to use pointers because I may use the data other places. On the other hand, I could always just return structs and pass the values around, or even just use variables.

 

What I don't understand is why the pointers caused a problem? You mentioned a clobbered stack..

user_1377889's picture
User
9572 posts

I primarily mentioned that you did not check the returned value from malloc() to be valid.

 

Bob

Log in to post new comments.