Commit f3345a2c authored by hu's avatar hu

更改了RTC时间停止,以及里程大计异常问题

parent e94bb947
No preview for this file type
This diff is collapsed.
project .intvect 1536 project .intvect 1536
project .text 316700 project .text 317548
project .rodata 411095 project .rodata 411087
project .secinfo 120 project .secinfo 120
project .syscall 6 project .syscall 6
project .romdata 9029 project .romdata 9029
......
...@@ -14,12 +14,12 @@ void RTE_RTC_KL30_Init(void) ...@@ -14,12 +14,12 @@ void RTE_RTC_KL30_Init(void)
void RTE_RTC_Wakeup_Init(void) void RTE_RTC_Wakeup_Init(void)
{ {
RTC_Init(); //RTC_Init();
} }
void RTE_RTC_Services_100Ms_Cbk(void) void RTE_RTC_Services_100Ms_Cbk(void)
{ {
RTC_Timing_Service(); RTC_Get_Time();
} }
...@@ -65,7 +65,7 @@ void RTE_RTC_Confirm_Overwrite(void) ...@@ -65,7 +65,7 @@ void RTE_RTC_Confirm_Overwrite(void)
mTimmerSetting.u8RTCMinute = RTE_RTC_MINUTE; /*0~~59 in Dec*/ mTimmerSetting.u8RTCMinute = RTE_RTC_MINUTE; /*0~~59 in Dec*/
mTimmerSetting.u8RTCSecond = RTE_RTC_SECOND; /*0~~59 in Dec*/ mTimmerSetting.u8RTCSecond = RTE_RTC_SECOND; /*0~~59 in Dec*/
RTC_Set_Time(&mTimmerSetting); RTC_Set_Time(mTimmerSetting.u8RTCYear, mTimmerSetting.u8RTCMonth, mTimmerSetting.u8RTCDayOfMonth, mTimmerSetting.u8RTCHour, mTimmerSetting.u8RTCMinute, mTimmerSetting.u8RTCSecond);
} }
......
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
#include "Clock.h" #include "Clock.h"
#include "GPIO.h" #include "GPIO.h"
#include "Watchdog.h" #include "Watchdog.h"
#include "TYW_FLASH.h"
#include "RTC.h"
#include "rh850_macros.h"
extern uint32_t TestBackupRam;
#define CLOCK_PROTECTED_WRITE(preg, pstatus, reg, value) \ #define CLOCK_PROTECTED_WRITE(preg, pstatus, reg, value) \
do \ do \
...@@ -17,7 +22,7 @@ ...@@ -17,7 +22,7 @@
} while ((pstatus) == 1U) } while ((pstatus) == 1U)
static const r_dev_ClkGenConfig_t g_stClockGenCfg = static const r_dev_ClkGenConfig_t g_stClockGenCfg =
{ {
/*mainosc*/ /*mainosc*/
{ {
/* FrequencyHz */ R_DEV_MOSC_FRQ_HZ, /* FrequencyHz */ R_DEV_MOSC_FRQ_HZ,
...@@ -103,7 +108,7 @@ static const r_dev_ClkSelConfig_t g_stClkSelectionCfg[] = ...@@ -103,7 +108,7 @@ static const r_dev_ClkSelConfig_t g_stClkSelectionCfg[] =
{R_DEV_CKS_CPU, R_DEV_CKS_SRC_PLL0, 2, 0u}, {R_DEV_CKS_CPU, R_DEV_CKS_SRC_PLL0, 2, 0u},
{R_DEV_CKS_SFMA, R_DEV_CKS_SRC_PLL0, 3, 0u}, {R_DEV_CKS_SFMA, R_DEV_CKS_SRC_PLL0, 3, 0u},
{R_DEV_CKS_SSIF, R_DEV_CKS_SRC_PLLFIX, 156, 0u}, {R_DEV_CKS_SSIF, R_DEV_CKS_SRC_PLLFIX, 156, 0u},
{R_DEV_CKS_ISM, R_DEV_CKS_SRC_CLKJIT, 0, 0u},
/* delimiter - do not remove */ /* delimiter - do not remove */
{R_DEV_CKS_LAST, R_DEV_CKS_SRC_MOSC, 2, 0u}, {R_DEV_CKS_LAST, R_DEV_CKS_SRC_MOSC, 2, 0u},
}; };
...@@ -153,7 +158,7 @@ void Clock_Enter_Sleep_Mode(void) ...@@ -153,7 +158,7 @@ void Clock_Enter_Sleep_Mode(void)
/*MainOsc continues operation in DEEPSTOP mode*/ /*MainOsc continues operation in DEEPSTOP mode*/
SYSMOSCSTPM = 0x03U; SYSMOSCSTPM = 0x03U;
/*High Speed IntOsc stops operation in DEEPSTOP mode.*/ /*High Speed IntOsc stops operation in DEEPSTOP mode.*/
//SYSROSCSTPM = 0x02U; // SYSROSCSTPM = 0x02U;
R_DEV_SetGenStopMask(R_DEV_HS_RING, 0U); R_DEV_SetGenStopMask(R_DEV_HS_RING, 0U);
/*Clock domain C_AWO_AWOT is stopped in DEEPSTOP mode*/ /*Clock domain C_AWO_AWOT is stopped in DEEPSTOP mode*/
SYSCKSC_AAWOTD_STPM = 0x02U; SYSCKSC_AAWOTD_STPM = 0x02U;
...@@ -163,14 +168,19 @@ void Clock_Enter_Sleep_Mode(void) ...@@ -163,14 +168,19 @@ void Clock_Enter_Sleep_Mode(void)
SYSCKSC_AFOUTS_STPM = 0X02U; SYSCKSC_AFOUTS_STPM = 0X02U;
/*Stop all active PLLs*/ /*Stop all active PLLs*/
//CLOCK_PROTECTED_WRITE(SYSPROTCMD1, SYSPROTS1, SYSPLL0E, 0x02U); /*Stop the PLL0*/ // CLOCK_PROTECTED_WRITE(SYSPROTCMD1, SYSPROTS1, SYSPLL0E, 0x02U); /*Stop the PLL0*/
//CLOCK_PROTECTED_WRITE(SYSPROTCMD1, SYSPROTS1, SYSPLL1E, 0x02U); /*Stop the PLL1*/ // CLOCK_PROTECTED_WRITE(SYSPROTCMD1, SYSPROTS1, SYSPLL1E, 0x02U); /*Stop the PLL1*/
R_DEV_ClkGenStop(R_DEV_PLL0); R_DEV_ClkGenStop(R_DEV_PLL0);
R_DEV_ClkGenStop(R_DEV_PLL1); R_DEV_ClkGenStop(R_DEV_PLL1);
/*Clear the RESF register*/ /*Clear the RESF register*/
/*start DEEPSTOP mode*/ /*start DEEPSTOP mode*/
/*wait for the transition to the DEEPSTOP mode by the unconditional loop*/ /*wait for the transition to the DEEPSTOP mode by the unconditional loop*/
} }
#pragma ghs section bss = ".absinitarea"
uint32_t u32ResetFlag;
uint32_t u32ResetSource;
#pragma ghs section bss = default
Clock_Startup_Mode_en_t Clock_Get_Startup_Mode(void) Clock_Startup_Mode_en_t Clock_Get_Startup_Mode(void)
{ {
...@@ -183,35 +193,35 @@ Clock_Startup_Mode_en_t Clock_Get_Startup_Mode(void) ...@@ -183,35 +193,35 @@ Clock_Startup_Mode_en_t Clock_Get_Startup_Mode(void)
u32ResetRESFValue = SYSRESF; u32ResetRESFValue = SYSRESF;
u32ResetRESFRValue = SYSRESFR; u32ResetRESFRValue = SYSRESFR;
u32ResetSource = SYSRESF;
/* Clear reset factor */ /* Clear reset factor */
SYSRESFC = 0xC70FU; SYSRESFC = 0xC70FU;
SYSRESFCR = 0xC70FU; SYSRESFCR = 0xC70FU;
if (u32ResetRESFValue & 0x00000200U) /*Power-up reset PURES: POC0RES,DBRES*/ if (u32ResetRESFValue & 0x0000C30FU)
{ {
enClockMode = CLOCK_STARTUP_PWR_ON; enClockMode = CLOCK_STARTUP_PWR_ON;
} }
else if (u32ResetRESFValue & 0x00004400U) /* DEEPSTOP reset ISORES ,Error Control Module */ else
{ {
enClockMode = CLOCK_STARTUP_WAKE_UP; enClockMode = CLOCK_STARTUP_WAKE_UP;
} }
else /*System reset SYSRES:WDTA1,WDTA0 ,Software and so on */
{
enClockMode = CLOCK_STARTUP_SYSTEM_RESET;
}
return enClockMode; return enClockMode;
} }
static uint32_t wbytest = 0 ;
void Sys_Enter_Sleep_Mode(void) void Sys_Enter_Sleep_Mode(void)
{ {
WDT_Clear(); WDT_Clear();
CLOCK_PROTECTED_WRITE(SYSPROTCMD0, SYSPROTS0, SYSCKSC_AWDTA0D_CTL, 0x06U); /* 看门狗时钟2048分频*/ CLOCK_PROTECTED_WRITE(SYSPROTCMD0, SYSPROTS0, SYSCKSC_AWDTA0D_CTL, 0x06U); /* 看门狗时钟2048分频*/
GPIO_Init(GPIO_SLEEP_MODE);
__DI(); __DI();
SYSWUFC0 = 0x7FFFFU; SYSWUFC0 = 0x7FFFFU;
/*---------------------------------------------*/ /*---------------------------------------------*/
//GPIO_Wakeup_PIN_Set(GPIO_WAKEUP_PIN_P0_5, GPIO_WAKEUP_FALLING_EDGE); GPIO_Wakeup_PIN_Set(GPIO_WAKEUP_PIN_P0_5, GPIO_WAKEUP_FALLING_EDGE);
GPIO_Wakeup_PIN_Set(GPIO_WAKEUP_PIN_P0_0, GPIO_WAKEUP_RISING_EDGE); GPIO_Wakeup_PIN_Set(GPIO_WAKEUP_PIN_P0_0, GPIO_WAKEUP_RISING_EDGE);
/*----------------------------------------------*/ /*----------------------------------------------*/
SYSWUFMSK0 &= 0x7FFFEU; SYSWUFMSK0 &= 0x7FFFEU;
...@@ -222,9 +232,7 @@ void Sys_Enter_Sleep_Mode(void) ...@@ -222,9 +232,7 @@ void Sys_Enter_Sleep_Mode(void)
CLOCK_PROTECTED_WRITE(SYSPROTCMD0, SYSPROTS0, SYSSTBC0PSC, 0x02U); CLOCK_PROTECTED_WRITE(SYSPROTCMD0, SYSPROTS0, SYSSTBC0PSC, 0x02U);
for (;;) RTC_Backup_Time();
{ TestBackupRam = 0xaabbccddu;
wbytest ++ ; hardware_reset();
}
} }
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
#include "r_typedefs.h" #include "r_typedefs.h"
#include "dr7f701441.dvf.h" #include "dr7f701441.dvf.h"
#include "RTC.h" #include "RTC.h"
#include <string.h>
volatile uint8_t g_RTCLeapYear; /*1:LeapYear , 0:Not a leap year*/ RTC_Information_st_t g_stRTCInformation;
volatile RTC_Information_st_t g_stRTCInformation; #define RTC_TIME_OUT_COUNT 500U
static uint8_t Cal_RTC_Week(uint16_t Year, uint8_t Month, uint8_t Day); static uint8_t Cal_RTC_Week(uint16_t Year, uint8_t Month, uint8_t Day);
...@@ -21,43 +22,21 @@ static uint8_t RTC_Dec_To_BCD(uint8_t u8RTCDec) ...@@ -21,43 +22,21 @@ static uint8_t RTC_Dec_To_BCD(uint8_t u8RTCDec)
uint8_t u8RTCData = (((u8RTCDec / 10U) % 10U) << 4U) + (u8RTCDec % 10U); uint8_t u8RTCData = (((u8RTCDec / 10U) % 10U) << 4U) + (u8RTCDec % 10U);
return u8RTCData; return u8RTCData;
} }
/**************************************************************************/ /**
* \brief Determine if a year is leap year
* \param Year: the year to be determined
* \retval \arg 0: Not leap year
* \arg 1: Leap year
******************************************************************************/
static uint8_t RTC_Determine_Leap_Year(uint16_t Year)
{
uint16_t u16RTCLeapYear = Year;
/*u16RTCLeapYear = ((Year >> 4) & 0x0F) * 10 + (Year & 0x0F);*/
if (u16RTCLeapYear & 0x0003U)
{
u16RTCLeapYear = 0U;
}
else
{
u16RTCLeapYear = 1U;
}
return (uint8_t)u16RTCLeapYear;
}
static void RTC_Stop(void) static void RTC_Stop(void)
{ {
uint16_t u16RTCCount = 0U;
/*Stop sub-counter */ /*Stop sub-counter */
RTCA0CE = 0U; RTCA0CE = 0U;
/*Wait sub-counter stop*/ /*Wait sub-counter stop*/
while (RTCA0CEST != 0) while ((RTCA0CEST != 0) && (u16RTCCount < RTC_TIME_OUT_COUNT))
{ {
; u16RTCCount++;
} }
} }
void RTC_Pre_Init(void) void RTC_Pre_Init(void)
{ {
uint16_t u16RTCCount = 0U;
RTC_Stop(); /* Stop RTCA*/ RTC_Stop(); /* Stop RTCA*/
#if (RTC_MODE_SELECT == RTC_MODE_MAIN) #if (RTC_MODE_SELECT == RTC_MODE_MAIN)
...@@ -80,56 +59,58 @@ void RTC_Pre_Init(void) ...@@ -80,56 +59,58 @@ void RTC_Pre_Init(void)
/*Starts sub-counter*/ /*Starts sub-counter*/
RTCA0CE = 1U; RTCA0CE = 1U;
u16RTCCount = 0U;
/*Wait sub-counter enable*/ /*Wait sub-counter enable*/
while (RTCA0CEST != 1U) while ((RTCA0CEST != 1U) && (u16RTCCount < RTC_TIME_OUT_COUNT))
{ {
; u16RTCCount++;
} }
} }
void RTC_Set_Time(RTC_Information_st_t *pstRTCTime) void RTC_Set_Time(uint8_t year, uint8_t month, uint16_t day, uint8_t hour, uint8_t minute, uint8_t second)
{ {
while (RTCA0WST != 0U) /*Check that all clock counters are running.*/ uint16_t u16RTCCount = 0U;
while ((RTCA0WST != 0U) && (u16RTCCount < RTC_TIME_OUT_COUNT)) /*Check that all clock counters are running.*/
{ {
; u16RTCCount++;
} }
RTCA0WAIT = 1U; /*Stop all clock counters*/ RTCA0WAIT = 1U; /*Stop all clock counters*/
while (RTCA0WST != 1U) /*Wait all clock counters stop*/ u16RTCCount = 0U;
while ((RTCA0WST != 1U) && (u16RTCCount < RTC_TIME_OUT_COUNT)) /*Wait all clock counters stop*/
{ {
; u16RTCCount++;
} }
/*Write start values*/ /*Write start values*/
RTCA0YEAR = RTC_Dec_To_BCD(pstRTCTime->u8RTCYear); RTCA0YEAR = RTC_Dec_To_BCD(year);
RTCA0MONTH = RTC_Dec_To_BCD(pstRTCTime->u8RTCMonth); RTCA0MONTH = RTC_Dec_To_BCD(month);
RTCA0DAY = RTC_Dec_To_BCD(pstRTCTime->u8RTCDayOfMonth); RTCA0DAY = RTC_Dec_To_BCD(day);
RTCA0HOUR = RTC_Dec_To_BCD(pstRTCTime->u8RTCHour); RTCA0HOUR = RTC_Dec_To_BCD(hour);
RTCA0MIN = RTC_Dec_To_BCD(pstRTCTime->u8RTCMinute); RTCA0MIN = RTC_Dec_To_BCD(minute);
RTCA0SEC = RTC_Dec_To_BCD(pstRTCTime->u8RTCSecond); RTCA0SEC = RTC_Dec_To_BCD(second);
/*Start all clock counters*/ /*Start all clock counters*/
RTCA0WAIT = 0U; RTCA0WAIT = 0U;
while (RTCA0WST != 0U) /*Check that all clock counters are running.*/ u16RTCCount = 0U;
while ((RTCA0WST != 0U) && (u16RTCCount < RTC_TIME_OUT_COUNT)) /*Check that all clock counters are running.*/
{ {
; u16RTCCount++;
} }
} }
/**************************************************************************/ /**
* \brief Rreal time clock timing control void RTC_Get_Time(void)
* \attention Call this function every 100 ms.
* \retval None
******************************************************************************/
void RTC_Timing_Service(void)
{ {
uint16_t u16RTCCount = 0U;
uint8_t Week = 0 ; uint8_t Week = 0 ;
while (RTCA0WST != 0U) /*Check that all clock counters are running.*/
while ((RTCA0WST != 0U) && (u16RTCCount < RTC_TIME_OUT_COUNT)) /*Check that all clock counters are running.*/
{ {
; u16RTCCount++;
} }
RTCA0WAIT = 1U; /*Stop all clock counters*/ RTCA0WAIT = 1U; /*Stop all clock counters*/
while (RTCA0WST != 1U) /*Wait all clock counters stop*/ u16RTCCount = 0U;
while ((RTCA0WST != 1U) && (u16RTCCount < RTC_TIME_OUT_COUNT)) /*Wait all clock counters stop*/
{ {
; u16RTCCount++;
} }
/*Read data*/ /*Read data*/
g_stRTCInformation.u8RTCYear = RTC_BCD_To_Dec(RTCA0YEAR); g_stRTCInformation.u8RTCYear = RTC_BCD_To_Dec(RTCA0YEAR);
...@@ -139,27 +120,60 @@ void RTC_Timing_Service(void) ...@@ -139,27 +120,60 @@ void RTC_Timing_Service(void)
g_stRTCInformation.u8RTCMinute = RTC_BCD_To_Dec(RTCA0MIN); g_stRTCInformation.u8RTCMinute = RTC_BCD_To_Dec(RTCA0MIN);
g_stRTCInformation.u8RTCSecond = RTC_BCD_To_Dec(RTCA0SEC); g_stRTCInformation.u8RTCSecond = RTC_BCD_To_Dec(RTCA0SEC);
Week = Cal_RTC_Week(g_stRTCInformation.u8RTCYear, g_stRTCInformation.u8RTCMonth, g_stRTCInformation.u8RTCDayOfMonth); Week = Cal_RTC_Week(g_stRTCInformation.u8RTCYear, g_stRTCInformation.u8RTCMonth, g_stRTCInformation.u8RTCDayOfMonth);
g_stRTCInformation.u8RTCWeek = Week ; g_stRTCInformation.u8RTCWeek = Week ;
g_RTCLeapYear = RTC_Determine_Leap_Year(g_stRTCInformation.u8RTCYear);
/*Start all clock counters*/ /*Start all clock counters*/
RTCA0WAIT = 0U; RTCA0WAIT = 0U;
while (RTCA0WST != 0U) /*Check that all clock counters are running.*/ u16RTCCount = 0U;
while ((RTCA0WST != 0U) && (u16RTCCount < RTC_TIME_OUT_COUNT)) /*Check that all clock counters are running.*/
{ {
; u16RTCCount++;
} }
} }
void RTC_Init(void)
#pragma ghs section bss=".NonInitArea"
RTC_Information_st_t RtcBackup;
#pragma ghs section bss=default
void RTC_Backup_Time(void)
{ {
RTC_Timing_Service(); RTC_Get_Time();
memcpy((uint8_t*)&RtcBackup, (uint8_t*)&g_stRTCInformation, sizeof (RtcBackup));
} }
void Rtc_Restore_Time(void)
{
uint16_t u16RTCCount = 0U;
RTC_Stop(); /* Stop RTCA*/
#if (RTC_MODE_SELECT == RTC_MODE_MAIN)
RTCA0SLSB = 1U; /*Frequency selection mode*/
RTCA0SCMP = 4000000U - 1U; /*4M*/
#else
RTCA0SLSB = 0U; /*32.768 kHz mode*/
RTCA0SUBU = 0U; /*Reserved Later modified,Error Correction*/
#endif
/*计算 星期几*/ RTCA0AMPM = 1U; /*fix 24Hour Format*/
/*Write start values*/
RTCA0YEAR = RTC_Dec_To_BCD(RtcBackup.u8RTCYear);
RTCA0MONTH = RTC_Dec_To_BCD(RtcBackup.u8RTCMonth);
RTCA0DAY = RTC_Dec_To_BCD(RtcBackup.u8RTCDayOfMonth);
RTCA0HOUR = RTC_Dec_To_BCD(RtcBackup.u8RTCHour);
RTCA0MIN = RTC_Dec_To_BCD(RtcBackup.u8RTCMinute);
RTCA0SEC = RTC_Dec_To_BCD(RtcBackup.u8RTCSecond);
/*Starts sub-counter*/
RTCA0CE = 1U;
u16RTCCount = 0U;
/*Wait sub-counter enable*/
while ((RTCA0CEST != 1U) && (u16RTCCount < RTC_TIME_OUT_COUNT))
{
u16RTCCount++;
}
}
/* ڼ*/
static uint8_t Cal_RTC_Week(uint16_t Year, uint8_t Month, uint8_t Day) static uint8_t Cal_RTC_Week(uint16_t Year, uint8_t Month, uint8_t Day)
{ {
if (Month < 3) if (Month < 3)
......
#ifndef RTC_H__ #ifndef RTC_H__
#define RTC_H__ #define RTC_H__
#include "r_typedefs.h" #include "r_typedefs.h"
...@@ -7,8 +6,7 @@ ...@@ -7,8 +6,7 @@
#define RTC_MODE_SELECT RTC_MODE_MAIN #define RTC_MODE_SELECT RTC_MODE_MAIN
/* RTC default time setting */ //#ifndef RTC_DEFAULT_TIME
#ifndef RTC_DEFAULT_TIME
#define RTC_DEFAULT_TIME 1U #define RTC_DEFAULT_TIME 1U
#define RTC_DEFAULT_YEAR 21U #define RTC_DEFAULT_YEAR 21U
#define RTC_DEFAULT_MONTH 1U #define RTC_DEFAULT_MONTH 1U
...@@ -16,9 +14,7 @@ ...@@ -16,9 +14,7 @@
#define RTC_DEFAULT_HOUR 0U #define RTC_DEFAULT_HOUR 0U
#define RTC_DEFAULT_MINUTE 0U #define RTC_DEFAULT_MINUTE 0U
#define RTC_DEFAULT_SECOND 0U #define RTC_DEFAULT_SECOND 0U
//#endif
#endif
typedef struct typedef struct
{ {
uint8_t u8RTCYear; /*00~~99 in Dec*/ uint8_t u8RTCYear; /*00~~99 in Dec*/
...@@ -30,8 +26,7 @@ typedef struct ...@@ -30,8 +26,7 @@ typedef struct
uint8_t u8RTCWeek ; /*1~7 in Dec*/ uint8_t u8RTCWeek ; /*1~7 in Dec*/
} RTC_Information_st_t; } RTC_Information_st_t;
extern volatile uint8_t g_RTCLeapYear; /*1:LeapYear , 0:Not a leap year*/ extern RTC_Information_st_t g_stRTCInformation;
extern volatile RTC_Information_st_t g_stRTCInformation;
/* RTC exported time register */ /* RTC exported time register */
#define RTC_YEAR g_stRTCInformation.u8RTCYear #define RTC_YEAR g_stRTCInformation.u8RTCYear
...@@ -43,9 +38,12 @@ extern volatile RTC_Information_st_t g_stRTCInformation; ...@@ -43,9 +38,12 @@ extern volatile RTC_Information_st_t g_stRTCInformation;
#define RTC_WEEK g_stRTCInformation.u8RTCWeek #define RTC_WEEK g_stRTCInformation.u8RTCWeek
#define RTC_LEAP_YEAR g_RTCLeapYear #define RTC_LEAP_YEAR g_RTCLeapYear
extern void RTC_Pre_Init(void); extern void RTC_Pre_Init(void);
extern void RTC_Init(void); //extern void RTC_Set_Time(uint16_t day, uint8_t hour, uint8_t minute, uint8_t second);
extern void RTC_Set_Time(RTC_Information_st_t *pstRTCTime); extern void RTC_Set_Time(uint8_t year, uint8_t month, uint16_t day, uint8_t hour, uint8_t minute, uint8_t second);
extern void RTC_Timing_Service(void); extern void RTC_Get_Time(void);
extern void RTC_Backup_Time(void);
extern void Rtc_Restore_Time(void);
#endif #endif
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include "r_dev_api.h" #include "r_dev_api.h"
#include "r_sfma_api.h" #include "r_sfma_api.h"
#include "SFMA_APP.h" #include "SFMA_APP.h"
#include "Watchdog.h"
#include "GPIO.h"
#include "RTC.h"
#include "rh850_macros.h"
#define SYSPROTCMDD1 (INT32U)(0xfff87000) #define SYSPROTCMDD1 (INT32U)(0xfff87000)
#define SYSCKSC_ISFMAS_CTL (INT32U)(0xfff85340) #define SYSCKSC_ISFMAS_CTL (INT32U)(0xfff85340)
#define SYSCKSC_ISFMAD_CTL (INT32U)(0xfff85380) #define SYSCKSC_ISFMAD_CTL (INT32U)(0xfff85380)
...@@ -44,9 +50,10 @@ static void Flash_WaitNop(INT32U loopcount); ...@@ -44,9 +50,10 @@ static void Flash_WaitNop(INT32U loopcount);
static void Flash_WaitNop(INT32U loopcount) static void Flash_WaitNop(INT32U loopcount)
{ {
uint32_t i; uint32_t i;
WDT_Clear();
for (i = 0; i < loopcount; i++) for (i = 0; i < loopcount; i++)
{ {
WDT_Clear();
asm("nop"); asm("nop");
asm("nop"); asm("nop");
asm("nop"); asm("nop");
...@@ -63,6 +70,7 @@ static void Flash_WaitNop(INT32U loopcount) ...@@ -63,6 +70,7 @@ static void Flash_WaitNop(INT32U loopcount)
void TYW_FLASH_PreInit(void) void TYW_FLASH_PreInit(void)
{ {
uint16_t WhileCnts = 0;
r_sfma0_Error_t ret; r_sfma0_Error_t ret;
uint32_t ssldr = 0x00000000u; uint32_t ssldr = 0x00000000u;
uint32_t spbcr = 0x00000100u; uint32_t spbcr = 0x00000100u;
...@@ -91,26 +99,35 @@ void TYW_FLASH_PreInit(void) ...@@ -91,26 +99,35 @@ void TYW_FLASH_PreInit(void)
R_DEV_WRITE_PROT_REG(SYSPROTCMDD1, SYSCKSC_ISFMAD_CTL, 0X03);/* 4分频率 480M/4=120M BΦ */ R_DEV_WRITE_PROT_REG(SYSPROTCMDD1, SYSCKSC_ISFMAD_CTL, 0X03);/* 4分频率 480M/4=120M BΦ */
while (0x03u != R_DEV_READ_REG(32, SYSCKSC_ISFMAD_CTL)) {} while (0x03u != R_DEV_READ_REG(32, SYSCKSC_ISFMAD_CTL)) {}
regval = R_DEV_READ_REG(32, (0xF2FF0000ul + CMNSR));
if (0x1u != (regval & 0x1u)) {
RTC_Backup_Time();
TestBackupRam = 0xaabbccddu;
hardware_reset();
}
R_DEV_WRITE_REG(32, (0xF2FF0000ul + CMNCR), cmncr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + CMNCR), cmncr);
/* R_DEV_WRITE_REG(32, (0xF2FF0000ul + SSLDR), ssldr);*/ /* R_DEV_WRITE_REG(32, (0xF2FF0000ul + SSLDR), ssldr);*/
R_DEV_WRITE_REG(32, (0xF2FF0000ul + SPBCR), spbcr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + SPBCR), spbcr);
R_DEV_WRITE_REG(32, (0xF2FF0000ul + SPODLY), spodly); R_DEV_WRITE_REG(32, (0xF2FF0000ul + SPODLY), spodly);
R_DEV_WRITE_REG(32, (0xF2FF0000ul + CKDLY), ckdly); R_DEV_WRITE_REG(32, (0xF2FF0000ul + CKDLY), ckdly);
WhileCnts = 0;
while (0x1u != (regval & 0x1u)) while (0x1u != (regval & 0x1u))
{ {
if (WhileCnts++ >= 100) {
RTC_Backup_Time();
TestBackupRam = 0xaabbccddu;
hardware_reset();
}
WDT_Clear();
regval = R_DEV_READ_REG(32, (0xF2FF0000ul + CMNSR)); regval = R_DEV_READ_REG(32, (0xF2FF0000ul + CMNSR));
} }
} }
void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter) void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter)
{ {
uint16_t WhileCnts = 0;
r_sfma0_Error_t ret; r_sfma0_Error_t ret;
uint32_t ssldr = 0x00000000u; uint32_t ssldr = 0x00000000u;
uint32_t spbcr = 0x00000100u; uint32_t spbcr = 0x00000100u;
...@@ -240,8 +257,12 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter) ...@@ -240,8 +257,12 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter)
*/ */
drdrenr = 0x00000111ul;/* CONFIRMED FIX */ drdrenr = 0x00000111ul;/* CONFIRMED FIX */
regval = R_DEV_READ_REG(32, (0xF2FF0000ul + CMNSR));
regval = 0; if (0x1u != (regval & 0x1u)) {
RTC_Backup_Time();
TestBackupRam = 0xaabbccddu;
hardware_reset();
}
R_DEV_WRITE_REG(32, (0xF2FF0000ul + CMNCR ), cmncr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + CMNCR ), cmncr);
/* R_DEV_WRITE_REG(32, (0xF2FF0000ul + SSLDR ), ssldr);*/ /* R_DEV_WRITE_REG(32, (0xF2FF0000ul + SSLDR ), ssldr);*/
...@@ -253,8 +274,6 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter) ...@@ -253,8 +274,6 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter)
R_DEV_WRITE_REG(32, (0xF2FF0000ul + SMENR ), smenr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + SMENR ), smenr);
R_DEV_WRITE_REG(32, (0xF2FF0000ul + SMCR ), smcr ); R_DEV_WRITE_REG(32, (0xF2FF0000ul + SMCR ), smcr );
R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRCR ), drcr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRCR ), drcr);
R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRCMR ), drcmr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRCMR ), drcmr);
R_DEV_WRITE_REG(32, (0xF2FF0000ul + DREAR ), drear); R_DEV_WRITE_REG(32, (0xF2FF0000ul + DREAR ), drear);
...@@ -263,9 +282,15 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter) ...@@ -263,9 +282,15 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter)
R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRDMCR ), drdmcr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRDMCR ), drdmcr);
R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRDRENR), drdrenr); R_DEV_WRITE_REG(32, (0xF2FF0000ul + DRDRENR), drdrenr);
WhileCnts = 0;
while (0x1u != (regval & 0x1u)) while (0x1u != (regval & 0x1u))
{ {
if (WhileCnts++ >= 100) {
RTC_Backup_Time();
TestBackupRam = 0xaabbccddu;
hardware_reset();
}
WDT_Clear();
regval = R_DEV_READ_REG(32, (0xF2FF0000ul + CMNSR)); regval = R_DEV_READ_REG(32, (0xF2FF0000ul + CMNSR));
} }
...@@ -273,14 +298,15 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter) ...@@ -273,14 +298,15 @@ void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter)
} }
#pragma ghs section bss=".NonInitArea"
uint32_t i_count;
uint32_t TestBackupRam;
#pragma ghs section bss=default
void TYW_FLASH_Init(void) void TYW_FLASH_Init(void)
{ {
uint32_t TEMP[2]; uint32_t TEMP[2];
FLASH_MANUFACTURER_ID_t FlashType; FLASH_MANUFACTURER_ID_t FlashType;
SFMA_DDR_Parameter_t SFMA_Parameter; SFMA_DDR_Parameter_t SFMA_Parameter;
uint32_t i_count;
i_count=0; i_count=0;
Total_Begin: Total_Begin:
i_count++; i_count++;
...@@ -288,13 +314,15 @@ Total_Begin: ...@@ -288,13 +314,15 @@ Total_Begin:
{ {
goto End_Begin; goto End_Begin;
} }
Flash_WaitNop(60); Flash_WaitNop(1000);
TYW_FLASH_PreInit(); TYW_FLASH_PreInit();
FlashType = SPI_NOR_Init(); FlashType = SPI_NOR_Init();
switch (FlashType) switch (FlashType)
{ {
case SPANSION: case SPANSION:
SFMA_Parameter.DTR_CMD = 0xEE;
SFMA_Parameter.DTR_MF0_7 = 0xff;
SFMA_Parameter.DTR_DummyCycle = 0x08;
break; break;
case WINBOND: case WINBOND:
SFMA_Parameter.DTR_CMD = 0xED; SFMA_Parameter.DTR_CMD = 0xED;
...@@ -314,16 +342,16 @@ Total_Begin: ...@@ -314,16 +342,16 @@ Total_Begin:
break; break;
} }
TYW_FLASH_DDRPreInit(&SFMA_Parameter); TYW_FLASH_DDRPreInit(&SFMA_Parameter);
Flash_WaitNop(60); Flash_WaitNop(1000);
TEMP[0] = ((*((volatile uint32_t *)((0x10000000u))))); TEMP[0] = ((*((volatile uint32_t *)((0x10000000u)))));
TEMP[1] = ((*((volatile uint32_t *)((0x10000004u))))); TEMP[1] = ((*((volatile uint32_t *)((0x10000004u)))));
if ((TEMP[0] != 0x50415247) && (TEMP[1] != 0x50415f45)) if ((TEMP[0] != 0x50415247) || (TEMP[1] != 0x50415f45))
{ {
goto Total_Begin; goto Total_Begin;
} }
End_Begin: End_Begin:
i_count=0; //i_count=0;
} }
#ifndef TYW_FLASH_H #ifndef TYW_FLASH_H
#define TYW_FLASH_H #define TYW_FLASH_H
#include"stdint.h" //#include"stdint.h"
#include "r_typedefs.h"
typedef enum typedef enum
...@@ -32,5 +33,7 @@ void TYW_FLASH_Init(void); ...@@ -32,5 +33,7 @@ void TYW_FLASH_Init(void);
void TYW_FLASH_PreInit(void); void TYW_FLASH_PreInit(void);
void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter); void TYW_FLASH_DDRPreInit(SFMA_DDR_Parameter_t *DDR_Parameter);
extern uint32_t TestBackupRam;
#endif #endif
\ No newline at end of file
...@@ -55,10 +55,11 @@ CONSTANTS ...@@ -55,10 +55,11 @@ CONSTANTS
MEMORY MEMORY
{ {
iROM_0 : ORIGIN = 0x00000000, LENGTH = 5120k iROM_0 : ORIGIN = 0x00200400, LENGTH = 2048k
iRAM_0 : ORIGIN = 0xFEB80000, LENGTH = 512k /* RAM addres space seen by external bus masters */ iRAM_0 : ORIGIN = 0xFEB80000, LENGTH = 512k /* RAM addres space seen by external bus masters */
iRAM_1 : ORIGIN = 0xFED80000, LENGTH = 512k /* local RAM address space */ iRAM_1 : ORIGIN = 0xFED80000, LENGTH = 512k /* local RAM address space */
iRAM_R : ORIGIN = 0x3FCE4000, LENGTH = 16k iRAM_R0 : ORIGIN = 0x3FCE4000, LENGTH = 1k
iRAM_R : ORIGIN = 0x3FCE4400, LENGTH = 16k
} }
SECTIONS SECTIONS
...@@ -67,7 +68,7 @@ SECTIONS ...@@ -67,7 +68,7 @@ SECTIONS
/* Start of internal ROM area (iROM_0) */ /* Start of internal ROM area (iROM_0) */
.intvect :>iROM_0 /* start of interrupt vector */ .intvect :>iROM_0 /* start of interrupt vector */
.intvect_end 0x00000600 :>. /* end of interrupt vector */ .intvect_end 0x200a00 :>. /* end of interrupt vector */
.text align(4) :>. /* program code area */ .text align(4) :>. /* program code area */
...@@ -111,6 +112,7 @@ SECTIONS ...@@ -111,6 +112,7 @@ SECTIONS
/* Start of internal retention RAM area (iRAM_R) */ /* Start of internal retention RAM area (iRAM_R) */
.absinitarea align(4) NOCLEAR :>iRAM_R0
.rdata align(4) :>iRAM_R /* user defined segment for for initialized data located in retention RAM */ .rdata align(4) :>iRAM_R /* user defined segment for for initialized data located in retention RAM */
.rbss align(4) :>. /* user defined segment for zero initialized data located in retention RAM */ .rbss align(4) :>. /* user defined segment for zero initialized data located in retention RAM */
.NonInitArea align(4) NOCLEAR :>. /* non initalised are in the BURAM */ .NonInitArea align(4) NOCLEAR :>. /* non initalised are in the BURAM */
......
...@@ -82,6 +82,11 @@ void Sys_Startup_Pre_Init(void) ...@@ -82,6 +82,11 @@ void Sys_Startup_Pre_Init(void)
* \attention * \attention
* \retval None * \retval None
******************************************************************************/ ******************************************************************************/
uint8_t u8ResetFlag = 0;
extern uint32_t u32ResetFlag;
extern uint32_t TestBackupRam;
void Sys_Startup_Init(void) void Sys_Startup_Init(void)
{ {
Clock_Init(); Clock_Init();
...@@ -97,7 +102,7 @@ void Sys_Startup_Init(void) ...@@ -97,7 +102,7 @@ void Sys_Startup_Init(void)
CPU_Init(); CPU_Init();
RTC_Init(); //RTC_Init();
Sys_Tick_Timer_Start(); Sys_Tick_Timer_Start();
/*COM_CAN_Init(); Ô­CAN³õʼ»¯Î»ÖÃ*/ /*COM_CAN_Init(); Ô­CAN³õʼ»¯Î»ÖÃ*/
...@@ -117,10 +122,26 @@ void Sys_Startup_Init(void) ...@@ -117,10 +122,26 @@ void Sys_Startup_Init(void)
ReadDTCEOLValue_Meter_K_LINE(); ReadDTCEOLValue_Meter_K_LINE();
d_printf("Init complete!\n"); d_printf("Init complete!\n");
InitSeriFlashExternReadMode(); InitSeriFlashExternReadMode();
/*30电数据初始化*/ //APP_Startup_Init(Clock_Get_Startup_Mode());
APP_Startup_Init(Clock_Get_Startup_Mode()); u8ResetFlag = Clock_Get_Startup_Mode();
if (u32ResetFlag != 0xA55AA55AUL)
{
u8ResetFlag = 0;
}
else
{
if ((u8ResetFlag == 0) && (TestBackupRam == 0xaabbccddu))
{
u8ResetFlag = 1;
Rtc_Restore_Time();
}
}
/*30电初始化*/
APP_Startup_Init(u8ResetFlag);
TestBackupRam = 0x11223344UL;
/*外发要用到EEP数据,位置移动*/ /*外发要用到EEP数据,位置移动*/
COM_CAN_Init(); COM_CAN_Init();
Gfx_Sys_Start(); Gfx_Sys_Start();
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
#include "r_typedefs.h" #include "r_typedefs.h"
#include "sys_scheduler.h" #include "sys_scheduler.h"
#include "Watchdog.h" #include "Watchdog.h"
extern uint32_t u32ResetFlag;
int main(void) int main(void)
{ {
Sys_Init(); Sys_Init();
while (1U) while (1U)
{ {
u32ResetFlag = 0xA55AA55AUL;
Sys_Scheduling_Service(); Sys_Scheduling_Service();
WDT_Clear(); WDT_Clear();
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment