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

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [FMTK/] [source/] [kernel/] [LockSemaphore.c] - Rev 23

Compare with Previous | Blame | View Log

// ============================================================================
//        __
//   \\__/ o\    (C) 2012-2016  Robert Finch, Stratford
//    \  __ /    All rights reserved.
//     \/_//     robfinch<remove>@finitron.ca
//       ||
//
// LockSemaphore.c
//
// This source file is free software: you can redistribute it and/or modify 
// it under the terms of the GNU Lesser General Public License as published 
// by the Free Software Foundation, either version 3 of the License, or     
// (at your option) any later version.                                      
//                                                                          
// This source file is distributed in the hope that it will be useful,      
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
// GNU General Public License for more details.                             
//                                                                          
// You should have received a copy of the GNU General Public License        
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
//                                                                          
// ============================================================================
//
pascal int LockSemaphore(int *sema, int retries)
{
    asm {
		ldi		r1,#1
		br		.0005
        lw      r1,32[bp]		 ; r1 = pointer to semaphore
		lw      r2,40[bp]		 ; r2 = #retries
.0001:
		tst		p0,r2			 ; timeout expired ?
p0.eq	mov		r1,r0			 ; if yes, return 0
p0.eq	br		.0005
        subui   r2,r2,#1		 ; decrement timeout
        lvwar   r3,[r1]			 ; load and reserve address
		tst		p0,r3
p0.lt   br      .0003            ; branch if free
        cmp     p0,r3,tr            ; test if already locked by this task
p0.eq	br		.0002
        ;chk     r3,r0,#256          ; check if locked by a valid task
.0003:
        swcr    tr,[r1]             ; try and lock it
p0.ne   br		.0001            ; lock failed, go try again
.0002:
        ldi     r1,#1
.0005:
    }
}
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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