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.

Functions__monitor int get_lock(void){if (the_lock == 0){/* Success, we managed to lock the lock. */the_lock = 1;return 1;}else{/* Failure, someone else has locked the lock. */return 0;}}/* release_lock -- Unlock the lock. */__monitor void release_lock(void){the_lock = 0;}The following is an example of a program fragment that uses the semaphore:void my_program(void){if (get_lock()){/* ... Do something ... */}}/* When done, release the lock. */release_lock();Example of implementing a semaphore in <strong>C++</strong>In <strong>C++</strong>, it is common to implement small methods with the intention that they should beinlined. However, the <strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong> does not support inlining offunctions and methods that are declared using the __monitor keyword.In the following example in <strong>C++</strong>, an auto object is used for controlling the monitorblock, which uses intrinsic functions instead of the __monitor keyword.#include volatile long tick_count = 0;Part 1. Using the compiler27

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

Saved successfully!

Ooh no, something went wrong!