/* ****************SPIN.C******** Spinlock semaphores for the MC68HC11EVB This example accompanies the book "Embedded Microcomputer Systems: Real Time Interfacing", Brooks-Cole, copyright (c) 2000, Jonathan W. Valvano 7/6/99 Interface between the TExaS simulator running a MC68HC11 EVB with ICC11 freeware compiler TExaS Copyright 1999 by Jonathan W. Valvano for more information about ICC11 see http://www.imagecraft.com You may use this file without restrictions */ void Wait(int *semaphore){ asm(" sei"); /* Test and set is atomic */ PORTC|=0x10; while((*semaphore)<=0){ /* disabled */ asm(" cli\n" /* disabled */ " nop\n" /* enabled */ " sei");} /* enabled */ (*semaphore)--; /* disabled */ PORTC&=0xEF; asm(" cli"); /* disabled */ } /* enabled */ void Signal(int *semaphore){ asm(" sei"); /* make increment is atomic */ PORTC|=0x20; (*semaphore)++; PORTC&=0xDF; asm(" cli"); }