Skip to content
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

Rewrite the RX interrupt to remove goto and simplify debug statements #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

edlongman
Copy link

The existing library was written using goto statements and in a way which masquerades as a State machine but it not really a state machine.

I have rewritten this interrupt as a state machine. See the diagram below:
New_ISR_model
No gotos now and it behaves much more like a state machine.

Also the UART debug statements have been compressed into a macro.

The structure that stores the bytes for received bytes has been made into a union so just the buffer can be written to as raw and the properties can be accessed separately.

//	+-------------trx_format--------------+
//	|             BUFFER              |sta|
//	|len|typ |chk  |                  |   |
//	|   |    |sum  |.... payload ...  |tus|
//	+-------------------------------------+

The Tx buffer struct could be constructed as struct of the rf_trx_buffer_t and the sync bytes. This would allow the txbuff state to be stored with the txbuffer

@tixiv
Copy link
Member

tixiv commented Nov 4, 2019

Hi edlongman,

I am one of the original authors of this library, feels like a thousand years ago when we wrote this thing... Nice that there is still interest in it.
We used it at the lab at the time for some projects like a RF-joystick for our blinkenborg and I later also used it for a telemetry system for our solarcar. Sadly at the moment I don't have any test system ready to go to test your modifications.
I still remember it was not an easy task to make the lib work fine with all the features (small AVR-microcntrollers used at the time, some with only 2k of flash), and also the RFM12 gave us a hard time, as the chip itself behaves pretty strangeley in some cases, and not like the datasheet describes - I don't really remember the details.

I'm sorry, but I am not in favour of accepting this pull request, as I can't test it, even less with all the different configuration options. I only know the library has been working flawlessly since years in the devices that still use it. i would prefer to have this old project just left alone here.

Regarding a real statemachine: I'm not sure what that is supposed to be - evrything is a statemachine that has states and changes them. in my eyes, the old statemachine is very real (and tested, and working fine)

Regarding goto: I like that command, especially when needing to leave a pretty nested block to clean up and return or something similar.
It makes for cleaner code in a lot of cases. There was a paper at some point in the 70's "goto considered harmfull". Many people think the goto command itself is bad style nowadays because of that paper (not having actually read it). But that title is pretty "clickbaity" to use modern terms. A more suitable title might be "sphaghetti code considered harmfull", which then and now is pretty true. Goto alone doesn't make for bad style. Try grepping the Linux kernel source for "goto" for example...it's full of it, and not for legacy reasosns....

@edlongman
Copy link
Author

edlongman commented Nov 5, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants