OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [FMTK/] [source/] [kernel/] [LockSemaphore.c] - Blame information for rev 23

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2016  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// LockSemaphore.c
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//                                                                          
23
// ============================================================================
24
//
25
pascal int LockSemaphore(int *sema, int retries)
26
{
27
    asm {
28
                ldi             r1,#1
29
                br              .0005
30
        lw      r1,32[bp]                ; r1 = pointer to semaphore
31
                lw      r2,40[bp]                ; r2 = #retries
32
.0001:
33
                tst             p0,r2                    ; timeout expired ?
34
p0.eq   mov             r1,r0                    ; if yes, return 0
35
p0.eq   br              .0005
36
        subui   r2,r2,#1                 ; decrement timeout
37
        lvwar   r3,[r1]                  ; load and reserve address
38
                tst             p0,r3
39
p0.lt   br      .0003            ; branch if free
40
        cmp     p0,r3,tr            ; test if already locked by this task
41
p0.eq   br              .0002
42
        ;chk     r3,r0,#256          ; check if locked by a valid task
43
.0003:
44
        swcr    tr,[r1]             ; try and lock it
45
p0.ne   br              .0001            ; lock failed, go try again
46
.0002:
47
        ldi     r1,#1
48
.0005:
49
    }
50
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.