Skip to content

Commit

Permalink
WIP: It creates an example WSPR packet using 3rd-party libs.
Browse files Browse the repository at this point in the history
  • Loading branch information
RPiks committed Nov 15, 2023
1 parent 5b10603 commit 6c5ad45
Show file tree
Hide file tree
Showing 16 changed files with 1,302 additions and 74 deletions.
53 changes: 0 additions & 53 deletions BitEmitter/bitemitter.c

This file was deleted.

13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,27 @@ add_executable(pico-wspr-tx)

target_sources(pico-wspr-tx PUBLIC
${CMAKE_CURRENT_LIST_DIR}/pico-hf-oscillator/lib/assert.c
${CMAKE_CURRENT_LIST_DIR}/BitEmitter/bitemitter.c
${CMAKE_CURRENT_LIST_DIR}/TxChannel/TxChannel.c
${CMAKE_CURRENT_LIST_DIR}/WSPRbeacon/thirdparty/WSPRutility.c
${CMAKE_CURRENT_LIST_DIR}/WSPRbeacon/thirdparty/nhash.c
${CMAKE_CURRENT_LIST_DIR}/WSPRbeacon/WSPRbeacon.c
${CMAKE_CURRENT_LIST_DIR}/debug/logutils.c
${CMAKE_CURRENT_LIST_DIR}/main.c
)

pico_set_program_name(pico-wspr-tx "pico-wspr-tx")
pico_set_program_version(pico-wspr-tx "0.1")

pico_enable_stdio_uart(pico-wspr-tx 1)
pico_enable_stdio_usb(pico-wspr-tx 0)
pico_enable_stdio_uart(pico-wspr-tx 0)
pico_enable_stdio_usb(pico-wspr-tx 1)

# Add the standard include files to the build
target_include_directories(pico-wspr-tx PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/pico-hf-oscillator/piodco
${CMAKE_CURRENT_LIST_DIR}/TxChannel
${CMAKE_CURRENT_LIST_DIR}/WSPRbeacon
${CMAKE_CURRENT_LIST_DIR}/WSPRbeacon/thirdparty
${CMAKE_CURRENT_LIST_DIR}/..
)

Expand Down
97 changes: 97 additions & 0 deletions TxChannel/TxChannel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
///////////////////////////////////////////////////////////////////////////////
//
// Roman Piksaykin [[email protected]], R2BDY
// https://www.qrz.com/db/r2bdy
//
///////////////////////////////////////////////////////////////////////////////
//
//
// TxChannel.c - Produces a time-accurate `bit` stream.
// Invokes a `modulator` function.
// DESCRIPTION
// Receives data asynchronously. Calls low level modulator function
// synchronously according to params.
//
// HOWTOSTART
// -
//
// PLATFORM
// Raspberry Pi pico.
//
// REVISION HISTORY
// -
//
// PROJECT PAGE
// https://github.com/RPiks/pico-WSPR-tx
//
// LICENCE
// MIT License (http://www.opensource.org/licenses/mit-license.php)
//
// Copyright (c) 2023 by Roman Piksaykin
//
// Permission is hereby granted, free of charge,to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction,including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////
#include "TxChannel.h"

TxChannelContext *pTX = NULL;

void __not_in_flash_func (TxChannelISR)(void)
{
if(!pTX)
{
pTX->_tm_future_call += 500LL;
goto EXIT;
}

pTX->_pf_modulator(FREQ_STEP_MILLIHERTZ, pTX->_u8byte_buffer[pTX->_ix_output++]);
pTX->_tm_future_call += pTX->_bit_period_us;

EXIT:
hw_clear_bits(&timer_hw->intr, 1U<<pTX->_timer_alarm_num);
timer_hw->alarm[pTX->_timer_alarm_num] = (uint32_t)pTX->_tm_future_call;
}

