From: baobrien Date: Tue, 5 Sep 2017 19:38:56 +0000 (+0000) Subject: More work on TDMA; Remembered to add tdma.c X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=8c75c1d7edfb6c82aa4d2e51417d6b89331f6a69;p=freetel-svn-tracking.git More work on TDMA; Remembered to add tdma.c git-svn-id: https://svn.code.sf.net/p/freetel/code@3359 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/tdma.c b/codec2-dev/src/tdma.c new file mode 100644 index 00000000..2dd625db --- /dev/null +++ b/codec2-dev/src/tdma.c @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: tdma.c + AUTHOR......: Brady O'Brien + DATE CREATED: 18 September 2016 + + Skeletion of the TDMA FSK modem + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2017 Brady O'Brien + + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 2.1, as + published by the Free Software Foundation. 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. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + + +#include "fsk.h" +#include "freedv_vhf_framing.h" +#include "tdma.h" +#include +#include +#include + +struct TDMA_MODEM * tdma_create(struct TDMA_MODE_SETTINGS mode){ + struct TDMA_MODEM * tdma; + + u32 Rs = mode.sym_rate; + u32 Fs = mode.samp_rate; + u32 slot_size = mode.slot_size; + //u32 frame_size = mode.frame_size; + u32 n_slots = mode.n_slots; + u32 M = mode.fsk_m; + u32 P = Fs/Rs; + u32 Ts = Fs/Rs; + + assert( (Fs%Rs)==0 ); + assert( M==2 || M==4); + + /* allocate the modem */ + tdma = (struct TDMA_MODEM *) malloc(sizeof(struct TDMA_MODEM)); + /* TODO: Malloc NULL checks */ + + /* Symbols over which pilot modem operates */ + u32 pilot_nsyms = slot_size/2; + + /* Set up pilot modem */ + struct FSK * pilot = fsk_create_hbr(Fs,Rs,P,M,Rs,Rs); + fsk_set_nsym(pilot,pilot_nsyms); + tdma->fsk_pilot = pilot; + + tdma->settings = mode; + tdma->state = no_sync; + tdma->sample_sync_offset = 0; + + /* Allocate buffer for incoming samples */ + /* TODO: We may only need a single slot's worth of samps -- look into this */ + COMP * samp_buffer = (COMP *) malloc(sizeof(COMP)*slot_size*Ts*n_slots); + + tdma->sample_buffer = samp_buffer; + + /* TODO: Allocate slot modems. Get pilot detection working first */ + + return tdma; + +} + +void tdma_print_stuff(struct TDMA_MODEM * tdma){ + printf("symrate: %d\n",tdma->settings.sym_rate); + printf("fsk_m: %d\n",tdma->settings.fsk_m); + printf("samprate: %d\n",tdma->settings.samp_rate); + printf("slotsize: %d\n",tdma->settings.slot_size); + printf("framesize: %d\n",tdma->settings.frame_size); + printf("nslots: %d\n",tdma->settings.n_slots); + printf("frametype: %d\n",tdma->settings.frame_type); + printf("sync_offset: %ld\n",tdma->sample_sync_offset); +} + +void tdma_destroy(struct TDMA_MODEM * tdma){ + /* TODO: Free slot modems (need to create them first) */ + fsk_destroy(tdma->fsk_pilot); + free(tdma->sample_buffer); + free(tdma); +} + +u32 tdma_get_N(struct TDMA_MODEM * tdma){ + u32 slot_size = tdma->settings.slot_size; + u32 Fs = tdma->settings.samp_rate; + u32 Rs = tdma->settings.sym_rate; + return slot_size * (Fs/Rs); +} + +void tdma_rx(struct TDMA_MODEM * tdma, COMP * samps){ + +} \ No newline at end of file diff --git a/codec2-dev/src/tdma.h b/codec2-dev/src/tdma.h index 7740d7ad..1357555b 100644 --- a/codec2-dev/src/tdma.h +++ b/codec2-dev/src/tdma.h @@ -33,6 +33,14 @@ #include #include "comp_prim.h" + +/* TODO: Replace these types with their full names */ +/* I'm just feeling lazy right now */ +typedef uint32_t u32; +typedef int32_t i32; +typedef uint8_t u8; +typedef float f32; + //typedef void (*tdma_cb_rx_frame)() /* The state for an individual slot */ @@ -105,4 +113,17 @@ struct TDMA_MODEM * tdma_create(struct TDMA_MODE_SETTINGS mode); /* Tear down and free a TDMA modem */ void tdma_destroy(struct TDMA_MODEM * tdma); + +/* Get the number of samples expected by RX for the next cycle */ +u32 tdma_get_N(struct TDMA_MODEM * tdma); + +/** + Put 1 slot's worth of samples into the TDMA modem + TODO: I'm still not entirely sure of what I want the semantics of this to look like +*/ +void tdma_rx(struct TDMA_MODEM * tdma, COMP * samps); + +/* Hideous debug function */ +void tdma_print_stuff(struct TDMA_MODEM * tdma); + #endif