support rtc and deep sleep for ru-d01-m200
This commit is contained in:
parent
8cbe613075
commit
fb4eb87659
|
@ -42,6 +42,53 @@ int main(void)
|
|||
webserver();
|
||||
#endif
|
||||
|
||||
int pin_fd = PrivOpen("/dev/pin_dev", O_RDWR);
|
||||
if(pin_fd < 0) {
|
||||
printf("open pin fd error:%d\n",pin_fd);
|
||||
return pin_fd;
|
||||
}
|
||||
|
||||
//config led pin in board
|
||||
struct PinStat pin_led;
|
||||
pin_led.pin = 57;
|
||||
// pin_led.pin = 8;
|
||||
struct PinParam parameter;
|
||||
parameter.cmd = GPIO_CONFIG_MODE;
|
||||
parameter.pin = pin_led.pin;
|
||||
parameter.mode = GPIO_CFG_OUTPUT;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||
ioctl_cfg.args = (void *)¶meter;
|
||||
|
||||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
printf("ioctl pin fd error %d\n", pin_fd);
|
||||
PrivClose(pin_fd);
|
||||
return pin_fd;
|
||||
}
|
||||
|
||||
PrivTaskDelay(20);
|
||||
int counter = 0;
|
||||
while(1){
|
||||
printf("counter:%d\n",counter++);
|
||||
pin_led.val = GPIO_HIGH;
|
||||
if(0 > PrivWrite(pin_fd, &pin_led, NULL_PARAMETER)) {
|
||||
printf("write pin fd error %d\n", pin_fd);
|
||||
PrivClose(pin_fd);
|
||||
return pin_fd;
|
||||
}
|
||||
PrivTaskDelay(20);
|
||||
|
||||
pin_led.val = GPIO_LOW;
|
||||
if(0 > PrivWrite(pin_fd, &pin_led, NULL_PARAMETER)) {
|
||||
printf("write pin fd error %d\n", pin_fd);
|
||||
PrivClose(pin_fd);
|
||||
return pin_fd;
|
||||
}
|
||||
PrivTaskDelay(4980);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
// int cppmain(void);
|
||||
|
|
|
@ -85,11 +85,11 @@ g_pfnVectors:
|
|||
.word DebugMon_Handler
|
||||
.word 0
|
||||
.word PendSV_Handler
|
||||
.word SysTick_Handler
|
||||
.word IsrEntry /* SysTick_Handler */
|
||||
.word WWDG_IRQHandler
|
||||
.word PVD_PVM_IRQHandler
|
||||
.word TAMP_STAMP_IRQHandler
|
||||
.word RTC_WKUP_IRQHandler
|
||||
.word IsrEntry
|
||||
.word FLASH_IRQHandler
|
||||
.word RCC_IRQHandler
|
||||
.word EXTI0_IRQHandler
|
||||
|
|
|
@ -411,4 +411,6 @@ __attribute__((weak)) void HwCpuReset(void)
|
|||
{
|
||||
SCB_AIRCR = SCB_RESET_VALUE;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), Reboot, HwCpuReset, reset machine );
|
||||
#ifdef TOOL_SHELL
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), Reboot, HwCpuReset, reset machine );
|
||||
#endif
|
|
@ -29,7 +29,7 @@ void SysTick_Handler(void)
|
|||
isrManager.done->incCounter();
|
||||
EnableLocalInterrupt(level);
|
||||
SysTick->SR = 0;
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
KTaskOsAssignAfterIrq(NONE);
|
||||
/* leave interrupt */
|
||||
level = DisableLocalInterrupt();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static volatile unsigned long tick_cycles = 0;
|
||||
int TickIsr(void)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
static volatile unsigned long tick_cycles = 0;
|
||||
int TickIsr(void)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -22,7 +22,7 @@ void SysTick_Handler(void)
|
|||
|
||||
// isrManager.done->incCounter();
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
// isrManager.done->decCounter();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ int TickIsr(void)
|
|||
uint64_t core_id = current_coreid();
|
||||
|
||||
clint->mtimecmp[core_id] += tick_cycles;
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ void SysTickConfiguration(void)
|
|||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
}
|
||||
DECLARE_HW_IRQ(SysTick_IRQn, SysTick_Handler, NONE);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
DECLARE_HW_IRQ(SYSTICK_IRQN, SysTick_Handler, NONE);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
DECLARE_HW_IRQ(SYSTICK_IRQN, SysTick_Handler, NONE);
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ void SysTickConfiguration(void)
|
|||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
}
|
||||
DECLARE_HW_IRQ(SysTick_IRQn, SysTick_Handler, NONE);
|
||||
|
|
|
@ -160,7 +160,7 @@ void BOARD_ConfigMPU(void)
|
|||
/* This is the timer interrupt service routine. */
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ void SysTick_Handler(void)
|
|||
x_base lock = 0;
|
||||
lock = DISABLE_INTERRUPT();
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
ENABLE_INTERRUPT(lock);
|
||||
}
|
||||
|
|
|
@ -448,7 +448,7 @@ void BOARD_ENETFlexibleConfigure(enet_config_t *config, uint8_t *hwAddr)
|
|||
/* This is the timer interrupt service routine. */
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
DECLARE_HW_IRQ(SYSTICK_IRQN, SysTick_Handler, NONE);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ Modification:
|
|||
/* This is the timer interrupt service routine. */
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -598,7 +598,7 @@ void BOARD_ConfigMPU(void)
|
|||
/* This is the timer interrupt service routine. */
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
|
||||
#ifdef BSP_USING_LPUART
|
||||
|
|
|
@ -40,6 +40,9 @@ Modification:
|
|||
#include "stm32l4xx_ll_rcc.h"
|
||||
#include "stm32l4xx_ll_gpio.h"
|
||||
#include "stm32l4xx_ll_cortex.h"
|
||||
#include "stm32l4xx_ll_rtc.h"
|
||||
#include "stm32l4xx_ll_exti.h"
|
||||
#include "stm32l4xx.h"
|
||||
|
||||
#ifdef BSP_USING_GPIO
|
||||
#include <connect_gpio.h>
|
||||
|
@ -92,11 +95,11 @@ Modification:
|
|||
extern void entry(void);
|
||||
extern int HwUsartInit();
|
||||
|
||||
|
||||
void SystemClockConfig(void)
|
||||
{
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
||||
|
||||
LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
|
||||
while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_0)
|
||||
{
|
||||
|
@ -104,6 +107,13 @@ void SystemClockConfig(void)
|
|||
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
||||
while (LL_PWR_IsActiveFlag_VOS() != 0)
|
||||
{
|
||||
}
|
||||
LL_RCC_LSI_Enable();
|
||||
|
||||
/* Wait till LSI is ready */
|
||||
while(LL_RCC_LSI_IsReady() != 1)
|
||||
{
|
||||
|
||||
}
|
||||
LL_RCC_MSI_Enable();
|
||||
|
||||
|
@ -115,6 +125,7 @@ void SystemClockConfig(void)
|
|||
LL_RCC_MSI_EnableRangeSelection();
|
||||
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_5);
|
||||
LL_RCC_MSI_SetCalibTrimming(0);
|
||||
LL_PWR_EnableBkUpAccess();
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_MSI);
|
||||
|
||||
/* Wait till System clock is ready */
|
||||
|
@ -126,26 +137,97 @@ void SystemClockConfig(void)
|
|||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
||||
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
|
||||
|
||||
LL_Init1msTick(2000000);
|
||||
|
||||
LL_SetSystemCoreClock(2000000);
|
||||
}
|
||||
|
||||
void NVIC_Configuration(void)
|
||||
{
|
||||
// TODO: config NVIC here
|
||||
NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
||||
}
|
||||
|
||||
void SysTickConfiguration(void)
|
||||
{
|
||||
// TODO: SysTickConfiguration
|
||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),15, 0));
|
||||
|
||||
// Configure the SysTick to have interrupt in 10ms(100Hz) time base.
|
||||
LL_InitTick(2000000,100);
|
||||
LL_SYSTICK_EnableIT();
|
||||
}
|
||||
|
||||
void SysTick_Handler(void)
|
||||
void InitSleepMode(void){
|
||||
LL_PWR_ClearFlag_WU();
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP0);
|
||||
LL_PWR_EnableLowPowerRunMode();
|
||||
LL_LPM_EnableDeepSleep();
|
||||
}
|
||||
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
// TODO: SysTick_Handler
|
||||
// x_base lock = 0;
|
||||
// lock = DISABLE_INTERRUPT();
|
||||
x_base lock = 0;
|
||||
lock = DISABLE_INTERRUPT();
|
||||
|
||||
// TickAndTaskTimesliceUpdate();
|
||||
|
||||
// ENABLE_INTERRUPT(lock);
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
ENABLE_INTERRUPT(lock);
|
||||
}
|
||||
DECLARE_HW_IRQ(SysTick_IRQn, SysTick_Handler, NONE);
|
||||
|
||||
int _rtc_sleep_ticks = 0;
|
||||
void RTC_WKUP_IRQHandler(int irqn, void *arg)
|
||||
{
|
||||
x_base lock = 0;
|
||||
lock = DISABLE_INTERRUPT();
|
||||
if(LL_RTC_IsActiveFlag_WUT(RTC) != RESET)
|
||||
{
|
||||
LL_RTC_ClearFlag_WUT(RTC);
|
||||
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_20);
|
||||
LL_RTC_ClearFlag_WUT(RTC);
|
||||
|
||||
TickAndTaskTimesliceUpdate(_rtc_sleep_ticks);
|
||||
_rtc_sleep_ticks = 0;
|
||||
}
|
||||
ENABLE_INTERRUPT(lock);
|
||||
}
|
||||
DECLARE_HW_IRQ(RTC_WKUP_IRQn, RTC_WKUP_IRQHandler, NONE);
|
||||
|
||||
void SuspendSystem(int idle_ticks){
|
||||
const int LSI_CLOCKS = 32768;
|
||||
_rtc_sleep_ticks = idle_ticks;
|
||||
// suspend systick to avoid wakeup mcu
|
||||
LL_SYSTICK_DisableIT();
|
||||
|
||||
// set wakeup rtc
|
||||
LL_RTC_DisableWriteProtection(RTC);
|
||||
LL_RTC_WAKEUP_Disable(RTC);
|
||||
|
||||
while (LL_RTC_IsActiveFlag_WUTW(RTC) != 1)
|
||||
{
|
||||
}
|
||||
|
||||
LL_RTC_WAKEUP_SetClock(RTC, LL_RTC_WAKEUPCLOCK_DIV_16);
|
||||
LL_PWR_EnableInternWU();
|
||||
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_20);
|
||||
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_20);
|
||||
|
||||
// LSI clock is used as RTC clock source
|
||||
LL_RTC_WAKEUP_SetAutoReload(RTC, LSI_CLOCKS*idle_ticks/TICK_PER_SECOND/16);
|
||||
LL_RTC_ClearFlag_WUT(RTC);
|
||||
|
||||
LL_RTC_WAKEUP_Enable(RTC);
|
||||
LL_RTC_EnableIT_WUT(RTC);
|
||||
LL_RTC_EnableWriteProtection(RTC);
|
||||
}
|
||||
|
||||
void ResumeSystem(void){
|
||||
KPrintf("Resume system\n");
|
||||
// restore systick
|
||||
LL_SYSTICK_EnableIT();
|
||||
|
||||
// disable wakeup rtc
|
||||
LL_RTC_DisableWriteProtection(RTC);
|
||||
LL_RTC_WAKEUP_Disable(RTC);
|
||||
LL_RTC_EnableWriteProtection(RTC);
|
||||
}
|
||||
|
||||
struct InitSequenceDesc _board_init[] =
|
||||
{
|
||||
|
@ -187,59 +269,6 @@ struct InitSequenceDesc _board_init[] =
|
|||
{ " NONE ", NONE },
|
||||
};
|
||||
|
||||
// TODO:
|
||||
void STRAIN_GPIO_Init(void)
|
||||
{
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15|LL_GPIO_PIN_0
|
||||
|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3|LL_GPIO_PIN_4
|
||||
|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8
|
||||
|LL_GPIO_PIN_9|LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOH, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3
|
||||
|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7
|
||||
|LL_GPIO_PIN_8|LL_GPIO_PIN_9|LL_GPIO_PIN_10|LL_GPIO_PIN_11
|
||||
|LL_GPIO_PIN_12|LL_GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10
|
||||
|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14
|
||||
|LL_GPIO_PIN_15|LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5
|
||||
|LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8|LL_GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void InitBoardHardware()
|
||||
{
|
||||
int i = 0;
|
||||
|
@ -249,6 +278,8 @@ void InitBoardHardware()
|
|||
|
||||
SysTickConfiguration();
|
||||
|
||||
InitSleepMode();
|
||||
|
||||
#ifdef BSP_USING_UART
|
||||
HwUsartInit();
|
||||
#endif
|
||||
|
@ -266,29 +297,10 @@ void InitBoardHardware()
|
|||
ret = _board_init[i].fn();
|
||||
KPrintf("initialize %s %s\n", _board_init[i].fn_name, ret == 0 ? "success" : "failed");
|
||||
}
|
||||
|
||||
|
||||
KPrintf("board init done.\n");
|
||||
KPrintf("start kernel...\n");
|
||||
|
||||
STRAIN_GPIO_Init();
|
||||
|
||||
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5);
|
||||
LL_mDelay(100);
|
||||
LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_5);
|
||||
|
||||
LL_mDelay(500);
|
||||
LL_SYSTICK_DisableIT();
|
||||
LL_PWR_ClearFlag_WU();
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
|
||||
LL_PWR_EnableLowPowerRunMode();
|
||||
LL_LPM_EnableDeepSleep();
|
||||
__WFI();
|
||||
LL_LPM_EnableSleep();
|
||||
LL_mDelay(5000);
|
||||
|
||||
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5);
|
||||
LL_mDelay(500);
|
||||
LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_5);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,18 @@ extern unsigned int g_service_table_end;
|
|||
#define MEM_OFFSET 64
|
||||
#define MEMORY_END_ADDRESS (0x20000000 + MEM_OFFSET * 1024)
|
||||
|
||||
#ifndef NVIC_PRIORITYGROUP_0
|
||||
#define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bit for pre-emption priority,
|
||||
4 bits for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bit for pre-emption priority,
|
||||
3 bits for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority,
|
||||
2 bits for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority,
|
||||
1 bit for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority,
|
||||
0 bit for subpriority */
|
||||
#endif
|
||||
|
||||
#ifdef SEPARATE_COMPILE
|
||||
typedef int (*main_t)(int argc, char *argv[]);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
||||
|
||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -Os -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
||||
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb
|
||||
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-ru-d01-m200.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -Werror
|
||||
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -flto -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-ru-d01-m200.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -Os -Werror
|
||||
|
||||
ifeq ($(CONFIG_LIB_MUSLLIB), y)
|
||||
export LFLAGS += -nostdlib -nostdinc -fno-builtin -nodefaultlibs
|
||||
|
@ -15,10 +15,10 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
|
|||
export LINK_LWIP := $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a
|
||||
endif
|
||||
|
||||
export APPLFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
|
||||
export APPLFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Os -Wl,--gc-sections,-Map=XiZi-app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
|
||||
|
||||
|
||||
export DEFINES := -DHAVE_CCONFIG_H -DSTM32F407xx -DUSE_HAL_DRIVER -DHAVE_SIGINFO
|
||||
export DEFINES := -DHAVE_CCONFIG_H -DSTM32L471xx -DHAVE_SIGINFO -DUSE_FULL_LL_DRIVER
|
||||
|
||||
export USING_NEWLIB =1
|
||||
export USING_VFS = 1
|
||||
|
|
|
@ -121,7 +121,6 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#define STM32L471xx
|
||||
|
||||
#if defined(STM32L412xx)
|
||||
#include "stm32l412xx.h"
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
menuconfig BSP_USING_UART
|
||||
bool "Using UART device"
|
||||
default n
|
||||
select RESOURCES_SERIAL
|
||||
if BSP_USING_UART
|
||||
source "$BSP_DIR/third_party_driver/uart/Kconfig"
|
||||
endif
|
||||
bool "Using UART device"
|
||||
default n
|
||||
select RESOURCES_SERIAL
|
||||
if BSP_USING_UART
|
||||
source "$BSP_DIR/third_party_driver/uart/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_GPIO
|
||||
bool "Using GPIO device"
|
||||
default n
|
||||
select RESOURCES_PIN
|
||||
if BSP_USING_GPIO
|
||||
source "$BSP_DIR/third_party_driver/gpio/Kconfig"
|
||||
endif
|
||||
bool "Using GPIO device"
|
||||
default n
|
||||
select RESOURCES_PIN
|
||||
if BSP_USING_GPIO
|
||||
source "$BSP_DIR/third_party_driver/gpio/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_RTC
|
||||
bool "Using RTC device"
|
||||
default n
|
||||
select RESOURCES_RTC
|
||||
if BSP_USING_RTC
|
||||
source "$BSP_DIR/third_party_driver/rtc/Kconfig"
|
||||
endif
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SRC_FILES := stm32l4xx_ll_rcc.c stm32l4xx_ll_gpio.c system_stm32l4xx.c stm32l4xx_ll_utils.c stm32l4xx_ll_usart.c
|
||||
SRC_FILES := stm32l4xx_ll_rcc.c stm32l4xx_ll_gpio.c system_stm32l4xx.c stm32l4xx_ll_utils.c stm32l4xx_ll_usart.c stm32l4xx_ll_rtc.c
|
||||
|
||||
ifeq ($(CONFIG_BSP_USING_DMA),y)
|
||||
SRC_FILES +=
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
******************************************************************************
|
||||
*/
|
||||
#define USE_FULL_LL_DRIVER
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
|
|
@ -0,0 +1,845 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_ll_rtc.c
|
||||
* @author MCD Application Team
|
||||
* @brief RTC LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_ll_rtc.h"
|
||||
#include "stm32l4xx_ll_cortex.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32L4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(RTC)
|
||||
|
||||
/** @addtogroup RTC_LL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup RTC_LL_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Default values used for prescaler */
|
||||
#define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU
|
||||
#define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU
|
||||
|
||||
/* Values used for timeout */
|
||||
#define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */
|
||||
#define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup RTC_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \
|
||||
|| ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM))
|
||||
|
||||
#define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU)
|
||||
|
||||
#define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU)
|
||||
|
||||
#define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
|
||||
|| ((__VALUE__) == LL_RTC_FORMAT_BCD))
|
||||
|
||||
#define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \
|
||||
|| ((__VALUE__) == LL_RTC_TIME_FORMAT_PM))
|
||||
|
||||
#define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U))
|
||||
#define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
|
||||
#define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
|
||||
#define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
|
||||
|
||||
#define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY))
|
||||
|
||||
#define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U))
|
||||
|
||||
#define IS_LL_RTC_MONTH(__MONTH__) (((__MONTH__) >= 1U) && ((__MONTH__) <= 12U))
|
||||
|
||||
#define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U)
|
||||
|
||||
#define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMA_MASK_ALL))
|
||||
|
||||
#define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \
|
||||
|| ((__VALUE__) == LL_RTC_ALMB_MASK_ALL))
|
||||
|
||||
|
||||
#define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \
|
||||
((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY))
|
||||
|
||||
#define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \
|
||||
((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY))
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup RTC_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup RTC_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-Initializes the RTC registers to their default reset values.
|
||||
* @note This function does not reset the RTC Clock source and RTC Backup Data
|
||||
* registers.
|
||||
* @param RTCx RTC Instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC registers are de-initialized
|
||||
* - LL_ERROR: RTC registers are not de-initialized
|
||||
*/
|
||||
ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx)
|
||||
{
|
||||
ErrorStatus status;
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
|
||||
/* Disable the write protection for RTC registers */
|
||||
LL_RTC_DisableWriteProtection(RTCx);
|
||||
|
||||
/* Set Initialization mode */
|
||||
status = LL_RTC_EnterInitMode(RTCx);
|
||||
if (status != LL_ERROR)
|
||||
{
|
||||
/* Reset TR, DR and CR registers */
|
||||
LL_RTC_WriteReg(RTCx, TR, 0x00000000U);
|
||||
|
||||
LL_RTC_WriteReg(RTCx, WUTR, RTC_WUTR_WUT);
|
||||
LL_RTC_WriteReg(RTCx, DR, (RTC_DR_WDU_0 | RTC_DR_MU_0 | RTC_DR_DU_0));
|
||||
/* Reset All CR bits except CR[2:0] */
|
||||
LL_RTC_WriteReg(RTCx, CR, (LL_RTC_ReadReg(RTCx, CR) & RTC_CR_WUCKSEL));
|
||||
|
||||
LL_RTC_WriteReg(RTCx, PRER, (RTC_PRER_PREDIV_A | RTC_SYNCH_PRESC_DEFAULT));
|
||||
LL_RTC_WriteReg(RTCx, ALRMAR, 0x00000000U);
|
||||
LL_RTC_WriteReg(RTCx, ALRMBR, 0x00000000U);
|
||||
LL_RTC_WriteReg(RTCx, SHIFTR, 0x00000000U);
|
||||
LL_RTC_WriteReg(RTCx, CALR, 0x00000000U);
|
||||
LL_RTC_WriteReg(RTCx, ALRMASSR, 0x00000000U);
|
||||
LL_RTC_WriteReg(RTCx, ALRMBSSR, 0x00000000U);
|
||||
|
||||
#if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
|
||||
#else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
|
||||
/* Reset Tamper and alternate functions configuration register */
|
||||
LL_RTC_WriteReg(RTCx, TAMPCR, 0x00000000U);
|
||||
|
||||
/* Reset Option register */
|
||||
LL_RTC_WriteReg(RTCx, OR, 0x00000000U);
|
||||
#endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
|
||||
|
||||
/* Exit Initialization mode */
|
||||
LL_RTC_DisableInitMode(RTCx);
|
||||
}
|
||||
|
||||
/* Enable the write protection for RTC registers */
|
||||
LL_RTC_EnableWriteProtection(RTCx);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the RTC registers according to the specified parameters
|
||||
* in RTC_InitStruct.
|
||||
* @param RTCx RTC Instance
|
||||
* @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
|
||||
* the configuration information for the RTC peripheral.
|
||||
* @note The RTC Prescaler register is write protected and can be written in
|
||||
* initialization mode only.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC registers are initialized
|
||||
* - LL_ERROR: RTC registers are not initialized
|
||||
*/
|
||||
ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct)
|
||||
{
|
||||
ErrorStatus status = LL_ERROR;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct->HourFormat));
|
||||
assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler));
|
||||
assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct->SynchPrescaler));
|
||||
|
||||
/* Disable the write protection for RTC registers */
|
||||
LL_RTC_DisableWriteProtection(RTCx);
|
||||
|
||||
/* Set Initialization mode */
|
||||
if (LL_RTC_EnterInitMode(RTCx) != LL_ERROR)
|
||||
{
|
||||
/* Set Hour Format */
|
||||
LL_RTC_SetHourFormat(RTCx, RTC_InitStruct->HourFormat);
|
||||
|
||||
/* Configure Synchronous and Asynchronous prescaler factor */
|
||||
LL_RTC_SetSynchPrescaler(RTCx, RTC_InitStruct->SynchPrescaler);
|
||||
LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler);
|
||||
|
||||
/* Exit Initialization mode */
|
||||
LL_RTC_DisableInitMode(RTCx);
|
||||
|
||||
status = LL_SUCCESS;
|
||||
}
|
||||
/* Enable the write protection for RTC registers */
|
||||
LL_RTC_EnableWriteProtection(RTCx);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_RTC_InitTypeDef field to default value.
|
||||
* @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct)
|
||||
{
|
||||
/* Set RTC_InitStruct fields to default values */
|
||||
RTC_InitStruct->HourFormat = LL_RTC_HOURFORMAT_24HOUR;
|
||||
RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT;
|
||||
RTC_InitStruct->SynchPrescaler = RTC_SYNCH_PRESC_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RTC current time.
|
||||
* @param RTCx RTC Instance
|
||||
* @param RTC_Format This parameter can be one of the following values:
|
||||
* @arg @ref LL_RTC_FORMAT_BIN
|
||||
* @arg @ref LL_RTC_FORMAT_BCD
|
||||
* @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
|
||||
* the time configuration information for the RTC.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC Time register is configured
|
||||
* - LL_ERROR: RTC Time register is not configured
|
||||
*/
|
||||
ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct)
|
||||
{
|
||||
ErrorStatus status = LL_ERROR;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
assert_param(IS_LL_RTC_FORMAT(RTC_Format));
|
||||
|
||||
if (RTC_Format == LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
|
||||
{
|
||||
assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct->Hours));
|
||||
assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat));
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_TimeStruct->TimeFormat = 0x00U;
|
||||
assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours));
|
||||
}
|
||||
assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes));
|
||||
assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
|
||||
{
|
||||
assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
|
||||
assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat));
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_TimeStruct->TimeFormat = 0x00U;
|
||||
assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
|
||||
}
|
||||
assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)));
|
||||
assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds)));
|
||||
}
|
||||
|
||||
/* Disable the write protection for RTC registers */
|
||||
LL_RTC_DisableWriteProtection(RTCx);
|
||||
|
||||
/* Set Initialization mode */
|
||||
if (LL_RTC_EnterInitMode(RTCx) != LL_ERROR)
|
||||
{
|
||||
/* Check the input parameters format */
|
||||
if (RTC_Format != LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, RTC_TimeStruct->Hours,
|
||||
RTC_TimeStruct->Minutes, RTC_TimeStruct->Seconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Hours),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Minutes),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Seconds));
|
||||
}
|
||||
|
||||
/* Exit Initialization mode */
|
||||
LL_RTC_DisableInitMode(RTCx);
|
||||
|
||||
/* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
|
||||
if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U)
|
||||
{
|
||||
status = LL_RTC_WaitForSynchro(RTCx);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = LL_SUCCESS;
|
||||
}
|
||||
}
|
||||
/* Enable the write protection for RTC registers */
|
||||
LL_RTC_EnableWriteProtection(RTCx);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
|
||||
* @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct)
|
||||
{
|
||||
/* Time = 00h:00min:00sec */
|
||||
RTC_TimeStruct->TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24;
|
||||
RTC_TimeStruct->Hours = 0U;
|
||||
RTC_TimeStruct->Minutes = 0U;
|
||||
RTC_TimeStruct->Seconds = 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RTC current date.
|
||||
* @param RTCx RTC Instance
|
||||
* @param RTC_Format This parameter can be one of the following values:
|
||||
* @arg @ref LL_RTC_FORMAT_BIN
|
||||
* @arg @ref LL_RTC_FORMAT_BCD
|
||||
* @param RTC_DateStruct pointer to a RTC_DateTypeDef structure that contains
|
||||
* the date configuration information for the RTC.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC Day register is configured
|
||||
* - LL_ERROR: RTC Day register is not configured
|
||||
*/
|
||||
ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct)
|
||||
{
|
||||
ErrorStatus status = LL_ERROR;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
assert_param(IS_LL_RTC_FORMAT(RTC_Format));
|
||||
|
||||
if ((RTC_Format == LL_RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10U) == 0x10U))
|
||||
{
|
||||
RTC_DateStruct->Month = (uint8_t)(((uint32_t) RTC_DateStruct->Month & (uint32_t)~(0x10U)) + 0x0AU);
|
||||
}
|
||||
|
||||
if (RTC_Format == LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
assert_param(IS_LL_RTC_YEAR(RTC_DateStruct->Year));
|
||||
assert_param(IS_LL_RTC_MONTH(RTC_DateStruct->Month));
|
||||
assert_param(IS_LL_RTC_DAY(RTC_DateStruct->Day));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Year)));
|
||||
assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month)));
|
||||
assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Day)));
|
||||
}
|
||||
assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct->WeekDay));
|
||||
|
||||
/* Disable the write protection for RTC registers */
|
||||
LL_RTC_DisableWriteProtection(RTCx);
|
||||
|
||||
/* Set Initialization mode */
|
||||
if (LL_RTC_EnterInitMode(RTCx) != LL_ERROR)
|
||||
{
|
||||
/* Check the input parameters format */
|
||||
if (RTC_Format != LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, RTC_DateStruct->Day, RTC_DateStruct->Month, RTC_DateStruct->Year);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Day),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Month), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Year));
|
||||
}
|
||||
|
||||
/* Exit Initialization mode */
|
||||
LL_RTC_DisableInitMode(RTCx);
|
||||
|
||||
/* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
|
||||
if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U)
|
||||
{
|
||||
status = LL_RTC_WaitForSynchro(RTCx);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = LL_SUCCESS;
|
||||
}
|
||||
}
|
||||
/* Enable the write protection for RTC registers */
|
||||
LL_RTC_EnableWriteProtection(RTCx);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00)
|
||||
* @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef *RTC_DateStruct)
|
||||
{
|
||||
/* Monday, January 01 xx00 */
|
||||
RTC_DateStruct->WeekDay = LL_RTC_WEEKDAY_MONDAY;
|
||||
RTC_DateStruct->Day = 1U;
|
||||
RTC_DateStruct->Month = LL_RTC_MONTH_JANUARY;
|
||||
RTC_DateStruct->Year = 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RTC Alarm A.
|
||||
* @note The Alarm register can only be written when the corresponding Alarm
|
||||
* is disabled (Use @ref LL_RTC_ALMA_Disable function).
|
||||
* @param RTCx RTC Instance
|
||||
* @param RTC_Format This parameter can be one of the following values:
|
||||
* @arg @ref LL_RTC_FORMAT_BIN
|
||||
* @arg @ref LL_RTC_FORMAT_BCD
|
||||
* @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
|
||||
* contains the alarm configuration parameters.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: ALARMA registers are configured
|
||||
* - LL_ERROR: ALARMA registers are not configured
|
||||
*/
|
||||
ErrorStatus LL_RTC_ALMA_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
assert_param(IS_LL_RTC_FORMAT(RTC_Format));
|
||||
assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct->AlarmMask));
|
||||
assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel));
|
||||
|
||||
if (RTC_Format == LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
|
||||
{
|
||||
assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours));
|
||||
assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
|
||||
assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
|
||||
}
|
||||
assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
|
||||
assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
|
||||
|
||||
if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
|
||||
{
|
||||
assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
|
||||
{
|
||||
assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
|
||||
assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
|
||||
assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
|
||||
}
|
||||
|
||||
assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
|
||||
assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
|
||||
|
||||
if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
|
||||
{
|
||||
assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable the write protection for RTC registers */
|
||||
LL_RTC_DisableWriteProtection(RTCx);
|
||||
|
||||
/* Select weekday selection */
|
||||
if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
|
||||
{
|
||||
/* Set the date for ALARM */
|
||||
LL_RTC_ALMA_DisableWeekday(RTCx);
|
||||
if (RTC_Format != LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
LL_RTC_ALMA_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RTC_ALMA_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the week day for ALARM */
|
||||
LL_RTC_ALMA_EnableWeekday(RTCx);
|
||||
LL_RTC_ALMA_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
|
||||
}
|
||||
|
||||
/* Configure the Alarm register */
|
||||
if (RTC_Format != LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours,
|
||||
RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat,
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds));
|
||||
}
|
||||
/* Set ALARM mask */
|
||||
LL_RTC_ALMA_SetMask(RTCx, RTC_AlarmStruct->AlarmMask);
|
||||
|
||||
/* Enable the write protection for RTC registers */
|
||||
LL_RTC_EnableWriteProtection(RTCx);
|
||||
|
||||
return LL_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RTC Alarm B.
|
||||
* @note The Alarm register can only be written when the corresponding Alarm
|
||||
* is disabled (@ref LL_RTC_ALMB_Disable function).
|
||||
* @param RTCx RTC Instance
|
||||
* @param RTC_Format This parameter can be one of the following values:
|
||||
* @arg @ref LL_RTC_FORMAT_BIN
|
||||
* @arg @ref LL_RTC_FORMAT_BCD
|
||||
* @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
|
||||
* contains the alarm configuration parameters.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: ALARMB registers are configured
|
||||
* - LL_ERROR: ALARMB registers are not configured
|
||||
*/
|
||||
ErrorStatus LL_RTC_ALMB_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
assert_param(IS_LL_RTC_FORMAT(RTC_Format));
|
||||
assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct->AlarmMask));
|
||||
assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel));
|
||||
|
||||
if (RTC_Format == LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
|
||||
{
|
||||
assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours));
|
||||
assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
|
||||
assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
|
||||
}
|
||||
assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
|
||||
assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
|
||||
|
||||
if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
|
||||
{
|
||||
assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
|
||||
{
|
||||
assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
|
||||
assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
|
||||
assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
|
||||
}
|
||||
|
||||
assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
|
||||
assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
|
||||
|
||||
if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
|
||||
{
|
||||
assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable the write protection for RTC registers */
|
||||
LL_RTC_DisableWriteProtection(RTCx);
|
||||
|
||||
/* Select weekday selection */
|
||||
if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
|
||||
{
|
||||
/* Set the date for ALARM */
|
||||
LL_RTC_ALMB_DisableWeekday(RTCx);
|
||||
if (RTC_Format != LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
LL_RTC_ALMB_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RTC_ALMB_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the week day for ALARM */
|
||||
LL_RTC_ALMB_EnableWeekday(RTCx);
|
||||
LL_RTC_ALMB_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
|
||||
}
|
||||
|
||||
/* Configure the Alarm register */
|
||||
if (RTC_Format != LL_RTC_FORMAT_BIN)
|
||||
{
|
||||
LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours,
|
||||
RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat,
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes),
|
||||
__LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds));
|
||||
}
|
||||
/* Set ALARM mask */
|
||||
LL_RTC_ALMB_SetMask(RTCx, RTC_AlarmStruct->AlarmMask);
|
||||
|
||||
/* Enable the write protection for RTC registers */
|
||||
LL_RTC_EnableWriteProtection(RTCx);
|
||||
|
||||
return LL_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
|
||||
* Day = 1st day of the month/Mask = all fields are masked).
|
||||
* @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
|
||||
{
|
||||
/* Alarm Time Settings : Time = 00h:00mn:00sec */
|
||||
RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMA_TIME_FORMAT_AM;
|
||||
RTC_AlarmStruct->AlarmTime.Hours = 0U;
|
||||
RTC_AlarmStruct->AlarmTime.Minutes = 0U;
|
||||
RTC_AlarmStruct->AlarmTime.Seconds = 0U;
|
||||
|
||||
/* Alarm Day Settings : Day = 1st day of the month */
|
||||
RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE;
|
||||
RTC_AlarmStruct->AlarmDateWeekDay = 1U;
|
||||
|
||||
/* Alarm Masks Settings : Mask = all fields are not masked */
|
||||
RTC_AlarmStruct->AlarmMask = LL_RTC_ALMA_MASK_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
|
||||
* Day = 1st day of the month/Mask = all fields are masked).
|
||||
* @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
|
||||
{
|
||||
/* Alarm Time Settings : Time = 00h:00mn:00sec */
|
||||
RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMB_TIME_FORMAT_AM;
|
||||
RTC_AlarmStruct->AlarmTime.Hours = 0U;
|
||||
RTC_AlarmStruct->AlarmTime.Minutes = 0U;
|
||||
RTC_AlarmStruct->AlarmTime.Seconds = 0U;
|
||||
|
||||
/* Alarm Day Settings : Day = 1st day of the month */
|
||||
RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMB_DATEWEEKDAYSEL_DATE;
|
||||
RTC_AlarmStruct->AlarmDateWeekDay = 1U;
|
||||
|
||||
/* Alarm Masks Settings : Mask = all fields are not masked */
|
||||
RTC_AlarmStruct->AlarmMask = LL_RTC_ALMB_MASK_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enters the RTC Initialization mode.
|
||||
* @note The RTC Initialization mode is write protected, use the
|
||||
* @ref LL_RTC_DisableWriteProtection before calling this function.
|
||||
* @param RTCx RTC Instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC is in Init mode
|
||||
* - LL_ERROR: RTC is not in Init mode
|
||||
*/
|
||||
ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx)
|
||||
{
|
||||
__IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
|
||||
ErrorStatus status = LL_SUCCESS;
|
||||
uint32_t tmp;
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
|
||||
/* Check if the Initialization mode is set */
|
||||
if (LL_RTC_IsActiveFlag_INIT(RTCx) == 0U)
|
||||
{
|
||||
/* Set the Initialization mode */
|
||||
LL_RTC_EnableInitMode(RTCx);
|
||||
|
||||
/* Wait till RTC is in INIT state and if Time out is reached exit */
|
||||
tmp = LL_RTC_IsActiveFlag_INIT(RTCx);
|
||||
while ((timeout != 0U) && (tmp != 1U))
|
||||
{
|
||||
if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
|
||||
{
|
||||
timeout --;
|
||||
}
|
||||
tmp = LL_RTC_IsActiveFlag_INIT(RTCx);
|
||||
if (timeout == 0U)
|
||||
{
|
||||
status = LL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Exit the RTC Initialization mode.
|
||||
* @note When the initialization sequence is complete, the calendar restarts
|
||||
* counting after 4 RTCCLK cycles.
|
||||
* @note The RTC Initialization mode is write protected, use the
|
||||
* @ref LL_RTC_DisableWriteProtection before calling this function.
|
||||
* @param RTCx RTC Instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC exited from in Init mode
|
||||
* - LL_ERROR: Not applicable
|
||||
*/
|
||||
ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
|
||||
/* Disable initialization mode */
|
||||
LL_RTC_DisableInitMode(RTCx);
|
||||
|
||||
return LL_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are
|
||||
* synchronized with RTC APB clock.
|
||||
* @note The RTC Resynchronization mode is write protected, use the
|
||||
* @ref LL_RTC_DisableWriteProtection before calling this function.
|
||||
* @note To read the calendar through the shadow registers after Calendar
|
||||
* initialization, calendar update or after wakeup from low power modes
|
||||
* the software must first clear the RSF flag.
|
||||
* The software must then wait until it is set again before reading
|
||||
* the calendar, which means that the calendar registers have been
|
||||
* correctly copied into the RTC_TR and RTC_DR shadow registers.
|
||||
* @param RTCx RTC Instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - LL_SUCCESS: RTC registers are synchronised
|
||||
* - LL_ERROR: RTC registers are not synchronised
|
||||
*/
|
||||
ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx)
|
||||
{
|
||||
__IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT;
|
||||
ErrorStatus status = LL_SUCCESS;
|
||||
uint32_t tmp;
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
|
||||
|
||||
/* Clear RSF flag */
|
||||
LL_RTC_ClearFlag_RS(RTCx);
|
||||
|
||||
/* Wait the registers to be synchronised */
|
||||
tmp = LL_RTC_IsActiveFlag_RS(RTCx);
|
||||
while ((timeout != 0U) && (tmp != 1U))
|
||||
{
|
||||
if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
|
||||
{
|
||||
timeout--;
|
||||
}
|
||||
tmp = LL_RTC_IsActiveFlag_RS(RTCx);
|
||||
if (timeout == 0U)
|
||||
{
|
||||
status = LL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* defined(RTC) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
|
@ -15,7 +15,6 @@
|
|||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#define USE_FULL_LL_DRIVER
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
|
|
@ -252,6 +252,131 @@ static int32 GpioIrqDisable(x_base pin)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
void STRAIN_GPIO_Init(void)
|
||||
{
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15|LL_GPIO_PIN_0
|
||||
|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3|LL_GPIO_PIN_4
|
||||
|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8
|
||||
|LL_GPIO_PIN_9|LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOH, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3
|
||||
|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7
|
||||
|LL_GPIO_PIN_8|LL_GPIO_PIN_9|LL_GPIO_PIN_10|LL_GPIO_PIN_11
|
||||
|LL_GPIO_PIN_12|LL_GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10
|
||||
|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14
|
||||
|LL_GPIO_PIN_15|LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5
|
||||
|LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8|LL_GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
// disable all modules
|
||||
/**/
|
||||
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_4|LL_GPIO_PIN_15);
|
||||
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_11);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_11|LL_GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_5);
|
||||
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_0);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
LL_GPIO_ResetOutputPin(GPIOC, LL_GPIO_PIN_4|LL_GPIO_PIN_10);
|
||||
LL_GPIO_SetOutputPin(GPIOC, LL_GPIO_PIN_7);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_7|LL_GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_4|LL_GPIO_PIN_15);
|
||||
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_11);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_11|LL_GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_5);
|
||||
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_0);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
LL_GPIO_ResetOutputPin(GPIOC, LL_GPIO_PIN_4|LL_GPIO_PIN_10);
|
||||
LL_GPIO_SetOutputPin(GPIOC, LL_GPIO_PIN_7);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_7|LL_GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
static uint32 Stm32PinConfigure(struct PinParam *param)
|
||||
{
|
||||
NULL_PARAM_CHECK(param);
|
||||
|
@ -391,6 +516,7 @@ int HwGpioInit(void)
|
|||
KPrintf("pin device register error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
STRAIN_GPIO_Init();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file connect_rtc.h
|
||||
* @brief define edu-arm32-board rtc function and struct
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023-02-02
|
||||
*/
|
||||
|
||||
#ifndef CONNECT_RTC_H
|
||||
#define CONNECT_RTC_H
|
||||
|
||||
#include <device.h>
|
||||
#include <stm32l4xx_ll_rcc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int HwRtcInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -20,7 +20,6 @@
|
|||
#ifndef STM32L4xx_LL_GPIO_H
|
||||
#define STM32L4xx_LL_GPIO_H
|
||||
|
||||
#define USE_FULL_LL_DRIVER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -31,8 +31,6 @@ extern "C" {
|
|||
* @{
|
||||
*/
|
||||
|
||||
#define USE_FULL_LL_DRIVER
|
||||
|
||||
#if defined(USART1) || defined(USART2) || defined(USART3) || defined(UART4) || defined(UART5)
|
||||
|
||||
/** @defgroup USART_LL USART
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := connect_pwr.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file usart/usart_uart_int/source/main.c
|
||||
* @brief This example demonstrates UART data receive and transfer by interrupt.
|
||||
@verbatim
|
||||
Change Logs:
|
||||
Date Author Notes
|
||||
2022-03-31 CDT First version
|
||||
@endverbatim
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
|
||||
*
|
||||
* This software component is licensed by XHSC under BSD 3-Clause license
|
||||
* (the "License"); You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file connect_pwr.c
|
||||
* @brief support ru-d01-m200 rtc function and register to bus framework
|
||||
* @version 2.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-09-13
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: connect_pwr.c
|
||||
Description: support ru-d01-m200 rtc configure and usart bus register function
|
||||
Others: take ... for reference
|
||||
1. Date: 2022-09-13
|
||||
Author: AIIT XUOS Lab
|
||||
*************************************************/
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
config RTC_BUS_NAME
|
||||
string "rtc bus name"
|
||||
default "rtc"
|
||||
config RTC_DRV_NAME
|
||||
string "rtc bus driver name"
|
||||
default "rtc_drv"
|
||||
config RTC_DEVICE_NAME
|
||||
string "rtc bus device name"
|
||||
default "rtc_dev"
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := connect_rtc.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,193 @@
|
|||
/**
|
||||
* @file connect_rtc.c
|
||||
* @brief support ru-d01-m200 rtc function and register to bus framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2024-08-27
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: connect_rtc.c
|
||||
Description: support ru-d01-m200 rtc configure and usart bus register function
|
||||
1. Date: 2024-08-27
|
||||
Author: AIIT XUOS Lab
|
||||
*************************************************/
|
||||
|
||||
#include <board.h>
|
||||
#include <connect_usart.h>
|
||||
#include "stm32l4xx_ll_rtc.h"
|
||||
#include "stm32l4xx_ll_rcc.h"
|
||||
#include "stm32l4xx_ll_gpio.h"
|
||||
#include "stm32l4xx_ll_bus.h"
|
||||
|
||||
static uint32 RtcConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
|
||||
struct RtcDriver *rtc_drv = (struct RtcDriver *)drv;
|
||||
struct RtcDrvConfigureParam *drv_param = (struct RtcDrvConfigureParam *)configure_info->private_data;
|
||||
|
||||
int cmd = drv_param->rtc_operation_cmd;
|
||||
time_t *time = drv_param->time;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case OPER_RTC_GET_TIME:
|
||||
{
|
||||
struct tm ct;
|
||||
// Combination of hours, minutes and seconds (Format: 0x00HHMMSS).
|
||||
uint32_t rtc_time;
|
||||
// Combination of WeekDay, Day, Month and Year (Format: 0xWWDDMMYY).
|
||||
uint32_t rtc_date;
|
||||
|
||||
rtc_time = LL_RTC_TIME_Get(RTC);
|
||||
rtc_date = LL_RTC_DATE_Get(RTC);
|
||||
|
||||
ct.tm_year = (rtc_date&(0xFF));
|
||||
ct.tm_mon = (rtc_date&(0xFF00))>>8;
|
||||
ct.tm_mday = (rtc_date&(0xFF0000))>>16;
|
||||
ct.tm_wday = (rtc_date&(0xFF000000))>>24;
|
||||
|
||||
ct.tm_hour = (rtc_time&(0xFF));
|
||||
ct.tm_min = (rtc_time&(0xFF00))>>8;
|
||||
ct.tm_sec = (rtc_time&(0xFF0000))>>16;
|
||||
|
||||
*time = mktime(&ct);
|
||||
}
|
||||
break;
|
||||
case OPER_RTC_SET_TIME:
|
||||
{
|
||||
struct tm *ct;
|
||||
LL_RTC_TimeTypeDef rtc_time;
|
||||
LL_RTC_DateTypeDef rtc_date;
|
||||
x_base lock;
|
||||
|
||||
lock = CriticalAreaLock();
|
||||
ct = localtime(time);
|
||||
rtc_time.Hours = ct->tm_hour;
|
||||
rtc_time.Minutes = ct->tm_min;
|
||||
rtc_time.Seconds = ct->tm_sec;
|
||||
rtc_date.WeekDay = ct->tm_wday;
|
||||
rtc_date.Month = ct->tm_mon;
|
||||
rtc_date.Day = ct->tm_mday;
|
||||
rtc_date.Year = ct->tm_year;
|
||||
LL_RTC_TIME_Init(RTC, LL_RTC_HOURFORMAT_24HOUR, &rtc_time);
|
||||
LL_RTC_DATE_Init(RTC, LL_RTC_HOURFORMAT_24HOUR, &rtc_date);
|
||||
CriticalAreaUnLock(lock);
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
return EOK;
|
||||
}
|
||||
|
||||
/*manage the rtc device operations*/
|
||||
static const struct RtcDevDone dev_done =
|
||||
{
|
||||
.open = NONE,
|
||||
.close = NONE,
|
||||
.write = NONE,
|
||||
.read = NONE,
|
||||
};
|
||||
|
||||
static int BoardRtcBusInit(struct RtcBus *rtc_bus, struct RtcDriver *rtc_driver)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
||||
/*Init the rtc bus */
|
||||
ret = RtcBusInit(rtc_bus, RTC_BUS_NAME);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit RtcBusInit error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*Init the rtc driver*/
|
||||
ret = RtcDriverInit(rtc_driver, RTC_DRV_NAME);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit RtcDriverInit error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*Attach the rtc driver to the rtc bus*/
|
||||
ret = RtcDriverAttachToBus(RTC_DRV_NAME, RTC_BUS_NAME);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit RtcDriverAttachToBus error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Attach the rtc device to the rtc bus*/
|
||||
static int BoardRtcDevBend(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
||||
static struct RtcHardwareDevice rtc_device;
|
||||
memset(&rtc_device, 0, sizeof(struct RtcHardwareDevice));
|
||||
|
||||
rtc_device.dev_done = &(dev_done);
|
||||
|
||||
ret = RtcDeviceRegister(&rtc_device, NONE, RTC_DEVICE_NAME);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit RtcDeviceInit device %s error %d\n", RTC_DEVICE_NAME, ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = RtcDeviceAttachToBus(RTC_DEVICE_NAME, RTC_BUS_NAME);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit RtcDeviceAttachToBus device %s error %d\n", RTC_DEVICE_NAME, ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int HwRtcInit(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
||||
static struct RtcBus rtc_bus;
|
||||
memset(&rtc_bus, 0, sizeof(struct RtcBus));
|
||||
|
||||
static struct RtcDriver rtc_driver;
|
||||
memset(&rtc_driver, 0, sizeof(struct RtcDriver));
|
||||
|
||||
rtc_driver.configure = &(RtcConfigure);
|
||||
|
||||
ret = BoardRtcBusInit(&rtc_bus, &rtc_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = BoardRtcDevBend();
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwRtcInit error ret %u\n", ret);
|
||||
}
|
||||
|
||||
LL_RTC_InitTypeDef RTC_InitStruct = {0};
|
||||
|
||||
if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI)
|
||||
{
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
|
||||
}
|
||||
|
||||
NVIC_SetPriority(RTC_WKUP_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
NVIC_EnableIRQ(RTC_WKUP_IRQn);
|
||||
|
||||
RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR;
|
||||
RTC_InitStruct.AsynchPrescaler = 127;
|
||||
RTC_InitStruct.SynchPrescaler = 255;
|
||||
LL_RTC_Init(RTC, &RTC_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
LL_RCC_EnableRTC();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -56,25 +56,6 @@ Modification:
|
|||
|
||||
static void UartIsr(struct SerialBus *serial, struct SerialDriver *serial_drv, struct SerialHardwareDevice *serial_dev);
|
||||
|
||||
static x_err_t UartGpioInit(USART_TypeDef *USARTx)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
|
||||
switch ((uint32)USARTx)
|
||||
{
|
||||
#ifdef BSP_USING_UART1
|
||||
case (uint32)USART1:
|
||||
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void SerialCfgParamCheck(struct SerialCfgParam *serial_cfg_default, struct SerialCfgParam *serial_cfg_new)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ void Rv32m1VgeaStart(void)
|
|||
|
||||
void LPIT0_IRQHandler(void)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
SystemClearSystickFlag();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ void XiZi_SysTick_Handler(void)
|
|||
{
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
ENABLE_INTERRUPT(lock);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ void XiZi_SysTick_Handler(void)
|
|||
{
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
ENABLE_INTERRUPT(lock);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ void SystemClock_Config(void)
|
|||
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ void SysTickConfiguration(void)
|
|||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
}
|
||||
DECLARE_HW_IRQ(SysTick_IRQn, SysTick_Handler, NONE);
|
||||
|
|
|
@ -92,7 +92,7 @@ void SysTickConfiguration(void)
|
|||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
}
|
||||
DECLARE_HW_IRQ(SysTick_IRQn, SysTick_Handler, NONE);
|
||||
|
|
|
@ -320,7 +320,7 @@ void BOARD_ConfigMPU(void)
|
|||
/* This is the timer interrupt service routine. */
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
|
||||
struct InitSequenceDesc _board_init[] =
|
||||
|
|
|
@ -175,7 +175,7 @@ void SysTick_Handler(void)
|
|||
x_base lock = 0;
|
||||
lock = DISABLE_INTERRUPT();
|
||||
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
|
||||
ENABLE_INTERRUPT(lock);
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ void BOARD_ConfigMPU(void)
|
|||
/* This is the timer interrupt service routine. */
|
||||
void SysTick_Handler(int irqn, void *arg)
|
||||
{
|
||||
TickAndTaskTimesliceUpdate();
|
||||
TickAndTaskTimesliceUpdate(1);
|
||||
}
|
||||
|
||||
struct InitSequenceDesc _board_init[] =
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <xs_base.h>
|
||||
|
||||
x_ticks_t CurrentTicksGain(void);
|
||||
void TickAndTaskTimesliceUpdate(void);
|
||||
void TickAndTaskTimesliceUpdate(x_ticks_t ticks);
|
||||
x_ticks_t CalculateTickFromTimeMs(uint32 ms);
|
||||
uint32 CalculateTimeMsFromTick(x_ticks_t ticks);
|
||||
|
||||
|
|
|
@ -43,10 +43,10 @@
|
|||
static int32 idle[CORE_NUM];
|
||||
__attribute__((aligned(MEM_ALIGN_SIZE)))
|
||||
|
||||
void RunningIntoLowPowerMode()
|
||||
void RunningIntoLowPowerMode()
|
||||
{
|
||||
#ifdef ARCH_ARM
|
||||
// __asm volatile("WFI");
|
||||
__asm volatile("wfi");
|
||||
#endif
|
||||
|
||||
#ifdef ARCH_RISCV
|
||||
|
@ -54,13 +54,43 @@ void RunningIntoLowPowerMode()
|
|||
#endif
|
||||
}
|
||||
|
||||
#define KERNEL_LOWPOWER
|
||||
#ifdef KERNEL_LOWPOWER
|
||||
void SuspendSystem(int idle_ticks);
|
||||
void ResumeSystem(void);
|
||||
#endif
|
||||
|
||||
extern DoubleLinklistType xiaoshan_delay_head;
|
||||
int CalculateSuspendTicks(void){
|
||||
x_ticks_t current_tick = 0;
|
||||
struct Delay *node = NONE;
|
||||
current_tick = CurrentTicksGain();
|
||||
node = SYS_DOUBLE_LINKLIST_ENTRY(xiaoshan_delay_head.node_next,
|
||||
struct Delay, link);
|
||||
|
||||
// TODO: check the ticks is positive or not
|
||||
int idle_ticks = node->ticks - current_tick;
|
||||
return idle_ticks>0?idle_ticks:0;
|
||||
}
|
||||
|
||||
static void IdleKTaskEntry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
#ifdef KERNEL_IDLE_HOOK
|
||||
HOOK(hook.idle.hook_Idle,());
|
||||
#endif
|
||||
#ifdef KERNEL_LOWPOWER
|
||||
int idle_ticks = CalculateSuspendTicks();
|
||||
if (idle_ticks > 0) {
|
||||
SuspendSystem(idle_ticks);
|
||||
}
|
||||
#endif
|
||||
RunningIntoLowPowerMode();
|
||||
#ifdef KERNEL_LOWPOWER
|
||||
if (idle_ticks > 0) {
|
||||
ResumeSystem();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -32,14 +32,14 @@ static x_ticks_t heartbeat_ticks = 0;
|
|||
#endif
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
#define UPDATE_GLOBAL_HEARTBEAT() \
|
||||
#define UPDATE_GLOBAL_HEARTBEAT(n) \
|
||||
do { \
|
||||
heartbeat_ticks[GetCpuId()]++; \
|
||||
heartbeat_ticks[GetCpuId()]+=n; \
|
||||
} while(0);
|
||||
#else
|
||||
#define UPDATE_GLOBAL_HEARTBEAT() \
|
||||
#define UPDATE_GLOBAL_HEARTBEAT(n) \
|
||||
do { \
|
||||
heartbeat_ticks ++; \
|
||||
heartbeat_ticks+=n; \
|
||||
} while(0);
|
||||
#endif
|
||||
|
||||
|
@ -61,11 +61,11 @@ x_ticks_t CurrentTicksGain(void)
|
|||
* this function increases global systick in tick interrupt,and process task time slice
|
||||
*
|
||||
*/
|
||||
void TickAndTaskTimesliceUpdate(void)
|
||||
void TickAndTaskTimesliceUpdate(x_ticks_t ticks)
|
||||
{
|
||||
struct TaskDescriptor *task = NONE;
|
||||
|
||||
UPDATE_GLOBAL_HEARTBEAT();
|
||||
UPDATE_GLOBAL_HEARTBEAT(ticks);
|
||||
|
||||
#if defined(SCHED_POLICY_FIFO)
|
||||
FifoTaskTimesliceUpdate();
|
||||
|
|
|
@ -57,6 +57,10 @@ ifeq ($(CONFIG_RESOURCES_WDT),y)
|
|||
SRC_DIR += watchdog
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_PWR),y)
|
||||
SRC_DIR += pwr
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_ADC),y)
|
||||
SRC_DIR += adc
|
||||
endif
|
||||
|
|
|
@ -33,6 +33,9 @@ extern "C" {
|
|||
#define OPER_WDT_SET_TIMEOUT 0x0002
|
||||
#define OPER_WDT_KEEPALIVE 0x0003
|
||||
|
||||
#define OPER_PWR_SUSPEND 0x0002
|
||||
#define OPER_PWR_WAKEUP 0x0003
|
||||
|
||||
typedef struct Bus *BusType;
|
||||
typedef struct HardwareDev *HardwareDevType;
|
||||
typedef struct Driver *DriverType;
|
||||
|
@ -46,6 +49,7 @@ enum BusType_e
|
|||
TYPE_USB_BUS,
|
||||
TYPE_CAN_BUS,
|
||||
TYPE_WDT_BUS,
|
||||
TYPE_PWR_BUS,
|
||||
TYPE_SDIO_BUS,
|
||||
TYPE_TOUCH_BUS,
|
||||
TYPE_LCD_BUS,
|
||||
|
@ -74,6 +78,7 @@ enum DevType
|
|||
TYPE_USB_DEV,
|
||||
TYPE_CAN_DEV,
|
||||
TYPE_WDT_DEV,
|
||||
TYPE_PWR_DEV,
|
||||
TYPE_SDIO_DEV,
|
||||
TYPE_TOUCH_DEV,
|
||||
TYPE_LCD_DEV,
|
||||
|
@ -102,6 +107,7 @@ enum DriverType_e
|
|||
TYPE_USB_DRV,
|
||||
TYPE_CAN_DRV,
|
||||
TYPE_WDT_DRV,
|
||||
TYPE_PWR_DRV,
|
||||
TYPE_SDIO_DRV,
|
||||
TYPE_TOUCH_DRV,
|
||||
TYPE_LCD_DRV,
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bus_pwr.h
|
||||
* @brief define pwr bus and drv function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#ifndef BUS_WDT_H
|
||||
#define BUS_WDT_H
|
||||
|
||||
#include <bus.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct PwrDriver
|
||||
{
|
||||
struct Driver driver;
|
||||
uint32 (*configure) (void *drv, struct BusConfigureInfo *ConfigureInfo);
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
struct PwrBus
|
||||
{
|
||||
struct Bus bus;
|
||||
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
/*Register the pwr bus*/
|
||||
int PwrBusInit(struct PwrBus *pwr_bus, const char *bus_name);
|
||||
|
||||
/*Register the pwr driver*/
|
||||
int PwrDriverInit(struct PwrDriver *pwr_driver, const char *driver_name);
|
||||
|
||||
/*Release the pwr device*/
|
||||
int PwrReleaseBus(struct PwrBus *pwr_bus);
|
||||
|
||||
/*Register the pwr driver to the pwr bus*/
|
||||
int PwrDriverAttachToBus(const char *drv_name, const char *bus_name);
|
||||
|
||||
/*Register the driver, manage with the double linklist*/
|
||||
int PwrDriverRegister(struct Driver *driver);
|
||||
|
||||
/*Find the register driver*/
|
||||
DriverType PwrDriverFind(const char *drv_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file dev_pwr.h
|
||||
* @brief define pwr dev function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#ifndef DEV_WDT_H
|
||||
#define DEV_WDT_H
|
||||
|
||||
#include <bus.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct PwrDevDone
|
||||
{
|
||||
uint32 (*open) (void *dev);
|
||||
uint32 (*close) (void *dev);
|
||||
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
|
||||
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
|
||||
};
|
||||
|
||||
struct PwrHardwareDevice
|
||||
{
|
||||
struct HardwareDev haldev;
|
||||
|
||||
const struct PwrDevDone *dev_done;
|
||||
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
/*Register the pwr device*/
|
||||
int PwrDeviceRegister(struct PwrHardwareDevice *pwr_device, const char *device_name);
|
||||
|
||||
/*Register the pwr device to the pwr bus*/
|
||||
int PwrDeviceAttachToBus(const char *dev_name, const char *bus_name);
|
||||
|
||||
/*Find the register pwr device*/
|
||||
HardwareDevType PwrDeviceFind(const char *dev_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -76,6 +76,11 @@ HardwareDevType ObtainConsole(void);
|
|||
#include <dev_wdt.h>
|
||||
#endif
|
||||
|
||||
#ifdef RESOURCES_PWR
|
||||
#include <bus_pwr.h>
|
||||
#include <dev_pwr.h>
|
||||
#endif
|
||||
|
||||
#ifdef RESOURCES_SDIO
|
||||
#include <bus_sdio.h>
|
||||
#include <dev_sdio.h>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
SRC_FILES +=bus_pwr.c dev_pwr.c drv_pwr.c
|
||||
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bus_pwr.c
|
||||
* @brief register pwr bus function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2024-08-27
|
||||
*/
|
||||
|
||||
#include <bus_pwr.h>
|
||||
#include <dev_pwr.h>
|
||||
|
||||
int PwrBusInit(struct PwrBus *pwr_bus, const char *bus_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(pwr_bus);
|
||||
NULL_PARAM_CHECK(bus_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (BUS_INSTALL != pwr_bus->bus.bus_state) {
|
||||
strncpy(pwr_bus->bus.bus_name, bus_name, NAME_NUM_MAX);
|
||||
|
||||
pwr_bus->bus.bus_type = TYPE_WDT_BUS;
|
||||
pwr_bus->bus.bus_state = BUS_INSTALL;
|
||||
pwr_bus->bus.private_data = pwr_bus->private_data;
|
||||
|
||||
ret = BusRegister(&pwr_bus->bus);
|
||||
if (EOK != ret) {
|
||||
KPrintf("PwrBusInit BusRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("PwrBusInit BusRegister bus has been register state%u\n", pwr_bus->bus.bus_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PwrDriverInit(struct PwrDriver *pwr_driver, const char *driver_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(pwr_driver);
|
||||
NULL_PARAM_CHECK(driver_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (DRV_INSTALL != pwr_driver->driver.driver_state) {
|
||||
pwr_driver->driver.driver_type = TYPE_WDT_DRV;
|
||||
pwr_driver->driver.driver_state = DRV_INSTALL;
|
||||
|
||||
strncpy(pwr_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
|
||||
|
||||
pwr_driver->driver.configure = pwr_driver->configure;
|
||||
|
||||
ret = PwrDriverRegister(&pwr_driver->driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("PwrDriverInit DriverRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("PwrDriverInit DriverRegister driver has been register state%u\n", pwr_driver->driver.driver_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PwrReleaseBus(struct PwrBus *pwr_bus)
|
||||
{
|
||||
NULL_PARAM_CHECK(pwr_bus);
|
||||
|
||||
return BusRelease(&pwr_bus->bus);
|
||||
}
|
||||
|
||||
int PwrDriverAttachToBus(const char *drv_name, const char *bus_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv_name);
|
||||
NULL_PARAM_CHECK(bus_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
struct Bus *bus;
|
||||
struct Driver *driver;
|
||||
|
||||
bus = BusFind(bus_name);
|
||||
if (NONE == bus) {
|
||||
KPrintf("PwrDriverAttachToBus find watchdog bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_WDT_BUS == bus->bus_type) {
|
||||
driver = PwrDriverFind(drv_name);
|
||||
if (NONE == driver) {
|
||||
KPrintf("PwrDriverAttachToBus find watchdog driver error!name %s\n", drv_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_WDT_DRV == driver->driver_type) {
|
||||
ret = DriverRegisterToBus(bus, driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("PwrDriverAttachToBus DriverRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file dev_pwr.c
|
||||
* @brief register pwr dev function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2024-08-27
|
||||
*/
|
||||
|
||||
#include <bus_pwr.h>
|
||||
#include <dev_pwr.h>
|
||||
|
||||
static DoubleLinklistType pwrdev_linklist;
|
||||
|
||||
/*Create the pwr device linklist*/
|
||||
static void PwrDeviceLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&pwrdev_linklist);
|
||||
}
|
||||
|
||||
HardwareDevType PwrDeviceFind(const char *dev_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev_name);
|
||||
|
||||
struct HardwareDev *device = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &pwrdev_linklist;
|
||||
|
||||
for (node = head->node_next; node != head; node = node->node_next) {
|
||||
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link);
|
||||
if (!strcmp(device->dev_name, dev_name)) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("PwrDeviceFind cannot find the %s device.return NULL\n", dev_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int PwrDeviceRegister(struct PwrHardwareDevice *pwr_device, const char *device_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(pwr_device);
|
||||
NULL_PARAM_CHECK(device_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool dev_link_flag = RET_FALSE;
|
||||
|
||||
if (!dev_link_flag) {
|
||||
PwrDeviceLinkInit();
|
||||
dev_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
if (DEV_INSTALL != pwr_device->haldev.dev_state) {
|
||||
strncpy(pwr_device->haldev.dev_name, device_name, NAME_NUM_MAX);
|
||||
pwr_device->haldev.dev_type = TYPE_WDT_DEV;
|
||||
pwr_device->haldev.dev_state = DEV_INSTALL;
|
||||
|
||||
pwr_device->haldev.dev_done = (struct HalDevDone *)pwr_device->dev_done;
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&pwrdev_linklist, &(pwr_device->haldev.dev_link));
|
||||
} else {
|
||||
KPrintf("PwrDeviceRegister device has been register state%u\n", pwr_device->haldev.dev_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PwrDeviceAttachToBus(const char *dev_name, const char *bus_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev_name);
|
||||
NULL_PARAM_CHECK(bus_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
struct Bus *bus;
|
||||
struct HardwareDev *device;
|
||||
|
||||
bus = BusFind(bus_name);
|
||||
if (NONE == bus) {
|
||||
KPrintf("PwrDeviceAttachToBus find pwr bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_WDT_BUS == bus->bus_type) {
|
||||
device = PwrDeviceFind(dev_name);
|
||||
if (NONE == device) {
|
||||
KPrintf("PwrDeviceAttachToBus find pwr device error!name %s\n", dev_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_WDT_DEV == device->dev_type) {
|
||||
ret = DeviceRegisterToBus(bus, device);
|
||||
if (EOK != ret) {
|
||||
KPrintf("PwrDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file drv_pwr.c
|
||||
* @brief register pwr drv function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2024-08-27
|
||||
*/
|
||||
|
||||
#include <bus_pwr.h>
|
||||
#include <dev_pwr.h>
|
||||
|
||||
static DoubleLinklistType pwrdrv_linklist;
|
||||
|
||||
/*Create the driver linklist*/
|
||||
static void PwrDrvLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&pwrdrv_linklist);
|
||||
}
|
||||
|
||||
DriverType PwrDriverFind(const char *drv_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv_name);
|
||||
|
||||
struct Driver *driver = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &pwrdrv_linklist;
|
||||
|
||||
for (node = head->node_next; node != head; node = node->node_next) {
|
||||
driver = SYS_DOUBLE_LINKLIST_ENTRY(node, struct Driver, driver_link);
|
||||
if (!strcmp(driver->drv_name, drv_name)) {
|
||||
return driver;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("PwrDriverFind cannot find the %s driver.return NULL\n", drv_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int PwrDriverRegister(struct Driver *driver)
|
||||
{
|
||||
NULL_PARAM_CHECK(driver);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool driver_link_flag = RET_FALSE;
|
||||
|
||||
if (!driver_link_flag) {
|
||||
PwrDrvLinkInit();
|
||||
driver_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&pwrdrv_linklist, &(driver->driver_link));
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
menu "Command shell"
|
||||
|
||||
menuconfig TOOL_SHELL
|
||||
select KERNEL_CONSOLE
|
||||
bool "Enable letter-shell function"
|
||||
default y
|
||||
|
||||
|
|
|
@ -24,10 +24,15 @@ long Hello(void)
|
|||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, Hello, Hello, show Hello World information);
|
||||
|
||||
#ifdef KERNEL_BANNER
|
||||
extern void ShowBanner(void);
|
||||
#endif
|
||||
|
||||
long ShowVersion(void)
|
||||
{
|
||||
#ifdef KERNEL_BANNER
|
||||
ShowBanner();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue