1 /* 2 * Copyright 2009, Colin Günther, coling@gmx.de 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "device.h" 8 9 10 #define CONVERT_HZ_TO_USECS(hertz) (1000000LL / (hertz)) 11 #define FREEBSD_CLOCK_FREQUENCY_IN_HZ 1000 12 13 14 int ticks; 15 static timer sHardClockTimer; 16 17 18 /*! 19 * Implementation of FreeBSD's hardclock timer. 20 */ 21 static status_t 22 hardClock(timer* hardClockTimer) 23 { 24 atomic_add((vint32*)&ticks, 1); 25 return B_OK; 26 } 27 28 29 /*! 30 * Initialization of the hardclock timer. 31 * 32 * Note: We are not using the FreeBSD variable hz as the invocation frequency 33 * as it is the case in FreeBSD's hardclock function. This is due to lower 34 * system load. The hz (see compat/sys/kernel.h) variable in the compat layer is 35 * set to 1000000 Hz, whereas it is usually set to 1000 Hz for FreeBSD. 36 */ 37 status_t 38 init_hard_clock() 39 { 40 status_t status; 41 42 ticks = 0; 43 status = add_timer(&sHardClockTimer, hardClock, 44 CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ), 45 B_PERIODIC_TIMER); 46 47 return status; 48 } 49 50 51 void 52 uninit_hard_clock() 53 { 54 cancel_timer(&sHardClockTimer); 55 } 56