Merge branch 'master' of github.com:mobilinkd/tnc3b-firmware

fsk9600
Rob Riggs 2019-01-05 20:49:00 -06:00
commit 52bc72ca6c
3 zmienionych plików z 75 dodań i 57 usunięć

Wyświetl plik

@ -143,6 +143,7 @@ osStaticTimerDef_t beaconTimer4ControlBlock;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
int lost_power = 0;
int reset_requested = 0;
char serial_number[25];
char serial_number_64[17] = {0};
@ -182,6 +183,8 @@ void configure_gpio_for_stop(void) __attribute__((noinline));
void power_down_vdd(void);
void configure_wakeup_gpio(void);
void enable_debug_gpio(void);
void init_rtc_date_time(void);
void init_rtc_alarm(void);
/* USER CODE END PFP */
@ -517,8 +520,11 @@ int main(void)
if (HAL_OPAMP_Start(&hopamp1) != HAL_OK) Error_Handler();
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK) Error_Handler();
// Initialize the BM78 Bluetooth module the first time we boot.
if (!bm78_initialized()) bm78_initialize();
// Initialize the BM78 Bluetooth module and the RTC date/time the first time we boot.
if (!bm78_initialized()) {
bm78_initialize();
// init_rtc_date_time();
}
else bm78_wait_until_ready();
init_ioport();
@ -893,9 +899,6 @@ static void MX_RTC_Init(void)
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
RTC_AlarmTypeDef sAlarm;
/* USER CODE BEGIN RTC_Init 1 */
@ -916,51 +919,7 @@ static void MX_RTC_Init(void)
_Error_Handler(__FILE__, __LINE__);
}
/**Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x0;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0x0;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x0;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Enable the Alarm B
*/
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_B;
init_rtc_date_time();
}
/* TIM1 init function */
@ -1303,6 +1262,66 @@ int _write(int file, char *ptr, int len) {
}
#endif
void init_rtc_date_time()
{
if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0) return;
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/**Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x0;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
sTime.TimeFormat = RTC_HOURFORMAT_24;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
void init_rtc_alarm()
{
RTC_AlarmTypeDef sAlarm;
/**Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0x0;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x0;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Enable the Alarm B
*/
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_B;
}
/* USER CODE END 4 */
/* USER CODE BEGIN Header_StartDefaultTask */

Wyświetl plik

@ -26,7 +26,7 @@ int powerOffViaUSB(void)
namespace mobilinkd { namespace tnc { namespace kiss {
const char FIRMWARE_VERSION[] = "0.8.12";
const char FIRMWARE_VERSION[] = "0.8.13";
const char HARDWARE_VERSION[] = "Mobilinkd TNC3 2.1.1";
Hardware& settings()
@ -108,13 +108,11 @@ void reply16(uint8_t cmd, uint16_t result) {
}
inline void reply(uint8_t cmd, const uint8_t* data, uint16_t len) {
auto buffer = (uint8_t*) malloc(len + 1);
if (buffer == nullptr) return;
uint8_t* buffer = static_cast<uint8_t*>(alloca(len + 1));
buffer[0] = cmd;
for (uint16_t i = 0; i != len and data[i] != 0; i++)
for (uint16_t i = 0; i != len; i++)
buffer[i + 1] = data[i];
ioport->write(buffer, len + 1, 6, osWaitForever);
free(buffer);
}
inline void reply_ext(uint8_t ext, uint8_t cmd, const uint8_t* data, uint16_t len) {
@ -453,7 +451,7 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
DEBUG("GET_CAPABILITIES");
reply16(hardware::GET_CAPABILITIES,
hardware::CAP_EEPROM_SAVE|hardware::CAP_BATTERY_LEVEL|
hardware::CAP_ADJUST_INPUT);
hardware::CAP_ADJUST_INPUT|hardware::CAP_DFU_FIRMWARE);
break;
case hardware::GET_ALL_VALUES:
@ -486,7 +484,7 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
options & KISS_OPTION_PTT_SIMPLEX ? 0 : 1);
reply16(hardware::GET_CAPABILITIES,
hardware::CAP_EEPROM_SAVE|hardware::CAP_BATTERY_LEVEL|
hardware::CAP_ADJUST_INPUT);
hardware::CAP_ADJUST_INPUT|hardware::CAP_DFU_FIRMWARE);
reply16(hardware::GET_MIN_INPUT_GAIN, 0);
reply16(hardware::GET_MAX_INPUT_GAIN, 4);
reply8(hardware::GET_MIN_INPUT_TWIST, -3);

Wyświetl plik

@ -48,6 +48,7 @@ constexpr const uint16_t CAP_BT_PIN_CHANGE = 0x8000;
constexpr const uint16_t CAP_VERBOSE_ERROR = 0x0001;
constexpr const uint16_t CAP_EEPROM_SAVE = 0x0002;
constexpr const uint16_t CAP_ADJUST_INPUT = 0x0004; // Auto-adjust input levels.
constexpr const uint16_t CAP_DFU_FIRMWARE = 0x0008; // DFU firmware style.
constexpr const uint8_t SAVE = 0; // Save settings to EEPROM.
constexpr const uint8_t SET_OUTPUT_GAIN = 1;