// $Id: msp430hardware.h,v 1.1 2004/07/14 05:20:00 jwhui Exp $ /* "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement * is hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." */ // @author Vlado Handziski // @author Joe Polastre // @author Cory Sharp #ifndef _H_msp430hardware_h #define _H_msp430hardware_h #include #include #include "msp430regtypes.h" typedef uint8_t bool; #define FALSE 0 #define TRUE 1 // CPU memory-mapped register access will cause nesc to issue race condition // warnings. Race conditions are a significant conern when accessing CPU // memory-mapped registers, because they can change even while interrupts // are disabled. This means that the standard nesc tools for resolving race // conditions, atomic statements that disable interrupt handling, do not // resolve CPU register race conditions. So, CPU registers access must be // treated seriously and carefully. // The macro MSP430REG_NORACE allows individual modules to internally // redeclare CPU registers as norace, eliminating nesc's race condition // warnings for their access. This macro should only be used after the // specific CPU register use has been verified safe and correct. Example // use: // // module MyLowLevelModule // { // // ... // } // implementation // { // MSP430REG_NORACE(TACCTL0); // // ... // } #undef norace #define MSP430REG_NORACE_EXPAND(type,name,addr) \ static volatile type name asm(#addr) #define MSP430REG_NORACE3(type,name,addr) \ MSP430REG_NORACE_EXPAND(type,name,addr) // MSP430REG_NORACE and MSP430REG_NORACE2 presume naming conventions among // type, name, and addr, which are defined in the local header // msp430regtypes.h and mspgcc's header io.h and its children. #define MSP430REG_NORACE2(rename,name) \ MSP430REG_NORACE3(TYPE_##name,rename,name##_) #define MSP430REG_NORACE(name) \ MSP430REG_NORACE3(TYPE_##name,name,name##_) // redefine ugly defines from msp-gcc #ifndef DONT_REDEFINE_SR_FLAGS #undef C #undef Z #undef N #undef V #undef GIE #undef CPUOFF #undef OSCOFF #undef SCG0 #undef SCG1 #undef LPM0_bits #undef LPM1_bits #undef LPM2_bits #undef LPM3_bits #undef LPM4_bits #define SR_C 0x0001 #define SR_Z 0x0002 #define SR_N 0x0004 #define SR_V 0x0100 #define SR_GIE 0x0008 #define SR_CPUOFF 0x0010 #define SR_OSCOFF 0x0020 #define SR_SCG0 0x0040 #define SR_SCG1 0x0080 #define LPM0_bits SR_CPUOFF #define LPM1_bits SR_SCG0+SR_CPUOFF #define LPM2_bits SR_SCG1+SR_CPUOFF #define LPM3_bits SR_SCG1+SR_SCG0+SR_CPUOFF #define LPM4_bits SR_SCG1+SR_SCG0+SR_OSCOFF+SR_CPUOFF #endif//DONT_REDEFINE_SR_FLAGS #ifdef interrupt #undef interrupt #endif #ifdef wakeup #undef wakeup #endif #ifdef signal #undef signal #endif // The signal attribute has opposite meaning in msp430-gcc than in avr-gcc #define TOSH_SIGNAL(signame) \ void sig_##signame() __attribute__((interrupt (signame), wakeup, spontaneous, C)) // TOSH_INTERRUPT allows nested interrupts #define TOSH_INTERRUPT(signame) \ void isr_##signame() __attribute__((interrupt (signame), signal, wakeup, spontaneous, C)) void TOSH_wait(void) { nop(); nop(); } #define TOSH_CYCLE_TIME_NS 250 void TOSH_wait_250ns(void) { // 4 MHz clock == 2 cycles per 250 ns nop(); nop(); } void TOSH_uwait(uint16_t u) { uint16_t i; for (i=0; i