dummy RTC

This commit is contained in:
Takashi Kojo
2018-01-01 12:18:08 +09:00
committed by Takashi Kojo
parent a429f5ef98
commit 379c6d0ad8
6 changed files with 317 additions and 130 deletions

View File

@@ -28,8 +28,20 @@
#include "wolfcrypt/test/test.h"
#include <time.h>
#warning "write MPU specific Set ups\n"
/* Dummy definition for test RTC */
#define RTC_YEAR 2018
#define RTC_MONTH 1
#define RTC_DAY 1
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
#include "stm32f2xx_hal.h"
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
@@ -42,18 +54,22 @@ static void CPU_CACHE_Enable (void) {
}
extern uint32_t os_time;
#ifdef RTE_CMSIS_RTOS_RTX
extern uint32_t os_time;
static time_t epochTime;
uint32_t HAL_GetTick(void) {
return os_time;
return os_time;
}
#endif
time_t time(time_t *t){
return os_time ;
return epochTime ;
}
void setTime(time_t t){
epochTime = t;
}
#endif
#ifdef WOLFSSL_CURRTIME_OSTICK
@@ -124,9 +140,11 @@ int main()
HAL_Init(); /* Initialize the HAL Library */
SystemClock_Config(); /* Configure the System Clock */
#if !defined(NO_FILESYSTEM)
#if !defined(NO_FILESYSTEM)
init_filesystem ();
#endif
#endif
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
printf("=== Start: Crypt Benchmark ===\n") ;
benchmark_test(arg) ;

View File

@@ -28,9 +28,22 @@
#include "wolfcrypt/test/test.h"
#include <stdio.h>
#include <time.h>
/* Dummy definition for test RTC */
#define RTC_YEAR 2018
#define RTC_MONTH 1
#define RTC_DAY 1
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
#include "stm32f2xx_hal.h"
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
@@ -43,6 +56,53 @@ static void CPU_CACHE_Enable (void) {
}
#ifdef RTE_CMSIS_RTOS_RTX
extern uint32_t os_time;
static time_t epochTime;
uint32_t HAL_GetTick(void) {
return os_time;
}
time_t time(time_t *t){
return epochTime ;
}
void setTime(time_t t){
epochTime = t;
}
#endif
#ifdef WOLFSSL_CURRTIME_OSTICK
#include <stdint.h>
extern uint32_t os_time;
double current_time(int reset)
{
if(reset) os_time = 0 ;
return (double)os_time /1000.0;
}
#else
#include <stdint.h>
#define DWT ((DWT_Type *) (0xE0001000UL) )
typedef struct
{
uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
} DWT_Type;
extern uint32_t SystemCoreClock ;
double current_time(int reset)
{
if(reset) DWT->CYCCNT = 0 ;
return ((double)DWT->CYCCNT/SystemCoreClock) ;
}
#endif
/*-----------------------------------------------------------------------------
* Initialize a Flash Memory Card
*----------------------------------------------------------------------------*/
@@ -68,13 +128,14 @@ static void init_filesystem (void) {
}
#endif
/*-----------------------------------------------------------------------------
* mian entry
*----------------------------------------------------------------------------*/
int main()
{
void * arg = NULL ;
MPU_Config();
CPU_CACHE_Enable();
HAL_Init(); /* Initialize the HAL Library */
@@ -84,6 +145,8 @@ int main()
init_filesystem ();
#endif
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
printf("=== Start: Crypt test === \n") ;
wolfcrypt_test(arg) ;
printf("=== End: Crypt test ===\n") ;

View File

@@ -23,39 +23,66 @@
#include <config.h>
#endif
#include <wolfssl/wolfcrypt/visibility.h>
#include <wolfssl/wolfcrypt/logging.h>
#include "wolfssl/wolfcrypt/settings.h"
#include "cmsis_os.h" /* CMSIS RTOS definitions */
#include "rl_net.h" /* Network definitions */
#include <time.h>
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
#include "stm32f2xx_hal.h"
#include "cmsis_os.h"
#include "rl_net.h"
#include <stdio.h>
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
#include <wolfssl/ssl.h>
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
// <h>RTC: for validate certificate date
// <o>Year <1970-2099>
#define RTC_YEAR 2018
// <o>Month <1=>Jan<2=>Feb<3=>Mar<4=>Apr<5=>May<6=>Jun<7=>Jul<8=>Aut<9=>Sep<10=>Oct<11=>Nov<12=>Dec
#define RTC_MONTH 1
// <o>Day <1-31>
#define RTC_DAY 1
// </h>
//------------- <<< end of configuration section >>> -----------------------
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
static void MPU_Config (void) {
}
static void CPU_CACHE_Enable (void) {
/*-----------------------------------------------------------------------------
* Initialize Clock Configuration
*----------------------------------------------------------------------------*/
void SystemClock_Config(void) {
#warning "write MPU specific System Clock Set up\n"
}
/*-----------------------------------------------------------------------------
* Initialize a Flash Memory Card
*----------------------------------------------------------------------------*/
#if !defined(NO_FILESYSTEM)
#include "rl_fs.h"
#include "rl_fs.h" /* FileSystem definitions */
static void init_filesystem (void) {
int32_t retv;
retv = finit ("M0:");
if (retv == 0) {
if (retv == fsOK) {
retv = fmount ("M0:");
if (retv == 0) {
if (retv == fsOK) {
printf ("Drive M0 ready!\n");
}
else {
printf ("Drive M0 mount failed!\n");
printf ("Drive M0 mount failed(%d)!\n", retv);
}
}
else {
@@ -64,6 +91,68 @@ static void init_filesystem (void) {
}
#endif
void net_loop(void const *arg)
{
while(1) {
net_main ();
osThreadYield ();
}
}
osThreadDef(net_loop, osPriorityNormal, 2, 0);
#ifdef RTE_CMSIS_RTOS_RTX
extern uint32_t os_time;
static time_t epochTime;
uint32_t HAL_GetTick(void) {
return os_time;
}
time_t time(time_t *t){
return epochTime ;
}
void setTime(time_t t){
epochTime = t;
}
#endif
#ifdef WOLFSSL_CURRTIME_OSTICK
#include <stdint.h>
extern uint32_t os_time;
double current_time(int reset)
{
if(reset) os_time = 0 ;
return (double)os_time /1000.0;
}
#else
#include <stdint.h>
#define DWT ((DWT_Type *) (0xE0001000UL) )
typedef struct
{
uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
} DWT_Type;
extern uint32_t SystemCoreClock ;
double current_time(int reset)
{
if(reset) DWT->CYCCNT = 0 ;
return ((double)DWT->CYCCNT/SystemCoreClock) ;
}
#endif
/*----------------------------------------------------------------------------
Main Thread 'main': Run Network
*---------------------------------------------------------------------------*/
#include <stdio.h>
typedef struct func_args {
int argc;
char** argv;
@@ -71,30 +160,38 @@ typedef struct func_args {
extern void echoclient_test(func_args * args) ;
/*-----------------------------------------------------------------------------
* mian entry
*----------------------------------------------------------------------------*/
int myoptind = 0;
char* myoptarg = NULL;
int main()
{
func_args args ;
args.argc = 1 ;
int main (void) {
static char *argv[] =
{ "client" } ;
static func_args args =
{ 1, argv } ;
MPU_Config(); /* Configure the MPU */
CPU_CACHE_Enable(); /* Enable the CPU Cache */
HAL_Init(); /* Initialize the HAL Library */
SystemClock_Config(); /* Configure the System Clock */
SystemClock_Config ();
#if !defined(NO_FILESYSTEM)
init_filesystem ();
#endif
netInitialize() ;
osDelay(300) ;
net_initialize ();
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n") ;
wolfSSL_Debugging_ON() ;
#endif
printf("Starting EchoClient, Enter messages to EchoServer (\"quit\" to quit the program)\n") ;
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
osThreadCreate (osThread(net_loop), NULL);
echoclient_test(&args) ;
printf("End of EchoClient\n") ;
while(1)
osDelay(1000);
}

View File

@@ -29,6 +29,15 @@
#include "rl_net.h" /* Network definitions */
#include <time.h>
#ifdef WOLFSSL_STM32_CUBEMX
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
#include "stm32f2xx_hal.h"
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
#endif
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
@@ -61,6 +70,19 @@
//------------- <<< end of configuration section >>> -----------------------
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
static void MPU_Config (void) {
}
static void CPU_CACHE_Enable (void) {
}
/*-----------------------------------------------------------------------------
* Initialize a Flash Memory Card
@@ -98,23 +120,23 @@ void net_loop(void const *arg)
osThreadDef(net_loop, osPriorityLow, 2, 0);
extern uint32_t os_time;
static time_t epoctime = 0;
#ifdef RTE_CMSIS_RTOS_RTX
extern uint32_t os_time;
static time_t epochTime;
uint32_t HAL_GetTick(void) {
return os_time;
return os_time;
}
#endif
time_t time(time_t *t){
return epoctime ;
return epochTime ;
}
void setTime(time_t t){
epoctime = t;;
epochTime = t;
}
#endif
#ifdef WOLFSSL_CURRTIME_OSTICK
@@ -161,10 +183,7 @@ int myoptind = 0;
char* myoptarg = NULL;
int main (void) {
struct tm *tm_gm;
time_t now;
static char *argv[] =
static char *argv[] =
{ "server" } ;
static func_args args = { 1, argv } ;
@@ -173,21 +192,18 @@ int main (void) {
HAL_Init(); /* Initialize the HAL Library */
SystemClock_Config(); /* Configure the System Clock */
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
now = time(NULL);
tm_gm = gmtime(&now);
printf("RTC=%04d/%02d/%02d\n", tm_gm->tm_year + 1900, tm_gm->tm_mon + 1, tm_gm->tm_mday);
#if !defined(NO_FILESYSTEM)
init_filesystem ();
#endif
net_initialize ();
#if defined(DEBUG_WOLFSSL)
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n") ;
wolfSSL_Debugging_ON() ;
#endif
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
osThreadCreate (osThread(net_loop), NULL);
echoserver_test(&args) ;

View File

@@ -29,7 +29,13 @@
#include "rl_net.h" /* Network definitions */
#include <time.h>
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
#include "stm32f2xx_hal.h"
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
@@ -39,7 +45,7 @@
// <s.15>IP Address
// <i>Static IPv4 Address
// <i>Default: "192.168.1.1"
#define REMOTE_IP "192.168.1.1"
#define REMOTE_IP "192.168.10.4"
// <s.6>Port
// <i> Default: "11111"
@@ -66,9 +72,7 @@
// </h>
//------------- <<< end of configuration section >>> -----------------------
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
@@ -81,6 +85,7 @@ static void CPU_CACHE_Enable (void) {
}
/*-----------------------------------------------------------------------------
* Initialize a Flash Memory Card
*----------------------------------------------------------------------------*/
@@ -115,25 +120,24 @@ void net_loop(void const *arg)
}
}
osThreadDef(net_loop, osPriorityNormal, 2, 0);
extern uint32_t os_time;
static time_t epoctime = 0;
osThreadDef(net_loop, osPriorityLow, 2, 0);
#ifdef RTE_CMSIS_RTOS_RTX
extern uint32_t os_time;
static time_t epochTime;
uint32_t HAL_GetTick(void) {
return os_time;
return os_time;
}
#endif
time_t time(time_t *t){
return epoctime ;
return epochTime ;
}
void setTime(time_t t){
epoctime = t;;
epochTime = t;
}
#endif
#ifdef WOLFSSL_CURRTIME_OSTICK
@@ -142,8 +146,8 @@ extern uint32_t os_time;
double current_time(int reset)
{
if(reset) os_time = 0 ;
return (double)os_time /1000.0;
if(reset) os_time = 0 ;
return (double)os_time /1000.0;
}
#else
@@ -160,8 +164,8 @@ extern uint32_t SystemCoreClock ;
double current_time(int reset)
{
if(reset) DWT->CYCCNT = 0 ;
return ((double)DWT->CYCCNT/SystemCoreClock) ;
if(reset) DWT->CYCCNT = 0 ;
return ((double)DWT->CYCCNT/SystemCoreClock) ;
}
#endif
@@ -180,53 +184,45 @@ int myoptind = 0;
char* myoptarg = NULL;
int main (void) {
struct tm *tm_gm;
time_t now;
static char *argv[] =
{ "client", "-h", REMOTE_IP, "-p", REMOTE_PORT,
static char *argv[] =
{ "client", "-h", REMOTE_IP, "-p", REMOTE_PORT,
"-v", " ", OTHER_OPTIONS } ;
static func_args args =
{ sizeof(argv)/sizeof(*argv[0]), argv } ;
static func_args args =
{ sizeof(argv)/sizeof(*argv[0]), argv } ;
char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"};
#define VERSIZE 2
char ver[VERSIZE];
char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"};
#define VERSIZE 2
char ver[VERSIZE];
MPU_Config(); /* Configure the MPU */
CPU_CACHE_Enable(); /* Enable the CPU Cache */
HAL_Init(); /* Initialize the HAL Library */
SystemClock_Config(); /* Configure the System Clock */
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
now = time(NULL);
tm_gm = gmtime(&now);
printf("RTC=%04d/%02d/%02d\n", tm_gm->tm_year + 1900, tm_gm->tm_mon + 1, tm_gm->tm_mday);
#if !defined(NO_FILESYSTEM)
init_filesystem ();
#endif
net_initialize ();
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n") ;
wolfSSL_Debugging_ON() ;
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n") ;
wolfSSL_Debugging_ON() ;
#endif
snprintf(ver, VERSIZE, "%d", TLS_VER);
argv[6] = ver;
printf("SSL/TLS Client(%d)\n ", sizeof(argv)/sizeof(argv[0])) ;
printf("SSL/TLS Client(%d)\n ", sizeof(argv)/sizeof(argv[0])) ;
printf(" Remote IP: %s, Port: %s\n Version: %s\n", argv[2], argv[4], verStr[TLS_VER]) ;
printf(" Other options: %s\n", OTHER_OPTIONS);
setTime((time_t)((RTC_YEAR-1970)*365*24*60*60) + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
osThreadCreate (osThread(net_loop), NULL);
osThreadCreate (osThread(net_loop), NULL);
client_test(&args) ;
while(1)
osDelay(1000);
while(1)
osDelay(1000);
}

View File

@@ -29,6 +29,13 @@
#include "rl_net.h" /* Network definitions */
#include <time.h>
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
#include "stm32f2xx_hal.h"
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
@@ -62,7 +69,6 @@
//------------- <<< end of configuration section >>> -----------------------
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
@@ -111,23 +117,22 @@ void net_loop(void const *arg)
osThreadDef(net_loop, osPriorityLow, 2, 0);
extern uint32_t os_time;
static time_t epoctime = 0;
#ifdef RTE_CMSIS_RTOS_RTX
extern uint32_t os_time;
static time_t epochTime;
uint32_t HAL_GetTick(void) {
return os_time;
return os_time;
}
#endif
time_t time(time_t *t){
return epoctime ;
return epochTime ;
}
void setTime(time_t t){
epoctime = t;;
epochTime = t;
}
#endif
#ifdef WOLFSSL_CURRTIME_OSTICK
@@ -154,8 +159,8 @@ extern uint32_t SystemCoreClock ;
double current_time(int reset)
{
if(reset) DWT->CYCCNT = 0 ;
return ((double)DWT->CYCCNT/SystemCoreClock) ;
if(reset) DWT->CYCCNT = 0 ;
return ((double)DWT->CYCCNT/SystemCoreClock) ;
}
#endif
@@ -174,38 +179,29 @@ int myoptind = 0;
char* myoptarg = NULL;
int main (void) {
static char *argv[] =
{ "server", "-p", SERVER_PORT,
"-v", " ", OTHER_OPTIONS } ;
static func_args args =
{ sizeof(argv)/sizeof(*argv[0]), argv } ;
struct tm *tm_gm;
time_t now;
static char *argv[] =
{ "server", "-p", SERVER_PORT,
"-v", " ", OTHER_OPTIONS } ;
static func_args args =
{ sizeof(argv)/sizeof(*argv[0]), argv } ;
char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"};
#define VERSIZE 2
char ver[VERSIZE];
char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"};
#define VERSIZE 2
char ver[VERSIZE];
MPU_Config(); /* Configure the MPU */
CPU_CACHE_Enable(); /* Enable the CPU Cache */
HAL_Init(); /* Initialize the HAL Library */
SystemClock_Config(); /* Configure the System Clock */
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
now = time(NULL);
tm_gm = gmtime(&now);
printf("RTC=%04d/%02d/%02d\n", tm_gm->tm_year + 1900, tm_gm->tm_mon + 1, tm_gm->tm_mday);
#if !defined(NO_FILESYSTEM)
init_filesystem ();
#endif
net_initialize ();
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n") ;
wolfSSL_Debugging_ON() ;
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n") ;
wolfSSL_Debugging_ON() ;
#endif
snprintf(ver, VERSIZE, "%d", TLS_VER);
@@ -214,6 +210,7 @@ int main (void) {
printf("SSL/TLS Server\n ") ;
printf(" Server Port: %s\n Version: %s\n", argv[2], verStr[TLS_VER]) ;
printf(" Other options: %s\n", OTHER_OPTIONS);
setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
osThreadCreate (osThread(net_loop), NULL);