+ Post New Thread
Results 1 to 13 of 13
  1. #1
    Member level 4
    Points: 433, Level: 4

    Join Date
    Sep 2019
    Posts
    69
    Helped
    0 / 0
    Points
    433
    Level
    4

    question regarding this C operations

    Hello, i cant see the link between the comment about TIM0_CC0 in the actual code bellow?
    and what is the meaning of |= in this code?
    Thanks.

    Code:
      // Set route to Location 15 and enable
      // TIM0_CC0 #15 is PC10
      TIMER0->ROUTELOC0 |=  TIMER_ROUTELOC0_CC0LOC_LOC15;
      TIMER0->ROUTEPEN |= TIMER_ROUTEPEN_CC0PEN;

  2. #2
    Super Moderator
    Points: 85,362, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,045
    Helped
    4676 / 4676
    Points
    85,362
    Level
    71

    Re: question regarding this C operations

    Standard C language.

    The '|' means logic OR.
    The '=' means 'becomes' in this context.

    '|=' means the left value becomes itself OR'ed with the right value.

    Without knowing what processor your code is for we can't comment on what it actually does in the program.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 3
    Points: 2,365, Level: 11
    Achievements:
    7 years registered

    Join Date
    Oct 2012
    Posts
    182
    Helped
    21 / 21
    Points
    2,365
    Level
    11

    Re: question regarding this C operations

    Hi,

    it is a bitwise inclusive OR assignment, see the link below.

    https://en.wikipedia.org/wiki/Bitwis...ment_operators

    greets



  4. #4
    Super Moderator
    Points: 83,988, Level: 70
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    17,081
    Helped
    3859 / 3859
    Points
    83,988
    Level
    70

    Re: question regarding this C operations

    Hi,

    you may try internet search like [c code "|="] on your own.
    First hit leads to this page:

    https://en.wikipedia.org/wiki/Operat..._C_and_C%2B%2B


    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  5. #5
    Member level 4
    Points: 433, Level: 4

    Join Date
    Sep 2019
    Posts
    69
    Helped
    0 / 0
    Points
    433
    Level
    4

    Re: question regarding this C operations

    Hello My Board is EFR32FG14
    regarding the -> i read its a pointer but i cant see the logic in here
    it loks like -> means sub member.



    •   AltAdvertisement

        
       

  6. #6
    Super Moderator
    Points: 85,362, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,045
    Helped
    4676 / 4676
    Points
    85,362
    Level
    71

    Re: question regarding this C operations

    regarding the -> i read its a pointer but i cant see the logic in here
    It is a pointer, usually to a structure member.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  7. #7
    Member level 4
    Points: 433, Level: 4

    Join Date
    Sep 2019
    Posts
    69
    Helped
    0 / 0
    Points
    433
    Level
    4

    Re: question regarding this C operations

    if -> is a pointer |= is OR then what is the logical meaning of such line?

    TIMER0->ROUTELOC0 |= TIMER_ROUTELOC0_CC0LOC_LOC15;

    Thanks.



  8. #8
    Advanced Member level 2
    Points: 5,541, Level: 17
    Achievements:
    7 years registered
    ZASto's Avatar
    Join Date
    Jan 2008
    Location
    Messy Corner, 44°47'31.56"N, 20°28'9.16"E
    Posts
    679
    Helped
    137 / 137
    Points
    5,541
    Level
    17

    Re: question regarding this C operations

    Try to find a book "C for dummies"
    Make no mistake between my personality and my attitude.
    My personality is who I am.
    My attitude depends on who you are.



  9. #9
    Advanced Member level 5
    Points: 18,935, Level: 33
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,362
    Helped
    841 / 841
    Points
    18,935
    Level
    33

    Re: question regarding this C operations

    TIMER0->ROUTELOC0 |= TIMER_ROUTELOC0_CC0LOC_LOC15;
    Yes, it can be confusing.

    Simplify!

    Let a -> b |= c;

    The operator |= is similar to += or -= or *= or /=.

    You can write it in longhand:

    a -> b = b | c;

    so you evaluate b |c first. The result is saved into b. Finally make a point to b.

    I guess you are still not happy; please take a look https://stackoverflow.com/questions/...tor-in-c-exist

    Some things are badly done. We have to live with it.



  10. #10
    Member level 4
    Points: 433, Level: 4

    Join Date
    Sep 2019
    Posts
    69
    Helped
    0 / 0
    Points
    433
    Level
    4

    Re: question regarding this C operations

    We are ORing in a value to a register. My processor has a TIMER0 with a register ROUTELOC0. It likely has a bit that is "CC0LOC_LOC15"

    Why Are we using OR for Setting route to Location?



  11. #11
    Super Moderator
    Points: 83,988, Level: 70
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    17,081
    Helped
    3859 / 3859
    Points
    83,988
    Level
    70

    Re: question regarding this C operations

    Hi,

    Why Are we using OR for Setting route to Location?
    How else?

    But wait. The benefit of OR is, that all other bits remain unchanged..

    Letīs assume you have a register of unknown value: 0b xxxx xxxx
    now you want to set bit0 and bit 3 (0b 0000 1001)
    then simply OR both registers and get: 0b xxxx 1xx1

    ****
    But yes, find a book for basics... a forum canīt replace school and reading books.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  12. #12
    Advanced Member level 5
    Points: 18,935, Level: 33
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,362
    Helped
    841 / 841
    Points
    18,935
    Level
    33

    Re: question regarding this C operations

    My processor has a TIMER0 with a register ROUTELOC0. It likely has a bit that is "CC0LOC_LOC15"
    You need to work out in longhand; the time shall be well invested.

    TIMER0 is a register within the processor that has been defined in some header files. The content of this register is described by a set of bits LOC0 to LOC15.

    How to set these values? This is the routine way in C to set some 16 bit registers to some defined state. There may be other ways (sure!) but this is short and clear.

    Read about bit manipulations of registers- the manual is a good source and all the variables are defined in the header files. Take a look at the header files to learn more.


    1 members found this post helpful.

  13. #13
    Advanced Member level 5
    Points: 18,935, Level: 33
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,362
    Helped
    841 / 841
    Points
    18,935
    Level
    33

    Re: question regarding this C operations

    You have added (INCLUDE files) a processor specific header file. Take a look at the inside (do not change anything) and look for a variable TIMER0.

    These system variables are very special: they are given only a location. It seems your TIMER0 is a 16 bit register. But this variable has to go to a fixed place. Hence TIMER0 is actually an address (one of the several registers).

    Now you cannot manipulate TIMER0 like you can (other variables); it is a pointer to a particular location (yes, registers are just memory locations for the processor). See the memory map model for the particular processor.

    Similarly, ROUTELOC0 and other variables are actually bit values but stored into an int. Please check with the program flow. There must not be any declaration for these variables. They are defined in the manual.

    You need to read something about the linker: how does it handle the timer registers.



--[[ ]]--