Shop OBEX P1 Docs P2 Docs Learn Events
Make SimpleSerial into a multiple-cog accessable object. — Parallax Forums

Make SimpleSerial into a multiple-cog accessable object.

photomankcphotomankc Posts: 943
edited 2009-10-17 04:44 in Propeller 1
I'm working on a custom driver for the Parallax 4x20 LCD for my thermostat project.· Last on the plate was the ability to set a backlight timeout without foreground attention.· To do this I made a simple little routine to fire off a cog to count-down milliseconds until it reaches zero or another backlight time request is made in which case it is reset to the request and starts over again.· When it reaches zero it clears the cog indicator and calls stop on itself.· I ran into lots of trouble though with simple_serial being touched by another cog.· The cog was launched from inside the LCD driver but if it touched the rx(byte) function that killed further communication and from then on no other text would be sent to the LCD.·

If I replace simple_serial with SerialMirror then it works just fine and backlight timer works just as I desire it.· However I do not need full duplex which just burns up a pin and I don't really want to use two cogs just to provide this function.· Does anyone know where I might start to make modify simple_serial work with multiple cogs?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-17 04:44
    What you're describing is normal in multi-processor systems. Each cog (in this case) has to reserve the common resources, probably using the LOCKxxx statements. When one cog wants to do serial I/O, it has to request exclusive access to the serial I/O pins, initialize the serial driver, send its data, release the I/O pins, and release the exclusive access. In order to have only one instance of the common variables (like SerialMirror), the variables declared in the VAR section have to be declared as part of a DAT section.

    You could add code to the Simple_Serial object to get exclusive access when the init method is called and release exclusive access when the finalize method is called. You'd just have to have your two different cogs call init whenever they want to output something and call finalize when they're done. You'd have to make sure that each cog doesn't hog the serial object preventing the other from doing its work.
Sign In or Register to comment.