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.

CCS - the main routine's progress with the pointer sub routines

Other Parts Discussed in Thread: DRV8301

Hi,

I've seen the partial of source code in the example project. I'm not very sure one thing.... When the program goes o  (*Alpha_State_Ptr)() which will jump to many sub-routine, will the main routine wait for all of sub-routines completed and just go to run #ifdef DRV8301 ?? Thanks !!

    for(;;)  //infinite loop
    {
        BackTicker++;

        // State machine entry & exit point
        //===========================================================
        (*Alpha_State_Ptr)();    // jump to an Alpha state (A0,B0,...)
        //===========================================================

#ifdef DRV8301
        //read the status registers from the DRV8301
        if(read_drv_status)
        {
            DRV8301_stat_reg1.all = DRV8301_SPI_Read(&SpibRegs,STAT_REG_1_ADDR);
            DRV8301_stat_reg2.all = DRV8301_SPI_Read(&SpibRegs,STAT_REG_2_ADDR);
            read_drv_status = 0;
        }
#endif        
    }

  • Hi,

    I am not sure if I understand your question correctly. Let me try:

    Every time the code reaches the (*Alpha_State_Ptr)(), the next line in the for(;;) loop will only be called after the function pointed by Alpha_State_Ptr returns - independently of the number of sub-routines it called after that.

    However, if throughout the code the pointer Alpha_State_Ptr can point to several functions across the code, then every time the code reaches the (*Alpha_State_Ptr)() statement it will only run the function whose address is assigned at that point (not all the possible values it could have across the code).

    Regards,

    Rafael