Shop OBEX P1 Docs P2 Docs Learn Events
Locks Not working , Need to make mutilple acces secure — Parallax Forums

Locks Not working , Need to make mutilple acces secure

Igor_RastIgor_Rast Posts: 357
edited 2012-10-30 16:48 in Propeller 1
Tring to implement the locks in my program to be sure i am not reading the data the same time that I am writing to the same data

so to get it startet im trying with some blinky leds . blink 2 runs form a second cog , ( this is where I would normaly measure temperture and write it to rom )
and blinking a led 5 now

blink runs from my main cog , normaly this is reading and displaying the reading , ( now blinking led 6 )

it is both are suppose to wait for each other for exlusive accec . but they just blink

think the newcog doesnt know the lock but im not getting it , would like some help .

VAR 
  byte lock
long stack1[128]  
PUB Main

  lock:=locknew

  dira[led_5]~~                                {make Led output}
  dira[led_6]~~                                {make Led output}
 
  cognew(blink2 ( lock ),@stack1)    
  
  repeat
    blink
    
PUB blink 
    repeat until not lockset(lock)
       outa[led_6]~~
       waitcnt (clkfreq+ cnt)
       
       outa[led_6]~        
       lockclr(lock)
       waitcnt (clkfreq / 20+ cnt)
        
       
PUB blink2 (lok)   

  dira[led_5]~~    
     
    repeat
      repeat until not lockset(lok)            
        outa[led_5]~~
        waitcnt (clkfreq * 3+ cnt)
       
        outa[led_5]~ 
        lockclr(lok)    
        waitcnt (clkfreq*2 + cnt)


Comments

  • RossHRossH Posts: 5,463
    edited 2012-10-30 15:51
    Hi Igor_Rast

    You are not waiting for the lock. To wait for a lock you need to use code like:
    PUB blink 
        repeat 
    
           repeat until not lockset(lock)   ' <--- wait at this line till we get a lock
    
           outa[led_6]~~
           waitcnt (clkfreq+ cnt)
           
           outa[led_6]~        
           lockclr(lock)
           waitcnt (clkfreq / 20+ cnt)
    
    
    

    See the Propeller manual page 126, and remember that in Spin, indentation is critical.

    Ross.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-10-30 16:26
    Hi Rossh . Thanks for the advice , i fixed that . i was already reading the manula but there is where i couldent get clear how to share to lock with the newly started cog ,
    I moddified the code , but now i only have 1 blinking led .
    the idear was to get them to blink one at a time so , only the binking one may do it work , the other one needs to wait till tis finnished
    . think you could help me with the last mods to get it working ,
    VAR 
      byte lock
    long stack1[128]  
    PUB Main
    
      lock:=locknew
    
      dira[9..15]~~                                {make Led output}
     
      cognew(blink2 ,@stack1)    
      
      repeat
        blink    
    
    
    PUB blink 
        repeat 
    
           repeat until not lockset(lock)   ' <--- wait at this line till we get a lock
    
           outa[led_4]~~
           waitcnt (clkfreq+ cnt)
           
           outa[led_4]~        
           lockclr(lock)
           waitcnt (clkfreq / 2+ cnt)   
           
           
    PUB blink2   
    
        repeat 
    
           repeat until not lockset(lock)   ' <--- wait at this line till we get a lock
    
           outa[led_5]~~
           waitcnt (clkfreq+ cnt)
           
           outa[led_5]~        
           lockclr(lock)
           waitcnt (clkfreq / 20+ cnt)
    
  • kuronekokuroneko Posts: 3,623
    edited 2012-10-30 16:36
    dira for your blink2 cog isn't set (for output that is). Just add a dira[led_5]~~ at the start of the method.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-10-30 16:48
    Thanks man , its working now ,
Sign In or Register to comment.