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.

Calling a function direclty from main.c vs from another function in hal.c in Motorware

Other Parts Discussed in Thread: MOTORWARE

I am using 28027F processor based board which is roughly based on the TI launchpad. I built up my code from Motorware lab 20 and that is working fine. I have been trying to develop SCI communication from the board and so I was trying to get GPIO 12 to toggle (always low for receive, make high only when transmitting) and I found a very interesting issue which I am unable to understand why. Here is what is happening.

1. In my first attempt, I defined GPIO 12 as output and set low in hal.c setupGpios function. Then in the main.c file I defined GPIO_handle so that I could call the toggle function directly. When I ran the program, I did single steps through the code and I can see that the CCS shows the it steps through the correct function from gpio.c but no changes are being made in the resgisters so basically nothing happens.

in main.c

.....

GPIO_Handle     gpioHandle;                   //!< the handle for the GPIO module, used for SCI Communication pin toggle.

.....

while (gMotorVars.Flag_enableSystem)

{

....

if(gReceiveflag==gReceivedNum)

{

GPIO_toggle(gpioHandle, GPIO_Number_12);

j=gReceivedNum+3;

HAL_sciaWrite(halHandle, 5);

GPIO_toggle(gpioHandle, GPIO_Number_12);

gReceiveflag= 0;
}

2. So in my second attempt, I created HAL_toggleGpio function in hal.c which calls the GPIO_toggle fuction from gpio.c I called the function that I created in hal.c in my main.c and CCS shows that it is going to the correct function in gpio.c and also changing the register values. So everything is working fine.

in  hal.c

.......

//HAL Toggle GPIO Function
void HAL_toggleGpio12(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
GPIO_toggle(obj->gpioHandle, GPIO_Number_12);
}

.....

in main.c

while (gMotorVars.Flag_enableSystem)

{

......

if(gReceiveflag==gReceivedNum)

{

HAL_toggleGpio12 (halHandle);

j=gReceivedNum+3;

HAL_sciaWrite(halHandle, 5);

HAL_toggleGpio12 (halHandle);

gReceiveflag= 0;
}

// increment counters
gCounter_updateGlobals++;

.....

The Question

So my question is what is the difference between calling a function in gpio.c directly from my main.c vs. first creating  a function HAL_toggleGpio in hal.c that will call the GPIO_toggle function from gpio.c and then calling the HAL_toggleGpio function in my main.c file. Why  does one work and other doesn't even though I can see that the CCS is going to the correct functions in both cases?

  • The difference is that in main.c you don't initialize the handle:

    GPIO_Handle     gpioHandle;

    And when using the HAL, the GPIO handle is initialized in the HAL_init function.

    So, what you need to do is to initialize the gpioHandle variable in main.c:

    gpioHandle = GPIO_init((void *)GPIO_BASE_ADDR,sizeof(GPIO_Obj));

    -Jorge