Sign in

username:

password:



Not a member?

Search code-comp



Search tips

Subscribe to code-comp



code-comp by Keywords

ARM7 | BIOS | Bug | EVM | JTAG | Linker | LOG_printf | McBSP | Profiling | Relocation | RTDX | Simulator | Target | Watch

Sponsor

NEW! TMS320C6474: 3x the performance. 1/3 the cost. Three 1 GHz cores on 1 chip.

Discussion Groups

Discussion Groups | Code-Composer | C code explanation

Technical discussions about Code Composer Studio.

  

Post a new Thread

C code explanation - sord...@hotmail.com - Sep 6 8:45:59 2006



       Hi to everyone,

     I have found an example program which uses McBSP and although I know quite well how to
program in C, I can't understand what these lines below mean:

------------------------------------------------------------

void mcbsp0_init()    				 
{
 *(unsigned volatile int *)McBSP0_SPCR = 0;	  
 *(unsigned volatile int *)McBSP0_PCR = 0;       
 *(unsigned volatile int *)McBSP0_RCR = 0x10040;  
 *(unsigned volatile int *)McBSP0_XCR = 0x10040;  
 *(unsigned volatile int *)McBSP0_DXR = 0;   
 *(unsigned volatile int *)McBSP0_SPCR = 0x12001;
}

void mcbsp0_write(int out_data)	 
{
 int temp;
 
 if (polling)
 {  
  temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
  while ( temp == 0)
    temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
 }        
 *(unsigned volatile int *)McBSP0_DXR = out_data;
}
-------------------------------------------------------------

      I know that in the first function, it is setting some constants, whose names have been
set in a header file that I haven't included. I am not sure what kind of data is *(unsigned
volatile int*), because it doesn't appear in the manual. I don't know why it has two '*' which
is used for pointers in C.

       The other question is next line:
temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
       I dont't know what operation is doing '&'. Is an AND gate operation??

               Thanks in advance,

      Pablo L.



(You need to be a member of code-comp -- send a blank email to code-comp-subscribe@yahoogroups.com )

RE: C code explanation - Timothy Fosdike - Sep 7 8:49:14 2006

>  *(unsigned volatile int *)McBSP0_SPCR = 0;

McBSP0_SPCR is an address declared as a numerical constant.  
(unsigned volatile int *) casts it to a particular datatype
and the leading * dereferences this pointer.  So the statement
means "set the unsigned integer at address McBSP0_SPCR to 0".

This can clearly be seen by adding more parentheses instead of using
operator precedence:

*((unsigned volatile int *)McBSP0_SPCR) = 0;

You should find a definition of 'volatile' fairly easily.

>   temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;

Again, explicitly showing operator precedence, we have:

temp = (*((unsigned volatile int *)McBSP0_SPCR)) & 0x20000;

so the sequence is:
1) cast address to pointer
2) retrieve pointer contents
3) and with constant
4) assign result to temp



(You need to be a member of code-comp -- send a blank email to code-comp-subscribe@yahoogroups.com )

Re: C code explanation - Raju Udava - Sep 7 8:54:03 2006

Pablo,

*(unsigned volatile int *)McBSP0_SPCR = 0;

In the above statement, *(unsigned volatile int *)* is typecasting.
McBSP0_SPCR holds an address. So outer * is used to get the value present in
that particular address.

& used is bit wise AND operator.

My suggestion: Refer a C book. You will find answers to your above queries.

On 9/6/06, s...@hotmail.com <s...@hotmail.com>
wrote:
>
>    Hi to everyone,
>
> I have found an example program which uses McBSP and although I know quite
> well how to program in C, I can't understand what these lines below mean:
>
> ----------------------------------------------------------
>
> void mcbsp0_init()
> {
> *(unsigned volatile int *)McBSP0_SPCR = 0;
> *(unsigned volatile int *)McBSP0_PCR = 0;
> *(unsigned volatile int *)McBSP0_RCR = 0x10040;
> *(unsigned volatile int *)McBSP0_XCR = 0x10040;
> *(unsigned volatile int *)McBSP0_DXR = 0;
> *(unsigned volatile int *)McBSP0_SPCR = 0x12001;
> }
>
> void mcbsp0_write(int out_data)
> {
> int temp;
>
> if (polling)
> {
> temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
> while ( temp == 0)
> temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
> }
> *(unsigned volatile int *)McBSP0_DXR = out_data;
> }
> ----------------------------------------------------------
>
> I know that in the first function, it is setting some constants, whose
> names have been set in a header file that I haven't included. I am not sure
> what kind of data is *(unsigned volatile int*), because it doesn't appear in
> the manual. I don't know why it has two '*' which is used for pointers in C.
>
> The other question is next line:
> temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
> I dont't know what operation is doing '&'. Is an AND gate operation??
>
> Thanks in advance,
>
> Pablo L.
>

-- 
----
Raju Udava
Bangalore.

" I am responsible for myself. No one can HELP "
                                          - My Love



(You need to be a member of code-comp -- send a blank email to code-comp-subscribe@yahoogroups.com )

Re: C code explanation - tien vuong - Sep 8 9:39:45 2006

Hi sordoknha,

--- s...@hotmail.com wrote:
>        Hi to everyone,
> 
>      I have found an example program which uses
> McBSP and although I know quite well how to program
> in C,
> I can't understand what these lines below
> mean:
------------------------------------------------------------
> 
> void mcbsp0_init()    				
> {
>  *(unsigned volatile int *)McBSP0_SPCR = 0;	  
>  *(unsigned volatile int *)McBSP0_PCR = 0;       
>  *(unsigned volatile int *)McBSP0_RCR = 0x10040;  
>  *(unsigned volatile int *)McBSP0_XCR = 0x10040;  
>  *(unsigned volatile int *)McBSP0_DXR = 0;   
>  *(unsigned volatile int *)McBSP0_SPCR = 0x12001;
> }
> 
> void mcbsp0_write(int out_data)	 
> {
>  int temp;
>  
>  if (polling)
>  {  
>   temp = *(unsigned volatile int *)McBSP0_SPCR &
> 0x20000;
>   while ( temp == 0)
>     temp = *(unsigned volatile int *)McBSP0_SPCR &
> 0x20000;
>  }        
>  *(unsigned volatile int *)McBSP0_DXR = out_data;
> }
>
-------------------------------------------------------------
> 
>       I know that in the first function, it is
> setting some constants, whose names have been set in
> a header file that I haven't included. I am not sure
> what kind of data is *(unsigned volatile int*),
> because it doesn't appear in the manual.

It doesn't because it isn't CCS specific, it is just
C.

> I don't
> know why it has two '*' which is used for pointers
> in C.

(unsigned volatile int *) is a type casting operator.
And the leading * is to get the value stored at the
followed pointer. You can read about "type casting"
and "volatile" in C books.

> 
>        The other question is next line:
> temp = *(unsigned volatile int *)McBSP0_SPCR &
> 0x20000;
>        I dont't know what operation is doing '&'. Is
> an AND gate operation??
> 

& is bit AND operator. When the above code is
executed, temp will be the result when ANDing each bit
stored at address pointed by McBSP0_SPCR with each bit
in 0x20000 in the same bit order. You can also read
about "bitwise operation" in C book.

Tien



(You need to be a member of code-comp -- send a blank email to code-comp-subscribe@yahoogroups.com )