Contiki 2.5
msp430def.h
1 /*
2  * Copyright (c) 2007, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)$Id: msp430def.h,v 1.5 2010/03/19 14:50:07 joxe Exp $
30  */
31 
32 #ifndef MSP430DEF_H
33 #define MSP430DEF_H
34 
35 #if defined(__IAR_SYSTEMS_ICC__) || defined(__MSPGCC__)
36 #include <msp430.h>
37 #if __MSPGCC__
38 #include <legacymsp430.h>
39 #endif /* __MSPGCC__ */
40 #else
41 #include <io.h>
42 #include <signal.h>
43 #endif
44 
45 #ifdef __IAR_SYSTEMS_ICC__
46 #include <intrinsics.h>
47 #include <in430.h>
48 #define dint() __disable_interrupt()
49 #define eint() __enable_interrupt()
50 #define __MSP430F1611__ 1
51 #define __MSP430__ 1
52 #define CC_CONF_INLINE
53 #define BV(x) (1 << x)
54 #else
55 #define CC_CONF_INLINE inline
56 #define MSP430_MEMCPY_WORKAROUND 1
57 #endif
58 
59 #ifdef HAVE_STDINT_H
60 #include <stdint.h>
61 #else
62 #ifndef uint8_t
63 typedef unsigned char uint8_t;
64 typedef unsigned short uint16_t;
65 typedef unsigned long uint32_t;
66 typedef signed char int8_t;
67 typedef short int16_t;
68 typedef long int32_t;
69 #endif
70 #endif /* !HAVE_STDINT_H */
71 
72 /* These names are deprecated, use C99 names. */
73 typedef uint8_t u8_t;
74 typedef uint16_t u16_t;
75 typedef uint32_t u32_t;
76 typedef int32_t s32_t;
77 
78 /* default DCOSYNCH Period is 30 seconds */
79 #ifdef DCOSYNCH_CONF_PERIOD
80 #define DCOSYNCH_PERIOD DCOSYNCH_CONF_PERIOD
81 #else
82 #define DCOSYNCH_PERIOD 30
83 #endif
84 
85 void msp430_cpu_init(void); /* Rename to cpu_init() later! */
86 void msp430_sync_dco(void);
87 
88 
89 #define cpu_init() msp430_cpu_init()
90 
91 void *sbrk(int);
92 
93 typedef int spl_t;
94 void splx_(spl_t);
95 spl_t splhigh_(void);
96 
97 #define splhigh() splhigh_()
98 #ifdef __IAR_SYSTEMS_ICC__
99 #define splx(sr) sr = __get_SR_register()
100 #else
101 #define splx(sr) __asm__ __volatile__("bis %0, r2" : : "r" (sr))
102 #endif
103 
104 /* Workaround for bug in msp430-gcc compiler */
105 #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
106 #ifndef memcpy
107 #include <string.h>
108 
109 void *w_memcpy(void *out, const void *in, size_t n);
110 #define memcpy(dest, src, count) w_memcpy(dest, src, count)
111 
112 /* #define memcpy(dest, src, count) do { \ */
113 /* if(count == 2) { \ */
114 /* *((uint8_t *)dest) = *((uint8_t *)src); \ */
115 /* *((uint8_t *)dest + 1) = *((uint8_t *)src + 1); \ */
116 /* } else { \ */
117 /* memcpy(dest, src, count); \ */
118 /* } \ */
119 /* } while(0) */
120 
121 void *w_memset(void *out, int value, size_t n);
122 #define memset(dest, value, count) w_memset(dest, value, count)
123 
124 /* #define memset(dest, value, count) do { \ */
125 /* if(count == 2) { \ */
126 /* *((uint8_t *)dest) = (uint8_t)value; \ */
127 /* *((uint8_t *)dest + 1) = (uint8_t)value; \ */
128 /* } else { \ */
129 /* memset(dest, value, count); \ */
130 /* } \ */
131 /* } while(0) */
132 #endif /* memcpy */
133 #endif /* __GNUC__ && __MSP430__ && MSP430_MEMCPY_WORKAROUND */
134 
135 
136 /* Moved from the msp430.h file with other msp430 related defines */
137 
138 #ifdef F_CPU
139 #define MSP430_CPU_SPEED F_CPU
140 #else
141 #define MSP430_CPU_SPEED 2457600UL
142 #endif
143 
144 #define MSP430_REQUIRE_CPUON 0
145 #define MSP430_REQUIRE_LPM1 1
146 #define MSP430_REQUIRE_LPM2 2
147 #define MSP430_REQUIRE_LPM3 3
148 
149 void msp430_add_lpm_req(int req);
150 void msp430_remove_lpm_req(int req);
151 
152 #endif /* MSP430DEF_H */