Chaitannya
Chaitannya

Reputation: 936

What is the '__IO' directive in GCC?

I am working on an embedded device, and there is some code that was originally compiled using the IAR compiler.

I am trying to recompile said code using the GCC compiler.

There is a particular statement: typedef __IO , which simply doesn't get compiled ("Unrecognized symbol error").

Could anyone suggest how I could get this statement to compile properly?

Upvotes: 16

Views: 29614

Answers (3)

Plasty Grove
Plasty Grove

Reputation: 2887

This is an old question, but in case someone wants to know this for ARM Microcontrollers, you can see that the definition is available in the CMSIS library. For example, __IO is defined as follows for cortex-m4:

#define     __IO    volatile             /*!< Defines 'read / write' permissions */

The full block is copy pasted below (Source):

#ifdef __cplusplus
  #define   __I     volatile             /*!< Defines 'read only' permissions */
#else
  #define   __I     volatile const       /*!< Defines 'read only' permissions */
#endif
#define     __O     volatile             /*!< Defines 'write only' permissions */
#define     __IO    volatile             /*!< Defines 'read / write' permissions */

/* following defines should be used for structure members */
#define     __IM     volatile const      /*! Defines 'read only' structure member permissions */
#define     __OM     volatile            /*! Defines 'write only' structure member permissions */
#define     __IOM    volatile            /*! Defines 'read / write' structure member permissions */

Upvotes: 6

Nithin
Nithin

Reputation: 81

_IO meaning volatile as per in C language...which will not optimize the code and in which value stated for the variable using _IO will be unpredictable or will be changing without knowledge of compiler and user

Upvotes: 8

Clifford
Clifford

Reputation: 93566

If it is not recognised it will be because an appropriate system header containing the definition has not been included.

It will be defined in the chip support header file provided with the toolchain. It is type qualifier, or rather a macro (#define) that will expand to a type qualifier. It is used for example as follows:

__IO uint8_t CSSR;

Here uint8_t is the type, so __IO cannot in fact be a typedef because it is not used where a type is valid. The __IO macro expands to whatever the particular compiler requires to ensure correct I/O access and addressing. In the typical case where I/O is memory mapped, it will simply expand to volatile since all I/O should be declared volatile to ensure explicit accesses are not optimised out.

If you want to be sure, download a demo version of the IAR tools and take a look in the header files at how it is defined for your particular architecture. Otherwise you might just use #define __IO volatile

Upvotes: 14

Related Questions