rfdsatt: add uuid and reset command; print banner at startup

This commit is contained in:
Harald Welte 2021-03-28 16:46:53 +02:00
parent f26576f299
commit f58fda447e
1 changed files with 72 additions and 3 deletions

View File

@ -21,17 +21,22 @@
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/i2c.h>
#include <libopencm3/stm32/desig.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/scb.h>
#include <libopencm3/cm3/systick.h>
#include <libcommon/iob.h>
#include <libcommon/microvty.h>
#include <stdio.h>
#include <stdlib.h>
#include "attenuator.h"
#include "misc.h"
static uint32_t last_reset_cause;
extern const struct attenuator_cfg board_att_cfg;
extern struct attenuator_state *board_att_st[];
@ -50,6 +55,9 @@ void msleep(uint32_t delay)
} while (wake > jiffies);
}
/***********************************************************************
* hardware initialization
***********************************************************************/
static void clock_setup(void)
{
@ -134,18 +142,79 @@ static void gpio_setup(void)
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
}
/***********************************************************************
* uVTY interface
***********************************************************************/
DEFUN(reset, reset_cmd, "reset", "Reset the board")
{
scb_reset_system();
}
DEFUN(uuid, uuid_cmd, "uuid", "Get the unique ID")
{
char uuid[4*3+1];
desig_get_unique_id_as_string(uuid, sizeof(uuid));
printf("UUID: %s\r\n", uuid);
}
DEFUN(att_set, att_set_cmd, "attenuator-set",
"Set an attenuator (channel, stage, dB)")
{
int channel, stage, dB;
int rc;
if (argc < 3) {
printf("You muts specify three arguments (channel, stage, db)\r\n");
return;
}
channel = atoi(argv[1]);
stage = atoi(argv[2]);
dB = atoi(argv[3]);
printf("Setting attenuator channel %d stage %d to %d dB...\r\n", channel, stage, dB);
rc = attenuator_set(channel, stage, dB*4);
if (rc < 0)
printf("Error setting attenuator: %d\r\n", rc);
}
/***********************************************************************
* main
***********************************************************************/
static void print_banner(void)
{
char uuid[4*3+1];
desig_get_unique_id_as_string(uuid, sizeof(uuid));
printf("\r\n======================================================================\r\n");
//printf("sysmocom RFDSATT main (build %s)\r\n", BUILD_VERSION);
printf("UUID: %s\r\n", uuid);
printf("Reset cause(s): 0x%08lx\r\n", last_reset_cause);
printf("======================================================================\r\n\r\n");
}
int main(void)
{
/* get, store and clear the cause of the last reset */
last_reset_cause = RCC_CSR & RCC_CSR_RESET_FLAGS;
RCC_CSR |= RCC_CSR_RMVF;
clock_setup();
gpio_setup();
usart_setup();
iob_init(USART2);
i2c_setup();
attenuator_init(&board_att_cfg, board_att_st);
microvty_init("rfdsat4ch> ");
printf("Welcome to RFDSATT\r\n");
fprintf(stderr, "Welcome to stderr\r\n");
microvty_init("rfdsat4ch> ");
microvty_register(&reset_cmd);
microvty_register(&uuid_cmd);
microvty_register(&att_set_cmd);
print_banner();
microvty_print_prompt();
/* Blink the LED (PB15) on the board with every transmitted byte. */
while (1) {