diff --git a/arch/dspic/core/CMakeLists.txt b/arch/dspic/core/CMakeLists.txt index 2e9dba116d1ee..cde4e1c12aa66 100644 --- a/arch/dspic/core/CMakeLists.txt +++ b/arch/dspic/core/CMakeLists.txt @@ -7,7 +7,7 @@ zephyr_library_sources( isr_wrapper.S prep_c.c thread.c - swap.c + swap.S tls.c reset0.S init.S diff --git a/arch/dspic/core/isr_wrapper.S b/arch/dspic/core/isr_wrapper.S index 0c278ec848d60..001801215bab0 100644 --- a/arch/dspic/core/isr_wrapper.S +++ b/arch/dspic/core/isr_wrapper.S @@ -4,15 +4,9 @@ */ #include #include +#include #define OFFSET DT_PROP(DT_NODELABEL(intc0), if_offset) -#if defined(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK512MPS512) -#define RAM_END 0x00013FFC -#elif defined(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK128MC106) -#define RAM_END 0x00007FFC -#endif - - .equ IF_OFFSET, OFFSET .section .text,code @@ -23,11 +17,13 @@ __COMMONInterrupt: .section .isr.text._COMMONInterrupt,keep,code,keep lnk #0x4 + /* Handle ISR calls and clear handles IRQ + */ mov.l w8, [w15++] - mov.sl #__kernel,w8 + mov.sl #__kernel + ___cpu_t_nested_OFFSET,w8 add.l [w8],#1,[w8] mov.w _INTTREGbits,w0 - and.l #(0x1ff&0xFFFF),w0 + and.l #0x1ff,w0 sub.l w0,#9,w0 mov.sl #__sw_isr_table,w1 sl.l w0,#3,w0 @@ -35,289 +31,74 @@ __COMMONInterrupt: mov.l [w2+4],w1 mov.l [w2],w0 - call w1 mov.w _INTTREGbits,w0 - and.l #(0x1ff&0xFFFF),w0 + and.l #0x1ff,w0 sub.l w0,#9,w0 call _arch_dspic_irq_clear - + /* Check and perform context switch + */ sub.l [w8],#1,w0 mov.l w0,[w8] + mov.l [--w15], w8 cp.l w0,#0 bra nz,.L2 - mov.sl #__kernel+20,w1 + mov.sl #__kernel + ___kernel_t_ready_q_OFFSET,w1 mov.l [w1],w1 - mov.sl #__kernel+8,w0 + mov.sl #__kernel + ___cpu_t_current_OFFSET,w0 mov.l [w0],w0 cp.l w1,w0 bra z,.L2 cp0.b _z_sys_post_kernel bra z,.L2 - mov.l [--w15], w8 ulnk CTXTSWP #0x0 mov.l w0, [w15++] mov.l #RAM_END, w0 mov.l w0, SPLIM - mov.l sr, w0 - and #0xe0, w0 - bra nz, 1f - mov.l [--w15], w0 - ulnk - mov.l w2, [w15++] - mov.l w1, [w15++] - mov.l w0, [w15++] - mov.l #_swap_working_set, w0 - mov.l [--w15], [w0++] - mov.l [--w15], [w0++] - mov.l [--w15], [w0] - mov.l [--w15], w1 - mov.l sr, [w15++] - mov.l w1, [w15++] - mov.l [w0--], w2 - mov.l [w0--], w1 - mov.l [w0], w0 - mov.l w0, [w15++] - 1: mov.l [--w15], w0 - push RCOUNT - push.l fsr - push.l fcr - mov.l w0, [w15++] - mov.l w1, [w15++] - mov.l w2, [w15++] - mov.l w3, [w15++] - mov.l w4, [w15++] - mov.l w5, [w15++] - mov.l w6, [w15++] - mov.l w7, [w15++] - push.l f0 - push.l f1 - push.l f2 - push.l f3 - push.l f4 - push.l f5 - push.l f6 - push.l f7 - lnk #0x4 - - mov.l #__kernel, w0 - mov.l #___cpu_t_current_OFFSET, w1 - add w0, w1, w1 - mov.l [w1], w2 - mov.l #___thread_t_callee_saved_OFFSET, w1 - add w2, w1, w1 + z_dspic_save_caller_saved + z_dspic_save_callee_saved - mov.l w8, [w1++] - mov.l w9, [w1++] - mov.l w10, [w1++] - mov.l w11, [w1++] - mov.l w12, [w1++] - mov.l w13, [w1++] - mov.l w14, [w1++] - mov.l f8, [w1++] - mov.l f9, [w1++] - mov.l f10, [w1++] - mov.l f11, [w1++] - mov.l f12, [w1++] - mov.l f13, [w1++] - mov.l f14, [w1++] - mov.l f15, [w1++] - mov.l f16, [w1++] - mov.l f17, [w1++] - mov.l f18, [w1++] - mov.l f19, [w1++] - mov.l f20, [w1++] - mov.l f21, [w1++] - mov.l f22, [w1++] - mov.l f23, [w1++] - mov.l f24, [w1++] - mov.l f25, [w1++] - mov.l f26, [w1++] - mov.l f27, [w1++] - mov.l f28, [w1++] - mov.l f29, [w1++] - mov.l f30, [w1++] - mov.l f31, [w1++] - mov.l #RCOUNT, w2 - mov.l [w2], [w1++] - mov.l #CORCON, w2 - mov.l [w2], [w1++] - mov.l #MODCON, w2 - mov.l [w2], [w1++] - mov.l #XMODSRT, w2 - mov.l [w2], [w1++] - mov.l #XMODEND, w2 - mov.l [w2], [w1++] - mov.l #YMODSRT, w2 - mov.l [w2], [w1++] - mov.l #YMODEND, w2 - mov.l [w2], [w1++] - mov.l #XBREV, w2 - mov.l [w2], [w1++] - slac.l A, [W1++] - sac.l A, [W1++] - suac.l A, [W1++] - slac.l B, [W1++] - sac.l B, [W1++] - suac.l B, [W1++] - mov.l w15, [w1++] - mov.l w14, [w1++] - mov.l #SPLIM, w2 - mov.l [w2], [w1++] + mov.l #__kernel_ready_q_cache_OFFSET, w2 + mov.l [w2], w2 + mov.l #__kernel_current_OFFSET, w1 + mov.l w2, [w1] - mov.sl #__kernel+20,w0 - mov.l [w0],w0 - mov.sl #__kernel,w1 - mov.l w0,[w1 + ___cpu_t_current_OFFSET] - mov.l [w0 + ___thread_t_tls_OFFSET],w0 - rcall __set_tls - - mov.l #__kernel, w0 - mov.l #___cpu_t_current_OFFSET, w1 - add w0, w1, w1 - mov.l [w1], w2 - mov.l #___thread_t_callee_saved_OFFSET, w1 - add w2, w1, w1 +#ifdef CONFIG_CURRENT_THREAD_USE_TLS + mov.l [w2 + ___thread_t_tls_OFFSET], w0 + rcall __set_tls +#endif - mov.l [w1++], w8 - mov.l [w1++], w9 - mov.l [w1++], w10 - mov.l [w1++], w11 - mov.l [w1++], w12 - mov.l [w1++], w13 - mov.l [w1++], w14 - mov.l [w1++], f8 - mov.l [w1++], f9 - mov.l [w1++], f10 - mov.l [w1++], f11 - mov.l [w1++], f12 - mov.l [w1++], f13 - mov.l [w1++], f14 - mov.l [w1++], f15 - mov.l [w1++], f16 - mov.l [w1++], f17 - mov.l [w1++], f18 - mov.l [w1++], f19 - mov.l [w1++], f20 - mov.l [w1++], f21 - mov.l [w1++], f22 - mov.l [w1++], f23 - mov.l [w1++], f24 - mov.l [w1++], f25 - mov.l [w1++], f26 - mov.l [w1++], f27 - mov.l [w1++], f28 - mov.l [w1++], f29 - mov.l [w1++], f30 - mov.l [w1++], f31 - mov.l #RCOUNT, w2 - mov.l [w1++], [w2] - mov.l #CORCON, w2 - mov.l [w1++], [w2] - mov.l #MODCON, w2 - mov.l [w1++], [w2] - mov.l #XMODSRT, w2 - mov.l [w1++], [w2] - mov.l #XMODEND, w2 - mov.l [w1++], [w2] - mov.l #YMODSRT, w2 - mov.l [w1++], [w2] - mov.l #YMODEND, w2 - mov.l [w1++], [w2] - mov.l #XBREV, w2 - mov.l [w1++], [w2] - clr A - clr B - llac.l [w1++], A - lac.l [w1++], A - luac.l [w1++], A - llac.l [w1++], B - lac.l [w1++], B - luac.l [w1++], B - mov.l [w1++], w15 - mov.l [w1++], w14 - mov.l #SPLIM, w2 - mov.l [w1++], [w2] + z_dspic_restore_callee_saved + z_dspic_restore_caller_saved - ulnk - pop.l f7 - pop.l f6 - pop.l f5 - pop.l f4 - pop.l f3 - pop.l f2 - pop.l f1 - pop.l f0 - mov.l [--w15], w7 - mov.l [--w15], w6 - mov.l [--w15], w5 - mov.l [--w15], w4 - mov.l [--w15], w3 - mov.l [--w15], w2 - mov.l [--w15], w1 - mov.l [--w15], w0 - pop.l fcr - pop.l fsr - pop RCOUNT - mov.l w0, [w15++] - mov.l sr, w0 - and #0xe0, w0 - mov.l [--w15], w0 - bra nz, 1f mov.l w2, [w15++] mov.l w1, [w15++] mov.l w0, [w15++] - mov.l #_swap_working_set, w0 - mov.l [--w15], [w0++] - mov.l [--w15], [w0++] - mov.l [--w15], [w0] - mov.l [--w15], w1 - mov.l [--w15], w2 - mov.l w2, sr - mov.l w1, [w15++] - mov.l [w0--], w2 - mov.l [w0--], w1 - mov.l [w0], w0 - lnk #0x4 - 1: - mov.l w2, [w15++] - mov.l w1, [w15++] - mov.l w0, [w15++] - mov.sl #__kernel, w0 - mov.l [w0 + ___cpu_t_current_OFFSET], w1 - mov.l #___thread_t_arch_OFFSET, w2 - add.l w2, w1, w1 - mov.l [w1 + ___thread_arch_t_swapped_from_thread_OFFSET], w0 + mov.sl #__kernel_current_OFFSET, w0 + mov.l [w0], w1 + mov.l [w1 + __thread_t_arch_swapped_from_thread_OFFSET], w0 mov.l #0, w2 cp.l w2, w0 mov.l [--w15], w0 - bra z, 1f - mov.l [w1 + ___thread_arch_t_swap_return_value_OFFSET], w0 - mov.l w2, [w1 + ___thread_arch_t_swapped_from_thread_OFFSET] - 1: + bra z, 2f + mov.l [w1 + __thread_t_arch_swap_return_value_OFFSET], w0 + mov.l w2, [w1 + __thread_t_arch_swapped_from_thread_OFFSET] + 2: mov.l [--w15], w1 mov.l [--w15], w2 nop retfie - - .L2: - mov.l [--w15], w8 ulnk -.L1: retfie - .section .text._arch_dspic_irq_clear,code - .align 4 - .global _arch_dspic_irq_clear ; export - .type _arch_dspic_irq_clear,@function -_arch_dspic_irq_clear: - +GTEXT(arch_dspic_irq_clear) +SECTION_FUNC(TEXT, arch_dspic_irq_clear) lnk #0 lsr.l w0,#5,w1 sl.l w1,#2,w1 diff --git a/arch/dspic/core/offsets/offsets.c b/arch/dspic/core/offsets/offsets.c index 08d68715feb95..822c9e9eb813f 100644 --- a/arch/dspic/core/offsets/offsets.c +++ b/arch/dspic/core/offsets/offsets.c @@ -7,6 +7,7 @@ #include #include +GEN_OFFSET_SYM(_thread_arch_t, cpu_level); GEN_OFFSET_SYM(_thread_arch_t, swap_return_value); GEN_OFFSET_SYM(_thread_arch_t, swapped_from_thread); diff --git a/arch/dspic/core/swap.S b/arch/dspic/core/swap.S new file mode 100644 index 0000000000000..692201f6b696f --- /dev/null +++ b/arch/dspic/core/swap.S @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025, Microchip Technology Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file swap.S + * + * @brief handles thread swap logic for dsPIC33A devices + */ +#include +#include +#include + + .equ NUM_TEMP_REGS, 12 + + .section .bss + .align 4 + .globl _swap_working_set +_swap_working_set: + .space NUM_TEMP_REGS*4 + +GTEXT(arch_swap) +SECTION_FUNC(TEXT, arch_swap) + + lnk #0x0 + mov.l w0, [w15++] + +#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING + rcall _z_thread_mark_switched_out +#endif + mov.l [--w15], w2 + + /* Get the kernel and thread structures + * w0 -> current _thread_t structure + */ + mov.l #__kernel_current_OFFSET, w0 + mov.l [w0], w1 + + mov.l w2, [w1 + __thread_t_arch_cpu_level_OFFSET] + + /*move -EAGAIN to the member (2s compliment of 11)*/ + mov.l #0xfffffff5, w2 + mov.l w2, [w1 + __thread_t_arch_swap_return_value_OFFSET] + mov.l #1, w2 + mov.l w2, [w1 + __thread_t_arch_swapped_from_thread_OFFSET] + + mov.l w1, w2 + mov.sl #__kernel_ready_q_cache_OFFSET, w0 + mov.l [w0], w1 + cp.l w1, w2 + bra z, 2f + + z_dspic_do_swap + 2: + + mov.l w1, [w15++] + mov.l w2, [w15++] + mov.l w0, [w15++] +#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING + rcall _z_thread_mark_switched_in +#endif + mov.sl #__kernel_current_OFFSET, w0 + mov.l [w0], w1 + + mov.l [w1 + __thread_t_arch_swapped_from_thread_OFFSET], w0 + cp.l w0, #0 + mov.l #0, w0 + mov.l w0, [w1 + __thread_t_arch_swapped_from_thread_OFFSET] + mov.l [--w15], w0 + bra z, 3f + + mov.l [w1 + __thread_t_arch_swap_return_value_OFFSET], w0 + 3: + mov.l [w1 + __thread_t_arch_cpu_level_OFFSET], w1 + cp.l w1, #0x0 + + bra z, 2f + bset.b 0x71, #0x7 + 2: + mov.l [--w15], w2 + mov.l [--w15], w1 + ulnk + return diff --git a/arch/dspic/core/swap.c b/arch/dspic/core/swap.c deleted file mode 100644 index 49be36e8c28b7..0000000000000 --- a/arch/dspic/core/swap.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2025, Microchip Technology Inc. - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include "kswap.h" - -int swap_working_set[NUM_TEMP_REGS]; - -int arch_swap(unsigned int key) -{ -#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING - z_thread_mark_switched_out(); -#endif - - register int result __asm__("w0"); - /* store off key and return value */ - _current->arch.cpu_level = key; - _current->arch.swap_return_value = -EAGAIN; - _current->arch.swapped_from_thread = 1; - result = _current->arch.swap_return_value; - - /*Check if swap is needed*/ - if (_kernel.ready_q.cache != _current) { - z_dspic_do_swap(); - } - -#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING - z_thread_mark_switched_in(); -#endif - - /* This arch has only one SP and dosent use any kernel call style ABI - * Which means a return will pollute the next stacks working reg (w0-w4) - * Adding a hack here to return w0 without modification - * TODO: analyse the use of return value from arch_swap - * Make sure the return value is not being intrepreted - * wrongly - */ - __asm__ volatile( - "mov.l w1, [w15++]\n\t" - "mov.l w2, [w15++]\n\t" - ); - _current->arch.swapped_from_thread = 0; - result = _current->arch.swap_return_value; - irq_unlock(_current->arch.cpu_level); - __asm__ volatile( - "mov.l [--w15], w2\n\t" - "mov.l [--w15], w1\n\t" - ); - return result; - - /* Context switch is performed here. Returning implies the - * thread has been context-switched-in again. - */ -} diff --git a/arch/dspic/include/kernel_arch_swap.h b/arch/dspic/include/kernel_arch_swap.h deleted file mode 100644 index 8a44a4e7e28e2..0000000000000 --- a/arch/dspic/include/kernel_arch_swap.h +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright (c) 2025, Microchip Technology Inc. - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Private kernel arch swap functions - * - * This file contains function helpers for dspic arch specific thread swap - * helper functions - */ - -#ifndef ZEPHYR_ARCH_DSPIC_INCLUDE_KERNEL_ARCH_SWAP_H_ -#define ZEPHYR_ARCH_DSPIC_INCLUDE_KERNEL_ARCH_SWAP_H_ - -#ifndef _ASMLANGUAGE - -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#include "kswap.h" - -#if defined(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK512MPS512) -#define RAM_END "0x00013FFC" -#elif defined(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK128MC106) -#define RAM_END "0x00007FFC" -#endif - - -#define NUM_TEMP_REGS 3 -extern int swap_working_set[NUM_TEMP_REGS]; - -static inline __attribute__((always_inline)) void z_dspic_save_context(void) -{ - /*Adjust stack for co-operative swap*/ - __asm__ volatile( - /*Check if in interrupt context*/ - "mov.l w0, [w15++]\n\t" - "mov.l #"RAM_END", w0\n\t" - "mov.l w0, SPLIM\n\t" - "mov.l sr, w0\n\t" - "and #0xe0, w0\n\t" - "bra nz, 1f\n\t" - - /*Not in interrupt context*/ - "mov.l [--w15], w0\n\t" - /*This unlink is needed to match esf*/ - "ulnk\n\t" - /*Backup the working reg W0-W2*/ - "mov.l w2, [w15++]\n\t" - "mov.l w1, [w15++]\n\t" - "mov.l w0, [w15++]\n\t" - "mov.l #_swap_working_set, w0\n\t" - "mov.l [--w15], [w0++]\n\t" - "mov.l [--w15], [w0++]\n\t" - "mov.l [--w15], [w0]\n\t" - /*Format SR and LR as its from interrupt*/ - "mov.l [--w15], w1\n\t" - "mov.l sr, [w15++]\n\t" - "mov.l w1, [w15++]\n\t" - "mov.l [w0--], w2\n\t" - "mov.l [w0--], w1\n\t" - "mov.l [w0], w0\n\t" - "mov.l w0, [w15++]\n\t" - - "1:\n\t" - "mov.l [--w15], w0\n\t" - "push RCOUNT\n\t" - "push.l fsr\n\t" - "push.l fcr\n\t" - "mov.l w0, [w15++]\n\t" - "mov.l w1, [w15++]\n\t" - "mov.l w2, [w15++]\n\t" - "mov.l w3, [w15++]\n\t" - "mov.l w4, [w15++]\n\t" - "mov.l w5, [w15++]\n\t" - "mov.l w6, [w15++]\n\t" - "mov.l w7, [w15++]\n\t" - "push.l f0\n\t" - "push.l f1\n\t" - "push.l f2\n\t" - "push.l f3\n\t" - "push.l f4\n\t" - "push.l f5\n\t" - "push.l f6\n\t" - "push.l f7\n\t" - "lnk #0x4\n\t"); - /*in isr lnk is done after esf push*/ - - /* Get the current thread callee_saved context - */ - __asm__ volatile("mov.l #__kernel, w0\n\t" - "mov.l #___cpu_t_current_OFFSET, w1\n\t" - "add w0, w1, w1\n\t" - "mov.l [w1], w2\n\t" - "mov.l #___thread_t_callee_saved_OFFSET, w1\n\t" - "add w2, w1, w1\n\t"); - - /*Save all callee saved registers*/ - __asm__ volatile("mov.l w8, [w1++]\n\t" - "mov.l w9, [w1++]\n\t" - "mov.l w10, [w1++]\n\t" - "mov.l w11, [w1++]\n\t" - "mov.l w12, [w1++]\n\t" - "mov.l w13, [w1++]\n\t" - "mov.l w14, [w1++]\n\t" - - "mov.l f8, [w1++]\n\t" - "mov.l f9, [w1++]\n\t" - "mov.l f10, [w1++]\n\t" - "mov.l f11, [w1++]\n\t" - "mov.l f12, [w1++]\n\t" - "mov.l f13, [w1++]\n\t" - "mov.l f14, [w1++]\n\t" - "mov.l f15, [w1++]\n\t" - "mov.l f16, [w1++]\n\t" - "mov.l f17, [w1++]\n\t" - "mov.l f18, [w1++]\n\t" - "mov.l f19, [w1++]\n\t" - "mov.l f20, [w1++]\n\t" - "mov.l f21, [w1++]\n\t" - "mov.l f22, [w1++]\n\t" - "mov.l f23, [w1++]\n\t" - "mov.l f24, [w1++]\n\t" - "mov.l f25, [w1++]\n\t" - "mov.l f26, [w1++]\n\t" - "mov.l f27, [w1++]\n\t" - "mov.l f28, [w1++]\n\t" - "mov.l f29, [w1++]\n\t" - "mov.l f30, [w1++]\n\t" - "mov.l f31, [w1++]\n\t" - - "mov.l #RCOUNT, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #CORCON, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #MODCON, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #XMODSRT, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #XMODEND, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #YMODSRT, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #YMODEND, w2\n\t" - "mov.l [w2], [w1++]\n\t" - "mov.l #XBREV, w2\n\t" - "mov.l [w2], [w1++]\n\t" - - "slac.l A, [W1++]\n\t" - "sac.l A, [W1++]\n\t" - "suac.l A, [W1++]\n\t" - "slac.l B, [W1++]\n\t" - "sac.l B, [W1++]\n\t" - "suac.l B, [W1++]\n\t" - - "mov.l w15, [w1++]\n\t" - "mov.l w14, [w1++]\n\t" - "mov.l #SPLIM, w2\n\t" - "mov.l [w2], [w1++]\n\t"); -} - -static inline __attribute__((always_inline)) void z_dspic_restore_context(void) -{ - /* Get the current thread callee_saved context - */ - __asm__ volatile("mov.l #__kernel, w0\n\t" - "mov.l #___cpu_t_current_OFFSET, w1\n\t" - "add w0, w1, w1\n\t" - "mov.l [w1], w2\n\t" - "mov.l #___thread_t_callee_saved_OFFSET, w1\n\t" - "add w2, w1, w1\n\t"); - - /*Restore all registers*/ - __asm__ volatile("mov.l [w1++], w8\n\t" - "mov.l [w1++], w9\n\t" - "mov.l [w1++], w10\n\t" - "mov.l [w1++], w11\n\t" - "mov.l [w1++], w12\n\t" - "mov.l [w1++], w13\n\t" - "mov.l [w1++], w14\n\t" - - "mov.l [w1++], f8\n\t" - "mov.l [w1++], f9\n\t" - "mov.l [w1++], f10\n\t" - "mov.l [w1++], f11\n\t" - "mov.l [w1++], f12\n\t" - "mov.l [w1++], f13\n\t" - "mov.l [w1++], f14\n\t" - "mov.l [w1++], f15\n\t" - "mov.l [w1++], f16\n\t" - "mov.l [w1++], f17\n\t" - "mov.l [w1++], f18\n\t" - "mov.l [w1++], f19\n\t" - "mov.l [w1++], f20\n\t" - "mov.l [w1++], f21\n\t" - "mov.l [w1++], f22\n\t" - "mov.l [w1++], f23\n\t" - "mov.l [w1++], f24\n\t" - "mov.l [w1++], f25\n\t" - "mov.l [w1++], f26\n\t" - "mov.l [w1++], f27\n\t" - "mov.l [w1++], f28\n\t" - "mov.l [w1++], f29\n\t" - "mov.l [w1++], f30\n\t" - "mov.l [w1++], f31\n\t" - - "mov.l #RCOUNT, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #CORCON, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #MODCON, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #XMODSRT, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #XMODEND, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #YMODSRT, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #YMODEND, w2\n\t" - "mov.l [w1++], [w2]\n\t" - "mov.l #XBREV, w2\n\t" - "mov.l [w1++], [w2]\n\t" - - "clr A\n\t" - "clr B\n\t" - "llac.l [w1++], A\n\t" - "lac.l [w1++], A\n\t" - "luac.l [w1++], A\n\t" - "llac.l [w1++], B\n\t" - "lac.l [w1++], B\n\t" - "luac.l [w1++], B\n\t" - - "mov.l [w1++], w15\n\t" - "mov.l [w1++], w14\n\t" - "mov.l #SPLIM, w2\n\t" - "mov.l [w1++], [w2]\n\t"); - - /*pop exception/swap saved stack frame*/ - __asm__ volatile( - /*in isr the unlink is done before esf pop*/ - "ulnk\n\t" - /*Thread context*/ - "pop.l f7\n\t" - "pop.l f6\n\t" - "pop.l f5\n\t" - "pop.l f4\n\t" - "pop.l f3\n\t" - "pop.l f2\n\t" - "pop.l f1\n\t" - "pop.l f0\n\t" - "mov.l [--w15], w7\n\t" - "mov.l [--w15], w6\n\t" - "mov.l [--w15], w5\n\t" - "mov.l [--w15], w4\n\t" - "mov.l [--w15], w3\n\t" - "mov.l [--w15], w2\n\t" - "mov.l [--w15], w1\n\t" - "mov.l [--w15], w0\n\t" - "pop.l fcr\n\t" - "pop.l fsr\n\t" - "pop RCOUNT\n\t" - - /* Check context and only pop the - * esf if in thread context - */ - "mov.l w0, [w15++]\n\t" - "mov.l sr, w0\n\t" - "and #0xe0, w0\n\t" - "mov.l [--w15], w0\n\t" - "bra nz, 1f\n\t" - - /*Backup the working reg W0-W2*/ - "mov.l w2, [w15++]\n\t" - "mov.l w1, [w15++]\n\t" - "mov.l w0, [w15++]\n\t" - "mov.l #_swap_working_set, w0\n\t" - "mov.l [--w15], [w0++]\n\t" - "mov.l [--w15], [w0++]\n\t" - "mov.l [--w15], [w0]\n\t" - /*Format SR and LR as its from interrupt*/ - "mov.l [--w15], w1\n\t" - "mov.l [--w15], w2\n\t" - "mov.l w2, sr\n\t" - "mov.l w1, [w15++]\n\t" - "mov.l [w0--], w2\n\t" - "mov.l [w0--], w1\n\t" - "mov.l [w0], w0\n\t" - - "lnk #0x4\n\t" - - /*Interrupt context*/ - "1:\n\t" - "nop\n\t"); -} - -/* routine which swaps the context. Needs to be written in assembly */ -static inline __attribute__((always_inline)) void z_dspic_do_swap(void) -{ - /* Switch to context 0 before starting context save and restore - * This Arch has 7 context and each has banked register sets for w0-w8 - * So in interrupt we are in ctx 1 and need to go to ctx 0 for tasks - */ - __asm__ volatile("CTXTSWP #0x0"); - - z_dspic_save_context(); - - /*Switch to next task in queue*/ - z_current_thread_set(_kernel.ready_q.cache); - - /* It is expected to save current thread's pointer on z_tls_current - * variable because k_current_get() call will get the current thread's - * pointer from this variable if the CONFIG_CURRENT_THREAD_USE_TLS - * is enabled. In ztest k_thread_abort() was trying to abort the - * current thread. - */ -#ifdef CONFIG_CURRENT_THREAD_USE_TLS - /* Thread-local cache of current thread ID, set in z_thread_entry() */ - _set_tls((void *)_current->tls); -#endif - - z_dspic_restore_context(); -} - -#ifdef __cplusplus -} -#endif - -#endif /* _ASMLANGUAGE */ - -#endif /* ZEPHYR_ARCH_DSPIC_INCLUDE_KERNEL_ARCH_SWAP_H_ */ diff --git a/arch/dspic/include/kernel_arch_swap_macro.S b/arch/dspic/include/kernel_arch_swap_macro.S new file mode 100644 index 0000000000000..405a4b524c699 --- /dev/null +++ b/arch/dspic/include/kernel_arch_swap_macro.S @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2025, Microchip Technology Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Private kernel arch swap functions + * + * This file contains function helpers for dspic arch specific thread swap + * helper functions + */ + +#ifndef ZEPHYR_ARCH_DSPIC_INCLUDE_KERNEL_ARCH_SWAP_H_ +#define ZEPHYR_ARCH_DSPIC_INCLUDE_KERNEL_ARCH_SWAP_H_ + +#include +#include + +#if defined(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK512MPS512) +#define RAM_END 0x00013FFC +#elif defined(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK128MC106) +#define RAM_END 0x00007FFC +#endif + +#if defined(_ASMLANGUAGE) + +.equ __kernel_current_OFFSET, __kernel + ___cpu_t_current_OFFSET +.equ __thread_t_arch_cpu_level_OFFSET, ___thread_t_arch_OFFSET + ___thread_arch_t_cpu_level_OFFSET +.equ __kernel_ready_q_cache_OFFSET, __kernel + ___kernel_t_ready_q_OFFSET + \ + ___ready_q_t_cache_OFFSET +.equ __thread_t_arch_swap_return_value_OFFSET, ___thread_t_arch_OFFSET + \ + ___thread_arch_t_swap_return_value_OFFSET +.equ __thread_t_arch_swapped_from_thread_OFFSET, ___thread_t_arch_OFFSET + \ + ___thread_arch_t_swapped_from_thread_OFFSET + +.extern _swap_working_set + +.macro z_dspic_save_caller_saved + push RCOUNT + push.l fsr + push.l fcr + mov.l w0, [w15++] + mov.l w1, [w15++] + mov.l w2, [w15++] + mov.l w3, [w15++] + mov.l w4, [w15++] + mov.l w5, [w15++] + mov.l w6, [w15++] + mov.l w7, [w15++] + push.l f0 + push.l f1 + push.l f2 + push.l f3 + push.l f4 + push.l f5 + push.l f6 + push.l f7 + lnk #0x4 +.endm + +.macro z_dspic_restore_caller_saved + ulnk + pop.l f7 + pop.l f6 + pop.l f5 + pop.l f4 + pop.l f3 + pop.l f2 + pop.l f1 + pop.l f0 + mov.l [--w15], w7 + mov.l [--w15], w6 + mov.l [--w15], w5 + mov.l [--w15], w4 + mov.l [--w15], w3 + mov.l [--w15], w2 + mov.l [--w15], w1 + mov.l [--w15], w0 + pop.l fcr + pop.l fsr + pop RCOUNT +.endm + +.macro z_dspic_get_current_callee_saved + /* Get the current thread callee_saved context + * and store it in w1 + */ + mov.l #__kernel, w0 + mov.l [w0 + ___cpu_t_current_OFFSET], w2 + mov.l #___thread_t_callee_saved_OFFSET, w1 + add w2, w1, w1 +.endm + +.macro z_dspic_save_callee_saved + z_dspic_get_current_callee_saved + + /*Save all callee saved registers*/ + mov.l w8, [w1++] + mov.l w9, [w1++] + mov.l w10, [w1++] + mov.l w11, [w1++] + mov.l w12, [w1++] + mov.l w13, [w1++] + mov.l w14, [w1++] + + mov.l f8, [w1++] + mov.l f9, [w1++] + mov.l f10, [w1++] + mov.l f11, [w1++] + mov.l f12, [w1++] + mov.l f13, [w1++] + mov.l f14, [w1++] + mov.l f15, [w1++] + mov.l f16, [w1++] + mov.l f17, [w1++] + mov.l f18, [w1++] + mov.l f19, [w1++] + mov.l f20, [w1++] + mov.l f21, [w1++] + mov.l f22, [w1++] + mov.l f23, [w1++] + mov.l f24, [w1++] + mov.l f25, [w1++] + mov.l f26, [w1++] + mov.l f27, [w1++] + mov.l f28, [w1++] + mov.l f29, [w1++] + mov.l f30, [w1++] + mov.l f31, [w1++] + + mov.l #RCOUNT, w2 + mov.l [w2], [w1++] + mov.l #CORCON, w2 + mov.l [w2], [w1++] + mov.l #MODCON, w2 + mov.l [w2], [w1++] + mov.l #XMODSRT, w2 + mov.l [w2], [w1++] + mov.l #XMODEND, w2 + mov.l [w2], [w1++] + mov.l #YMODSRT, w2 + mov.l [w2], [w1++] + mov.l #YMODEND, w2 + mov.l [w2], [w1++] + mov.l #XBREV, w2 + mov.l [w2], [w1++] + + slac.l A, [W1++] + sac.l A, [W1++] + suac.l A, [W1++] + slac.l B, [W1++] + sac.l B, [W1++] + suac.l B, [W1++] + + mov.l w15, [w1++] + mov.l w14, [w1++] + mov.l #SPLIM, w2 + mov.l [w2], [w1++] +.endm + +.macro z_dspic_restore_callee_saved + z_dspic_get_current_callee_saved + + /*restore all callee saved registers*/ + mov.l [w1++], w8 + mov.l [w1++], w9 + mov.l [w1++], w10 + mov.l [w1++], w11 + mov.l [w1++], w12 + mov.l [w1++], w13 + mov.l [w1++], w14 + + mov.l [w1++], f8 + mov.l [w1++], f9 + mov.l [w1++], f10 + mov.l [w1++], f11 + mov.l [w1++], f12 + mov.l [w1++], f13 + mov.l [w1++], f14 + mov.l [w1++], f15 + mov.l [w1++], f16 + mov.l [w1++], f17 + mov.l [w1++], f18 + mov.l [w1++], f19 + mov.l [w1++], f20 + mov.l [w1++], f21 + mov.l [w1++], f22 + mov.l [w1++], f23 + mov.l [w1++], f24 + mov.l [w1++], f25 + mov.l [w1++], f26 + mov.l [w1++], f27 + mov.l [w1++], f28 + mov.l [w1++], f29 + mov.l [w1++], f30 + mov.l [w1++], f31 + + mov.l #RCOUNT, w2 + mov.l [w1++], [w2] + mov.l #CORCON, w2 + mov.l [w1++], [w2] + mov.l #MODCON, w2 + mov.l [w1++], [w2] + mov.l #XMODSRT, w2 + mov.l [w1++], [w2] + mov.l #XMODEND, w2 + mov.l [w1++], [w2] + mov.l #YMODSRT, w2 + mov.l [w1++], [w2] + mov.l #YMODEND, w2 + mov.l [w1++], [w2] + mov.l #XBREV, w2 + mov.l [w1++], [w2] + + clr A + clr B + llac.l [W1++], A + lac.l [W1++], A + luac.l [W1++], A + llac.l [W1++], B + lac.l [W1++], B + luac.l [W1++], B + + mov.l [w1++], w15 + mov.l [w1++], w14 + mov.l #SPLIM, w2 + mov.l [w1++], [w2] +.endm + +.macro z_dspic_temp_backup_working_reg + /*Backup the working reg W0-W2*/ + mov.l w2, [w15++] + mov.l w1, [w15++] + mov.l w0, [w15++] + mov.l #_swap_working_set, w0 + mov.l [--w15], [w0++] + mov.l [--w15], [w0++] + mov.l [--w15], [w0] +.endm + +.macro z_dspic_restore_working_reg + mov.l [w0--], w2 + mov.l [w0--], w1 + mov.l [w0], w0 +.endm + +.macro z_dspic_stack_thread_to_irq + ulnk + /*backup the working reg w0-w2*/ + z_dspic_temp_backup_working_reg + /*Format SR and LR as its from interrupt*/ + mov.l [--w15], w1 + mov.l sr, [w15++] + mov.l w1, [w15++] + /*restore the working reg w0-w2*/ + z_dspic_restore_working_reg +.endm + +.macro z_dspic_stack_irq_to_thread + /*backup the working reg w0-w2*/ + z_dspic_temp_backup_working_reg + /*Format SR and LR as its from interrupt*/ + mov.l [--w15], w1 + mov.l [--w15], w2 + mov.l w2, sr + mov.l w1, [w15++] + /*restore the working reg w0-w2*/ + z_dspic_restore_working_reg + lnk #0x4 +.endm + +.macro z_dspic_do_swap + /* Set the SPLIM to end of RAM + * To avoid, stack overflow fault. + */ + mov.l w0, [w15++] + mov.l #RAM_END, w0 + mov.l w0, SPLIM + mov.l [--w15], w0 + /* Switch to context 0 before starting context save and restore + * This Arch has 7 context and each has banked register sets for w0-w8 + * So in interrupt we are in ctx 1 and need to go to ctx 0 for tasks + */ + ctxtswp #0x0 + + /* Save the current context + */ + z_dspic_stack_thread_to_irq + z_dspic_save_caller_saved + z_dspic_save_callee_saved + + /* Switch to next task in queue + * No need to save and restore working registers here + * */ + mov.l #__kernel_ready_q_cache_OFFSET, w2 + mov.l [w2], w2 + mov.l #__kernel_current_OFFSET, w1 + mov.l w2, [w1] + +#ifdef CONFIG_CURRENT_THREAD_USE_TLS + /*Switch the TLS pointer for the task to be swapped*/ + mov.l [w2 + ___thread_t_tls_OFFSET], w0 + rcall __set_tls +#endif + + /* Restore next thread context + */ + z_dspic_restore_callee_saved + z_dspic_restore_caller_saved + z_dspic_stack_irq_to_thread +.endm + +#endif /* _ASMLANGUAGE */ + +#endif /* ZEPHYR_ARCH_DSPIC_INCLUDE_KERNEL_ARCH_SWAP_H_ */ diff --git a/boards/microchip/dspic33/dspic33a_curiosity/board.yml b/boards/microchip/dspic33/dspic33a_curiosity/board.yml index 412a13838177c..85e0b848fffab 100644 --- a/boards/microchip/dspic33/dspic33a_curiosity/board.yml +++ b/boards/microchip/dspic33/dspic33a_curiosity/board.yml @@ -4,5 +4,4 @@ board: vendor: microchip socs: - name: p33ak128mc106 - - name: p33ak256mc506 - name: p33ak512mps512 diff --git a/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK128MC106.webp b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK128MC106.webp new file mode 100644 index 0000000000000..0bf4c782b2464 Binary files /dev/null and b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK128MC106.webp differ diff --git a/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp new file mode 100644 index 0000000000000..f7625cd19357e Binary files /dev/null and b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp differ diff --git a/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp.license b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp.license new file mode 100644 index 0000000000000..917f5636f5564 --- /dev/null +++ b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/dsPIC33AK512MPS512.webp.license @@ -0,0 +1,4 @@ +** +* Copyright (c) 2025, Microchip Technology Inc. +* SPDX-License-Identifier: Apache-2.0 +*/ \ No newline at end of file diff --git a/boards/microchip/dspic33/dspic33a_curiosity/doc/img/ev74h48a.webp b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/ev74h48a.webp new file mode 100644 index 0000000000000..f61a8b895fe02 Binary files /dev/null and b/boards/microchip/dspic33/dspic33a_curiosity/doc/img/ev74h48a.webp differ diff --git a/boards/microchip/dspic33/dspic33a_curiosity/doc/index.rst b/boards/microchip/dspic33/dspic33a_curiosity/doc/index.rst new file mode 100644 index 0000000000000..30b2adeb89780 --- /dev/null +++ b/boards/microchip/dspic33/dspic33a_curiosity/doc/index.rst @@ -0,0 +1,207 @@ +.. zephyr:board:: dspic33a_curiosity + +Overview +******** + +The Curiosity Platform Development Board (EV74H48A) is a +full-featured development and demonstration platform enabling +customers to explore the capabilities of the dsPIC33A Digital +Signal Controller (DSC) family and also the PIC32A MCU family. +This board requires a DIM (Daughter Interface Module): +dsPIC33AK128MC106 or dsPIC33AK512MPS512 + +Hardware +******** + + - Baseboard + - dsPIC33A Curiosity Board + - Supported DIM Modules + - dsPIC33AK128MC106 + - dsPIC33AK512MPS512 + +dsPIC33AK128MC106 + - High-Performance dsPIC33A DSP CPU + - 16-bit dsPIC33 core compatible + - Non-paged linear Data/Flash 24-bit addressing space + - 16-bit/32-bit instructions for optimized code size and performance + - 32-bit Working Registers + - Program flash: 128 KB + - RAM: 16KB + - 3 Instances of UARTs + - One Dedicated 32-bit Timer/Counter + - Four Single Output Capture/Compare/PWM/Timer (SCCP) Modules + - The POSC and Internal FRC oscillators can use the on-chip PLL to achieve higher operating speeds. + +dsPIC33AK512MPS512 + - High-Performance dsPIC33A DSP CPU + - 16-bit dsPIC33 core compatible + - Linear 24-bit program/data memory addressing space (no paging required) + - 16-bit/32-bit instructions for optimized code size and performance + - 32-bit Working Registers + - Program flash: 512 KB + - RAM: 64KB + - 3 Instances of UARTs + - Three Dedicated 32-Bit Timers/Counters + - Single (SCCP) and Multiple (MCCP) Output Capture/Compare/PWM/Timer Modules + - Two 1.6 GHz PLLs for Peripheral which can be clocked from the FRC or a Crystal Oscillator + +For more information about the Baseboard please see `Curiosity Platform Development Board User's Guide`_ +For more information about the dsPIC33AK128MC106 please see `dsPIC33AK128MC106 Family Data Sheet`_ +For more information about the dsPIC33AK512MPS512 please see `dsPIC33AK512MPS512 Family Data Sheet`_ + +Supported Features +================== + +.. zephyr:board-supported-hw:: + +Connections and IOs +=================== +The dsPIC33A Curiosity board requires one of the following: dsPIC33AK128MC106 or dsPIC33AK512MPS512 + + - Insert the appropriate DIM board into the 120-pin socket, ensuring correct orientation. + - Connect the Curiosity board to the host PC via USB. + - Power and programming are handled through the on-board PKOB debugger. + - Remove the jumper ``J28`` to enable the debugger. + - ``J25`` is a 3-pin jumper used to choose the power source for the board. + Place the jumper on pins 1-2 to use USB power (5V_USB). + +System Clock +============ + - The dsPIC33AK128MC106/dsPIC33AK512MPS512 uses its internal 8 MHz FRC oscillator as the default clock source. + - They also support multiple clock sources and an on-chip PLL, allowing the system and peripherals to operate at higher performance levels. + - Peripheral clocks (Fast, Standard, Slow) are derived via fixed divisors. + - See Processor clock control register in chapter ``oscillator module`` of the data sheet. + +Serial Port +=========== + - The dsPIC33A Curiosity board provides a UART interface for console output and communication with a PC. + - The serial interface can be accessed through the baseboard's DIM connector: + - UART1 is configured for serial logs. + - Pin 102 on base board USB to UART Converter TX + - Pin 100 on base board USB to UART Converter RX + +For more information about the DIM pins please see `dsPIC33AK128MC106 DIM schematics`_ `dsPIC33AK512MPS512 DIM schematics`_ + +ToolChain Setup +=============== + - Download and install the latest ``MPLABXIDE`` where you get the ``XC-DSC`` compiler from Microchip + - Go to the official Microchip MPLAB X IDE please see `MPLABxIDE Installation`_ + - The XC-DSC toolchain is not part of the Zephyr SDK by default, + so the path to the compiler must be added manually. + +Setting the Toolchain Variant +============================= + - Zephyr uses the variable :makevar:`ZEPHYR_TOOLCHAIN_VARIANT` to select which + toolchain to use. For this board, the variant name is ``xcdsc``. + + - To specify it on the command line: + + .. code-block:: console + + west build -b dspic33a_curiosity/ samples/hello_world -- -DZEPHYR_TOOLCHAIN_VARIANT=xcdsc + +Setting the Toolchain Path +========================== +#. The XC-DSC compiler must be installed separately from Zephyr. The installation + directory should be provided using the :makevar:`ZEPHYR_TOOLCHAIN_PATH` variable. + +#. Typical installation paths are: + +- **Windows**: ``C:\Program Files\Microchip\xc-dsc\`` +- **Linux**: ``/opt/microchip/xc16/`` + +#. To specify it on the command line: + + .. code-block:: console + + west build -p always -b dspic33a_curiosity/ samples/hello_world/ -- -DZEPHYR_TOOLCHAIN_VARIANT=xcdsc -DXCDSC_TOOLCHAIN_PATH=/opt/microchip/xc-dsc/ + +Building +======== + +#. Build :zephyr:code-sample:`hello_world` application as you normally do. + +#. After a successful build, the following files are produced: + build/zephyr/zephyr.elf this will be used to flash + +#. To build sample on the command line: + + .. code-block:: console + + west build -p always -b dspic33a_curiosity/ samples/hello_world/ -- -DZEPHYR_TOOLCHAIN_VARIANT=xcdsc -DXCDSC_TOOLCHAIN_PATH=/opt/microchip/xc-dsc/ + +Flashing +======== +#. Run your favorite terminal program to listen for output. + Under Linux the terminal should be :code:`/dev/ttyACM1`. + + For example: + + .. code-block:: console + + $ minicom -D /dev/ttyACM1 -o + + The -o option tells minicom not to send the modem initialization + string. Connection should be configured as follows: + + - Speed: 115200 + - Data: 8 bits + - Parity: None + - Stop bits: 1 + +#. Flash your board using ``west`` from the second terminal window. + Split first and second terminal windows to view both of them. + + .. code-block:: console + + $ west flash + +#. You should see ``"Hello World! "`` in the first terminal window. + If you don't see this message, press the Reset button and the message should appear. + +Debugging +========= +#. This board supports application flashing and debugging + using the Microchip Debugger (MDB) command-line tool, which is part of the + MPLAB X installation. + +#. MDB can be used to program and debug Zephyr applications through a simple + command's executed in a terminal. + + .. code-block:: console + + $ mdb + - Device dsPIC33AK128MC106 + - Hwtool pkob4 + - Program build/zephyr/zephyr.elf + - run + - quit + +#. The commands performs the following actions + + - Connects to the target device (dsPIC33AK128MC106). + - Loads the hardware debugger (PKOB4). + - Programs the compiled Zephyr ELF binary. + - Starts program execution on the target. + - Exits the debugger session. + +For more information about MDB please see `Microchip Debugger (MDB) User's Guide`_ + +References +********** +.. target-notes:: + +.. _Curiosity Platform Development Board User's Guide: + https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/UserGuides/Curiosity-Platform-Development-Board-Users-Guide-DS70005562.pdf +.. _dsPIC33AK128MC106 Family Data Sheet: + https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/DataSheets/dsPIC33AK128MC106-Family-Data-Sheet-DS70005539.pdf +.. _dsPIC33AK128MC106 DIM schematics: + https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/InformationSheet/dsPIC33AK128MC106-General-Purpose-DIM-Info-Sheet-DS70005556.pdf +.. _dsPIC33AK512MPS512 Family Data Sheet: + https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/DataSheets/dsPIC33AK512MPS512-Family-Data-Sheet-DS70005591.pdf +.. _dsPIC33AK512MPS512 DIM schematics: + https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/InformationSheet/dsPIC33AK512MPS512-General-Purpose-DIM-Info-Sheet-DS70005563.pdf +.. _MPLABxIDE Installation : + https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide +.. _Microchip Debugger (MDB) User's Guide: + https://www.microchip.com/content/dam/mchp/documents/DEV/ProductDocuments/UserGuides/50002102G.pdf diff --git a/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc106.dts b/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc106.dts index ff347435c1628..d6f010061b845 100644 --- a/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc106.dts +++ b/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc106.dts @@ -80,7 +80,6 @@ }; &timer1 { - clock-frequency = <8000000>; status = "okay"; }; diff --git a/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc506.dts b/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc506.dts deleted file mode 100644 index 9213a07beb6d8..0000000000000 --- a/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak128mc506.dts +++ /dev/null @@ -1 +0,0 @@ -/*Nothing here */ diff --git a/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak512mps512.dts b/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak512mps512.dts index 143b68997098b..c57d41379610e 100644 --- a/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak512mps512.dts +++ b/boards/microchip/dspic33/dspic33a_curiosity/dspic33a_curiosity_p33ak512mps512.dts @@ -79,7 +79,6 @@ }; &timer1 { - clock-frequency = <8000000>; status = "okay"; }; diff --git a/cmake/compiler/xcdsc/generic.cmake b/cmake/compiler/xcdsc/generic.cmake index 043f88a5fd6bd..38f036d22ba2a 100644 --- a/cmake/compiler/xcdsc/generic.cmake +++ b/cmake/compiler/xcdsc/generic.cmake @@ -35,7 +35,7 @@ function(find_dspic33_dfp) set(_home "$ENV{HOME}") if(WIN32 AND NOT _home) set(_home "$ENV{USERPROFILE}") - file(TO_CMAKE_PATH "${_home}" _home) + file(TO_CMAKE_PATH "${_home}" _home) endif() # Root search list: HOME first (highest priority), then system roots @@ -155,24 +155,24 @@ function(find_dspic33_dfp) set(${FD_OUT_ROOT} "${DFP_ROOT}" PARENT_SCOPE) endfunction() -if ("${BOARD_QUALIFIERS}" MATCHES "/p33ak128mc106" AND - "${BOARD}" MATCHES "dspic33a_curiosity") - set(TARGET_CPU "33AK128MC106") - find_dspic33_dfp( - OUT_INFO C30_DEVICE_INFO - OUT_ROOT DFP_ROOT - ARCHES AK - FAMILIES MC - ) +if("${BOARD_QUALIFIERS}" MATCHES "/p33ak128mc106" AND + "${BOARD}" MATCHES "dspic33a_curiosity") + set(TARGET_CPU "33AK128MC106") + find_dspic33_dfp( + OUT_INFO C30_DEVICE_INFO + OUT_ROOT DFP_ROOT + ARCHES AK + FAMILIES MC + ) elseif("${BOARD_QUALIFIERS}" MATCHES "/p33ak512mps512" AND - "${BOARD}" MATCHES "dspic33a_curiosity") - set(TARGET_CPU "33AK512MPS512") - find_dspic33_dfp( - OUT_INFO C30_DEVICE_INFO - OUT_ROOT DFP_ROOT - ARCHES AK - FAMILIES MP - ) + "${BOARD}" MATCHES "dspic33a_curiosity") + set(TARGET_CPU "33AK512MPS512") + find_dspic33_dfp( + OUT_INFO C30_DEVICE_INFO + OUT_ROOT DFP_ROOT + ARCHES AK + FAMILIES MP + ) endif() message(STATUS "DFP file in ${C30_DEVICE_INFO}") message(STATUS "DFP path ${DFP_ROOT}") @@ -182,7 +182,7 @@ set(ENV{DFP_ROOT} "${DFP_ROOT}") set(ENV{TARGET_CPU} "${TARGET_CPU}") set(CMAKE_C_FLAGS "-D__XC_DSC__ -mdfp=\"${DFP_ROOT}/xc16\"" CACHE STRING "" FORCE) -set(CMAKE_ASM_FLAGS "-mdfp=\"${DFP_ROOT}/xc16\"" CACHE STRING "" FORCE) +set(CMAKE_ASM_FLAGS "-D__XC_DSC__ -mdfp=\"${DFP_ROOT}/xc16\"" CACHE STRING "" FORCE) # Append to DTS preprocessor flags with DFP path if(DEFINED DTS_EXTRA_CPPFLAGS AND NOT "${DTS_EXTRA_CPPFLAGS}" STREQUAL "") @@ -195,17 +195,17 @@ find_program(CMAKE_C_COMPILER xc-dsc-gcc PATHS ${XCDSC_TOOLCHAIN_PATH}/bin/ NO_D # Get compiler version execute_process( - COMMAND ${CMAKE_C_COMPILER} --version - OUTPUT_VARIABLE XCDSC_VERSION_STR - ERROR_VARIABLE XCDSC_VERSION_ERR - OUTPUT_STRIP_TRAILING_WHITESPACE ) + COMMAND ${CMAKE_C_COMPILER} --version + OUTPUT_VARIABLE XCDSC_VERSION_STR + ERROR_VARIABLE XCDSC_VERSION_ERR + OUTPUT_STRIP_TRAILING_WHITESPACE ) # Verify that the installed version is v3.30 or higher if("${XCDSC_VERSION_STR}" MATCHES ".*v([0-9]+)\\.([0-9]+).*") - string(REGEX REPLACE ".*v([0-9]+)\\.([0-9]+).*" "\\1\\2" __XCDSC_VERSION__ "${XCDSC_VERSION_STR}") - math(EXPR XCDSC_VERSION_INT "${__XCDSC_VERSION__}") - if(XCDSC_VERSION_INT LESS 330) - message(FATAL_ERROR "XC-DSC compiler v3.30 or newer is required. Found version: ${XCDSC_VERSION_STR}") - endif() + string(REGEX REPLACE ".*v([0-9]+)\\.([0-9]+).*" "\\1\\2" __XCDSC_VERSION__ "${XCDSC_VERSION_STR}") + math(EXPR XCDSC_VERSION_INT "${__XCDSC_VERSION__}") + if(XCDSC_VERSION_INT LESS 330) + message(FATAL_ERROR "XC-DSC compiler v3.30 or newer is required. Found version: ${XCDSC_VERSION_STR}") + endif() else() - message(FATAL_ERROR "Unable to detect XC-DSC compiler version from: '${XCDSC_VERSION_STR}'") + message(FATAL_ERROR "Unable to detect XC-DSC compiler version from: '${XCDSC_VERSION_STR}'") endif() diff --git a/cmake/toolchain/xcdsc/Kconfig b/cmake/toolchain/xcdsc/Kconfig index 923c90caf1c82..7ea14243f02c5 100644 --- a/cmake/toolchain/xcdsc/Kconfig +++ b/cmake/toolchain/xcdsc/Kconfig @@ -10,6 +10,8 @@ config PICOLIBC_SUPPORTED def_bool y help XC-DSC toolchain supports picolib for C development. +config LIBC_ERRNO + default y config TOOLCHAIN_XCDSC_SUPPORTS_THREAD_LOCAL_STORAGE bool "XC-DSC toolchain supports TLS" def_bool y @@ -17,3 +19,7 @@ config TOOLCHAIN_XCDSC_SUPPORTS_THREAD_LOCAL_STORAGE help Set this if the XC-DSC toolchain being used for the build supports thread local storage. +choice LIBC_IMPLEMENTATION + prompt "C Library Implementation" + default EXTERNAL_LIBC +endchoice diff --git a/drivers/gpio/Kconfig.mchp_dspic b/drivers/gpio/Kconfig.mchp_dspic index d36a3461852ea..9e819de4773b1 100644 --- a/drivers/gpio/Kconfig.mchp_dspic +++ b/drivers/gpio/Kconfig.mchp_dspic @@ -5,5 +5,6 @@ config GPIO_DSPIC bool "dsPIC33A GPIO driver" default y + depends on DT_HAS_MICROCHIP_DSPIC_GPIO_ENABLED help Enable support for the dsPIC33A GPIO driver. diff --git a/drivers/pinctrl/pinctrl_mchp_dspic33_g1.c b/drivers/pinctrl/pinctrl_mchp_dspic33_g1.c index e57676d30df7c..5f5d72c2adef9 100644 --- a/drivers/pinctrl/pinctrl_mchp_dspic33_g1.c +++ b/drivers/pinctrl/pinctrl_mchp_dspic33_g1.c @@ -94,7 +94,7 @@ static int pinctrl_configure_pin(pinctrl_soc_pin_t soc_pin) ret = -EINVAL; } - return 0; + return ret; } int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg) @@ -105,6 +105,9 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp for (uint8_t i = 0U; i < pin_cnt; i++) { ret = pinctrl_configure_pin(pins[i]); + if (ret) { + break; + } } return ret; diff --git a/drivers/serial/Kconfig.dspic_uart b/drivers/serial/Kconfig.dspic_uart index f97564d98aa9f..627df96e60afb 100644 --- a/drivers/serial/Kconfig.dspic_uart +++ b/drivers/serial/Kconfig.dspic_uart @@ -4,6 +4,7 @@ config UART_DSPIC bool "dsPIC33A UART driver" default y + depends on DT_HAS_MICROCHIP_DSPIC33_UART_ENABLED select SERIAL_HAS_DRIVER select SERIAL_SUPPORT_INTERRUPT select PINCTRL diff --git a/drivers/serial/uart_mchp_dspic33_g1.c b/drivers/serial/uart_mchp_dspic33_g1.c index 861a4bf1de927..228b635510ef9 100644 --- a/drivers/serial/uart_mchp_dspic33_g1.c +++ b/drivers/serial/uart_mchp_dspic33_g1.c @@ -303,9 +303,10 @@ static int uart_dspic_poll_in(const struct device *dev, unsigned char *c) int ret_val; key = k_spin_lock(&lock); - /* If receiver buffer is empty, return -1 */ + if ((*UxSTA & BIT_RXBE) != 0U) { - ret_val = -EPERM; + /* uart_poll_in api expects to return -1, if receiver buffer is empty */ + ret_val = -1; } else { diff --git a/drivers/timer/CMakeLists.txt b/drivers/timer/CMakeLists.txt index 4b90f9d54c138..c830805140a5b 100644 --- a/drivers/timer/CMakeLists.txt +++ b/drivers/timer/CMakeLists.txt @@ -23,7 +23,6 @@ zephyr_library_sources_ifdef(CONFIG_ITE_IT8XXX2_TIMER ite_it8xxx2_timer.c) zephyr_library_sources_ifdef(CONFIG_LEON_GPTIMER leon_gptimer.c) zephyr_library_sources_ifdef(CONFIG_LITEX_TIMER litex_timer.c) zephyr_library_sources_ifdef(CONFIG_MCHP_DSPIC33_TIMER mchp_dspic33_timer.c) -zephyr_library_sources_ifdef(CONFIG_MCHP_MEC5_KTIMER mchp_mec5_ktimer.c) zephyr_library_sources_ifdef(CONFIG_MCHP_XEC_RTOS_TIMER mchp_xec_rtos_timer.c) zephyr_library_sources_ifdef(CONFIG_MCHP_SAM_PIT64B_TIMER mchp_sam_pit64b_timer.c) zephyr_library_sources_ifdef(CONFIG_MCUX_LPTMR_TIMER mcux_lptmr_timer.c) diff --git a/drivers/timer/mchp_dspic33_timer.c b/drivers/timer/mchp_dspic33_timer.c index 873d3c6f782db..7e1f47c6a1bda 100644 --- a/drivers/timer/mchp_dspic33_timer.c +++ b/drivers/timer/mchp_dspic33_timer.c @@ -18,10 +18,14 @@ #define TIMER1_CYCLES_PER_TICK \ ((sys_clock_hw_cycles_per_sec() + \ - ((2U * DT_INST_PROP(0, prescalar) * CONFIG_SYS_CLOCK_TICKS_PER_SEC) / 2U)) / \ - (2U * DT_INST_PROP(0, prescalar) * CONFIG_SYS_CLOCK_TICKS_PER_SEC)) + ((2U * DT_INST_PROP(0, prescaler) * CONFIG_SYS_CLOCK_TICKS_PER_SEC) / 2U)) / \ + (2U * DT_INST_PROP(0, prescaler) * CONFIG_SYS_CLOCK_TICKS_PER_SEC)) +#define TIMER1_BASE DT_REG_ADDR(DT_NODELABEL(timer1)) #define MAX_TIMER_CLOCK_CYCLES 0xFFFFFFFFU +#define TMRx_OFFSET 0x0004U +#define PRx_OFFSET 0x0008U + static struct k_spinlock lock; static uint64_t total_cycles; static uint64_t prev_announced_cycle; @@ -31,6 +35,12 @@ static uint32_t un_announced_cycles; const int32_t z_sys_timer_irq_for_test = DT_INST_IRQN(0); #endif +/* Timer configuration from DeviceTree */ +static volatile uint32_t *TxCON = (uint32_t *)TIMER1_BASE; +static volatile uint32_t *TMRx = (uint32_t *)(TIMER1_BASE + TMRx_OFFSET); +static volatile uint32_t *PRx = (uint32_t *)(TIMER1_BASE + PRx_OFFSET); + +/* Map prescaler value to bits */ static uint8_t map_prescaler_to_bits(uint32_t val) { uint8_t ret_val; @@ -55,27 +65,40 @@ static uint8_t map_prescaler_to_bits(uint32_t val) return ret_val; } -static void configure_timer1(void) +/* Configure timer registers */ +static void configure_timer(uint32_t cycles) { - const uint32_t timer_count = (uint32_t)TIMER1_CYCLES_PER_TICK - 1U; + /* Turn off timer and clear TMR register */ + *TxCON &= ~(0x8000U); + *TMRx = 0; - /* clear timer control and timer count register */ - T1CONbits.ON = 0; + /* set the timeout count */ + *PRx = cycles - 1U; - /* Select standard peripheral clock */ - T1CONbits.TCS = 0; - T1CONbits.TCKPS = map_prescaler_to_bits(DT_INST_PROP(0, prescalar)); - TMR1 = 0; - IEC1bits.T1IE = 0; - IFS1bits.T1IF = 0; + /* Start the timer. */ + *TxCON |= 0x8000U; +} - /* set the time out count */ - PR1 = (uint32_t)timer_count; +static void initialize_timer(void) +{ + /* Standard peripheral clock */ + *TxCON &= ~(0x0002U); + *TxCON |= (map_prescaler_to_bits(DT_INST_PROP(0, prescaler)) << 4U); - /* Start the timer. */ - T1CONbits.ON = 1; + configure_timer(TIMER1_CYCLES_PER_TICK); } +/* Busy wait */ +#ifdef CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT +void arch_busy_wait(uint32_t usec_to_wait) +{ + ARG_UNUSED(usec_to_wait); + __asm__ volatile("sl.l w0,#0x03,w0\n\t" + "repeat.w w0\n\t" + "neop\n\n\t"); +} +#endif + /** * @brief Return the current 32-bit cycle count from a hardware timer */ @@ -85,11 +108,11 @@ uint32_t sys_clock_cycle_get_32(void) k_spinlock_key_t key; key = k_spin_lock(&lock); - cycles = (uint32_t)total_cycles + (PR1 * (uint32_t)arch_dspic_irq_isset(DT_INST_IRQN(0))) + - TMR1; + cycles = (uint32_t)total_cycles + (*PRx * (uint32_t)arch_dspic_irq_isset(DT_INST_IRQN(0))) + + *TMRx; k_spin_unlock(&lock, key); - return cycles * 2U * DT_INST_PROP(0, prescalar); + return cycles * 2U * DT_INST_PROP(0, prescaler); } uint32_t sys_clock_elapsed(void) @@ -110,11 +133,10 @@ uint32_t sys_clock_elapsed(void) * Number of cycles per tick */ ticks_elapsed = ((uint32_t)(total_cycles - prev_announced_cycle) + - (uint32_t)(TMR1 + ((uint32_t)TIMER1_CYCLES_PER_TICK / 10U))) / + (uint32_t)(*TMRx + (TIMER1_CYCLES_PER_TICK / 10U))) / ((uint32_t)TIMER1_CYCLES_PER_TICK); k_spin_unlock(&lock, key); } while (0); - return ticks_elapsed; } @@ -128,7 +150,7 @@ void sys_clock_set_timeout(int32_t ticks, bool idle) do { if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { - /* if it is not in tickles mode, no need to change the + /* If it is not in tickles mode, no need to change the * Timeout interval, it will periodically interrupt * At every tick */ @@ -138,23 +160,17 @@ void sys_clock_set_timeout(int32_t ticks, bool idle) /* check if it is K_TICKS_FOREVER, is so set to max cycles */ next_count = (ticks == K_TICKS_FOREVER) ? MAX_TIMER_CLOCK_CYCLES - : (uint32_t)(ticks * TIMER1_CYCLES_PER_TICK); - key = k_spin_lock(&lock); - total_cycles = total_cycles + (uint64_t)TMR1; - un_announced_cycles = un_announced_cycles + TMR1; + : (uint32_t)((uint32_t)(ticks * TIMER1_CYCLES_PER_TICK) + 1U); - /* clear the timer1 counter register and set the period register to the - * New timeout value. This should be done with TIMER1 disabled - */ - T1CONbits.ON = 0; - TMR1 = 0; - PR1 = next_count; - T1CONbits.ON = 1; + key = k_spin_lock(&lock); + total_cycles = total_cycles + (uint64_t)*TMRx; + un_announced_cycles = un_announced_cycles + *TMRx; + configure_timer(next_count); k_spin_unlock(&lock, key); } while (0); } -/* Timer1 ISR */ +/* ISR */ static void timer1_isr(const void *arg) { uint32_t elapsed_ticks; @@ -167,51 +183,35 @@ static void timer1_isr(const void *arg) * Of cycles per tick. For tickles, the period would have been set * To the next event time. */ - elapsed_ticks = (uint32_t)(un_announced_cycles + PR1) / (uint32_t)TIMER1_CYCLES_PER_TICK; + elapsed_ticks = (uint32_t)(un_announced_cycles + *PRx) / (uint32_t)TIMER1_CYCLES_PER_TICK; key = k_spin_lock(&lock); - total_cycles = total_cycles + (uint64_t)PR1; + total_cycles = total_cycles + (uint64_t)*PRx; if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { /* If not in tickles mode set the interrupt to happen at the next * Tick. Clear the timer1 counter register and set the period register * to the tick timeout value. This should be done with TIMER1 disabled. */ - T1CONbits.ON = 0; - PR1 = (uint32_t)TIMER1_CYCLES_PER_TICK; - T1CONbits.ON = 1; + *TxCON &= ~(0x8000U); + *PRx = TIMER1_CYCLES_PER_TICK; + *TxCON |= 0x8000U; } k_spin_unlock(&lock, key); - /* - * The hardware timer (TMR1/PR1) has a limited range. If PR1 hits its maximum - * value (MAX_TIMER_CLOCK_CYCLES), we must stop and restart the timer with this - * max period to prevent overflow/wraparound issues. - * - * Otherwise, if PR1 is within range, we reset un_announced_cycles and call + /* If PR1 is within range, we reset un_announced_cycles and call * sys_clock_announce(elapsed_ticks) to inform the kernel about the elapsed * system ticks. This keeps the Zephyr kernel’s time accounting accurate. */ - if (PR1 != MAX_TIMER_CLOCK_CYCLES) { - T1CONbits.ON = 0; + if (*PRx != MAX_TIMER_CLOCK_CYCLES) { + *TxCON &= ~(0x8000U); un_announced_cycles = 0; prev_announced_cycle = total_cycles; sys_clock_announce(elapsed_ticks); } } -#ifdef CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT -void arch_busy_wait(uint32_t usec_to_wait) -{ - uint32_t cycles_to_wait = sys_clock_hw_cycles_per_sec() / USEC_PER_SEC * usec_to_wait; - - while (cycles_to_wait-- > 0) { - __asm__ volatile("nop\n\t"); - } -} -#endif - -/* Initialize the system clock driver */ +/* Driver init: get first enabled timer from DT */ int sys_clock_driver_init(void) { /* connect the timer1 isr to the interrupt. The interrupt number @@ -223,7 +223,7 @@ int sys_clock_driver_init(void) * Every interrupt will reload the period register with the * next interrupt tick count */ - configure_timer1(); + initialize_timer(); irq_enable(DT_INST_IRQN(0)); return 0; } diff --git a/dts/bindings/timer/microchip,dspic33-timer.yaml b/dts/bindings/timer/microchip,dspic33-timer.yaml index e2029a20c5189..b6f3c885e61c4 100644 --- a/dts/bindings/timer/microchip,dspic33-timer.yaml +++ b/dts/bindings/timer/microchip,dspic33-timer.yaml @@ -15,7 +15,7 @@ properties: type: int required: true - prescalar: + prescaler: type: int required: true diff --git a/dts/dspic/p33ak128mc106.dtsi b/dts/dspic/p33ak128mc106.dtsi index 6f7a5a8bb5f30..b609e990d10f3 100644 --- a/dts/dspic/p33ak128mc106.dtsi +++ b/dts/dspic/p33ak128mc106.dtsi @@ -49,7 +49,7 @@ sram0: memory@4000 { compatible = "zephyr,memory"; - reg = <0x4000 0x20000>; + reg = <0x4000 0x4000>; label = "SRAM"; }; @@ -67,7 +67,7 @@ compatible = "microchip,dspic33-timer"; reg = <0x1E00 0xC>; clock-frequency = <4000000>; - prescalar = <8>; + prescaler = <8>; interrupt-parent = <&intc0>; interrupts = <48 1>; label = "TIMER_1"; diff --git a/dts/dspic/p33ak512mps512.dtsi b/dts/dspic/p33ak512mps512.dtsi index 4a8443e93b7b8..e6b5ed086c44a 100644 --- a/dts/dspic/p33ak512mps512.dtsi +++ b/dts/dspic/p33ak512mps512.dtsi @@ -66,7 +66,7 @@ compatible = "microchip,dspic33-timer"; reg = <0x1CE0 0xC>; clock-frequency = <4000000>; - prescalar = <8>; + prescaler = <8>; interrupt-parent = <&intc0>; interrupts = <48 1>; label = "TIMER_1"; diff --git a/include/zephyr/toolchain/xcdsc.h b/include/zephyr/toolchain/xcdsc.h index 26b161215f772..853d35710067f 100644 --- a/include/zephyr/toolchain/xcdsc.h +++ b/include/zephyr/toolchain/xcdsc.h @@ -237,17 +237,22 @@ static inline int popcount(unsigned int x) #define __GENERIC_DOT_SECTION(segment) __attribute__((section("." STRINGIFY(segment)))) #define Z_GENERIC_DOT_SECTION(segment) __GENERIC_DOT_SECTION(segment) -#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_XSDSC_H_ */ +#define ALIAS_OF(of) __attribute__((alias(#of))) -/* Double indirection to ensure section names are expanded before - * stringification - */ -#define __GENERIC_SECTION(segment) __attribute__((section(STRINGIFY(segment)))) -#define Z_GENERIC_SECTION(segment) __GENERIC_SECTION(segment) +#define FUNC_ALIAS(real_func, new_alias, return_type) return_type new_alias() ALIAS_OF(real_func) -#define __GENERIC_DOT_SECTION(segment) __attribute__((section("." STRINGIFY(segment)))) -#define Z_GENERIC_DOT_SECTION(segment) __GENERIC_DOT_SECTION(segment) +#if defined(_ASMLANGUAGE) -#define ALIAS_OF(of) __attribute__((alias(#of))) +.macro func_section sect sym + .section .§&.&sym&, keep, code, keep + .align 4 + .type _&sym&, @function +_&sym&: +.endm -#define FUNC_ALIAS(real_func, new_alias, return_type) return_type new_alias() ALIAS_OF(real_func) +#define GTEXT(sym) .global _##sym +#define SECTION_FUNC(sect, sym) func_section sect sym + +#endif /* _ASMLANGUAGE */ + +#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_XSDSC_H_ */ diff --git a/samples/basic/blinky/prj.conf b/samples/basic/blinky/prj.conf index fe2e63c01ec01..969277e35be2f 100644 --- a/samples/basic/blinky/prj.conf +++ b/samples/basic/blinky/prj.conf @@ -1,5 +1,4 @@ CONFIG_GPIO=y CONFIG_PRINTK=y CONFIG_RAM_CONSOLE=y -CONFIG_GPIO_DSPIC=y CONFIG_STATIC_INIT_GNU=y diff --git a/soc/microchip/dspic33/dspic33a/Kconfig.soc b/soc/microchip/dspic33/dspic33a/Kconfig.soc index ce681e7832048..916c8e36c1b11 100644 --- a/soc/microchip/dspic33/dspic33a/Kconfig.soc +++ b/soc/microchip/dspic33/dspic33a/Kconfig.soc @@ -25,5 +25,4 @@ config SOC_P33AK256MC506 config SOC default "p33ak128mc106" if SOC_P33AK128MC106 - default "p33ak256mc506" if SOC_P33AK256MC506 default "p33ak512mps512" if SOC_P33AK512MPS512 diff --git a/soc/microchip/dspic33/soc.yml b/soc/microchip/dspic33/soc.yml index 560781a1dafe8..16b5c9332e3fe 100644 --- a/soc/microchip/dspic33/soc.yml +++ b/soc/microchip/dspic33/soc.yml @@ -5,4 +5,3 @@ family: socs: - name: p33ak512mps512 - name: p33ak128mc106 - - name: p33ak256mc506 diff --git a/tests/kernel/mem_protect/stack_random/testcase.yaml b/tests/kernel/mem_protect/stack_random/testcase.yaml index b809f2875b9ef..57a52dcc2b767 100644 --- a/tests/kernel/mem_protect/stack_random/testcase.yaml +++ b/tests/kernel/mem_protect/stack_random/testcase.yaml @@ -2,6 +2,7 @@ tests: kernel.memory_protection.stack_random: arch_exclude: - posix + - dspic tags: - kernel - memory_protection diff --git a/tests/kernel/mem_protect/stackprot/src/main.c b/tests/kernel/mem_protect/stackprot/src/main.c index caf328a9ae1f4..ced761eba69b0 100644 --- a/tests/kernel/mem_protect/stackprot/src/main.c +++ b/tests/kernel/mem_protect/stackprot/src/main.c @@ -139,6 +139,14 @@ ZTEST_USER(stackprot, test_stackprot) */ ZTEST(stackprot, test_create_alt_thread) { + /** + * Since for the DSPIC the stack is growing upwards this test is not supported + * Skip this test to avoid failures. + */ +#ifdef CONFIG_DSPIC + ztest_test_skip(); +#endif + /* Start thread */ k_thread_create(&alt_thread_data, alt_thread_stack_area, STACKSIZE, alternate_thread, NULL, NULL, NULL,