본문 바로가기

Linux/Device Driver

시간 처리와 커널 타이머 함수

#include <linux/delay.h>
mdelay() :
밀리초 (1/1000초) 단위의 시간을 지연 시킨다.
n 으로 설정된 루프 개수만큼 udelay을 반복 하며 지연 시킨다. n으로 설정할 수 있는 값은
MAX_UDELAY_MS 값에 의해 제한 받으며 일반적으로 5밀리초 이내의 값을 지정해야 한다.


#include <linux/delay.h>
void udelay(unsigned long usecs); // 원하는 시간을 입력
마이크로 초 단위의 지연을 발생 시킨다.


#include <linux/delay.h>
void ndelay(unsigned long nsecs);
나노초 단위로 (1/1000000000) 시간을 지연 시킨다.


#include <linux/time.h>
void do_gettimeofday(struct timval *tv);
현재 시스템의 시간을 얻는다.


#include <linux/time.h>
void do_settimeofday(struct timeval *tv);
itn do_settimeofday(struct timespec *tv); // v2.6
tv의 시간을 시스템 시간으로 설정한다.


#include <linux/time.h>
unsigned long mktime(unsigned int year, unsigned int mon, unsigned int day, unsigned int hour, unsigned int min, unsigned int sec);
년 월 일 시 분 초 로 표현된 시간을 초로 변환


#include <linux/timer.h>
void init_timer(struct timer_list *timer);
커널 타이머 목록에 등록될 수 있도록 timer 구조체 변수를 초기화 한다.


#include <linux/timer.h>
void add_timer(sturct timer_list *timer);
커널 타이머 목록에 등록 한다. 커널 타이머 목록 연결 리스트 구조로 구조체의 내용을 복사하는 것이 아니라 구조체의 링크 정보만을 수정한다.