DSP C54X ioport的用法

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<cnt; i++)

tmp = *(unsigned int *) (org + i);
*(unsigned int *) (org + offset +i) = tmp;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值