1 /*******************************************************************
2 Components for embedded applications builded for
3 laboratory and medical instruments firmware
5 tpu_nitc.c - TPU NITC - New Input Capture/Input Transition Counter
6 Full description TPUPN08
8 Copyright (C) 2001-2003 by Pavel Pisa pisa@cmp.felk.cvut.cz
9 (C) 2001-2003 by PiKRON Ltd. http://www.pikron.com
11 *******************************************************************/
14 #include <system_def.h>
17 #include <periph/tpu_sup.h>
18 #include <periph/tpu_func.h>
20 int tpu_nitc_init(int chan, int prio, int edges, int tcr_source,
21 int param_addr, int continual, int max_count)
24 if(chan>15) return -1;
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 */
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;
34 if(tcr_source==2) control|=NITC_CHCTRL_CAPT_TCR2;
35 else control|=NITC_CHCTRL_CAPT_TCR1;
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;
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 */
51 tpu_set_cpr(chan,prio);