Simplified ports interface, used by just ARMv7-M so far. Integration of ccportab.h into port layers ongoing too.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14464 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-06-04 11:59:01 +00:00
parent 67e27c9902
commit e0d5638a2b
8 changed files with 202 additions and 63 deletions

View File

@ -423,14 +423,6 @@
/* Module data structures and types. */
/*===========================================================================*/
/**
* @brief Type of stack and memory alignment enforcement.
* @note In this architecture the stack alignment is enforced to 64 bits,
* 32 bits alignment is supported by hardware but deprecated by ARM,
* the implementation choice is to not offer the option.
*/
typedef uint64_t stkalign_t;
/**
* @brief Interrupt saved context.
* @details This structure represents the stack frame saved during a
@ -605,6 +597,11 @@ struct port_context {
/* Note, checked above.*/
#endif
/**
* @brief Optimized thread function declaration macro.
*/
#define PORT_THD_FUNCTION(tname, arg) void tname(void *arg)
/**
* @brief Platform dependent part of the @p chThdCreateI() API.
* @details This code usually setup the context switching frame represented

View File

@ -32,65 +32,78 @@
#include <stdint.h>
#include <stdbool.h>
#include "ccportab.h"
/**
* @name Kernel types
* @name Architecture data constraints
*/
#define PORT_ARCH_SIZEOF_DATA_PTR 4
#define PORT_ARCH_SIZEOF_CODE_PTR 4
#define PORT_ARCH_REGISTERS_WIDTH 32
#define PORT_ARCH_REVERSE_ORDER 1
/** @} */
/**
* @name Port types
* @{
*/
typedef uint32_t rtcnt_t; /**< Realtime counter. */
typedef uint64_t rttime_t; /**< Realtime accumulator. */
typedef uint32_t syssts_t; /**< System status word. */
typedef uint8_t tmode_t; /**< Thread flags. */
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t trefs_t; /**< Thread references counter. */
typedef uint8_t tslices_t; /**< Thread time slices counter.*/
typedef uint32_t tprio_t; /**< Thread priority. */
typedef int32_t msg_t; /**< Inter-thread message. */
typedef int32_t eventid_t; /**< Numeric event identifier. */
typedef uint32_t eventmask_t; /**< Mask of event identifiers. */
typedef uint32_t eventflags_t; /**< Mask of event flags. */
typedef int32_t cnt_t; /**< Generic signed counter. */
typedef uint32_t ucnt_t; /**< Generic unsigned counter. */
/**
* @brief Realtime counter.
*/
typedef uint32_t port_rtcnt_t;
/**
* @brief Realtime accumulator.
*/
typedef uint64_t port_rttime_t;
/**
* @brief System status word.
*/
typedef uint32_t port_syssts_t;
/**
* @brief Type of stack and memory alignment enforcement.
* @note In this architecture the stack alignment is enforced to 64 bits,
* 32 bits alignment is supported by hardware but deprecated by ARM,
* the implementation choice is to not offer the option.
*/
typedef uint64_t port_stkalign_t;
/** @} */
/**
* @brief This port does not define OS-related types.
*/
#define PORT_DOES_NOT_PROVIDE_TYPES
/**
* @brief ROM constant modifier.
* @note It is set to use the "const" keyword in this port.
* @deprecated
*/
#define ROMCONST const
#define ROMCONST CC_ROMCONST
/**
* @brief Makes functions not inlineable.
* @note If the compiler does not support such attribute then some
* time-dependent services could be degraded.
* @deprecated
*/
#define NOINLINE __attribute__((noinline))
/**
* @brief Optimized thread function declaration macro.
*/
#define PORT_THD_FUNCTION(tname, arg) void tname(void *arg)
/**
* @brief Packed variable specifier.
*/
#define PACKED_VAR __attribute__((packed))
#define NOINLINE CC_NO_INLINE
/**
* @brief Memory alignment enforcement for variables.
* @deprecated
*/
#define ALIGNED_VAR(n) __attribute__((aligned(n)))
#define ALIGNED_VAR(n) CC_ALIGN_DATA(n)
/**
* @brief Size of a pointer.
* @note To be used where the sizeof operator cannot be used, preprocessor
* expressions for example.
* @deprecated
*/
#define SIZEOF_PTR 4
/**
* @brief True if alignment is low-high in current architecture.
*/
#define REVERSE_ORDER 1
#define SIZEOF_PTR PORT_ARCH_SIZEOF_DATA_PTR
#endif /* CHTYPES_H */

