hadie/rtty.c

83 wiersze
1.7 KiB
C
Czysty Zwykły widok Historia

/* hadie - High Altitude Balloon flight software */
/*============================================================*/
/* Copyright (C)2010 Philip Heron <phil@sanslogic.co.uk> */
/* */
/* This program is distributed under the terms of the GNU */
/* General Public License, version 2. You may use, modify, */
/* and redistribute it under the terms of this license. A */
/* copy should be included with this source. */
#include "config.h"
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#define RTTY_DELAY (1000000 / RTTY_BAUD)
/* MARK = Upper tone, Idle, bit */
#define TXENABLE (0x04)
#define MARK (0x02)
#define SPACE (0x01)
/* RTTY speed */
uint16_t rtty_delay = (1000000 / RTTY_BAUD);
//#define RTTY_DELAY rtty_delay
2010-06-08 08:03:24 +00:00
void rtx_baud(int baud)
{
rtty_delay = 1000000 / baud;
}
2010-06-08 08:03:24 +00:00
inline void rtx_bit(uint8_t b)
{
PORTB &= ~(MARK | SPACE);
PORTB |= b;
}
2010-06-08 08:03:24 +00:00
void rtx_byte(uint8_t byte)
{
int i;
/* Start bit */
2010-06-08 08:03:24 +00:00
rtx_bit(SPACE);
_delay_us(RTTY_DELAY);
/* 7 bit */
for(i = 0; i < 8; i++)
{
2010-06-08 08:03:24 +00:00
if(byte & 1 << i) rtx_bit(MARK); else rtx_bit(SPACE);
_delay_us(RTTY_DELAY);
}
/* Stop bit 1 */
2010-06-08 08:03:24 +00:00
rtx_bit(MARK);
_delay_us(RTTY_DELAY);
_delay_us(RTTY_DELAY / 2);
}
2010-06-08 08:03:24 +00:00
void rtx_string(char *s)
{
2010-06-08 08:03:24 +00:00
while(*s != '\0') rtx_byte(*(s++));
}
2010-06-08 08:03:24 +00:00
void rtx_string_P(PGM_P s)
{
char b;
2010-06-08 08:03:24 +00:00
while((b = pgm_read_byte(s++)) != '\0') rtx_byte(b);
}
void rtx_data(uint8_t *data, size_t length)
{
int b;
for(b = 0; b < length; b++) rtx_byte(data[b]);
}
2010-06-08 08:03:24 +00:00
void rtx_init()
{
/* We use Port B pins 1, 2 and 3 - MARK by default */
2010-06-08 08:03:24 +00:00
rtx_bit(MARK);
PORTB |= TXENABLE;
DDRB |= MARK | SPACE | TXENABLE;
}