-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Remove hardware dependence in portmacros.h #1112
Conversation
We do the same thing here as well - https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/CCS/MSP430X/portmacro.h#L43. Did you face any problem for which you made this change? |
Well for one thing, I think conceptually taking a dependence on Secondly, getting rid of this HW dependency would make this port consistent with the vast majority of other The specific issue that prompted this PR was using a part which has an Is there hesitation about merging this or are you asking because you would like to adjust the CCS port as well? That would take me a minute because I don't have the CCS toolchain set up, but if you have it set up and can audit the disassembly it's pretty straight forward to confirm that the enable/disable interrupts macros emit the same two instructions before and after the change. |
No substantive change in the force-push, just realized I had unbalanced bracket spacing |
I was trying the same change on CCS and figured that inline assembly is not supported for it - https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/438841/inline-asm-function-for-c-program. So we cannot do it for CCS port. I found the following when I tested these changes for IAR -
|
The IAR MSP430X port `#include "msp430.h"` which pulls all the hardware register definitions into anything which `#include "FreeRTOS.h"`. This removes that hardware dependency "leak" by removing the header file and re-defining the `portDISABLE_INTERRUPTS()` and `portENABLE_INTERRUPTS()` macros in terms of `__asm`.
Thanks for taking a look. It's strange that it compiles for me without warning even without the I read the TI e2e post you linked, but did not come to the same conclusion as you. The poster there was interested in manipulating registers across the C/ASM boundary which the TI compiler does not support. Simple insertion of a Some snippets from the compiler manual (published 2021) that suggest to me this would work in CCS: |
Thank you.
I did not arrive at this conclusion by just reading the post/manual. I created a project and made the changes and when the compilation failed, I tried to search for the reason which is when I found this. |
Thank you for pointing this out. This is what I missed. I tried your changes in CCS and I get a warning saying that "NOP is needed before setting GIE bit". I added a NOP before EINT and the following changes wok for me -
The above code generates the exact same assembly as compiler intrinsic:
I also needed to add I also noticed that IAR compiler intrinsic also inserts NOP before EINT:
which does not get inserted with the current definition:
Would you please update the portENABLE_INTERRUPTS for IAR also to include a NOP before EINT:
Thank your for your contribution! |
Signed-off-by: Gaurav Aggarwal <[email protected]>
@mayl I have made the changes I suggested in my previous comment. Let me know if you have any concern. Thank you for your contribution! |
Hi, thanks for that. Work got busy for me and I haven't been able to look at this.
The other reason for my slow response is that this also seems suspect to me, and I wanted to run it to ground... I found some indications that this error in CCS may be a bug. I looked at how the IAR intrinsics work (not the ASM we wrote here, but the actual intrinsics) and they seem to only insert a nop before EINT if the instruction before was a DINT. This makes some sense because the pipeline would cause interrupts to maybe never be disabled (FreeRTOS handles this case with the NOP after DINT). What's less clear why in a general case you would need a NOP before EINT... Anyway, I'm not fully sure yet but you may see a PR in the future pulling out the extra NOP when I get my head fully around what's happening in the warning you are responding to... |
I did not look at IAR intrinsics but looked at the assembly produced and for me, it inserted a NOP before EINT even when the previous instruction was not DINT.
Sure. Till then, the code functionally correct and we can merge this PR. |
Quality Gate passedIssues Measures |
Remove hardware dependence in portmacros.h
Description
The IAR MSP430X port
#include "msp430.h"
which pulls all the hardware register definitions into anything which#include "FreeRTOS.h"
. This removes that hardware dependency "leak" by removing the header file and re-defining theportDISABLE_INTERRUPTS()
andportENABLE_INTERRUPTS()
macros in terms of__asm
.Test Steps
Checklist:
I tested in IAR at work, don't have a license here at home to test with. Verified by looking at the disassembly of the
portDISABLE_INTERRUPTS()
andportENABLE_INTERRUPTS()
macros and confirming they are identical to before.Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.