Skip to content

Commit a4f16dd

Browse files
[Fixes]: Fix ISR premption
[Description]: Fixed use of neop instruction (used nop instead) Doc fixes in arch and board Added optimisation levels ISR vector number lost on premption, fixed by adding workaround for for alternate vec number calculation Signed-off-by: Muhammed Zamroodh <[email protected]>
1 parent fc4c08f commit a4f16dd

File tree

12 files changed

+67
-13
lines changed

12 files changed

+67
-13
lines changed

arch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ choice IRQ_VECTOR_TABLE_TYPE
579579
prompt "IRQ vector table type"
580580
depends on GEN_IRQ_VECTOR_TABLE
581581
default IRQ_VECTOR_TABLE_JUMP_BY_CODE if (RISCV && !RISCV_HAS_CLIC)
582+
default IRQ_VECTOR_TABLE_JUMP_BY_CODE if DSPIC
582583
default IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS
583584

584585
config IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS

arch/dspic/core/isr_wrapper.S

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
.type __COMMONInterrupt,@function
1717
__COMMONInterrupt:
1818
.section .isr.text._COMMONInterrupt,keep,code,keep
19+
mov.sl #__irq_vector_table+4, w0
20+
subr.l w0, [--w15], w0
21+
lsr w0, #2, w0
1922
lnk #0x4
2023
/* Handle ISR calls and clear handles IRQ
2124
*/
2225
mov.l w8, [w15++]
2326
mov.sl #__kernel + ___cpu_t_nested_OFFSET,w8
2427
add.l [w8],#1,[w8]
25-
mov.w _INTTREGbits,w0
26-
and.l #0x1ff,w0
27-
sub.l w0,#9,w0
28+
29+
mov.l w0, [w15++]
2830
mov.sl #__sw_isr_table,w1
2931
sl.l w0,#3,w0
3032
add.l w0,w1,w2
3133
mov.l [w2+4],w1
3234
mov.l [w2],w0
3335

3436
call w1
35-
mov.w _INTTREGbits,w0
36-
and.l #0x1ff,w0
37-
sub.l w0,#9,w0
37+
mov.l [--w15], w0
3838
call _arch_dspic_irq_clear
3939

4040
/* Check and perform context switch

arch/dspic/core/vector_table.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ __vector_table:
2929
.long __MathErrorTrap
3030
.long __GeneralTrap
3131
.long __ReservedTrap7
32+
.set offset, 0
33+
.rept CONFIG_NUM_IRQS
34+
.pword __irq_vector_table + offset
35+
.set offset, offset + 4
36+
.endr

arch/dspic/include/kernel_arch_swap_macro.S

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@
271271
.endm
272272

273273
.macro z_dspic_do_swap
274-
/* Set the SPLIM to end of RAM
275-
* To avoid, stack overflow fault.
276-
*/
277274
/* Switch to context 0 before starting context save and restore
278275
* This Arch has 7 context and each has banked register sets for w0-w8
279276
* So in interrupt we are in ctx 1 and need to go to ctx 0 for tasks

boards/microchip/dspic33/dspic33a_curiosity/board.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <zephyr/init.h>
77
#include <zephyr/kernel.h>
88

9+
/* Board level init for dspic33a_curiosity
10+
*/
911
void board_early_init_hook(void)
1012
{
1113
}