/// @brief Initializes a TxChannel context. Starts ISR.
/// @param bit_period_us Period of data bits, BPS speed = 1e6/bit_period_us.
/// @param timer_alarm_num Pico-specific hardware timer resource id.
/// @param pfmodulator Ptr to low level real-time modulator function.
/// @return the Context.
TxChannelContext *TxChannelInit(const uint32_t bit_period_us, uint8_t timer_alarm_num,
void *pfmodulator)
{
assert_(pfmodulator);
assert_(bit_period_us > 10);

TxChannelContext *p = calloc(1, sizeof(TxChannelContext));
assert_(p);

p->_bit_period_us = bit_period_us;
p->_timer_alarm_num = timer_alarm_num;
p->_pf_modulator = pfmodulator;

hw_set_bits(&timer_hw->inte, 1U << p->_timer_alarm_num);
irq_set_exclusive_handler(TIMER_IRQ_0, TxChannelISR);
irq_set_priority(TIMER_IRQ_0, 0x00);
irq_set_enabled(TIMER_IRQ_0, true);

p->_tm_future_call = timer_hw->timerawl + 500LL;
timer_hw->alarm[p->_timer_alarm_num] = (uint32_t)p->_tm_future_call;

return p;
}
32 changes: 17 additions & 15 deletions BitEmitter/bitemitter.h → TxChannel/TxChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
///////////////////////////////////////////////////////////////////////////////
//
//
// BitEmitter.h - Produces a time-accurate bit stream.
//
// TxChannel.h - Produces a time-accurate stream.
// Invokes a `modulator` function.
// DESCRIPTION
// Receives data asynchronously. Calls low level bit tx funcs synchronously
// in time according to params.
// Receives data asynchronously. Calls low level modulator function
// synchronously according to params.
//
// HOWTOSTART
// .
// -
//
// PLATFORM
// Raspberry Pi pico.
//
// REVISION HISTORY
//
// Rev 0.1 18 Nov 2023
// Initial release.
// -
//
// PROJECT PAGE
// https://github.com/RPiks/pico-WSPR-tx
//
// LICENCE
// MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down Expand Up @@ -55,24 +56,25 @@
#include "pico/stdlib.h"
#include "../pico-hf-oscillator/lib/assert.h"

#define FREQ_STEP_MILLIHERTZ 1465

typedef struct
{
uint64_t _tm_future_call;
uint32_t _bit_period_us;
uint8_t _bits_per_sample;

uint8_t _timer_alarm_num;

uint8_t _u8byte_buffer[256];
uint8_t _ix_input, _ix_output;
uint8_t _ixbit_output;

int (*_pf_modulator)(uint8_t bits_per_sample, uint8_t sample_val);
int (*_pf_modulator)(uint32_t frq_step, uint8_t shift_val);
int (*_pf_setPTT)(uint8_t bptt_state);

} BitEmitterContext;
} TxChannelContext;

BitEmitterContext *BitEmitterInit(const uint32_t bit_period_us, uint8_t timer_alarm_num,
uint8_t bits_per_sample, void *pfmodulator);
void __not_in_flash_func (BitEmitterISR)(void);
TxChannelContext *TxChannelInit(const uint32_t bit_period_us, uint8_t timer_alarm_num,
void *pfmodulator);
void __not_in_flash_func (TxChannelISR)(void);

#endif
32 changes: 32 additions & 0 deletions WSPRbeacon/WSPRbeacon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "WSPRbeacon.h"

#include <WSPRutility.h>

WSPRbeaconContext *WSPRbeaconInit(const char *pcallsign, const char *pgridsquare, int txpow_dbm,
void *pfsk4modulator)
{
WSPRbeaconContext *p = calloc(1, sizeof(WSPRbeaconContext));
assert_(p);

strncpy(p->_pu8_callsign, pcallsign, sizeof(p->_pu8_callsign));
strncpy(p->_pu8_locator, pgridsquare, sizeof(p->_pu8_locator));
p->_u8_txpower = txpow_dbm;

p->_pTX = TxChannelInit(682667, 0, pfsk4modulator);
assert_(p->_pTX);

return p;
}

void WSPRbeaconSetDialFreq(WSPRbeaconContext *pctx, uint32_t freq_hz)
{
assert_(pctx);
pctx->_u32_dialfreqhz = freq_hz;
}

int WSPRbeaconCreatePacket(WSPRbeaconContext *pctx)
{
assert_(pctx);

wspr_encode(pctx->_pu8_callsign, pctx->_pu8_locator, pctx->_u8_txpower, pctx->_pu8_outbuf);
}
29 changes: 29 additions & 0 deletions WSPRbeacon/WSPRbeacon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef WSPRBEACON_H_
#define WSPRBEACON_H_

#include <stdint.h>
#include <string.h>
#include <TxChannel.h>

typedef struct
{
uint8_t _pu8_callsign[12];
uint8_t _pu8_locator[7];
uint8_t _u8_txpower;

uint8_t _pu8_outbuf[256];

TxChannelContext *_pTX;
uint32_t _u32_dialfreqhz;

} WSPRbeaconContext;

WSPRbeaconContext *WSPRbeaconInit(const char *pcallsign, const char *pgridsquare, int txpow_dbm,
void *pfsk4modulator);
void WSPRbeaconSetDialFreq(WSPRbeaconContext *pctx, uint32_t freq_hz);
int WSPRbeaconCreatePacket(WSPRbeaconContext *pctx);
int WSPRbeaconSendPacket(const WSPRbeaconContext *pctx);

//int WSPRbeaconFSK4mod(uint8_t bits_per_sample, uint8_t sample_val);

#endif
Loading

0 comments on commit 6c5ad45

Please sign in to comment.