debug.h DEBUG_LEVEL PRINTD

/******************************************************************************

                  版权所有 (C) 2014

 ******************************************************************************
  文 件 名   : debug.h
  版 本 号   : 初稿
  作    者   : zhj2232006
  生成日期   : 2014年10月8日
  最近修改   :
  功能描述   : debug.h 的头文件, DEBUG_LEVEL 需根据需要设置值。
            此文件包含 PRINTD 宏,用法:
            PRINTD(...),与 printf函数类似,但不需要再加换行符 。
              define DEBUG_LEVEL 3   打印文件名、行号、函数名称和自定义内容
              define DEBUG_LEVEL 2   打印函数名称和自定义内容
              define DEBUG_LEVEL 1   仅打印自定义内容
              define DEBUG_LEVEL 0  对 printf 函数无调用,无任何打印信息。
  函数列表   :
  修改历史   :

******************************************************************************/

#ifndef __DEBUG_H__
#define __DEBUG_H__

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

#define DEBUG_LEVEL 2

/*
#define DEBUG

#ifdef DEBUG
#define DEBUG_LEVEL 1
#else
#define DEBUG_LEVEL 0
#endif
*/

#if DEBUG_LEVEL >= 1
#define DEBUG
#else
#undef DEBUG
#endif

#if DEBUG_LEVEL == 3
#define PRINTD(format, ...) printf("[DBG]File: %s, Line: %d, Function: %s()" format "\r\n", __FILE__, __LINE__, __FUNCTION__,  ##__VA_ARGS__)
#elif DEBUG_LEVEL == 2
#define PRINTD(format, ...) printf("[DBG]Function: %s()" format "\r\n", __FUNCTION__,  ##__VA_ARGS__)
#elif DEBUG_LEVEL == 1
#define PRINTD(format, ...) printf(format "\r\n", ##__VA_ARGS__)
#elif DEBUG_LEVEL == 0
#define PRINTD(...)
#endif

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

