Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

question regarding this C operations

yefj

Full Member level 1
Joined
Sep 12, 2019
Messages
97
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
718
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;
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,128
Helped
4,678
Reputation
9,371
Reaction score
4,415
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
120,720
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.
 

yefj

Full Member level 1
Joined
Sep 12, 2019
Messages
97
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
718
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.
 

yefj

Full Member level 1
Joined
Sep 12, 2019
Messages
97
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
718
if -> is a pointer |= is OR then what is the logical meaning of such line?

TIMER0->ROUTELOC0 |= TIMER_ROUTELOC0_CC0LOC_LOC15;

Thanks.
 

c_mitra

Advanced Member level 5
Joined
Nov 13, 2012
Messages
3,367
Helped
846
Reputation
1,692
Reaction score
797
Trophy points
1,393
Activity points
25,731

yefj

Full Member level 1
Joined
Sep 12, 2019
Messages
97
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
718
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?
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,310
Helped
3,918
Reputation
7,834
Reaction score
3,780
Trophy points
113
Activity points
114,890
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
 

c_mitra

Advanced Member level 5
Joined
Nov 13, 2012
Messages
3,367
Helped
846
Reputation
1,692
Reaction score
797
Trophy points
1,393
Activity points
25,731
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.
 
  • Like
Reactions: yefj

    yefj

    points: 2
    Helpful Answer Positive Rating

c_mitra

Advanced Member level 5
Joined
Nov 13, 2012
Messages
3,367
Helped
846
Reputation
1,692
Reaction score
797
Trophy points
1,393
Activity points
25,731
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.
 

Toggle Sidebar

Part and Inventory Search


Welcome to EDABoard.com

Sponsor

Sponsor

Design Fast


×
Top