From 285513c401954c5ad012ae4ae5411f72b7f73ffc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 3 Nov 2013 11:20:42 +0200 Subject: [PATCH] Support chaining packets to create a larger packet MFX packets with response windows won't fit into the 256 bits available in a single packet structure. I'd rather keep the length field 8-bit to preserve atomicity, and this also allows certain tricks later that would be harder to do with a single packet. --- arducontrol/output.c | 39 ++++++++++++++++++++++++++------------- arducontrol/output.h | 1 + 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/arducontrol/output.c b/arducontrol/output.c index 673f232..e017560 100644 --- a/arducontrol/output.c +++ b/arducontrol/output.c @@ -14,7 +14,9 @@ enum State SENDING }; -OutputPacket packet; +OutputPacket packets[4]; +uint8_t chain_length; +uint8_t current_packet; volatile uint8_t packet_state = IDLE; static uint8_t out_bit; static uint8_t out_time; @@ -32,7 +34,14 @@ void output_init(void) OutputPacket *output_create_packet(void) { while(packet_state!=IDLE) ; - return &packet; + chain_length = 1; + return &packets[0]; +} + +OutputPacket *output_create_chained_packet(void) +{ + ++chain_length; + return &packets[chain_length-1]; } void output_send_packet(void) @@ -40,6 +49,7 @@ void output_send_packet(void) if(packet_state!=IDLE) return; + current_packet = 0; packet_state = READY; } @@ -88,27 +98,29 @@ static inline void output_tick(void) if(out_time && !--out_time) { + OutputPacket *packet = &packets[current_packet]; ++out_bit; - if(out_bit>=packet.length) + if(out_bit>=packet->length) { PORTD &= ~BIT(POLARITY); - if(packet.repeat_count>1) + if(--packet->repeat_count) { - if(packet.repeat_count<0xFF) - --packet.repeat_count; - delay_time = packet.repeat_delay; + delay_time = packet->repeat_delay; packet_state = READY; } else { - delay_time = packet.final_delay; - packet_state = IDLE; + delay_time = packet->final_delay; + if(++current_packet>3]; + out_data = packet->data[out_bit>>3]; else out_data >>= 1; @@ -117,7 +129,7 @@ static inline void output_tick(void) else PORTD &= ~BIT(POLARITY); - out_time = packet.bit_duration; + out_time = packet->bit_duration; } return; @@ -125,10 +137,11 @@ static inline void output_tick(void) if(packet_state==READY) { + OutputPacket *packet = &packets[current_packet]; packet_state = SENDING; out_bit = 0; - out_time = packet.bit_duration; - out_data = packet.data[0]; + out_time = packet->bit_duration; + out_data = packet->data[0]; if(out_data&1) PORTD |= BIT(POLARITY); else diff --git a/arducontrol/output.h b/arducontrol/output.h index 162e1e0..2fde262 100644 --- a/arducontrol/output.h +++ b/arducontrol/output.h @@ -15,6 +15,7 @@ typedef struct void output_init(void); OutputPacket *output_create_packet(void); +OutputPacket *output_create_chained_packet(void); void output_send_packet(void); void output_set_power(uint8_t); uint8_t output_is_power_on(); -- 2.45.2