Forums

How to access IO registers on ADSP 21992 using C language?

Started by Paul October 7, 2005
hi, greetings,

How can I access IO register on 21992 using C language?

It seems IO registers on ADSP 21992 are not mapped to system memory. If
I want to access these IO registers, I need to set the IOPG first and
then set the relative  memory address for them.

For example, if I want to write PWM0_TM, i can do this with Assemble
language like this:

IOPG=PWM0_Page;   	// page of PWM0 block
ar = PWM_Period;
IO(PWM0_TM)= ar;	//write to PWM period register

But how can I do this with C language? I can not figure out how to set
the memory address for such IO registers.

Thanks.

Paul wrote:

> hi, greetings, > > How can I access IO register on 21992 using C language? > > It seems IO registers on ADSP 21992 are not mapped to system memory. If > I want to access these IO registers, I need to set the IOPG first and > then set the relative memory address for them. > > For example, if I want to write PWM0_TM, i can do this with Assemble > language like this: > > IOPG=PWM0_Page; // page of PWM0 block > ar = PWM_Period; > IO(PWM0_TM)= ar; //write to PWM period register > > But how can I do this with C language? I can not figure out how to set > the memory address for such IO registers. > > Thanks. >
I hate that. If you can write to I/O with a variable address you can make a generic pair of assembly routines that'll let you read and write I/O; you'll do this by passing the address (and maybe a write value), then passing back a read value (if it's a read). If you must use a fixed address (Bad ADI, BAD ADI) then you'll have to make a much of such routines -- I would generate them with a script... Double check to make sure that your compiler vendor hasn't done this for you. It's the sort of thing that a tool vendor should supply, not that they always do, or always get right when they bother. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Tim Wescott wrote:

   ...

> If you can write to I/O with a variable address you can make a generic > pair of assembly routines that'll let you read and write I/O; you'll do > this by passing the address (and maybe a write value), then passing back > a read value (if it's a read). > > If you must use a fixed address (Bad ADI, BAD ADI) then you'll have to > make a much of such routines -- I would generate them with a script... > > Double check to make sure that your compiler vendor hasn't done this for > you. It's the sort of thing that a tool vendor should supply, not that > they always do, or always get right when they bother.
If those addresses are treated like RAM, can't you just define pointers to them? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
No. I dont think these IO registers can be treated like RAM. I checked
the memory map. The IO memory space seems a different part of RAM.

Paul wrote:

> No. I dont think these IO registers can be treated like RAM. I checked > the memory map. The IO memory space seems a different part of RAM. >
Yup. I double checked for you. God I hate that. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
So it seems no way to access the IO register using C language,right?

Damm ADI.

paul

Paul wrote:
> So it seems no way to access the IO register using C language,right? > > Damm ADI. > > paul
In general, HLLs don't give the programmer access to registers, status flags, or other processor-specific resources. It isn't possible to do that portably, and portability is supposed to be a hallmark of high-level code. Any such access must always be a language extension specific to a particular processor. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Tim Wescott wrote:
> Paul wrote: > > > hi, greetings, > > > > How can I access IO register on 21992 using C language? > > > > It seems IO registers on ADSP 21992 are not mapped to system memory. If > > I want to access these IO registers, I need to set the IOPG first and > > then set the relative memory address for them. > > > > For example, if I want to write PWM0_TM, i can do this with Assemble > > language like this: > > > > IOPG=PWM0_Page; // page of PWM0 block > > ar = PWM_Period; > > IO(PWM0_TM)= ar; //write to PWM period register > > > > But how can I do this with C language? I can not figure out how to set > > the memory address for such IO registers. > > > > Thanks. > > > I hate that. > > If you can write to I/O with a variable address you can make a generic > pair of assembly routines that'll let you read and write I/O; you'll do > this by passing the address (and maybe a write value), then passing back > a read value (if it's a read). > > If you must use a fixed address (Bad ADI, BAD ADI) then you'll have to > make a much of such routines -- I would generate them with a script...
It be possible with macros using inline assembly
> > Double check to make sure that your compiler vendor hasn't done this for > you. It's the sort of thing that a tool vendor should supply, not that > they always do, or always get right when they bother. >
yeh, it looks as if it could get a little tricky, I haven't used that ADSP but it looks like IOPG is some sort of global paging register, so I would think that it's required to bracket the access with a store and disable interrupt and restore interrupt. -Lasse
Paul wrote:
> How can I access IO register on 21992 using C language?
I'm not familiar with the 21992, but for the 2116x and Tiger families, ADI provides builtin_sysreg_read() and builtin_sysreg_write() functions. Look for something like that. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536 A pessimist is an optimist with experience
>hi, greetings, > >How can I access IO register on 21992 using C language? > >It seems IO registers on ADSP 21992 are not mapped to system memory. If >I want to access these IO registers, I need to set the IOPG first and >then set the relative memory address for them. > >For example, if I want to write PWM0_TM, i can do this with Assemble >language like this: > >IOPG=PWM0_Page; // page of PWM0 block >ar = PWM_Period; >IO(PWM0_TM)= ar; //write to PWM period register > >But how can I do this with C language? I can not figure out how to set >the memory address for such IO registers. > >Thanks.
Hi I found a solution for this issue, by an example sent to me from ADI, and I'd like to share. I was interested in ADC control, but this could be used for any IO register: #include <adsp-2199x.h> #include <sysreg.h> sysreg_write(sysreg_IOPG, ADC_Page); io_space_write(ADC_CTRL, 0x0207);//write 0x207 into the ADC_CTRL register daphna.