bsp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. #include "bsp.h"
  2. #include "led.h"
  3. #include "gw_ctrl.h"
  4. #include "lora.h"
  5. #include "encoder.h"
  6. const char PowerOn_Info[][64]={
  7. {" _ooOoo_"},
  8. {" o8888888o"},
  9. {" 88\" . \"88"},
  10. {" (| -_- |)"},
  11. {" O\\ = /O"},
  12. {" ____/`---'\\____"},
  13. {" . ' \\| |// `."},
  14. {" / \\\\||| : |||// \\"},
  15. {" / _||||| -:- |||||- \\"},
  16. {" | | \\\\ - /// | |"},
  17. {" | \\_| ''\\---/'' | |"},
  18. {" \\ .-\\__ `-` ___/-. /"},
  19. {" ___`. .' /--.--\\ `. . __"},
  20. {" ."" '< `.___\\_<|>_/___.' >'""."},
  21. {" | | : `- \\`.;`\\ _ /`;.`/ - ` : | |"},
  22. {" \\ \\ `-. \\_ __\\ /__ _/ .-` / /"},
  23. {"======`-.____`-.___\\_____/___.-`____.-'======"},
  24. {" `=---='"},
  25. {""},
  26. {"............................................."}
  27. };
  28. OS_TMR watch_tmr;
  29. task_count_t task_count;//任务运行次数
  30. timeout_t tt_watchdog={0xff,0,(1000)};
  31. device_info_t device_info;
  32. device_fixed_info_t device_fixed_info;
  33. union data_u Voltage,Temperature;
  34. FunctionalState irq_state = ENABLE;
  35. timeout_t tt_real_time = {
  36. 0xff,
  37. 0,
  38. REAL_TIME_TIMEOUT,
  39. };
  40. uint8_t watchdog_num = 0;
  41. //定时喂狗
  42. void watchdog_feed(void)
  43. {
  44. if(timeout_isOut(&tt_watchdog))
  45. {
  46. IWDG_ReloadCounter();
  47. watchdog_num++;
  48. if(watchdog_num > 10)
  49. {
  50. watchdog_num = 0;
  51. if(task_count.uart_count_cur != task_count.uart_count_prev)
  52. {
  53. task_count.uart_count_prev = task_count.uart_count_cur;
  54. }
  55. else
  56. {
  57. NVIC_SystemReset();
  58. }
  59. if(task_count.lora_count_cur != task_count.lora_count_prev)
  60. {
  61. task_count.lora_count_prev = task_count.lora_count_cur;
  62. }
  63. else
  64. {
  65. NVIC_SystemReset();
  66. }
  67. if(task_count.prog_count_cur != task_count.prog_count_prev)
  68. {
  69. task_count.prog_count_prev = task_count.prog_count_cur;
  70. }
  71. else
  72. {
  73. NVIC_SystemReset();
  74. }
  75. //离线升级时不判断
  76. if(device_fixed_info.Work_State == DEV_WORK_STATE_UPDATING &&\
  77. ota_state.update_mode == OTA_WORK_STATE_MASTER)
  78. {}
  79. else
  80. {
  81. if(task_count.ota_count_cur != task_count.ota_count_prev)
  82. {
  83. task_count.ota_count_prev = task_count.ota_count_cur;
  84. }
  85. else
  86. {
  87. NVIC_SystemReset();
  88. }
  89. }
  90. if(hd_id == PCB_V1)
  91. {
  92. if(task_count.encoder_count_cur != task_count.encoder_count_prev)
  93. {
  94. task_count.encoder_count_prev = task_count.encoder_count_cur;
  95. }
  96. else
  97. {
  98. NVIC_SystemReset();
  99. }
  100. }
  101. }
  102. }
  103. }
  104. static void watchdog_feed_timer(void *p_tmr, void *p_arg)
  105. {
  106. // static uint8_t led_flag = 0;
  107. #if 1
  108. IWDG_ReloadCounter();
  109. #endif
  110. // RTC_Get();
  111. }
  112. void watchdog_init(uint8_t pre,uint16_t rlr)
  113. {
  114. OS_ERR err;
  115. #if 0
  116. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  117. IWDG_SetPrescaler(pre);
  118. IWDG_SetReload(rlr);
  119. IWDG_ReloadCounter();
  120. IWDG_Enable();
  121. #endif
  122. OSTmrCreate(&watch_tmr, "watch_tmr", 1, 1, OS_OPT_TMR_PERIODIC, watchdog_feed_timer, NULL, &err);
  123. OSTmrStart(&watch_tmr, &err);
  124. }
  125. void GPIO_COMM_Init(u32 clk, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed)
  126. {
  127. GPIO_InitTypeDef GPIO_InitStructure;
  128. RCC_APB2PeriphClockCmd(clk, ENABLE);
  129. GPIO_InitStructure.GPIO_Pin = GPIO_Pin;
  130. GPIO_InitStructure.GPIO_Mode = mode;
  131. GPIO_InitStructure.GPIO_Speed = speed;
  132. GPIO_Init(GPIOx, &GPIO_InitStructure);
  133. GPIO_SetBits(GPIOx, GPIO_Pin);
  134. }
  135. void BSP_Init(void)
  136. {
  137. SystemInit();
  138. SysTick_init();
  139. // watchdog_init(IWDG_Prescaler_256, 4000);
  140. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断优先级分组
  141. RTC_Init();
  142. adc_init();
  143. power_on_read();//上电读取数据
  144. HD_ID_Init();//pcb版本引脚初始化
  145. hd_id = get_HD_ID();//读取pcb版本
  146. key_init();
  147. LED_Init();//led初始化
  148. sw_gpio_init();//切换开关初始化
  149. pos_init();
  150. uart_init(UART1_ID, 115200, USART_WordLength_8b, USART_Parity_No);
  151. uart_init(UART2_ID, 115200, USART_WordLength_9b, USART_Parity_Even);//加密模块
  152. uart_init(UART3_ID, 115200, USART_WordLength_8b, USART_Parity_No);//显示屏
  153. uart_init(UART4_ID, 9600, USART_WordLength_9b, USART_Parity_Even);
  154. uart_init(UART5_ID, 9600, USART_WordLength_9b, USART_Parity_Even);
  155. //控制引脚初始化
  156. //RS485_CTL(PA1)
  157. GPIO_COMM_Init(RCC_APB2Periph_GPIOA, GPIOA,
  158. GPIO_Pin_1, GPIO_Mode_Out_PP, GPIO_Speed_50MHz);
  159. RS485_RX();
  160. }
  161. void test_flash_crc(void)
  162. {
  163. // int i;
  164. // uint8_t flash_buf[64]={0X01,0X00,0X00,0X00,0X01,0X02,0X00,0X00,0X62,0X00,0X00,0X00,0X01,0X00,0X00,0X00,0X01,0X04,0X00,0X00,0XEC,0X96,0X98,0X00,0X18,0X00,0X00,0X00,0XEC,0X9B,0X06,0X08,0X00,0X00,0X00,0X00,0X4C,0X50,0X53,0X58};
  165. // uint32_t getcrc;
  166. // Flash_BufferRead(OTA_UPDATE_APP3_FLASH_START_ADDR,(uint8_t *)flash_buf,64);
  167. // Flash_RangeErase(OTA_UPDATE_PT_FLASH_START_ADDR, OTA_UPDATE_PT_FLASH_SIZE);
  168. // Flash_BufferWrite(OTA_UPDATE_PT_FLASH_START_ADDR,(uint32_t *)flash_buf,40);
  169. // Flash_BufferWrite(OTA_UPDATE_PT_FLASH_START_ADDR+64,(uint32_t *)flash_buf,40);
  170. // Flash_BufferWrite(OTA_UPDATE_PT_FLASH_START_ADDR+128,(uint32_t *)flash_buf,64);
  171. // Flash_BufferWrite(OTA_UPDATE_PT_FLASH_START_ADDR+2048,(uint32_t *)flash_buf,64);
  172. // Flash_BufferWrite(OTA_UPDATE_PT_FLASH_START_ADDR+2048+64,(uint32_t *)flash_buf,64);
  173. // data_dump("sd",(uint8_t *)flash_buf,64);
  174. // memset(flash_buf,0,64);
  175. // Flash_BufferRead(OTA_UPDATE_PT_FLASH_START_ADDR,(uint8_t *)flash_buf,64);
  176. // data_dump("addr1",(uint8_t *)flash_buf,64);
  177. // memset(flash_buf,0,64);
  178. // Flash_BufferRead(OTA_UPDATE_PT_FLASH_START_ADDR+64,(uint8_t *)flash_buf,64);
  179. // data_dump("addr2",(uint8_t *)flash_buf,64);
  180. //
  181. // memset(flash_buf,0,64);
  182. // Flash_BufferRead(OTA_UPDATE_PT_FLASH_START_ADDR+2048,(uint8_t *)flash_buf,64);
  183. // data_dump("addr2",(uint8_t *)flash_buf,64);
  184. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  185. // CRC_ResetDR();
  186. // CRC_CalcBlockCRC((uint32_t*)OTA_UPDATE_PT_FLASH_START_ADDR, 40/4);
  187. // getcrc = CRC_GetCRC();
  188. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  189. // printf("crc1=%08x\n",getcrc);
  190. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  191. // CRC_ResetDR();
  192. // CRC_CalcBlockCRC((uint32_t*)(OTA_UPDATE_PT_FLASH_START_ADDR+64), 40/4);
  193. // getcrc = CRC_GetCRC();
  194. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  195. // printf("crc2=%08x\n",getcrc);
  196. //
  197. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  198. // CRC_ResetDR();
  199. // CRC_CalcBlockCRC((uint32_t*)OTA_UPDATE_PT_FLASH_START_ADDR, 64/4);
  200. // getcrc = CRC_GetCRC();
  201. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  202. // printf("crc1=%08x\n",getcrc);
  203. //
  204. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  205. // CRC_ResetDR();
  206. // CRC_CalcBlockCRC((uint32_t*)(OTA_UPDATE_PT_FLASH_START_ADDR+128), 64/4);
  207. // getcrc = CRC_GetCRC();
  208. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  209. // printf("crc2=%08x\n",getcrc);
  210. //
  211. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  212. // CRC_ResetDR();
  213. // CRC_CalcBlockCRC((uint32_t*)(OTA_UPDATE_PT_FLASH_START_ADDR+2048), 64/4);
  214. // getcrc = CRC_GetCRC();
  215. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  216. // printf("crc3=%08x\n",getcrc);
  217. //
  218. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  219. // CRC_ResetDR();
  220. // CRC_CalcBlockCRC((uint32_t*)(OTA_UPDATE_PT_FLASH_START_ADDR+2048+64), 64/4);
  221. // getcrc = CRC_GetCRC();
  222. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  223. // printf("crc4=%08x\n",getcrc);
  224. //
  225. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);
  226. // CRC_ResetDR();
  227. // CRC_CalcBlockCRC((uint32_t*)OTA_UPDATE_APP3_FLASH_START_ADDR, 64/4);
  228. // getcrc = CRC_GetCRC();
  229. // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,DISABLE);
  230. // printf("crc5=%08x\n",getcrc);
  231. }
  232. //按键任务处理函数
  233. void key_task_handle(uint8_t num)
  234. {
  235. switch(num)
  236. {
  237. case 1://显示lora信道
  238. loraindex_led_flag = 1;
  239. timeout_setValue(&led_info.tt_loraindex_led_state,LED_LORA_INDEX_TIME,1);//设置loraindex灯计时参数
  240. close_all_led();
  241. Data_lastNbit_led(lora_para_choice+1,4,1);//显示Lora组号
  242. key_info[KEY0_PRES-1].execute = 1;
  243. break;
  244. case 2:
  245. // device_fixed_info.Work_State = DEV_WORK_STATE_XSP_UPDATING;
  246. // ota_xsp_info.xsp_ota_begin = 1;
  247. // ota_xsp_info.xsp_count = 0;
  248. // ota_xsp_info.error_num = 0;
  249. // ota_xsp_init();
  250. // ota_xsp_info_read_test();//升级显示屏
  251. // test_flash_crc();
  252. break;
  253. case 3:
  254. break;
  255. case 4:
  256. break;
  257. case 5://离线升级
  258. device_fixed_info.master_updata_start = 1;
  259. ota_state.offline_mode = KEY_TRIGGER;
  260. break;
  261. default:
  262. break;
  263. }
  264. }
  265. //比较设备类型
  266. uint8_t device_type_cmp(uint32_t device_fixed, uint16_t device_rcv)
  267. {
  268. uint8_t ret = 0;
  269. uint16_t temp = 0;
  270. temp = (device_fixed>>16)&0x0000FFFF;
  271. if(temp == device_rcv)
  272. {
  273. ret = 1;
  274. }
  275. return ret;
  276. }
  277. //比较接收设备的类型和sn(sn不能是0xffffffff)
  278. int device_type_and_id_cmp_NoBroadcast(uint16_t device_type, uint32_t device_sn)
  279. {
  280. int ret = 0;
  281. if((device_type == device_info.device_type) && (device_sn == device_info.device_sn))
  282. {
  283. ret = 1;
  284. }
  285. return ret;
  286. }
  287. float Temp_test(void);
  288. //读取温度
  289. void Temp_get(void)
  290. {
  291. Temperature.dataf = Temp_test();
  292. device_fixed_info.Temperature = Temperature.datai;
  293. // printf("temperature uint32:%08x\n",device_fixed_info.Temperature);
  294. }
  295. #define ADC_READ_TIMES 3
  296. u16 get_adc(uint8_t channel, uint8_t rank, uint8_t sample_time);
  297. //读电压
  298. float adc_get(void)
  299. {
  300. OS_ERR err;
  301. float vol,temp_vol_sum = 0;
  302. uint16_t temp=0,times=0;
  303. times = ADC_READ_TIMES;
  304. while(times--) {
  305. temp = get_adc(ADC_Channel_0, 1, ADC_SampleTime_239Cycles5);
  306. vol = (float)temp*3300/4096; //电压值(mV)
  307. temp_vol_sum += vol;
  308. // printf("ADC_Channel_0 Voltage measurement is : %f mV(%d)\r\n",vol, temp); //串口打印电压值
  309. OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_DLY, &err);
  310. }
  311. vol = temp_vol_sum / ADC_READ_TIMES;
  312. vol /= 1000;
  313. // printf("ADC_Channel_0 Voltage measurement is : %f V\r\n",vol); //串口打印电压值
  314. return vol*2; //实际电压应乘2
  315. }
  316. //读电压
  317. void Voltage_get(void)
  318. {
  319. Voltage.dataf = adc_get();
  320. device_fixed_info.Voltage = Voltage.datai;
  321. // printf("voltage u32:%08x\n",device_fixed_info.Voltage);
  322. }
  323. //实时参数读取
  324. void device_real_time_para_read(void)
  325. {
  326. if(timeout_isOut(&tt_real_time))
  327. {
  328. Temp_get();//读温度
  329. Voltage_get();//读电压
  330. }
  331. }
  332. //中断设置
  333. void device_irq_set(FunctionalState state)
  334. {
  335. EXTI_InitTypeDef EXTI_InitStructure;
  336. EXTI_InitStructure.EXTI_Line=EXTI_Line0|EXTI_Line1;
  337. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  338. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //上升沿和下降沿触发
  339. EXTI_InitStructure.EXTI_LineCmd = state;
  340. EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
  341. if(hd_id == PCB_V1)
  342. {
  343. EXTI_InitStructure.EXTI_Line=EXTI_Line6|EXTI_Line7|EXTI_Line9|EXTI_Line10|EXTI_Line12|EXTI_Line13|EXTI_Line14|EXTI_Line15;
  344. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  345. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //上升沿和下降沿触发
  346. EXTI_InitStructure.EXTI_LineCmd = state;
  347. EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
  348. }
  349. irq_state = state;
  350. if(irq_state==ENABLE)
  351. {
  352. printf("irq enable\n");
  353. }
  354. else
  355. {
  356. printf("irq disable\n");
  357. }
  358. }
  359. //运行时中断控制
  360. void run_irq_set(void)
  361. {
  362. //进入产测关闭中断,退出产测打开中断
  363. //升级时主设备和从设备时关闭中断,进入旁观者和升级状态上报时,打开中断
  364. if(device_fixed_info.Work_State==DEV_WORK_STATE_PT || ((device_fixed_info.Work_State==DEV_WORK_STATE_UPDATING) && ((ota_state.update_mode!=OTA_WORK_STATE_ONLOOKER)&&(ota_state.update_mode!=OTA_WORK_STATE_UPLOAD))))
  365. {
  366. if(irq_state==ENABLE)
  367. {
  368. device_irq_set(DISABLE);
  369. }
  370. }
  371. else
  372. {
  373. if(irq_state==DISABLE)
  374. {
  375. device_irq_set(ENABLE);
  376. }
  377. }
  378. }
  379. //设备模块复位判断
  380. void device_module_reset(void)
  381. {
  382. ciphertext_state_isout();//加密模块死机判断
  383. //判断Lora是否超时重启
  384. if(timeout_isOut(&tt_lora_rcv_state))
  385. {
  386. timeout_start(&tt_lora_rst_rcv_state,1);
  387. printf("lora一小时未收到数据\n");
  388. lora_init();//lora初始化
  389. }
  390. //Lora复位后一段时间依旧未接收到数据
  391. if(timeout_isOut(&tt_lora_rst_rcv_state))
  392. {
  393. printf("lora复位5分钟后还未收到数据\n");
  394. if(Reset_encoder_judge())//编码器在工作不能复位
  395. device_fixed_info.reset_flag = 1;
  396. else
  397. NVIC_SystemReset();
  398. }
  399. if(device_fixed_info.reset_flag)
  400. {
  401. if(Reset_encoder_judge()==0)
  402. {
  403. printf("采集器复位\n");
  404. device_fixed_info.reset_flag = 0;
  405. NVIC_SystemReset();
  406. }
  407. }
  408. //读编码器后2s定时
  409. if(timeout_isOut(&read_encoder_para.tt_encoder))
  410. {
  411. read_encoder_para.flag = 0;
  412. }
  413. }
  414. /*
  415. *********************************************************************************************************
  416. * BSP_CPU_ClkFreq()
  417. *
  418. * Description : Read CPU registers to determine the CPU clock frequency of the chip.
  419. * 读取cpu寄存器确定时钟频率
  420. * Argument(s) : none.
  421. *
  422. * Return(s) : The CPU clock frequency, in Hz. 返回CPU始终频率
  423. *
  424. * Caller(s) : Application.
  425. *
  426. * Note(s) : none.
  427. *********************************************************************************************************
  428. */
  429. CPU_INT32U BSP_CPU_ClkFreq (void)
  430. {
  431. RCC_ClocksTypeDef rcc_clocks;
  432. RCC_GetClocksFreq(&rcc_clocks);
  433. return ((CPU_INT32U)rcc_clocks.HCLK_Frequency);
  434. }
  435. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  436. void CPU_TS_TmrInit (void)
  437. {
  438. CPU_INT32U cpu_clk_freq_hz;
  439. cpu_clk_freq_hz = BSP_CPU_ClkFreq();
  440. CPU_TS_TmrFreqSet(cpu_clk_freq_hz);
  441. }
  442. #endif
  443. /*$PAGE*/
  444. /*
  445. *********************************************************************************************************
  446. * CPU_TS_TmrRd()
  447. *
  448. * Description : Get current CPU timestamp timer count value.
  449. *
  450. * Argument(s) : none.
  451. *
  452. * Return(s) : Timestamp timer count (see Notes #2a & #2b).
  453. *
  454. * Caller(s) : CPU_TS_Init(),
  455. * CPU_TS_Get32(),
  456. * CPU_TS_Get64(),
  457. * CPU_IntDisMeasStart(),
  458. * CPU_IntDisMeasStop().
  459. *
  460. * This function is an INTERNAL CPU module function & MUST be implemented by application/
  461. * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
  462. *
  463. * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
  464. * if either of the following CPU features is enabled :
  465. *
  466. * (a) CPU timestamps
  467. * (b) CPU interrupts disabled time measurements
  468. *
  469. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  470. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  471. *
  472. * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  473. * data type.
  474. *
  475. * (1) If timer has more bits, truncate timer values' higher-order bits greater
  476. * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  477. *
  478. * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  479. * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  480. * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  481. *
  482. * In other words, if timer size is not a binary-multiple of 8-bit octets
  483. * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  484. * octet word size SHOULD be configured (e.g. to 16-bits). However, the
  485. * minimum supported word size for CPU timestamp timers is 8-bits.
  486. *
  487. * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
  488. * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
  489. *
  490. * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
  491. *
  492. * (1) If timer is a 'down' counter whose values decrease with each time count,
  493. * then the returned timer value MUST be ones-complemented.
  494. *
  495. * (c) (1) When applicable, the amount of time measured by CPU timestamps is
  496. * calculated by either of the following equations :
  497. *
  498. * (A) Time measured = Number timer counts * Timer period
  499. *
  500. * where
  501. *
  502. * Number timer counts Number of timer counts measured
  503. * Timer period Timer's period in some units of
  504. * (fractional) seconds
  505. * Time measured Amount of time measured, in same
  506. * units of (fractional) seconds
  507. * as the Timer period
  508. *
  509. * Number timer counts
  510. * (B) Time measured = ---------------------
  511. * Timer frequency
  512. *
  513. * where
  514. *
  515. * Number timer counts Number of timer counts measured
  516. * Timer frequency Timer's frequency in some units
  517. * of counts per second
  518. * Time measured Amount of time measured, in seconds
  519. *
  520. * (2) Timer period SHOULD be less than the typical measured time but MUST be less
  521. * than the maximum measured time; otherwise, timer resolution inadequate to
  522. * measure desired times.
  523. *********************************************************************************************************
  524. */
  525. //#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  526. //CPU_TS_TMR CPU_TS_TmrRd (void)
  527. //{
  528. // return (CPU_TS_TMR)0;
  529. //}
  530. //#endif
  531. //#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  532. //void CPU_TS_TmrInit2 (void)
  533. //{
  534. // CPU_INT32U fclk_freq;
  535. //
  536. //
  537. // fclk_freq = BSP_CPU_ClkFreq();
  538. //
  539. // BSP_REG_DEM_CR |= (CPU_INT32U)BSP_BIT_DEM_CR_TRCENA;
  540. // BSP_REG_DWT_CYCCNT = (CPU_INT32U)0u;
  541. // BSP_REG_DWT_CR |= (CPU_INT32U)BSP_BIT_DWT_CR_CYCCNTENA;
  542. //
  543. // CPU_TS_TmrFreqSet((CPU_TS_TMR_FREQ)fclk_freq);
  544. //}
  545. //#endif
  546. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  547. CPU_TS_TMR CPU_TS_TmrRd (void)
  548. {
  549. extern volatile uint32_t TickCounter;
  550. return (TickCounter);
  551. }
  552. #endif
  553. //打印系统时钟
  554. void system_clk_read(void)
  555. {
  556. RCC_ClocksTypeDef get_rcc_Clock;
  557. RCC_GetClocksFreq(&get_rcc_Clock);
  558. printf("\r\nSYSCLK parameter\r\n");
  559. printf("SSYSCLK_F = %dHz\r\n",get_rcc_Clock.SYSCLK_Frequency); /*!< returns SYSCLK clock frequency expressed in Hz */
  560. printf("HCLK_F = %dHz\r\n",get_rcc_Clock.HCLK_Frequency); /*!< returns HCLK clock frequency expressed in Hz */
  561. printf("PCLK1_F = %dHz\r\n",get_rcc_Clock.PCLK1_Frequency); /*!< returns PCLK1 clock frequency expressed in Hz */
  562. printf("PCLK2_F = %dHz\r\n",get_rcc_Clock.PCLK2_Frequency); /*!< returns PCLK2 clock frequency expressed in Hz */
  563. printf("ADCCLK_F = %dHz\r\n",get_rcc_Clock.ADCCLK_Frequency); /*!< returns ADCCLK clock frequency expressed in Hz */
  564. }