11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Primitives for interrupts, concurrency, and OS-related programming/* Class for controlling critical blocks */class Mutex{public:Mutex (){_state = __get_interrupt_state();__disable_interrupt();}~Mutex (){__set_interrupt_state(_state);}private:__istate_t _state;};void f(){static long next_stop = 100;extern void do_stuff();long tick;/* A critical block */{Mutex m;/* Read volatile variable 'tick_count' in a safe wayand put the value in a local variable */}tick = tick_count;}if (tick >= next_stop){next_stop += 100;do_stuff();}<strong>C++</strong> AND SPECIAL FUNCTION TYPES<strong>C++</strong> member functions can be declared using special function types. However, interruptmember functions must be static. When calling a non-static member function, it must be28<strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong>Reference Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!