70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
|
|
/* armando modem - 2014 */
|
||
|
|
|
||
|
|
#ifdef __XC16
|
||
|
|
#include <xc.h>
|
||
|
|
#include <dsp.h>
|
||
|
|
#include <libq.h>
|
||
|
|
#elif __unix
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
#include "modem.h"
|
||
|
|
#include "modulator.h"
|
||
|
|
|
||
|
|
#include "../peripheral/dac.h"
|
||
|
|
#include "../peripheral/gpio.h"
|
||
|
|
|
||
|
|
rotor_symbol rotor_constellation[MAX_MODULATION_ALPHABET_SIZE];
|
||
|
|
rotor_symbol silence;
|
||
|
|
|
||
|
|
// buffer dei simboli
|
||
|
|
uint8_t tx_symbol_buffer[MAX_SYMBOL_BUFFER_SIZE];
|
||
|
|
uint8_t tx_symbol_buffer_index, tx_symbol_buffer_lenght;
|
||
|
|
|
||
|
|
void modulator_setup(void) {
|
||
|
|
// TX
|
||
|
|
#ifdef USE_GPIO
|
||
|
|
set_tx_GPIOs();
|
||
|
|
#endif
|
||
|
|
modulator_prepare_constellation_symbols(mod.constellation, rotor_constellation);
|
||
|
|
}
|
||
|
|
|
||
|
|
// #####################################################
|
||
|
|
|
||
|
|
// genera un buffer di campioni
|
||
|
|
|
||
|
|
void modulator_generate_sample_buffer(fractional *Q_buffer, fractional *I_buffer, uint8_t size, rotor_symbol symbol) {
|
||
|
|
uint8_t i;
|
||
|
|
|
||
|
|
static fractional modulator_rotor, modulator_rotor_position;
|
||
|
|
i = 0;
|
||
|
|
while (i < size) {
|
||
|
|
modulator_rotor_position = modulator_rotor + symbol.offset;
|
||
|
|
Q_buffer[i] = __builtin_mulss(_Q15sinPI(modulator_rotor_position), // non deve saturare
|
||
|
|
symbol.gain) >> 15;
|
||
|
|
|
||
|
|
I_buffer[i] = __builtin_mulss(_Q15cosPI(modulator_rotor_position), // non deve saturare
|
||
|
|
symbol.gain) >> 15;
|
||
|
|
|
||
|
|
modulator_rotor += symbol.increment; // la _Q15 satura!
|
||
|
|
++i;
|
||
|
|
}
|
||
|
|
|
||
|
|
#if ! defined(__DEBUG)
|
||
|
|
// viene riasserito dal DMA del dac, dove mettere?
|
||
|
|
populate_tx_sample_buffer = 0; // fatto
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
// traduce da modulazione astratta a parametri per il modulatore
|
||
|
|
|
||
|
|
void modulator_prepare_constellation_symbols(symbol *constellation, rotor_symbol *mod_constellation) {
|
||
|
|
uint8_t i;
|
||
|
|
for (i = 0; i < mod.alphabet_size; i++) {
|
||
|
|
mod_constellation[i].increment = get_angular_frequency(constellation[i].frequency);
|
||
|
|
mod_constellation[i].offset = constellation[i].phase;
|
||
|
|
mod_constellation[i].gain = constellation[i].amplitude;
|
||
|
|
}
|
||
|
|
}
|