@@ -37,6 +37,14 @@ struct timespec
*/
extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
+/**
+ * @brief 睡眠指定时间
+ *
+ * @param usec 微秒
+ * @return int
+ */
+extern int usleep(useconds_t usec);
+
/**
* @brief 获取当前的CPU时间
*
@@ -59,4 +59,20 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
}
return 0;
-}
+}
+int usleep(useconds_t usec)
+{
+ struct timespec ts = {
+ tv_sec : (long int)(usec / 1000000),
+ tv_nsec : (long int)(usec % 1000000) * 1000UL
+ };
+ return nanosleep(&ts, NULL);
@@ -14,3 +14,10 @@
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
+int usleep(useconds_t usec);