Skip to content

Commit

Permalink
Merge branch 'feature/emulator_actual_emb' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
divanchykhin committed Jun 4, 2015
2 parents 8d85248 + 6f33b3c commit 3e7ab3a
Show file tree
Hide file tree
Showing 61 changed files with 10,659 additions and 2,984 deletions.
1 change: 1 addition & 0 deletions tests/emulator/build-cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcc sa-aes-128.c hal/win-lnx-common/sa-commlayer.c sa-eax-128.c hal/win-lnx-common/sa-eeprom.c hal/win-lnx-common/sa-hal-time-provider.c saccp_protocol.c sagdp_protocol.c saoudp_protocol.c sasp_protocol.c sa_client_comm_stack.c test-counters.c test-generator.c zepto-mem-mngmt.c -D USED_AS_MASTER -D USED_AS_MASTER_COMMSTACK -o ../cs.bin
1 change: 1 addition & 0 deletions tests/emulator/build-cu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcc hal/win-lnx-common/sa-commlayer.c sa_client_central_unit.c sa_test_control_prog.c test-counters.c test-generator.c zepto-mem-mngmt.c -D USED_AS_MASTER -D USED_AS_MASTER_CORE -o ../cu.bin
1 change: 1 addition & 0 deletions tests/emulator/build-slv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcc sa-aes-128.c hal/win-lnx-common/sa-commlayer.c sa-eax-128.c hal/win-lnx-common/sa-eeprom.c hal/win-lnx-common/sa-hal-time-provider.c saccp_protocol.c sagdp_protocol.c saoudp_protocol.c sasp_protocol.c sa_server.c sa_test_plugins.c test-counters.c test-generator.c yoctovm_protocol.c zepto-mem-mngmt.c -o ../slv.bin
30 changes: 30 additions & 0 deletions tests/emulator/hal/hal-eeprom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#if !defined __HAL_EEPROM_H__
#define __HAL_EEPROM_H__

#include "../sa-common.h"


// calls
bool hal_init_eeprom_access();
bool hal_eeprom_write( const uint8_t* data, uint16_t size, uint16_t address );
bool hal_eeprom_read( uint8_t* data, uint16_t size, uint16_t address);
void hal_eeprom_flush();

#endif // __HAL_EEPROM_H__
44 changes: 26 additions & 18 deletions tests/emulator/sa-commlayer.h → tests/emulator/hal/hal-waiting.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,29 @@ Copyright (C) 2015 OLogN Technologies AG
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#if !defined __SA_COMMLAYER_H__
#define __SA_COMMLAYER_H__


// RET codes
#define COMMLAYER_RET_FAILED 0 // not authenticated, etc
#define COMMLAYER_RET_OK 1 // new packet
#define COMMLAYER_RET_PENDING 2


bool communicationInitializeAsServer();
bool communicationInitializeAsClient();
void communicationTerminate();
uint8_t sendMessage( uint16_t* msgSize, const uint8_t * buff );
uint8_t getMessage( uint16_t* msgSize, uint8_t * buff, int maxSize ); // returns when a packet received
uint8_t tryGetMessage(uint16_t* msgSize, uint8_t * buff, int maxSize); // returns immediately, but a packet reception is not guaranteed

#endif // __SA_COMMLAYER_H__
#if !defined __SA_HAL_WAITING_H__
#define __SA_HAL_WAITING_H__

#include "../sa-common.h"
#include "sa-hal-time-provider.h"

typedef struct _waiting_for
{
sa_time_val wait_time;
uint8_t wait_packet;
uint8_t wait_i2c;
uint8_t wait_legs;
uint16_t leg_mask; // [in]
uint16_t leg_values_waited; // [in]
uint16_t leg_value_received; // [out]
} waiting_for;

#define WAIT_RESULTED_IN_FAILURE 0
#define WAIT_RESULTED_IN_TIMEOUT 1
#define WAIT_RESULTED_IN_PACKET 2
#define WAIT_RESULTED_IN_I2C 3
#define WAIT_RESULTED_IN_PINS 4

