/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See the file COPYING * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Copyright (C) 2010 Frank van Maarseveen */ #include #include #include #include "common.h" #include "bits.h" #include "timer0.h" #include "hardware.h" #include "transmit.h" /* * Define the clock period T expressed in 16us ticks. Constraints: * - receiver.c must be configured for this T too. * - T must be even. * - 2T must be <= 128 */ #define T 20 /* 320 us, 3125Hz */ static void tx_bit(uint8_t bit) { if (bit) CLR(LED); else SET(LED); t0_tickwait((uint8_t)(0.5 * T + 0.5)); TOGGLE(LED); t0_tickwait((uint8_t)(0.5 * T + 0.5)); } /* * Transmit precomputed packets using Manchester/BPSK coding. Put idle * time around the data to mark frame boundaries. * * Initial level is '1' (LED on). The first transition is for the first bit * which by definition must be zero: At T/2 of every clock cycle there is a * transition: up means bit value '1', down means bit value '0'. */ void tx_packet(prog_uint8_t *buf, uint8_t len) { prog_uint8_t *p, *end; uint8_t i, byte; end = buf + len; OUTPUT(LED); SET(LED); t0_tickwait(2 * T); for (p = buf; p < end; ++p) { byte = pgm_read_byte(p); for (i = 0; i < 8; ++i) { tx_bit(byte & 0x80); byte <<= 1; } } CLR(LED); t0_tickwait(2 * T); }