Skip to content

Commit 8d8eb0d

Browse files
carlescufigalak
authored andcommitted
arm: Cortex-M0: Adapt core register code to M0
The Cortex-M0(+) and in general processors that support only the ARMv6-M instruction set have a reduced set of registers and fields compared to the ARMv7-M compliant processors. This change goes through all core registers and disables or removes everything that is not part of the ARMv6-M architecture when compiling for Cortex-M0. Jira: ZEP-1497 Change-id: I13e2637bb730e69d02f2a5ee687038dc69ad28a8 Signed-off-by: Vinayak Chettimada <[email protected]> Signed-off-by: Carles Cufi <[email protected]> Signed-off-by: Kumar Gala <[email protected]>
1 parent 420e5c0 commit 8d8eb0d

File tree

5 files changed

+174
-133
lines changed

5 files changed

+174
-133
lines changed

arch/arm/core/cortex_m/scb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void sys_arch_reboot(int type)
9090
DO_REBOOT();
9191
}
9292

93+
#if !defined(CONFIG_CPU_CORTEX_M0_M0PLUS)
9394
/**
9495
*
9596
* @brief Set the number of priority groups based on the number of exception
@@ -134,3 +135,4 @@ void _ScbNumPriGroupSet(unsigned int n)
134135

135136
__scs.scb.aircr.val = reg.val;
136137
}
138+
#endif /* !CONFIG_CPU_CORTEX_M0_M0PLUS */

arch/arm/core/fault.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,7 @@ void _Fault(const NANO_ESF *esf)
372372
*/
373373
void _FaultInit(void)
374374
{
375+
#if !defined(CONFIG_CPU_CORTEX_M0_M0PLUS)
375376
_ScbDivByZeroFaultEnable();
377+
#endif /* !CONFIG_CPU_CORTEX_M0_M0PLUS */
376378
}

arch/arm/include/cortex_m/exc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ static ALWAYS_INLINE int _IsInIsr(void)
5555
/*
5656
* IRQs + PendSV (14) + SVC (11) + SYSTICK (15) are interrupts.
5757
* Vectors 12 and 13 are reserved, we'll never be in there
58+
* On ARMv6-M there is no nested execution bit, so we check exception 3,
59+
* hard fault, to a detect a nested exception.
5860
*/
61+
#if defined(CONFIG_CPU_CORTEX_M0_M0PLUS)
62+
return (vector > 10) || (vector == 3);
63+
#else
5964
return (vector > 10) || (vector && _ScbIsNestedExc());
65+
#endif /* CONFIG_CPU_CORTEX_M0_M0PLUS */
6066
}
6167

