hello

Dependents:   nespresso_demo nespresso_endpoint EnvoyNespressoEndpointColorDetectorV2

Fork of nsdl by Robert Taylor

Committer:
bjblazkowicz
Date:
Mon Jul 14 12:33:59 2014 +0000
Revision:
2:05e4cd1a1542
Parent:
0:f6e4e1bbb3fe
WIP - registration is broken in this commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GeofferyOmlette 0:f6e4e1bbb3fe 1 /* This file has been prepared for Doxygen automatic documentation generation.*/
GeofferyOmlette 0:f6e4e1bbb3fe 2 /*! \file *********************************************************************
GeofferyOmlette 0:f6e4e1bbb3fe 3 *
GeofferyOmlette 0:f6e4e1bbb3fe 4 * \brief This file implements some macros that makes the IAR C-compiler and
GeofferyOmlette 0:f6e4e1bbb3fe 5 * avr-gcc work with the same code base for the AVR architecture.
GeofferyOmlette 0:f6e4e1bbb3fe 6 *
GeofferyOmlette 0:f6e4e1bbb3fe 7 * \par Documentation
GeofferyOmlette 0:f6e4e1bbb3fe 8 * For comprehensive code documentation, supported compilers, compiler
GeofferyOmlette 0:f6e4e1bbb3fe 9 * settings and supported devices see readme.html
GeofferyOmlette 0:f6e4e1bbb3fe 10 *
GeofferyOmlette 0:f6e4e1bbb3fe 11 * \author
GeofferyOmlette 0:f6e4e1bbb3fe 12 * Atmel Corporation: http://www.atmel.com \n
GeofferyOmlette 0:f6e4e1bbb3fe 13 * Support email: avr@atmel.com
GeofferyOmlette 0:f6e4e1bbb3fe 14 *
GeofferyOmlette 0:f6e4e1bbb3fe 15 * $Revision: 613 $
GeofferyOmlette 0:f6e4e1bbb3fe 16 * $Date: 2006-04-07 14:40:07 +0200 (fr, 07 apr 2006) $ \n
GeofferyOmlette 0:f6e4e1bbb3fe 17 *
GeofferyOmlette 0:f6e4e1bbb3fe 18 * Copyright (c) 2008, Atmel Corporation All rights reserved.
GeofferyOmlette 0:f6e4e1bbb3fe 19 *
GeofferyOmlette 0:f6e4e1bbb3fe 20 * Redistribution and use in source and binary forms, with or without
GeofferyOmlette 0:f6e4e1bbb3fe 21 * modification, are permitted provided that the following conditions are met:
GeofferyOmlette 0:f6e4e1bbb3fe 22 *
GeofferyOmlette 0:f6e4e1bbb3fe 23 * 1. Redistributions of source code must retain the above copyright notice,
GeofferyOmlette 0:f6e4e1bbb3fe 24 * this list of conditions and the following disclaimer.
GeofferyOmlette 0:f6e4e1bbb3fe 25 *
GeofferyOmlette 0:f6e4e1bbb3fe 26 * 2. Redistributions in binary form must reproduce the above copyright notice,
GeofferyOmlette 0:f6e4e1bbb3fe 27 * this list of conditions and the following disclaimer in the documentation
GeofferyOmlette 0:f6e4e1bbb3fe 28 * and/or other materials provided with the distribution.
GeofferyOmlette 0:f6e4e1bbb3fe 29 *
GeofferyOmlette 0:f6e4e1bbb3fe 30 * 3. The name of ATMEL may not be used to endorse or promote products derived
GeofferyOmlette 0:f6e4e1bbb3fe 31 * from this software without specific prior written permission.
GeofferyOmlette 0:f6e4e1bbb3fe 32 *
GeofferyOmlette 0:f6e4e1bbb3fe 33 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
GeofferyOmlette 0:f6e4e1bbb3fe 34 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
GeofferyOmlette 0:f6e4e1bbb3fe 35 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
GeofferyOmlette 0:f6e4e1bbb3fe 36 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
GeofferyOmlette 0:f6e4e1bbb3fe 37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
GeofferyOmlette 0:f6e4e1bbb3fe 38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
GeofferyOmlette 0:f6e4e1bbb3fe 39 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
GeofferyOmlette 0:f6e4e1bbb3fe 40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
GeofferyOmlette 0:f6e4e1bbb3fe 41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
GeofferyOmlette 0:f6e4e1bbb3fe 42 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
GeofferyOmlette 0:f6e4e1bbb3fe 43 ******************************************************************************/
GeofferyOmlette 0:f6e4e1bbb3fe 44
GeofferyOmlette 0:f6e4e1bbb3fe 45 #ifndef COMPILER_AVR_H
GeofferyOmlette 0:f6e4e1bbb3fe 46 #define COMPILER_AVR_H
GeofferyOmlette 0:f6e4e1bbb3fe 47
GeofferyOmlette 0:f6e4e1bbb3fe 48 //#include <stdint.h>
GeofferyOmlette 0:f6e4e1bbb3fe 49 #include <stdbool.h>
GeofferyOmlette 0:f6e4e1bbb3fe 50 #include <stdlib.h>
GeofferyOmlette 0:f6e4e1bbb3fe 51
GeofferyOmlette 0:f6e4e1bbb3fe 52 /** This macro will protect the following code from interrupts.*/
GeofferyOmlette 0:f6e4e1bbb3fe 53 #define AVR_ENTER_CRITICAL_REGION( ) uint8_t volatile saved_sreg = SREG; \
GeofferyOmlette 0:f6e4e1bbb3fe 54 cli();
GeofferyOmlette 0:f6e4e1bbb3fe 55
GeofferyOmlette 0:f6e4e1bbb3fe 56 /** This macro must always be used in conjunction with AVR_ENTER_CRITICAL_REGION
GeofferyOmlette 0:f6e4e1bbb3fe 57 so that interrupts are enabled again.*/
GeofferyOmlette 0:f6e4e1bbb3fe 58 #define AVR_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg;
GeofferyOmlette 0:f6e4e1bbb3fe 59
GeofferyOmlette 0:f6e4e1bbb3fe 60 #if defined( __ICCAVR__ )
GeofferyOmlette 0:f6e4e1bbb3fe 61
GeofferyOmlette 0:f6e4e1bbb3fe 62 #include <inavr.h>
GeofferyOmlette 0:f6e4e1bbb3fe 63 #include <ioavr.h>
GeofferyOmlette 0:f6e4e1bbb3fe 64 #include <intrinsics.h>
GeofferyOmlette 0:f6e4e1bbb3fe 65 #include <pgmspace.h>
GeofferyOmlette 0:f6e4e1bbb3fe 66
GeofferyOmlette 0:f6e4e1bbb3fe 67 #ifndef __HAS_ELPM__
GeofferyOmlette 0:f6e4e1bbb3fe 68 #define _MEMATTR __flash
GeofferyOmlette 0:f6e4e1bbb3fe 69 #else /* __HAS_ELPM__ */
GeofferyOmlette 0:f6e4e1bbb3fe 70 #define _MEMATTR __farflash
GeofferyOmlette 0:f6e4e1bbb3fe 71 #endif /* __HAS_ELPM__ */
GeofferyOmlette 0:f6e4e1bbb3fe 72
GeofferyOmlette 0:f6e4e1bbb3fe 73 /**
GeofferyOmlette 0:f6e4e1bbb3fe 74 Perform a delay of \c us microseconds.
GeofferyOmlette 0:f6e4e1bbb3fe 75
GeofferyOmlette 0:f6e4e1bbb3fe 76 The macro F_CPU is supposed to be defined to a constant defining the CPU
GeofferyOmlette 0:f6e4e1bbb3fe 77 clock frequency (in Hertz).
GeofferyOmlette 0:f6e4e1bbb3fe 78
GeofferyOmlette 0:f6e4e1bbb3fe 79 The maximal possible delay is 262.14 ms / F_CPU in MHz.
GeofferyOmlette 0:f6e4e1bbb3fe 80
GeofferyOmlette 0:f6e4e1bbb3fe 81 \note For the IAR compiler, currently F_CPU must be a
GeofferyOmlette 0:f6e4e1bbb3fe 82 multiple of 1000000UL (1 MHz).
GeofferyOmlette 0:f6e4e1bbb3fe 83 */
GeofferyOmlette 0:f6e4e1bbb3fe 84 #define delay_us( us ) ( __delay_cycles( ( F_CPU / 1000000UL ) * ( us ) ) )
GeofferyOmlette 0:f6e4e1bbb3fe 85
GeofferyOmlette 0:f6e4e1bbb3fe 86 /*
GeofferyOmlette 0:f6e4e1bbb3fe 87 * Some preprocessor magic to allow for a header file abstraction of
GeofferyOmlette 0:f6e4e1bbb3fe 88 * interrupt service routine declarations for the IAR compiler. This
GeofferyOmlette 0:f6e4e1bbb3fe 89 * requires the use of the C99 _Pragma() directive (rather than the
GeofferyOmlette 0:f6e4e1bbb3fe 90 * old #pragma one that could not be used as a macro replacement), as
GeofferyOmlette 0:f6e4e1bbb3fe 91 * well as two different levels of preprocessor concetanations in
GeofferyOmlette 0:f6e4e1bbb3fe 92 * order to do both, assign the correct interrupt vector name, as well
GeofferyOmlette 0:f6e4e1bbb3fe 93 * as construct a unique function name for the ISR.
GeofferyOmlette 0:f6e4e1bbb3fe 94 *
GeofferyOmlette 0:f6e4e1bbb3fe 95 * Do *NOT* try to reorder the macros below, or you'll suddenly find
GeofferyOmlette 0:f6e4e1bbb3fe 96 * out about all kinds of IAR bugs...
GeofferyOmlette 0:f6e4e1bbb3fe 97 */
GeofferyOmlette 0:f6e4e1bbb3fe 98 #define PRAGMA(x) _Pragma( #x )
GeofferyOmlette 0:f6e4e1bbb3fe 99 #define ISR(vec) PRAGMA( vector=vec ) __interrupt void handler_##vec(void)
GeofferyOmlette 0:f6e4e1bbb3fe 100 #define sei( ) (__enable_interrupt( ))
GeofferyOmlette 0:f6e4e1bbb3fe 101 #define cli( ) (__disable_interrupt( ))
GeofferyOmlette 0:f6e4e1bbb3fe 102
GeofferyOmlette 0:f6e4e1bbb3fe 103 #define nop( ) (__no_operation())
GeofferyOmlette 0:f6e4e1bbb3fe 104
GeofferyOmlette 0:f6e4e1bbb3fe 105 #define watchdog_reset( ) (__watchdog_reset( ))
GeofferyOmlette 0:f6e4e1bbb3fe 106
GeofferyOmlette 0:f6e4e1bbb3fe 107
GeofferyOmlette 0:f6e4e1bbb3fe 108 #define INLINE PRAGMA( inline=forced ) static
GeofferyOmlette 0:f6e4e1bbb3fe 109
GeofferyOmlette 0:f6e4e1bbb3fe 110 #define FLASH_DECLARE(x) _MEMATTR x
GeofferyOmlette 0:f6e4e1bbb3fe 111 #define FLASH_STRING(x) ((_MEMATTR const char *)(x))
GeofferyOmlette 0:f6e4e1bbb3fe 112 #define FLASH_STRING_T char const _MEMATTR *
GeofferyOmlette 0:f6e4e1bbb3fe 113 #define FLASH_BYTE_ARRAY_T uint8_t const _MEMATTR *
GeofferyOmlette 0:f6e4e1bbb3fe 114 #define PGM_READ_BYTE(x) *(x)
GeofferyOmlette 0:f6e4e1bbb3fe 115 #define PGM_READ_WORD(x) *(x)
GeofferyOmlette 0:f6e4e1bbb3fe 116
GeofferyOmlette 0:f6e4e1bbb3fe 117 #define SHORTENUM /**/
GeofferyOmlette 0:f6e4e1bbb3fe 118
GeofferyOmlette 0:f6e4e1bbb3fe 119 #elif defined( __GNUC__ )
GeofferyOmlette 0:f6e4e1bbb3fe 120
GeofferyOmlette 0:f6e4e1bbb3fe 121 #include <avr/io.h>
GeofferyOmlette 0:f6e4e1bbb3fe 122 #include <avr/interrupt.h>
GeofferyOmlette 0:f6e4e1bbb3fe 123 #include <avr/pgmspace.h>
GeofferyOmlette 0:f6e4e1bbb3fe 124 #include <util/delay.h>
GeofferyOmlette 0:f6e4e1bbb3fe 125
GeofferyOmlette 0:f6e4e1bbb3fe 126 #define delay_us( us ) (_delay_us( us ))
GeofferyOmlette 0:f6e4e1bbb3fe 127
GeofferyOmlette 0:f6e4e1bbb3fe 128 #define INLINE static inline
GeofferyOmlette 0:f6e4e1bbb3fe 129
GeofferyOmlette 0:f6e4e1bbb3fe 130 #define nop() do { __asm__ __volatile__ ("nop"); } while (0)
GeofferyOmlette 0:f6e4e1bbb3fe 131
GeofferyOmlette 0:f6e4e1bbb3fe 132 #define MAIN_TASK_PROLOGUE int
GeofferyOmlette 0:f6e4e1bbb3fe 133
GeofferyOmlette 0:f6e4e1bbb3fe 134
GeofferyOmlette 0:f6e4e1bbb3fe 135 #define MAIN_TASK_EPILOGUE() return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 136
GeofferyOmlette 0:f6e4e1bbb3fe 137 #define SHORTENUM __attribute__ ((packed))
GeofferyOmlette 0:f6e4e1bbb3fe 138
GeofferyOmlette 0:f6e4e1bbb3fe 139 #else
GeofferyOmlette 0:f6e4e1bbb3fe 140 #error Compiler not supported.
GeofferyOmlette 0:f6e4e1bbb3fe 141 #endif
GeofferyOmlette 0:f6e4e1bbb3fe 142
GeofferyOmlette 0:f6e4e1bbb3fe 143 #endif
GeofferyOmlette 0:f6e4e1bbb3fe 144