uint8_t hal_wait_for( waiting_for* wf );

#endif // __SA_HAL_WAITING_H__
58 changes: 58 additions & 0 deletions tests/emulator/hal/sa-commlayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#if !defined __SA_COMMLAYER_H__
#define __SA_COMMLAYER_H__

#include "../sa-common.h"
#include "zepto-mem-mngmt-hal-spec.h"
#include "../zepto-mem-mngmt.h"

bool communication_initialize();
void communication_terminate();


// RET codes
#define COMMLAYER_RET_FAILED 0
#define COMMLAYER_RET_OK 1
#define COMMLAYER_RET_PENDING 2

#define COMMLAYER_RET_FROM_CENTRAL_UNIT 10
#define COMMLAYER_RET_FROM_DEV 11
#define COMMLAYER_RET_TIMEOUT 12

#define COMMLAYER_RET_FROM_COMMM_STACK 10



uint8_t sendMessage( MEMORY_HANDLE mem_h );

//uint8_t wait_for_communication_event( MEMORY_HANDLE mem_h, uint16_t timeout );
//uint8_t wait_for_communication_event( uint16_t timeout );
#ifdef USED_AS_MASTER
#ifdef USED_AS_MASTER_COMMSTACK
uint8_t send_to_central_unit( MEMORY_HANDLE mem_h );
#elif defined USED_AS_MASTER_CORE
uint8_t send_to_commm_stack( MEMORY_HANDLE mem_h );
#else
#error unknown configuration
#endif
#endif



#endif // __SA_COMMLAYER_H__
61 changes: 61 additions & 0 deletions tests/emulator/hal/sa-hal-time-provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#if !defined __SA_HAL_TIME_PROVIDER_H__
#define __SA_HAL_TIME_PROVIDER_H__

#include "../sa-common.h"
#include <hal-time-convertions.h>

typedef struct _sa_time_struct
{
uint16_t low_t;
uint16_t high_t;
} sa_time_struct;
// NOTE: the struct above is not to be used directly
// use typedef below instead
typedef sa_time_struct sa_time_val;

#define TIME_MILLISECONDS16_TO_TIMEVAL( mslow, timeval ) HAL_TIME_MILLISECONDS16_TO_TIMEVAL( mslow, timeval )
#define TIME_MILLISECONDS32_TO_TIMEVAL( mslow, mshigh, timeval ) HAL_TIME_MILLISECONDS32_TO_TIMEVAL( mslow, mshigh, timeval )

void sa_get_time( sa_time_val* t ); // PLATFORM-SPECIFIC IMPLEMENTATION



// operations (to be added upon necessity)

INLINE void sa_hal_time_val_copy_from( sa_time_val* t1, const sa_time_val* t2 )
{
t1->high_t = t2->high_t;
t1->low_t = t2->low_t;
}

INLINE bool sa_hal_time_val_is_less( sa_time_val* t1, sa_time_val* t2 )
{
if ( t1->high_t < t2->high_t ) return true;
if ( t1->high_t > t2->high_t ) return false;
return t1->low_t < t2->low_t;
}

#define SA_TIME_LOAD_TICKS_FOR_1_SEC( x ) {(x).low_t = 1000; (x).high_t = 0;}
#define SA_TIME_INCREMENT_BY_TICKS( x, y ) {(x).low_t += (y).low_t; (x).high_t += (y).high_t; (x).high_t += (x).low_t < (y).low_t ? 1 : 0;}
#define SA_TIME_SUBTRACT_TICKS_OR_ZERO( x, y ) {if ( sa_hal_time_val_is_less( &(x), (y) ) ) {(x).low_t = 0; (x).high_t = 0;} else {(x).low_t -= (y).low_t; (x).high_t -= (y).high_t; (x).high_t -= (x).low_t < (y).low_t ? 1 : 0;} }
#define SA_TIME_MUL_TICKS_BY_2( x ) {uint16_t tmp = ((x).low_t) >> 15; (x).low_t <<= 1; (x).high_t = ((x).high_t << 1) | tmp;}
#define SA_TIME_MUL_TICKS_BY_1_AND_A_HALF( x ) {uint16_t lo = (x).low_t, hi = (x).high_t; uint16_t tmp = ((x).high_t) & 1; (x).low_t >>= 15; (x).low_t |= tmp << 15; (x).high_t = ((x).high_t << 1) | tmp; (x).low_t += lo; (x).high_t += hi; (x).high_t += (x).low_t < lo ? 1 : 0;}

