Hello
I'm working on a K60 with MQX 4.2.0.
I use Ethernet via rtcs stack.
Currently, to get data received from ethernet (in TCP or UDP), I call periodically recvfrom or recv. Then this is a "polling" mode.
Are they a way to use it in "interrupt" mode. Is exist a system via callback notification or a semaphore to be averted when frame is received from the socket?
THank:smileyhappy:
Solved! Go to Solution.
Hi Arnaud,
You are right, I realized it just some time after I post my reply.
Unfortunately I am afraid that RTCS sockets do not support such implementation (callbacks).
Best option is probably to have special task just for receiving Ethernet data (like in HTTP server). This task could be also automatically generated and discarded…
You can use recv() function if you waiting just for data from one socket.
If you need monitor wider communication, please use function select() or selectset()/selectall(). It will block receive task until any activity on selected sockets.
Receive task could work in loop and just after select() function you can place some socket content processing and notify high level task by e.g. lwevent about new data. After that back to waiting for new socket activity.
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Arnaud,
You can use OPT_RECEIVE_NOWAIT socket option in calling setsockopt() function. This will cause that recv() will not wait for data, but immediately returns size of received data. 0 means that buffer is empty, -1 is error.
In MQX 4.2 you have one additional option:
You can use MSG_DONTWAIT flag in call of recv() function. This specific call is executed as non-blocking.
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello
I known these option, but this solution still polling mode to get data from ethernet.
Then I must have a task which call periodically a recv.
I need an high reactivity on Ethernet received frame, then I must have a periodic task with a very low period.
I'm like to keep the reactivity but decrease the CPU load,
It is why I'm looking for a way to be prevent on Eth received frame without need polling...
Are they a way to do this with MQX?
Hi Arnaud,
You are right, I realized it just some time after I post my reply.
Unfortunately I am afraid that RTCS sockets do not support such implementation (callbacks).
Best option is probably to have special task just for receiving Ethernet data (like in HTTP server). This task could be also automatically generated and discarded…
You can use recv() function if you waiting just for data from one socket.
If you need monitor wider communication, please use function select() or selectset()/selectall(). It will block receive task until any activity on selected sockets.
Receive task could work in loop and just after select() function you can place some socket content processing and notify high level task by e.g. lwevent about new data. After that back to waiting for new socket activity.
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you,
I will use the possible blocant wait in the recv() to block the task unitl new data is received!
:smileyhappy: