Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2005, Swedish Institute of Computer Science 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * @(#)$Id: hwconf.h,v 1.2 2010/01/25 23:12:09 anthony-a Exp $ 00032 */ 00033 #ifndef __HWCONF_H__ 00034 #define __HWCONF_H__ 00035 00036 #include "sys/cc.h" 00037 00038 #include <cc2430_sfr.h> 00039 00040 #define HWCONF_PIN(name, port, bit) \ 00041 static CC_INLINE void name##_SELECT() {P##port##SEL &= ~(1 << bit);} \ 00042 static CC_INLINE void name##_SELECT_IO() {P##port##SEL &= ~(1 << bit);} \ 00043 static CC_INLINE void name##_SELECT_PM() {P##port##SEL |= 1 << bit;} \ 00044 static CC_INLINE void name##_SET() {P##port##_##bit = 1; } \ 00045 static CC_INLINE void name##_CLEAR() {P##port##_##bit = 0; } \ 00046 static CC_INLINE unsigned char name##_READ() {return P##port##_##bit; } \ 00047 static CC_INLINE void name##_MAKE_OUTPUT() {P##port##DIR |= 1 << bit;} \ 00048 static CC_INLINE void name##_MAKE_INPUT() {P##port##DIR &= ~(1 << bit); } 00049 00050 #define HWCONF_IRQ_XXX(name, port, bit) \ 00051 static CC_INLINE void name##_ENABLE_IRQ() { \ 00052 if ( port == 2 ) { PICTL |= P2IEN; p2ien |= 1<<bit; IEN2 |= P2IE; } \ 00053 if (( port == 0) && ( bit <4)) { PICTL |= P0IENL; p0ien |= 1<<bit; IEN1 |= P0IE; } \ 00054 if ((port == 0) && ( bit >=4)) { PICTL |= P0IENH; p0ien |= 1<<bit; IEN1 |= P0IE; } \ 00055 if ( port == 1) { P##port##IEN |= 1 << bit; IEN2 |= P1IE; } \ 00056 } \ 00057 static CC_INLINE void name##_DISABLE_IRQ() { \ 00058 if ( port == 2 ) { \ 00059 p2ien &= ~(1<<bit); \ 00060 if (p2ien==0) PICTL &= ~P2IEN; \ 00061 } \ 00062 if (( port == 0) && ( bit <4)) { \ 00063 p0ien &= ~(1<<bit); \ 00064 if ((p0ien&0xf)==0) PICTL &= ~P0IENL; \ 00065 } \ 00066 if (( port == 0) && ( bit >=4)) { \ 00067 p0ien &= ~(1<<bit); \ 00068 if ((p0ien&0xf0)==0) PICTL &= ~P0IENH; \ 00069 } \ 00070 if ( port == 1) { P##port##IEN &= ~(1 << bit); } \ 00071 } \ 00072 static CC_INLINE int name##_IRQ_ENABLED() {return P##port##IEN & (1 << bit);} \ 00073 static CC_INLINE int name##_CHECK_IRQ() {return P##port##IFG & (1 << bit);} \ 00074 static CC_INLINE void name##_IRQ_FLAG_OFF() { \ 00075 P##port##IFG &= ~(1 << bit); \ 00076 if (port == 0) {IRCON &= ~P0IF;} \ 00077 else {IRCON2 &= ~P##port##IF;} \ 00078 } 00079 00080 #define HWCONF_IRQ(name, port, bit) \ 00081 static CC_INLINE void name##_ENABLE_IRQ() { \ 00082 if ( port == 1) { P##port##IEN |= 1 << bit; } \ 00083 } \ 00084 static CC_INLINE void name##_DISABLE_IRQ() { \ 00085 if ( port == 1) { P##port##IEN &= ~(1 << bit); } \ 00086 } \ 00087 static CC_INLINE int name##_IRQ_ENABLED() {return P##port##IEN & (1 << bit);} \ 00088 static CC_INLINE int name##_CHECK_IRQ() {return P##port##IFG & (1 << bit);} \ 00089 static CC_INLINE int name##_IRQ_PORT() {return IRQ_PORT##port;} 00090 00091 #define HWCONF_PORT_0_IRQ(name, bit) \ 00092 static CC_INLINE void name##_ENABLE_IRQ() { \ 00093 if ( bit <4 ) { PICTL |= P0IENL; p0ien |= 1<<bit; IEN1 |= P0IE; } \ 00094 if ( bit >=4 ) { PICTL |= P0IENH; p0ien |= 1<<bit; IEN1 |= P0IE; } \ 00095 } \ 00096 static CC_INLINE void name##_DISABLE_IRQ() { \ 00097 if ( bit <4) { \ 00098 p0ien &= ~(1<<bit); \ 00099 if ((p0ien&0xf)==0) PICTL &= ~P0IENL; \ 00100 } \ 00101 if ( bit >=4) { \ 00102 p0ien &= ~(1<<bit); \ 00103 if ((p0ien&0xf0)==0) PICTL &= ~P0IENH; \ 00104 } \ 00105 } \ 00106 static CC_INLINE int name##_IRQ_ENABLED() {return p0ien & (1 << bit);} \ 00107 static CC_INLINE void name##_IRQ_EDGE_SELECTD() {PICTL |= P0ICON;} \ 00108 static CC_INLINE void name##_IRQ_EDGE_SELECTU() {PICTL &= ~P0ICON;} \ 00109 static CC_INLINE int name##_CHECK_IRQ() {return P0IFG & (1 << bit);} \ 00110 static CC_INLINE void name##_IRQ_FLAG_OFF() { \ 00111 IRCON_P0IF = 0; \ 00112 P0IFG = 0; \ 00113 } 00114 00115 #define HWCONF_PORT_1_IRQ(name, bit) \ 00116 static CC_INLINE void name##_ENABLE_IRQ() { P1IEN |= 1 << bit; IEN2 |= P1IE; } \ 00117 static CC_INLINE void name##_DISABLE_IRQ() { \ 00118 P1IEN &= ~(1 << bit); \ 00119 if (P1IEN == 0) { IEN2 &= ~P1IE; } \ 00120 } \ 00121 static CC_INLINE int name##_IRQ_ENABLED() { return P1IEN & (1 << bit); } \ 00122 static CC_INLINE void name##_IRQ_EDGE_SELECTD() {PICTL |= P1ICON;} \ 00123 static CC_INLINE void name##_IRQ_EDGE_SELECTU() {PICTL &= ~P1ICON;} \ 00124 static CC_INLINE int name##_CHECK_IRQ() { return P1IFG & (1 << bit); } \ 00125 static CC_INLINE void name##_IRQ_FLAG_OFF() { \ 00126 IRCON2_P1IF = 0; \ 00127 P1IFG = 0; \ 00128 } 00129 00130 #define HWCONF_PORT_2_IRQ(name, bit) \ 00131 static CC_INLINE void name##_ENABLE_IRQ() { \ 00132 PICTL |= P2IEN; \ 00133 p2ien |= 1<<bit; \ 00134 IEN2 |= P2IE; \ 00135 } \ 00136 static CC_INLINE void name##_DISABLE_IRQ() { \ 00137 p2ien &= ~(1<<bit); \ 00138 if (p2ien==0) { PICTL &= ~P2IEN; IEN2 &= ~P2IE; } \ 00139 } \ 00140 static CC_INLINE int name##_IRQ_ENABLED() {return p2ien & (1 << bit);} \ 00141 static CC_INLINE void name##_IRQ_EDGE_SELECTD() {PICTL |= P2ICON;} \ 00142 static CC_INLINE void name##_IRQ_EDGE_SELECTU() {PICTL &= ~P2ICON;} \ 00143 static CC_INLINE int name##_CHECK_IRQ() {return P2IFG & (1 << bit);} \ 00144 static CC_INLINE void name##_IRQ_FLAG_OFF() { \ 00145 IRCON2_P2IF = 0; \ 00146 P2IFG = 0; \ 00147 } 00148 00149 #endif /* __HWCONF_H__ */