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 // // Signal modulation and DAC //
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// Defines how many consecutive ones we send
// before we need "stuff" in a zero
#define BIT_STUFF_LEN 5 #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) #define SWITCH_TONE(inc) (((inc) == MARK_INC) ? SPACE_INC : MARK_INC)
static void afsk_txStart(Afsk *afsk) { static void afsk_txStart(Afsk *afsk) {
@ -352,7 +357,7 @@ static void afsk_txStart(Afsk *afsk) {
ATOMIC(afsk->tailLength = DIV_ROUND(CONFIG_AFSK_TRAILER_LEN * BITRATE, 8000)); ATOMIC(afsk->tailLength = DIV_ROUND(CONFIG_AFSK_TRAILER_LEN * BITRATE, 8000));
} }
// This is the DAC ISR, called at sampling ratewhenever the DAC IRQ is on. // This is the DAC ISR, called at sampling rate whenever the DAC IRQ is on.
// It modulates the data to be transmitted and returns a value directly // It modulates the data to be transmitted and returns a value directly
// for output on the DAC // for output on the DAC
uint8_t afsk_dac_isr(Afsk *afsk) { uint8_t afsk_dac_isr(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 // // These functions make the "class" act like a file //
// pointer, which can be read from or written to. // // pointer, which can be read from or written to. //
// Handy for sending and receiving data :) // // Handy for sending and receiving data :) //

View File

@ -1,19 +1,35 @@
//////////////////////////////////////////////////////
// First things first, all the includes we need //
//////////////////////////////////////////////////////
#ifndef FSK_MODEM_H #ifndef FSK_MODEM_H
#define FSK_MODEM_H #define FSK_MODEM_H
#include "config.h" #include "config.h" // Various configuration values
#include "hardware.h" #include "hardware.h" // Hardware functions
#include <cfg/compiler.h> #include <cfg/compiler.h> // Compiler info from BertOS
#include <io/kfile.h> #include <struct/fifobuf.h> // FIFO buffer implementation from BertOS
#include <struct/fifobuf.h> #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 SAMPLERATE 9600 // The rate at which we are sampling and synthesizing
#define BITRATE 1200 // The actual bitrate at baseband. This is the baudrate. #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 typedef struct Hdlc
{ {
uint8_t demodulatedBits; // Incoming bitstream from demodulator 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) bool receiving; // Whether or not where actually receiving data (or just noise ;P)
} Hdlc; } 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 typedef struct Afsk
{ {
KFile fd; KFile fd; // A file descriptor for reading from and
// writing to the modem
// I/O hardware pins // I/O hardware pins
int adcPin; // Pin for incoming signal int adcPin; // Pin for incoming signal
@ -94,9 +112,10 @@ INLINE Afsk *AFSK_CAST(KFile *fd) {
return (Afsk *)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); void afsk_adc_isr(Afsk *af, int8_t sample);
uint8_t afsk_dac_isr(Afsk *af); uint8_t afsk_dac_isr(Afsk *af);
void afsk_init(Afsk *af, int adc_ch, int dac_ch); void afsk_init(Afsk *af, int adc_ch, int dac_ch);
#endif #endif

View File

@ -2,12 +2,16 @@
#ifndef FSK_CFG #ifndef FSK_CFG
#define FSK_CFG #define FSK_CFG
#define CONFIG_AFSK_RX_BUFLEN 64 #define CONFIG_AFSK_RX_BUFLEN 64 // The size of the modems receive buffer
#define CONFIG_AFSK_TX_BUFLEN 64 #define CONFIG_AFSK_TX_BUFLEN 64 // The size of the modems transmit buffer
#define CONFIG_AFSK_DAC_SAMPLERATE 9600 #define CONFIG_AFSK_DAC_SAMPLERATE 9600 // The samplerate of the DAC. Note that
#define CONFIG_AFSK_RXTIMEOUT 0 // 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_PREAMBLE_LEN 250UL // The length of the packet preamble in milliseconds
#define CONFIG_AFSK_TRAILER_LEN 100UL #define CONFIG_AFSK_TRAILER_LEN 100UL // The length of the packet tail in milliseconds
#endif #endif

View File

@ -11,7 +11,7 @@
#include <avr/interrupt.h> // AVR interrupt functions from BertOS #include <avr/interrupt.h> // AVR interrupt functions from BertOS
// A reference to our modem "object" // A reference to our modem "object"
static Afsk *context; static Afsk *modem;
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// And now for the actual hardware functions // // And now for the actual hardware functions //
@ -19,11 +19,10 @@ static Afsk *context;
// This function initializes the ADC and configures // This function initializes the ADC and configures
// it the way we need. // 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" // Store a reference to our modem "object"
// FIXME: rename this modem = _modem;
context = _context;
// Also make sure that we are not trying to use // Also make sure that we are not trying to use
// a pin that can't be used for analog input // 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 // can't read negative voltages. By doing this simple
// math, we bring it back to an AC representation // math, we bring it back to an AC representation
// we can do further calculations on. // 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 // We also need to check if we're supposed to spit
// out some modulated data to the DAC. // out some modulated data to the DAC.
@ -124,7 +123,7 @@ DECLARE_ISR(ADC_vect) {
// we also need to trigger another pin controlled // we also need to trigger another pin controlled
// by the PORTD register. This is the PTT pin // by the PORTD register. This is the PTT pin
// which tells the radio to open it transmitter. // 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 else
// If we're not supposed to transmit anything, we // If we're not supposed to transmit anything, we
// keep quiet by continously sending 128, which // 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 <cpu/irq.h> // Interrupt functionality from BertOS
#include <cfg/debug.h> // Debug configuration from BertOS #include <cfg/debug.h> // Debug configuration from BertOS
@ -11,6 +15,11 @@
#include "afsk.h" // Header for AFSK modem #include "afsk.h" // Header for AFSK modem
#include "protocol/mp1.h" // Header for MP.1 protocol #include "protocol/mp1.h" // Header for MP.1 protocol
//////////////////////////////////////////////////////
// A few definitions //
//////////////////////////////////////////////////////
static Afsk afsk; // Declare a AFSK modem struct static Afsk afsk; // Declare a AFSK modem struct
static MP1 mp1; // Declare a protocol struct static MP1 mp1; // Declare a protocol struct
static Serial ser; // Declare a serial interface 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. // Received on the serial port.
//////////////////////////////////////////////////////
// And here comes the actual program :) //
//////////////////////////////////////////////////////
// This is a callback we register with the protocol, // This is a callback we register with the protocol,
// so we can process each packet as they are decoded. // so we can process each packet as they are decoded.
// Right now it just prints the packet to the serial port. // 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" #define VERS_HOST "vixen"