yb_arm/osp/src/ospDelay.c
2023-07-12 14:14:31 +08:00

58 lines
871 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "osp.h"
////////
/*
*osp_delay - delay function
*input:
* delay (ms)
*return
* OSP_OK
*/
#if 0
OSP_STATUS osp_delay(U32 delay)
{
struct timespec reqt;
struct timespec remt;
reqt.tv_sec=delay/1000;
reqt.tv_nsec =(delay%1000) *1000000;/*1ms*/
nanosleep(&reqt,&remt);
return (OSP_OK);
}
#endif
OSP_STATUS osp_delay(uint32_t delay)
{
struct timespec reqt;
struct timespec remt;
reqt.tv_sec = delay / 1000000;
reqt.tv_nsec = (delay % 1000000) * 1000; /*1us*/
nanosleep(&reqt, &remt);
return (OSP_OK);
}
void osp_delay_while(uint64_t ns)
{
uint64_t org;
uint64_t ticks;
org = osp_get_cycel();
/* 50MHz for Cycel */
ticks = (ns / 20);
while (osp_get_cycel() <= (org + ticks));
}