boards/microchip/dspic33/dspic33a_curiosity/doc/index.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,39 @@ Building
130130
131131
west build -p always -b dspic33a_curiosity/<qualifier> samples/hello_world/ -- -DZEPHYR_TOOLCHAIN_VARIANT=xcdsc -DXCDSC_TOOLCHAIN_PATH=/opt/microchip/xc-dsc/<version>
132132
133+
Optimizations
134+
-------------
135+
136+
The XC-DSC toolchain hooks its optimization levels in
137+
``cmake/compiler/xcdsc/compiler_flags.cmake`` by mapping Zephyr's generic
138+
properties to concrete compiler flags. In this file:
139+
140+
* ``optimization_speed`` uses ``-O2``.
141+
* ``optimization_size`` uses ``-O2``.
142+
* ``optimization_size_aggressive`` uses ``-Os``.
143+
* ``optimization_debug`` uses ``-O1``.
144+
145+
In general, :kconfig:option:`CONFIG_SIZE_OPTIMIZATIONS` is enabled in the base
146+
configuration, so Zephyr picks ``optimization_size`` and therefore ``-O2`` for
147+
every ``west build`` unless you override the setting in your **application
148+
prj.conf** (the configuration that sits inside your sample or app directory,
149+
not a global project file).
150+
151+
To change that default, set one of these options in your application's
152+
``prj.conf`` and rebuild:
153+
154+
- ``CONFIG_SIZE_OPTIMIZATIONS`` (Zephyr default) keeps the ``-O2`` size profile.
155+
- ``CONFIG_SIZE_OPTIMIZATIONS_AGGRESSIVE`` switches to ``optimization_size_aggressive``,
156+
which adds the ``-Os`` mapping described in ``compiler_flags.cmake``. This
157+
level is only available when your XC-DSC compiler is licensed.
158+
- ``CONFIG_SPEED_OPTIMIZATIONS`` selects ``optimization_speed`` (``-O2``).
159+
- ``CONFIG_DEBUG_OPTIMIZATIONS`` selects ``optimization_debug`` (``-O1``).
160+
- ``CONFIG_NO_OPTIMIZATIONS`` forces (``-O0``).
161+
162+
After saving the desired configuration in your application's ``prj.conf``, rerun
163+
``west build`` and the build system will regenerate all XC-DSC command lines
164+
with the matching optimization level, no edits to the CMake files are required.
165+
133166
Flashing
134167
========
135168
#. Run your favorite terminal program to listen for output.

cmake/compiler/xcdsc/compiler_flags.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
set_compiler_property(PROPERTY debug -g)
33
# Optimization for debug builds
44
set_compiler_property(PROPERTY optimization_debug -O1)
5-
set_compiler_property(PROPERTY optimization_speed -O1)
5+
set_compiler_property(PROPERTY optimization_speed -O2)
66
# Optimize for size
7-
set_compiler_property(PROPERTY optimization_size -O1)
8-
set_compiler_property(PROPERTY optimization_size_aggressive -O1)
7+
set_compiler_property(PROPERTY optimization_size -O2)
8+
set_compiler_property(PROPERTY optimization_size_aggressive -Os)
99
# Basic warnings
1010
check_set_compiler_property(PROPERTY warning_base -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-unused-but-set-variable )
1111
# Compiler flags for imacros. The specific header must be appended by user.

doc/hardware/arch/dspic33a.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ Microchip Technology featuring a high-performance 32-bit CPU core with DSP
1515
capabilities, integrated FPU, and rich peripheral set. The family is designed
1616
for real-time control applications requiring signal processing capabilities.
1717

18+
dsPIC33A on Zephyr
19+
******************
20+
.. image:: ./images/block_diagram.png
21+
:align: center
22+
23+
The dsPIC33A port provides:
24+
25+
- **Board support:** the dsPIC33A Curiosity Platform baseboard (EV74H48A) fitted with either the dsPIC33AK128MC106 or dsPIC33AK512MPS512 DIM modules.
26+
- **SoC support:** both dsPIC33AK128MC106 (128 KB flash / 16 KB RAM) and dsPIC33AK512MPS512 (512 KB flash / 64 KB RAM) devices.
27+
- **Driver coverage:** dsPIC33-specific pin control, GPIO, UART console, and system timer drivers.
28+
- **Basic services:** console output, logging back ends, and idle/power management.
29+
1830
Key supported features
1931
**********************
2032

92.2 KB
Loading

drivers/timer/mchp_dspic33_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void arch_busy_wait(uint32_t usec_to_wait)
9696
ARG_UNUSED(usec_to_wait);
9797
__asm__ volatile("sl.l w0,#0x03,w0\n\t"
9898
"repeat.w w0\n\t"
99-
"neop\n\n\t");
99+
"nop\n\n\t");
100100
}
101101
#endif
102102

0 commit comments

Comments
 (0)