dl8dtl - Nov 26, 2006 - 08:38 PM Post subject: RE: Binary constants in IAR C ?> Binary notation was added in C99 if I remember correctly.
No, it's been rejected by the committee.
In the C99 rationale, you can find under 6.4.4.1 Integer constants:
``A proposal to add binary constants was rejected due to lack of precedent and insufficient utility.''
So please tell your (national) standards body there *is* sufficient utility for it. As for the first part, I'm trying to get the 0b patch officially as an extension into GCC. Once that happened, there will be at least one very prominent C implementation that sets a precedent case. ;-) All those microcontroller implementations are probably nothing the ISO C standardization body might be aware of, but for sure, GCC is.
> IAR is not fully up to C99 yet,
It's about the most complete C99 implementation I've seen.
PINA_Bit0 이런 녀석이 winavr 쪽의 PINA0 이런것과 1:1 매칭이 되는지
PINA0 PORTA0 이런것이 정말 비트 단위로 읽어올수 있고 조작이 가능한지도 모호한 상황인데..
아무튼 아래의 링크는 iar 용 매크로 라던가 변수선언들을 변환하여
일반적인 avr용 컴파일러에서 컴파일이 가능하도록 해주는 래핑소스이다.
/* Input Pins, Port A */
#define PINA _SFR_IO8(0x19)
/* Data Direction Register, Port A */
#define DDRA _SFR_IO8(0x1A)
/* Data Register, Port A */
#define PORTA _SFR_IO8(0x1B)
/* Port A Data Register - PORTA */
#define PA7 7
#define PA6 6
#define PA5 5
#define PA4 4
#define PA3 3
#define PA2 2
#define PA1 1
#define PA0 0
/* Port A Data Direction Register - DDRA */
#define DDA7 7
#define DDA6 6
#define DDA5 5
#define DDA4 4
#define DDA3 3
#define DDA2 2
#define DDA1 1
#define DDA0 0
/* Port A Input Pins - PINA */
#define PINA7 7
#define PINA6 6
#define PINA5 5
#define PINA4 4
#define PINA3 3
#define PINA2 2
#define PINA1 1
#define PINA0 0
[출처: C:\WinAVR-20100110\avr\include\avr\iom128.h]
-- 퇴근후 추가
대충해보니 머.. 정의문이라서 정수로 들어가다 보니 아무런 의미도 없는듯 -_-
아무튼, PINA.0 이런식으로 구성이 가능한것은 code vision 쪽 확장인것으로 추측되고
winavr에서는 표준적으로 비트 마스킹을 통해서만 가능한 것으로 추측된다.
/* Input Pins, Port A */
#define PINA _SFR_IO8(0x19)
/* Data Direction Register, Port A */
#define DDRA _SFR_IO8(0x1A)
/* Data Register, Port A */
#define PORTA _SFR_IO8(0x1B)
정리하자면
PINA는 입력된 값을 읽고
PORTA는 출력할 값을 읽고
DDRA는 그 포트의 방향을 정해준다.
예를들어, UART 같은 경우
TX 값은 PORTA에 쓰고, RX값은 PINA에서 읽는 식이라고 하면 되려나?
Pin* is for read, Port* is for write and DDR* is for direction...
* = Register ( A, D,C...)
PIN* is the register you use to read the value on a port if it is an input (so if the corresponding bit in DDR* is '0'). PORT* is used to output values, or to read earlier outputted values back.
outp() inp()는 매크로이다.
정확한 시기는 모르겠지만, winAVR-20050414 버전 이후 제외된 것으로 보인다.
물론 <compat/deprecated.h> 를 사용하면 호환되도록 작동은 가능할 것으로 보이지만,
문법적으로 깔끔하지 않고, 표준 C를 따르지 않는(이 부분은 좀 이해가 안됨) 이유로 인해서
불편함을 감수하고 위의 매크로가 제외되었다고 한다.
There was a discussion a while back on the avr-gcc mailing list. Some
"old stuff" has been purged. Some people are not happy about it. But the purged macros were non-standard, had confusing syntax and unclear semantics, and had been deprecated for over two years, so (IMHO) the
maintainers were justified in purging them.
The quick fix for legacy code is to create a new header (e.g.
"legacy.h") that defines the purged macros for you. E.g.,
/* Copyright (c) 2005,2006 Joerg Wunsch
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* $Id: deprecated.h,v 1.6.2.2 2008/07/30 21:39:21 arcanum Exp $ */
#ifndef _COMPAT_DEPRECATED_H_
#define _COMPAT_DEPRECATED_H_
/** \defgroup deprecated_items "compat/deprecated.h": Deprecated items
This header file contains several items that used to be available
in previous versions of this library, but have eventually been
deprecated over time.
\code #include "compat/deprecated.h" \endcode
These items are supplied within that header file for backward
compatibility reasons only, so old source code that has been
written for previous library versions could easily be maintained
until its end-of-life. Use of any of these items in new code is
strongly discouraged.
*/
/** \name Allowing specific system-wide interrupts
In addition to globally enabling interrupts, each device's particular
interrupt needs to be enabled separately if interrupts for this device are
desired. While some devices maintain their interrupt enable bit inside
the device's register set, external and timer interrupts have system-wide
configuration registers.
Example:
\code
// Enable timer 1 overflow interrupts.
timer_enable_int(_BV(TOIE1));
// Do some work...
// Disable all timer interrupts.
timer_enable_int(0);
\endcode
\note Be careful when you use these functions. If you already have a
different interrupt enabled, you could inadvertantly disable it by
enabling another intterupt. */
/*@{*/
/** \ingroup deprecated_items
\def enable_external_int(mask)
\deprecated
This macro gives access to the \c GIMSK register (or \c EIMSK register
if using an AVR Mega device or \c GICR register for others). Although this
macro is essentially the same as assigning to the register, it does
adapt slightly to the type of device being used. This macro is
unavailable if none of the registers listed above are defined. */
/* Define common register definition if available. */
#if defined(EIMSK)
# define __EICR EIMSK
#elif defined(GIMSK)
# define __EICR GIMSK
#elif defined(GICR)
# define __EICR GICR
#endif
/* If common register defined, define macro. */
#if defined(__EICR) || defined(__DOXYGEN__)
#define enable_external_int(mask) (__EICR = mask)
#endif
/** \ingroup deprecated_items
\deprecated
This function modifies the \c timsk register.
The value you pass via \c ints is device specific. */
static __inline__ void timer_enable_int (unsigned char ints)
{
#ifdef TIMSK
TIMSK = ints;
#endif
}
/** \def INTERRUPT(signame)
\ingroup deprecated_items
\deprecated
Introduces an interrupt handler function that runs with global interrupts
initially enabled. This allows interrupt handlers to be interrupted.
As this macro has been used by too many unsuspecting people in the
past, it has been deprecated, and will be removed in a future
version of the library. Users who want to legitimately re-enable
interrupts in their interrupt handlers as quickly as possible are
encouraged to explicitly declare their handlers as described
\ref attr_interrupt "above".
*/
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
# define __INTR_ATTRS used, externally_visible
#else /* GCC < 4.1 */
# define __INTR_ATTRS used
#endif
#ifdef __cplusplus
#define INTERRUPT(signame) \
extern "C" void signame(void); \
void signame (void) __attribute__ ((interrupt,__INTR_ATTRS)); \
void signame (void)
#else
#define INTERRUPT(signame) \
void signame (void) __attribute__ ((interrupt,__INTR_ATTRS)); \
void signame (void)
#endif
/*@}*/
/**
\name Obsolete IO macros
Back in a time when AVR-GCC and avr-libc could not handle IO port
access in the direct assignment form as they are handled now, all
IO port access had to be done through specific macros that
eventually resulted in inline assembly instructions performing the
desired action.
These macros became obsolete, as reading and writing IO ports can
be done by simply using the IO port name in an expression, and all
bit manipulation (including those on IO ports) can be done using
generic C bit manipulation operators.
The macros in this group simulate the historical behaviour. While
they are supposed to be applied to IO ports, the emulation actually
uses standard C methods, so they could be applied to arbitrary
memory locations as well.
*/
/*@{*/
/**
\ingroup deprecated_items
\def inp(port)
\deprecated
Read a value from an IO port \c port.
*/
#define inp(port) (port)
/**
\ingroup deprecated_items
\def outp(val, port)
\deprecated
Write \c val to IO port \c port.
*/
#define outp(val, port) (port) = (val)
/**
\ingroup deprecated_items
\def inb(port)
\deprecated
Read a value from an IO port \c port.
*/
#define inb(port) (port)
/**
\ingroup deprecated_items
\def outb(port, val)
\deprecated
Write \c val to IO port \c port.
*/
#define outb(port, val) (port) = (val)
/**
\ingroup deprecated_items
\def sbi(port, bit)
\deprecated
Set \c bit in IO port \c port.
*/
#define sbi(port, bit) (port) |= (1 << (bit))
/**
\ingroup deprecated_items
\def cbi(port, bit)
\deprecated
Clear \c bit in IO port \c port.
*/
#define cbi(port, bit) (port) &= ~(1 << (bit))
/*@}*/
#endif /* _COMPAT_DEPRECATED_H_ */