time.README
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. README for MIPS time services
  2. Jun Sun
  3. jsun@mvista.com or jsun@junsun.net
  4. ABOUT
  5. -----
  6. This file describes the new arch/mips/kernel/time.c, related files and the 
  7. services they provide. 
  8. If you are short in patience and just want to know how to use time.c for a 
  9. new board or convert an existing board, go to the last section.
  10. FILES, COMPATABILITY AND CONFIGS
  11. ---------------------------------
  12. The old arch/mips/kernel/time.c is renamed to old-time.c.
  13. A new time.c is put there, together with include/asm-mips/time.h.
  14. Two configs variables are introduced, CONFIG_OLD_TIME_C and CONFIG_NEW_TIME_C.
  15. So we allow boards using 
  16. 1) old time.c (CONFIG_OLD_TIME_C)
  17. 2) new time.c (CONFIG_NEW_TIME_C)
  18. 3) neither (their own private time.c)
  19. However, it is expected every board will move to the new time.c in the near
  20. future.
  21. WHAT THE NEW CODE PROVIDES?
  22. --------------------------- 
  23. The new time code provide the following services:
  24.   a) Implements functions required by Linux common code:
  25. time_init
  26. do_gettimeofday
  27. do_settimeofday
  28.   b) provides an abstraction of RTC and null RTC implementation as default.
  29. extern unsigned long (*rtc_get_time)(void);
  30. extern int (*rtc_set_time)(unsigned long);
  31.   c) a set of gettimeoffset functions for different CPUs and different
  32.      needs.
  33.   d) high-level and low-level timer interrupt routines where the timer 
  34.      interrupt source  may or may not be the CPU timer.  The high-level 
  35.      routine is dispatched through do_IRQ() while the low-level is 
  36.      dispatched in assemably code (usually int-handler.S)
  37. WHAT THE NEW CODE REQUIRES?
  38. ---------------------------
  39. For the new code to work properly, each board implementation needs to supply
  40. the following functions or values:
  41.   a) board_time_init - a function pointer.  Invoked at the beginnig of
  42.      time_init().  It is optional.
  43. 1. (optional) set up RTC routines
  44. 2. (optional) calibrate and set the mips_counter_frequency
  45.   b) board_timer_setup - a function pointer.  Invoked at the end of time_init()
  46. 1. (optional) over-ride any decisions made in time_init()
  47. 2. set up the irqaction for timer interrupt.
  48. 3. enable the timer interrupt
  49.   c) (optional) board-specific RTC routines.
  50.   d) (optional) mips_counter_frequency - It must be definied if the board
  51.      is using CPU counter for timer interrupt or it is using fixed rate
  52.      gettimeoffset().
  53. PORTING GUIDE
  54. -------------
  55. Step 1: decide how you like to implement the time services.
  56.   a) does this board have a RTC?  If yes, implement the two RTC funcs.
  57.   b) does the CPU have counter/compare registers? 
  58.      If the answer is no, you need a timer to provide the timer interrupt
  59.      at 100 HZ speed.
  60.      You cannot use the fast gettimeoffset functions, i.e.,
  61. unsigned long fixed_rate_gettimeoffset(void);
  62. unsigned long calibrate_div32_gettimeoffset(void);
  63. unsigned long calibrate_div64_gettimeoffset(void);
  64.     You can use null_gettimeoffset() will gives the same time resolution as
  65.     jiffy.  Or you can implement your own gettimeoffset (probably based on 
  66.     some ad hoc hardware on your machine.)
  67.   c) The following sub steps assume your CPU has counter register.
  68.      Do you plan to use the CPU counter register as the timer interrupt
  69.      or use an exnternal timer?
  70.      In order to CPU counter register as the timer interrupt source, you must
  71.      know the counter speed (mips_counter_frequency).  It is usually the
  72.      same as the CPU speed (Or it is ALWAYS the same?)
  73.   d) decide on whether you want to use high-level or low-level timer
  74.      interrupt routines.  The low-level one is presumably faster, but should
  75.      not make too mcuh difference.
  76. Step 2:  the machine setup() function
  77.   If you supply board_time_init(), set the function poointer.
  78.   Set the function pointer board_timer_setup() (mandatory)
  79. Step 3: implement rtc routines, board_time_init() and board_timer_setup()
  80.   if needed.
  81.   board_time_init() - 
  82.    a) (optional) set up RTC routines, 
  83.         b) (optional) calibrate and set the mips_counter_frequency
  84.       (only needed if you intended to use fixed_rate_gettimeoffset
  85.        or use cpu counter as timer interrupt source)
  86.   board_timer_setup() - 
  87.   a) (optional) over-write any choices made above by time_init().
  88.   b) machine specific code should setup the timer irqaction.
  89.   c) enable the timer interrupt
  90.   If the RTC chip is a common chip, I suggest the routines are put under
  91.   arch/mips/libs.  For example, for DS1386 chip, one would create
  92.   rtc-ds1386.c under arch/mips/lib directory.  Add the following line to
  93.   the arch/mips/lib/Makefile:
  94. obj-$(CONFIG_DDB5476) += rtc-ds1386.o
  95. Step 4: if you are using low-level timer interrupt, change your interrupt
  96.   dispathcing code to check for timer interrupt and jump to 
  97.   ll_timer_interrupt() directly  if one is detected.
  98. Step 5: Modify arch/mips/config.in and add CONFIG_NEW_TIME_C to your machine.
  99.   Modify the appropriate defconfig if applicable.
  100. Final notes: 
  101. For some tricky cases, you may need to add your own wrapper functions 
  102. for some of the functions in time.c.  
  103. For example, you may define your own timer interrupt routine, which does
  104. its own processing and in turn calls timer_interrupt().
  105. You can also over-ride any of the built-in functions (gettimeoffset,
  106. RTC routines and/or timer interrupt routine).