updated command line 802.15.4 checksum calculator and added serClose to GoodFET to...
[goodfet] / firmware / include / adc.h
1 /*! \file adc.h
2
3         \author Scott Livingston
4
5         \brief Prototypes for ADC application.  Note that this code was
6                written only with the x2274 chip and GoodFET31 in mind;
7                specifically, pin 5 of the (JTAG) header is sampled.
8                Supporting x2618, x1611/12 and other GoodFET boards remains!
9                For timing considerations, see at least Section 20.2.5
10                "Sample and Conversion Timing" (on page 589?) of msp430x2xx
11                family manual.
12
13         \date September 2010
14 */
15
16 #ifndef ADC_H
17 #define ADC_H
18
19 #include "command.h"
20 #include "app.h"
21
22 #define ADC 0x74
23
24 //! Initialize ADC10 module (specific to 2xx chip family).
25 void init_adc10();
26
27 //! Uninit/stop ADC10 module (specific to 2xx chip family).
28 void uninit_adc10();
29
30 //! Return a single, instantaneous sample.
31 u16 sample_adc10();
32
33 //! Fill cmddata string; sampling repeatedly at a fixed rate.
34 u16 nsamples_adc10( u8 N_count, //! Number samples to obtain (bounded w.r.t. cmddata)
35                                                                                 u8 t_sample, /*! sample-and-hold time; this is
36                                                                                                                                      written directly to ADC10SHTx
37                                                                                                                                                  field of ADC10CTL0 register;
38                                                                                                                                                  possible values are
39                                                                                                                                                  00   4 ADC10CLK ticks,
40                                                                                                                                                  01   8 ADC10CLK ticks,
41                                                                                                                                                  10  16 ADC10CLK ticks,
42                                                                                                                                                  11  64 ADC10CLK ticks. */
43                                                                                 u8 clock_div ); /*! Value by which to divide SMCLK
44                                                                                                                                                           (which is assumed to be 16
45                                                                                                                                                           MHz), then giving
46                                                                                                                                                           ADC10CLK.
47                                                                                                                                                                 Possible values are 1..8
48                                                                                                                                                                 Cf. Fig. 20-1 (on page 585?)
49                                                                                                                                                           of the msp430x2xxx family
50                                                                                                                                                           manual. */
51
52
53 //! Command codes
54 #define ADC10_INIT    0x81 //! Initialize ADC10 module (i.e., get ready for sampling).
55 #define ADC10_UNINIT  0x82 //! Uninitialize (or "stop") ADC10.
56 #define ADC10_1SAMPLE 0x83 //! Capture a single sample.
57
58 /*! Capture a sequence of samples at a constant rate and write result
59     till requested number of samples is acquired or cmddata array is
60     filled, whichever is smaller. Hence, in the maximum length case,
61     (CMDDATALEN-4)/2 10-bit samples are obtained (128 total using
62     x2274 chip).
63
64     The command has several possible formats, switched according to
65     the length of received command data (from client). See above
66     comments about nsamples_adc10 function for meaning of ``t_samlpe''
67     and ``clock_div.''
68     
69     length 0  =>  max sample sequence length, t_sample = 3, clock_div = 8;
70            1  =>  user-specified sequence length, t_sample = 3, clock_div = 8;
71            3  =>  user-specified length, t_sample and clock_div. */
72 #define ADC10_NSAMPLE 0x84 
73
74 extern app_t const adc_app;
75
76 #endif // ADC_H
77