diff --git a/.gitignore b/.gitignore index e4c4d2d48..d16360a27 100644 --- a/.gitignore +++ b/.gitignore @@ -81,11 +81,9 @@ cov-int cyassl.tgz *.log *.trs -IDE\MDK-ARM\Projects/ -IDE\MDK-ARM\STM32F2xx_StdPeriph_Lib/inc -IDE\MDK-ARM\STM32F2xx_StdPeriph_Lib/src IDE\MDK-ARM\LPC43xx\Drivers/ IDE\MDK-ARM\LPC43xx\LPC43xx/ *.gcno *.gcda *.gcov + diff --git a/IDE/MDK-ARM/MDK-ARM/CyaSSL/Retarget.c b/IDE/MDK-ARM/MDK-ARM/CyaSSL/Retarget.c index 00aaef181..bb59c8ce1 100644 --- a/IDE/MDK-ARM/MDK-ARM/CyaSSL/Retarget.c +++ b/IDE/MDK-ARM/MDK-ARM/CyaSSL/Retarget.c @@ -259,11 +259,3 @@ void _sys_exit (int return_code) } -/*--------------------------- time -----------------------------------------*/ -long time(long *t) -{ - return ((long) 0) ; /** DUMMY TIME() **/ -} -/*----------------------------------------------------------------------------- - * end of file - *----------------------------------------------------------------------------*/ diff --git a/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvopt b/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvopt index e93e9595f..eb6599f1e 100644 --- a/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvopt +++ b/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvopt @@ -532,10 +532,10 @@ 1 0 0 - 0 + 5 0 - 0 - 0 + 19 + 32 0 ..\..\..\ctaocrypt\test\test.c test.c @@ -642,122 +642,10 @@ STM32F2xx_StdPeriph_Lib - 0 + 1 0 0 0 - - 2 - 10 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_cryp.c - stm32f2xx_cryp.c - 0 - 0 - - - 2 - 11 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_hash.c - stm32f2xx_hash.c - 0 - 0 - - - 2 - 12 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rcc.c - stm32f2xx_rcc.c - 0 - 0 - - - 2 - 13 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rng.c - stm32f2xx_rng.c - 0 - 0 - - - 2 - 14 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rtc.c - stm32f2xx_rtc.c - 0 - 0 - - - 2 - 15 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_pwr.c - stm32f2xx_pwr.c - 0 - 0 - - - 2 - 16 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_tim.c - stm32f2xx_tim.c - 0 - 0 - @@ -768,7 +656,7 @@ 0 3 - 17 + 10 1 0 0 @@ -784,7 +672,7 @@ 3 - 18 + 11 1 0 0 @@ -800,7 +688,7 @@ 3 - 19 + 12 4 0 0 @@ -816,7 +704,7 @@ 3 - 20 + 13 4 0 0 @@ -832,7 +720,7 @@ 3 - 21 + 14 1 0 0 @@ -848,7 +736,7 @@ 3 - 22 + 15 4 0 0 @@ -864,7 +752,7 @@ 3 - 23 + 16 4 0 0 @@ -880,7 +768,7 @@ 3 - 24 + 17 1 0 0 @@ -904,7 +792,7 @@ 0 4 - 25 + 18 1 0 0 @@ -920,7 +808,7 @@ 4 - 26 + 19 1 0 0 @@ -936,7 +824,7 @@ 4 - 27 + 20 1 0 0 @@ -952,7 +840,7 @@ 4 - 28 + 21 1 0 0 @@ -968,7 +856,7 @@ 4 - 29 + 22 1 0 0 @@ -984,7 +872,7 @@ 4 - 30 + 23 1 0 0 @@ -1000,7 +888,7 @@ 4 - 31 + 24 1 0 0 @@ -1016,7 +904,7 @@ 4 - 32 + 25 1 0 0 @@ -1032,7 +920,7 @@ 4 - 33 + 26 1 0 0 @@ -1056,7 +944,7 @@ 0 5 - 34 + 27 1 0 0 @@ -1072,7 +960,7 @@ 5 - 35 + 28 1 0 0 @@ -1088,7 +976,7 @@ 5 - 36 + 29 1 0 0 @@ -1104,7 +992,7 @@ 5 - 37 + 30 1 0 0 @@ -1120,7 +1008,7 @@ 5 - 38 + 31 1 0 0 @@ -1136,7 +1024,7 @@ 5 - 39 + 32 1 0 0 @@ -1152,7 +1040,7 @@ 5 - 40 + 33 1 0 0 @@ -1168,7 +1056,7 @@ 5 - 41 + 34 1 0 0 @@ -1184,7 +1072,7 @@ 5 - 42 + 35 1 0 0 @@ -1200,7 +1088,7 @@ 5 - 43 + 36 1 0 0 @@ -1216,7 +1104,7 @@ 5 - 44 + 37 1 0 0 @@ -1232,7 +1120,7 @@ 5 - 45 + 38 1 0 0 @@ -1248,7 +1136,7 @@ 5 - 46 + 39 1 0 0 @@ -1264,7 +1152,7 @@ 5 - 47 + 40 1 0 0 @@ -1280,7 +1168,7 @@ 5 - 48 + 41 1 0 0 @@ -1296,7 +1184,7 @@ 5 - 49 + 42 1 0 0 @@ -1312,7 +1200,7 @@ 5 - 50 + 43 1 0 0 @@ -1328,7 +1216,7 @@ 5 - 51 + 44 1 0 0 @@ -1344,7 +1232,7 @@ 5 - 52 + 45 1 0 0 @@ -1360,7 +1248,7 @@ 5 - 53 + 46 1 0 0 @@ -1376,7 +1264,7 @@ 5 - 54 + 47 1 0 0 @@ -1392,7 +1280,23 @@ 5 - 55 + 48 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\ctaocrypt\src\port.c + port.c + 0 + 0 + + + 5 + 49 1 0 0 @@ -1408,7 +1312,7 @@ 5 - 56 + 50 1 0 0 @@ -1424,7 +1328,7 @@ 5 - 57 + 51 1 0 0 @@ -1440,7 +1344,7 @@ 5 - 58 + 52 1 0 0 @@ -1456,7 +1360,7 @@ 5 - 59 + 53 1 0 0 @@ -1472,7 +1376,7 @@ 5 - 60 + 54 1 0 0 @@ -1488,7 +1392,7 @@ 5 - 61 + 55 1 0 0 @@ -1504,7 +1408,7 @@ 5 - 62 + 56 1 0 0 @@ -1520,7 +1424,7 @@ 5 - 63 + 57 1 0 0 @@ -1534,22 +1438,6 @@ 0 0 - - 5 - 64 - 1 - 0 - 0 - 9 - 0 - 0 - 0 - 0 - ..\..\..\ctaocrypt\src\port.c - port.c - 0 - 0 - @@ -1560,7 +1448,7 @@ 0 6 - 65 + 58 1 0 0 @@ -1576,7 +1464,7 @@ 6 - 66 + 59 1 0 0 @@ -1592,7 +1480,7 @@ 6 - 67 + 60 5 0 0 @@ -1608,7 +1496,7 @@ 6 - 68 + 61 1 0 0 @@ -1624,7 +1512,7 @@ 6 - 69 + 62 1 0 0 @@ -1640,7 +1528,7 @@ 6 - 70 + 63 5 0 0 @@ -1656,7 +1544,7 @@ 6 - 71 + 64 5 0 0 @@ -1672,7 +1560,7 @@ 6 - 72 + 65 5 0 0 @@ -1688,14 +1576,14 @@ 6 - 73 + 66 2 0 0 0 0 - 0 - 0 + 156 + 169 0 ..\MDK-ARM\config\startup_stm32f2xx.s startup_stm32f2xx.s @@ -1712,14 +1600,14 @@ 0 7 - 74 + 67 1 0 0 0 0 - 0 - 0 + 1 + 1 0 ..\MDK-ARM\CyaSSL\cyassl_MDK_ARM.c cyassl_MDK_ARM.c @@ -1728,14 +1616,14 @@ 7 - 75 + 68 1 - 0 + 1 0 0 0 - 0 - 0 + 194 + 262 0 ..\MDK-ARM\CyaSSL\Retarget.c Retarget.c @@ -1744,14 +1632,14 @@ 7 - 76 + 69 1 0 0 - 0 + 1 0 - 0 - 0 + 36 + 52 0 ..\STM32F2xx_StdPeriph_Lib\time-STM32F2xx.c time-STM32F2xx.c diff --git a/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvproj b/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvproj index 7f2501b14..7d4f33359 100644 --- a/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvproj +++ b/IDE/MDK-ARM/Projects/MDK-ARM-STM32F2xx.uvproj @@ -349,7 +349,7 @@ 0 - HAVE_CONFIG_H CYASSL_STM32F2xx __DBG_ITM __RTX USE_STDPERIPH_DRIVER MDK_CONF_RTX_TCP_FS + HAVE_CONFIG_H CYASSL_STM32F2xx __DBG_ITM __RTX MDK_CONF_RTX_TCP_FS ..\MDK-ARM\CyaSSL;C:..\STM32F2xx_StdPeriph_Lib\inc;..\..\..\ @@ -441,43 +441,6 @@ STM32F2xx_StdPeriph_Lib - - - stm32f2xx_cryp.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_cryp.c - - - stm32f2xx_hash.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_hash.c - - - stm32f2xx_rcc.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rcc.c - - - stm32f2xx_rng.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rng.c - - - stm32f2xx_rtc.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rtc.c - - - stm32f2xx_pwr.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_pwr.c - - - stm32f2xx_tim.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_tim.c - - MDK-ARM @@ -1539,43 +1502,6 @@ STM32F2xx_StdPeriph_Lib - - - stm32f2xx_cryp.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_cryp.c - - - stm32f2xx_hash.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_hash.c - - - stm32f2xx_rcc.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rcc.c - - - stm32f2xx_rng.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rng.c - - - stm32f2xx_rtc.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rtc.c - - - stm32f2xx_pwr.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_pwr.c - - - stm32f2xx_tim.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_tim.c - - MDK-ARM @@ -1914,6 +1840,11 @@ 1 ..\..\..\ctaocrypt\src\misc.c + + port.c + 1 + ..\..\..\ctaocrypt\src\port.c + pwdbased.c 1 @@ -1959,11 +1890,6 @@ 1 ..\..\..\ctaocrypt\src\tfm.c - - port.c - 1 - ..\..\..\ctaocrypt\src\port.c - @@ -2753,43 +2679,6 @@ STM32F2xx_StdPeriph_Lib - - - stm32f2xx_cryp.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_cryp.c - - - stm32f2xx_hash.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_hash.c - - - stm32f2xx_rcc.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rcc.c - - - stm32f2xx_rng.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rng.c - - - stm32f2xx_rtc.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_rtc.c - - - stm32f2xx_pwr.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_pwr.c - - - stm32f2xx_tim.c - 1 - ..\STM32F2xx_StdPeriph_Lib\src\stm32f2xx_tim.c - - MDK-ARM @@ -3266,6 +3155,11 @@ 1 ..\..\..\ctaocrypt\src\misc.c + + port.c + 1 + ..\..\..\ctaocrypt\src\port.c + pwdbased.c 1 @@ -3351,11 +3245,6 @@ - - port.c - 1 - ..\..\..\ctaocrypt\src\port.c - diff --git a/IDE/MDK-ARM/STM32F2xx_StdPeriph_Lib/time-STM32F2xx.c b/IDE/MDK-ARM/STM32F2xx_StdPeriph_Lib/time-STM32F2xx.c index 66940453a..37154d136 100644 --- a/IDE/MDK-ARM/STM32F2xx_StdPeriph_Lib/time-STM32F2xx.c +++ b/IDE/MDK-ARM/STM32F2xx_StdPeriph_Lib/time-STM32F2xx.c @@ -24,109 +24,229 @@ #endif #include "time.h" -#include "stm32f2xx_tim.h" -#include "stm32f2xx_rcc.h" - +#define PERIPH_BASE ((uint32_t)0x40000000) /*----------------------------------------------------------------------------- * initialize RTC *----------------------------------------------------------------------------*/ -#include "stm32f2xx_rtc.h" -#include "stm32f2xx_rcc.h" -#include "stm32f2xx_pwr.h" +#include "stm32f2xx.h" -static init_RTC() +#define assert_param(a) + +#define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F) +#define SYNCHRO_TIMEOUT ((uint32_t) 0x00008000) +#define Bcd2ToByte(v) \ + ((((uint8_t)(v & (uint8_t)0xF0) >> (uint8_t)0x4) * 10) + (v & (uint8_t)0x0F)) +#define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F) +#define RTC_TR_MNT ((uint32_t)0x00007000) +#define RTC_TR_MNU ((uint32_t)0x00000F00) + +#define PWR_OFFSET (PWR_BASE - PERIPH_BASE) +#define CR_OFFSET (PWR_OFFSET + 0x00) +#define DBP_BitNumber 0x08 +#define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4)) +#define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF) +#define INITMODE_TIMEOUT ((uint32_t) 0x00010000) + +static void init_RTC() { - RTC_InitTypeDef RTC_InitStruct ; + __IO uint32_t initcounter = 0x00 ; + uint32_t initstatus = 0x00; /* Enable the PWR clock : RCC_APB1Periph_PWR */ + ((uint32_t *)RCC)[0x10] |= ((uint32_t)0x10000000) ; - RTC_TimeTypeDef RTC_Time ; - RTC_DateTypeDef RTC_Date ; - - - /* Enable the PWR clock */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); - /* Allow access to RTC */ - PWR_BackupAccessCmd(ENABLE); - -/***Configures the External Low Speed oscillator (LSE)****/ - - RCC_LSEConfig(RCC_LSE_ON); - + *(__IO uint32_t *) CR_DBP_BB = ENABLE ; + /* RCC_LSEConfig(RCC_LSE_ON) */ + *(__IO uint8_t *) (RCC_BASE + 0x70) = ((uint8_t)0x00); + /* Reset LSEBYP bit */ + *(__IO uint8_t *) (RCC_BASE + 0x70) = ((uint8_t)0x00); + *(__IO uint8_t *) (RCC_BASE + 0x70) = ((uint8_t)0x01); /* Wait till LSE is ready */ - while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) - { - } + while((RCC->BDCR << 0x2) == 0x0) { } + /* Select the RTC clock source: RCC_RTCCLKSource_LSE */ + ((RCC_TypeDef *)RCC)->BDCR |= (uint32_t)0x00000100; - /* Select the RTC Clock Source */ - RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); - /* Enable the RTC Clock */ - RCC_RTCCLKCmd(ENABLE); + *(__IO uint32_t *) (PERIPH_BB_BASE + (((RCC_BASE - PERIPH_BASE)+ 0x70) * 32) + (0x0F* 4)) = (uint32_t)ENABLE; - /* Wait for RTC APB registers synchronisation */ - RTC_WaitForSynchro(); + *(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE; + RTC->ISR = (uint32_t) RTC_INIT_MASK; + do { + initstatus = RTC->ISR & RTC_ISR_INITF; + initcounter++; + } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00)); + + /* Disable the write protection for RTC registers */ + RTC->WPR = 0xCA; + RTC->WPR = 0x53; - /* Calendar Configuration with LSI supposed at 32KHz */ - RTC_InitStruct.RTC_AsynchPrediv = 0x7F; - RTC_InitStruct.RTC_SynchPrediv = 0xFF; - RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24; - RTC_Init(&RTC_InitStruct); + RTC->CR &= ((uint32_t)~(RTC_CR_FMT)); /* Clear RTC CR FMT Bit */ + /* Set RTC_CR register */ + RTC->CR |= ((uint32_t)0x00000000) ; /* RTC_HourFormat_24 */ - RTC_GetTime(RTC_Format_BIN, &RTC_Time) ; - RTC_GetDate(RTC_Format_BIN, &RTC_Date) ; + /* Configure the RTC PRER */ + RTC->PRER = 0x7f ; + RTC->PRER |= (uint32_t)(0xff << 16); + + /* Exit Initialization mode */ + RTC->ISR &= (uint32_t)~RTC_ISR_INIT; + + /* Enable the write protection for RTC registers */ + RTC->WPR = 0xFF; } /*----------------------------------------------------------------------------- * initialize TIM *----------------------------------------------------------------------------*/ +#define RCC_APB1Periph_TIM2 ((uint32_t)0x00000001) + static void init_TIM() { - TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure ; + uint16_t tmpcr1 = 0; - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE) ; + ((uint32_t *)RCC)[0x10] |= RCC_APB1Periph_TIM2 ; - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Prescaler = 60; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; - TIM_TimeBaseStructure.TIM_Period = 0xffffffff; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; + tmpcr1 = TIM2->CR1 ; + tmpcr1 &= (uint16_t) (~(((uint16_t)0x0010) | ((uint16_t)0x0060) )); + /* CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS) */ + tmpcr1 |= (uint16_t)0x0000 ; /* CR1 |= TIM_CounterMode_Up */ + TIM2->CR1= tmpcr1 ; - TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); + TIM2->ARR = 0xffffffff ; /* ARR= TIM_Period */ + TIM2->PSC = 60 ; /* PSC = TIM_Prescaler */ + TIM2->EGR = ((uint16_t)0x0001) ; /* EGR = TIM_PSCReloadMode_Immediate */ - TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure) ; - TIM_Cmd(TIM2, ENABLE) ; + *(uint16_t *)(PERIPH_BASE+0x0) |=((uint16_t)0x0001) ; + /* TIM_Cmd(TIM2, ENABLE) ; */ } void init_time(void) { - init_RTC() ; + init_RTC() ; init_TIM() ; } +static void GetTime(uint8_t *h, uint8_t *m, uint8_t *s) +{ + uint32_t tmpreg = 0; + tmpreg = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK); + *h = (uint8_t)Bcd2ToByte((uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16)); + *m = (uint8_t)Bcd2ToByte((uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8)); + *s = (uint8_t)Bcd2ToByte((tmpreg & (RTC_TR_ST | RTC_TR_SU))); +} + +static uint32_t ByteToBcd2(uint8_t Value) +{ + uint8_t bcdhigh = 0; + while (Value >= 10) { + bcdhigh++; + Value -= 10; + } + return ((uint8_t)(bcdhigh << 4) | Value); +} + +static void SetTime(uint8_t h, uint8_t m, uint8_t s) +{ + __IO uint32_t synchrocounter = 0; + uint32_t synchrostatus = 0x00; + __IO uint32_t initcounter = 0; + uint32_t initstatus = 0x00; + uint32_t tmpreg ; + + tmpreg = ((ByteToBcd2(h) << 16) | (ByteToBcd2(m) << 8) | ByteToBcd2(s)) ; + /* Disable the write protection for RTC registers */ + RTC->WPR = 0xCA; + RTC->WPR = 0x53; + RTC->ISR &= (uint32_t)~RTC_ISR_INIT; + + RTC->ISR = (uint32_t)RTC_INIT_MASK; + + /* Wait till RTC is in INIT state and if Time out is reached exit */ + do { + initstatus = RTC->ISR & RTC_ISR_INITF; + initcounter++; + } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00)); + + RTC->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); + + RTC->ISR &= (uint32_t)RTC_RSF_MASK; + /* Wait the registers to be synchronised */ + do { + synchrostatus = RTC->ISR & RTC_ISR_RSF; + synchrocounter++; + } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00)); + + RTC->WPR = 0xFF; +} + +static void GetDate(uint8_t *y, uint8_t *m, uint8_t *d) +{ + uint32_t tmpreg = 0; + tmpreg = (uint32_t)(RTC->DR & RTC_TR_RESERVED_MASK); + *y = (uint8_t)Bcd2ToByte((uint8_t)((tmpreg & (RTC_DR_YT|RTC_DR_YU)) >>16)); + *m = (uint8_t)Bcd2ToByte((uint8_t)((tmpreg & (RTC_DR_MT|RTC_DR_MU)) >> 8)); + *d = (uint8_t)Bcd2ToByte((uint8_t)(tmpreg & (RTC_DR_DT |RTC_DR_DU))); +} + +static void SetDate(uint8_t y, uint8_t m, uint8_t d) +{ + __IO uint32_t synchrocounter = 0; + uint32_t synchrostatus = 0x00; + __IO uint32_t initcounter = 0; + uint32_t initstatus = 0x00; + uint32_t tmpreg = 0 ; + + tmpreg = ((ByteToBcd2(y) << 16) | (ByteToBcd2(m) << 8) | ByteToBcd2(d)) ; + /* Disable the write protection for RTC registers */ + RTC->WPR = 0xCA; + RTC->WPR = 0x53; + RTC->ISR &= (uint32_t)~RTC_ISR_INIT; + + RTC->ISR = (uint32_t)RTC_INIT_MASK; + + /* Wait till RTC is in INIT state and if Time out is reached exit */ + do { + initstatus = RTC->ISR & RTC_ISR_INITF; + initcounter++; + } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00)); + + RTC->DR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); + + RTC->ISR &= (uint32_t)RTC_RSF_MASK; + /* Wait the registers to be synchronised */ + do { + synchrostatus = RTC->ISR & RTC_ISR_RSF; + synchrocounter++; + } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00)); + + RTC->WPR = 0xFF; +} + + +#include +void CYASSL_MSG(const char *msg) ; + struct tm *Cyassl_MDK_gmtime(const time_t *c) { - - RTC_TimeTypeDef RTC_Time ; - RTC_DateTypeDef RTC_Date ; + uint8_t h, m, s ; + uint8_t y, mo, d ; static struct tm date ; - RTC_GetTime(RTC_Format_BIN, &RTC_Time) ; - RTC_GetDate(RTC_Format_BIN, &RTC_Date) ; + GetTime(&h, &m, &s) ; + GetDate(&y, &mo, &d) ; - date.tm_year = RTC_Date.RTC_Year + 100 ; - date.tm_mon = RTC_Date.RTC_Month - 1 ; - date.tm_mday = RTC_Date.RTC_Date ; - date.tm_hour = RTC_Time.RTC_Hours ; - date.tm_min = RTC_Time.RTC_Minutes ; - date.tm_sec = RTC_Time.RTC_Seconds ; + date.tm_year = y + 100 ; + date.tm_mon = mo - 1 ; + date.tm_mday = d ; + date.tm_hour = h ; + date.tm_min = m ; + date.tm_sec = s ; #if defined(DEBUG_CYASSL) { char msg[100] ; - sprintf(msg, "Debug::Cyassl_KEIL_gmtime(DATE=/%4d/%02d/%02d TIME=%02d:%02d:%02d)\n", - RTC_Date.RTC_Year+2000, RTC_Date.RTC_Month, RTC_Date.RTC_Date, - RTC_Time.RTC_Hours, RTC_Time.RTC_Minutes, RTC_Time.RTC_Seconds) ; + sprintf(msg, + "Debug::Cyassl_KEIL_gmtime(DATE=/%2d/%02d/%04d TIME=%02d:%02d:%02d)\n", + d, mo, y+2000, h, m, s) ; CYASSL_MSG(msg) ; } #endif @@ -138,48 +258,42 @@ double current_time() { return ((double)TIM2->CNT/1000000.0) ; } - -typedef struct func_args { - int argc; - char** argv; - int return_code; -} func_args; - - -#include - -void time_main(void *args) -{ - char * datetime ; - RTC_TimeTypeDef RTC_Time ; - RTC_DateTypeDef RTC_Date ; - int year ; - if( args == NULL || ((func_args *)args)->argc == 1) { - RTC_GetTime(RTC_Format_BIN, &RTC_Time) ; - RTC_GetDate(RTC_Format_BIN, &RTC_Date) ; - printf("Date: %d/%d/%d, Time: %02d:%02d:%02d\n", - RTC_Date.RTC_Month, RTC_Date.RTC_Date, RTC_Date.RTC_Year+2000, - RTC_Time.RTC_Hours, RTC_Time.RTC_Minutes, RTC_Time.RTC_Seconds) ; - } else if(((func_args *)args)->argc == 3 && - ((func_args *)args)->argv[1][0] == '-' && - ((func_args *)args)->argv[1][1] == 'd' ) { - datetime = ((func_args *)args)->argv[2]; - sscanf(datetime, "%d/%d/%d", - (int *)&RTC_Date.RTC_Month, (int *)&RTC_Date.RTC_Date, &year) ; - RTC_Date.RTC_Year = year - 2000 ; - RTC_Date.RTC_WeekDay = 0 ; - RTC_SetDate(RTC_Format_BIN, &RTC_Date) ; - } else if(((func_args *)args)->argc == 3 && - ((func_args *)args)->argv[1][0] == '-' && - ((func_args *)args)->argv[1][1] == 't' ) { - datetime = ((func_args *)args)->argv[2]; - sscanf(datetime, "%d:%d:%d", - (int *)&RTC_Time.RTC_Hours, - (int *)&RTC_Time.RTC_Minutes, - (int *)&RTC_Time.RTC_Seconds - ) ; - RTC_SetTime(RTC_Format_BIN, &RTC_Time) ; - } else printf("Invalid argument\n") ; -} + +typedef struct func_args { + int argc; + char** argv; + int return_code; +} func_args; + +void time_main(void *args) +{ + char * datetime ; + uint8_t h, m, s ; + uint8_t y, mo, d ; + + if( args == NULL || ((func_args *)args)->argc == 1) { + GetTime(&h, &m, &s) ; + GetDate(&y, &mo, &d) ; + printf("Date: %d/%d/%d, Time: %02d:%02d:%02d\n", + mo, d, y+2000, h, m, s) ; + } else if(((func_args *)args)->argc == 3 && + ((func_args *)args)->argv[1][0] == '-' && + ((func_args *)args)->argv[1][1] == 'd' ) { + datetime = ((func_args *)args)->argv[2]; + sscanf(datetime, "%d/%d/%d", (int *)&mo, (int *)&d, (int *) &y) ; + SetDate(y-2000, mo, d) ; + } else if(((func_args *)args)->argc == 3 && + ((func_args *)args)->argv[1][0] == '-' && + ((func_args *)args)->argv[1][1] == 't' ) { + datetime = ((func_args *)args)->argv[2]; + sscanf(datetime, "%d:%d:%d", + (int *)&h, (int *)&m, (int *)&s) ; + SetTime(h, m, s) ; + } else printf("Invalid argument\n") ; +} +/******************************************************************* + time() +********************************************************************/ +time_t time(time_t * t) { return 0 ; } diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index 24e3caf7c..8147bf87f 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -74,12 +74,6 @@ #include #endif -#if defined(CYASSL_MDK_ARM) - #include - #include - extern FILE * CyaSSL_fopen(const char *fname, const char *mode) ; - #define fopen CyaSSL_fopen -#endif #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) /* include test cert and key buffers for use with NO_FILESYSTEM */ @@ -92,6 +86,12 @@ #endif #endif +#if defined(CYASSL_MDK_ARM) + #include + #include + extern FILE * CyaSSL_fopen(const char *fname, const char *mode) ; + #define fopen CyaSSL_fopen +#endif #ifdef HAVE_NTRU #include "crypto_ntru.h" @@ -2471,23 +2471,24 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out) static const char* caKeyFile = "a:\\certs\\ca-key.der"; static const char* caCertFile = "a:\\certs\\ca-cert.pem"; #endif -#elif !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && defined(CYASSL_MKD_SHELL) - static char* clientKey = "certs/client-key.der"; - static char* clientCert = "certs/client-cert.der"; - void set_clientKey(char *key) { clientKey = key ; } /* set by shell command */ - void set_clientCert(char *cert) { clientCert = cert ; } /* set by shell command */ - #ifdef CYASSL_CERT_GEN - static char* caKeyFile = "certs/ca-key.der"; - static char* caCertFile = "certs/ca-cert.pem"; - void set_caKeyFile (char * key) { caKeyFile = key ; } /* set by shell command */ - void set_caCertFile(char * cert) { caCertFile = cert ; } /* set by shell command */ - #endif -#elif !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) - static const char* clientKey = "./certs/client-key.der"; - static const char* clientCert = "./certs/client-cert.der"; - #ifdef CYASSL_CERT_GEN - static const char* caKeyFile = "./certs/ca-key.der"; - static const char* caCertFile = "./certs/ca-cert.pem"; + #elif defined(CYASSL_MKD_SHELL) + static char* clientKey = "certs/client-key.der"; + static char* clientCert = "certs/client-cert.der"; + void set_clientKey(char *key) { clientKey = key ; } /* set by shell command */ + void set_clientCert(char *cert) { clientCert = cert ; } /* set by shell command */ + #ifdef CYASSL_CERT_GEN + static char* caKeyFile = "certs/ca-key.der"; + static char* caCertFile = "certs/ca-cert.pem"; + void set_caKeyFile (char * key) { caKeyFile = key ; } /* set by shell command */ + void set_caCertFile(char * cert) { caCertFile = cert ; } /* set by shell command */ + #endif + #else + static const char* clientKey = "./certs/client-key.der"; + static const char* clientCert = "./certs/client-cert.der"; + #ifdef CYASSL_CERT_GEN + static const char* caKeyFile = "./certs/ca-key.der"; + static const char* caCertFile = "./certs/ca-cert.pem"; + #endif #endif #endif @@ -2728,7 +2729,7 @@ int rsa_test(void) int pemSz; size_t bytes3; word32 idx3 = 0; - FILE* file3 ; + FILE* file3 ; #ifdef CYASSL_TEST_CERT DecodedCert decode; #endif