-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emulator actual embodiment: update of hal-related code
- Loading branch information
1 parent
6cae114
commit 9153783
Showing
7 changed files
with
264 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
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_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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters