Initial version semiworking but problem with cast uint16_t to int16

master
Lucjan Bryndza 2014-05-11 19:02:50 +02:00
rodzic a6c142c459
commit b0c7e3a205
3 zmienionych plików z 44 dodań i 8 usunięć

Wyświetl plik

@ -182,7 +182,7 @@ class trx_device_base //Add noncopyable
trx_device_base& operator=(const trx_device_base&) = delete; trx_device_base& operator=(const trx_device_base&) = delete;
static constexpr auto MAX_CODECS = 4; static constexpr auto MAX_CODECS = 4;
static constexpr auto FFT_UPDATE_TIME_MS = 250; //FFT update time in ms static constexpr auto FFT_UPDATE_TIME_MS = 250; //FFT update time in ms
static const auto TX_SAMPLE_RATE = 32000; static const auto TX_SAMPLE_RATE = 8000;
static const auto RX_SAMPLE_RATE = 8000; static const auto RX_SAMPLE_RATE = 8000;
public: public:
//Os specific locker //Os specific locker

Wyświetl plik

@ -22,17 +22,33 @@
#include <board/adc_audio.hpp> #include <board/adc_audio.hpp>
#include <board/dac_audio.hpp> #include <board/dac_audio.hpp>
#include <isix.h> #include <isix.h>
#include <foundation/dbglog.h>
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
namespace ham { namespace ham {
namespace psk { namespace psk {
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
//STM32 AD/AC device //STM32 AD/AC device
class stm32adac_device : public trx_device_base, isix::task_base { class stm32adac_device : public trx_device_base, isix::task_base {
static constexpr auto THREAD_STACK_SIZE = 1024;
static constexpr auto THREAD_PRIORITY = 2;
public: public:
static constexpr auto err_success = 0; static constexpr auto err_success = 0;
//! Constructor //! Constructor
stm32adac_device( handler_t evt_callback ) stm32adac_device( handler_t evt_callback )
: trx_device_base( evt_callback ) { : trx_device_base( evt_callback ) {
#if 0
//FIXME: Testonly sintab
static constexpr auto fo = 1000;
static constexpr auto calc = 32767;
static constexpr float pi = 4 * std::atan(1);
for( int n = 0; n < 256; ++n ) {
m_tbuf[n] = calc + calc * std::sin( float(fo) * ( 2.0f * pi ) * (float)n / float(8000) );
//m_buf[n] = (n*65535)/ns;
//m_buf[n] = (n%2)?65535:0;
dbprintf("V=%i", (int)m_tbuf[n] - (int)calc );
}
#endif
start_thread( THREAD_STACK_SIZE, THREAD_PRIORITY );
} }
//! Destructor //! Destructor
virtual ~stm32adac_device() { virtual ~stm32adac_device() {
@ -72,7 +88,9 @@ private:
isix::semaphore m_spectrum { 1, 1 }; //! Spectrum lock isix::semaphore m_spectrum { 1, 1 }; //! Spectrum lock
isix::semaphore m_busy { 1, 1 }; //! Busy notificator isix::semaphore m_busy { 1, 1 }; //! Busy notificator
isix::semaphore m_start { 0, 1 }; //! Start thread isix::semaphore m_start { 0, 1 }; //! Start thread
int m_thread_status {}; //! Thread error code volatile int m_thread_status {}; //! Thread error code
volatile bool m_thread_cont { false }; //! Break main loop
//uint16_t m_tbuf[sample_size]; //! Test buffer
}; };
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
} }

Wyświetl plik

@ -16,7 +16,7 @@
* ===================================================================================== * =====================================================================================
*/ */
#include "libpsk/port/isix/stm32adac_device.hpp" #include "libpsk/port/isix/stm32adac_device.hpp"
#include <foundation/dbglog.h>
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
namespace ham { namespace ham {
namespace psk { namespace psk {
@ -66,9 +66,11 @@ int stm32adac_device::setup_sound_hardware( trx_device_base::mode m )
} }
const int ret = enable_hw_rx(); const int ret = enable_hw_rx();
if( ret != 0 ) return ret; if( ret != 0 ) return ret;
dbprintf("Do receive processing");
} }
if( m == trx_device_base::mode::transmit && get_mode()!=trx_device_base::mode::transmit ) if( m == trx_device_base::mode::transmit && get_mode()!=trx_device_base::mode::transmit )
{ {
dbprintf("Do transmit processing");
if( get_mode()==trx_device_base::mode::on ) if( get_mode()==trx_device_base::mode::on )
{ {
const int ret = disable_hw_rx(); const int ret = disable_hw_rx();
@ -81,12 +83,16 @@ int stm32adac_device::setup_sound_hardware( trx_device_base::mode m )
if( get_mode()!=trx_device_base::mode::off && m == trx_device_base::mode::off ) if( get_mode()!=trx_device_base::mode::off && m == trx_device_base::mode::off )
{ {
//Disable and wait for stop //Disable and wait for stop
m_thread_cont = false;
join(); join();
dbprintf("Thread exited - terminate");
return m_thread_status; return m_thread_status;
} }
else if( get_mode()==trx_device_base::mode::off && m != trx_device_base::mode::off ) else if( get_mode()==trx_device_base::mode::off && m != trx_device_base::mode::off )
{ {
//! Restart the thread again //! Restart the thread again
dbprintf("Thread wakeup request");
m_thread_cont = true;
return m_start.signal(); return m_start.signal();
} }
return err_success; return err_success;
@ -102,10 +108,18 @@ void stm32adac_device::main()
m_thread_status = m_busy.wait( isix::ISIX_TIME_INFINITE ); m_thread_status = m_busy.wait( isix::ISIX_TIME_INFINITE );
if( m_thread_status < 0 ) break; if( m_thread_status < 0 ) break;
int errcode = 0; int errcode = 0;
for(;m_start.getval()>0 && !errcode ;) { dbprintf("Start procesing PSK");
for(; m_thread_cont && !errcode ;) {
lock( trx_device_base::lock_object );
if ( get_mode()==trx_device_base::mode::on ) errcode = receive_thread(); if ( get_mode()==trx_device_base::mode::on ) errcode = receive_thread();
else if( get_mode()==trx_device_base::mode::transmit ) errcode = transmit_thread(); else if( get_mode()==trx_device_base::mode::transmit ) errcode = transmit_thread();
else {
dbprintf("Unknown mode %i!", get_mode() );
break;
}
unlock( trx_device_base::lock_object );
} }
dbprintf("Stop procesing PSK reason getval: %i error: %i", m_start.getval(), errcode );
if( get_mode()==trx_device_base::mode::on ) { if( get_mode()==trx_device_base::mode::on ) {
//Disable sound receive //Disable sound receive
set_mode_off(); set_mode_off();
@ -130,9 +144,8 @@ int stm32adac_device::receive_thread()
if( ptr == nullptr ) { if( ptr == nullptr ) {
return m_adc_audio.errno(); return m_adc_audio.errno();
} }
lock( trx_device_base::lock_object );
adc_process( ptr, sample_size ); adc_process( ptr, sample_size );
unlock( trx_device_base::lock_object ); //dbprintf("RX process ptr %p", ptr );
return m_adc_audio.commit_buffer( reinterpret_cast<uint16_t*>(ptr) ); return m_adc_audio.commit_buffer( reinterpret_cast<uint16_t*>(ptr) );
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
@ -143,9 +156,14 @@ int stm32adac_device::transmit_thread()
if( !buf ) { if( !buf ) {
return m_dac_audio.errno(); return m_dac_audio.errno();
} }
lock( trx_device_base::lock_object );
auto status = dac_process( reinterpret_cast<int16_t*>(buf), sample_size ); auto status = dac_process( reinterpret_cast<int16_t*>(buf), sample_size );
unlock( trx_device_base::lock_object ); if( status == 0 ) {
for( size_t i = 0; i < sample_size; ++i ) {
reinterpret_cast<uint16_t*>(buf)[i] = int( reinterpret_cast<int16_t*>(buf)[i] ) + 32767;
}
}
// memcpy( buf, m_tbuf, sizeof m_tbuf );
//dbprintf("TX process ptr %p", buf );
auto cstatus = m_dac_audio.commit_buffer( buf ); auto cstatus = m_dac_audio.commit_buffer( buf );
if( cstatus) return cstatus; if( cstatus) return cstatus;
if( status) return status; if( status) return status;