Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
0e4e0a97
Commit
0e4e0a97
authored
10 years ago
by
Cristian Maglie
Committed by
Cristian Maglie
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Bootloader: small refactoring
parent
a17594a8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bootloaders/zero/sam_ba_monitor.c
+145
-147
145 additions, 147 deletions
bootloaders/zero/sam_ba_monitor.c
with
145 additions
and
147 deletions
bootloaders/zero/sam_ba_monitor.c
+
145
−
147
View file @
0e4e0a97
...
...
@@ -174,161 +174,159 @@ void sam_ba_monitor_run(void)
{
ptr_data
=
NULL
;
command
=
'z'
;
// Start waiting some cmd
while
(
1
)
while
(
1
)
{
sam_ba_monitor_loop
();
}
}
void
sam_ba_monitor_loop
(
void
)
{
length
=
ptr_monitor_if
->
getdata
(
data
,
SIZEBUFMAX
);
ptr
=
data
;
for
(
i
=
0
;
i
<
length
;
i
++
,
ptr
++
)
{
length
=
ptr_monitor_if
->
getdata
(
data
,
SIZEBUFMAX
)
;
ptr
=
data
;
for
(
i
=
0
;
i
<
length
;
i
++
)
if
(
*
ptr
==
0xff
)
continue
;
if
(
*
ptr
==
'#'
)
{
if
(
*
ptr
!=
0xff
)
if
(
b_terminal_mode
)
{
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
if
(
command
==
'S'
)
{
if
(
*
ptr
==
'#'
)
//Check if some data are remaining in the "data" buffer
if
(
length
>
i
)
{
if
(
b_terminal_mode
)
{
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
if
(
command
==
'S'
)
{
//Check if some data are remaining in the "data" buffer
if
(
length
>
i
)
{
//Move current indexes to next avail data (currently ptr points to "#")
ptr
++
;
i
++
;
//We need to add first the remaining data of the current buffer already read from usb
//read a maximum of "current_number" bytes
u32tmp
=
min
((
length
-
i
),
current_number
);
memcpy
(
ptr_data
,
ptr
,
u32tmp
);
i
+=
u32tmp
;
ptr
+=
u32tmp
;
j
=
u32tmp
;
}
//update i with the data read from the buffer
i
--
;
ptr
--
;
//Do we expect more data ?
if
(
j
<
current_number
)
ptr_monitor_if
->
getdata_xmd
(
ptr_data
,
current_number
-
j
);
__asm
(
"nop"
);
}
else
if
(
command
==
'R'
)
{
ptr_monitor_if
->
putdata_xmd
(
ptr_data
,
current_number
);
}
else
if
(
command
==
'O'
)
{
*
ptr_data
=
(
char
)
current_number
;
}
else
if
(
command
==
'H'
)
{
*
((
uint16_t
*
)
ptr_data
)
=
(
uint16_t
)
current_number
;
}
else
if
(
command
==
'W'
)
{
*
((
int
*
)
ptr_data
)
=
current_number
;
}
else
if
(
command
==
'o'
)
{
sam_ba_putdata_term
(
ptr_data
,
1
);
}
else
if
(
command
==
'h'
)
{
current_number
=
*
((
uint16_t
*
)
ptr_data
);
sam_ba_putdata_term
((
uint8_t
*
)
&
current_number
,
2
);
}
else
if
(
command
==
'w'
)
{
current_number
=
*
((
uint32_t
*
)
ptr_data
);
sam_ba_putdata_term
((
uint8_t
*
)
&
current_number
,
4
);
}
else
if
(
command
==
'G'
)
{
call_applet
(
current_number
);
/* Rebase the Stack Pointer */
__set_MSP
(
sp
);
cpu_irq_enable
();
if
(
b_sam_ba_interface_usart
)
{
ptr_monitor_if
->
put_c
(
0x6
);
}
}
else
if
(
command
==
'T'
)
{
b_terminal_mode
=
1
;
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
else
if
(
command
==
'N'
)
{
if
(
b_terminal_mode
==
0
)
{
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
b_terminal_mode
=
0
;
}
else
if
(
command
==
'V'
)
{
ptr_monitor_if
->
putdata
(
"v"
,
1
);
ptr_monitor_if
->
putdata
((
uint8_t
*
)
RomBOOT_Version
,
strlen
(
RomBOOT_Version
));
ptr_monitor_if
->
putdata
(
" "
,
1
);
ptr
=
(
uint8_t
*
)
&
(
__DATE__
);
i
=
0
;
while
(
*
ptr
++
!=
'\0'
)
i
++
;
ptr_monitor_if
->
putdata
((
uint8_t
*
)
&
(
__DATE__
),
i
);
ptr_monitor_if
->
putdata
(
" "
,
1
);
i
=
0
;
ptr
=
(
uint8_t
*
)
&
(
__TIME__
);
while
(
*
ptr
++
!=
'\0'
)
i
++
;
ptr_monitor_if
->
putdata
((
uint8_t
*
)
&
(
__TIME__
),
i
);
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
command
=
'z'
;
current_number
=
0
;
if
(
b_terminal_mode
)
{
ptr_monitor_if
->
putdata
(
">"
,
1
);
}
//Move current indexes to next avail data (currently ptr points to "#")
ptr
++
;
i
++
;
//We need to add first the remaining data of the current buffer already read from usb
//read a maximum of "current_number" bytes
u32tmp
=
min
((
length
-
i
),
current_number
);
memcpy
(
ptr_data
,
ptr
,
u32tmp
);
i
+=
u32tmp
;
ptr
+=
u32tmp
;
j
=
u32tmp
;
}
//update i with the data read from the buffer
i
--
;
ptr
--
;
//Do we expect more data ?
if
(
j
<
current_number
)
ptr_monitor_if
->
getdata_xmd
(
ptr_data
,
current_number
-
j
);
__asm
(
"nop"
);
}
else
if
(
command
==
'R'
)
{
ptr_monitor_if
->
putdata_xmd
(
ptr_data
,
current_number
);
}
else
if
(
command
==
'O'
)
{
*
ptr_data
=
(
char
)
current_number
;
}
else
if
(
command
==
'H'
)
{
*
((
uint16_t
*
)
ptr_data
)
=
(
uint16_t
)
current_number
;
}
else
if
(
command
==
'W'
)
{
*
((
int
*
)
ptr_data
)
=
current_number
;
}
else
if
(
command
==
'o'
)
{
sam_ba_putdata_term
(
ptr_data
,
1
);
}
else
if
(
command
==
'h'
)
{
current_number
=
*
((
uint16_t
*
)
ptr_data
);
sam_ba_putdata_term
((
uint8_t
*
)
&
current_number
,
2
);
}
else
if
(
command
==
'w'
)
{
current_number
=
*
((
uint32_t
*
)
ptr_data
);
sam_ba_putdata_term
((
uint8_t
*
)
&
current_number
,
4
);
}
else
if
(
command
==
'G'
)
{
call_applet
(
current_number
);
/* Rebase the Stack Pointer */
__set_MSP
(
sp
);
cpu_irq_enable
();
if
(
b_sam_ba_interface_usart
)
{
ptr_monitor_if
->
put_c
(
0x6
);
}
else
}
else
if
(
command
==
'T'
)
{
b_terminal_mode
=
1
;
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
else
if
(
command
==
'N'
)
{
if
(
b_terminal_mode
==
0
)
{
if
((
'0'
<=
*
ptr
)
&&
(
*
ptr
<=
'9'
))
{
current_number
=
(
current_number
<<
4
)
|
(
*
ptr
-
'0'
);
}
else
if
((
'A'
<=
*
ptr
)
&&
(
*
ptr
<=
'F'
))
{
current_number
=
(
current_number
<<
4
)
|
(
*
ptr
-
'A'
+
0xa
);
}
else
if
((
'a'
<=
*
ptr
)
&&
(
*
ptr
<=
'f'
))
{
current_number
=
(
current_number
<<
4
)
|
(
*
ptr
-
'a'
+
0xa
);
}
else
if
(
*
ptr
==
','
)
{
ptr_data
=
(
uint8_t
*
)
current_number
;
current_number
=
0
;
}
else
{
command
=
*
ptr
;
current_number
=
0
;
}
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
ptr
++
;
b_terminal_mode
=
0
;
}
else
if
(
command
==
'V'
)
{
ptr_monitor_if
->
putdata
(
"v"
,
1
);
ptr_monitor_if
->
putdata
((
uint8_t
*
)
RomBOOT_Version
,
strlen
(
RomBOOT_Version
));
ptr_monitor_if
->
putdata
(
" "
,
1
);
ptr
=
(
uint8_t
*
)
&
(
__DATE__
);
i
=
0
;
while
(
*
ptr
++
!=
'\0'
)
i
++
;
ptr_monitor_if
->
putdata
((
uint8_t
*
)
&
(
__DATE__
),
i
);
ptr_monitor_if
->
putdata
(
" "
,
1
);
i
=
0
;
ptr
=
(
uint8_t
*
)
&
(
__TIME__
);
while
(
*
ptr
++
!=
'\0'
)
i
++
;
ptr_monitor_if
->
putdata
((
uint8_t
*
)
&
(
__TIME__
),
i
);
ptr_monitor_if
->
putdata
(
"
\n\r
"
,
2
);
}
command
=
'z'
;
current_number
=
0
;
if
(
b_terminal_mode
)
{
ptr_monitor_if
->
putdata
(
">"
,
1
);
}
}
else
{
if
((
'0'
<=
*
ptr
)
&&
(
*
ptr
<=
'9'
))
{
current_number
=
(
current_number
<<
4
)
|
(
*
ptr
-
'0'
);
}
else
if
((
'A'
<=
*
ptr
)
&&
(
*
ptr
<=
'F'
))
{
current_number
=
(
current_number
<<
4
)
|
(
*
ptr
-
'A'
+
0xa
);
}
else
if
((
'a'
<=
*
ptr
)
&&
(
*
ptr
<=
'f'
))
{
current_number
=
(
current_number
<<
4
)
|
(
*
ptr
-
'a'
+
0xa
);
}
else
if
(
*
ptr
==
','
)
{
ptr_data
=
(
uint8_t
*
)
current_number
;
current_number
=
0
;
}
else
{
command
=
*
ptr
;
current_number
=
0
;
}
}
}
}
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