Skip to content

drivers/at: Add at_urc_isr module to process URCs upon arrival #14327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2020

Conversation

leandrolanzieri
Copy link
Contributor

@leandrolanzieri leandrolanzieri commented Jun 22, 2020

Contribution description

This adds the at_urc_isr pseudomodule to the AT driver. This module allows to trigger the processing of registered URCs when AT_EOL_RECV_2 character is detected (and no response is pending). It makes use of event threads to process the buffer and call the callback function.

Testing procedure

  • Use the tests/driver_at application and register an URC. When the URC arrives the notification should be displayed without having to manually process it. All the other functionalities of the driver should still work as usual.
  • Change at_urc_isr by at_urc in the application and now manually processing should be needed.

Issues/PRs references

None.

@leandrolanzieri leandrolanzieri added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers labels Jun 22, 2020
@aabadie aabadie self-assigned this Jun 23, 2020
Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, except the small nit I just found.

Do you have a way to test this and report in the PR ? (I have no access to AT based devices ATM).

@leandrolanzieri
Copy link
Contributor Author

I have pushed a fixup because I was getting an error return code when sending the commands, also the stack size of the event thread was too small to use printf, so I changed that configuration.

Do you have a way to test this and report in the PR ? (I have no access to AT based devices ATM).

I tested with the UBLOX sara-r410m. You can see that I registered an URC with the response of the scan, which takes several seconds. Then I issued the command to scan (which times out). Finally I get the message and it's reported as a received URC. Also immediate commands still work as usual.

2020-06-30 10:28:07,561 #  main(): This is RIOT! (Version: 2020.07-devel-1344-g205911-pr/drivers/at_isr_urc)
2020-06-30 10:28:07,561 # AT command test app
> add_urc +COPS
2020-06-30 10:28:13,028 #  add_urc +COPS
2020-06-30 10:28:13,028 # urc registered
> init 1 115200
2020-06-30 10:28:16,616 #  init 1 115200
> send AT+COPS=?
2020-06-30 10:28:22,351 #  send AT+COPS=?
2020-06-30 10:28:32,384 # Error
> 2020-06-30 10:28:51,739 #  urc received: +COPS: (2,"262 01","262 01","26201",9),,(0,1,2,3,4),(0,1,2)
send AT+CGMI
2020-06-30 10:28:59,274 # send AT+CGMI
2020-06-30 10:28:59,292 # Response (len=6): u-blox
> 

@aabadie
Copy link
Contributor

aabadie commented Jun 30, 2020

Sorry to only think about this now. I'm wondering if we could avoid the use of the event thread, since this adds another thread. Maybe that's not possible, since directly calling the callback when the URC would be done in ISR context if I understand it correctly.

@leandrolanzieri
Copy link
Contributor Author

since directly calling the callback when the URC would be done in ISR context if I understand it correctly.

Yeah, this is the main reason why I am using event thread. I think in this case it's ok to use these types of OS mechanisms for offloading.

That being said, another alternative could be that the user initializes the event queue and handles the even loop? Maybe even chose the behaviour using pseudomodules.

@aabadie
Copy link
Contributor

aabadie commented Jun 30, 2020

another alternative could be that the user initializes the event queue and handles the even loop?

That would move the complexity in the user code. I'm not sure that's very friendly for this kind of things. Since this part is only build when enabling the URC isr I think this is fine.

Please address my remaining comments and squash directly !

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

Please squash!

@leandrolanzieri leandrolanzieri force-pushed the pr/drivers/at_isr_urc branch from 1d3e851 to 955efd8 Compare June 30, 2020 09:46
@leandrolanzieri
Copy link
Contributor Author

@aabadie squashed. Thanks for reviewing!

@leandrolanzieri leandrolanzieri added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 30, 2020
@aabadie
Copy link
Contributor

aabadie commented Jun 30, 2020

Travis failed and I can't restart it but that's not a problem since Murdock is green => GO!

@aabadie aabadie merged commit d132ef4 into RIOT-OS:master Jun 30, 2020
@aaltuntas
Copy link
Contributor

Hello,

I am not sure if I am allowed to directly jump into the conversation -I am not a contributor just an ordinary RIOT user :)- but I could share a useful experience with you although the PR has just been merged:). In our FW, we communicate with ublox modems using this at driver. We have spent considerable amount of time in properly processing all emitted URCs. According to our observations by means of a logic analyzer, it's really hard to decide when the AT device will NOT send a URC. We have observed cases in which we send out an AT command and the first thing that we receive is a URC. Then the response of the command follows. It might sound weird but this is how the ublox modem behaves. That being said, I am not so confident that this implementation will guarantee to capture all emitted URCs.

@leandrolanzieri leandrolanzieri deleted the pr/drivers/at_isr_urc branch June 30, 2020 11:02
@miri64 miri64 added this to the Release 2020.07 milestone Jun 30, 2020
@aabadie
Copy link
Contributor

aabadie commented Jun 30, 2020

I am not so confident that this implementation will guarantee to capture all emitted URCs.

@leandrolanzieri what do you think ? Did you encounter such problems with your ublox driver ?

@leandrolanzieri
Copy link
Contributor Author

@leandrolanzieri what do you think ? Did you encounter such problems with your ublox driver ?

Not so far, but if the behaviour is as @aaltuntas describes (having URCs in the middle of commands) it is possible that we do not catch all URCs with just the interrupt. I will keep an eye on that while I continue with the driver.

@aaltuntas do you have any suggestions for improvement here?

@aaltuntas
Copy link
Contributor

aaltuntas commented Jun 30, 2020

Our approach was not event based, we refactored at_expect_bytes to check for and process URCs at the beginning. The purpose of this was to capture the URCs that are received during the execution of at_send_cmd for example. Additionally, we followed the same procedure in at_drain. The purpose of this was to handle URCs that were received during idle times when there was no ongoing AT operation. We inserted delays of default 20ms just before at_drain in functions like at_send_cmd_get_resp. This delay is suggested by the ublox AT manual, which will give time the modem to emit any URCs.

So, keeping those in mind, I would suggest to put dev->awaiting_response flag in functions that constitute a whole AT operation like at_send_cmd_get_resp etc. rather than in every sub-function. To me, the best place is right after the at_send_cmd function. On the other hand, if it's adapted properly, your event based URC processing would be a cleaner solution than that of ours. Last but not least, my suggestions might only apply to ublox modems. I don't have the opportunity to test our modified driver against different AT devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants