硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3405|回复: 4
收起左侧

怎样写好注释?

[复制链接]

29

主题

101

回帖

188

积分

初级会员

积分
188
发表于 2016-12-20 09:44:21 | 显示全部楼层 |阅读模式
  1. /**
  2.   * @brief  Initializes the RCC Oscillators according to the specified parameters in the
  3.   *         RCC_OscInitTypeDef.
  4.   * @param  RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that
  5.   *         contains the configuration information for the RCC Oscillators.
  6.   * @note   The PLL is not disabled when used as system clock.
  7.   * @note   Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not
  8.   *         supported by this API. User should request a transition to LSE Off
  9.   *         first and then LSE On or LSE Bypass.
  10.   * @note   Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  11.   *         supported by this API. User should request a transition to HSE Off
  12.   *         first and then HSE On or HSE Bypass.
  13.   * @retval HAL status
  14.   */
  15. __weak HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef  *RCC_OscInitStruct)
  16. {
  17. ;
  18. }
复制代码
这是stm32cube HAL库函数的注释。
  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f4xx_hal_rcc.c
  4.   * @author  MCD Application Team
  5.   * @version V1.6.0
  6.   * @date    04-November-2016
  7.   * @brief   RCC HAL module driver.
  8.   *          This file provides firmware functions to manage the following
  9.   *          functionalities of the Reset and Clock Control (RCC) peripheral:
  10.   *           + Initialization and de-initialization functions
  11.   *           + Peripheral Control functions
  12.   *      
  13.   @verbatim               
  14.   ==============================================================================
  15.                       ##### RCC specific features #####
  16.   ==============================================================================
  17.     [..]  
  18.       After reset the device is running from Internal High Speed oscillator
  19.       (HSI 16MHz) with Flash 0 wait state, Flash prefetch buffer, D-Cache
  20.       and I-Cache are disabled, and all peripherals are off except internal
  21.       SRAM, Flash and JTAG.
  22.       (+) There is no prescaler on High speed (AHB) and Low speed (APB) busses;
  23.           all peripherals mapped on these busses are running at HSI speed.
  24.       (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
  25.       (+) All GPIOs are in input floating state, except the JTAG pins which
  26.           are assigned to be used for debug purpose.
  27.    
  28.     [..]         
  29.       Once the device started from reset, the user application has to:        
  30.       (+) Configure the clock source to be used to drive the System clock
  31.           (if the application needs higher frequency/performance)
  32.       (+) Configure the System clock frequency and Flash settings  
  33.       (+) Configure the AHB and APB busses prescalers
  34.       (+) Enable the clock for the peripheral(s) to be used
  35.       (+) Configure the clock source(s) for peripherals which clocks are not
  36.           derived from the System clock (I2S, RTC, ADC, USB OTG FS/SDIO/RNG)
  37.                       ##### RCC Limitations #####
  38.   ==============================================================================
  39.     [..]  
  40.       A delay between an RCC peripheral clock enable and the effective peripheral
  41.       enabling should be taken into account in order to manage the peripheral read/write
  42.       from/to registers.
  43.       (+) This delay depends on the peripheral mapping.
  44.       (+) If peripheral is mapped on AHB: the delay is 2 AHB clock cycle
  45.           after the clock enable bit is set on the hardware register
  46.       (+) If peripheral is mapped on APB: the delay is 2 APB clock cycle
  47.           after the clock enable bit is set on the hardware register
  48.     [..]  
  49.       Implemented Workaround:
  50.       (+) For AHB & APB peripherals, a dummy read to the peripheral register has been
  51.           inserted in each __HAL_RCC_PPP_CLK_ENABLE() macro.
  52.   @endverbatim
  53.   ******************************************************************************
  54.   * @attention
  55.   *
  56.   * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  57.   *
  58.   * Redistribution and use in source and binary forms, with or without modification,
  59.   * are permitted provided that the following conditions are met:
  60.   *   1. Redistributions of source code must retain the above copyright notice,
  61.   *      this list of conditions and the following disclaimer.
  62.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  63.   *      this list of conditions and the following disclaimer in the documentation
  64.   *      and/or other materials provided with the distribution.
  65.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  66.   *      may be used to endorse or promote products derived from this software
  67.   *      without specific prior written permission.
  68.   *
  69.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  70.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  71.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  72.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  73.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  74.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  77.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  78.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  79.   *
  80.   ******************************************************************************
  81.   */
复制代码
这是C文件的注释
里面有很多@开头的标签,这种格式好像可以借助工具生成api文档,我们个人写程序写成什么样才算比较好?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
发表于 2016-12-20 09:46:44 | 显示全部楼层
我比较喜欢uCOS-III的注释,我们的工程也是这种形式的注释,因人而异吧。
回复

使用道具 举报

29

主题

101

回帖

188

积分

初级会员

积分
188
 楼主| 发表于 2016-12-20 09:55:24 | 显示全部楼层
有没有什么写注释的好工具?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
发表于 2016-12-21 08:15:52 | 显示全部楼层

回 captainliuy 的帖子

captainliuy:有没有什么写注释的好工具? (2016-12-20 09:55) 
我一直用的最low的方法,我是复制粘贴的,如果你用的Sublime,NotePad++等编辑器,应该有专用的插件。
回复

使用道具 举报

0

主题

42

回帖

42

积分

新手上路

积分
42
发表于 2020-8-6 22:21:52 | 显示全部楼层
@brief那些,用的是Doxygen软件,可以生成HTML、PDF等格式,方便查看,达到代码即文档的效果。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-3 17:31 , Processed in 0.212516 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表