#endif // __SA_HAL_TIME_PROVIDER_H__
116 changes: 116 additions & 0 deletions tests/emulator/hal/win-lnx-common/hal-eeprom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*******************************************************************************
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#include "../hal-eeprom.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#ifdef _MSC_VER
#include <windows.h>
#include <io.h>
#endif


// Interface is implemented based on file IO
// File has a standard name

//FILE* f = NULL;
int efile = -1;
#ifdef _MSC_VER
HANDLE hfile = INVALID_HANDLE_VALUE;
#endif

bool hal_init_eeprom_access()
{
// f = fopen( MASTER_SLAVE_BIT == 1 ? "sa-eeprom-master": "sa-eeprom-slave", "rw+b" );
efile = open( MASTER_SLAVE_BIT == 1 ? "sa-eeprom-master": "sa-eeprom-slave.dat", O_RDWR | O_CREAT | O_BINARY, S_IWRITE | S_IREAD );
#ifdef _MSC_VER
hfile = (HANDLE) _get_osfhandle (efile);
if ( hfile == INVALID_HANDLE_VALUE )
return false;
#endif
return efile != -1;
}

bool hal_eeprom_write( const uint8_t* data, uint16_t size, uint16_t address )
{
int res;
res = lseek( efile, address, SEEK_SET);
if ( res == -1 )
return false;
res = write( efile, data, size );
if ( res != size )
return false;
return true;
}

bool hal_eeprom_read( uint8_t* data, uint16_t size, uint16_t address)
{
int res;
res = lseek( efile, address, SEEK_SET);
if ( res == -1 )
return false;
res = read( efile, data, size );
if ( res != size )
return false;
return true;
}

void hal_eeprom_flush()
{
#ifdef _MSC_VER
FlushFileBuffers(hfile);
#else
fsync( efile );
#endif
}

/*
void eeprom_write( uint8_t id, uint8_t* data, uint8_t size)
{
char filename[256];
prepareFileName( filename, id );
FILE* f = fopen( filename, "wb" );
assert( f );
int written = fwrite( data, 1, size, f );
assert( written == size );
fclose( f );
}
void eeprom_read_fixed_size( uint8_t id, uint8_t* data, uint8_t size)
{
char filename[256];
prepareFileName( filename, id );
FILE* f = fopen( filename, "rb" );
assert( f );
int retrieved = fread ( data, 1, size, f );
assert( retrieved == size );
fclose( f );
}
uint8_t eeprom_read_size( uint8_t id )
{
char filename[256];
prepareFileName( filename, id );
FILE* f = fopen( filename, "wb" );
assert( f );
fseek ( f, 0, SEEK_END );
int size = ftell( f );
fclose( f );
return size;
}
*/
27 changes: 27 additions & 0 deletions tests/emulator/hal/win-lnx-common/hal-time-convertions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#if !defined __HAL_TIME_CONVERTIONS_H__
#define __HAL_TIME_CONVERTIONS_H__

// present implementation assumes that resolution of h/w timer is 1 ms
// macros below must be reimplemented if this is not the case
#define HAL_TIME_MILLISECONDS16_TO_TIMEVAL( mslow, timeval ) {(timeval).low_t = (mslow); (timeval).high_t = 0;}
#define HAL_TIME_MILLISECONDS32_TO_TIMEVAL( mslow, mshigh, timeval ) {(timeval).low_t = (mslow); (timeval).high_t = mshigh;}


#endif // __HAL_TIME_CONVERTIONS_H__
Loading

0 comments on commit 3e7ab3a

Please sign in to comment.