Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
3bf5fea4
Commit
3bf5fea4
authored
Mar 19, 2020
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev/sdb-storage: new API to support multiple board-specific calibration parameters
parent
c2d19b30
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
6 deletions
+166
-6
sdb-storage.c
dev/sdb-storage.c
+131
-6
storage.h
include/storage.h
+35
-0
No files found.
dev/sdb-storage.c
View file @
3bf5fea4
...
...
@@ -623,13 +623,137 @@ int storage_match_sfp(struct s_sfpinfo *sfp)
return
0
;
}
/*
* Phase transition ("calibration" file)
*/
#define VALIDITY_BIT 0x80000000
static
wrc_cal_data_t
cal_data
;
static
int
calc_checksum
(
wrc_cal_data_t
*
cal
)
{
int
i
;
uint32_t
cksum
;
cksum
+=
cal
->
magic
;
cksum
+=
cal
->
param_count
;
for
(
i
=
0
;
i
<
cal
->
param_count
;
i
++
)
{
cksum
+=
cal
->
params
[
i
].
id
;
cksum
+=
cal
->
params
[
i
].
value
;
}
return
cksum
;
}
int
storage_load_calibration
(
void
)
{
int
ret
=
0
;
cal_data
.
param_count
=
0
;
if
(
sdbfs_open_id
(
&
wrc_sdb
,
SDB_VENDOR
,
SDB_DEV_CALIB
)
<
0
)
{
pp_printf
(
"%s: can't open cal file
\n
"
,
__FUNCTION__
);
return
-
1
;
}
if
(
sdbfs_fread
(
&
wrc_sdb
,
0
,
&
cal_data
,
sizeof
(
cal_data
))
!=
sizeof
(
cal_data
))
{
ret
=
-
1
;
cal_data
.
param_count
=
0
;
goto
out_close
;
}
if
(
cal_data
.
magic
!=
CAL_FILE_MAGIC
)
{
pp_printf
(
"%s: invalid magic
\n
"
,
__FUNCTION__
);
cal_data
.
param_count
=
0
;
ret
=
-
1
;
goto
out_close
;
}
if
(
cal_data
.
checksum
!=
calc_checksum
(
&
cal_data
))
{
pp_printf
(
"%s: invalid checksum
\n
"
,
__FUNCTION__
);
cal_data
.
param_count
=
0
;
ret
=
-
1
;
goto
out_close
;
}
out_close:
sdbfs_close
(
&
wrc_sdb
);
return
ret
;
}
int
storage_save_calibration
(
void
)
{
int
ret
=
0
;
cal_data
.
magic
=
CAL_FILE_MAGIC
;
if
(
sdbfs_open_id
(
&
wrc_sdb
,
SDB_VENDOR
,
SDB_DEV_CALIB
)
<
0
)
{
pp_printf
(
"%s: can't open cal file
\n
"
,
__FUNCTION__
);
return
-
1
;
}
cal_data
.
checksum
=
calc_checksum
(
&
cal_data
);
sdbfs_ferase
(
&
wrc_sdb
,
0
,
wrc_sdb
.
f_len
);
if
(
sdbfs_fwrite
(
&
wrc_sdb
,
0
,
&
cal_data
,
sizeof
(
cal_data
))
!=
sizeof
(
cal_data
))
goto
out_close
;
out_close:
sdbfs_close
(
&
wrc_sdb
);
return
ret
;
}
int
storage_get_calibration_parameter
(
int
id
,
uint32_t
*
valp
)
{
int
i
;
for
(
i
=
0
;
i
<
cal_data
.
param_count
;
i
++
)
{
if
(
id
==
cal_data
.
params
[
i
].
id
)
{
*
valp
=
cal_data
.
params
[
i
].
value
;
return
0
;
}
}
return
-
1
;
}
int
storage_set_calibration_parameter
(
int
id
,
uint32_t
val
)
{
int
i
;
for
(
i
=
0
;
i
<
cal_data
.
param_count
;
i
++
)
{
if
(
id
==
cal_data
.
params
[
i
].
id
)
{
cal_data
.
params
[
i
].
value
=
val
;
return
0
;
}
}
if
(
cal_data
.
param_count
>=
CAL_MAX_PARAMS
)
return
-
1
;
cal_data
.
params
[
cal_data
.
param_count
].
id
=
id
;
cal_data
.
params
[
cal_data
.
param_count
].
value
=
val
;
cal_data
.
param_count
++
;
}
wrc_cal_data_t
*
storage_get_calibration_data
(
void
)
{
return
&
cal_data
;
}
// FIXME: migrate to new API
int
storage_phtrans
(
uint32_t
*
valp
,
uint8_t
write
)
{
int
ret
=
-
1
;
/*
int ret = -1;
uint32_t value;
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_CALIB) < 0)
...
...
@@ -650,7 +774,8 @@ int storage_phtrans(uint32_t *valp, uint8_t write)
}
out:
sdbfs_close(&wrc_sdb);
return
ret
;
return ret;*/
return
0
;
}
/*
...
...
include/storage.h
View file @
3bf5fea4
...
...
@@ -11,6 +11,22 @@
#include "sfp.h"
// calibration parameter definitions. Board-specific.
#define CAL_MAX_PARAMS 8
#define CAL_FILE_MAGIC 0xcafebabe
#define ASCII_TO_U32(a, b, c, d) ((((uint32_t)(a)&0xff) << 24) | \
(((uint32_t)(b)&0xff) << 16) | \
(((uint32_t)(c)&0xff) << 8) | \
(((uint32_t)(d)&0xff) << 16))
#define CAL_PARAM_T24P ASCII_TO_U32('t', '2', '4', 'p')
#define CAL_PARAM_PHY_TARGET_TX_PHASE ASCII_TO_U32('l', 'p', 't', 'p')
#define CAL_PARAM_DDS_LO_IOUPDATE_DELAY_PS ASCII_TO_U32('e', '1', '4', '0')
#define CAL_PARAM_DDS_REF_IOUPDATE_DELAY_PS ASCII_TO_U32('e', '1', '4', '1')
#define CAL_PARAM_CLKA_SYNC_DELAY_PS ASCII_TO_U32('e', '1', '4', '2')
#define CAL_PARAM_CLKB_SYNC_DELAY_PS ASCII_TO_U32('e', '1', '4', '3')
#define SFP_SECTION_PATTERN 0xdeadbeef
#if defined CONFIG_LEGACY_EEPROM
...
...
@@ -63,6 +79,19 @@ struct s_sfpinfo {
uint8_t
chksum
;
}
__attribute__
((
__packed__
));
typedef
struct
{
uint32_t
magic
;
uint32_t
param_count
;
uint32_t
checksum
;
struct
{
uint32_t
id
;
uint32_t
value
;
}
params
[
CAL_MAX_PARAMS
];
}
wrc_cal_data_t
;
void
storage_init
(
struct
i2c_bus
*
bus
,
int
i2c_addr
);
int
storage_sfpdb_erase
(
void
);
...
...
@@ -98,4 +127,10 @@ int storage_sdbfs_erase(int mem_type, uint32_t base_adr, uint32_t blocksize,
int
storage_gensdbfs
(
int
mem_type
,
uint32_t
base_adr
,
uint32_t
blocksize
,
uint8_t
i2c_adr
);
int
storage_load_calibration
(
void
);
int
storage_save_calibration
(
void
);
int
storage_get_calibration_parameter
(
int
id
,
uint32_t
*
valp
);
int
storage_set_calibration_parameter
(
int
id
,
uint32_t
val
);
wrc_cal_data_t
*
storage_get_calibration_data
(
void
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment