From ff109ac9e64f0f107a21343cd82d603b04c35aaf Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 10 Feb 2018 11:25:29 +0000 Subject: MISRA-related changes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11473 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal_buffers.c | 14 ++++++++------ os/hal/src/hal_pal.c | 8 ++++---- os/hal/src/hal_queues.c | 20 ++++++++++++-------- os/hal/src/hal_serial.c | 9 ++++++--- os/hal/src/hal_serial_usb.c | 8 +++++--- 5 files changed, 35 insertions(+), 24 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/hal_buffers.c b/os/hal/src/hal_buffers.c index 599c9517b..c85be601c 100644 --- a/os/hal/src/hal_buffers.c +++ b/os/hal/src/hal_buffers.c @@ -358,14 +358,14 @@ msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, sysinterval_t timeout) { size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp, size_t n, sysinterval_t timeout) { size_t r = 0; - sysinterval_t deadline; + systime_t deadline; osalDbgCheck(n > 0U); osalSysLock(); /* Time window for the whole operation.*/ - deadline = osalOsGetSystemTimeX() + timeout; + deadline = osalTimeAddX(osalOsGetSystemTimeX(), timeout); while (true) { size_t size; @@ -380,7 +380,8 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp, msg = ibqGetFullBufferTimeoutS(ibqp, timeout); } else { - sysinterval_t next_timeout = deadline - osalOsGetSystemTimeX(); + sysinterval_t next_timeout = osalTimeDiffX(osalOsGetSystemTimeX(), + deadline); /* Handling the case where the system time went past the deadline, in this case next becomes a very high number because the system @@ -740,14 +741,14 @@ msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b, size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp, size_t n, sysinterval_t timeout) { size_t w = 0; - sysinterval_t deadline; + systime_t deadline; osalDbgCheck(n > 0U); osalSysLock(); /* Time window for the whole operation.*/ - deadline = osalOsGetSystemTimeX() + timeout; + deadline = osalTimeAddX(osalOsGetSystemTimeX(), timeout); while (true) { size_t size; @@ -762,7 +763,8 @@ size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp, msg = obqGetEmptyBufferTimeoutS(obqp, timeout); } else { - sysinterval_t next_timeout = deadline - osalOsGetSystemTimeX(); + sysinterval_t next_timeout = osalTimeDiffX(osalOsGetSystemTimeX(), + deadline); /* Handling the case where the system time went past the deadline, in this case next becomes a very high number because the system diff --git a/os/hal/src/hal_pal.c b/os/hal/src/hal_pal.c index c6f562c16..573ca2ff8 100644 --- a/os/hal/src/hal_pal.c +++ b/os/hal/src/hal_pal.c @@ -117,7 +117,7 @@ void palSetBusMode(IOBus *bus, iomode_t mode) { palSetGroupMode(bus->portid, bus->mask, bus->offset, mode); } -#if PAL_USE_CALLBACKS || defined(__DOXYGEN__) +#if (PAL_USE_CALLBACKS == TRUE) || defined(__DOXYGEN__) /** * @brief Associates a callback to a port/pad. * @@ -151,9 +151,9 @@ void palSetLineCallbackI(ioline_t line, palcallback_t cb, void *arg) { pep->cb = cb; pep->arg = arg; } -#endif /* PAL_USE_CALLBACKS */ +#endif /* PAL_USE_CALLBACKS == TRUE */ -#if PAL_USE_WAIT || defined(__DOXYGEN__) +#if (PAL_USE_WAIT == TRUE) || defined(__DOXYGEN__) /** * @brief Waits for an edge on the specified port/pad. * @@ -194,7 +194,7 @@ msg_t palWaitLineTimeoutS(ioline_t line, palevent_t *pep = pal_lld_get_line_event(line); return osalThreadEnqueueTimeoutS(&pep->threads, timeout); } -#endif /* PAL_USE_WAIT */ +#endif /* PAL_USE_WAIT == TRUE */ #endif /* HAL_USE_PAL == TRUE */ diff --git a/os/hal/src/hal_queues.c b/os/hal/src/hal_queues.c index 4ec84c1b3..1e2386c2a 100644 --- a/os/hal/src/hal_queues.c +++ b/os/hal/src/hal_queues.c @@ -68,7 +68,9 @@ static size_t iq_read(input_queue_t *iqp, uint8_t *bp, size_t n) { } /* Number of bytes before buffer limit.*/ - s1 = iqp->q_top - iqp->q_rdptr; + /*lint -save -e9033 [10.8] Checked to be safe.*/ + s1 = (size_t)(iqp->q_top - iqp->q_rdptr); + /*lint -restore*/ if (n < s1) { memcpy((void *)bp, (void *)iqp->q_rdptr, n); iqp->q_rdptr += n; @@ -114,20 +116,22 @@ static size_t oq_write(output_queue_t *oqp, const uint8_t *bp, size_t n) { } /* Number of bytes before buffer limit.*/ - s1 = oqp->q_top - oqp->q_wrptr; + /*lint -save -e9033 [10.8] Checked to be safe.*/ + s1 = (size_t)(oqp->q_top - oqp->q_wrptr); + /*lint -restore*/ if (n < s1) { - memcpy((void *)oqp->q_wrptr, (void *)bp, n); + memcpy((void *)oqp->q_wrptr, (const void *)bp, n); oqp->q_wrptr += n; } else if (n > s1) { - memcpy((void *)oqp->q_wrptr, (void *)bp, s1); + memcpy((void *)oqp->q_wrptr, (const void *)bp, s1); bp += s1; s2 = n - s1; - memcpy((void *)oqp->q_buffer, (void *)bp, s2); + memcpy((void *)oqp->q_buffer, (const void *)bp, s2); oqp->q_wrptr = oqp->q_buffer + s2; } else { /* n == s1 */ - memcpy((void *)oqp->q_wrptr, (void *)bp, n); + memcpy((void *)oqp->q_wrptr, (const void *)bp, n); oqp->q_wrptr = oqp->q_buffer; } @@ -395,7 +399,7 @@ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp, size_t done; done = iq_read(iqp, bp, n); - if (done == 0) { + if (done == (size_t)0) { msg_t msg = osalThreadEnqueueTimeoutS(&iqp->q_waiting, timeout); /* Anything except MSG_OK causes the operation to stop.*/ @@ -664,7 +668,7 @@ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp, size_t done; done = oq_write(oqp, bp, n); - if (done == 0) { + if (done == (size_t)0) { msg_t msg = osalThreadEnqueueTimeoutS(&oqp->q_waiting, timeout); /* Anything except MSG_OK causes the operation to stop.*/ diff --git a/os/hal/src/hal_serial.c b/os/hal/src/hal_serial.c index ee2b9ad55..734316877 100644 --- a/os/hal/src/hal_serial.c +++ b/os/hal/src/hal_serial.c @@ -100,13 +100,16 @@ static msg_t _ctl(void *ip, unsigned int operation, void *arg) { case CHN_CTL_NOP: osalDbgCheck(arg == NULL); break; + case CHN_CTL_INVALID: + osalDbgAssert(false, "invalid CTL operation"); + break; default: #if defined(SD_LLD_IMPLEMENTS_CTL) + /* Delegating to the LLD if supported.*/ return sd_lld_control(sdp, operation, arg); -#endif - case CHN_CTL_INVALID: - osalDbgAssert(false, "invalid CTL operation"); +#else break; +#endif } return MSG_OK; } diff --git a/os/hal/src/hal_serial_usb.c b/os/hal/src/hal_serial_usb.c index 0e63a386c..02a61d09b 100644 --- a/os/hal/src/hal_serial_usb.c +++ b/os/hal/src/hal_serial_usb.c @@ -135,6 +135,9 @@ static msg_t _ctl(void *ip, unsigned int operation, void *arg) { case CHN_CTL_NOP: osalDbgCheck(arg == NULL); break; + case CHN_CTL_INVALID: + osalDbgAssert(false, "invalid CTL operation"); + break; default: #if defined(SDU_LLD_IMPLEMENTS_CTL) /* The SDU driver does not have a LLD but the application can use this @@ -143,10 +146,9 @@ static msg_t _ctl(void *ip, unsigned int operation, void *arg) { unsigned int operation, void *arg); return sdu_lld_control(sdup, operation, arg); -#endif - case CHN_CTL_INVALID: - osalDbgAssert(false, "invalid CTL operation"); +#else break; +#endif } return MSG_OK; } -- cgit v1.2.3