You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/11/20 13:41:34 UTC

[GitHub] [mynewt-core] sjanc commented on a change in pull request #2413: STM32 RTC based os tick

sjanc commented on a change in pull request #2413:
URL: https://github.com/apache/mynewt-core/pull/2413#discussion_r527697145



##########
File path: hw/mcu/stm/stm32_common/src/hal_os_tick.c
##########
@@ -54,6 +55,315 @@ __WFI(void)
 #endif
 #endif
 
+#if MYNEWT_VAL(OS_TICKS_USE_RTC)
+
+#if MYNEWT_VAL(STM32_CLOCK_LSE) && (((32768 / OS_TICKS_PER_SEC) * OS_TICKS_PER_SEC) != 32768)
+#error OS_TICKS_PER_SEC should be divisible by power of 2 like 128, 256, 512, 1024 when OS_TICKS_USE_RTC is enabled.
+#endif
+
+#ifndef HAL_RTC_MODULE_ENABLED
+#error Define HAL_RTC_MODULE_ENABLED in stm32[fl][0-4]xx_hal_conf.h in your bsp
+#endif
+
+#define ASYNCH_PREDIV       7
+#define SYNCH_PREDIV        (32768 / (ASYNCH_PREDIV + 1) - 1)
+#define SUB_SECONDS_BITS    12
+
+#if defined(STM32L0) || defined(STM32F0)
+#define RTC_IRQ RTC_IRQn
+#else
+#define RTC_IRQ RTC_Alarm_IRQn
+#endif
+
+#if defined(STM32L0) || defined(STM32L1)
+#define IS_RTC_ENABLED (RCC->CSR & RCC_CSR_RTCEN)
+#else
+#define IS_RTC_ENABLED (RCC->BDCR & RCC_BDCR_RTCEN)
+#endif
+
+_Static_assert(SUB_SECONDS_BITS == __builtin_popcount(SYNCH_PREDIV), "SUB_SECONDS_BITS should be number of 1s in SYNCH_PREDIV");
+
+/* RTC time of the last tick. */
+static uint32_t last_rtc_time;
+static uint32_t sub_seconds_per_tick;
+static uint8_t sub_seconds_tick_bits;
+
+/* RTC holds UTC time. */
+static RTC_HandleTypeDef rtc = {
+    .Instance = RTC,
+    .Init = {
+        .HourFormat = RTC_HOURFORMAT_24,
+        .OutPut = RTC_OUTPUT_DISABLE,
+        .OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH,
+        .OutPutType = RTC_OUTPUT_TYPE_PUSHPULL,
+    }
+};
+
+/* RTC AlarmA used for OS ticks. */
+static RTC_AlarmTypeDef alarm = {
+    .AlarmTime = {
+        .Hours = 0,
+        .Minutes = 0,
+        .Seconds = 0,
+        .SubSeconds = 0,
+        .TimeFormat = RTC_HOURFORMAT12_AM,
+        .SecondFraction = 0,
+        .DayLightSaving = RTC_DAYLIGHTSAVING_NONE,
+        .StoreOperation = RTC_STOREOPERATION_RESET,
+    },
+    .AlarmMask = RTC_ALARMMASK_ALL,
+    .AlarmSubSecondMask = 0,
+    .Alarm = RTC_ALARM_A,
+};
+
+static uint32_t
+rtc_time_to_sub_seconds(const RTC_TimeTypeDef *time)
+{
+    int32_t sub_seconds;

Review comment:
       is this signed type on purpose?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org