您的位置:首页 > 运维架构

关键词ioport的作用是什么

2009-06-13 09:17 239 查看
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! */
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: