DSP

DSP C54X ioport的用法

2019-07-13 15:09发布

The ioport keyword enables access to the I/O port space of the C54x devices. The keyword has the form: ioport type port hex_num ioport is the keyword that indicates this is a port variable.
type must be char, short, int, or the unsigned variable.
porthex_num refers to the port number. The hex_num argument is a hexadecimal number.
All declarations of port variables must be done at the file level. Port variables declared at the function level are not supported. Do not use the ioport keyword in a function prototype.
For example, the following code declares the I/O port as unsigned port 10h, writes a to port 10h, then reads port 10h into b:
ioport unsigned port10; /* variable to access I/O port 10h */
int func ()
{
     ...
     port10 = a;         /* write a to port 10h             */
     ...
     b = port10;         /* read port 10h into b            */
     ...
}
The use of port variables is not limited to assignments. Port variables can be used in expressions like any other variable. Following are examples:
a = port10 + b; /* read port 10h, add b, assign to a       */
port10 += a;     /* read port 10h, add a, write to port 10h */
In calls, port variables are passed by value, not by reference:
call(port10);    /* read port 10h and pass (by value) to call */
call(&port10);    /* invalid pass by reference! */

DSP中如何访问I/O,数据空间 访问I/O空间
I/O空间地址声明
要在程序中访问io空间地址,必须首先用关键字“ioport”对要访问的地址进行定义。
语法:ioport t ype porthex_num
ioport 声明io空间端口变量的关键字;
type 变量类型,可以为char, short, int或unsigned int;
porthex_num 端口号,port后面接16进制数字。

ioport unsigned int port10;

注:声明io空间地址必须在C文件起始声明,不允许在函数中使用ioport声明io空间地址。 I/O空间地址访问
访问用ioport关键字声明的I/O端口变量和访问一般变量没有区别。

ioport unsigned int port10;
int func ()
{
...
port10 = a;
...
b = port10;
...
}
I/O端口变量的使用不仅仅局限于赋值,和其他变量同样也可以应用于其它的表达式。

call (port10);
a = port10 + b;
port10 += a;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
程序中访问的任何一个IO地址都必须在C语言程序起始处用ioport关键字声明!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
访问数据空间
访问数据空间不需要对要访问的单元预先声明,访问是通过指针的方法实现的。

unsigned int org,cnt,block,offset,tmp,i;
org = *(unsigned int *) 0x8000;
cnt = *(unsigned int *) 0x8001;
block = *(unsigned int *) 0x8002;
offset = *(unsigned int *) 0x8003;
for (i=0; i
tmp = *(unsigned int *) (org + i);
*(unsigned int *) (org + offset +i) = tmp;