|
发表于 2012-9-16 11:11:34
|
显示全部楼层
本帖最后由 kebaojun305 于 2012-9-16 11:17 编辑
还可以再优化 库里占空间的是参数检测 把参数检测的宏定义屏蔽 就基本上和你使用寄存器操作一样的大小了。 同样适用 STM8S的库 ,比如如下的一个库函数中的参数检测- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_MODE(ADC_InitStruct->ADC_Mode));
- assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ScanConvMode));
- assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode));
- assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConv));
- assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
- assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfChannel));
复制代码 在库的配置头文件(XX_conf.h)中可以屏蔽到这个检测(第3行 实际上注释已经写的很清楚了。- /* Uncomment the line below to expanse the "assert_param" macro in the
- Standard Peripheral Library drivers code */
- /* #define USE_FULL_ASSERT 1 */
- /* Exported macro ------------------------------------------------------------*/
- #ifdef USE_FULL_ASSERT
- /**
- * @brief The assert_param macro is used for function's parameters check.
- * @param expr: If expr is false, it calls assert_failed function
- * which reports the name of the source file and the source
- * line number of the call that failed.
- * If expr is true, it returns no value.
- * @retval None
- */
- #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
- /* Exported functions ------------------------------------------------------- */
- void assert_failed(uint8_t* file, uint32_t line);
- #else
- #define assert_param(expr) ((void)0)
- #endif /* USE_FULL_ASSERT */
复制代码 |
|