diff --git a/firmware/baseband/baseband_dma.cpp b/firmware/baseband/baseband_dma.cpp index b6c50cde..aa119dc6 100644 --- a/firmware/baseband/baseband_dma.cpp +++ b/firmware/baseband/baseband_dma.cpp @@ -108,11 +108,6 @@ static Semaphore semaphore; static volatile const gpdma::channel::LLI* next_lli = nullptr; -void test() { - quitt = 1; - chSemSignalI(&semaphore); -} - void transfer_complete() { next_lli = gpdma_channel_sgpio.next_lli(); quitt = 0; diff --git a/firmware/baseband/baseband_dma.hpp b/firmware/baseband/baseband_dma.hpp index 683fc08f..99e32de8 100644 --- a/firmware/baseband/baseband_dma.hpp +++ b/firmware/baseband/baseband_dma.hpp @@ -39,8 +39,6 @@ void configure( const baseband::Direction direction ); -void test(); - void enable(const baseband::Direction direction); bool is_enabled(); diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index 4253b003..c34df643 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -603,9 +603,80 @@ static const int8_t sintab[1024] = { #define FILTER_SIZE 576 #define SAMPLE_BUFFER_SIZE SAMPLES_PER_BIT + FILTER_SIZE -static float waveform_biphase[] = {0.00253265133022, 0.00255504491037, 0.00256667102126, 0.0025672385497, 0.00255649674667, 0.00253423716573, 0.00250029547253, 0.00245455311551, 0.00239693884806, 0.00232743009314, 0.00224605414143, 0.00215288917468, 0.00204806510656, 0.00193176423352, 0.00180422168917, 0.00166572569587, 0.00151661760823, 0.00135729174364, 0.00118819499588, 0.00100982622839, 0.000822735444702, 0.000627522734284, 0.000424836992883, 0.000215374417197, -1.23225298158e-07, -0.000220870549765, -0.000446040728168, -0.000674767880774, -0.000906149680707, -0.00113925016637, -0.00137310275567, -0.00160671345499, -0.00183906425517, -0.00206911670572, -0.00229581565752, -0.00251809316382, -0.00273487252813, -0.00294507248686, -0.0031476115141, -0.00334141223473, -0.0035254059317, -0.00369853713255, -0.00385976825946, -0.00400808432674, -0.00414249766903, -0.00426205268297, -0.00436583056466, -0.00445295402495, -0.00452259196407, -0.00457396408696, -0.00460634544047, -0.00461907085337, -0.00461153926002, -0.00458321788861, -0.00453364629481, -0.00446244022186, -0.0043692952683, -0.00425399034471, -0.0041163909013, -0.00395645190841, -0.00377422057251, -0.0035698387709, -0.00334354518872, -0.00309567714275, -0.00282667207705, -0.00253706871632, -0.00222750786389, -0.00189873283191, -0.00155158949247, -0.0011870259394, -0.000806091751623, -0.000409936849938, 1.90059383236e-07, 0.00042294345989, 0.000856883423268, 0.00130047843362, 0.00175210863919, 0.00221006953169, 0.00267257605183, 0.00313776711824, 0.0036037105756, 0.00406840855594, 0.00452980324611, 0.00498578305229, 0.00543418915128, 0.00587282241677, 0.00629945070701, 0.00671181649912, 0.00710764485348, 0.00748465169059, 0.00784055236082, 0.00817307048659, 0.00847994705483, 0.00875894973632, 0.00900788240743, 0.00922459484812, 0.00940699258958, 0.00955304688301, 0.00966080476069, 0.00972839915915, 0.00975405907344, 0.00973611971083, 0.00967303261139, 0.00956337570235, 0.00940586325271, 0.00919935569384, 0.00894286927184, 0.00863558549687, 0.00827686035476, 0.00786623324593, 0.00740343561706, 0.00688839925073, 0.00632126417893, 0.00570238618641, 0.00503234387065, 0.0043119452256, 0.00354223371723, 0.00272449381977, 0.0018602559824, 0.000951300997274, -3.36259008787e-07, -0.000992363737284, -0.0020222298062, -0.00308712154498, -0.00418396376074, -0.00530941875093, -0.0064598868296, -0.00763150763453, -0.00882016223, -0.0100214760183, -0.011230822471, -0.0124433276877, -0.0136538757908, -0.0148571151577, -0.0160474654948, -0.0172191257514, -0.0183660828705, -0.0194821213717, -0.0205608337587, -0.0215956317392, -0.0225797582461, -0.0235063002445, -0.0243682023052, -0.0251582809259, -0.0258692395759, -0.0264936844398, -0.0270241408326, -0.0274530702548, -0.0277728880563, -0.0279759816737, -0.0280547294041, -0.0280015196764, -0.0278087707783, -0.0274689509968, -0.026974599126, -0.0263183452962, -0.0254929320749, -0.02449123579, -0.0233062880235, -0.0219312972225, -0.0203596703733, -0.0185850346832, -0.0166012592143, -0.0144024764108, -0.0119831034641, -0.00933786345535, -0.00646180621834, -0.0033503288631, 8.04098443393e-07, 0.00359544108347, 0.0074370242845, 0.0115285710889, 0.0158726561293, 0.0204713940206, 0.0253264228417, 0.0304388884133, 0.0358094294279, 0.041438163483, 0.0473246740673, 0.0534679985499, 0.0598666172177, 0.0665184434076, 0.0734208147742, 0.0805704857345, 0.0879636211267, 0.0955957911196, 0.103461967402, 0.111556520688, 0.119873219553, 0.128405230643, 0.137145120254, 0.146084857323, 0.155215817824, 0.164528790593, 0.174013984585, 0.18366103756, 0.193459026213, 0.203396477728, 0.213461382761, 0.223641209834, 0.233922921126, 0.244292989649, 0.254737417779, 0.265241757122, 0.275791129685, 0.286370250309, 0.296963450356, 0.307554702567, 0.318127647097, 0.328665618632, 0.339151674584, 0.349568624272, 0.359899059063, 0.37012538339, 0.380229846614, 0.39019457563, 0.400001608191, 0.40963292682, 0.419070493361, 0.428296283903, 0.437292324199, 0.446040725381, 0.45452371993, 0.462723697829, 0.470623242797, 0.478205168549, 0.485452554966, 0.492348784132, 0.498877576118, 0.505023024448, 0.510769631171, 0.516102341434, 0.521006577488, 0.525468272051, 0.529473900929, 0.533010514831, 0.536065770289, 0.538627959622, 0.540686039841, 0.542229660459, 0.543249190098, 0.543735741853, 0.543681197332, 0.543078229311, 0.541920322948, 0.540201795495, 0.537917814453, 0.535064414122, 0.5316385105, 0.527637914479, 0.523061343309, 0.51790843029, 0.512179732652, 0.505876737611, 0.499001866561, 0.491558477398, 0.483550864942, 0.474984259467, 0.46586482332, 0.456199645625, 0.445996735085, 0.43526501088, 0.424014291681, 0.412255282783, 0.399999561397, 0.387259560081, 0.374048548451, 0.360380613021, 0.346270635398, 0.331734268754, 0.316787912671, 0.301448686393, 0.28573440054, 0.269663527349, 0.253255169494, 0.236529027553, 0.219505366195, 0.202204979147, 0.184649153022, 0.166859630089, 0.148858570049, 0.13066851092, 0.112312329091, 0.0938131986527, 0.0751945500785, 0.0564800283494, 0.0376934506144, 0.018858763477, 0.0, -0.018858763477, -0.0376934506144, -0.0564800283494, -0.0751945500785, -0.0938131986527, -0.112312329091, -0.13066851092, -0.148858570049, -0.166859630089, -0.184649153022, -0.202204979147, -0.219505366195, -0.236529027553, -0.253255169494, -0.269663527349, -0.28573440054, -0.301448686393, -0.316787912671, -0.331734268754, -0.346270635398, -0.360380613021, -0.374048548451, -0.387259560081, -0.399999561397, -0.412255282783, -0.424014291681, -0.43526501088, -0.445996735085, -0.456199645625, -0.46586482332, -0.474984259467, -0.483550864942, -0.491558477398, -0.499001866561, -0.505876737611, -0.512179732652, -0.51790843029, -0.523061343309, -0.527637914479, -0.5316385105, -0.535064414122, -0.537917814453, -0.540201795495, -0.541920322948, -0.543078229311, -0.543681197332, -0.543735741853, -0.543249190098, -0.542229660459, -0.540686039841, -0.538627959622, -0.536065770289, -0.533010514831, -0.529473900929, -0.525468272051, -0.521006577488, -0.516102341434, -0.510769631171, -0.505023024448, -0.498877576118, -0.492348784132, -0.485452554966, -0.478205168549, -0.470623242797, -0.462723697829, -0.45452371993, -0.446040725381, -0.437292324199, -0.428296283903, -0.419070493361, -0.40963292682, -0.400001608191, -0.39019457563, -0.380229846614, -0.37012538339, -0.359899059063, -0.349568624272, -0.339151674584, -0.328665618632, -0.318127647097, -0.307554702567, -0.296963450356, -0.286370250309, -0.275791129685, -0.265241757122, -0.254737417779, -0.244292989649, -0.233922921126, -0.223641209834, -0.213461382761, -0.203396477728, -0.193459026213, -0.18366103756, -0.174013984585, -0.164528790593, -0.155215817824, -0.146084857323, -0.137145120254, -0.128405230643, -0.119873219553, -0.111556520688, -0.103461967402, -0.0955957911196, -0.0879636211267, -0.0805704857345, -0.0734208147742, -0.0665184434076, -0.0598666172177, -0.0534679985499, -0.0473246740673, -0.041438163483, -0.0358094294279, -0.0304388884133, -0.0253264228417, -0.0204713940206, -0.0158726561293, -0.0115285710889, -0.0074370242845, -0.00359544108347, -8.04098443393e-07, 0.0033503288631, 0.00646180621834, 0.00933786345535, 0.0119831034641, 0.0144024764108, 0.0166012592143, 0.0185850346832, 0.0203596703733, 0.0219312972225, 0.0233062880235, 0.02449123579, 0.0254929320749, 0.0263183452962, 0.026974599126, 0.0274689509968, 0.0278087707783, 0.0280015196764, 0.0280547294041, 0.0279759816737, 0.0277728880563, 0.0274530702548, 0.0270241408326, 0.0264936844398, 0.0258692395759, 0.0251582809259, 0.0243682023052, 0.0235063002445, 0.0225797582461, 0.0215956317392, 0.0205608337587, 0.0194821213717, 0.0183660828705, 0.0172191257514, 0.0160474654948, 0.0148571151577, 0.0136538757908, 0.0124433276877, 0.011230822471, 0.0100214760183, 0.00882016223, 0.00763150763453, 0.0064598868296, 0.00530941875093, 0.00418396376074, 0.00308712154498, 0.0020222298062, 0.000992363737284, 3.36259008787e-07, -0.000951300997274, -0.0018602559824, -0.00272449381977, -0.00354223371723, -0.0043119452256, -0.00503234387065, -0.00570238618641, -0.00632126417893, -0.00688839925073, -0.00740343561706, -0.00786623324593, -0.00827686035476, -0.00863558549687, -0.00894286927184, -0.00919935569384, -0.00940586325271, -0.00956337570235, -0.00967303261139, -0.00973611971083, -0.00975405907344, -0.00972839915915, -0.00966080476069, -0.00955304688301, -0.00940699258958, -0.00922459484812, -0.00900788240743, -0.00875894973632, -0.00847994705483, -0.00817307048659, -0.00784055236082, -0.00748465169059, -0.00710764485348, -0.00671181649912, -0.00629945070701, -0.00587282241677, -0.00543418915128, -0.00498578305229, -0.00452980324611, -0.00406840855594, -0.0036037105756, -0.00313776711824, -0.00267257605183, -0.00221006953169, -0.00175210863919, -0.00130047843362, -0.000856883423268, -0.00042294345989, -1.90059383236e-07, 0.000409936849938, 0.000806091751623, 0.0011870259394, 0.00155158949247, 0.00189873283191, 0.00222750786389, 0.00253706871632, 0.00282667207705, 0.00309567714275, 0.00334354518872, 0.0035698387709, 0.00377422057251, 0.00395645190841, 0.0041163909013, 0.00425399034471, 0.0043692952683, 0.00446244022186, 0.00453364629481, 0.00458321788861, 0.00461153926002, 0.00461907085337, 0.00460634544047, 0.00457396408696, 0.00452259196407, 0.00445295402495, 0.00436583056466, 0.00426205268297, 0.00414249766903, 0.00400808432674, 0.00385976825946, 0.00369853713255, 0.0035254059317, 0.00334141223473, 0.0031476115141, 0.00294507248686, 0.00273487252813, 0.00251809316382, 0.00229581565752, 0.00206911670572, 0.00183906425517, 0.00160671345499, 0.00137310275567, 0.00113925016637, 0.000906149680707, 0.000674767880774, 0.000446040728168, 0.000220870549765, 1.23225298158e-07, -0.000215374417197, -0.000424836992883, -0.000627522734284, -0.000822735444702, -0.00100982622839, -0.00118819499588, -0.00135729174364, -0.00151661760823, -0.00166572569587, -0.00180422168917, -0.00193176423352, -0.00204806510656, -0.00215288917468, -0.00224605414143, -0.00232743009314, -0.00239693884806, -0.00245455311551, -0.00250029547253, -0.00253423716573, -0.00255649674667, -0.0025672385497, -0.00256667102126, -0.00255504491037}; - -int cnt, re, im; +static int32_t waveform_biphase[] = { + 165,167,168,168,167,166,163,160, + 157,152,147,141,134,126,118,109, + 99,88,77,66,53,41,27,14, + 0,-14,-29,-44,-59,-74,-89,-105, + -120,-135,-150,-165,-179,-193,-206,-218, + -231,-242,-252,-262,-271,-279,-286,-291, + -296,-299,-301,-302,-302,-300,-297,-292, + -286,-278,-269,-259,-247,-233,-219,-202, + -185,-166,-145,-124,-101,-77,-52,-26, + 0,27,56,85,114,144,175,205, + 236,266,296,326,356,384,412,439, + 465,490,513,535,555,574,590,604, + 616,626,633,637,639,638,633,626, + 616,602,586,565,542,515,485,451, + 414,373,329,282,232,178,121,62, + 0,-65,-132,-202,-274,-347,-423,-500, + -578,-656,-736,-815,-894,-973,-1051,-1128, + -1203,-1276,-1347,-1415,-1479,-1540,-1596,-1648, + -1695,-1736,-1771,-1799,-1820,-1833,-1838,-1835, + -1822,-1800,-1767,-1724,-1670,-1605,-1527,-1437, + -1334,-1217,-1087,-943,-785,-611,-423,-219, + 0,235,487,755,1040,1341,1659,1994, + 2346,2715,3101,3504,3923,4359,4811,5280, + 5764,6264,6780,7310,7856,8415,8987,9573, + 10172,10782,11404,12036,12678,13329,13989,14656, + 15330,16009,16694,17382,18074,18767,19461,20155, + 20848,21539,22226,22909,23586,24256,24918,25571, + 26214,26845,27464,28068,28658,29231,29787,30325, + 30842,31339,31814,32266,32694,33097,33473,33823, + 34144,34437,34699,34931,35131,35299,35434,35535, + 35602,35634,35630,35591,35515,35402,35252,35065, + 34841,34579,34279,33941,33566,33153,32702,32214, + 31689,31128,30530,29897,29228,28525,27788,27017, + 26214,25379,24513,23617,22693,21740,20761,19755, + 18725,17672,16597,15501,14385,13251,12101,10935, + 9755,8563,7360,6148,4927,3701,2470,1235, + 0,-1235,-2470,-3701,-4927,-6148,-7360,-8563, + -9755,-10935,-12101,-13251,-14385,-15501,-16597,-17672, + -18725,-19755,-20761,-21740,-22693,-23617,-24513,-25379, + -26214,-27017,-27788,-28525,-29228,-29897,-30530,-31128, + -31689,-32214,-32702,-33153,-33566,-33941,-34279,-34579, + -34841,-35065,-35252,-35402,-35515,-35591,-35630,-35634, + -35602,-35535,-35434,-35299,-35131,-34931,-34699,-34437, + -34144,-33823,-33473,-33097,-32694,-32266,-31814,-31339, + -30842,-30325,-29787,-29231,-28658,-28068,-27464,-26845, + -26214,-25571,-24918,-24256,-23586,-22909,-22226,-21539, + -20848,-20155,-19461,-18767,-18074,-17382,-16694,-16009, + -15330,-14656,-13989,-13329,-12678,-12036,-11404,-10782, + -10172,-9573,-8987,-8415,-7856,-7310,-6780,-6264, + -5764,-5280,-4811,-4359,-3923,-3504,-3101,-2715, + -2346,-1994,-1659,-1341,-1040,-755,-487,-235, + 0,219,423,611,785,943,1087,1217, + 1334,1437,1527,1605,1670,1724,1767,1800, + 1822,1835,1838,1833,1820,1799,1771,1736, + 1695,1648,1596,1540,1479,1415,1347,1276, + 1203,1128,1051,973,894,815,736,656, + 578,500,423,347,274,202,132,65, + 0,-62,-121,-178,-232,-282,-329,-373, + -414,-451,-485,-515,-542,-565,-586,-602, + -616,-626,-633,-638,-639,-637,-633,-626, + -616,-604,-590,-574,-555,-535,-513,-490, + -465,-439,-412,-384,-356,-326,-296,-266, + -236,-205,-175,-144,-114,-85,-56,-27, + 0,26,52,77,101,124,145,166, + 185,202,219,233,247,259,269,278, + 286,292,297,300,302,302,301,299, + 296,291,286,279,271,262,252,242, + 231,218,206,193,179,165,150,135, + 120,105,89,74,59,44,29,14, + 0,-14,-27,-41,-53,-66,-77,-88, + -99,-109,-118,-126,-134,-141,-147,-152, + -157,-160,-163,-166,-167,-168,-168,-167 +}; class RDSProcessor : public BasebandProcessor { public: @@ -613,21 +684,20 @@ public: for (size_t i = 0; i= 9) { s = 0; if(sample_count >= SAMPLES_PER_BIT) { cur_bit = (shared_memory.rdsdata[(bit_pos / 26) & 15]>>(25-(bit_pos % 26))) & 1; prev_output = cur_output; cur_output = prev_output ^ cur_bit; - - inverting = (cur_output == 1); - float *src = waveform_biphase; + int32_t *src = waveform_biphase; int idx = in_sample_index; for(int j=0; j= SAMPLE_BUFFER_SIZE) idx = 0; } @@ -644,7 +714,8 @@ public: out_sample_index++; if (out_sample_index >= SAMPLE_BUFFER_SIZE) out_sample_index = 0; - switch(mphase) { + //AM @ 228k/4=57kHz + switch (mphase) { case 0: case 2: sample = 0; break; case 1: break; @@ -652,14 +723,14 @@ public: } mphase++; if (mphase >= 4) mphase = 0; - //sample *= 16; sample_count++; } else { s++; } - - frq = sample * 586 * 33; // / 8; + + //FM + frq = (sample>>16) * 386760; phase = (phase + frq); sphase = phase + (256<<16); @@ -672,21 +743,19 @@ public: } private: - int bit_pos; - float sample_buffer[SAMPLE_BUFFER_SIZE] = {0}; - float val; - int prev_output = 0; - int cur_output = 0; - int cur_bit = 0; + int8_t re, im; + uint8_t mphase, s; + uint32_t bit_pos; + int32_t sample_buffer[SAMPLE_BUFFER_SIZE] = {0}; + int32_t val; + uint8_t prev_output = 0; + uint8_t cur_output = 0; + uint8_t cur_bit = 0; int sample_count = SAMPLES_PER_BIT; - int inverting = 0; - int phase; - int in_sample_index = 0; - float sample; + int32_t sample; int out_sample_index = SAMPLE_BUFFER_SIZE-1; - int8_t s; - uint32_t sphase, mphase; + uint32_t phase, sphase; int32_t sig, frq, frq_im, rdsc; int32_t k; }; @@ -697,17 +766,6 @@ static BasebandConfiguration baseband_configuration; static baseband::Direction direction = baseband::Direction::Transmit; static WORKING_AREA(baseband_thread_wa, 8192); -/*static __attribute__((noreturn)) msg_t basebandrx_fn(void *arg) { - (void)arg; - chRegSetThreadName("baseband"); - - BasebandStatsCollector stats; - BasebandStatisticsMessage message; - - while(true) { - - } -}*/ static __attribute__((noreturn)) msg_t baseband_fn(void *arg) { (void)arg; @@ -718,7 +776,6 @@ static __attribute__((noreturn)) msg_t baseband_fn(void *arg) { while(true) { if (direction == baseband::Direction::Transmit) { - const auto buffer_tmp = baseband::dma::wait_for_tx_buffer(); const buffer_c8_t buffer { @@ -737,8 +794,7 @@ static __attribute__((noreturn)) msg_t baseband_fn(void *arg) { } } ); - } else if (direction == baseband::Direction::Receive) { - // TODO: Place correct sampling rate into buffer returned here: + } else { const auto buffer_tmp = baseband::dma::wait_for_rx_buffer(); const buffer_c8_t buffer { @@ -994,9 +1050,7 @@ int main(void) { /* TODO: Ensure DMAs are configured to point at first LLI in chain. */ - //if( direction == baseband::Direction::Receive ) { - rf::rssi::dma::allocate(4, 400); - //} + rf::rssi::dma::allocate(4, 400); touch::dma::allocate(); touch::dma::enable();