More commenting

This commit is contained in:
Mark Qvist 2014-04-06 20:26:24 +02:00
parent b4de1f73ea
commit 19cca9487a
6 changed files with 66 additions and 26 deletions

View File

@ -336,7 +336,12 @@ void afsk_adc_isr(Afsk *afsk, int8_t currentSample) {
// Signal modulation and DAC //
//////////////////////////////////////////////////////
// Defines how many consecutive ones we send
// before we need "stuff" in a zero
#define BIT_STUFF_LEN 5
// A macro for switching what tone is being
// synthesized by the DAC.
#define SWITCH_TONE(inc) (((inc) == MARK_INC) ? SPACE_INC : MARK_INC)
static void afsk_txStart(Afsk *afsk) {
@ -444,7 +449,7 @@ uint8_t afsk_dac_isr(Afsk *afsk) {
//////////////////////////////////////////////////////
// File operation overwrites for read/write //
// File operation functions for read/write //
// These functions make the "class" act like a file //
// pointer, which can be read from or written to. //
// Handy for sending and receiving data :) //

View File

@ -1,19 +1,35 @@
//////////////////////////////////////////////////////
// First things first, all the includes we need //
//////////////////////////////////////////////////////
#ifndef FSK_MODEM_H
#define FSK_MODEM_H
#include "config.h"
#include "hardware.h"
#include "config.h" // Various configuration values
#include "hardware.h" // Hardware functions
#include <cfg/compiler.h>
#include <io/kfile.h>
#include <struct/fifobuf.h>
#include <cfg/compiler.h> // Compiler info from BertOS
#include <struct/fifobuf.h> // FIFO buffer implementation from BertOS
#include <io/kfile.h> // The BertOS KFile interface. This is
// used for letting other functions read
// from or write to the modem like a
// file descriptor.
//////////////////////////////////////////////////////
// Our type definitions and function declarations //
//////////////////////////////////////////////////////
#define SAMPLERATE 9600 // The rate at which we are sampling and synthesizing
#define BITRATE 1200 // The actual bitrate at baseband. This is the baudrate.
#define SAMPLESPERBIT (SAMPLERATE / BITRATE) // How many DAC/ADC samples constitute on bit (8).
#define SAMPLESPERBIT (SAMPLERATE / BITRATE) // How many DAC/ADC samples constitute one bit (8).
// This defines an errortype for a receive-
// buffer overrun.
#define RX_OVERRUN BV(0)
// This struct defines a Hdlc parser. It will let
// us parse the raw bits coming in from the modem
// and synchronise to byte boundaries.
typedef struct Hdlc
{
uint8_t demodulatedBits; // Incoming bitstream from demodulator
@ -22,11 +38,13 @@ typedef struct Hdlc
bool receiving; // Whether or not where actually receiving data (or just noise ;P)
} Hdlc;
#define RX_OVERRUN BV(0)
// This is our primary modem struct. It defines
// all the values we need to modulate and
// demodulate data from the physical medium.
typedef struct Afsk
{
KFile fd;
KFile fd; // A file descriptor for reading from and
// writing to the modem
// I/O hardware pins
int adcPin; // Pin for incoming signal
@ -94,7 +112,8 @@ INLINE Afsk *AFSK_CAST(KFile *fd) {
return (Afsk *)fd;
}
// Declare ISRs and initialization functions
// Declare Interrupt Service Routines
// and initialization functions
void afsk_adc_isr(Afsk *af, int8_t sample);
uint8_t afsk_dac_isr(Afsk *af);
void afsk_init(Afsk *af, int adc_ch, int dac_ch);

View File

@ -2,12 +2,16 @@
#ifndef FSK_CFG
#define FSK_CFG
#define CONFIG_AFSK_RX_BUFLEN 64
#define CONFIG_AFSK_TX_BUFLEN 64
#define CONFIG_AFSK_DAC_SAMPLERATE 9600
#define CONFIG_AFSK_RXTIMEOUT 0
#define CONFIG_AFSK_RX_BUFLEN 64 // The size of the modems receive buffer
#define CONFIG_AFSK_TX_BUFLEN 64 // The size of the modems transmit buffer
#define CONFIG_AFSK_DAC_SAMPLERATE 9600 // The samplerate of the DAC. Note that
// changing it here will not change the
// actual sample rate. It is defined here
// so various functions can use it.
#define CONFIG_AFSK_RXTIMEOUT 0 // How long a read operation from the modem
// will wait for data before timing out.
#define CONFIG_AFSK_PREAMBLE_LEN 500UL
#define CONFIG_AFSK_TRAILER_LEN 100UL
#define CONFIG_AFSK_PREAMBLE_LEN 250UL // The length of the packet preamble in milliseconds
#define CONFIG_AFSK_TRAILER_LEN 100UL // The length of the packet tail in milliseconds
#endif

View File

@ -11,7 +11,7 @@
#include <avr/interrupt.h> // AVR interrupt functions from BertOS
// A reference to our modem "object"
static Afsk *context;
static Afsk *modem;
//////////////////////////////////////////////////////
// And now for the actual hardware functions //
@ -19,11 +19,10 @@ static Afsk *context;
// This function initializes the ADC and configures
// it the way we need.
void hw_afsk_adcInit(int ch, Afsk *_context)
void hw_afsk_adcInit(int ch, Afsk *_modem)
{
// Store a reference to our modem "object"
// FIXME: rename this
context = _context;
modem = _modem;
// Also make sure that we are not trying to use
// a pin that can't be used for analog input
@ -109,7 +108,7 @@ DECLARE_ISR(ADC_vect) {
// can't read negative voltages. By doing this simple
// math, we bring it back to an AC representation
// we can do further calculations on.
afsk_adc_isr(context, ((int16_t)((ADC) >> 2) - 128));
afsk_adc_isr(modem, ((int16_t)((ADC) >> 2) - 128));
// We also need to check if we're supposed to spit
// out some modulated data to the DAC.
@ -124,7 +123,7 @@ DECLARE_ISR(ADC_vect) {
// we also need to trigger another pin controlled
// by the PORTD register. This is the PTT pin
// which tells the radio to open it transmitter.
PORTD = (afsk_dac_isr(context) & 0xF0) | BV(3);
PORTD = (afsk_dac_isr(modem) & 0xF0) | BV(3);
else
// If we're not supposed to transmit anything, we
// keep quiet by continously sending 128, which

View File

@ -1,4 +1,8 @@
//////////////////////////////////////////////////////
// First things first, all the includes we need //
//////////////////////////////////////////////////////
#include <cpu/irq.h> // Interrupt functionality from BertOS
#include <cfg/debug.h> // Debug configuration from BertOS
@ -11,6 +15,11 @@
#include "afsk.h" // Header for AFSK modem
#include "protocol/mp1.h" // Header for MP.1 protocol
//////////////////////////////////////////////////////
// A few definitions //
//////////////////////////////////////////////////////
static Afsk afsk; // Declare a AFSK modem struct
static MP1 mp1; // Declare a protocol struct
static Serial ser; // Declare a serial interface struct
@ -30,6 +39,10 @@ static bool sertx = false; // Flag signifying whether it's time to send da
// Received on the serial port.
//////////////////////////////////////////////////////
// And here comes the actual program :) //
//////////////////////////////////////////////////////
// This is a callback we register with the protocol,
// so we can process each packet as they are decoded.
// Right now it just prints the packet to the serial port.

View File

@ -1,2 +1,2 @@
#define VERS_BUILD 371
#define VERS_BUILD 377
#define VERS_HOST "vixen"