View File

@ -3,7 +3,8 @@ PORTSRC = $(CHIBIOS)/os/common/ports/ARMv7-M/chcore.c
PORTASM = $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/chcoreasm.S
PORTINC = $(CHIBIOS)/os/common/ports/ARMv7-M \
PORTINC = $(CHIBIOS)/os/common/portability/GCC \
$(CHIBIOS)/os/common/ports/ARMv7-M \
$(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC
# Shared variables

View File

@ -377,6 +377,48 @@
/* Module data structures and types. */
/*===========================================================================*/
#if defined(PORT_DOES_NOT_PROVIDE_TYPES) || defined(__DOXYGEN__)
/**
* @name Kernel types
* @{
*/
typedef port_rtcnt_t rtcnt_t; /**< Realtime counter. */
typedef port_syssts_t syssts_t; /**< System status word. */
typedef port_stkalign_t stkalign_t; /**< Stack alignment type. */
#if (PORT_ARCH_REGISTERS_WIDTH == 32) || defined(__DOXYGEN__)
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint32_t tprio_t; /**< Thread priority. */
typedef int32_t msg_t; /**< Inter-thread message. */
typedef int32_t eventid_t; /**< Numeric event identifier. */
typedef uint32_t eventmask_t; /**< Mask of event identifiers. */
typedef uint32_t eventflags_t; /**< Mask of event flags. */
typedef int32_t cnt_t; /**< Generic signed counter. */
typedef uint32_t ucnt_t; /**< Generic unsigned counter. */
#elif PORT_ARCH_REGISTERS_WIDTH == 16
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint16_t tprio_t; /**< Thread priority. */
typedef int16_t msg_t; /**< Inter-thread message. */
typedef int16_t eventid_t; /**< Numeric event identifier. */
typedef uint16_t eventmask_t; /**< Mask of event identifiers. */
typedef uint16_t eventflags_t; /**< Mask of event flags. */
typedef int16_t cnt_t; /**< Generic signed counter. */
typedef uint16_t ucnt_t; /**< Generic unsigned counter. */
#elif PORT_ARCH_REGISTERS_WIDTH == 8
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t tprio_t; /**< Thread priority. */
typedef int16_t msg_t; /**< Inter-thread message. */
typedef int8_t eventid_t; /**< Numeric event identifier. */
typedef uint8_t eventmask_t; /**< Mask of event identifiers. */
typedef uint8_t eventflags_t; /**< Mask of event flags. */
typedef int8_t cnt_t; /**< Generic signed counter. */
typedef uint8_t ucnt_t; /**< Generic unsigned counter. */
#else
#error "unsupported PORT_ARCH_REGISTERS_WIDTH value"
#endif
/** @} */
#endif /* defined(PORT_DOES_NOT_PROVIDE_TYPES) */
#if (CH_CFG_ST_RESOLUTION == 32) || defined(__DOXYGEN__)
/**
* @brief Type of system time.

View File

@ -96,7 +96,6 @@
#include "chrestrictions.h"
/* Base kernel headers.*/
#include "chtypes.h"
#include "chearly.h"
#include "chrfcu.h"
#include "chdebug.h"

View File

@ -28,6 +28,13 @@
#ifndef CHEARLY_H
#define CHEARLY_H
/* Port architecture-related definitions.*/
#if !defined(PORT_NEW_TYPES)
#include "chtypes.h"
#else
#include "chporttypes.h"
#endif
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
@ -40,10 +47,80 @@
/* Derived constants and error checks. */
/*===========================================================================*/
#if defined(PORT_DOES_NOT_PROVIDE_TYPES)
#if !defined(PORT_ARCH_SIZEOF_DATA_PTR)
#error "PORT_ARCH_SIZEOF_DATA_PTR not defined in chtypes.h"
#endif
#if !defined(PORT_ARCH_SIZEOF_CODE_PTR)
#error "PORT_ARCH_SIZEOF_CODE_PTR not defined in chtypes.h"
#endif
#if !defined(PORT_ARCH_REGISTERS_WIDTH)
#error "PORT_ARCH_REGISTERS_WIDTH not defined in chtypes.h"
#endif
#if !defined(PORT_ARCH_REVERSE_ORDER)
#error "PORT_ARCH_REVERSE_ORDER not defined in chtypes.h"
#endif
#endif
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
#if defined(PORT_DOES_NOT_PROVIDE_TYPES) || defined(__DOXYGEN__)
/**
* @name Kernel types
* @{
*/
typedef port_rtcnt_t rtcnt_t; /**< Realtime counter. */
typedef port_rttime_t rttime_t; /**< Realtime accumulator. */
typedef port_syssts_t syssts_t; /**< System status word. */
typedef port_stkalign_t stkalign_t; /**< Stack alignment type. */
#if (PORT_ARCH_REGISTERS_WIDTH == 32) || defined(__DOXYGEN__)
typedef uint8_t tmode_t; /**< Thread flags. */
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t trefs_t; /**< Thread references counter. */
typedef uint8_t tslices_t; /**< Thread time slices counter.*/
typedef uint32_t tprio_t; /**< Thread priority. */
typedef int32_t msg_t; /**< Inter-thread message. */
typedef int32_t eventid_t; /**< Numeric event identifier. */
typedef uint32_t eventmask_t; /**< Mask of event identifiers. */
typedef uint32_t eventflags_t; /**< Mask of event flags. */
typedef int32_t cnt_t; /**< Generic signed counter. */
typedef uint32_t ucnt_t; /**< Generic unsigned counter. */
#elif PORT_ARCH_REGISTERS_WIDTH == 16
typedef uint8_t tmode_t; /**< Thread flags. */
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t trefs_t; /**< Thread references counter. */
typedef uint8_t tslices_t; /**< Thread time slices counter.*/
typedef uint16_t tprio_t; /**< Thread priority. */
typedef int16_t msg_t; /**< Inter-thread message. */
typedef int16_t eventid_t; /**< Numeric event identifier. */
typedef uint16_t eventmask_t; /**< Mask of event identifiers. */
typedef uint16_t eventflags_t; /**< Mask of event flags. */
typedef int16_t cnt_t; /**< Generic signed counter. */
typedef uint16_t ucnt_t; /**< Generic unsigned counter. */
#elif PORT_ARCH_REGISTERS_WIDTH == 8
typedef uint8_t tmode_t; /**< Thread flags. */
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t trefs_t; /**< Thread references counter. */
typedef uint8_t tslices_t; /**< Thread time slices counter.*/
typedef uint8_t tprio_t; /**< Thread priority. */
typedef int16_t msg_t; /**< Inter-thread message. */
typedef int8_t eventid_t; /**< Numeric event identifier. */
typedef uint8_t eventmask_t; /**< Mask of event identifiers. */
typedef uint8_t eventflags_t; /**< Mask of event flags. */
typedef int8_t cnt_t; /**< Generic signed counter. */
typedef uint8_t ucnt_t; /**< Generic unsigned counter. */
#else
#error "unsupported PORT_ARCH_REGISTERS_WIDTH value"
#endif
/** @} */
#endif /* defined(PORT_DOES_NOT_PROVIDE_TYPES) */
/**
* @brief Type of a core identifier.
* @note Core identifiers have ranges from 0 to @p PORT_CORES_NUMBER - 1.
@ -66,9 +143,24 @@ typedef struct ch_os_instance os_instance_t;
/**
* @brief Utility to make the parameter a quoted string.
*
* @param[in] a literal to be string-ified
*/
#define __CH_STRINGIFY(a) #a
/**
* @brief Structure field offset utility.
*
* @param[in] st structured type name
* @param[in] m field name in the structured type
* @return The offset of the field in the structured type.
*/
#define __CH_OFFSETOF(st, m) \
/*lint -save -e9005 -e9033 -e413 [11.8, 10.8, 1.3] Normal pointers
arithmetic, it is safe.*/ \
((size_t)((char *)&((st *)0)->m - (char *)0)) \
/*lint -restore*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/

View File

@ -67,12 +67,6 @@
/* Module local functions. */
/*===========================================================================*/
#define _offsetof(st, m) \
/*lint -save -e9005 -e9033 -e413 [11.8, 10.8, 1.3] Normal pointers
arithmetic, it is safe.*/ \
((size_t)((char *)&((st *)0)->m - (char *)0)) \
/*lint -restore*/
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
@ -90,30 +84,30 @@ ROMCONST chdebug_t ch_debug = {
(uint8_t)sizeof (void *),
(uint8_t)sizeof (systime_t),
(uint8_t)sizeof (thread_t),
(uint8_t)_offsetof(thread_t, hdr.pqueue.prio),
(uint8_t)_offsetof(thread_t, ctx),
(uint8_t)_offsetof(thread_t, rqueue.next),
(uint8_t)_offsetof(thread_t, rqueue.prev),
(uint8_t)_offsetof(thread_t, name),
(uint8_t)__CH_OFFSETOF(thread_t, hdr.pqueue.prio),
(uint8_t)__CH_OFFSETOF(thread_t, ctx),
(uint8_t)__CH_OFFSETOF(thread_t, rqueue.next),
(uint8_t)__CH_OFFSETOF(thread_t, rqueue.prev),
(uint8_t)__CH_OFFSETOF(thread_t, name),
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
(uint8_t)_offsetof(thread_t, wabase),
(uint8_t)__CH_OFFSETOF(thread_t, wabase),
#else
(uint8_t)0,
#endif
(uint8_t)_offsetof(thread_t, state),
(uint8_t)_offsetof(thread_t, flags),
(uint8_t)__CH_OFFSETOF(thread_t, state),
(uint8_t)__CH_OFFSETOF(thread_t, flags),
#if CH_CFG_USE_DYNAMIC == TRUE
(uint8_t)_offsetof(thread_t, refs),
(uint8_t)__CH_OFFSETOF(thread_t, refs),
#else
(uint8_t)0,
#endif
#if CH_CFG_TIME_QUANTUM > 0
(uint8_t)_offsetof(thread_t, ticks),
(uint8_t)__CH_OFFSETOF(thread_t, ticks),
#else
(uint8_t)0,
#endif
#if CH_DBG_THREADS_PROFILING == TRUE
(uint8_t)_offsetof(thread_t, time)
(uint8_t)__CH_OFFSETOF(thread_t, time)
#else
(uint8_t)0
#endif
@ -138,7 +132,7 @@ thread_t *chRegFirstThread(void) {
chSysLock();
p = (uint8_t *)REG_HEADER(currcore)->next;
/*lint -save -e413 [1.3] Safe to subtract a calculated offset.*/
tp = (thread_t *)(p - _offsetof(thread_t, rqueue));
tp = (thread_t *)(p - __CH_OFFSETOF(thread_t, rqueue));
/*lint -restore*/
#if CH_CFG_USE_DYNAMIC == TRUE
tp->refs++;
@ -174,7 +168,7 @@ thread_t *chRegNextThread(thread_t *tp) {
else {
uint8_t *p = (uint8_t *)nqp;
/*lint -save -e413 [1.3] Safe to subtract a calculated offset.*/
ntp = (thread_t *)(p - _offsetof(thread_t, rqueue));
ntp = (thread_t *)(p - __CH_OFFSETOF(thread_t, rqueue));
/*lint -restore*/
chDbgAssert(ntp->refs < (trefs_t)255, "too many references");

View File

@ -74,6 +74,7 @@
*****************************************************************************
*** Next ***
- NEW: Simplified interface between ports and RT/NIL.
- NEW: STM32 ADCv3, USARTv2, USARTv3, USBv1 updated for dynamic clocking.
- NEW: Improved PWR settings for STM32G0, STM32G4 and STM32L4+.
- NEW: Dynamic support implemented for STM32G0, STM32G4, STM32L4+, STM32WL.