X-Git-Url: http://git.droids-corp.org/?p=protos%2Fxbee-avr.git;a=blobdiff_plain;f=spi_servo.c;h=7a85070a762bdcd84c9667d3597c044aa056f3b6;hp=4b0d24191ef9aefb5f140d2309223b40c9e85a5e;hb=HEAD;hpb=bf003cd191abeafb1c31a7a24aa573b7a20e527e diff --git a/spi_servo.c b/spi_servo.c index 4b0d241..7a85070 100644 --- a/spi_servo.c +++ b/spi_servo.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include "spi_servo.h" #include "main.h" @@ -24,9 +24,6 @@ * callback is unloaded. */ -/* 1ms */ -#define SPI_EVT_PERIOD (10000UL/SCHEDULER_UNIT) - #define PPM_BIT 0x01 #define BYPASS_BIT 0x02 @@ -44,6 +41,8 @@ struct spi_servo_rx { }; static struct spi_servo_rx spi_servo_rx; +static struct callout spi_timer; + /* * SPI protocol: * @@ -124,7 +123,7 @@ static void decode_rx_servo(union spi_byte0 byte0, union spi_byte1 byte1) } /* called by the scheduler */ -static void spi_servo_cb(void *arg) +static void spi_servo_cb(struct callout_mgr *cm, struct callout *tim, void *arg) { uint8_t idx; union spi_byte0 byte0; @@ -147,13 +146,13 @@ static void spi_servo_cb(void *arg) if (spi_servo_tx.next_byte != 0) { spi_send_byte(spi_servo_tx.next_byte); spi_servo_tx.next_byte = 0; - return; + goto reschedule; } /* if there is no updated servo, send 0 and return. */ if (spi_servo_tx.cmd_mask == 0) { spi_send_byte(0); - return; + goto reschedule; } /* else find it and send it */ @@ -170,6 +169,11 @@ static void spi_servo_cb(void *arg) spi_send_one_servo(idx, spi_servo_tx.servo[idx]); spi_servo_tx.cmd_mask &= (~(1 << idx)); spi_servo_tx.cur_idx = idx; + + reschedule: + /* don't use callout_reschedule() here, we want to schedule in one tick + * relative to current time: 1 tick is 682us at 12Mhz */ + callout_schedule(cm, tim, 0); } void spi_servo_init(void) @@ -180,13 +184,13 @@ void spi_servo_init(void) /* remove power reduction on spi */ PRR0 &= ~(1 << PRSPI); - /* Enable SPI, Master, set clock rate fck/64 */ - SPCR = (1<