Implementing a semaphore in user mode code

Implementing a semaphore in user mode code

Post by David Worthe » Tue, 19 Aug 2003 23:43:28



Hi All,
I have a situation where I need to implement a semaphore in user mode code,
meaning I cannot disable interrupts. Does anyone have any code snippets to
share that will work on a Coldfire processor in user mode?
Regards, David
 
 
 

Implementing a semaphore in user mode code

Post by 42Bastian Schi » Wed, 20 Aug 2003 13:24:50


On Mon, 18 Aug 2003 10:43:28 -0400, "David Worthen"


>Hi All,
>I have a situation where I need to implement a semaphore in user mode code,
>meaning I cannot disable interrupts. Does anyone have any code snippets to
>share that will work on a Coldfire processor in user mode?

Depends on the ColdFire architecture, V4 implemenents the "tas" opcode
from the 68k which allows semaphores.

But you might do it with addq/subq

sema: dc.l -1

busy_wait:
        addq.l  #1,sema
        beq.s   got_sema
        subq.l  #1,sema         ; restore "old" value
        bra.s   busy_wait

got_sema:
        ;; critical code
        ;; ...

        ;; return semaphore
        subq.l  #1,sema         ; set to -1

---
42Bastian



 
 
 

1. implement a semaphore?...

Hi:

I have a MC332 running at 16 Mhz.  

(1) The set up:

I have the periodic timer interrupt (PIT) interrupting every 977
microseconds (~1000 Hz).  In every interrupt I do increment a
number of "tick" counter variables relative to the 977 microsecond
PIT interrupt.  Later in the code I have 'if' staments wich
execute every time the corresponding tick counter reaches a number
close to say 50 Hz, 25 Hz, 5 Hz since I am attempting to execute
different tasks at different rates asynchronously.

(2) The problem:

Since I am accessing a common database, I am afraid that I have
(eventually) some memory access conflicts where a 50 Hz
'if' statement reads from memory and an interrupt occurs.  I wonder
if I can attribute some quasi-periodic misbehavior or data
corruption to this time conflicts?  Basically, I am concerned with
read-modify-write or just write-to-memory type of conflicts.

(3) The question:

My question then boils down to how can I implement a fire-sure
data access semaphore scheme?  I have tried several schemes, but
have been unsuccessful.  May be the solution is simple and in front
of my nose, but I do not see it!

(4) Conclussion:

In any event, I am sure that I am  reinventing the wheel in
this one case, and I'll appreciate any help in this regard!

Best whishes:

Miguel

--
Miguel Simon

Research Assistant
School of Aerospace and Mechanical Engineering
University of Oklahoma



http://www.ecn.ou.edu/~msimon/main.html
Ph:     (405) 325-5052
Fax:    (405) 325-1088

2. URGENT: Money98 and Windows 2000 !?

3. user mode / supervisor mode on 68000

4. BC45, Powerpack , Thunking and BBS

5. How to detect User Mode

6. Java Vectors and IDL

7. Detecting supervisor/user mode

8. How to detect User Mode on a CPU32+ ???

9. Superviser/User mode useless for Multitasking?

10. User/Supervisor Mode

11. How does one implement VM in a 68000?

12. Help: about MC68MH360 implement BRI ISDN U interface