修改delay

This commit is contained in:
Robofish 2025-07-31 04:46:32 +08:00
parent 5369861c88
commit a91f175e9e
2 changed files with 30 additions and 19 deletions

View File

@ -1,24 +1,34 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <stdint.h>
#include "bsp\delay.h"
#include "bsp/bsp.h"
#include <cmsis_os2.h>
#include <main.h>
/* Exported constants ------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */
/* Exported functions prototypes -------------------------------------------- */
int8_t BSP_Delay(uint32_t ms);
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private typedef ---------------------------------------------------------- */
/* Private variables -------------------------------------------------------- */
/* Private function -------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
int8_t BSP_Delay(uint32_t ms) {
uint32_t tick_period = 1000u / osKernelGetTickFreq();
uint32_t ticks = ms / tick_period;
int8_t BSP_Delay_Init(void);
int8_t BSP_Delay_us(uint32_t us);
int8_t BSP_Delay_ms(uint32_t ms);
switch (osKernelGetState()) {
case osKernelError:
case osKernelReserved:
case osKernelLocked:
case osKernelSuspended:
return BSP_ERR;
#ifdef __cplusplus
case osKernelRunning:
osDelay(ticks ? ticks : 1);
break;
case osKernelInactive:
case osKernelReady:
HAL_Delay(ms);
break;
}
return BSP_OK;
}
#endif

View File

@ -1,2 +1,3 @@
uart,要求开启dma和中断
can,要求开启can的中断
can,要求开启can的中断
delay,暂时只有delay_ms函数
1 uart 要求开启dma和中断
2 can 要求开启can的中断
3 delay 暂时只有delay_ms函数