Skip to content

Commit f743a39

Browse files
Release: v6.1
Additions: - Added the dsPIC33 architecture doc Fixes: - Fix SPLIM updation on swap - Fix test, thread self abort - Fix the philosophors build for 128k flash device - Fix stack overflow issue in main for tests - Fix base address and offset for interrupt controller in dts Signed-off-by: Muhammed Zamroodh <[email protected]>
1 parent 4c32f95 commit f743a39

File tree

24 files changed

+594
-84
lines changed

24 files changed

+594
-84
lines changed

arch/dspic/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ config DYNAMIC_INTERRUPTS
1717
config GEN_IRQ_START_VECTOR
1818
default 0
1919

20+
config ARCH_HAS_THREAD_ABORT
21+
default y
22+
23+
config ISR_STACK_SIZE
24+
default 128
25+
2026
config DSPIC33_IRQ_OFFLOAD_IRQ
2127
int "IRQ number for irq_offload()"
2228
default 34

arch/dspic/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ zephyr_library_sources(
1414
vector_table.S
1515
reset1.S
1616
irq_offload.c
17+
thread_abort.c
1718
)
1819

1920
zephyr_linker_sources(ROM_START SORT_KEY 0x00 vector_table.ld)

arch/dspic/core/fatal.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ volatile uint32_t reason, address;
1919
#define EXCEPTION_HANDLER __attribute__((interrupt, no_auto_psv, weak, naked))
2020
#define BUS_ERROR_MASK 0xF
2121
#define MATH_ERROR_MASK 0x1F
22+
#define STACK_ERROR_MASK 0x10
2223
#define GENERAL_TRAP_MASK 0x8000000Fu
2324

2425
void __attribute__((weak)) TRAPS_halt_on_error(void);
@@ -100,6 +101,15 @@ void EXCEPTION_HANDLER _MathErrorTrap(void)
100101
/** Stack error.**/
101102
void EXCEPTION_HANDLER _StackErrorTrap(void)
102103
{
104+
const char *name = k_thread_name_get(_current);
105+
106+
reason = INTCON1 & STACK_ERROR_MASK;
107+
address = PCTRAP;
108+
if (name == NULL) {
109+
name = "Unnamed";
110+
}
111+
LOG_ERR("ERROR !!! Exception reason = %d, address = 0x%x", reason, address);
112+
LOG_ERR("Thread : %p (%s)\n", _current, name);
103113
INTCON1bits.STKERR = 0;
104114
PCTRAP = 0;
105115
TRAPS_halt_on_error();

arch/dspic/core/isr_wrapper.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ __COMMONInterrupt:
5454
bra z,.L2
5555
ulnk
5656
CTXTSWP #0x0
57-
mov.l w0, [w15++]
58-
mov.l #RAM_END, w0
59-
mov.l w0, SPLIM
60-
mov.l [--w15], w0
6157
z_dspic_save_caller_saved
6258
z_dspic_save_callee_saved
6359

arch/dspic/core/thread_abort.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025, Microchip Technology Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* @file
8+
* @brief DSPIC k_thread_abort() routine
9+
*
10+
* thread abort needs to be called with IRQ locked, there is chance for the
11+
* thread to be switched out before it completes abort call. This can happen in
12+
* the event of a thread performing a self abort and an interrupt happens in
13+
* between.
14+
*/
15+
16+
#include <zephyr/kernel.h>
17+
#include <zephyr/toolchain.h>
18+
#include <zephyr/linker/sections.h>
19+
#include <kswap.h>
20+
#include <zephyr/sys/__assert.h>
21+
22+
void z_impl_k_thread_abort(k_tid_t thread)
23+
{
24+
struct k_spinlock lock;
25+
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_thread, abort, thread);
26+
27+
k_spinlock_key_t key = k_spin_lock(&lock);
28+
29+
z_thread_abort(thread);
30+
k_spin_unlock(&_sched_spinlock, key);
31+
32+
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_thread, abort, thread);
33+
}

arch/dspic/include/kernel_arch_swap_macro.S

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@
153153
sac.l B, [W1++]
154154
suac.l B, [W1++]
155155

156-
mov.l w15, [w1++]
157-
mov.l w14, [w1++]
158156
mov.l #SPLIM, w2
159157
mov.l [w2], [w1++]
158+
mov.l w15, [w1++]
159+
mov.l w14, [w1++]
160160
.endm
161161

162162
.macro z_dspic_restore_callee_saved
@@ -222,10 +222,10 @@
222222
lac.l [W1++], B
223223
luac.l [W1++], B
224224

225-
mov.l [w1++], w15
226-
mov.l [w1++], w14
227225
mov.l #SPLIM, w2
228226
mov.l [w1++], [w2]
227+
mov.l [w1++], w15
228+
mov.l [w1++], w14
229229
.endm
230230

231231
.macro z_dspic_temp_backup_working_reg
@@ -274,10 +274,6 @@
274274
/* Set the SPLIM to end of RAM
275275
* To avoid, stack overflow fault.
276276
*/
277-
mov.l w0, [w15++]
278-
mov.l #RAM_END, w0
279-
mov.l w0, SPLIM
280-
mov.l [--w15], w0
281277
/* Switch to context 0 before starting context save and restore
282278
* This Arch has 7 context and each has banked register sets for w0-w8
283279
* So in interrupt we are in ctx 1 and need to go to ctx 0 for tasks
Binary file not shown.
Binary file not shown.

boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp.license

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)