-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Serial attach interrupt #95
base: master
Are you sure you want to change the base?
Conversation
added optional custom handler to Serial interrupt. Is similar to NeoHWSerial by SlashDevin (https://github.com/SlashDevin/NeoHWSerial), but: - user function also gets UART status as parameter to e.g. detect LIN break in user routine. - ported to Arduino Due Added as core extension because AFAIK cannot be implemented as library for Due. Also note similar pull request for AVR (arduino/ArduinoCore-avr#297)
- add Serialx.attachInterrupt_Send() - rename Serialx.attachInterrupt() to Serialx.attachInterrupt_Receive()
- updated modification date to sync with SAM core - no functional change
I believe I just found a bug which causes a stall to the attachSend() -> please wait before merge! I will update when/if I fixed it. Sorry! Done, see below |
- activate custom send_ISR also for 1B write - previous solution only worked for >=2B writes
@gicking yes. Anything you push to the branch the pull request is based on automatically becomes part of the pull request. |
hi per1234, thanks a lot for your confirmation! Have a great day :-) |
Note: a discussion is ongoing in the respective AVR "pull request page" about whether Serial.attachInterrupt_*() can and should be done as a library instead of a core extension. So please merge yet. Thanks! |
Note: in the parallel discussion for AVR a proposal was made by matthijskooijman to separate Serial similarly to AVRs. In that case no core extension for AVR or SAM would be required, a library like NeoHWSerial would do. This option is preferrable to be, so please don't merge this pull-request just now, but wait for the SAM discussion |
To keep the discussion clean, I created new issues for the "separate serial objects" implementation here: #100 and arduino/ArduinoCore-samd#489. Let's keep this issue about adding the serial interrupt API. |
@matthijskooijman: if the serials for SAM can be implemented similar to AVR, Rx- and Tx-interrupts can be added via a library like NeoHWSerial. In that case I would withdraw this pull request. For now I propose to leave it open and discuss it in the above issues arduino/ArduinoCore-sam#100 and arduino/ArduinoCore-samd#489, you created. |
seriously? It takes 16 months to automatically send a legal form...??? |
Hi @gicking , Have you had any update on whether this will be merged? I think that the Arduino SDK should give the user access to the interrupts either via class methods like yours or any other type of hook implementation. I mention this because with a project I am working we need all the 4 USART ports. As the data has to be processed directly via interrupts, the Serial class is limited as you only have access to the RX buffer from the polling methods: At the end what we did is deleted the USARTx_Handlers in the variants.cpp to suit our needs and override the weak USARTx_Handlers with our implementation. With your feature I could call the Arduino SDK function and would not need to modify the variants.cpp file. Also may I suggest to add a Example class MyClass
{
static void MyMethod(uint8_t data,uint32 status,void * args)
{
MyClass * pMyClass = static_cast<MyClass *>(args);
//Do something with the data of the instance
}
};
MyClass classInstance;
void setup()
{
attachInterrupt_Receive(MyClass::MyMethod,static_cast<void *>&classInstance);
} |
hey @vChavezB , unfortunately there was no response after April 2021. A similar issues was raised by @matthijskooijman, see here and here, also with zero response by the core team. And similar pull requests from 2017 by @facchinm and 2019 by @anklimov are also still open. In general I get the feeling that support for the SAM boards was dropped altogether. As for your request for an ISR with parameters, I'm not sure I understand. The ISR is not called by the SW but by the interrupt controller. So who would provide the argument during runtime? Or do you propose to add a callback pointer only for For your explanation thanks a lot in advance! Georg |
yes, from what I see this board development is not active. As the project we are working on will be released and I have modified directly this repo I think I will make my own board based on this repo with the json board definition so its accessible in the IDE as I do not see any more features being integrated here... About the callback with an extra void argument... The advantage I see of this argument (void *) is that it gives context to the callback. Yes you could do this inside the custom routine but it limits what you can do. For example, with the extra argument you can have access to the members of a class class MyClass
{
public:
static void MyMethod(uint8_t data,uint32 status,void * args)
{
MyClass * pMyClass = static_cast<MyClass *>(args);
pMyClass->count++;
}
int count=0;
}; Without this argument, it would be more difficult to interact with an object instance in the callback. Which given the nature of the Arduino SDK (C++) I think its a good idea, since it allows an OOP approach. So How could you increment the
MyClass myInstance;
void MyClass::MyMethod(uint8_t data,uint32 status)
{
myInstance.count++;
} What happens if you have more instances? Then you woul need to hardcode the instance you want to use for the callback MyClass myInstance[2];
void MyClass::MyMethod1(uint8_t data,uint32 status)
{
myInstance[0].count++;
}
void MyClass::MyMethod2(uint8_t data,uint32 status)
{
myInstance[1].count++;
}
As you see, passing an extra argument allows to use the callback within a class in a much simpler way. So the extra argument gives the context to the callback. Also when you think about programming a Driver for Hardware in C, you normally have an API which gives you opportunity for a |
This reverts commit b64442c.
hi again, do you propose the ISR calls the attached function with the received byte, the UART status, and the optional void* argument - which may be a callback function...? Sorry, I still don't quite get it... Therefore I propose you create a pull request to my repo, and provide an example how the argument is passed. Thanks in advance! Georg |
Hi Georg, I already started tinkering around with this repo. I added the callback with argument parameter here: https://github.com/vChavezB/ArduinoCore-sam I also added support for the USART2 peripheral of the Atsam3x8e. As I do not know if the mantainers are interested in adding these features I think I will continue with a fork and a custom boards package since the compiler version is really old. Regards |
added optional argument for user ISR function, see proposal from arduino#95 (comment)
hi again, thanks for the clarification, now I understand :-) I have added the void* argument to my repo and this pull request - for whatever it's worth... Have a nice X-mas and a Happy New Year! Regards, Georg |
added optional argument pointer, see arduino/ArduinoCore-sam#95 (comment)
seems like our impression is correct, see this discussion on Due development status |
Added option to attach custom functions to Serial receive and transmit interrupts.
Receive is similar to NeoHWSerial by SlashDevin but
Transmit is new:
Attached please find an example (tested for Mega and Due). Connect Tx1 & Rx1 and check serial monitor. A separate pull request was started for AVR (see here)
Serial_attach_interrupt.zip