Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1f7473d2
authored
Jul 28, 2019
by
Enrico Pozzobon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mostly similar firmwares
parent
0bf790c5
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
141 additions
and
207 deletions
+141
-207
templates/bluepill/src/main.ino
+25
-43
templates/esp32/src/main.ino
+27
-45
templates/esp32/src/uartp.c
+15
-15
templates/f7/Src/test.c
+0
-23
templates/uno/src/main.ino
+38
-53
templates/uno/src/uartp.c
+15
-15
templates/uno/test
+21
-13
No files found.
templates/bluepill/src/main.ino
View file @
1f7473d2
...
...
@@ -3,20 +3,22 @@
#include "uartp.h"
#define MAX_BYTES 100
#define CMDBUF_LEN 72
static
uint8_t
cmdbuf
[
CMDBUF_LEN
];
//#define DEBUG
#define CRYPTO_BUSY A7
#define SerialOut Serial1
uint8_t
npub
[
CRYPTO_NPUBBYTES
];
uint8_t
nsec
[
CRYPTO_NSECBYTES
];
uint8_t
k
[
CRYPTO_KEYBYTES
];
uint8_t
ad
[
MAX_BYTES
];
unsigned
long
long
int
adlen
;
uint8_t
m
[
MAX_BYTES
];
unsigned
long
long
int
mlen
;
uint8_t
c
[
MAX_BYTES
];
unsigned
long
long
int
clen
;
int
res
;
unsigned
long
long
int
adlen
=
0
;
unsigned
long
long
int
mlen
=
0
;
unsigned
long
long
int
clen
=
0
;
int
res
=
0
;
void
setup
();
void
loop
();
...
...
@@ -26,13 +28,13 @@ extern "C" {
#endif
void
uart_wbyte
(
uint8_t
x
)
{
Serial
1
.
write
((
uint8_t
)
(
x
));
Serial
Out
.
write
((
uint8_t
)
(
x
));
}
uint8_t
uart_rbyte
()
{
int
r
;
do
{
r
=
Serial
1
.
read
();
r
=
Serial
Out
.
read
();
}
while
(
r
==
-
1
);
return
(
uint8_t
)
(
0xff
&
r
);
}
...
...
@@ -41,56 +43,37 @@ uint8_t uart_rbyte() {
}
#endif
int
dbg_printf
(
const
char
*
format
,
...)
{
int
r
=
0
;
#ifdef DEBUG
#define DEBUG_BUF_LEN 80
char
printbuf
[
DEBUG_BUF_LEN
+
2
];
va_list
vargs
;
va_start
(
vargs
,
format
);
r
=
vsnprintf
(
printbuf
+
1
,
DEBUG_BUF_LEN
,
format
,
vargs
);
va_end
(
vargs
);
if
(
r
<
0
)
{
memcpy
(
printbuf
+
1
,
"DEBUG ERROR
\r\n
"
,
13
);
r
=
13
;
}
r
=
r
>
DEBUG_BUF_LEN
?
DEBUG_BUF_LEN
:
r
;
printbuf
[
0
]
=
0xde
;
// Debug messages should start with "\xde"
uartp_send
(
printbuf
,
r
+
1
);
#endif
return
r
;
}
void
my_assert
(
bool
b
)
{
if
(
b
)
return
;
dbg_printf
(
"Assertion failed
\r\n
"
);
for
(;;)
yield
();
}
void
setup
()
{
Serial
1
.
begin
(
115200
);
Serial
Out
.
begin
(
115200
);
pinMode
(
CRYPTO_BUSY
,
OUTPUT
);
digitalWrite
(
CRYPTO_BUSY
,
HIGH
);
delay
(
100
);
Serial1
.
print
(
"Hello, World!"
);
memset
(
npub
,
0
,
CRYPTO_NPUBBYTES
);
memset
(
nsec
,
0
,
CRYPTO_NSECBYTES
);
memset
(
k
,
0
,
CRYPTO_KEYBYTES
);
memset
(
ad
,
0
,
MAX_BYTES
);
memset
(
m
,
0
,
MAX_BYTES
);
memset
(
c
,
0
,
MAX_BYTES
);
SerialOut
.
print
(
"Hello, World!"
);
}
void
loop
()
{
static
uint8_t
buf
[
256
]
;
uint16_t
len
=
uartp_recv
(
buf
,
255
);
uint8_t
action
=
buf
[
0
];
if
(
len
==
0
||
len
>
255
)
int
res
;
uint16_t
len
=
uartp_recv
(
cmdbuf
,
CMDBUF_LEN
-
1
);
uint8_t
action
=
cmd
buf
[
0
];
if
(
len
==
0
||
len
>
CMDBUF_LEN
-
1
)
return
;
uint16_t
l
=
len
-
1
;
uint16_t
rl
=
0
;
uint8_t
*
var
=
buf
+
1
;
uint8_t
*
var
=
cmd
buf
+
1
;
switch
(
action
)
{
case
'm'
:
my_assert
(
l
<=
MAX_BYTES
);
memcpy
(
m
,
var
,
l
);
mlen
=
l
;
break
;
case
'c'
:
my_assert
(
l
<=
MAX_BYTES
);
memcpy
(
c
,
var
,
l
);
clen
=
l
;
break
;
...
...
@@ -124,10 +107,9 @@ void loop() {
case
'S'
:
var
=
nsec
;
rl
=
CRYPTO_NSECBYTES
;
break
;
case
'R'
:
var
=
(
uint8_t
*
)
&
res
;
rl
=
sizeof
(
res
);
break
;
default
:
dbg_printf
(
"Unknown command
\r\n
"
);
my_assert
(
false
);
}
buf
[
0
]
=
action
;
memcpy
(
buf
+
1
,
var
,
rl
);
uartp_send
(
buf
,
rl
+
1
);
cmd
buf
[
0
]
=
action
;
memcpy
(
cmd
buf
+
1
,
var
,
rl
);
uartp_send
(
cmd
buf
,
rl
+
1
);
}
templates/esp32/src/main.ino
View file @
1f7473d2
...
...
@@ -3,19 +3,22 @@
#include "uartp.h"
#define MAX_BYTES 100
#define CMDBUF_LEN 72
static
uint8_t
cmdbuf
[
CMDBUF_LEN
];
//#define DEBUG
#define CRYPTO_BUSY 12
#define SerialOut Serial
uint8_t
npub
[
CRYPTO_NPUBBYTES
];
uint8_t
nsec
[
CRYPTO_NSECBYTES
];
uint8_t
k
[
CRYPTO_KEYBYTES
];
uint8_t
ad
[
MAX_BYTES
];
unsigned
long
long
int
adlen
;
uint8_t
m
[
MAX_BYTES
];
unsigned
long
long
int
mlen
;
uint8_t
c
[
MAX_BYTES
];
unsigned
long
long
int
clen
;
unsigned
long
long
int
adlen
=
0
;
unsigned
long
long
int
mlen
=
0
;
unsigned
long
long
int
clen
=
0
;
int
res
=
0
;
void
setup
();
void
loop
();
...
...
@@ -24,14 +27,14 @@ void loop();
extern
"C"
{
#endif
void
uart_w
ri
te
(
uint8_t
x
)
{
Serial
.
write
((
uint8_t
)
(
x
));
void
uart_w
by
te
(
uint8_t
x
)
{
Serial
Out
.
write
((
uint8_t
)
(
x
));
}
uint8_t
uart_r
ead
()
{
uint8_t
uart_r
byte
()
{
int
r
;
do
{
r
=
Serial
.
read
();
r
=
Serial
Out
.
read
();
}
while
(
r
==
-
1
);
return
(
uint8_t
)
(
0xff
&
r
);
}
...
...
@@ -40,58 +43,37 @@ uint8_t uart_read() {
}
#endif
#ifdef DEBUG
#define DEBUG_BUF_LEN 80
int
dbg_printf
(
const
char
*
format
,
...)
{
char
printbuf
[
DEBUG_BUF_LEN
+
2
];
va_list
vargs
;
va_start
(
vargs
,
format
);
int
r
=
vsnprintf
(
printbuf
+
1
,
DEBUG_BUF_LEN
,
format
,
vargs
);
va_end
(
vargs
);
if
(
r
<
0
)
{
memcpy
(
printbuf
+
1
,
"DEBUG ERROR
\r\n
"
,
13
);
r
=
13
;
}
r
=
r
>
DEBUG_BUF_LEN
?
DEBUG_BUF_LEN
:
r
;
printbuf
[
0
]
=
0xde
;
// Debug messages should start with "\xde"
uartp_send
(
printbuf
,
r
+
1
);
return
r
;
}
#else
#define dbg_printf(...) (0)
#endif
void
my_assert
(
bool
b
)
{
if
(
b
)
return
;
dbg_printf
(
"Assertion failed
\r\n
"
);
for
(;;)
yield
();
}
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
Out
.
begin
(
115200
);
pinMode
(
CRYPTO_BUSY
,
OUTPUT
);
digitalWrite
(
CRYPTO_BUSY
,
HIGH
);
delay
(
100
);
Serial
.
print
(
"Hello, World!"
);
memset
(
npub
,
0
,
CRYPTO_NPUBBYTES
);
memset
(
nsec
,
0
,
CRYPTO_NSECBYTES
);
memset
(
k
,
0
,
CRYPTO_KEYBYTES
);
memset
(
ad
,
0
,
MAX_BYTES
);
memset
(
m
,
0
,
MAX_BYTES
);
memset
(
c
,
0
,
MAX_BYTES
);
SerialOut
.
print
(
"Hello, World!"
);
}
void
loop
()
{
static
uint8_t
buf
[
256
];
int
res
;
uint16_t
len
=
uartp_recv
(
buf
,
255
);
uint8_t
action
=
buf
[
0
];
if
(
len
==
0
||
len
>
255
)
uint16_t
len
=
uartp_recv
(
cmdbuf
,
CMDBUF_LEN
-
1
);
uint8_t
action
=
cmd
buf
[
0
];
if
(
len
==
0
||
len
>
CMDBUF_LEN
-
1
)
return
;
uint16_t
l
=
len
-
1
;
uint16_t
rl
=
0
;
uint8_t
*
var
=
buf
+
1
;
uint8_t
*
var
=
cmd
buf
+
1
;
switch
(
action
)
{
case
'm'
:
my_assert
(
l
<=
MAX_BYTES
);
memcpy
(
m
,
var
,
l
);
mlen
=
l
;
break
;
case
'c'
:
my_assert
(
l
<=
MAX_BYTES
);
memcpy
(
c
,
var
,
l
);
clen
=
l
;
break
;
...
...
@@ -123,11 +105,11 @@ void loop() {
case
'K'
:
var
=
k
;
rl
=
CRYPTO_KEYBYTES
;
break
;
case
'P'
:
var
=
npub
;
rl
=
CRYPTO_NPUBBYTES
;
break
;
case
'S'
:
var
=
nsec
;
rl
=
CRYPTO_NSECBYTES
;
break
;
case
'R'
:
var
=
(
uint8_t
*
)
&
res
;
rl
=
sizeof
(
res
);
break
;
default
:
dbg_printf
(
"Unknown command
\r\n
"
);
my_assert
(
false
);
}
buf
[
0
]
=
action
;
memcpy
(
buf
+
1
,
var
,
rl
);
uartp_send
(
buf
,
rl
+
1
);
cmd
buf
[
0
]
=
action
;
memcpy
(
cmd
buf
+
1
,
var
,
rl
);
uartp_send
(
cmd
buf
,
rl
+
1
);
}
templates/esp32/src/uartp.c
View file @
1f7473d2
#include <stdint.h>
#include "uartp.h"
extern
void
uart_w
ri
te
(
uint8_t
x
);
extern
uint8_t
uart_r
ead
();
extern
void
uart_w
by
te
(
uint8_t
x
);
extern
uint8_t
uart_r
byte
();
// Simple serial protocol with packets and checksum
const
uint8_t
AMUX_TAG
=
0xf9
;
...
...
@@ -13,24 +13,24 @@ void uartp_send(const void *src, uint16_t len) {
uint8_t
len_ind_0
,
len_ind_1
,
fcs
,
info
;
const
uint8_t
*
buf
=
(
const
uint8_t
*
)
src
;
uart_w
ri
te
(
AMUX_TAG
);
uart_w
by
te
(
AMUX_TAG
);
len_ind_0
=
(
uint8_t
)
(
0xff
&
len
);
len_ind_1
=
(
uint8_t
)
(
0xff
&
(
len
>>
7
));
if
(
len
<
128
)
{
uart_w
ri
te
(
len_ind_0
);
uart_w
by
te
(
len_ind_0
);
}
else
{
uart_w
ri
te
(
len_ind_0
|
AMUX_EXT
);
uart_w
ri
te
(
len_ind_1
);
uart_w
by
te
(
len_ind_0
|
AMUX_EXT
);
uart_w
by
te
(
len_ind_1
);
}
fcs
=
0
;
for
(
uint16_t
i
=
0
;
i
<
len
;
i
++
)
{
info
=
buf
[
i
];
fcs
+=
info
;
uart_w
ri
te
(
buf
[
i
]);
uart_w
by
te
(
buf
[
i
]);
}
fcs
=
255
-
fcs
;
uart_w
ri
te
(
fcs
);
uart_w
ri
te
(
AMUX_END
);
uart_w
by
te
(
fcs
);
uart_w
by
te
(
AMUX_END
);
}
...
...
@@ -44,13 +44,13 @@ uint16_t uartp_recv(void *dst, uint16_t buf_len) {
do
{
tag_old
=
tag
;
tag
=
uart_r
ead
();
tag
=
uart_r
byte
();
}
while
(
tag
!=
AMUX_TAG
||
tag_old
!=
AMUX_END
);
len
=
(
uint16_t
)
uart_r
ead
();
len
=
(
uint16_t
)
uart_r
byte
();
if
(
len
&
AMUX_EXT
)
{
len
&=
(
~
AMUX_EXT
);
len
|=
(
uint16_t
)
(
uart_r
ead
()
<<
7
);
len
|=
(
uint16_t
)
(
uart_r
byte
()
<<
7
);
}
if
(
len
>
buf_len
)
{
return
len
;
...
...
@@ -59,12 +59,12 @@ uint16_t uartp_recv(void *dst, uint16_t buf_len) {
uint16_t
i
=
0
;
cs
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
info
=
uart_r
ead
();
info
=
uart_r
byte
();
buf
[
i
]
=
info
;
cs
+=
info
;
}
cs
+=
uart_r
ead
();
tag
=
uart_r
ead
();
cs
+=
uart_r
byte
();
tag
=
uart_r
byte
();
if
(
0xff
==
cs
)
{
if
(
AMUX_END
==
tag
)
{
return
len
;
...
...
templates/f7/Src/test.c
View file @
1f7473d2
...
...
@@ -57,31 +57,9 @@ static inline void interrupts() {
// TODO: if necessary, provide a way to enable interrupts
}
#define DEBUG_BUF_LEN 80
int
dbg_printf
(
const
char
*
format
,
...)
{
int
r
=
0
;
char
printbuf
[
DEBUG_BUF_LEN
+
2
];
va_list
vargs
;
va_start
(
vargs
,
format
);
r
=
vsnprintf
(
printbuf
+
1
,
DEBUG_BUF_LEN
,
format
,
vargs
);
va_end
(
vargs
);
if
(
r
<
0
)
{
memcpy
(
printbuf
+
1
,
"DEBUG ERROR
\r\n
"
,
13
);
r
=
13
;
}
r
=
r
>
DEBUG_BUF_LEN
?
DEBUG_BUF_LEN
:
r
;
printbuf
[
0
]
=
0xde
;
// Debug messages should start with "\xde"
uartp_send
(
printbuf
,
r
+
1
);
return
r
;
}
void
my_assert
(
bool
b
)
{
if
(
b
)
return
;
dbg_printf
(
"Assertion failed
\r\n
"
);
Error_Handler
();
for
(;;);
}
...
...
@@ -140,7 +118,6 @@ void test_loop() {
case
'S'
:
var
=
nsec
;
rl
=
CRYPTO_NSECBYTES
;
break
;
case
'R'
:
var
=
(
uint8_t
*
)
&
res
;
rl
=
sizeof
(
res
);
break
;
default:
dbg_printf
(
"Unknown command
\r\n
"
);
my_assert
(
false
);
}
buf
[
0
]
=
action
;
...
...
templates/uno/src/main.ino
View file @
1f7473d2
...
...
@@ -3,32 +3,38 @@
#include "uartp.h"
#define MAX_BYTES 100
#define CMDBUF_LEN 72
static
uint8_t
cmdbuf
[
CMDBUF_LEN
];
//#define DEBUG
#define CRYPTO_BUSY 12
#define SerialOut Serial
uint8_t
npub
[
CRYPTO_NPUBBYTES
];
uint8_t
nsec
[
CRYPTO_NSECBYTES
];
uint8_t
k
[
CRYPTO_KEYBYTES
];
uint8_t
ad
[
MAX_BYTES
];
unsigned
long
long
int
adlen
;
uint8_t
m
[
MAX_BYTES
];
unsigned
long
long
int
mlen
;
uint8_t
c
[
MAX_BYTES
];
unsigned
long
long
int
clen
;
unsigned
long
long
int
adlen
=
0
;
unsigned
long
long
int
mlen
=
0
;
unsigned
long
long
int
clen
=
0
;
int
res
=
0
;
void
setup
();
void
loop
();
#ifdef __cplusplus
extern
"C"
{
#endif
void
uart_w
ri
te
(
uint8_t
x
)
{
Serial
.
write
((
uint8_t
)
(
x
));
void
uart_w
by
te
(
uint8_t
x
)
{
Serial
Out
.
write
((
uint8_t
)
(
x
));
}
uint8_t
uart_r
ead
()
{
uint8_t
uart_r
byte
()
{
int
r
;
do
{
r
=
Serial
.
read
();
r
=
Serial
Out
.
read
();
}
while
(
r
==
-
1
);
return
(
uint8_t
)
(
0xff
&
r
);
}
...
...
@@ -37,65 +43,44 @@ uint8_t uart_read() {
}
#endif
#ifdef DEBUG
#define DEBUG_BUF_LEN 80
int
dbg_printf
(
const
char
*
format
,
...)
{
char
printbuf
[
DEBUG_BUF_LEN
+
2
];
va_list
vargs
;
va_start
(
vargs
,
format
);
int
r
=
vsnprintf
(
printbuf
+
1
,
DEBUG_BUF_LEN
,
format
,
vargs
);
va_end
(
vargs
);
if
(
r
<
0
)
{
memcpy
(
printbuf
+
1
,
"DEBUG ERROR
\r\n
"
,
13
);
r
=
13
;
}
r
=
r
>
DEBUG_BUF_LEN
?
DEBUG_BUF_LEN
:
r
;
printbuf
[
0
]
=
0xde
;
// Debug messages should start with "\xde"
uartp_send
(
printbuf
,
r
+
1
);
return
r
;
}
#else
#define dbg_printf(...) (0)
#endif
void
assert
(
bool
b
)
{
void
my_assert
(
bool
b
)
{
if
(
b
)
return
;
dbg_printf
(
"Assertion failed
\r\n
"
);
for
(;;)
yield
();
}
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
Out
.
begin
(
115200
);
pinMode
(
CRYPTO_BUSY
,
OUTPUT
);
digitalWrite
(
CRYPTO_BUSY
,
HIGH
);
delay
(
100
);
Serial
.
print
(
"Hello, World!"
);
memset
(
npub
,
0
,
CRYPTO_NPUBBYTES
);
memset
(
nsec
,
0
,
CRYPTO_NSECBYTES
);
memset
(
k
,
0
,
CRYPTO_KEYBYTES
);
memset
(
ad
,
0
,
MAX_BYTES
);
memset
(
m
,
0
,
MAX_BYTES
);
memset
(
c
,
0
,
MAX_BYTES
);
SerialOut
.
print
(
"Hello, World!"
);
}
void
loop
()
{
static
uint8_t
buf
[
256
];
int
res
;
uint16_t
len
=
uartp_recv
(
buf
,
255
);
uint8_t
action
=
buf
[
0
];
if
(
len
==
0
||
len
>
255
)
uint16_t
len
=
uartp_recv
(
cmdbuf
,
CMDBUF_LEN
-
1
);
uint8_t
action
=
cmd
buf
[
0
];
if
(
len
==
0
||
len
>
CMDBUF_LEN
-
1
)
return
;
uint16_t
l
=
len
-
1
;
uint16_t
rl
=
0
;
uint8_t
*
var
=
buf
+
1
;
uint8_t
*
var
=
cmd
buf
+
1
;
switch
(
action
)
{
case
'm'
:
assert
(
l
<=
MAX_BYTES
);
memcpy
(
m
,
var
,
l
);
mlen
=
l
;
break
;
case
'c'
:
assert
(
l
<=
MAX_BYTES
);
memcpy
(
c
,
var
,
l
);
clen
=
l
;
break
;
case
'a'
:
assert
(
l
<=
MAX_BYTES
);
memcpy
(
ad
,
var
,
l
);
adlen
=
l
;
break
;
case
'k'
:
assert
(
l
==
CRYPTO_KEYBYTES
);
memcpy
(
k
,
var
,
l
);
break
;
case
'p'
:
assert
(
l
==
CRYPTO_NPUBBYTES
);
memcpy
(
npub
,
var
,
l
);
break
;
case
's'
:
assert
(
l
==
CRYPTO_NSECBYTES
);
memcpy
(
nsec
,
var
,
l
);
break
;
case
'm'
:
my_
assert
(
l
<=
MAX_BYTES
);
memcpy
(
m
,
var
,
l
);
mlen
=
l
;
break
;
case
'c'
:
my_
assert
(
l
<=
MAX_BYTES
);
memcpy
(
c
,
var
,
l
);
clen
=
l
;
break
;
case
'a'
:
my_
assert
(
l
<=
MAX_BYTES
);
memcpy
(
ad
,
var
,
l
);
adlen
=
l
;
break
;
case
'k'
:
my_
assert
(
l
==
CRYPTO_KEYBYTES
);
memcpy
(
k
,
var
,
l
);
break
;
case
'p'
:
my_
assert
(
l
==
CRYPTO_NPUBBYTES
);
memcpy
(
npub
,
var
,
l
);
break
;
case
's'
:
my_
assert
(
l
==
CRYPTO_NSECBYTES
);
memcpy
(
nsec
,
var
,
l
);
break
;
case
'e'
:
noInterrupts
();
asm
(
"nop"
);
...
...
@@ -120,11 +105,11 @@ void loop() {
case
'K'
:
var
=
k
;
rl
=
CRYPTO_KEYBYTES
;
break
;
case
'P'
:
var
=
npub
;
rl
=
CRYPTO_NPUBBYTES
;
break
;
case
'S'
:
var
=
nsec
;
rl
=
CRYPTO_NSECBYTES
;
break
;
case
'R'
:
var
=
(
uint8_t
*
)
&
res
;
rl
=
sizeof
(
res
);
break
;
default
:
dbg_printf
(
"Unknown command
\r\n
"
);
assert
(
false
);
my_assert
(
false
);
}
buf
[
0
]
=
action
;
memcpy
(
buf
+
1
,
var
,
rl
);
uartp_send
(
buf
,
rl
+
1
);
cmd
buf
[
0
]
=
action
;
memcpy
(
cmd
buf
+
1
,
var
,
rl
);
uartp_send
(
cmd
buf
,
rl
+
1
);
}
templates/uno/src/uartp.c
View file @
1f7473d2
#include <stdint.h>
#include "uartp.h"
extern
void
uart_w
ri
te
(
uint8_t
x
);
extern
uint8_t
uart_r
ead
();
extern
void
uart_w
by
te
(
uint8_t
x
);
extern
uint8_t
uart_r
byte
();
// Simple serial protocol with packets and checksum
const
uint8_t
AMUX_TAG
=
0xf9
;
...
...
@@ -13,24 +13,24 @@ void uartp_send(const void *src, uint16_t len) {
uint8_t
len_ind_0
,
len_ind_1
,
fcs
,
info
;
const
uint8_t
*
buf
=
(
const
uint8_t
*
)
src
;
uart_w
ri
te
(
AMUX_TAG
);
uart_w
by
te
(
AMUX_TAG
);
len_ind_0
=
(
uint8_t
)
(
0xff
&
len
);
len_ind_1
=
(
uint8_t
)
(
0xff
&
(
len
>>
7
));
if
(
len
<
128
)
{
uart_w
ri
te
(
len_ind_0
);
uart_w
by
te
(
len_ind_0
);
}
else
{
uart_w
ri
te
(
len_ind_0
|
AMUX_EXT
);
uart_w
ri
te
(
len_ind_1
);
uart_w
by
te
(
len_ind_0
|
AMUX_EXT
);
uart_w
by
te
(
len_ind_1
);
}
fcs
=
0
;
for
(
uint16_t
i
=
0
;
i
<
len
;
i
++
)
{
info
=
buf
[
i
];
fcs
+=
info
;
uart_w
ri
te
(
buf
[
i
]);
uart_w
by
te
(
buf
[
i
]);
}
fcs
=
255
-
fcs
;
uart_w
ri
te
(
fcs
);
uart_w
ri
te
(
AMUX_END
);
uart_w
by
te
(
fcs
);
uart_w
by
te
(
AMUX_END
);
}
...
...
@@ -44,13 +44,13 @@ uint16_t uartp_recv(void *dst, uint16_t buf_len) {
do
{
tag_old
=
tag
;
tag
=
uart_r
ead
();
tag
=
uart_r
byte
();
}
while
(
tag
!=
AMUX_TAG
||
tag_old
!=
AMUX_END
);
len
=
(
uint16_t
)
uart_r
ead
();
len
=
(
uint16_t
)
uart_r
byte
();
if
(
len
&
AMUX_EXT
)
{
len
&=
(
~
AMUX_EXT
);
len
|=
(
uint16_t
)
(
uart_r
ead
()
<<
7
);
len
|=
(
uint16_t
)
(
uart_r
byte
()
<<
7
);
}
if
(
len
>
buf_len
)
{
return
len
;
...
...
@@ -59,12 +59,12 @@ uint16_t uartp_recv(void *dst, uint16_t buf_len) {
uint16_t
i
=
0
;
cs
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
info
=
uart_r
ead
();
info
=
uart_r
byte
();
buf
[
i
]
=
info
;
cs
+=
info
;
}
cs
+=
uart_r
ead
();
tag
=
uart_r
ead
();
cs
+=
uart_r
byte
();
tag
=
uart_r
byte
();
if
(
0xff
==
cs
)
{
if
(
AMUX_END
==
tag
)
{
return
len
;
...
...
templates/uno/test
View file @
1f7473d2
...
...
@@ -104,6 +104,21 @@ class UARTP:
else
:
return
buf
def
stdin_read
(
n
):
b
=
sys
.
stdin
.
buffer
.
read
(
n
)
if
len
(
b
)
!=
n
:
sys
.
exit
(
1
)
return
b
def
stdin_readvar
():
l
=
stdin_read
(
4
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
v
=
stdin_read
(
l
)
return
v
def
main
(
argv
):
eprint
(
argv
[
0
])
script_dir
=
os
.
path
.
split
(
argv
[
0
])[
0
]
...
...
@@ -113,22 +128,15 @@ def main(argv):
dev
=
get_serial
()
flash
(
dev
)
eprint
(
"Flashed"
)
time
.
sleep
(
1
)
time
.
sleep
(
0.
1
)
ser
=
serial
.
Serial
(
dev
,
baudrate
=
115200
,
timeout
=
5
)
uartp
=
UARTP
(
ser
)
def
stdin_read
(
n
):
b
=
sys
.
stdin
.
buffer
.
read
(
n
)
if
len
(
b
)
!=
n
:
sys
.
exit
(
1
)
return
b
def
stdin_readvar
():
l
=
stdin_read
(
4
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
v
=
stdin_read
(
l
)
return
v
ser
.
setDTR
(
True
)
time
.
sleep
(
0.01
)
ser
.
setDTR
(
False
)
time
.
sleep
(
1
)
exp_hello
=
b
"Hello, World!"
hello
=
ser
.
read
(
len
(
exp_hello
))
...
...
@@ -167,7 +175,7 @@ def main(argv):
c
=
struct
.
pack
(
"B"
,
action
)
uartp
.
send
(
c
)
ack
=
uartp
.
recv
()
if
len
(
ack
)
!=
1
or
ack
[
0
]
!=
action
:
if
len
(
ack
)
<
1
or
ack
[
0
]
!=
action
:
raise
Exception
(
"Unacknowledged variable transfer"
)
eprint
(
"Operation
%
c completed successfully"
%
action
)
...
...
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