OBEX examples with locks
frank freedman
Posts: 1,983
in Propeller 1
Can anyone recommend a few good examples of OBEX items using Locks?
Thanks
FF
Thanks
FF
Comments
Are you sure you need them Frank?
-Phil
Actually I wanted to be able to set off a timing generator and enable only one pass per request, have n ADCs controlled by the timing generator collecting data and storing in cog at PASM speed, have each write their data to either a shared buffer or separate buffer for transfer out to another cog or external process. Currently I have gotten this working using I/O lines but after going through the book sanandak has up on spin/pasm/c, I thought I would give this a try. Maybe save an I/O pin or two. He shows a good example of this, but I have to look harder at what he is doing on the PASM side.
Not need, just want to understand how to use them at the bit level in PASM. An inquiring mind wants to know (at least while the gray matter can still gain more than it looses......)
Thanks,
FF
http://forums.parallax.com/discussion/109727/does-anyone-use-locks/p1
Following up on Phil's comment, one OBEX object that implements locks for the i2c buss is Kye's, I2C_ROMEngine. http://obex.parallax.com/object/23
It is specifically for eeprom. Multiple cogs can access the eeprom, mediated by locks to prevent collisions. A couple of things about it. All of the reads and writes are funneled through the readpage and writepage methods, and those commence by waiting for the assigned lock to be free, and finish by clearing it. The start method either uses lock that is passed in by the caller, or, if the entry parameter is -1, it checks out a newlock. Notice that both the pin numbers and also the lock number are stored in the DAT area, so that one instance of the object shares those, a system-wide resource. The Start method should only be called once, usually at the top level, and the object should be declared in every other object that needs to use the resource, whether or not they will be launched into a separate cog. These other objects should not call the Start method, but they have access to all the methods to read and write data due to the shared nature of DAT variables.
I use my own i2c object to sort out access to hardware devices with the same considerations, setlock before the start, and clearlock after the stop for each transaction, where several cogs have to hit the same i2c bus, a system resource with shared DAT pins and lock. Greatly simplifies the code and its development.
(Is there any sort of catalog/index of the objects in OBEX?) Asking if anyone knew of good examples in OBEX was a way to circumvent having to look at every object to see if it used a lock and how. If there was a downloadable image of the OBEX not zipped or anything it could at least be searched. Is there any sort of catalog for this?
So, now to check the examples cited.
Thanks to all
Been asked for many times. No such luck as of yet. You'd think, for all the times people have asked for such a thing, someone would have created an HTML scraper capable of downloading every object in the OBEX by now.
https://david.zemon.name/downloads/complete_obex.zip
The compressed zip is a little over 50 MB and the expand zip is a little over 60 MB. Not too shabby overall. Only took about 30 seconds to download the whole thing over my ~30 Mbps connection.
UPDATE:
Git repo is online https://github.com/DavidZemon/ObexDownloader
I haven't been able to reproduce your index file. I'd like to get this script running on a schedule from CI server so we have always-up-to-date OBEX downloads. How did you get the file?
Okay, thanks. That helps. I'll see if I can make it work from that.
That's a reasonable problem... I think I'll update the script to unzip all the archives and, before the script completes, compress the entire folder into a single archive. That should make the whole thing far more usable.
E.g. a serial-object that is used to show text on a terminal from different cogs sending at the same time:
- With no locks: the serial data gets corrupted on bit level, the terminal receives no vaild data bytes.
- with locks on byte level: the communication works, but you get a wild mix of characters from all sending cogs.
- with locks on string level: you see a whole strings from one of the cogs on the terminal, but still not usable if you need several strings, or strings with decimal numbers for a message.
- with locks on CarriagReturn characters: shows full lines from one cog on the terminal, but not usable if you need several lines to show together.
What I want to say: On what level you need to lock the serial object to one of the cogs depends a lot on the application, and this can only be decided by the one that programs the application, and not by the driver object.
The Serial object should be locked to one cog as long as necessary, but as short as possible. The other cogs are normally blocked while they wait to get the lock.
Andy
1Mbaud FullDuplexSerial (Fixed baud-rate)/asm_write_ex.spin: repeat while (lockset(lockId))
3-Axis CNC Control Package/SD-MMC_FATEngine.spin: repeat while(lockset(cardLockID - 1))
640 x 480 VGA Tile Map Driver w_ Mouse Cursor/VGA64_TMPEngine.spin: repeat while(lockset(lockNumber - 1))
74C922 Keypad Driver/74c922buffer.spin:repeat until not lockset(SemID) ' Lets lock the memory
74C92X Keypad Buffer and Driver/74c92Xbuffer.spin:repeat until not lockset(SemID) ' Lock it
Combo PS2 Keyboard and Mouse Driver/PS2_HIDEngine.spin: repeat while(lockset(keyboardLockNumber - 1))
DS1307 RTC Driver/DS1307_RTCEngine.spin: repeat while(lockset(lockNumber - 1))
FAT16_32 Full File System Driver/Full File System Driver with DS1302 RTC/DS1302_SD-MMC_FATEngine.spin: repeat while(lockset(cardLockID - 1))
Full Duplex Serial Port Driver/Full-Duplex_COMEngine.spin: while(lockset(lockNumber - 1))
Generic I2C EEPROM Driver/I2C_ROMEngine.spin: repeat while(lockset(lockNumber - 1))
ILI9325 320x240 TFT driver/touchSPI.spin:select lockset lock wc ' try to claim spi lock
IR Kit/ir_reader_nec.spin: repeat while lockset(lock)
KISS WAV Player Driver/SD-MMC_FATEngine.spin: repeat while(lockset(cardLockID - 1))
KISS WAV Recorder Driver/SD-MMC_FATEngine.spin: repeat while(lockset(cardLockID - 1))
Lock-Bit Demo/simple_multicore_demo3d.spin: repeat until lockset(LockID) == False 'Wait in this loop for lock to open
Nordic nRF2401 Rf Tranceiver Handler/TRF24G.spin: repeat until not lockset( rf_sem )
Octal Button Debouncer/D8C_BUTEngine.spin: repeat while(lockset(lockNumber - 1))
PROPSHELL/PROPSHELL-master/Full-Duplex_COMEngine.spin: while(lockset(lockNumber - 1))
Propeller Backpack TV Overlay/prop_backpack_tv_overlay2.spin: repeat while lockset(timelock)
Pulsadis detector/pulsadis dual processor for Obex/Full-Duplex_COMEngine.spin: while(lockset(lockNumber - 1))
SYSLOG - Multicog debug_log to SD_Serial/DS1307_RTCEngine.spin: repeat while(lockset(lockNumber - 1))
Servos and Encoders Calibration/SD-MMC_FATEngine.spin: repeat while(lockset(cardLockID - 1))
Settings/driver_socket.spin: repeat while NOT lockset(SocketLockid)
Switch Debounce/DebounceCog.c: lockset(SemID);
Trending Barometer/I2C_ROMEngine.spin: repeat while(lockset(lockNumber - 1))
Wheel_Controller/Wheel_Controller.spin: repeat until not lockset(mutex_id)
Wiimote IR blob tracking camera/wiicamera.spin: add clockset,clkpin_ 'Set up clock
mdb_RealTimeClock/MDB_RealTimeClock.spin: repeat until not LockSet(gLockId)
uSDPropLoader/DS1307_RTCEngine.spin: repeat while(lockset(lockNumber - 1))
That said, I've written some pretty intricate PASM code and never felt the need for a lock.
Interesting that a lot of those OBEX objects that use locks are Kye's. (Kwabena W. Agyeman). Those that contain the word "Engine". Sadly Kye hasn't been around here for over a year. I think he's still involved in computer vision and imaging. All of the OBEX examples show lockset in a SPIN context, none that I can see in PASM. It's not hard to see why that is so, in the context of objects that mix SPIN and PASM.
A highly off-book use of locks in PASM can be found it a puzzle from Kuroneko,
http://forums.parallax.com/discussion/129585/resolved-puzzle-connection-terminated
Locks are used to communicate a long from one PASM cog to another without using other HUB ram or a pin.
It's a good one to sort through for education.
The attached is (shameless plug) from my book on leanpub
Propeller Programming
Sridhar