工具与软件:
我需要实现微秒级延迟、例如延迟(1us)或延迟(5us)。
但在示例代码中,我只能找到 sleep()和 nanosleep()(),我不知道如何使用。
我想知道是否有其他可用函数可以实现微秒级延迟、例如 MSP430中的__delay_cycles ()函数。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
我需要实现微秒级延迟、例如延迟(1us)或延迟(5us)。
但在示例代码中,我只能找到 sleep()和 nanosleep()(),我不知道如何使用。
我想知道是否有其他可用函数可以实现微秒级延迟、例如 MSP430中的__delay_cycles ()函数。
但我曾尝试使用用户睡眠、但实际上是在毫秒内延迟。
我实际上输入的值只能以1k 为单位。 例如,usleep(2000)、usleep(3000 )。
#define configTICK_RATE_Hz (1000UL)
#define Tick_period_USECS (1000000L/configTICK_RATE_Hz)
int usleep (useconds_t usec)
{
TickType_t xDelay;
/* usec 必须小于1000000 */
if (usec >= 1000000)
{
错误号= EINVAL;
返回(-1);
}
/*吸顶*/
xDelay =(usec + tick_period_USECS - 1)/ tick_period_USECS ;
/*必须添加一个节拍以确保 xDelay 节拍的完整持续时间*/
vTaskDelay (xDelay + 1);
返回(0);
}