#endif /* __DEBUG_H__ */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
mylog 是一个多线程安全、高效、易用性很强的 C/C 库 .只需要一个初始化日志目录以及文件名,你就可以像使用 printf 一样的去打印日志。通过日志可以定位(多线程)请求 ip, logid,执行时间等。 1 说明 1) 本文件夹包含源码src以及示例文件sample 2) 编译src生成output(包括iånclude和lib) 3) 使用output的lib和include,具体可以查看sample的Makefile和code 4) 日志级别为FATAL, WARNING, NOTICE, TRACE, DEBUG,以此级别变低 5) 使用MY_LOG_FATAL等打印日志,和printf使用方式类似,非常简单。 2 使用API(查看mylog.h) 1) 初始化日志目录 my_log_init(const char* log_path, const char* normal_path, const char* warn_fatal_path, const int log_level) log_path : log路径 normal_path : 正常日志目录 warn_fatal_path : 异常日志目录 log_level : 日志级别 2) 初始化线程日志数据 my_log_thread_init() 多线程使用 3) 设置一个线程的logid my_log_set_logid(logid) 必须在my_log_thread_init() 之后使用。 4) 设置一个线程的reqip  my_log_set_reqip(reqip) 必须在my_log_thread_init() 之后使用. 5) 设置一个线程的reqip my_log_set_mod(mod) 设置一个线程的reqip, 必须在单线程中使用或者my_log_thread_init() 之后使用. 6)设置计算执行时间的类型(打印时间是ms还是us) my_log_set_time_type(time_type) 必须在单线程中使用或者my_log_thread_init() 之后使用. 7) 打印FATAL日志 MY_LOG_FATAL(logfmt, arg...) 日记级别 >=1会打印 FATAL日志。 8)打印WARNNING日志 MY_LOG_WARNING(logfmt, arg...) 日记级别 >=2会打印 WARNING日志。 9) 打印NOTICE日志 MY_LOG_NOTICE(logfmt, arg...) 日记级别 >=4会打印 NOTICE日志。 10)打印TRACE日志 MY_LOG_TRACE(logfmt, arg...) 日记级别 >=8会打印TRACE日志。 11) 打印DEBUG日志 MY_LOG_DEBUG(logfmt, arg...) 标签:mylog 分享 window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "2", "bdMiniList": [], "bdPic": "", "bdStyle": "1", "bdSize": "24" }, "share": {} }; with (document)0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' ~(-new Date() / 36e5)];\r\n \r\n \r\n \r\n \r\n \u8f6f\u4ef6\u9996\u9875\r\n \u8f6f\u4ef6\u4e0b\u8f7d\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nwindow.changyan.api.config({\r\nappid: 'cysXjLKDf', conf: 'prod_33c27aefa42004c9b2c12a759c851039' });
NEWS for OpenSC -- History of user visible changes Complete change history is available online: http://www.opensc-project.org/opensc/timeline New in 0.12.0; 2010-12-22 * OpenSC uses a single reader driver, specified at compile time. * New card driver: Italian eID (CNS) by Emanuele Pucciarelli. * New card driver: Portuguese eID by Jo茫o Poupino. * New card driver: westcos by Fran莽ois Leblanc. * pkcs11-tool can use a slot based on ID, label or index in the slot list. * PIN flags are updated from supported cards when C_GetTokenInfo is called. * Support for CardOS 4.4 cards added. * Fature to exclude readers from OpenSC PKCS#11 via "ignored_readers" configuration file entry. * #229: Support semi-automatic fixes to cards personalized with older and broken OpenSC versions. * Software keys removed from pkcs15-init and the PKCS#11 module. OpenSC can either generate keys on card or import plaintext keys to the card, but will never generate plaintext key material in software by itself. All traces of a software token (PKCS#15 Section 7) shall be removed. * Updates to PC/SC driver to build with pcsc-lite >= 1.6.2 * Build script for a binary Mac OS X installer for 10.5 and 10.6 systems. Binary installer includes OpenSC.tokend for platform integration. 10.6 installer includes engine_pkcs11. * Modify Rutoken S binary interfaces by Aktiv Co. * Support GOST R 34.10-2001 and GOST R 34.11-94 by Aktiv Co. * CardOS driver now emulates sign on rsa keys with sign+decrypt usage with padding and decrypt(). This is compatible with old cards and card initialized by Siemens software. Removed "--split-key" option, as it is no longer needed. * Improved debugging support: debug level 3 will show everything except of ASN1 and card matching debugging (usualy not needed). * Massive changes to libopensc. This library is now internal, only used by opensc-pkcs11.so and command line tools. Header files are no longer installed, library should not be used by other applications.
以下是一个基于STM32 HAL库的PWMGenerator2Level例程,可用于生成2级PWM信号: ```c /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f4xx_hal.h" /* Private variables ---------------------------------------------------------*/ TIM_HandleTypeDef htim1; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_TIM1_Init(void); /* Private user code ---------------------------------------------------------*/ int main(void) { /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM1_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); //启动PWM通道1 HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); //启动PWM通道2 uint16_t period = 1000; //设置PWM周期为1000 uint16_t duty1 = 500; //设置PWM通道1的占空比为50% uint16_t duty2 = 250; //设置PWM通道2的占空比为25% __HAL_TIM_SET_AUTORELOAD(&htim1, period); //设置PWM周期 __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty1); //设置PWM通道1的占空比 __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, duty2); //设置PWM通道2的占空比 /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 50; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) { Error_Handler(); } } /** * @brief TIM1 Initialization Function * @param None * @retval None */ static void MX_TIM1_Init(void) { /* USER CODE BEGIN TIM1_Init 0 */ /* USER CODE END TIM1_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; /* USER CODE BEGIN TIM1_Init 1 */ /* USER CODE END TIM1_Init 1 */ htim1.Instance = TIM1; htim1.Init.Prescaler = 99; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 999; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0; htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; if (HAL_TIM_Base_Init(&htim1) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM2; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM1_Init 2 */ /* USER CODE END TIM1_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ while(1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ ``` 需要注意的是,此例程中使用了TIM1通用定时器,并分别使用了其PWM输出通道1和通道2来生成2级PWM信号。在while循环中,没有任何操作,因为PWM信号已经被成功生成并输出。如果需要修改PWM周期和占空比,请修改以下变量: ```c uint16_t period = 1000; //设置PWM周期为1000 uint16_t duty1 = 500; //设置PWM通道1的占空比为50% uint16_t duty2 = 250; //设置PWM通道2的占空比为25% ``` 其中period表示PWM周期,duty1和duty2分别表示PWM通道1和通道2的占空比。需要注意的是,占空比的范围是0~period之间的整数。如果需要将占空比设置为50%,则可以将duty1设置为period/2。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值