More work on TDMA; Remembered to add tdma.c
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 5 Sep 2017 19:38:56 +0000 (19:38 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 5 Sep 2017 19:38:56 +0000 (19:38 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3359 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/tdma.c [new file with mode: 0644]
codec2-dev/src/tdma.h

diff --git a/codec2-dev/src/tdma.c b/codec2-dev/src/tdma.c
new file mode 100644 (file)
index 0000000..2dd625d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+
+
+#include "fsk.h"
+#include "freedv_vhf_framing.h"
+#include "tdma.h"
+#include <stdint.h>
+#include <assert.h>
+#include <stdio.h>
+
+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
index 7740d7ad60425aacb9f1dadb06d30072d0f32fba..1357555bd5e563657b31fff43edf603f6f9ec861 100644 (file)
 #include <stdint.h>
 #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