Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
ae6028c7
Commit
ae6028c7
authored
6 years ago
by
Alexandre Abadie
Browse files
Options
Downloads
Patches
Plain Diff
tests/periph_eeprom: refactor test application + fix bounds
parent
dfe03562
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/periph_eeprom/main.c
+89
-3
89 additions, 3 deletions
tests/periph_eeprom/main.c
with
89 additions
and
3 deletions
tests/periph_eeprom/main.c
+
89
−
3
View file @
ae6028c7
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include
<stdio.h>
#include
<stdio.h>
#include
<string.h>
#include
<string.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<assert.h>
#include
"shell.h"
#include
"shell.h"
...
@@ -65,7 +66,7 @@ static int cmd_read(int argc, char **argv)
...
@@ -65,7 +66,7 @@ static int cmd_read(int argc, char **argv)
return
1
;
return
1
;
}
}
if
(
pos
+
count
>
=
EEPROM_SIZE
)
{
if
(
pos
+
count
>
EEPROM_SIZE
)
{
puts
(
"Failed: cannot read out of eeprom bounds"
);
puts
(
"Failed: cannot read out of eeprom bounds"
);
return
1
;
return
1
;
}
}
...
@@ -78,6 +79,26 @@ static int cmd_read(int argc, char **argv)
...
@@ -78,6 +79,26 @@ static int cmd_read(int argc, char **argv)
return
0
;
return
0
;
}
}
static
int
cmd_read_byte
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
{
printf
(
"usage: %s <pos>
\n
"
,
argv
[
0
]);
return
1
;
}
uint32_t
pos
=
atoi
(
argv
[
1
]);
if
(
pos
>=
EEPROM_SIZE
)
{
puts
(
"Failed: cannot read out of eeprom bounds"
);
return
1
;
}
uint8_t
byte
=
eeprom_read_byte
(
pos
);
printf
(
"Byte read from EEPROM: 0x%02X (%c)
\n
"
,
byte
,
byte
);
return
0
;
}
static
int
cmd_write
(
int
argc
,
char
**
argv
)
static
int
cmd_write
(
int
argc
,
char
**
argv
)
{
{
if
(
argc
<
3
)
{
if
(
argc
<
3
)
{
...
@@ -87,7 +108,7 @@ static int cmd_write(int argc, char **argv)
...
@@ -87,7 +108,7 @@ static int cmd_write(int argc, char **argv)
uint32_t
pos
=
atoi
(
argv
[
1
]);
uint32_t
pos
=
atoi
(
argv
[
1
]);
if
(
pos
+
strlen
(
argv
[
2
])
>
=
EEPROM_SIZE
)
{
if
(
pos
+
strlen
(
argv
[
2
])
>
EEPROM_SIZE
)
{
puts
(
"Failed: cannot write out of eeprom bounds"
);
puts
(
"Failed: cannot write out of eeprom bounds"
);
return
1
;
return
1
;
}
}
...
@@ -98,10 +119,75 @@ static int cmd_write(int argc, char **argv)
...
@@ -98,10 +119,75 @@ static int cmd_write(int argc, char **argv)
return
0
;
return
0
;
}
}
static
int
cmd_write_byte
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
3
)
{
printf
(
"usage: %s <pos> <byte>
\n
"
,
argv
[
0
]);
return
1
;
}
uint32_t
pos
=
atoi
(
argv
[
1
]);
if
(
pos
>=
EEPROM_SIZE
)
{
puts
(
"Failed: cannot write out of eeprom bounds"
);
return
1
;
}
eeprom_write_byte
(
pos
,
*
(
uint8_t
*
)
argv
[
2
]);
printf
(
"Byte written to EEPROM
\n
"
);
return
0
;
}
static
int
cmd_test
(
int
argc
,
char
**
argv
)
{
(
void
)
argv
;
if
(
argc
!=
1
)
{
puts
(
"FAILED"
);
return
1
;
}
const
char
*
test
=
"test"
;
/* test read/write function */
/* read/write from beginning of EEPROM */
size_t
ret
=
eeprom_write
(
0
,
(
uint8_t
*
)
test
,
4
);
assert
(
ret
==
4
);
char
*
expected
[
4
];
ret
=
eeprom_read
(
0
,
(
uint8_t
*
)
expected
,
4
);
assert
(
strncmp
((
const
char
*
)
expected
,
(
const
char
*
)
test
,
4
)
==
0
);
assert
(
ret
==
4
);
/* read/write at end of EEPROM */
ret
=
eeprom_write
(
EEPROM_SIZE
-
4
,
(
uint8_t
*
)
test
,
4
);
assert
(
ret
==
4
);
ret
=
eeprom_read
(
EEPROM_SIZE
-
4
,
(
uint8_t
*
)
expected
,
4
);
assert
(
strncmp
((
const
char
*
)
expected
,
test
,
4
)
==
0
);
assert
(
ret
==
4
);
/* read/write single byte */
eeprom_write_byte
(
0
,
'A'
);
assert
(
eeprom_read_byte
(
0
)
==
'A'
);
eeprom_write_byte
(
EEPROM_SIZE
-
1
,
'A'
);
assert
(
eeprom_read_byte
(
EEPROM_SIZE
-
1
)
==
'A'
);
eeprom_write_byte
(
EEPROM_SIZE
/
2
,
'A'
);
assert
(
eeprom_read_byte
(
EEPROM_SIZE
/
2
)
==
'A'
);
puts
(
"SUCCESS"
);
return
0
;
}
static
const
shell_command_t
shell_commands
[]
=
{
static
const
shell_command_t
shell_commands
[]
=
{
{
"info"
,
"Print information about eeprom"
,
cmd_info
},
{
"info"
,
"Print information about eeprom"
,
cmd_info
},
{
"read"
,
"Read bytes from eeprom"
,
cmd_read
},
{
"read"
,
"Read bytes from eeprom"
,
cmd_read
},
{
"write"
,
"Write bytes to eeprom"
,
cmd_write
},
{
"write"
,
"Write bytes to eeprom"
,
cmd_write
},
{
"read_byte"
,
"Read a single byte from eeprom"
,
cmd_read_byte
},
{
"write_byte"
,
"Write a single byte to eeprom"
,
cmd_write_byte
},
{
"test"
,
"Test the EEPROM implementation"
,
cmd_test
},
{
NULL
,
NULL
,
NULL
}
{
NULL
,
NULL
,
NULL
}
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment