aboutsummaryrefslogtreecommitdiff
path: root/kernel/ppm.c
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2011-03-22 02:51:32 +0000
committerDimitri Sokolyuk <demon@dim13.org>2011-03-22 02:51:32 +0000
commit58a011ea08a55bee223a0028ddb6237e466b93d0 (patch)
tree591f0ebf970820580c65912e0b893401d2a20f56 /kernel/ppm.c
parentd3e3547ebab9a28e7599ed218a13876a2289c122 (diff)
tweak api
Diffstat (limited to 'kernel/ppm.c')
-rw-r--r--kernel/ppm.c76
1 files changed, 33 insertions, 43 deletions
diff --git a/kernel/ppm.c b/kernel/ppm.c
index 62920e8..3af03a2 100644
--- a/kernel/ppm.c
+++ b/kernel/ppm.c
@@ -24,39 +24,7 @@
#define OFF PORTB &= ~_BV(PB1)
#if 0
-void
-ppm(void *arg)
-{
- struct ppmarg *a = (struct ppmarg *)arg;
- uint32_t r = release();
- uint32_t d = deadline();
- uint32_t t;
- uint32_t s;
- uint8_t i;
-
- DDRB |= _BV(DDB1);
- PORTB &= ~_BV(PB1); /* high is low */
-
- /* frame length 22.5ms, channel 0.7-1.7ms, stop 0.3 ms */
-
- for (;;) {
- s = 0;
-
- t = (uint32_t)a->value[i] * MSEC(1) / 0x3ff;
- s += MSEC(1) + t;
-
- /* channel frame 0.7..1.7ms high */
- OFF;
- r = d += MSEC(1) + t;
- update(r, d);
-
- /* stop frame 0.3ms low */
- ON;
- r = d += MSEC(25) - t - MSEC(1);
- update(r, d);
- }
-}
-#endif
+uint32_t buffer[ADCCHANNELS];
void
ppm(void *arg)
@@ -70,37 +38,59 @@ ppm(void *arg)
DDRB |= _BV(DDB1);
PORTB &= ~_BV(PB1); /* high is low */
- /* frame length 22.5ms, channel 0.7-1.7ms, stop 0.3 ms */
+ /* frame length 20ms, channel 0.7-1.7ms, stop 0.3 ms */
for (;;) {
/* start frame 0.3ms low */
- OFF;
+ ON;
r = d += USEC(300);
update(r, d);
wait(0);
- for (i = 0, t = 0; i < ADCCHANNELS; i++)
- t += a->value[i];
+ for (i = 0, t = 0; i < ADCCHANNELS; i++) {
+ buffer[i] = a->value[i];
+ t += buffer[i];
+ }
+ signal(0);
/* sync frame */
- ON;
- //r = d += USEC(22500) - MSEC(t) / 0x3ff - MSEC(ADCCHANNELS) - USEC(300);
+ OFF;
r = d += MSEC(20) - MSEC(t) / 0x3ff - MSEC(ADCCHANNELS) - USEC(300);
update(r, d);
for (i = 0; i < ADCCHANNELS; i++) {
-
/* start frame 0.3ms low */
- OFF;
+ ON;
r = d += USEC(300);
update(r, d);
/* channel frame 0.7..1.7ms high */
- ON;
- r = d += USEC(700) + MSEC(a->value[i]) / 0x3ff;
+ OFF;
+ r = d += USEC(700) + MSEC(buffer[i]) / 0x3ff;
update(r, d);
}
+
+ }
+}
+#else
+void
+ppm(void *arg)
+{
+ struct ppmarg *a = (struct ppmarg *)arg;
+ uint32_t t;
+
+ DDRB |= _BV(DDB1);
+ PORTB &= ~_BV(PB1);
+
+ for (;;) {
+ wait(0);
+ t = MSEC(1) + MSEC(a->value[0]) / 0x3ff;
signal(0);
+ period(MSEC(20));
+ PORTB ^= _BV(PB1);
+ snooze(t);
+ PORTB ^= _BV(PB1);
}
}
+#endif