6268
/**

include/arch/arm/cortex_m/scb.h

Lines changed: 130 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,6 @@ static inline int _ScbHiPriVectorPendingGet(void)
207207
return reg.bit.vectpending;
208208
}
209209

210-
/**
211-
*
212-
* @brief Find out if the currently executing exception is nested
213-
*
214-
* This routine determines if the currently executing exception is nested.
215-
*
216-
* @return 1 if nested, 0 otherwise
217-
*/
218-
219-
static inline int _ScbIsNestedExc(void)
220-
{
221-
/* !bit == preempted exceptions */
222-
return !__scs.scb.icsr.bit.rettobase;
223-
}
224-
225210
/**
226211
*
227212
* @brief Find out if running in thread mode
@@ -280,76 +265,6 @@ static inline uint32_t _ScbActiveVectorGet(void)
280265
return __scs.scb.icsr.bit.vectactive;
281266
}
282267

283-
/**
284-
*
285-
* @brief Find out if vector table is in SRAM or ROM
286-
*
287-
* This routine determines if the currently executing exception is nested.
288-
*
289-
* @return 1 if in SRAM, 0 if in ROM
290-
*/
291-
292-
static inline uint32_t _ScbIsVtableInSram(void)
293-
{
294-
return !!__scs.scb.vtor.bit.tblbase;
295-
}
296-
297-
/**
298-
*
299-
* @brief Move vector table from SRAM to ROM and vice-versa
300-
*
301-
* This routine moves the vector table to the given memory region.
302-
*
303-
* @return 1 if in SRAM, 0 if in ROM
304-
*/
305-
306-
static inline void _ScbVtableLocationSet(
307-
int sram /* 1 to move vector to SRAM, 0 to move it to ROM */
308-
)
309-
{
310-
__ASSERT(!(sram & 0xfffffffe), "");
311-
__scs.scb.vtor.bit.tblbase = sram;
312-
}
313-
314-
/**
315-
*
316-
* @brief Obtain base address of vector table
317-
*
318-
* This routine returns the vector table's base address.
319-
*
320-
* @return the base address of the vector table
321-
*/
322-
323-
static inline uint32_t _ScbVtableAddrGet(void)
324-
{
325-
return __scs.scb.vtor.bit.tbloff;
326-
}
327-
328-
/**
329-
*
330-
* @brief Set base address of vector table
331-
*
332-
* @a addr must align to the number of exception entries in vector table:
333-
*
334-
* numException = 16 + num_interrupts where each entry is 4 Bytes
335-
*
336-
* As a minimum, @a addr must be a multiple of 128:
337-
*
338-
* 0 <= num_interrupts < 16: multiple 0x080
339-
* 16 <= num_interrupts < 48: multiple 0x100
340-
* 48 <= num_interrupts < 112: multiple 0x200
341-
* ....
342-
* @param addr base address, aligned on 128 minimum
343-
*
344-
* @return N/A
345-
*/
346-
347-
static inline void _ScbVtableAddrSet(uint32_t addr)
348-
{
349-
__ASSERT(!(addr & 0x7F), "invalid vtable base Addr");
350-
__scs.scb.vtor.bit.tbloff = addr;
351-
}
352-
353268
/**
354269
*
355270
* @brief Find out if data regions are little endian
@@ -365,22 +280,6 @@ static inline int _ScbIsDataLittleEndian(void)
365280
return !(__scs.scb.aircr.bit.endianness);
366281
}
367282

368-
/**
369-
*
370-
* @brief Get the programmed number of priority groups
371-
*
372-
* Exception priorities can be sub-divided into groups, with sub-priorities.
373-
* Within these groups, exceptions do not preempt each other. The sub-priorities
374-
* are only used to decide which exception will run when several are pending.
375-
*
376-
* @return the number of priority groups
377-
*/
378-
379-
static inline int _ScbNumPriGroupGet(void)
380-
{
381-
return 1 << (7 - __scs.scb.aircr.bit.prigroup);
382-
}
383-
384283
/**
385284
*
386285
* @brief CPU goes to sleep after exiting an ISR
@@ -478,36 +377,6 @@ static inline void _ScbSleepDeepClear(void)
478377
__scs.scb.scr.bit.sleepdeep = 0;
479378
}
480379

481-
/**
482-
*
483-
* @brief Enable faulting on division by zero
484-
*
485-
* This routine enables the divide by zero fault.
486-
* By default, the CPU ignores the error.
487-
*
488-
* @return N/A
489-
*/
490-
491-
static inline void _ScbDivByZeroFaultEnable(void)
492-
{
493-
__scs.scb.ccr.bit.div_0_trp = 1;
494-
}
495-
496-
/**
497-
*
498-
* @brief Ignore division by zero errors
499-
*
500-
* This routine disables the divide by zero fault.
501-
* This is the default behavior.
502-
*
503-
* @return N/A
504-
*/
505-
506-
static inline void _ScbDivByZeroFaultDisable(void)
507-
{
508-
__scs.scb.ccr.bit.div_0_trp = 0;
509-
}
510-
511380
/**
512381
*
513382
* @brief Enable faulting on unaligned access
@@ -614,6 +483,136 @@ static inline void _ScbExcPrioSet(uint8_t exc, uint8_t pri)
614483
}
615484

616485
#if !defined(CONFIG_CPU_CORTEX_M0_M0PLUS)
486+
/**
487+
*
488+
* @brief Find out if the currently executing exception is nested
489+
*
490+
* This routine determines if the currently executing exception is nested.
491+
*
492+
* @return 1 if nested, 0 otherwise
493+
*/
494+
495+
static inline int _ScbIsNestedExc(void)
496+
{
497+
/* !bit == preempted exceptions */
498+
return !__scs.scb.icsr.bit.rettobase;
499+
}
500+
501+
/**
502+
*
503+
* @brief Find out if vector table is in SRAM or ROM
504+
*
505+
* This routine determines if the currently executing exception is nested.
506+
*
507+
* @return 1 if in SRAM, 0 if in ROM
508+
*/
509+
510+
static inline uint32_t _ScbIsVtableInSram(void)
511+
{
512+
return !!__scs.scb.vtor.bit.tblbase;
513+
}
514+
515+
/**
516+
*
517+
* @brief Move vector table from SRAM to ROM and vice-versa
518+
*
519+
* This routine moves the vector table to the given memory region.
520+
*
521+
* @return 1 if in SRAM, 0 if in ROM
522+
*/
523+
524+
static inline void _ScbVtableLocationSet(
525+
int sram /* 1 to move vector to SRAM, 0 to move it to ROM */
526+
)
527+
{
528+
__ASSERT(!(sram & 0xfffffffe), "");
529+
__scs.scb.vtor.bit.tblbase = sram;
530+
}
531+
532+
/**
533+
*
534+
* @brief Obtain base address of vector table
535+
*
536+
* This routine returns the vector table's base address.
537+
*
538+
* @return the base address of the vector table
539+
*/
540+
541+
static inline uint32_t _ScbVtableAddrGet(void)
542+
{
543+
return __scs.scb.vtor.bit.tbloff;
544+
}
545+
546+
/**
547+
*
548+
* @brief Set base address of vector table
549+
*
550+
* @a addr must align to the number of exception entries in vector table:
551+
*
552+
* numException = 16 + num_interrupts where each entry is 4 Bytes
553+
*
554+
* As a minimum, @a addr must be a multiple of 128:
555+
*
556+
* 0 <= num_interrupts < 16: multiple 0x080
557+
* 16 <= num_interrupts < 48: multiple 0x100
558+
* 48 <= num_interrupts < 112: multiple 0x200
559+
* ....
560+
* @param addr base address, aligned on 128 minimum
561+
*
562+
* @return N/A
563+
*/
564+
565+
static inline void _ScbVtableAddrSet(uint32_t addr)
566+
{
567+
__ASSERT(!(addr & 0x7F), "invalid vtable base Addr");
568+
__scs.scb.vtor.bit.tbloff = addr;
569+
}
570+
571+
/**
572+
*
573+
* @brief Enable faulting on division by zero
574+
*
575+
* This routine enables the divide by zero fault.
576+
* By default, the CPU ignores the error.
577+
*
578+
* @return N/A
579+
*/
580+
581+
static inline void _ScbDivByZeroFaultEnable(void)
582+
{
583+
__scs.scb.ccr.bit.div_0_trp = 1;
584+
}
585+
586+
/**
587+
*
588+
* @brief Ignore division by zero errors
589+
*
590+
* This routine disables the divide by zero fault.
591+
* This is the default behavior.
592+
*
593+
* @return N/A
594+
*/
595+
596+
static inline void _ScbDivByZeroFaultDisable(void)
597+
{
598+
__scs.scb.ccr.bit.div_0_trp = 0;
599+
}
600+
601+
/**
602+
*
603+
* @brief Get the programmed number of priority groups
604+
*
605+
* Exception priorities can be sub-divided into groups, with sub-priorities.
606+
* Within these groups, exceptions do not preempt each other. The sub-priorities
607+
* are only used to decide which exception will run when several are pending.
608+
*
609+
* @return the number of priority groups
610+
*/
611+
612+
static inline int _ScbNumPriGroupGet(void)
613+
{
614+
return 1 << (7 - __scs.scb.aircr.bit.prigroup);
615+
}
617616

618617
/**
619618
*

0 commit comments

Comments
 (0)