multi-thread use of W5100_Indirect_Driver.spin
Javalin
Posts: 892
All,
I'd like to raise/highlight an issue in the W5100_Indirect_Driver.spin driver relating to use of the W5100 chip from multiple Propeller cog's. As Microsoft would say - its not "thread safe"....
The ReadIND and WriteIND functions don't wait for the cog to complete its current action before setting the command variable and waiting output. For example if you're using (as I am) 3 sockets for a web server in one cog, and one for a dedicated client socket in another, it all goes badly wrong when both access the W5100 at the same time.
"fixed" code below:
The writeIND function - i've commented out the if _block statement as the function always needs to wait.
James
I'd like to raise/highlight an issue in the W5100_Indirect_Driver.spin driver relating to use of the W5100 chip from multiple Propeller cog's. As Microsoft would say - its not "thread safe"....
The ReadIND and WriteIND functions don't wait for the cog to complete its current action before setting the command variable and waiting output. For example if you're using (as I am) 3 sockets for a web server in one cog, and one for a dedicated client socket in another, it all goes badly wrong when both access the W5100 at the same time.
"fixed" code below:
PUB readIND(_register, _dataPtr, _Numbytes) '' High level access to Indirect/parallel routine for reading from the W5100. '' Note for faster execution of functions code them in assembly routine like the examples of setting the MAC/IP addresses. '' '' params: _register is the 2 byte register address. See the constant block with register definitions '' _dataPtr is the place to return the byte(s) of data read from the W5100 (use the @ in front of the byte variable) '' _Numbytes is the number of bytes to read '' return: none 'If the ASM cog is running, execute the command if (W5100flags & _Flag_ASMstarted) ' wait for the current command to complete repeat while command 'Send the command command := _readIND + @_register 'wait for the command to complete repeat while command return 'end of readIND
PUB writeIND(_block, _register, _dataPtr, _Numbytes) '' High level access to Indirect/parallel routine for writing to the W5100. '' Note for faster execution of functions code them in assembly routine like the examples of setting the MAC/IP addresses. '' '' params: _block if true will wait for ASM routine to send before continuing '' _register is the 2 byte register address. See the constant block with register definitions '' _dataPtr is a pointer to the byte(s) of data to be written (use the @ in front of the byte variable) '' _Numbytes is the number of bytes to write '' return: none 'If the ASM cog is running, execute the command if (W5100flags & _Flag_ASMstarted) ' wait for the current command to complete repeat while command 'Send the command command := _writeIND + @_register 'wait for the command to complete (forced - declaration left as is for compatibility) 'if _block repeat while command return 'end of writeIND
The writeIND function - i've commented out the if _block statement as the function always needs to wait.
James
Comments
Before the command variable is set - i.e.
This needs to be done in the following functions : Initialize, Disconnect and Close
James