TNeo
BETA v1.08-11-g97e5a6d
|
Architecture-specific details
The context switch is implemented using the core software 0 interrupt (CS0
), which is configured by the kernel to the lowest priority (1). This interrupt is handled completely by the kernel, application should never touch it.
The interrupt priority level 1 should not be configured to use shadow register sets.
Multi-vectored interrupt mode should be enabled.
src/arch/pic32/tn_arch_pic32_int_vec1.S
must be included in the main project itself, in order to dispatch vector1 (core software interrupt 0) correctly. Do note that if we include this file in the TNeo library project, it doesn't work for vector, unfortunately._DefaultInterrupt
when it's time to switch context.For generic information about interrupts in TNeo, refer to the page Interrupts.
PIC32 port has system interrupts only, there are no user interrupts.
PIC32 port supports nested interrupts. The kernel provides C-language macros for calling C-language interrupt service routines, which can use either MIPS32 or MIPS16e mode. Both software and shadow register interrupt context saving is supported. Usage is as follows:
In spite of the fact that the kernel provides separate stack for interrupt, this isn't a mandatory on PIC32: you're able to define your ISR in a standard way, making it use stask of interrupted task and work a bit faster. Like this:
There is always a tradeoff. There are no additional constraints on ISR defined without kernel-provided macro: in either ISR, you can call the same set of kernel services.
When you make a decision on whether particular ISR should use separate stack, consider the following:
For generic information on building TNeo, refer to the page Building TNeo.
MPLABX project for PIC32 port resides in the lib_project/pic32/tneo_pic32.X
directory. This is a library project in terms of MPLABX, so if you use MPLABX you can easily add it to your application project by right-clicking Libraries -> Add Library Project ...
. Alternatively, of course you can just build it and use resulting tneo_pic32.X.a
file in whatever way you like.
If you want to build TNeo manually, refer to the section Building manually for generic notes about it, and there is a couple of arch-dependent sources you need to add to the project:
src/arch/pic32/tn_arch_pic32.c
src/arch/pic32/tn_arch_pic32mx_xc32.S
tn_arch_pic32_int_vec1.S
, which should be included in your application project to make things work. It is needed to dispatch vector1 (Core Software Interrupt 0) correctly.The context switch is implemented using the external interrupt 0 (INT0
). It is handled completely by the kernel, application should never touch it.
For generic information about interrupts in TNeo, refer to the page Interrupts.
PIC24/dsPIC TNeo port supports nested interrupts. It allows to specify the range of system interrupt priorities. Refer to the subsection Interrupt types for details on what is system interrupt.
System interrupts use separate interrupt stack instead of the task's stack. This approach saves a lot of RAM.
The range is specified by just a single number: TN_P24_SYS_IPL
, which represents maximum system interrupt priority. Here is a list of available priorities and their characteristics:
[1 .. TN_P24_SYS_IPL]
:tn_p24_soft_isr()
must be used.[(TN_P24_SYS_IPL + 1) .. 6]
:tn_p24_soft_isr()
must not be used.disi
instruction when entering/exiting system ISR: we need to safely modify SP
and SPLIM
.7
:tn_p24_soft_isr()
must not be used.disi
instruction leaves interrupts of priority 7 enabled).The kernel provides C-language macro for calling C-language system interrupt service routines.
Usage is as follows:
TN_P24_SYS_IPL
). Use standard way to define it. If TN_CHECK_PARAM
is on, kernel checks it: if you violate this rule, debugger will be halted by the kernel when entering ISR. In release build, CPU is just reset.The problem with PIC24/dsPIC is that when we write something like:
We actually have read-modify-write sequence which can be interrupted, so that resulting data could be corrupted. PIC24/dsPIC port provides several macros that offer atomic access to the structure bit field.
The kernel would not probably provide that kind of functionality, but TNeo itself needs it, so, it is made public so that application can use it too.
Refer to the page Atomic bit-field access macros for details.
For generic information on building TNeo, refer to the page Building TNeo.
MPLABX project for PIC24/dsPIC port resides in the lib_project/pic24_dspic/tneo_pic24_dspic.X
directory. This is a library project in terms of MPLABX, so if you use MPLABX you can easily add it to your main project by right-clicking Libraries -> Add Library Project ...
.
Alternatively, of course you can just build it and use resulting .a
file in whatever way you like.
If you want to build TNeo manually, refer to the section Building manually for generic notes about it, and additionally you should add arch-dependent sources: all .c
and .S
files from src/arch/pic24_dspic
The context switch is implemented in a standard for Cortex-M CPUs way: the PendSV exception. SVC exception is used for _tn_arch_context_switch_now_nosave()
. These two exceptions are configured by the kernel to the lowest priority.
For generic information about interrupts in TNeo, refer to the page Interrupts.
Cortex-M port has system interrupts only, there are no user interrupts.
Interrupts use separate interrupt stack, i.e. MSP (Main Stack Pointer). Tasks use PSP (Process Stack Pointer).
There are no constraints on ISRs: no special macros for ISR definition, or whatever. This is because Cortex-M processors are designed with OS applications in mind, so a number of featureas are available to make OS implementation easier and make OS operations more efficient.
For generic information on building TNeo, refer to the page Building TNeo.
There are many environments for building for Cortex-M CPUs (Keil, Eclipse, CooCox), all available projects reside in lib_project/cortex_m
directory. They usually are pretty enough if you want to just build the kernel with non-default configuration.
If, however, you want to build it not using provided project, refer to the section Building manually for generic notes about it, and additionally you should add arch-dependent sources: all .c
and .S
files from src/arch/cortex_m
.
There are some additional tips depending on the build environment:
Keil 5, ARMCC compiler
To satisfy building requirements, a couple of actions needed:
.S
) aren't preprocessed by default, so, in project options, Asm tab, "Misc Controls" field, type the following: --cpreproc
Keil 5, GCC compiler
Unfortunately, when GCC toolchain is used from Keil uVision IDE, for .S
files it calls arm-none-eabi-as
, which does not call C preprocessor.
Instead, arm-none-eabi-gcc
should be used, but unfortunately I was unable to make Keil uVision issue arm-none-eabi-gcc
for .S
files, the only way to use GCC toolchain in Keil uVision that I'm aware of is to preprocess the file manually, like that:
cpp -P -undef tn_arch_cortex_m.S \ -D __GNUC__ -D __ARM_ARCH -D __ARM_ARCH_7M__ \ -I ../.. -I ../../core \ > tn_arch_cortex_m3_gcc.s
(this example is for Cortex-M3, you may check the file tn_arch_detect.h
to see what should you define instead of __ARM_ARCH_7M__
for other cores)
And then, add the output file tn_arch_cortex_m3_gcc.s
to the project instead of tn_arch_cortex_m.S