Contiki-NG
msp430-def.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 
30 #ifndef MSP430_DEF_H_
31 #define MSP430_DEF_H_
32 
33 #ifdef __IAR_SYSTEMS_ICC__
34 #include <intrinsics.h>
35 #include <in430.h>
36 #include <msp430.h>
37 #define dint() __disable_interrupt()
38 #define eint() __enable_interrupt()
39 #define __MSP430__ 1
40 #define CC_CONF_INLINE
41 
42 #else /* __IAR_SYSTEMS_ICC__ */
43 
44 #ifdef __MSPGCC__
45 #include <msp430.h>
46 #include <legacymsp430.h>
47 #else /* __MSPGCC__ */
48 #include <io.h>
49 #include <signal.h>
50 #if !defined(MSP430_MEMCPY_WORKAROUND) && (__GNUC__ < 4)
51 #define MSP430_MEMCPY_WORKAROUND 1
52 #endif
53 #endif /* __MSPGCC__ */
54 
55 #define CC_CONF_INLINE inline
56 
57 #endif /* __IAR_SYSTEMS_ICC__ */
58 
59 /* Master interrupt state representation data type */
60 #define INT_MASTER_CONF_STATUS_DATATYPE __istate_t
61 
62 #ifndef BV
63 #define BV(x) (1 << x)
64 #endif
65 
66 #include <stdint.h>
67 
68 /* These names are deprecated, use C99 names. */
69 typedef uint8_t u8_t;
70 typedef uint16_t u16_t;
71 typedef uint32_t u32_t;
72 typedef int32_t s32_t;
73 
74 /* Types for clocks and uip_stats */
75 typedef unsigned short uip_stats_t;
76 typedef unsigned long clock_time_t;
77 typedef long off_t;
78 
79 /* Our clock resolution, this is the same as Unix HZ. */
80 #define CLOCK_CONF_SECOND 128UL
81 
82 /* Use 16-bit rtimer (default in Contiki-NG is 32) */
83 #define RTIMER_CONF_CLOCK_SIZE 2
84 
85 typedef int spl_t;
86 spl_t splhigh_(void);
87 
88 #define splhigh() splhigh_()
89 #ifdef __IAR_SYSTEMS_ICC__
90 #define splx(sr) __bis_SR_register(sr)
91 #else
92 #define splx(sr) __asm__ __volatile__("bis %0, r2" : : "r" (sr))
93 #endif
94 
95 /* Workaround for bug in msp430-gcc compiler */
96 #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
97 #ifndef memcpy
98 #include <string.h>
99 
100 void *w_memcpy(void *out, const void *in, size_t n);
101 #define memcpy(dest, src, count) w_memcpy(dest, src, count)
102 
103 void *w_memset(void *out, int value, size_t n);
104 #define memset(dest, value, count) w_memset(dest, value, count)
105 
106 #endif /* memcpy */
107 #endif /* __GNUC__ && __MSP430__ && MSP430_MEMCPY_WORKAROUND */
108 
109 #define memory_barrier() asm volatile("" : : : "memory")
110 
111 #define MSP430_REQUIRE_CPUON 0
112 #define MSP430_REQUIRE_LPM1 1
113 #define MSP430_REQUIRE_LPM2 2
114 #define MSP430_REQUIRE_LPM3 3
115 
116 /* Platform-specific checksum implementation */
117 #define UIP_ARCH_IPCHKSUM 1
118 
119 #define BAUD2UBR(baud) ((F_CPU/baud))
120 
121 void msp430_add_lpm_req(int req);
122 void msp430_remove_lpm_req(int req);
123 void msp430_cpu_init(void); /* Rename to cpu_init() later! */
124 void msp430_sync_dco(void);
125 #define cpu_init() msp430_cpu_init()
126 void *sbrk(int);
127 
128 #endif /* MSP430_DEF_H_ */