diff options
Diffstat (limited to 'cpukit/score/cpu/avr/avr/sfr_defs.h')
-rw-r--r-- | cpukit/score/cpu/avr/avr/sfr_defs.h | 266 |
1 files changed, 135 insertions, 131 deletions
diff --git a/cpukit/score/cpu/avr/avr/sfr_defs.h b/cpukit/score/cpu/avr/avr/sfr_defs.h index b687f56167..2b8392689a 100644 --- a/cpukit/score/cpu/avr/avr/sfr_defs.h +++ b/cpukit/score/cpu/avr/avr/sfr_defs.h @@ -1,3 +1,9 @@ +/** + * @file + * + * @brief Macros for Accessing AVR Special Function Registers + */ + /* Copyright (c) 2002, Marek Michalkiewicz <marekm@amelek.gda.pl> All rights reserved. @@ -34,85 +40,89 @@ #ifndef _AVR_SFR_DEFS_H_ #define _AVR_SFR_DEFS_H_ 1 -/** \defgroup avr_sfr_notes Additional notes from <avr/sfr_defs.h> - \ingroup avr_sfr - - The \c <avr/sfr_defs.h> file is included by all of the \c <avr/ioXXXX.h> - files, which use macros defined here to make the special function register - definitions look like C variables or simple constants, depending on the - <tt>_SFR_ASM_COMPAT</tt> define. Some examples from \c <avr/iocanxx.h> to - show how to define such macros: - -\code -#define PORTA _SFR_IO8(0x02) -#define EEAR _SFR_IO16(0x21) -#define UDR0 _SFR_MEM8(0xC6) -#define TCNT3 _SFR_MEM16(0x94) -#define CANIDT _SFR_MEM32(0xF0) -\endcode - - If \c _SFR_ASM_COMPAT is not defined, C programs can use names like - <tt>PORTA</tt> directly in C expressions (also on the left side of - assignment operators) and GCC will do the right thing (use short I/O - instructions if possible). The \c __SFR_OFFSET definition is not used in - any way in this case. - - Define \c _SFR_ASM_COMPAT as 1 to make these names work as simple constants - (addresses of the I/O registers). This is necessary when included in - preprocessed assembler (*.S) source files, so it is done automatically if - \c __ASSEMBLER__ is defined. By default, all addresses are defined as if - they were memory addresses (used in \c lds/sts instructions). To use these - addresses in \c in/out instructions, you must subtract 0x20 from them. - - For more backwards compatibility, insert the following at the start of your - old assembler source file: - -\code -#define __SFR_OFFSET 0 -\endcode - - This automatically subtracts 0x20 from I/O space addresses, but it's a - hack, so it is recommended to change your source: wrap such addresses in - macros defined here, as shown below. After this is done, the - <tt>__SFR_OFFSET</tt> definition is no longer necessary and can be removed. - - Real example - this code could be used in a boot loader that is portable - between devices with \c SPMCR at different addresses. - -\verbatim -<avr/iom163.h>: #define SPMCR _SFR_IO8(0x37) -<avr/iom128.h>: #define SPMCR _SFR_MEM8(0x68) -\endverbatim - -\code -#if _SFR_IO_REG_P(SPMCR) - out _SFR_IO_ADDR(SPMCR), r24 -#else - sts _SFR_MEM_ADDR(SPMCR), r24 -#endif -\endcode - - You can use the \c in/out/cbi/sbi/sbic/sbis instructions, without the - <tt>_SFR_IO_REG_P</tt> test, if you know that the register is in the I/O - space (as with \c SREG, for example). If it isn't, the assembler will - complain (I/O address out of range 0...0x3f), so this should be fairly - safe. - - If you do not define \c __SFR_OFFSET (so it will be 0x20 by default), all - special register addresses are defined as memory addresses (so \c SREG is - 0x5f), and (if code size and speed are not important, and you don't like - the ugly \#if above) you can always use lds/sts to access them. But, this - will not work if <tt>__SFR_OFFSET</tt> != 0x20, so use a different macro - (defined only if <tt>__SFR_OFFSET</tt> == 0x20) for safety: - -\code - sts _SFR_ADDR(SPMCR), r24 -\endcode - - In C programs, all 3 combinations of \c _SFR_ASM_COMPAT and - <tt>__SFR_OFFSET</tt> are supported - the \c _SFR_ADDR(SPMCR) macro can be - used to get the address of the \c SPMCR register (0x57 or 0x68 depending on - device). */ +/** + * @defgroup avr_sfr_notes Additional notes from <avr/sfr_defs.h> + * + * @ingroup avr_sfr + * + * The @c <avr/sfr_defs.h> file is included by all of the @c <avr/ioXXXX.h> + * files, which use macros defined here to make the special function register + * definitions look like C variables or simple constants, depending on the + * <tt>_SFR_ASM_COMPAT</tt> define. Some examples from @c <avr/iocanxx.h> to + * show how to define such macros: + * + * @code + * #define PORTA _SFR_IO8(0x02) + * #define EEAR _SFR_IO16(0x21) + * #define UDR0 _SFR_MEM8(0xC6) + * #define TCNT3 _SFR_MEM16(0x94) + * #define CANIDT _SFR_MEM32(0xF0) + * @endcode + * + * If @c _SFR_ASM_COMPAT is not defined, C programs can use names like + * <tt>PORTA</tt> directly in C expressions (also on the left side of + * assignment operators) and GCC will do the right thing (use short I/O + * instructions if possible). The @c __SFR_OFFSET definition is not used in + * any way in this case. + * + * Define @c _SFR_ASM_COMPAT as 1 to make these names work as simple constants + * (addresses of the I/O registers). This is necessary when included in + * preprocessed assembler (*.S) source files, so it is done automatically if + * @c __ASSEMBLER__ is defined. By default, all addresses are defined as if + * they were memory addresses (used in @c lds/sts instructions). To use these + * addresses in @c in/out instructions, you must subtract 0x20 from them. + * + * For more backwards compatibility, insert the following at the start of your + * old assembler source file: + * + * @code + * #define __SFR_OFFSET 0 + * @endcode + * + * This automatically subtracts 0x20 from I/O space addresses, but it's a + * hack, so it is recommended to change your source: wrap such addresses in + * macros defined here, as shown below. After this is done, the + * <tt>__SFR_OFFSET</tt> definition is no longer necessary and can be removed. + + * Real example - this code could be used in a boot loader that is portable + * between devices with @c SPMCR at different addresses. + * + * @verbatim + * <avr/iom163.h>: #define SPMCR _SFR_IO8(0x37) + * <avr/iom128.h>: #define SPMCR _SFR_MEM8(0x68) + * @endverbatim + * + * @code + * #if _SFR_IO_REG_P(SPMCR) + * out _SFR_IO_ADDR(SPMCR), r24 + * #else + * sts _SFR_MEM_ADDR(SPMCR), r24 + * #endif + * @endcode + * + * You can use the @c in/out/cbi/sbi/sbic/sbis instructions, without the + * <tt>_SFR_IO_REG_P</tt> test, if you know that the register is in the I/O + * space (as with @c SREG, for example). If it isn't, the assembler will + * complain (I/O address out of range 0...0x3f), so this should be fairly + * safe. + * + * If you do not define @c __SFR_OFFSET (so it will be 0x20 by default), all + * special register addresses are defined as memory addresses (so @c SREG is + * 0x5f), and (if code size and speed are not important, and you don't like + * the ugly \#if above) you can always use lds/sts to access them. But, this + * will not work if <tt>__SFR_OFFSET</tt> != 0x20, so use a different macro + * (defined only if <tt>__SFR_OFFSET</tt> == 0x20) for safety: + * + * @code + * sts _SFR_ADDR(SPMCR), r24 + * @endcode + * + * In C programs, all 3 combinations of @c _SFR_ASM_COMPAT and + * <tt>__SFR_OFFSET</tt> are supported - the @c _SFR_ADDR(SPMCR) macro can be + * used to get the address of the @c SPMCR register (0x57 or 0x68 depending on + * device). + */ +/**@{**/ #ifdef __ASSEMBLER__ #define _SFR_ASM_COMPAT 1 @@ -190,23 +200,23 @@ #define _SFR_WORD(sfr) _MMIO_WORD(_SFR_ADDR(sfr)) #define _SFR_DWORD(sfr) _MMIO_DWORD(_SFR_ADDR(sfr)) -/** \name Bit manipulation */ - -/*@{*/ -/** \def _BV - \ingroup avr_sfr - - \code #include <avr/io.h>\endcode - - Converts a bit number into a byte value. - - \note The bit shift is performed by the compiler which then inserts the - result into the code. Thus, there is no run-time overhead when using - _BV(). */ - +/** + * @name Bit Manipulation + */ +/**@{**/ + +/** + * @code #include <avr/io.h> @endcode + * + * Converts a bit number into a byte value. + * + * @note The bit shift is performed by the compiler which then inserts the + * result into the code. Thus, there is no run-time overhead when using + * _BV(). + */ #define _BV(bit) (1 << (bit)) -/*@}*/ +/** @} */ #ifndef _VECTOR #define _VECTOR(N) __vector_ ## N @@ -215,53 +225,47 @@ #ifndef __ASSEMBLER__ -/** \name IO register bit manipulation */ - -/*@{*/ - - - -/** \def bit_is_set - \ingroup avr_sfr - - \code #include <avr/io.h>\endcode - - Test whether bit \c bit in IO register \c sfr is set. - This will return a 0 if the bit is clear, and non-zero - if the bit is set. */ +/** + * @name IO Register Bit Manipulation + */ +/**@{**/ +/** + * @code #include <avr/io.h> @endcode + * + * Test whether bit @c bit in IO register @c sfr is set. + * This will return a 0 if the bit is clear, and non-zero + * if the bit is set. + */ #define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit)) -/** \def bit_is_clear - \ingroup avr_sfr - - \code #include <avr/io.h>\endcode - - Test whether bit \c bit in IO register \c sfr is clear. - This will return non-zero if the bit is clear, and a 0 - if the bit is set. */ +/** + * @code #include <avr/io.h> @endcode + * + * Test whether bit @c bit in IO register @c sfr is clear. + * This will return non-zero if the bit is clear, and a 0 + * if the bit is set. + */ #define bit_is_clear(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit))) -/** \def loop_until_bit_is_set - \ingroup avr_sfr - - \code #include <avr/io.h>\endcode - - Wait until bit \c bit in IO register \c sfr is set. */ - +/** + * @code #include <avr/io.h> @endcode + * + * Wait until bit @c bit in IO register @c sfr is set. + */ #define loop_until_bit_is_set(sfr, bit) do { } while (bit_is_clear(sfr, bit)) -/** \def loop_until_bit_is_clear - \ingroup avr_sfr - - \code #include <avr/io.h>\endcode - - Wait until bit \c bit in IO register \c sfr is clear. */ - +/** + * @code #include <avr/io.h> @endcode + * + * Wait until bit @c bit in IO register @c sfr is clear. + */ #define loop_until_bit_is_clear(sfr, bit) do { } while (bit_is_set(sfr, bit)) -/*@}*/ +/** @} */ + +/** @} */ #endif /* !__ASSEMBLER__ */ |