diff --git a/os/hal/include/hal_i2c.h b/os/hal/include/hal_i2c.h index e337a913f..c5776d2e4 100644 --- a/os/hal/include/hal_i2c.h +++ b/os/hal/include/hal_i2c.h @@ -74,12 +74,12 @@ * @brief Driver state machine possible states. */ typedef enum { - I2C_UNINIT = 0, /**< Not initialized. */ - I2C_STOP = 1, /**< Stopped. */ - I2C_READY = 2, /**< Ready. */ - I2C_ACTIVE_TX = 3, /**< Transmitting. */ - I2C_ACTIVE_RX = 4, /**< Receiving. */ - I2C_LOCKED = 5 /**> Bus or driver locked. */ + I2C_UNINIT = 0, /**< @brief Not initialized. */ + I2C_STOP = 1, /**< @brief Stopped. */ + I2C_READY = 2, /**< @brief Ready. */ + I2C_ACTIVE_TX = 3, /**< @brief Transmitting. */ + I2C_ACTIVE_RX = 4, /**< @brief Receiving. */ + I2C_LOCKED = 5 /**< @brief Bus locked. */ } i2cstate_t; #include "hal_i2c_lld.h" diff --git a/os/hal/include/hal_mmc_spi.h b/os/hal/include/hal_mmc_spi.h index fa9d137f8..2d596dba3 100644 --- a/os/hal/include/hal_mmc_spi.h +++ b/os/hal/include/hal_mmc_spi.h @@ -117,7 +117,7 @@ typedef struct { * @brief Current configuration data. */ const MMCConfig *config; - /*** + /** * @brief Addresses use blocks instead of bytes. */ bool block_addresses; diff --git a/os/hal/ports/STM32/LLD/I2Cv2/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv2/hal_i2c_lld.c index 7fa0b8672..190337d92 100644 --- a/os/hal/ports/STM32/LLD/I2Cv2/hal_i2c_lld.c +++ b/os/hal/ports/STM32/LLD/I2Cv2/hal_i2c_lld.c @@ -743,7 +743,7 @@ void i2c_lld_start(I2CDriver *i2cp) { i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C2_TX_DMA_CHANNEL) | STM32_DMA_CR_PL(STM32_I2C_I2C2_DMA_PRIORITY); } -#endif /*STM32_I2C_USE_DMA == TRUE */ +#endif /* STM32_I2C_USE_DMA == TRUE */ #if defined(STM32_I2C2_GLOBAL_NUMBER) || defined(__DOXYGEN__) nvicEnableVector(STM32_I2C2_GLOBAL_NUMBER, STM32_I2C_I2C2_IRQ_PRIORITY); @@ -779,7 +779,7 @@ void i2c_lld_start(I2CDriver *i2cp) { i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C3_TX_DMA_CHANNEL) | STM32_DMA_CR_PL(STM32_I2C_I2C3_DMA_PRIORITY); } -#endif /*STM32_I2C_USE_DMA == TRUE */ +#endif /* STM32_I2C_USE_DMA == TRUE */ #if defined(STM32_I2C3_GLOBAL_NUMBER) || defined(__DOXYGEN__) nvicEnableVector(STM32_I2C3_GLOBAL_NUMBER, STM32_I2C_I2C3_IRQ_PRIORITY); @@ -815,7 +815,7 @@ void i2c_lld_start(I2CDriver *i2cp) { i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C4_TX_DMA_CHANNEL) | STM32_DMA_CR_PL(STM32_I2C_I2C4_DMA_PRIORITY); } -#endif /*STM32_I2C_USE_DMA == TRUE */ +#endif /* STM32_I2C_USE_DMA == TRUE */ #if defined(STM32_I2C4_GLOBAL_NUMBER) || defined(__DOXYGEN__) nvicEnableVector(STM32_I2C4_GLOBAL_NUMBER, STM32_I2C_I2C4_IRQ_PRIORITY); diff --git a/os/hal/ports/STM32/LLD/I2Cv3/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv3/hal_i2c_lld.c index 7d2960304..29f941f48 100644 --- a/os/hal/ports/STM32/LLD/I2Cv3/hal_i2c_lld.c +++ b/os/hal/ports/STM32/LLD/I2Cv3/hal_i2c_lld.c @@ -866,7 +866,7 @@ void i2c_lld_start(I2CDriver *i2cp) { dmaSetRequestSource(i2cp->rx.dma, STM32_DMAMUX1_I2C2_RX); dmaSetRequestSource(i2cp->tx.dma, STM32_DMAMUX1_I2C2_TX); } -#endif /*STM32_I2C_USE_DMA == TRUE */ +#endif /* STM32_I2C_USE_DMA == TRUE */ } #endif /* STM32_I2C_USE_I2C2 */ @@ -893,7 +893,7 @@ void i2c_lld_start(I2CDriver *i2cp) { dmaSetRequestSource(i2cp->rx.dma, STM32_DMAMUX1_I2C3_RX); dmaSetRequestSource(i2cp->tx.dma, STM32_DMAMUX1_I2C3_TX); } -#endif /*STM32_I2C_USE_DMA == TRUE */ +#endif /* STM32_I2C_USE_DMA == TRUE */ } #endif /* STM32_I2C_USE_I2C3 */ @@ -920,7 +920,7 @@ void i2c_lld_start(I2CDriver *i2cp) { bdmaSetRequestSource(i2cp->rx.bdma, STM32_DMAMUX2_I2C4_RX); bdmaSetRequestSource(i2cp->tx.bdma, STM32_DMAMUX2_I2C4_TX); } -#endif /*STM32_I2C_USE_DMA == TRUE */ +#endif /* STM32_I2C_USE_DMA == TRUE */ } #endif /* STM32_I2C_USE_I2C4 */ } diff --git a/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c b/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c index aa4b63dd5..74e05624d 100644 --- a/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c +++ b/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c @@ -512,7 +512,7 @@ static void otg_isoc_out_failed_handler(USBDriver *usbp) { /*otgp->oe[ep].DOEPCTL |= (DOEPCTL_EPDIS | DOEPCTL_SNAK); while (otgp->oe[ep].DOEPCTL & DOEPCTL_EPENA) ;*/ - /* Prepare transfer for next frame */ + /* Prepare transfer for next frame.*/ _usb_isr_invoke_out_cb(usbp, ep); } } diff --git a/os/hal/ports/STM32/LLD/SDIOv1/hal_sdc_lld.c b/os/hal/ports/STM32/LLD/SDIOv1/hal_sdc_lld.c index da92db473..95bee6491 100644 --- a/os/hal/ports/STM32/LLD/SDIOv1/hal_sdc_lld.c +++ b/os/hal/ports/STM32/LLD/SDIOv1/hal_sdc_lld.c @@ -110,7 +110,7 @@ static bool sdc_lld_prepare_read_bytes(SDCDriver *sdcp, /* Transaction starts just after DTEN bit setting.*/ sdcp->sdio->DCTRL = SDIO_DCTRL_DTDIR | - SDIO_DCTRL_DTMODE | /* multibyte data transfer */ + SDIO_DCTRL_DTMODE | /* Multibyte data transfer.*/ SDIO_DCTRL_DMAEN | SDIO_DCTRL_DTEN; @@ -228,10 +228,6 @@ static bool sdc_lld_wait_transaction_end(SDCDriver *sdcp, uint32_t n, sdcp->sdio->ICR = STM32_SDIO_ICR_ALL_FLAGS; sdcp->sdio->DCTRL = 0; osalSysUnlock(); - - /* Wait until interrupt flags to be cleared.*/ - /*while (((DMA2->LISR) >> (sdcp->dma->ishift)) & STM32_DMA_ISR_TCIF) - dmaStreamClearInterrupt(sdcp->dma);*/ #else /* Waits for transfer completion at DMA level, then the stream is disabled and cleared.*/ diff --git a/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c b/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c index 62a3bbf17..84186e024 100644 --- a/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c +++ b/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c @@ -150,7 +150,7 @@ static bool sdc_lld_prepare_read_bytes(SDCDriver *sdcp, /* Transaction starts just after DTEN bit setting.*/ sdcp->sdmmc->DCTRL = SDMMC_DCTRL_DTDIR | - SDMMC_DCTRL_DTMODE | /* multibyte data transfer */ + SDMMC_DCTRL_DTMODE | /* Multibyte data transfer.*/ SDMMC_DCTRL_DMAEN | SDMMC_DCTRL_DTEN; diff --git a/os/hal/src/hal_queues.c b/os/hal/src/hal_queues.c index 106922fcd..6c58ebb04 100644 --- a/os/hal/src/hal_queues.c +++ b/os/hal/src/hal_queues.c @@ -82,7 +82,7 @@ static size_t iq_read(input_queue_t *iqp, uint8_t *bp, size_t n) { memcpy((void *)bp, (void *)iqp->q_buffer, s2); iqp->q_rdptr = iqp->q_buffer + s2; } - else { /* n == s1 */ + else { memcpy((void *)bp, (void *)iqp->q_rdptr, n); iqp->q_rdptr = iqp->q_buffer; } @@ -130,7 +130,7 @@ static size_t oq_write(output_queue_t *oqp, const uint8_t *bp, size_t n) { memcpy((void *)oqp->q_buffer, (const void *)bp, s2); oqp->q_wrptr = oqp->q_buffer + s2; } - else { /* n == s1 */ + else { memcpy((void *)oqp->q_wrptr, (const void *)bp, n); oqp->q_wrptr = oqp->q_buffer; } diff --git a/os/hal/src/hal_rtc.c b/os/hal/src/hal_rtc.c index ea1d551b3..06d4ec698 100644 --- a/os/hal/src/hal_rtc.c +++ b/os/hal/src/hal_rtc.c @@ -258,7 +258,7 @@ void rtcConvertStructTmToDateTime(const struct tm *timp, timespec->day = (uint32_t)timp->tm_mday; timespec->dayofweek = (uint32_t)timp->tm_wday + 1U; if (-1 == timp->tm_isdst) { - timespec->dstflag = 0U; /* set zero if dst is unknown */ + timespec->dstflag = 0U; /* Set zero if dst is unknown.*/ } else { timespec->dstflag = (uint32_t)timp->tm_isdst; @@ -293,7 +293,7 @@ uint32_t rtcConvertDateTimeToFAT(const RTCDateTime *timespec) { day = timespec->day; month = timespec->month; - /* handle DST flag */ + /* Handle DST flag.*/ if (1U == timespec->dstflag) { hour += 1U; if (hour == 24U) { diff --git a/os/oslib/src/chpipes.c b/os/oslib/src/chpipes.c index 6f6e8a30f..47c9dd892 100644 --- a/os/oslib/src/chpipes.c +++ b/os/oslib/src/chpipes.c @@ -129,7 +129,7 @@ static size_t pipe_write(pipe_t *pp, const uint8_t *bp, size_t n) { memcpy((void *)pp->buffer, (const void *)bp, s2); pp->wrptr = pp->buffer + s2; } - else { /* n == s1 */ + else { memcpy((void *)pp->wrptr, (const void *)bp, n); pp->wrptr = pp->buffer; } @@ -180,7 +180,7 @@ static size_t pipe_read(pipe_t *pp, uint8_t *bp, size_t n) { memcpy((void *)bp, (void *)pp->buffer, s2); pp->rdptr = pp->buffer + s2; } - else { /* n == s1 */ + else { memcpy((void *)bp, (void *)pp->rdptr, n); pp->rdptr = pp->buffer; } diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index f1bb4d9f2..e8a877957 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -423,7 +423,7 @@ static inline void chVTDoTickI(void) { fn = vtp->func; vtp->func = NULL; - /* if the list becomes empty then the timer is stopped.*/ + /* If the list becomes empty then the timer is stopped.*/ if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) { port_timer_stop_alarm(); } @@ -439,7 +439,7 @@ static inline void chVTDoTickI(void) { while (vtp->delta <= nowdelta); } - /* if the list is empty, nothing else to do.*/ + /* If the list is empty, nothing else to do.*/ if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) { return; } diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c index c5f3fa859..d1c42e55d 100644 --- a/os/rt/src/chschd.c +++ b/os/rt/src/chschd.c @@ -605,6 +605,6 @@ void chSchDoReschedule(void) { /* Swap operation as tail call.*/ chSysSwitch(currp, otp); } -#endif /*!defined(CH_SCH_DO_RESCHEDULE_HOOKED) */ +#endif /* !defined(CH_SCH_DO_RESCHEDULE_HOOKED) */ /** @} */ diff --git a/tools/style/stylecheck.pl b/tools/style/stylecheck.pl index 2aecf4eb6..9a44cbd4a 100644 --- a/tools/style/stylecheck.pl +++ b/tools/style/stylecheck.pl @@ -24,8 +24,6 @@ $filename = basename($filename); my $cr = "\r"; my $lf = "\n"; my $tab = "\t"; -my $c_comment = ""; -my $state = "start"; sub style { my $desc = shift; @@ -40,10 +38,57 @@ sub error { } my $emptycnt = 0; +my $c_comment_complete = 0; +my $c_comment = ""; +my $state = "start"; foreach my $line (@c_source) { $lineno += 1; + #**************************************************************************** + # Processing comments after decoding. + if ($c_comment_complete != 0) { +# print($c_comment . "\n"); + + #****************************************************************************** + # Special case of lint comment. + if ("$c_comment" =~ /^\s*\/\*lint/) { + } + else { + #****************************************************************************** + # Check on glued doxygen back-comment start. + if ("$c_comment" =~ /^\s*\/\*\*<[^\s]/) { + style "detected glued doxygen back-comment start"; + } + + #****************************************************************************** + # Check on glued doxygen comment start. + if ("$c_comment" =~ /^\s*\/\*\*[^\s<]/) { + style "detected glued doxygen comment start"; + } + + #****************************************************************************** + # Check on glued comment start. + if ("$c_comment" =~ /^\s*\/\*[^\s\*=]/) { + style "detected glued comment start"; + } + + #****************************************************************************** + # Check on lower case letter at comment beginning. + if ("$c_comment" =~ /^\s*\/\*\s*[a-z]/) { + style "detected lower case comment start"; + } + + #****************************************************************************** + # Check on loose comment stop. +# if ("$line" =~ /\s\*\//) { +# style "detected loose comment stop"; +# } + } + + $c_comment_complete = 0; + } + #**************************************************************************** # Check on EOL. if (not ($line =~ /$cr$lf$/)) { @@ -91,17 +136,25 @@ foreach my $line (@c_source) { # State machine handling. if ($state eq "start") { + #****************************************************************************** + # Standard separator. + #****************************************************************************** # Comment start matching. - if ("$line" =~ /^\s*\/\*/) { + if ("$line" =~ /\/\*/) { + + #****************************************************************************** + # Single or multi line comments. if ("$line" =~ /\*\//) { # Special case of single line comments. - $line =~ /^\s*(\/\*.*\*\/)/; + $line =~ /(\/\*.*\*\/)/; + $c_comment = $1; + $c_comment_complete = 1; } else { # Start of multi-line comment. $line =~ /(\/\*.*)/; - $c_comment = $1 . " "; + $c_comment = $1; $state = "incomment"; } } @@ -171,7 +224,7 @@ foreach my $line (@c_source) { # Check on (some) operators. # Before: <<= << >>= >> <= >= == != += -= *= /= %= &= |= ^= if ($line =~ /(\(\S<<=?|\S>>=?|[^\s<]<=|[^\s>]>=|\S[=!+\-*\/%&|^]=)/) { - style "detected glued assignment/comparison operator (1)"; + style "detected glued operator (1)"; } # After: = elsif ($line =~ /=[^\s=]/) { @@ -209,16 +262,27 @@ foreach my $line (@c_source) { #****************************************************************************** # Scanning for comment end. elsif ($state eq "incomment") { - if ("$line" =~ /\*\/\s*$/) { - # End of mult-line comment. + # Left trimming. + $line =~ s/^\s+//; + if ("$line" =~ /^\s*\*\/\s*$/) { + # Just end of comment line. + $c_comment .= "*/"; + $c_comment_complete = 1; +# print("$c_comment"); + $state = "start"; + } + elsif ("$line" =~ /\*\/\s*$/) { + # Text followed by end of comment. $line =~ /(.*\*\/)/; - $c_comment .= $1; + $c_comment .= " " . $1; + $c_comment_complete = 1; # print("$c_comment"); $state = "start"; } else { - # Add the whole line. - $c_comment .= $line . " "; + # Add the whole line, remove first * and following spaces if any. + $line =~ s/^\*?\s*//; + $c_comment .= " " . $line; # print("$c_comment"); } } diff --git a/tools/style/test_negatives.txt b/tools/style/test_negatives.txt index a77a4cab8..fee96e551 100644 --- a/tools/style/test_negatives.txt +++ b/tools/style/test_negatives.txt @@ -19,3 +19,36 @@ a && b a || b a ^^ b +foo(); /* Function call.*/ + +foo(); /* Multiple lines + right comment.*/ + +/** @} */ + +/*lint .*/ + +/* Good comment.*/ + +/** @Good comment.*/ + +/**< @Good comment.*/ + +/* + This is a good comment. +*/ + +/* + * Good comment. + */ + +/* Multiple lines + comment 1.*/ + +/* + * Multiple lines + * comment 2. + */ + +/*===========================================================================*/ + diff --git a/tools/style/test_positives.txt b/tools/style/test_positives.txt index dab285123..ae7e2c735 100644 --- a/tools/style/test_positives.txt +++ b/tools/style/test_positives.txt @@ -58,4 +58,8 @@ a ||b a^^b a^^ b a ^^b - +/** Comment.*/ +/**Comment.*/ +/*Comment*/ +/* comment*/ +/* Comment. */