2018-01-23 12:49:48 +00:00
|
|
|
/*
|
|
|
|
|
Aerospace Decoder - Copyright (C) 2018 Bob Anderson (VK2GJ)
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file portab.c
|
|
|
|
|
* @brief Application portability module code.
|
|
|
|
|
*
|
|
|
|
|
* @addtogroup application_portability
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-25 08:10:39 +00:00
|
|
|
#include "hal.h"
|
2018-03-01 13:34:09 +00:00
|
|
|
#include "chprintf.h"
|
2018-06-08 15:27:31 +00:00
|
|
|
#include "pkttypes.h"
|
2018-01-25 08:10:39 +00:00
|
|
|
#include "portab.h"
|
2018-04-19 14:12:25 +00:00
|
|
|
#include "usb.h"
|
2018-06-08 15:27:31 +00:00
|
|
|
#include "types.h"
|
2018-03-01 13:34:09 +00:00
|
|
|
#include <stdarg.h>
|
2018-01-23 12:49:48 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
/* Module local definitions. */
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
2018-06-08 15:27:31 +00:00
|
|
|
const radio_band_t band_2m = {
|
|
|
|
|
.start = BAND_MIN_2M_FREQ,
|
|
|
|
|
.end = BAND_MAX_2M_FREQ,
|
|
|
|
|
.step = BAND_STEP_2M_HZ,
|
|
|
|
|
.def_aprs = BAND_DEF_2M_APRS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const radio_band_t band_70cm = {
|
|
|
|
|
.start = BAND_MIN_70CM_FREQ,
|
|
|
|
|
.end = BAND_MAX_70CM_FREQ,
|
|
|
|
|
.step = BAND_STEP_70CM_HZ,
|
|
|
|
|
.def_aprs = BAND_DEF_70CM_APRS
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-23 12:49:48 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
/* Module exported variables. */
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
/* Module local types. */
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
/* Module local variables. */
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
/* Module local functions. */
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
/* Module exported functions. */
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
2018-06-08 15:27:31 +00:00
|
|
|
typedef struct SysProviders {
|
|
|
|
|
|
|
|
|
|
} providers_t;
|
|
|
|
|
|
|
|
|
|
const radio_param_t radio_list[NUM_PKT_RADIOS] = {
|
|
|
|
|
{ /* Radio #1 */
|
|
|
|
|
.unit = PKT_RADIO_1,
|
|
|
|
|
.type = SI4464,
|
|
|
|
|
.band = {
|
|
|
|
|
(radio_band_t * const)&band_2m,
|
|
|
|
|
NULL
|
|
|
|
|
}
|
|
|
|
|
} /* End radio1 */
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-01 13:34:09 +00:00
|
|
|
const SerialConfig debug_config = {
|
|
|
|
|
115200,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-25 08:10:39 +00:00
|
|
|
void pktConfigSerialDiag(void) {
|
|
|
|
|
/* USART3 TX. */
|
2018-03-01 13:34:09 +00:00
|
|
|
palSetLineMode(LINE_USART3_TX, PAL_MODE_ALTERNATE(7));
|
2018-01-25 08:10:39 +00:00
|
|
|
/* USART3 RX. */
|
2018-03-01 13:34:09 +00:00
|
|
|
palSetLineMode(LINE_USART3_RX, PAL_MODE_ALTERNATE(7));
|
2018-01-25 08:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pktConfigSerialPkt(void) {
|
2018-03-01 13:34:09 +00:00
|
|
|
|
2018-01-25 08:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-23 12:49:48 +00:00
|
|
|
void pktSetLineModeICU(void) {
|
2018-01-25 08:10:39 +00:00
|
|
|
palSetLineMode(LINE_ICU, PAL_MODE_INPUT | PAL_MODE_ALTERNATE(2));
|
2018-01-23 12:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 13:34:09 +00:00
|
|
|
void pktSerialStart(void) {
|
2018-04-29 15:14:36 +00:00
|
|
|
#if ENABLE_EXTERNAL_I2C == FALSE
|
2018-03-01 13:34:09 +00:00
|
|
|
pktConfigSerialDiag();
|
|
|
|
|
pktConfigSerialPkt();
|
|
|
|
|
sdStart(SERIAL_CFG_DEBUG_DRIVER, &debug_config);
|
2018-03-09 01:25:41 +00:00
|
|
|
#endif
|
2018-03-01 13:34:09 +00:00
|
|
|
/* Setup diagnostic resource access semaphore. */
|
2018-04-04 14:21:00 +00:00
|
|
|
extern binary_semaphore_t diag_out_sem;
|
|
|
|
|
chBSemObjectInit(&diag_out_sem, false);
|
2018-03-01 13:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len) {
|
|
|
|
|
(void)level;
|
2018-03-09 01:25:41 +00:00
|
|
|
#if ENABLE_EXTERNAL_I2C == FALSE
|
2018-03-01 13:34:09 +00:00
|
|
|
chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len);
|
2018-03-09 01:25:41 +00:00
|
|
|
#else
|
|
|
|
|
(void)buf;
|
|
|
|
|
(void)len;
|
|
|
|
|
#endif
|
2018-03-01 13:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dbgPrintf(uint8_t level, const char *format, ...) {
|
|
|
|
|
(void)level;
|
2018-03-09 01:25:41 +00:00
|
|
|
#if ENABLE_EXTERNAL_I2C == FALSE
|
2018-03-01 13:34:09 +00:00
|
|
|
va_list arg;
|
|
|
|
|
int done;
|
|
|
|
|
|
|
|
|
|
va_start(arg, format);
|
|
|
|
|
done = chprintf((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, format, arg);
|
|
|
|
|
va_end(arg);
|
|
|
|
|
|
|
|
|
|
return done;
|
2018-03-09 01:25:41 +00:00
|
|
|
#else
|
|
|
|
|
(void)format;
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
2018-03-01 13:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-08 15:27:31 +00:00
|
|
|
/*
|
|
|
|
|
* Read GPIO that are used for:
|
|
|
|
|
* a) general use or
|
|
|
|
|
* b) UART and s/w I2C external.
|
|
|
|
|
*
|
|
|
|
|
* @return State of lines regardless of general or specific use.
|
|
|
|
|
*/
|
|
|
|
|
uint8_t pktReadIOlines() {
|
|
|
|
|
return palReadLine(LINE_GPIO_PIN1)
|
|
|
|
|
| palReadLine(LINE_IO_TXD) << 1
|
|
|
|
|
| palReadLine(LINE_IO_RXD) << 2
|
|
|
|
|
| palReadLine(LINE_GPIO_PIN2);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 13:34:09 +00:00
|
|
|
void pktWrite(uint8_t *buf, uint32_t len) {
|
|
|
|
|
chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-14 14:41:23 +00:00
|
|
|
void pktPowerUpRadio(radio_unit_t radio) {
|
2018-03-29 12:23:12 +00:00
|
|
|
/* TODO: Implement hardware mapping. */
|
|
|
|
|
(void)radio;
|
2018-04-14 14:41:23 +00:00
|
|
|
/*
|
|
|
|
|
* NOTE: RADIO_CS and RADIO_SDN pins are configured in board.h
|
|
|
|
|
* RADIO_SDN is configured to open drain as it is pulled up on PCB by 100K.
|
|
|
|
|
* The radio powers up in SDN mode.
|
|
|
|
|
*
|
2018-04-20 00:20:50 +00:00
|
|
|
* CS is set as push-pull and initialized to HIGH.
|
2018-04-14 14:41:23 +00:00
|
|
|
*/
|
2018-03-01 13:34:09 +00:00
|
|
|
|
|
|
|
|
// Power up transceiver
|
|
|
|
|
palClearLine(LINE_RADIO_SDN); // Radio SDN low (power up transceiver)
|
|
|
|
|
chThdSleep(TIME_MS2I(10)); // Wait for transceiver to power up
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-14 14:41:23 +00:00
|
|
|
void pktPowerDownRadio(radio_unit_t radio) {
|
2018-03-29 12:23:12 +00:00
|
|
|
/* TODO: Implement hardware mapping. */
|
|
|
|
|
(void)radio;
|
2018-03-01 13:34:09 +00:00
|
|
|
|
2018-04-14 14:41:23 +00:00
|
|
|
/*
|
|
|
|
|
* Put radio in shutdown mode.
|
|
|
|
|
* All registers are lost.
|
|
|
|
|
*/
|
|
|
|
|
palSetLine(LINE_RADIO_SDN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sysConfigureCoreIO(void) {
|
|
|
|
|
/* Setup SPI3. */
|
|
|
|
|
palSetLineMode(LINE_SPI_SCK, PAL_MODE_ALTERNATE(6)
|
|
|
|
|
| PAL_STM32_OSPEED_HIGHEST); // SCK
|
|
|
|
|
palSetLineMode(LINE_SPI_MISO, PAL_MODE_ALTERNATE(6)
|
|
|
|
|
| PAL_STM32_OSPEED_HIGHEST); // MISO
|
|
|
|
|
palSetLineMode(LINE_SPI_MOSI, PAL_MODE_ALTERNATE(6)
|
|
|
|
|
| PAL_STM32_OSPEED_HIGHEST); // MOSI
|
|
|
|
|
|
|
|
|
|
/* Setup I2C1. */
|
|
|
|
|
palSetLineMode(LINE_I2C_SDA, PAL_MODE_ALTERNATE(4)
|
|
|
|
|
| PAL_STM32_OSPEED_HIGHEST
|
|
|
|
|
| PAL_STM32_OTYPE_OPENDRAIN); // SDA
|
|
|
|
|
palSetLineMode(LINE_I2C_SCL, PAL_MODE_ALTERNATE(4)
|
|
|
|
|
| PAL_STM32_OSPEED_HIGHEST
|
|
|
|
|
| PAL_STM32_OTYPE_OPENDRAIN); // SCL
|
2018-04-19 14:12:25 +00:00
|
|
|
|
|
|
|
|
#if ACTIVATE_USB
|
|
|
|
|
startUSB();
|
|
|
|
|
#endif
|
2018-03-01 13:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-08 15:27:31 +00:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
radio_freq_t pktCheckAllowedFrequency(radio_unit_t radio, radio_freq_t freq) {
|
|
|
|
|
/* Check validity. */
|
|
|
|
|
uint8_t radios = NUM_PKT_RADIOS/*sizeof(radio_list) / sizeof(radio_param_t)*/;
|
|
|
|
|
for(uint8_t i = 0; i < radios; i++) {
|
|
|
|
|
if(radio_list[i].unit != radio)
|
|
|
|
|
continue;
|
|
|
|
|
for(uint8_t x = 0; x < NUM_BANDS_PER_RADIO; x++) {
|
|
|
|
|
if(radio_list[i].band[x] == NULL)
|
|
|
|
|
/* No more bands in this radio. */
|
|
|
|
|
return FREQ_RADIO_INVALID;
|
|
|
|
|
if(radio_list[i].band[x]->start <= freq
|
|
|
|
|
&& freq < radio_list[i].band[x]->end)
|
|
|
|
|
return freq;
|
|
|
|
|
} /* End for bands */
|
|
|
|
|
} /* End for radios*/
|
|
|
|
|
return FREQ_RADIO_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 12:49:48 +00:00
|
|
|
/** @} */
|
2018-03-01 13:34:09 +00:00
|
|
|
|