关键词ioport的作用是什么

来源:互联网 发布:蜂窝数据怎么一键开启 编辑:程序博客网 时间:2024/04/28 07:01

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! */

 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cdm_xu/archive/2009/06/13/4265563.aspx