2021-04-05 19:18:30 +00:00
|
|
|
/*
|
|
|
|
* uSDR.c
|
|
|
|
*
|
|
|
|
* Created: Mar 2021
|
|
|
|
* Author: Arjan te Marvelde
|
|
|
|
*
|
|
|
|
* The main loop of the application.
|
|
|
|
* This initializes the units that do the actual work, and then loops in the background.
|
|
|
|
* Other units are:
|
|
|
|
* - dsp.c, containing all signal processing in RX and TX branches. This part runs on the second processor core.
|
|
|
|
* - si5351.c, containing all controls for setting up the si5351 clock generator.
|
|
|
|
* - lcd.c, contains all functions to put something on the LCD
|
|
|
|
* - hmi.c, contains all functions that handle user inputs
|
|
|
|
*/
|
|
|
|
|
2021-04-03 19:39:24 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "pico/stdlib.h"
|
2021-11-24 12:33:08 +00:00
|
|
|
#include "pico/sem.h"
|
|
|
|
#include "hardware/i2c.h"
|
2021-04-12 20:21:40 +00:00
|
|
|
#include "hardware/gpio.h"
|
2021-04-03 19:39:24 +00:00
|
|
|
#include "hardware/timer.h"
|
|
|
|
#include "hardware/clocks.h"
|
|
|
|
|
2021-04-12 20:21:40 +00:00
|
|
|
#include "hmi.h"
|
2021-04-03 19:39:24 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "dsp.h"
|
|
|
|
#include "si5351.h"
|
2021-04-05 19:18:30 +00:00
|
|
|
#include "monitor.h"
|
2021-11-24 12:33:08 +00:00
|
|
|
#include "relay.h"
|
2021-04-03 19:39:24 +00:00
|
|
|
|
2021-11-24 12:33:08 +00:00
|
|
|
|
|
|
|
#define I2C0_SDA 16
|
|
|
|
#define I2C0_SCL 17
|
|
|
|
#define I2C1_SDA 18
|
|
|
|
#define I2C1_SCL 19
|
2021-04-03 19:39:24 +00:00
|
|
|
|
2021-04-08 20:32:27 +00:00
|
|
|
/*
|
|
|
|
* LED TIMER definition and callback routine
|
|
|
|
*/
|
2022-06-28 20:00:47 +00:00
|
|
|
#define LED_MS 1000
|
2021-04-03 19:39:24 +00:00
|
|
|
struct repeating_timer led_timer;
|
|
|
|
bool led_callback(struct repeating_timer *t)
|
|
|
|
{
|
|
|
|
static bool led_state;
|
|
|
|
|
|
|
|
gpio_put(PICO_DEFAULT_LED_PIN, led_state);
|
|
|
|
led_state = (led_state?false:true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-24 12:33:08 +00:00
|
|
|
/*
|
|
|
|
* Scheduler callback function.
|
|
|
|
* This executes every LOOP_MS.
|
|
|
|
*/
|
2022-06-28 20:00:47 +00:00
|
|
|
#define LOOP_MS 100
|
2021-11-24 12:33:08 +00:00
|
|
|
semaphore_t loop_sem;
|
|
|
|
struct repeating_timer loop_timer;
|
|
|
|
bool loop_callback(struct repeating_timer *t)
|
|
|
|
{
|
|
|
|
sem_release(&loop_sem);
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2021-04-03 19:39:24 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2022-06-28 20:00:47 +00:00
|
|
|
/*
|
|
|
|
* Optional: increase core voltage (normally 1.1V)
|
|
|
|
* Optional: overclock the CPU to 250MHz (normally 125MHz)
|
|
|
|
* Note that clk_peri (e.g. I2C) is derived from the SYS PLL
|
|
|
|
* Note that clk_adc sampling clock is derived from the 48MHz USB PLL.
|
|
|
|
*/
|
|
|
|
//vreg_set_voltage(VREG_VOLTAGE_1_25); sleep_ms(10);
|
|
|
|
//set_sys_clock_khz(250000, false); sleep_ms(10);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize LED pin output
|
|
|
|
*/
|
2021-04-03 19:39:24 +00:00
|
|
|
gpio_init(PICO_DEFAULT_LED_PIN);
|
|
|
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
2022-06-28 20:00:47 +00:00
|
|
|
gpio_put(PICO_DEFAULT_LED_PIN, true); // Set LED on
|
2021-11-24 12:33:08 +00:00
|
|
|
add_repeating_timer_ms(-LED_MS, led_callback, NULL, &led_timer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* i2c0 is used for the si5351 interface
|
|
|
|
* i2c1 is used for the LCD and all other interfaces
|
2022-06-28 20:00:47 +00:00
|
|
|
* if the display cannot keep up, try lowering the i2c1 frequency
|
2022-08-12 09:15:30 +00:00
|
|
|
* Do not invoke i2c using functions from interrupt handlers!
|
2021-11-24 12:33:08 +00:00
|
|
|
*/
|
2022-06-28 20:00:47 +00:00
|
|
|
i2c_init(i2c0, 400000); // i2c0 initialisation at 400Khz
|
2021-11-24 12:33:08 +00:00
|
|
|
gpio_set_function(I2C0_SDA, GPIO_FUNC_I2C);
|
|
|
|
gpio_set_function(I2C0_SCL, GPIO_FUNC_I2C);
|
|
|
|
gpio_pull_up(I2C0_SDA);
|
|
|
|
gpio_pull_up(I2C0_SCL);
|
2022-06-28 20:00:47 +00:00
|
|
|
i2c_init(i2c1, 100000); // i2c1 initialisation at 100Khz
|
2021-11-24 12:33:08 +00:00
|
|
|
gpio_set_function(I2C1_SDA, GPIO_FUNC_I2C);
|
|
|
|
gpio_set_function(I2C1_SCL, GPIO_FUNC_I2C);
|
|
|
|
gpio_pull_up(I2C1_SDA);
|
|
|
|
gpio_pull_up(I2C1_SCL);
|
2021-04-03 19:39:24 +00:00
|
|
|
|
2022-06-28 20:00:47 +00:00
|
|
|
/* Initialize the SW units */
|
|
|
|
mon_init(); // Monitor shell on stdio
|
|
|
|
si_init(); // VFO control unit
|
|
|
|
dsp_init(); // Signal processing unit
|
2021-11-27 15:54:40 +00:00
|
|
|
relay_init();
|
2022-06-28 20:00:47 +00:00
|
|
|
lcd_init(); // LCD output unit
|
|
|
|
hmi_init(); // HMI user inputs
|
2021-04-03 19:39:24 +00:00
|
|
|
|
2021-11-24 12:33:08 +00:00
|
|
|
/* A simple round-robin scheduler */
|
|
|
|
sem_init(&loop_sem, 1, 1) ;
|
|
|
|
add_repeating_timer_ms(-LOOP_MS, loop_callback, NULL, &loop_timer);
|
|
|
|
while (1)
|
2021-04-03 19:39:24 +00:00
|
|
|
{
|
2022-06-28 20:00:47 +00:00
|
|
|
sem_acquire_blocking(&loop_sem); // Wait until timer callback releases sem
|
2022-08-12 09:15:30 +00:00
|
|
|
hmi_evaluate(); // Refresh HMI (and VFO, BPF, etc)
|
2022-06-28 20:00:47 +00:00
|
|
|
mon_evaluate(); // Check monitor input
|
2021-04-03 19:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|