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.

TMS320F28379D: C2000WARE-MOTORCONTROL-SDK clarke module

Part Number: TMS320F28379D
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE, C2000WARE-MOTORCONTROL-SDK, MOTORWARE

Hi community

I am trying to migrate from controlSUITE to C2000ware. However, I have confused with the codding styles! as an example, could evreyone please let me know what does this function do?

static inline uint_least8_t
CLARKE_getNumSensors(CLARKE_Handle handle)
{
    CLARKE_Obj *obj = (CLARKE_Obj *)handle;

    return(obj->numSensors);
} // end of CLARKE_getNumSensors() function

It is a part of clarke.h header file of C2000WARE-MOTORCONTROL-SDK.

I have problem with first line of the function body. What does it do?

Regards

  • You mean the line "CLARKE_Obj *obj = (CLARKE_Obj *)handle;"? The handle parameter is type CLARKE_Handle which is defined as a pointer to a CLARKE_Obj object. This line of code is declaring a local pointer to a CLARKE_Obj and setting that equal to handle so that the local pointer can be used to get to the numSensors value.

    Whitney

  • Thanks for the reply

    I cant understand why not the code directly gets the number of sensors as follows:

    uint_least8_t Number= handle-> numSensors;

    Another question: Is this a kind of type casting? why it is used?

    (CLARKE_Obj *)handle; 

    Sorry for such questions but I am armature in embedded programming.

    Best regards

  • You could just access it directly. The coding style of these libraries mimics object oriented programming style where members of structs can be private and need to be accessed through "get" functions.

    The line is casting handle to type (CLARKE_Obj *), yes. I don't think it's actually necessary since CLARKE_Handle is equivalent to CLARKE_Obj* though.

    Whitney

  • Thank you Whitney

    Do you know any resource or text book for simply learning this programming style? Consider this that I'm an electrical engineer and am using TI DSP for motor control programming.

    Best regards

  • Some of these modules originated in the MotorWare package which contains a document called "motorware_software_architecture.pdf" which goes into some explanations about how the code is designed.

    As I said, this code is meant to mimic object oriented programming languages (like C++) even though the code is written in C, so a little knowledge of OOP is helpful to recognize the principles being applied. You could probably find some resources online to give you a light introduction to it, but I don't think it's necessary since C is ultimately not an OOP language.

    Whitney