From 07fc57b2c8e748cacfc80a319127224dbba4c3a5 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 2 Feb 2017 11:28:02 +0000 Subject: Simulator compiles, to be tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10078 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/simulator/posix/hal_lld.c | 41 ++++++++++++++-------------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'os/hal/ports/simulator/posix/hal_lld.c') diff --git a/os/hal/ports/simulator/posix/hal_lld.c b/os/hal/ports/simulator/posix/hal_lld.c index 52adb4e4c..e6a7ec3e5 100755 --- a/os/hal/ports/simulator/posix/hal_lld.c +++ b/os/hal/ports/simulator/posix/hal_lld.c @@ -22,6 +22,10 @@ * @{ */ +#include +#include +#include + #include "hal.h" /*===========================================================================*/ @@ -32,8 +36,8 @@ /* Driver local variables and types. */ /*===========================================================================*/ -static LARGE_INTEGER nextcnt; -static LARGE_INTEGER slice; +static struct timeval nextcnt; +static struct timeval tick = {0UL, 1000000UL / OSAL_ST_FREQUENCY}; /*===========================================================================*/ /* Driver local functions. */ @@ -51,31 +55,21 @@ static LARGE_INTEGER slice; * @brief Low level HAL driver initialization. */ void hal_lld_init(void) { - WSADATA wsaData; - - /* Initialization.*/ - if (WSAStartup(2, &wsaData) != 0) { - printf("Unable to locate a winsock DLL\n"); - exit(1); - } - printf("ChibiOS/RT simulator (Win32)\n"); - if (!QueryPerformanceFrequency(&slice)) { - printf("QueryPerformanceFrequency() error"); - exit(1); - } - slice.QuadPart /= CH_CFG_ST_FREQUENCY; - QueryPerformanceCounter(&nextcnt); - nextcnt.QuadPart += slice.QuadPart; - - fflush(stdout); +#if defined(__APPLE__) + puts("ChibiOS/RT simulator (OS X)\n"); +#else + puts("ChibiOS/RT simulator (Linux)\n"); +#endif + gettimeofday(&nextcnt, NULL); + timeradd(&nextcnt, &tick, &nextcnt); } /** * @brief Interrupt simulation. */ void _sim_check_for_interrupts(void) { - LARGE_INTEGER n; + struct timeval tv; #if HAL_USE_SERIAL if (sd_lld_interrupt_pending()) { @@ -87,10 +81,9 @@ void _sim_check_for_interrupts(void) { } #endif - /* Interrupt Timer simulation (10ms interval).*/ - QueryPerformanceCounter(&n); - if (n.QuadPart > nextcnt.QuadPart) { - nextcnt.QuadPart += slice.QuadPart; + gettimeofday(&tv, NULL); + if (timercmp(&tv, &nextcnt, >=)) { + timeradd(&nextcnt, &tick, &nextcnt); CH_IRQ_PROLOGUE(); -- cgit v1.2.3