0
RTOS를 더 잘 이해하고 스케쥴러를 구현하기 시작했습니다. 내 코드를 테스트하고 싶지만 불행히도 지금 당장 HW가 없다. C에서 타이머에 해당하는 ISR을 실행하는 가장 쉬운 방법은 무엇입니까?C에서 하드웨어 타이머 인터럽트 시뮬레이트
편집 : Sneftel의 답변 덕분에 타이머 인터럽트를 시뮬레이션 할 수있었습니다. 아래 코드는 http://www.makelinux.net/alp/069에서 영감을 얻었습니다. 제가 놓친 유일한 방법은 중첩 된 방식으로 그것을하는 것입니다. 따라서 ISR이 다른 타이머 인터럽트를 실행하면 ISR의 새 인스턴스가 첫 번째 인터럽트를 선점하게됩니다.
#include<stdlib.h>
#include<stdio.h>
#include<assert.h>
#include<signal.h>
#include<sys/time.h>
#include<string.h>
#ifdef X86_TEST_ENVIRONMENT
void simulatedTimer(int signum)
{
static int i=0;
printf("System time is %d.\n", i);
}
#endif
int main(void)
{
#ifdef X86_TEST_ENVIRONMENT
struct sigaction sa;
struct itimerval timer;
/* Install timer_handler as the signal handler for SIGVTALRM. */
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &simulatedTimer;
sigaction (SIGVTALRM, &sa, NULL);
/* Configure the timer to expire after 250 msec... */
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = CLOCK_TICK_RATE_MS * 1000;
/* ... and every 250 msec after that. */
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = CLOCK_TICK_RATE_MS * 1000;
/* Start a virtual timer. It counts down whenever this process is executing. */
setitimer (ITIMER_VIRTUAL, &timer, NULL);
#endif
#ifdef X86_TEST_ENVIRONMENT
/* Do busy work. */
while (1);
#endif
return 0;
}