OneOS driver-RTC

OneOS driver RTC

1 Introduction

RTC (Real-Time Clock) real-time clock can provide accurate real-time time, and it can be used to generate year, month, day, hour, minute, second and other information. At present, most real-time clock chips use crystal oscillators with high precision as the clock source. In order to work even when the main power supply fails, some clock chips will be powered by an external battery to keep the time information valid.

2. RTC device registration

Take stm32l475-atk-pandora as an example.

2.1. os_driver_info_t and os_device_info_t structure creation

  1. os_driver_info_t

Location: drivers\hal\st\drivers\drv_rtc.c

OS_DRIVER_INFO: Register the structure os_driver_info_t to the "driver_table" section;

OS_DRIVER_DEFINE: Register the initialization function called when the system starts to initialize.

  1. os_device_info_t

Location: templates\stm32l475-atk-pandora\board\peripherals.c

OS_HAL_DEVICE_DEFINE registration structure os_device_info_t to "device_table" section

2.2.RTC_HandleTypeDef structure (hrtc)

  1. Structure definition

drivers\hal\st\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Inc\stm32l4xx_hal_rtc.h

 

  1. Structure initialization
  1. MX_RTC_Init function

位置:templates\stm32l475-atk-pandora\board\CubeMX_Config\Src\main.c

Initialize the Instance and Init members.

As can be seen from the figure above, the Instance member is assigned the RTC macro. RTC macro definition and RTC_TypeDef structure are defined as follows. The macro RTC is defined as the base address of the RTC register, which points to the RTC_TypeDef structure. The members of the structure are all 32-bit registers, which are registers related to time and date. As long as you know the base address of the structure, that is, RTC_BASE in the figure below, you can access the register members in it, so that you can perform operations such as obtaining and setting time and date.

 

位置:st\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Include\stm32l475xx.h

 

(2) Other initialization functions

位置:drivers\hal\st\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rtc.c

HAL_RTC_Init and HAL_RTC_DeInit functions: mainly assign values ​​to the function pointer members in the structure;

HAL_RTC_RegisterCallback and HAL_RTC_UnRegisterCallback functions: also assign values ​​to the function pointer members in the structure.

 

3. Registration function

Device driver layer probe function:

Note: The operation interface has only one os_rtc_control interface.

Structure stm32_rtc

Note that the above probe function directly calls os_device_register, that is, there is no device framework layer, and it is directly registered to the device management layer

Although not registered to the device framework layer, there is still drivers\rtc\rtc.c . Normally rtc.c is the device framework layer, but it is different here. It did not reach this layer during registration, and the user call also starts from rtc.c, not from the device management layer. Access to the RTC device starts directly from the interface in rtc.c, and the interface of the device management layer is called in the interface in rtc.c. See the Device Access section below for details.

4. RTC device access

Location: drivers\rtc\rtc.c

In addition, there are two interfaces, set_date and set_time, through which the user can set the date and time by calling the rtc_get and rtc_set interfaces.

 

The execution flow of the rtc_get structure.

 

rtc.c

rtc_get

device.c

os_device_open_s

os_device_control

drv_rtc.c

os_rtc_control

stm32_rtc_get_timestamp

device.c

os_device_close

 

The RTC_HandleTypeDef structure hrtc contains the RTC register base address member, which was mentioned in the previous content. Then use the HAL_RTC_GetTime and HAL_RTC_GetDate interfaces to access the registers to obtain the time and date.

Graduates of the National People’s University stole the information of all students in the school to build a beauty scoring website, and have been criminally detained. The new Windows version of QQ based on the NT architecture is officially released. The United States will restrict China’s use of Amazon, Microsoft and other cloud services that provide training AI models . Open source projects announced to stop function development LeaferJS , the highest-paid technical position in 2023, released: Visual Studio Code 1.80, an open source and powerful 2D graphics library , supports terminal image functions . The number of Threads registrations has exceeded 30 million. "Change" deepin adopts Asahi Linux to adapt to Apple M1 database ranking in July: Oracle surges, opening up the score again
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/5443273/blog/10086160