2021-03-27 22:31:32 +00:00
|
|
|
/*
|
2021-03-28 14:46:33 +00:00
|
|
|
* Main firmware program for the sysmocom rfdsatt-4ch (RF digital step attenuator; 4 channel)
|
2021-03-27 22:31:32 +00:00
|
|
|
*
|
2021-03-28 14:46:33 +00:00
|
|
|
* Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
|
2021-03-27 22:31:32 +00:00
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
2021-03-28 14:46:33 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2021-03-27 22:31:32 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2021-03-28 14:46:33 +00:00
|
|
|
* GNU General Public License for more details.
|
2021-03-27 22:31:32 +00:00
|
|
|
*
|
2021-03-28 14:46:33 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-03-27 22:31:32 +00:00
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libopencm3/stm32/rcc.h>
|
|
|
|
#include <libopencm3/stm32/gpio.h>
|
|
|
|
#include <libopencm3/stm32/usart.h>
|
2021-03-28 10:16:21 +00:00
|
|
|
#include <libopencm3/stm32/i2c.h>
|
2021-03-28 14:46:53 +00:00
|
|
|
#include <libopencm3/stm32/desig.h>
|
2021-03-28 10:16:21 +00:00
|
|
|
#include <libopencm3/cm3/nvic.h>
|
2021-03-28 14:46:53 +00:00
|
|
|
#include <libopencm3/cm3/scb.h>
|
2021-03-28 10:16:21 +00:00
|
|
|
#include <libopencm3/cm3/systick.h>
|
|
|
|
|
2021-04-11 14:24:33 +00:00
|
|
|
#include <librfn/time.h>
|
2021-05-05 20:37:28 +00:00
|
|
|
#include <librfn/util.h>
|
|
|
|
#include <librfn/fibre.h>
|
2021-04-11 14:24:33 +00:00
|
|
|
|
2021-03-28 12:58:57 +00:00
|
|
|
#include <libcommon/iob.h>
|
2021-05-05 20:37:28 +00:00
|
|
|
#include <libcommon/utils.h>
|
2021-03-28 13:32:31 +00:00
|
|
|
#include <libcommon/microvty.h>
|
2021-03-28 12:58:57 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2021-03-28 14:46:53 +00:00
|
|
|
#include <stdlib.h>
|
2021-03-28 12:58:57 +00:00
|
|
|
|
2021-03-28 10:16:21 +00:00
|
|
|
#include "attenuator.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2021-03-28 14:46:53 +00:00
|
|
|
static uint32_t last_reset_cause;
|
|
|
|
|
2021-03-28 12:58:57 +00:00
|
|
|
extern const struct attenuator_cfg board_att_cfg;
|
|
|
|
extern struct attenuator_state *board_att_st[];
|
|
|
|
|
2021-03-28 10:16:21 +00:00
|
|
|
/* busy wait specified number of ms */
|
|
|
|
void msleep(uint32_t delay)
|
|
|
|
{
|
2021-05-06 06:32:48 +00:00
|
|
|
uint32_t wake = time_now() + delay*1000;
|
2021-03-28 10:16:21 +00:00
|
|
|
do {
|
2021-04-11 14:24:33 +00:00
|
|
|
} while (wake > time_now());
|
2021-03-28 10:16:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 14:46:53 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* hardware initialization
|
|
|
|
***********************************************************************/
|
2021-03-27 22:31:32 +00:00
|
|
|
|
|
|
|
static void clock_setup(void)
|
|
|
|
{
|
2021-03-28 20:08:20 +00:00
|
|
|
rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_48MHZ]);
|
2021-03-28 10:16:21 +00:00
|
|
|
/* HCLK=48MHz; ADC=6MHz; APB1=24MHz; APB2=48MHz; USB=48MHz */
|
|
|
|
|
|
|
|
/* tick rate of 1ms */
|
2021-03-27 22:31:32 +00:00
|
|
|
|
|
|
|
/* Enable GPIOC clock. */
|
|
|
|
rcc_periph_clock_enable(RCC_GPIOA);
|
|
|
|
rcc_periph_clock_enable(RCC_GPIOB);
|
|
|
|
rcc_periph_clock_enable(RCC_GPIOC);
|
|
|
|
|
|
|
|
/* Enable clocks for USARTs */
|
|
|
|
rcc_periph_clock_enable(RCC_USART1);
|
|
|
|
rcc_periph_clock_enable(RCC_USART2);
|
|
|
|
}
|
|
|
|
|
2021-03-28 12:58:57 +00:00
|
|
|
static void i2c_setup(void)
|
|
|
|
{
|
|
|
|
rcc_periph_clock_enable(RCC_I2C1);
|
|
|
|
|
2021-03-28 16:38:26 +00:00
|
|
|
#ifdef STM32F1
|
2021-05-07 14:23:30 +00:00
|
|
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
2021-03-28 12:58:57 +00:00
|
|
|
GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,
|
2021-05-07 14:23:30 +00:00
|
|
|
GPIO_I2C1_RE_SCL | GPIO_I2C1_RE_SDA);
|
2021-03-28 16:38:26 +00:00
|
|
|
#else
|
|
|
|
gpio_set_af(GPIOB, GPIO_AF1, GPIO8 | GPIO9);
|
|
|
|
#endif
|
2021-03-28 12:58:57 +00:00
|
|
|
|
|
|
|
/* disable before making config changes */
|
|
|
|
i2c_peripheral_disable(I2C1);
|
|
|
|
|
2021-03-28 16:38:26 +00:00
|
|
|
#ifdef STM32F1
|
2021-03-28 12:58:57 +00:00
|
|
|
/* APB1 runs at 24 MHz */
|
2021-03-28 20:08:20 +00:00
|
|
|
i2c_set_clock_frequency(I2C1, 24);
|
2021-03-28 16:38:26 +00:00
|
|
|
#endif
|
2021-03-28 12:58:57 +00:00
|
|
|
|
|
|
|
/* 400 kHz fast mode I2C */
|
2021-03-28 16:38:26 +00:00
|
|
|
i2c_set_speed(I2C1, i2c_speed_fm_400k, 24);
|
2021-03-28 12:58:57 +00:00
|
|
|
|
|
|
|
//...
|
|
|
|
|
|
|
|
i2c_peripheral_enable(I2C1);
|
|
|
|
}
|
|
|
|
|
2021-03-27 22:31:32 +00:00
|
|
|
static void usart_setup(void)
|
|
|
|
{
|
2021-03-28 12:58:57 +00:00
|
|
|
/* USART1: connected to debug header */
|
|
|
|
|
2021-03-27 22:31:32 +00:00
|
|
|
/* Setup GPIO pin GPIO_USART1_TX. */
|
2021-03-28 16:38:26 +00:00
|
|
|
#ifdef STM32F1
|
2021-03-27 22:31:32 +00:00
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
2021-03-28 16:38:26 +00:00
|
|
|
#else
|
|
|
|
gpio_set_af(GPIOA, GPIO_AF1, GPIO9 | GPIO10);
|
|
|
|
#endif
|
2021-03-27 22:31:32 +00:00
|
|
|
/* Setup UART parameters. */
|
|
|
|
usart_set_baudrate(USART1, 115200);
|
|
|
|
usart_set_databits(USART1, 8);
|
|
|
|
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
2021-03-28 13:32:31 +00:00
|
|
|
usart_set_mode(USART1, USART_MODE_TX_RX);
|
2021-03-27 22:31:32 +00:00
|
|
|
usart_set_parity(USART1, USART_PARITY_NONE);
|
|
|
|
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
|
|
|
/* Finally enable the USART. */
|
|
|
|
usart_enable(USART1);
|
|
|
|
|
2021-03-28 12:58:57 +00:00
|
|
|
/* USART2: connected to 2.5mm stereo jack */
|
|
|
|
|
2021-03-27 22:31:32 +00:00
|
|
|
/* Setup GPIO pin GPIO_USART2_TX. */
|
2021-03-28 16:38:26 +00:00
|
|
|
#ifdef STM32F1
|
2021-03-27 22:31:32 +00:00
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
2021-03-28 16:38:26 +00:00
|
|
|
#else
|
|
|
|
gpio_set_af(GPIOA, GPIO_AF1, GPIO2 | GPIO13);
|
|
|
|
#endif
|
2021-03-27 22:31:32 +00:00
|
|
|
/* Setup UART parameters. */
|
|
|
|
usart_set_baudrate(USART2, 115200);
|
|
|
|
usart_set_databits(USART2, 8);
|
|
|
|
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
2021-03-28 13:32:31 +00:00
|
|
|
usart_set_mode(USART2, USART_MODE_TX_RX);
|
2021-03-27 22:31:32 +00:00
|
|
|
usart_set_parity(USART2, USART_PARITY_NONE);
|
|
|
|
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
|
|
|
/* Finally enable the USART. */
|
|
|
|
usart_enable(USART2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gpio_setup(void)
|
|
|
|
{
|
2021-03-28 16:38:26 +00:00
|
|
|
#ifdef STM32F1
|
2021-04-13 16:42:14 +00:00
|
|
|
/* disable JTAG, keep SWJ-DP (we use some related GPIOs) */
|
|
|
|
rcc_periph_clock_enable(RCC_AFIO);
|
2021-05-07 14:23:30 +00:00
|
|
|
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, AFIO_MAPR_PD01_REMAP | AFIO_MAPR_I2C1_REMAP);
|
2021-04-13 16:42:14 +00:00
|
|
|
|
|
|
|
/* Set GPIO15 (in GPIO port B) to 'output push-pull' for the LED. */
|
2021-03-27 22:31:32 +00:00
|
|
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
2021-03-28 16:38:26 +00:00
|
|
|
#else
|
|
|
|
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO15);
|
|
|
|
#endif
|
2021-03-27 22:31:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 14:46:53 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* uVTY interface
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
DEFUN(reset, reset_cmd, "reset", "Reset the board")
|
|
|
|
{
|
|
|
|
scb_reset_system();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(uuid, uuid_cmd, "uuid", "Get the unique ID")
|
|
|
|
{
|
2021-03-28 16:06:59 +00:00
|
|
|
char uuid[4*3*2+1];
|
2021-03-28 14:46:53 +00:00
|
|
|
desig_get_unique_id_as_string(uuid, sizeof(uuid));
|
|
|
|
printf("UUID: %s\r\n", uuid);
|
|
|
|
}
|
|
|
|
|
2021-03-28 14:53:54 +00:00
|
|
|
DEFUN(version, version_cmd, "version", "Get the firmware version")
|
|
|
|
{
|
|
|
|
printf("Firmware Version: %s\r\n", GIT_VERSION);
|
|
|
|
}
|
|
|
|
|
2021-05-05 20:39:56 +00:00
|
|
|
DEFUN(att_show, att_show_cmd, "show", "Show state of all attenuators")
|
2021-05-05 20:38:41 +00:00
|
|
|
{
|
|
|
|
unsigned int channel;
|
|
|
|
|
2021-05-07 07:05:41 +00:00
|
|
|
for (channel = 1; channel <= board_att_cfg.num_channels; channel++) {
|
|
|
|
unsigned int stage_idx;
|
2021-05-05 20:38:41 +00:00
|
|
|
int stage_qdb[2];
|
|
|
|
int sum_qdb = 0;
|
|
|
|
|
2021-05-07 07:05:41 +00:00
|
|
|
for (stage_idx = 0; stage_idx < ARRAY_SIZE(stage_qdb); stage_idx++) {
|
|
|
|
stage_qdb[stage_idx] = attenuator_stage_get(channel, stage_idx+1, ATT_VAL_CURRENT);
|
|
|
|
sum_qdb += stage_qdb[stage_idx];
|
2021-05-05 20:38:41 +00:00
|
|
|
}
|
|
|
|
printf("Channel %02u: Stage1 %02d dB, Stage2 %02d dB, Sum %02d dB\r\n",
|
|
|
|
channel, stage_qdb[0]/4, stage_qdb[1]/4, sum_qdb/4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 20:39:56 +00:00
|
|
|
DEFUN(att_set, att_set_cmd, "set",
|
2021-03-28 14:46:53 +00:00
|
|
|
"Set an attenuator (channel, stage, dB)")
|
|
|
|
{
|
|
|
|
int channel, stage, dB;
|
|
|
|
int rc;
|
|
|
|
|
2021-05-07 07:05:41 +00:00
|
|
|
if (argc < 3 || argc > 4) {
|
|
|
|
printf("You must specify two (channel, dB) or three arguments (channel, stage, db)\r\n");
|
2021-03-28 14:46:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-07 07:05:41 +00:00
|
|
|
switch (argc) {
|
|
|
|
case 3:
|
|
|
|
channel = atoi(argv[1]);
|
|
|
|
dB = atoi(argv[2]);
|
|
|
|
rc = attenuator_chan_set(channel, dB*4, true);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
channel = atoi(argv[1]);
|
|
|
|
stage = atoi(argv[2]);
|
|
|
|
dB = atoi(argv[3]);
|
|
|
|
rc = attenuator_stage_set(channel, stage, dB*4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("You must specify two (channel, dB) or three arguments (channel, stage, db)\r\n");
|
|
|
|
break;
|
|
|
|
}
|
2021-03-28 14:46:53 +00:00
|
|
|
|
|
|
|
if (rc < 0)
|
2021-05-07 07:05:41 +00:00
|
|
|
printf("Error setting attenuator %d: %d\r\n", channel, rc);
|
2021-03-28 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 20:57:48 +00:00
|
|
|
|
|
|
|
DEFUN(interact, interact_cmd, "interact", "Enter interactive single-key mode")
|
|
|
|
{
|
2021-05-07 07:05:41 +00:00
|
|
|
uint8_t g_chan = 1;
|
|
|
|
uint8_t g_stage = 1;
|
2021-05-05 20:57:48 +00:00
|
|
|
uint8_t g_val = 0;
|
|
|
|
|
2021-05-07 10:28:30 +00:00
|
|
|
printf("Entering interactive single-key mode. Press 'X' for exit, '?' for help\r\n");
|
2021-05-05 20:57:48 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int ch, rc;
|
|
|
|
/* read one blocking char */
|
|
|
|
do {
|
|
|
|
ch = getchar();
|
|
|
|
} while (ch == EOF);
|
|
|
|
|
|
|
|
switch (ch) {
|
2021-05-07 10:28:30 +00:00
|
|
|
case '?':
|
|
|
|
printf( "'1'..'4': Select channel\r\n"
|
|
|
|
"'0' : Set attenuation of current channel+stage to 0 dB\r\n"
|
|
|
|
"'f' : Set attenuation of current channel+stage to 31 dB\r\n"
|
|
|
|
"'+'/'-' : Increment/decrement attenuation in dB\r\n"
|
|
|
|
"'a'/'b' : Select stage 1/2 within channel\r\n"
|
|
|
|
"'X' : Exit interactive mode\r\n"
|
|
|
|
);
|
|
|
|
break;
|
2021-05-05 20:57:48 +00:00
|
|
|
case 'X': /* exit */
|
|
|
|
return;
|
|
|
|
case '1': case '2': case '3': case '4': /* channel number */
|
2021-05-07 07:05:41 +00:00
|
|
|
g_chan = ch - '0';
|
|
|
|
g_stage = 1;
|
2021-05-06 06:20:03 +00:00
|
|
|
g_val = attenuator_stage_get(g_chan, g_stage, ATT_VAL_CURRENT);
|
2021-05-05 20:57:48 +00:00
|
|
|
break;
|
|
|
|
case '0': /* set to 0dB */
|
|
|
|
g_val = 0;
|
|
|
|
break;
|
|
|
|
case 'f': /* set to full attenuation */
|
|
|
|
g_val = 31;
|
|
|
|
break;
|
|
|
|
case '+': /* increment by 1dB */
|
|
|
|
if (g_val < 31)
|
|
|
|
g_val++;
|
|
|
|
break;
|
|
|
|
case '-': /* decrement by 1dB */
|
|
|
|
if (g_val > 0)
|
|
|
|
g_val--;
|
|
|
|
break;
|
2021-05-07 07:05:41 +00:00
|
|
|
case 'a': /* stage 1 */
|
|
|
|
if (g_stage != 1) {
|
|
|
|
g_stage = 1;
|
2021-05-06 06:20:03 +00:00
|
|
|
g_val = attenuator_stage_get(g_chan, g_stage, ATT_VAL_CURRENT);
|
2021-05-05 20:57:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-05-07 07:05:41 +00:00
|
|
|
case 'b': /* stage 2 */
|
|
|
|
if (g_stage != 2) {
|
|
|
|
g_stage = 2;
|
2021-05-06 06:20:03 +00:00
|
|
|
g_val = attenuator_stage_get(g_chan, g_stage, ATT_VAL_CURRENT);
|
2021-05-05 20:57:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-05-06 06:20:03 +00:00
|
|
|
rc = attenuator_stage_set(g_chan, g_stage, g_val*4);
|
2021-05-05 20:57:48 +00:00
|
|
|
if (rc < 0)
|
|
|
|
printf("Error setting attenuator: %d\r\n", rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-06 06:33:01 +00:00
|
|
|
DEFUN(test, test_cmd, "test", "Enter interactive test-ramp mode")
|
|
|
|
{
|
2021-05-07 07:05:41 +00:00
|
|
|
uint8_t g_chan = 1;
|
2021-05-06 06:33:01 +00:00
|
|
|
uint8_t g_val = 0;
|
|
|
|
|
2021-05-07 10:28:30 +00:00
|
|
|
printf("Interactive test-ramp mode. Press 'X' for exit, '?' for help\r\n");
|
2021-05-06 06:33:01 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int ch, rc;
|
|
|
|
if ((ch = getchar()) != EOF) {
|
|
|
|
switch (ch) {
|
2021-05-07 10:28:30 +00:00
|
|
|
case '?':
|
|
|
|
printf( "'1'..'4': Select channel\r\n"
|
|
|
|
"'0' : Set attenuation of current channel to 0 dB\r\n"
|
|
|
|
"'a'/'b' : Select stage 1/2 within channel\r\n"
|
|
|
|
"'X' : Exit interactive test-ramp mode\r\n"
|
|
|
|
);
|
|
|
|
break;
|
2021-05-06 06:33:01 +00:00
|
|
|
case 'X': /* exit */
|
|
|
|
return;
|
|
|
|
case '1': case '2': case '3': case '4': /* channel number */
|
2021-05-07 07:05:41 +00:00
|
|
|
g_chan = ch - '0';
|
2021-05-06 06:33:01 +00:00
|
|
|
g_val = 0;
|
|
|
|
break;
|
|
|
|
case '0': /* set to 0dB */
|
|
|
|
g_val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g_val < 60)
|
|
|
|
g_val += 10;
|
|
|
|
else
|
|
|
|
g_val = 0;
|
|
|
|
|
|
|
|
rc = attenuator_chan_set(g_chan, g_val*4, false);
|
|
|
|
if (rc < 0)
|
|
|
|
printf("Error setting attenuator: %d\r\n", rc);
|
|
|
|
|
|
|
|
msleep(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 20:57:48 +00:00
|
|
|
|
2021-03-28 14:46:53 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* main
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
static void print_banner(void)
|
|
|
|
{
|
2021-03-28 16:06:59 +00:00
|
|
|
char uuid[4*3*2+1];
|
2021-03-28 14:46:53 +00:00
|
|
|
desig_get_unique_id_as_string(uuid, sizeof(uuid));
|
|
|
|
|
|
|
|
printf("\r\n======================================================================\r\n");
|
2021-03-28 14:53:54 +00:00
|
|
|
printf("sysmocom RFDSATT main (build %s)\r\n", GIT_VERSION);
|
2021-03-28 14:46:53 +00:00
|
|
|
printf("UUID: %s\r\n", uuid);
|
|
|
|
printf("Reset cause(s): 0x%08lx\r\n", last_reset_cause);
|
|
|
|
printf("======================================================================\r\n\r\n");
|
|
|
|
}
|
|
|
|
|
2021-05-05 20:37:28 +00:00
|
|
|
typedef struct {
|
|
|
|
uint32_t time;
|
|
|
|
fibre_t fibre;
|
|
|
|
} led_fibre_t;
|
|
|
|
|
|
|
|
int led_fibre(fibre_t *fibre)
|
|
|
|
{
|
|
|
|
led_fibre_t *led = containerof(fibre, led_fibre_t, fibre);
|
|
|
|
|
|
|
|
PT_BEGIN_FIBRE(fibre);
|
|
|
|
|
|
|
|
led->time = time_now();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
led->time += 500000;
|
|
|
|
PT_WAIT_UNTIL(fibre_timeout(led->time));
|
|
|
|
gpio_toggle(GPIOB, GPIO15); /* LED on/off */
|
|
|
|
}
|
|
|
|
|
|
|
|
PT_END();
|
|
|
|
}
|
|
|
|
|
|
|
|
led_fibre_t led = {
|
|
|
|
.fibre = FIBRE_VAR_INIT(led_fibre)
|
|
|
|
};
|
|
|
|
|
|
|
|
extern fibre_t microvty_fibre;
|
|
|
|
|
2021-03-27 22:31:32 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2021-03-28 14:46:53 +00:00
|
|
|
/* get, store and clear the cause of the last reset */
|
|
|
|
last_reset_cause = RCC_CSR & RCC_CSR_RESET_FLAGS;
|
|
|
|
RCC_CSR |= RCC_CSR_RMVF;
|
|
|
|
|
2021-03-27 22:31:32 +00:00
|
|
|
clock_setup();
|
|
|
|
gpio_setup();
|
|
|
|
usart_setup();
|
2021-03-28 12:58:57 +00:00
|
|
|
iob_init(USART2);
|
|
|
|
i2c_setup();
|
2021-05-05 20:37:28 +00:00
|
|
|
time_init();
|
2021-03-28 12:58:57 +00:00
|
|
|
attenuator_init(&board_att_cfg, board_att_st);
|
2021-03-28 14:46:53 +00:00
|
|
|
|
2021-03-28 13:32:31 +00:00
|
|
|
microvty_init("rfdsat4ch> ");
|
2021-03-28 14:46:53 +00:00
|
|
|
microvty_register(&reset_cmd);
|
|
|
|
microvty_register(&uuid_cmd);
|
2021-03-28 14:53:54 +00:00
|
|
|
microvty_register(&version_cmd);
|
2021-05-05 20:38:41 +00:00
|
|
|
microvty_register(&att_show_cmd);
|
2021-03-28 14:46:53 +00:00
|
|
|
microvty_register(&att_set_cmd);
|
2021-05-05 20:57:48 +00:00
|
|
|
microvty_register(&interact_cmd);
|
2021-05-06 06:33:01 +00:00
|
|
|
microvty_register(&test_cmd);
|
2021-03-28 13:32:31 +00:00
|
|
|
|
2021-03-28 14:46:53 +00:00
|
|
|
print_banner();
|
|
|
|
microvty_print_prompt();
|
2021-03-27 22:31:32 +00:00
|
|
|
|
2021-05-05 20:37:28 +00:00
|
|
|
fibre_run(&led.fibre);
|
|
|
|
fibre_run(µvty_fibre);
|
|
|
|
|
|
|
|
fibre_scheduler_main_loop();
|
2021-03-27 22:31:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|