Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions arch/tricore/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,20 @@
TRICORE_SRC2IRQ(TRICORE_SRC_GPSR_BASE + \
((src_cpu) * TRICORE_SRCNUM_PER_GPSR + (dest_cpu)) * 4)

#ifdef CONFIG_ARCH_IRQPRIO
# define TRICORE_SCHEDIRQ \
TRICORE_GPSR_IRQNUM(up_cpu_index(), up_cpu_index())
#endif

/* TriCore interrupt priority range, higher value means higher priority. */

#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
#define TRICORE_IRQ_DISABLE_PRIORITY CONFIG_ARCH_IRQ_DISABLE_PRIORITY
#endif

#define TRICORE_IRQ_MIN_PRIORITY 1
#define TRICORE_IRQ_MAX_PRIORITY 255

/* For use with EABI and floating point, the stack must be aligned to 8-byte
* addresses.
*/
Expand Down Expand Up @@ -410,6 +420,11 @@ static inline_function uintptr_t up_getusrsp(void *regs)
{
uintptr_t *csaregs = (uintptr_t *)regs;

if (csaregs == NULL)
{
return 0;
}

if (csaregs[REG_LPCXI] & PCXI_UL)
{
csaregs = tricore_csa2addr(csaregs[REG_LPCXI]);
Expand Down
2 changes: 2 additions & 0 deletions arch/tricore/include/tc3xx/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#define TRICORE_SRC_BASE 0xf0038000 /* SRC_CPU0SB, IRQ 0 */
#define TRICORE_SRC_GPSR_BASE 0xf0038990 /* SRC_GPSR0SR0 */
#define TRICORE_INT_SRB_BASE 0xf0037010 /* INT_SRB0 */
#define TRICORE_INT_LASR_BASE 0xf0037204 /* INT_LASR0 */
#define TRICORE_INT_LASR_SPACING 0x10 /* INT_LASRn spacing */

#define TRICORE_SRC_SRPN_MASK 0xff /* Service request priority */
#define TRICORE_SRC_SRE (1 << 10) /* Service request enable */
Expand Down
2 changes: 2 additions & 0 deletions arch/tricore/include/tc4xx/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#define TRICORE_SRC_BASE 0xf4432000 /* SRC_CPU0SB, IRQ 0 */
#define TRICORE_SRC_GPSR_BASE 0xf4433460 /* SRC_GPSR0SR0 */
#define TRICORE_INT_SRB_BASE 0xf4430b00 /* INT_SRB0 */
#define TRICORE_INT_LASR_BASE 0xf4430c20 /* INT_LASR0 */
#define TRICORE_INT_LASR_SPACING 0x34 /* INT_LASRn spacing */

#define TRICORE_SRC_SRPN_MASK 0xff /* Service request priority */
#define TRICORE_SRC_VM_MASK (0x7 << 8) /* Virtual machine */
Expand Down
2 changes: 0 additions & 2 deletions arch/tricore/src/common/gnu/tricore_head.S
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
****************************************************************************/

#define TRICORE_PSW_RESET 0x980 /* Supervisor, call depth counting on */
#define TRICORE_BIV_VECTOR 0x1fe0 /* Single interrupt vector at INTTAB + 0x1fe0 */

#ifdef CONFIG_ARCH_CHIP_TC3XX
# define TC3XX_WDTCPU0_CON0 0xf003624c /* CPU0 watchdog CON0, 0xc apart per CPU */
Expand Down Expand Up @@ -156,7 +155,6 @@ tricore_head:

movh.a %a15, hi:__INTTAB_CPU0
lea %a15, [%a15]lo:__INTTAB_CPU0
lea %a15, [%a15]TRICORE_BIV_VECTOR
mov.d %d15, %a15
mtcr TRICORE_CPU_BIV, %d15
isync
Expand Down
17 changes: 14 additions & 3 deletions arch/tricore/src/common/gnu/tricore_vectors.S
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,25 @@ tricore_traptab:
.size tricore_traptab, . - tricore_traptab

/****************************************************************************
* Interrupt vector table. One entry serves all priorities; the startup
* code sets the BIV priority bits accordingly.
* Interrupt vector table
*
* CONFIG_ARCH_IRQPRIO=y (Hardware-managed, Full BIV table):
* SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
* SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
* CONFIG_ARCH_IRQPRIO=n (Software-managed, One-entry BIV table):
* Only the SRPN 255 entry exists, all IRQs vector to
* tricore_irq_sched. No nesting support. Saves BIV flash (~8KB).
****************************************************************************/

.section .inttab, "ax", @progbits
.p2align 5
.global tricore_inttab
.type tricore_inttab, @function
tricore_inttab:
INTSLOT tricore_doirq
INTSLOT tricore_irq_sched
#ifdef CONFIG_ARCH_IRQPRIO
.rept TRICORE_IRQ_MAX_PRIORITY - 1
INTSLOT tricore_irq_direct
.endr
#endif
.size tricore_inttab, . - tricore_inttab
2 changes: 0 additions & 2 deletions arch/tricore/src/common/tasking/tricore_head.asm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
****************************************************************************/

#define TRICORE_PSW_RESET 0x980 /* Supervisor, call depth counting on */
#define TRICORE_BIV_VECTOR 0x1fe0 /* Single interrupt vector at INTTAB + 0x1fe0 */

#ifdef CONFIG_ARCH_CHIP_TC3XX
# define TC3XX_WDTCPU0_CON0 0xf003624c /* CPU0 watchdog CON0, 0xc apart per CPU */
Expand Down Expand Up @@ -180,7 +179,6 @@ tricore_head:

movh.a a15, #@HIS(__INTTAB_CPU0)
lea a15, [a15]@LOS(__INTTAB_CPU0)
lea a15, [a15]TRICORE_BIV_VECTOR
mov.d d15, a15
mtcr #TRICORE_CPU_BIV, d15
isync
Expand Down
22 changes: 18 additions & 4 deletions arch/tricore/src/common/tasking/tricore_vectors.asm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
.extern tricore_svcall
.extern tricore_fcutrap_recover
.extern g_fcu_csa_base
.extern tricore_doirq
.extern tricore_irq_sched
#ifdef CONFIG_ARCH_IRQPRIO
.extern tricore_irq_direct
#endif

TRAPSLOT .macro cls, entry
svlcx
Expand Down Expand Up @@ -137,16 +140,27 @@ ctx_notfcu:
.size tricore_traptab, * - tricore_traptab

;****************************************************************************
; Interrupt vector table. One entry serves all priorities; the startup
; code sets the BIV priority bits accordingly.
; Interrupt vector table
;
; CONFIG_ARCH_IRQPRIO=y (Hardware-managed, Full BIV table):
; SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
; SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
; CONFIG_ARCH_IRQPRIO=n (Software-managed, One-entry BIV table):
; Only the SRPN 255 entry exists, all IRQs vector to
; tricore_irq_sched. No nesting support. Saves BIV flash (~8KB).
;****************************************************************************

.sdecl ".text.inttab",code,protect
.sect ".text.inttab"
.align 32
.global tricore_inttab
tricore_inttab: .type func
INTSLOT tricore_doirq
INTSLOT tricore_irq_sched
#ifdef CONFIG_ARCH_IRQPRIO
.dup TRICORE_IRQ_MAX_PRIORITY - 1
INTSLOT tricore_irq_direct
.endm
#endif
.size tricore_inttab, * - tricore_inttab

.end
98 changes: 75 additions & 23 deletions arch/tricore/src/common/tricore_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,95 @@
* Public Functions
****************************************************************************/

#ifdef CONFIG_ARCH_IRQPRIO

/****************************************************************************
* Name: tricore_doirq
* Name: tricore_irq_direct
*
* Description:
* Common interrupt handler, entered from the interrupt vector in
* tricore_vectors.S/.asm with the lower context saved.
* Fast interrupt path (analogous to ARM-M exception_direct).
* Only dispatches the IRQ handler, no context switch.
* If a context switch is needed, triggers the scheduling GPSR which
* will execute after all higher-priority interrupts have returned.
*
****************************************************************************/

void tricore_doirq(void)
void tricore_irq_direct(void)
{
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
struct tcb_s *tcb = this_task();
uintptr_t *regs = tricore_csa2addr(tricore_mfcr(TRICORE_CPU_PCXI));
int irq = tricore_irq_from_lasr();

up_irq_enable();

tricore_ack_irq(irq);
irq_dispatch(irq, regs);

if (*running_task != this_task())
{
cpu_set_t cpuset;

CPU_ZERO(&cpuset);
CPU_SET(up_cpu_index(), &cpuset);
up_trigger_irq(TRICORE_SCHEDIRQ, cpuset);
}

tricore_jump_backto_link();
}

#endif /* CONFIG_ARCH_IRQPRIO */

/****************************************************************************
* Name: tricore_irq_sched
*
* Description:
* Context-switch interrupt path. Two dispatch schemes share this path
* with different roles, selected by CONFIG_ARCH_IRQPRIO.
*
* CONFIG_ARCH_IRQPRIO=y:
* SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
* SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
* CONFIG_ARCH_IRQPRIO=n:
* tricore_irq_sched does dispatch and task switch for all IRQs.
* No nesting support and no scheduling GPSR.
*
****************************************************************************/

#ifdef CONFIG_SUPPRESS_INTERRUPTS
PANIC();
#else
int irq = NDX_TO_IRQ(tricore_mfcr(TRICORE_CPU_ICR) &
TRICORE_ICR_CCPN_MASK);
void tricore_irq_sched(void)
{
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
uintptr_t *regs = tricore_csa2addr(tricore_mfcr(TRICORE_CPU_PCXI));
struct tcb_s *tcb;
#ifndef CONFIG_ARCH_IRQPRIO
int irq = tricore_irq_from_lasr();
#endif

if (*running_task != NULL)
{
(*running_task)->xcp.regs = regs;
tricore_store_pprs(*running_task);

#ifdef CONFIG_ARCH_IRQPRIO
if ((*running_task)->sigdeliver && !(*running_task)->xcp.saved_regs)
{
up_schedule_sigaction(*running_task);
}
#endif
}

board_autoled_on(LED_INIRQ);
#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
up_irq_save();
up_irq_enable();
#endif

/* Deliver the IRQ */
board_autoled_on(LED_INIRQ);

#ifndef CONFIG_ARCH_IRQPRIO
tricore_ack_irq(irq);

irq_dispatch(irq, regs);
#endif

tcb = this_task();

/* Check for a context switch. */

Expand All @@ -98,22 +154,20 @@ void tricore_doirq(void)
tcb = this_task();
#endif

/* Updata PPRS register */

tricore_store_pprs(*running_task);
tricore_restore_pprs(tcb);

/* Record the new "running" task when context switch occurred.
* g_running_tasks[] is only used by assertion logic for reporting
* crashes.
*/

*running_task = tcb;

tricore_mtcr(TRICORE_CPU_PCXI, tricore_addr2csa(tcb->xcp.regs));
UP_ISB();
}

/* The saved context may also reference a signal-delivery CSA. */

tricore_restore_pprs(tcb);
tricore_mtcr(TRICORE_CPU_PCXI, tricore_addr2csa(tcb->xcp.regs));
UP_ISB();

/* (*running_task)->xcp.regs is about to become invalid and
* will be marked as NULL to avoid misusage. the same applies
* to (*running_task)->xcp.pprs.
Expand All @@ -123,7 +177,5 @@ void tricore_doirq(void)
tricore_change_pprs(*running_task, UINT32_MAX);

board_autoled_off(LED_INIRQ);
#endif

tricore_jump_backto_link();
}
19 changes: 18 additions & 1 deletion arch/tricore/src/common/tricore_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,31 @@ extern uintptr_t _eheap[]; /* End+1 of .heap */
* Inline Functions
****************************************************************************/

/****************************************************************************
* Name: tricore_irq_from_lasr
*
* Description:
* Get irq number from ICU's last acknowledged SRN register
*
****************************************************************************/

static inline_function int tricore_irq_from_lasr(void)
{
uintptr_t addr = TRICORE_INT_LASR_BASE +
up_cpu_index() * TRICORE_INT_LASR_SPACING;

return (getreg32(addr) >> 16) & 0x7ff;
}

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

/* Interrupt ****************************************************************/

void tricore_ack_irq(int irq);
void tricore_doirq(void);
int tricore_srpn_to_irq(int srpn);
int tricore_irq_to_srpn(int irq);

/* Startup ******************************************************************/

Expand Down
Loading
Loading