]> rtime.felk.cvut.cz Git - sysless.git/blob - arch/m68k/generic/drivers/tpu_nitc.c
d17b215cffa3187c67330e1e3a2f49516bb8996a
[sysless.git] / arch / m68k / generic / drivers / tpu_nitc.c
1 /*******************************************************************
2   Components for embedded applications builded for
3   laboratory and medical instruments firmware
4
5   tpu_nitc.c - TPU NITC - New Input Capture/Input Transition Counter
6               Full description TPUPN08
7
8   Copyright (C) 2001-2003 by Pavel Pisa pisa@cmp.felk.cvut.cz
9             (C) 2001-2003 by PiKRON Ltd. http://www.pikron.com
10
11  *******************************************************************/
12
13 #include <types.h>
14 #include <system_def.h>
15 #include <sim.h>
16 #include <tpu.h>
17 #include <periph/tpu_sup.h>
18 #include <periph/tpu_func.h>
19
20 int tpu_nitc_init(int chan, int prio, int edges, int tcr_source,
21                   int param_addr, int continual, int max_count)
22 {
23   unsigned control;
24   if(chan>15) return -1;
25
26   tpu_set_cpr(chan,0);          /* disable chanel function */
27   tpu_set_ier(chan,0);          /* disable MCU interrupt  */
28   tpu_set_cfsr(chan,0xA);       /* NITC - New input transition counter */
29
30   control=NITC_CHCTRL_FIXED;
31   if(edges&NITC_CHCTRL_RISING_EDGE)  control|=NITC_CHCTRL_RISING_EDGE;
32   if(edges&NITC_CHCTRL_FALLING_EDGE) control|=NITC_CHCTRL_FALLING_EDGE;
33   if(tcr_source){
34     if(tcr_source==2)                control|=NITC_CHCTRL_CAPT_TCR2;
35     else                             control|=NITC_CHCTRL_CAPT_TCR1;
36   }
37   *tpu_param_addr(chan,NITC_CHANNEL_CONTROL)=control;
38   *tpu_param_addr(chan,NITC_PARAM_ADDR_AND_LINK)=param_addr&0x7e;
39   *tpu_param_addr(chan,NITC_MAX_COUNT)=max_count;
40   *tpu_param_addr(chan,NITC_TRANS_COUNT)=0;
41
42   /* 0 .. Single shot, 1 .. Continual, */
43   /* 2 .. Single with Links, 3 .. Continual with Links */
44   tpu_set_hsqr(chan,continual?1:0);
45   /* 1 .. Initialize TCR mode, 2 .. Initialize parameter mode */
46   if(tcr_source)
47     tpu_set_hsrr(chan,1);
48   else
49     tpu_set_hsrr(chan,2);
50   tpu_clear_cisr(chan);
51   tpu_set_cpr(chan,prio);
52
53   return 0;
54 }