AnsweredAssumed Answered

What does it mean? "if(A==B==C)" in Freescale USB stack v4.0.3

Question asked by Kai Liu on May 24, 2013
Latest reply on Dec 23, 2015 by Renato Laureano

I have to debug code and look into source code of Freescale USB stack (v4.0.3) because of my project.

 

In khci_kinetis.c::_usb_khci_atom_tr(), line 261, there is a statement I can not fully understand.

 

        if (USB_EVENT_SET == _usb_event_wait_ticks(&khci_event, KHCI_EVENT_MASK, FALSE, 1) == USB_OK)

        {

            break;

        }

 

#define USB_EVENT_SET 0x02

#define USB_OK 0x00

uint_16 _usb_event_wait_ticks(USB_EVENT_STRUCT_PTR, uint_32, uint_8, uint_16);

 

That statement means

     if (0x02==var==0x00) break;

 

What is it anyway? I guess the judgement will be evaluated from left to right. If var equals to 0x02, then it is 0x01 as True. Otherwise it is 0x00 as false, then the truth value is compared to 0x00 to get second turth result.

 

Am I right? I still get confused why Freescale use such statement.

 

I double checked with v4.1.1, the latest release USB stack, it changes to

 

       if ((USB_EVENT_SET == _usb_event_wait_ticks(&khci_event, KHCI_EVENT_MASK, FALSE, 1)) == USB_OK)

        {

            break;

        }

 

It makes things much easier and safer. However, I doubt why Freescale can not use much simpler statements such as

 

if (USB_EVENT_SET == _usb_event_wait_ticks(&khci_event, KHCI_EVENT_MASK, FALSE, 1))

 

or

 

if (USB_EVENT_SET != usb_event_wait_ticks(&khci_event, KHCI_EVENT_MASK, FALSE, 1))

Outcomes