Rev 5 | Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 6 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | #include "chprintf.h" |
35 | #include "chprintf.h" |
36 | 36 | ||
37 | 37 | ||
38 | #include "ap_math.h" |
38 | #include "ap_math.h" |
39 | #include "hardware.h" |
39 | #include "hardware.h" |
- | 40 | #include "useAdc.h" |
|
40 | #include "spiInterface.h" |
41 | #include "spiInterface.h" |
41 | #include "SSD1306.h" |
42 | #include "SSD1306.h" |
42 | 43 | ||
- | 44 | #include "timer2.h" |
|
- | 45 | ||
- | 46 | static MUTEX_DECL(mutexDisplay); |
|
43 | 47 | ||
44 | /*===========================================================================*/ |
48 | /*===========================================================================*/ |
45 | /* Command line related. */ |
49 | /* Command line related. */ |
46 | /*===========================================================================*/ |
50 | /*===========================================================================*/ |
47 | 51 | ||
Line 105... | Line 109... | ||
105 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SD2, commands }; |
109 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SD2, commands }; |
106 | 110 | ||
107 | /* |
111 | /* |
108 | * Red LEDs blinker thread, times are in milliseconds. |
112 | * Red LEDs blinker thread, times are in milliseconds. |
109 | */ |
113 | */ |
- | 114 | uint16_t sampleVal; |
|
- | 115 | ||
110 | static WORKING_AREA(waThread1, 128); |
116 | static WORKING_AREA(waThread1, 128); |
111 | static msg_t Thread1(void *arg) { |
117 | static msg_t Thread1(void *arg) { |
112 | 118 | ||
113 | (void) arg; |
119 | (void) arg; |
114 | chRegSetThreadName("blinker"); |
120 | chRegSetThreadName("PLL "); |
115 | while (TRUE) { |
121 | while (TRUE) { |
116 | palClearPad(GPIOA, GPIOA_STROBE); |
122 | sampleVal = getNextPulse(); |
- | 123 | ||
117 | chThdSleep(1); |
124 | chThdSleep(1); |
118 | palSetPad(GPIOA, GPIOA_STROBE); |
- | |
119 | chThdSleepMilliseconds(50); |
- | |
120 | } |
125 | } |
121 | return 0; |
126 | return 0; |
122 | } |
127 | } |
123 | 128 | ||
124 | /* |
129 | /* |
Line 136... | Line 141... | ||
136 | * RTOS is active. |
141 | * RTOS is active. |
137 | */ |
142 | */ |
138 | halInit(); |
143 | halInit(); |
139 | chSysInit(); |
144 | chSysInit(); |
140 | 145 | ||
- | 146 | ||
- | 147 | initTimer2(); |
|
- | 148 | ||
- | 149 | useAdc(); |
|
- | 150 | ||
141 | /* |
151 | /* |
142 | * Activates the serial driver 2 using the driver default configuration. |
152 | * Activates the serial driver 2 using the driver default configuration. |
143 | */ |
153 | */ |
144 | sdStart(&SD2, NULL); |
154 | sdStart(&SD2, NULL); |
145 | 155 | ||
Line 150... | Line 160... | ||
150 | 160 | ||
151 | ap_init(); |
161 | ap_init(); |
152 | 162 | ||
153 | 163 | ||
154 | /* |
164 | /* |
155 | * Creates the blinker thread. |
165 | * Creates the PLL thread |
156 | */ |
166 | */ |
157 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
167 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
158 | 168 | ||
159 | /* start the SPI hardware for display */ |
169 | /* start the SPI hardware for display */ |
160 | ssd1306spiInit(); |
170 | ssd1306spiInit(); |
161 | 171 | ||
162 | ssd1306_begin( SSD1306_SWITCHCAPVCC, 0) ; |
172 | ssd1306_begin( SSD1306_SWITCHCAPVCC, 0) ; |
- | 173 | int spd = 800; |
|
- | 174 | ||
- | 175 | int adv = 0; |
|
- | 176 | setRPM(spd); |
|
163 | 177 | ||
164 | int x = 0; |
- | |
165 | while(1) |
178 | while(1) |
166 | { |
179 | { |
- | 180 | spd = getRPM(); |
|
- | 181 | ||
- | 182 | adv = getAdc(0) * 1200 / 4096 - 300; |
|
- | 183 | ||
- | 184 | ||
167 | /* initialise the display */ |
185 | /* initialise the display */ |
- | 186 | chMtxLock(&mutexDisplay); |
|
168 | clearDisplay(); |
187 | clearDisplay(); |
169 | 188 | ||
170 | dim(x); |
- | |
171 | font_gotoxy(0,0); |
189 | font_gotoxy(0,0); |
172 | font_puts("count"); |
- | |
173 | font_sig_digits(12, 0,1,2, x); |
- | |
174 | 190 | ||
175 | print_digits(64, 32, 4,2, 10000-x); |
191 | print_digits(64, 16, 4, 1, adv); |
176 | 192 | ||
- | 193 | print_digits(64, 32, 4,-1, spd); |
|
- | 194 | print_large_string("RPM:",0,32,4); |
|
- | 195 | print_large_string("ADV:",0,16,4); |
|
- | 196 | ||
- | 197 | font_puts("count"); |
|
- | 198 | font_sig_digits(12, 0,1,-1, sampleVal); |
|
177 | 199 | ||
178 | 200 | ||
179 | display(); |
201 | display(); |
- | 202 | ||
- | 203 | chMtxUnlock(); |
|
180 | // |
204 | // |
181 | // invertDisplay(x & 32); |
205 | // invertDisplay(x & 32); |
182 | 206 | ||
183 | chThdSleep(MS2ST(10)); |
207 | chThdSleep(MS2ST(10)); |
184 | 208 | ||
185 | if (x++ == 10000) |
- | |
186 | x=0; |
- | |
187 | } |
209 | } |
188 | 210 | ||
189 | 211 | ||
190 | /* |
212 | /* |
191 | * Normal main() thread activity, in this demo it does nothing except |
213 | * Normal main() thread activity, in this demo it does nothing except |