V1.0
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
/*!
|
||||
* \file main.c
|
||||
*
|
||||
* \brief Target main implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
void app_uart_init(void)
|
||||
{
|
||||
GPIO_InitCfg_t gpio_cfg = {0};
|
||||
|
||||
gpio_cfg.Mux = GPIO_Mux0;
|
||||
gpio_cfg.Pull = GPIO_PULLUP;
|
||||
gpio_cfg.Int = NOT_INT;
|
||||
gpio_cfg.FunSel = UART0_TX;
|
||||
|
||||
gpio_cfg.Pin = GPIO_18;
|
||||
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
gpio_cfg.FunSel = UART0_RX;
|
||||
gpio_cfg.Pin = GPIO_19;
|
||||
gpio_cfg.Dir = GPIO_DIR_INPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
UART_InitCfg_t uart_cfg = {0};
|
||||
|
||||
uart_cfg.Parity = UART_PARITY_DISABLE;
|
||||
uart_cfg.StopBits = UART_STOP_1_BITS;
|
||||
uart_cfg.WordLength = UART_DATA_8_BITS;
|
||||
uart_cfg.BaudRate = UART_BAUDRATE_115200;
|
||||
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
|
||||
|
||||
xc_uart_init(UART0_IDX, &uart_cfg);
|
||||
}
|
||||
|
||||
void clock_init(void)
|
||||
{
|
||||
CLOCK_InitCfg_t clock_cfg;
|
||||
|
||||
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
|
||||
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_32M;
|
||||
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
|
||||
|
||||
if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
|
||||
} else if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
|
||||
}
|
||||
|
||||
xc_clock_init_cfg(&clock_cfg);
|
||||
|
||||
SysTick_Config(xc_clock_hfclk_in_get() / 100);
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
|
||||
clock_init();
|
||||
|
||||
app_uart_init();
|
||||
|
||||
xc_rc32k_calib_by_hw( );
|
||||
|
||||
DEBUG("__START__\n");
|
||||
|
||||
/* RTC DEMO */
|
||||
rtc_demo();
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* main loop */
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/*!
|
||||
* \file rtc.c
|
||||
*
|
||||
* \brief Target rtc implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "rtc.h"
|
||||
#include "xc_drv_rtc.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
//#define LED1_PIN GPIO_26
|
||||
//#define LED2_PIN GPIO_27
|
||||
//#define KEY1_PIN GPIO_1
|
||||
//#define KEY2_PIN GPIO_5
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
Rtc_Intr_Sta_t RTC_Intr_Sta = {
|
||||
.T1_CMR = false,
|
||||
.T2_CMR = false,
|
||||
.T3_CMR = false,
|
||||
.Day = false,
|
||||
.Hour = false,
|
||||
.Min = false,
|
||||
.Sec = false
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief rtc_demo
|
||||
* @details
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void rtc_demo(void)
|
||||
{
|
||||
DEBUG("__RTC_DEMO__\r");
|
||||
|
||||
RTC_InitCfg_t rtc_cfg = {0};
|
||||
Rtc_DateTypeDef_t Date={0};
|
||||
|
||||
rtc_cfg.Date.Sec = 0;
|
||||
rtc_cfg.Date.Min = 0;
|
||||
rtc_cfg.Date.Hour = 18;
|
||||
rtc_cfg.Date.Day = 154;
|
||||
rtc_cfg.Date.Week = 6;
|
||||
|
||||
rtc_cfg.DateLimit.SecLimit = 60;
|
||||
rtc_cfg.DateLimit.MinLimit = 60;
|
||||
rtc_cfg.DateLimit.HourLimit = 24;
|
||||
|
||||
rtc_cfg.MatchTime.ch = RTC_MATCH_T1;
|
||||
rtc_cfg.MatchTime.Sec = 5;
|
||||
rtc_cfg.MatchTime.Min = 02;
|
||||
rtc_cfg.MatchTime.Hour = 18;
|
||||
rtc_cfg.MatchTime.Week = RTC_MATCH_SATURDAY;
|
||||
rtc_cfg.MatchTimeEnable = true;
|
||||
|
||||
rtc_cfg.SecIT_Enable = true;
|
||||
rtc_cfg.MinIT_Enable = true;
|
||||
rtc_cfg.HourIT_Enable = true;
|
||||
rtc_cfg.DayIT_Enable = false;
|
||||
|
||||
xc_rtc_init(&rtc_cfg);
|
||||
xc_rtc_start();
|
||||
NVIC_EnableIRQ(RTC_IRQn);
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(RTC_Intr_Sta.T1_CMR == true)
|
||||
{
|
||||
DEBUG("RTC T1 CMR Irq\n");
|
||||
RTC_Intr_Sta.T1_CMR = false;
|
||||
}
|
||||
|
||||
if(RTC_Intr_Sta.T2_CMR == true)
|
||||
{
|
||||
DEBUG("RTC T2 CMR Irq\n");
|
||||
RTC_Intr_Sta.T2_CMR = false;
|
||||
}
|
||||
|
||||
if(RTC_Intr_Sta.T3_CMR == true)
|
||||
{
|
||||
DEBUG("RTC T3 CMR Irq\n");
|
||||
RTC_Intr_Sta.T3_CMR = false;
|
||||
}
|
||||
|
||||
if(RTC_Intr_Sta.Sec == true)
|
||||
{
|
||||
xc_rtc_date_get(&Date);
|
||||
DEBUG("%02d:%02d:%02d\n", Date.Hour, Date.Min, Date.Sec);
|
||||
RTC_Intr_Sta.Sec = false;
|
||||
}
|
||||
|
||||
if(RTC_Intr_Sta.Min == true)
|
||||
{
|
||||
RTC_Intr_Sta.Min = false;
|
||||
}
|
||||
|
||||
if(RTC_Intr_Sta.Hour == true)
|
||||
{
|
||||
RTC_Intr_Sta.Hour = false;
|
||||
}
|
||||
|
||||
if(RTC_Intr_Sta.Day == true)
|
||||
{
|
||||
RTC_Intr_Sta.Day = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief T1_CMR_Callback
|
||||
* @details RTC compare timer1 callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t T1_CMR_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.T1_CMR = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief T2_CMR_Callback
|
||||
* @details RTC compare timer2 callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t T2_CMR_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.T2_CMR = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief T3_CMR_Callback
|
||||
* @details RTC compare timer3 callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t T3_CMR_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.T3_CMR = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sec_Callback
|
||||
* @details RTC second callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t Sec_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.Sec = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Min_Callback
|
||||
* @details RTC minute callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t Min_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.Min = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hour_Callback
|
||||
* @details RTC hour callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t Hour_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.Hour = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Day_Callback
|
||||
* @details RTC Day callback function
|
||||
* @param void
|
||||
* @retval uint8_t
|
||||
*/
|
||||
__RAM_CODE uint8_t Day_Callback(void)
|
||||
{
|
||||
RTC_Intr_Sta.Day = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user