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