Spectrum analyzer shellcode, forked from Ossmann's. GPL polluted for now, but as...
[goodfet] / shellcode / chipcon / cc1110 / specan.h
1 /*
2  * Copyright 2010 Michael Ossmann
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; see the file COPYING.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #define u8 unsigned char
21 #define u16 unsigned int
22 #define u32 unsigned long
23
24 /*
25  * There is one channel per column of the display.  The radio is tuned to one
26  * channel at a time and RSSI is displayed for that channel.
27  */
28 #define NUM_CHANNELS 132
29
30 /*
31  * wide mode (default): 44 MHz on screen, 333 kHz per channel
32  * narrow mode: 6.6 MHz on screen, 50 kHz per channel
33  */
34 #define WIDE 0
35 #define NARROW 1
36 #define ULTRAWIDE 2
37
38 /*
39  * short mode (default): displays RSSI >> 2
40  * tall mode: displays RSSI
41  */
42 #define SHORT 0
43 #define TALL 1
44
45 /* vertical scrolling */
46 #define SHORT_STEP  16
47 #define TALL_STEP   4
48 #define MAX_VSCROLL 208
49 #define MIN_VSCROLL 0
50
51 /* frequencies in MHz */
52 #define DEFAULT_FREQ     915
53 #define WIDE_STEP        5
54 #define NARROW_STEP      1
55 #define ULTRAWIDE_STEP   20
56 #define WIDE_MARGIN      13
57 #define NARROW_MARGIN    3
58 #define ULTRAWIDE_MARGIN 42
59
60 /* frequency bands supported by device */
61 #define BAND_300 0
62 #define BAND_400 1
63 #define BAND_900 2
64
65 /* band limits in MHz */
66 #define MIN_300  281
67 #define MAX_300  361
68 #define MIN_400  378
69 #define MAX_400  481
70 #define MIN_900  749
71 #define MAX_900  962
72
73 /* band transition points in MHz */
74 #define EDGE_400 369
75 #define EDGE_900 615
76
77 /* VCO transition points in Hz */
78 #define MID_300  318000000
79 #define MID_400  424000000
80 #define MID_900  848000000
81
82 /* channel spacing in Hz */
83 #define WIDE_SPACING      199952
84 #define NARROW_SPACING    49988
85 #define ULTRAWIDE_SPACING 666504
86
87 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
88 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
89
90
91 /* Keeping track of all this for each channel allows us to tune faster. */
92 typedef struct {
93         /* frequency setting */
94         u8 freq2;
95         u8 freq1;
96         u8 freq0;
97         
98         /* frequency calibration */
99         u8 fscal3;
100         u8 fscal2;
101         u8 fscal1;
102
103         /* signal strength */
104         u8 ss;
105         u8 max;
106 } channel_info;
107
108 void clear();
109 void plot(u8 col);
110 void putchar(char c);
111 u8 getkey();
112 void draw_ruler();
113 void draw_freq();
114 void radio_setup();
115 void set_filter();
116 void set_radio_freq(u32 freq);
117 void calibrate_freq(u32 freq, u8 ch);
118 u16 set_center_freq(u16 freq);
119 void tune(u8 ch);
120 void set_width(u8 w);
121 void poll_keyboard();
122 void main(void);