pico-WSPR-tx/main.c

163 wiersze
5.2 KiB
C
Czysty Zwykły widok Historia

///////////////////////////////////////////////////////////////////////////////
//
// Roman Piksaykin [piksaykin@gmail.com], R2BDY
// https://www.qrz.com/db/r2bdy
//
///////////////////////////////////////////////////////////////////////////////
//
//
2023-11-16 20:47:53 +00:00
// main.c - The project entry point.
//
// DESCRIPTION
2023-11-16 20:47:53 +00:00
// The pico-WSPR-tx project provides WSPR beacon function using only
// Pi Pico board. *NO* additional hardware such as freq.synth required.
2023-11-30 09:54:27 +00:00
// External GPS receiver is optional and serves a purpose of holding
// WSPR time window order and accurate frequancy drift compensation.
//
// HOWTOSTART
2023-11-30 09:54:27 +00:00
// ./build.sh; cp ./build/*.uf2 /media/Pico_Board/
//
// PLATFORM
// Raspberry Pi pico.
//
// REVISION HISTORY
// Rev 0.1 18 Nov 2023
2023-11-30 09:54:27 +00:00
// Rev 0.5 02 Dec 2023
//
2023-11-16 20:47:53 +00:00
// PROJECT PAGE
// https://github.com/RPiks/pico-WSPR-tx
//
2023-11-30 09:54:27 +00:00
// SUBMODULE PAGE
// https://github.com/RPiks/pico-hf-oscillator
//
// 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 <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "pico/multicore.h"
#include "pico-hf-oscillator/lib/assert.h"
#include "pico-hf-oscillator/defines.h"
2023-11-30 09:54:27 +00:00
#include <defines.h>
#include <piodco.h>
#include <WSPRbeacon.h>
2023-11-30 09:54:27 +00:00
#include <logutils.h>
#include <protos.h>
2023-12-10 18:33:38 +00:00
#define CONFIG_GPS_SOLUTION_IS_MANDATORY NO
#define CONFIG_GPS_RELY_ON_PAST_SOLUTION NO
#define CONFIG_SCHEDULE_SKIP_SLOT_COUNT 5
#define CONFIG_WSPR_DIAL_FREQUENCY 18106000UL //24926000UL // 28126000UL //7040000UL
2023-12-10 18:33:38 +00:00
#define CONFIG_CALLSIGN "R2BDY"
#define CONFIG_LOCATOR4 "KO85"
2023-11-28 00:10:01 +00:00
WSPRbeaconContext *pWSPR;
2023-11-14 14:33:55 +00:00
int main()
{
2023-11-28 00:10:01 +00:00
StampPrintf("\n");
sleep_ms(5000);
StampPrintf("R2BDY Pico-WSPR-tx start.");
2023-11-14 14:33:55 +00:00
InitPicoHW();
2023-11-28 21:06:38 +00:00
PioDco DCO = {0};
2023-11-28 00:10:01 +00:00
StampPrintf("WSPR beacon init...");
WSPRbeaconContext *pWB = WSPRbeaconInit(
2023-12-10 18:33:38 +00:00
CONFIG_CALLSIGN,/* the Callsign. */
CONFIG_LOCATOR4,/* the default QTH locator if GPS isn't used. */
12, /* Tx power, dbm. */
2023-11-28 00:10:01 +00:00
&DCO, /* the PioDCO object. */
2023-12-10 18:33:38 +00:00
CONFIG_WSPR_DIAL_FREQUENCY,
2023-11-28 00:10:01 +00:00
55UL, /* the carrier freq. shift relative to dial freq. */
2023-11-30 16:18:09 +00:00
RFOUT_PIN /* RF output GPIO pin. */
2023-11-28 00:10:01 +00:00
);
assert_(pWB);
pWSPR = pWB;
2023-11-28 21:06:38 +00:00
2023-12-10 18:33:38 +00:00
pWB->_txSched._u8_tx_GPS_mandatory = CONFIG_GPS_SOLUTION_IS_MANDATORY;
pWB->_txSched._u8_tx_GPS_past_time = CONFIG_GPS_RELY_ON_PAST_SOLUTION;
pWB->_txSched._u8_tx_slot_skip = CONFIG_SCHEDULE_SKIP_SLOT_COUNT;
2023-11-28 00:10:01 +00:00
multicore_launch_core1(Core1Entry);
2023-11-28 21:06:38 +00:00
StampPrintf("RF oscillator started.");
DCO._pGPStime = GPStimeInit(0, 9600, GPS_PPS_PIN);
assert_(DCO._pGPStime);
2023-11-28 00:10:01 +00:00
2023-11-29 17:08:07 +00:00
int tick = 0;
2023-11-28 00:10:01 +00:00
for(;;)
{
2023-12-10 18:33:38 +00:00
/*
if(WSPRbeaconIsGPSsolutionActive(pWB))
{
const char *pgps_qth = WSPRbeaconGetLastQTHLocator(pWB);
if(pgps_qth)
{
strncpy(pWB->_pu8_locator, pgps_qth, 4);
pWB->_pu8_locator[5] = 0x00;
}
}
2023-12-10 18:33:38 +00:00
*/
if(pWB->_txSched._u8_tx_GPS_mandatory)
{
WSPRbeaconTxScheduler(pWB, YES);
}
else
{
StampPrintf("Omitting GPS solution, start tx now.");
PioDCOStart(pWB->_pTX->_p_oscillator);
WSPRbeaconCreatePacket(pWB);
sleep_ms(100);
WSPRbeaconSendPacket(pWB);
StampPrintf("The system will be halted when tx is completed.");
for(;;)
{
if(!TxChannelPending(pWB->_pTX))
{
PioDCOStop(pWB->_pTX->_p_oscillator);
StampPrintf("System halted.");
}
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(500);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
}
}
2023-11-30 09:54:27 +00:00
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(100);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
2023-11-28 00:10:01 +00:00
2023-11-30 16:18:09 +00:00
#ifdef DEBUG
2023-11-30 09:54:27 +00:00
if(0 == ++tick % 60)
2023-11-29 17:08:07 +00:00
WSPRbeaconDumpContext(pWB);
2023-11-30 16:18:09 +00:00
#endif
2023-11-30 09:54:27 +00:00
sleep_ms(900);
2023-11-28 00:10:01 +00:00
}
2023-11-14 14:33:55 +00:00
}