Skip to content

cpu: centralized cortex initialization and some defines#3100

Merged
jnohlgard merged 16 commits intoRIOT-OS:masterfrom
haukepetersen:opt_cortexm_init
May 30, 2015
Merged

cpu: centralized cortex initialization and some defines#3100
jnohlgard merged 16 commits intoRIOT-OS:masterfrom
haukepetersen:opt_cortexm_init

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

Based on #3023

  • added a centralized core implementation for all cortex CPUs
  • moved default stack size defines to cpu.h in cortexm_common
  • moved uart0 bufsize define to cpu.h in cortexm_common
  • moved typed of panic_t to cpu.h in cortexm_common
  • adapted all effected CPUs

EDIT:
Forgot to explain one feature: The device specific interrupt priorities are now initialized on startup to a default value. As we are using only one interrupt priority for everything to prevent interrupt preemtion, this saves the need to set the interrupt priority in during peripheral initialization -> helps to keep the periph code smaller.

@haukepetersen haukepetersen added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels May 27, 2015
@haukepetersen haukepetersen added this to the Release 2015.06 milestone May 27, 2015
@jnohlgard
Copy link
Copy Markdown
Member

Impressive work

@jnohlgard
Copy link
Copy Markdown
Member

is this WIP?
cortexm_init() should be called from all of the affected CPUs during cpu_init().

@haukepetersen
Copy link
Copy Markdown
Contributor Author

not really WIP, I just forgot the cortexm_init()... Thx for reminding me, I will fix this ASAP

@jnohlgard
Copy link
Copy Markdown
Member

Let's try to get this merged asap so that we don't accumulate more dependencies.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

+1!

@haukepetersen
Copy link
Copy Markdown
Contributor Author

added those missing calls to cortexm_init(). Will rebase this PR once #3023 is merged...

@jnohlgard
Copy link
Copy Markdown
Member

OK to squash.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

will do when I rebase after the merge of #3023.

@jnohlgard
Copy link
Copy Markdown
Member

#3023 is merged, please rebase

@haukepetersen
Copy link
Copy Markdown
Contributor Author

did, but broke something... Fixing it as we speak.

@haukepetersen haukepetersen added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 29, 2015
@haukepetersen
Copy link
Copy Markdown
Contributor Author

fixed. Ready for final review, Travis and hopefully merging.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This TODO reference is something that I have been curious about for some time, what does it mean? Is there an open issue for this? Is this related to the COREIF_NG definition found in most (all?) platform makefiles?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, there is: #1892

Once in a time, boards/cpus used dINT and eINT macros for enabling/disabling interrupts. Then the current API with enableIRQ and disableIRQ was introduced. But there are still some occurances of the old calls left, so we were not able to remove them so far...

@jnohlgard
Copy link
Copy Markdown
Member

How are the Cortex-M common IRQs affected by this change? Will they have a higher priority than the vendor specific IRQs since the default IRQ prio is set to 1?

@jnohlgard
Copy link
Copy Markdown
Member

I think the code looks good, waiting for Travis. The question of IRQ priorities is something to keep in mind though, since the preemption order of the ISR may have been affected.

@haukepetersen Thank you for doing this large and somewhat ungrateful work for the long term greater good of the OS.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

They are not. We use only two of them, PendSV and SVC, which are both set explicitly in cortexm_init. The others we do not use (or even panic when they encounter, so their prios to not really matter...).

@haukepetersen
Copy link
Copy Markdown
Contributor Author

@gebart: by the way, did you notice the implicitly included solution on handling cortex-M4 CPUs without FPU? This should be taken care of for once and all...

@jnohlgard
Copy link
Copy Markdown
Member

@haukepetersen

They are not. We use only two of them, PendSV and SVC, which are both set explicitly in cortexm_init. The others we do not use (or even panic when they encounter, so their prios to not really matter...).

That clears things up. Thanks for the explanation

@gebart: by the way, did you notice the implicitly included solution on handling cortex-M4 CPUs without FPU? This should be taken care of for once and all...

I did see some special handling of M4F in the makefiles, but the context switching is still broken with regards to floating point registers, right?

@jnohlgard
Copy link
Copy Markdown
Member

@haukepetersen but the M4F stuff was in #3023, I am not sure what you mean.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

oh yep, it was in #3023. I just had looked at your comment in #1366 in wanted to point out that that concern is solved...

But you are right, the handling of the FPU registers on context switching is still not implement. This could lead to corrupted data if more than one thread is using the FPU simultaneously...

@kaspar030
Copy link
Copy Markdown
Contributor

the handling of the FPU registers on context switching is still not implement. This could lead to corrupted data if more than one thread is using the FPU simultaneously...

Shouldn't we then disable hard FPU until this is sorted out?

@haukepetersen
Copy link
Copy Markdown
Contributor Author

might not be the worst idea. But unrelated to this PR... How about we move that discussion to #1366?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we leave this in but commented out, until #1366 is resolved?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really. If we leave this out, the CPU goes into hardfault as soon as it encounters a 'float' somewhere. We can only leave this out, as soon as we disabled the FPU compiler options or changed them to use soft float explicitly... I will prepare another PR for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And remember, as long as there is only one thread using the FPU at a time, everything works fine at the moment... :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I smell hard-to-find bugs...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO we should make this an opt-in pseudomodule until this is sorted out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thats why I'm just preparing a PR to fix this...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done: #3112

Regarding the FPU initialization above: I makes much sense to leave it in. With #3112 the FPU should not be used. But if it is under some unforeseeable circumstances is used (though I don't know how this could happen), this initialization would prevent the CPU from going into hard-fault.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, I see your points.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

fixed issues with uart0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is not cpu_conf.h always included by cpu.h?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not on the arm7 and the msp430...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

on these platforms it will be as soon as we clean them up and move them to the current structure...

@haukepetersen
Copy link
Copy Markdown
Contributor Author

something went wrong while rebasing with the saml21-xpro, fixed now.

@jnohlgard
Copy link
Copy Markdown
Member

ACK
Travis is green, go

jnohlgard pushed a commit that referenced this pull request May 30, 2015
cpu: centralized cortex initialization and some defines
@jnohlgard jnohlgard merged commit 41e1b57 into RIOT-OS:master May 30, 2015
@haukepetersen haukepetersen deleted the opt_cortexm_init branch May 30, 2015 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants