aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
Diffstat (limited to 'os')
-rw-r--r--os/common/oslib/src/chheap.c18
-rw-r--r--os/common/oslib/src/chmemcore.c4
-rw-r--r--os/rt/include/chalign.h11
-rw-r--r--os/rt/include/chdebug.h16
-rw-r--r--os/rt/include/chsys.h4
-rw-r--r--os/rt/src/chthreads.c5
6 files changed, 36 insertions, 22 deletions
diff --git a/os/common/oslib/src/chheap.c b/os/common/oslib/src/chheap.c
index d49c68386..91d41864a 100644
--- a/os/common/oslib/src/chheap.c
+++ b/os/common/oslib/src/chheap.c
@@ -66,6 +66,14 @@
#define H_SIZE(hp) ((hp)->used.size)
+/*
+ * Number of pages between two pointers in a MISRA-compatible way.
+ */
+#define NPAGES(p1, p2) \
+ /*lint -save -e9033 [10.8] The cast is safe.*/ \
+ ((size_t)((p1) - (p2))) \
+ /*lint -restore*/
+
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
@@ -188,7 +196,7 @@ void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align) {
/* Pointer aligned to the requested alignment.*/
ahp = (heap_header_t *)MEM_ALIGN_NEXT(H_BLOCK(hp), align) - 1U;
- if ((ahp < H_LIMIT(hp)) && (pages <= (size_t)(H_LIMIT(hp) - 1U - ahp))) {
+ if ((ahp < H_LIMIT(hp)) && (pages <= NPAGES(H_LIMIT(hp), ahp - 1U))) {
/* The block is large enough to contain a correctly aligned area
of sufficient size.*/
@@ -196,15 +204,15 @@ void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align) {
/* The block is not properly aligned, must split it.*/
size_t bpages;
- bpages = H_LIMIT(hp) - H_BLOCK(ahp);
- H_PAGES(hp) = ahp - H_BLOCK(hp);
+ bpages = NPAGES(H_LIMIT(hp), H_BLOCK(ahp));
+ H_PAGES(hp) = NPAGES(ahp, H_BLOCK(hp));
if (bpages > pages) {
/* The block is bigger than required, must split the excess.*/
heap_header_t *fp;
/* Creating the excess block.*/
fp = H_BLOCK(ahp) + pages;
- H_PAGES(fp) = bpages - pages - 1U;
+ H_PAGES(fp) = NPAGES(bpages, pages - 1U);
/* Linking the excess block.*/
H_NEXT(fp) = H_NEXT(hp);
@@ -226,7 +234,7 @@ void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align) {
fp = H_BLOCK(hp) + pages;
H_NEXT(fp) = H_NEXT(hp);
- H_PAGES(fp) = H_LIMIT(hp) - H_BLOCK(fp);
+ H_PAGES(fp) = NPAGES(H_LIMIT(hp), H_BLOCK(fp));
H_NEXT(qp) = fp;
}
}
diff --git a/os/common/oslib/src/chmemcore.c b/os/common/oslib/src/chmemcore.c
index fd90ac971..c094ac2aa 100644
--- a/os/common/oslib/src/chmemcore.c
+++ b/os/common/oslib/src/chmemcore.c
@@ -114,9 +114,7 @@ void *chCoreAllocAlignedI(size_t size, unsigned align) {
size = MEM_ALIGN_NEXT(size, align);
p = (uint8_t *)MEM_ALIGN_NEXT(nextmem, align);
- /* ---????? lint -save -e9033 [10.8] The cast is safe.*/
- if ((size_t)(endmem - p) < size) {
- /* ---????? lint -restore*/
+ if (((size_t)endmem - (size_t)p) < size) {
return NULL;
}
nextmem = p + size;
diff --git a/os/rt/include/chalign.h b/os/rt/include/chalign.h
index 9662b3b2f..b2065923e 100644
--- a/os/rt/include/chalign.h
+++ b/os/rt/include/chalign.h
@@ -64,7 +64,10 @@
* @param[in] p variable to be aligned
* @param[in] a alignment, must be a power of two
*/
-#define MEM_ALIGN_PREV(p, a) ((size_t)(p) & ~MEM_ALIGN_MASK(a))
+#define MEM_ALIGN_PREV(p, a) \
+ /*lint -save -e9033 [10.8] The cast is safe.*/ \
+ ((size_t)(p) & ~MEM_ALIGN_MASK(a)) \
+ /*lint -restore*/
/**
* @brief Aligns to the new aligned memory address.
@@ -72,8 +75,10 @@
* @param[in] p variable to be aligned
* @param[in] a alignment, must be a power of two
*/
-#define MEM_ALIGN_NEXT(p, a) MEM_ALIGN_PREV((size_t)(p) + \
- MEM_ALIGN_MASK(a), (a))
+#define MEM_ALIGN_NEXT(p, a) \
+ /*lint -save -e9033 [10.8] The cast is safe.*/ \
+ MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK(a), (a)) \
+ /*lint -restore*/
/**
* @brief Returns whatever a pointer or memory size is aligned.
diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h
index f1a4230f4..a6631fffb 100644
--- a/os/rt/include/chdebug.h
+++ b/os/rt/include/chdebug.h
@@ -244,17 +244,17 @@ typedef struct {
/* When a trace feature is disabled the associated functions are replaced by
an empty macro.*/
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) == 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) == 0U
#define _dbg_trace_switch(otp)
#endif
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) == 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) == 0U
#define _dbg_trace_isr_enter(isr)
#define _dbg_trace_isr_leave(isr)
#endif
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) == 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) == 0U
#define _dbg_trace_halt(reason)
#endif
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) == 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) == 0U
#define chDbgWriteTraceI(up1, up2)
#define chDbgWriteTrace(up1, up2)
#endif
@@ -334,17 +334,17 @@ extern "C" {
#endif
#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__)
void _dbg_trace_init(void);
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) != 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) != 0U
void _dbg_trace_switch(thread_t *otp);
#endif
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) != 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) != 0U
void _dbg_trace_isr_enter(const char *isr);
void _dbg_trace_isr_leave(const char *isr);
#endif
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) != 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) != 0U
void _dbg_trace_halt(const char *reason);
#endif
-#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) != 0
+#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) != 0U
void chDbgWriteTraceI(void *up1, void *up2);
void chDbgWriteTrace(void *up1, void *up2);
void chDbgSuspendTraceI(uint16_t mask);
diff --git a/os/rt/include/chsys.h b/os/rt/include/chsys.h
index 5e90f0a35..3f51244d5 100644
--- a/os/rt/include/chsys.h
+++ b/os/rt/include/chsys.h
@@ -295,6 +295,10 @@
/* External declarations. */
/*===========================================================================*/
+#if !defined(__DOXYGEN__)
+extern stkalign_t ch_idle_thread_wa[];
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c
index 74c41fa7b..c9cbfac0d 100644
--- a/os/rt/src/chthreads.c
+++ b/os/rt/src/chthreads.c
@@ -172,8 +172,7 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
chDbgCheck(MEM_IS_ALIGNED(tdp->wbase, PORT_WORKING_AREA_ALIGN) &&
MEM_IS_ALIGNED(tdp->wend, PORT_STACK_ALIGN) &&
(tdp->wend > tdp->wbase) &&
- ((size_t)((tdp->wend - tdp->wbase) *
- sizeof (stkalign_t)) >= THD_WORKING_AREA_SIZE(0)));
+ (((size_t)tdp->wend - (size_t)tdp->wbase) >= THD_WORKING_AREA_SIZE(0)));
chDbgCheck((tdp->prio <= HIGHPRIO) && (tdp->funcp != NULL));
/* The thread structure is laid out in the upper part of the thread
@@ -518,7 +517,7 @@ void chThdExitS(msg_t msg) {
registry because there is no memory to recover.*/
#if CH_CFG_USE_DYNAMIC == TRUE
if ((tp->refs == (trefs_t)0) &&
- (tp->flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) {
+ ((tp->flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC)) {
REG_REMOVE(tp);
}
#else