Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
G4_mpu
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
ISC2
pro
G4_mpu
Commits
9efa67a8
Commit
9efa67a8
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: finishing UART
parent
314d9910
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mpu_user_console_etu.c
+14
-8
14 additions, 8 deletions
mpu_user_console_etu.c
user_cmd.c
+31
-8
31 additions, 8 deletions
user_cmd.c
user_cmd.h
+17
-3
17 additions, 3 deletions
user_cmd.h
with
62 additions
and
19 deletions
mpu_user_console_etu.c
+
14
−
8
View file @
9efa67a8
...
@@ -62,14 +62,16 @@ void test_supervisor_mode() {
...
@@ -62,14 +62,16 @@ void test_supervisor_mode() {
}
}
void
ask_user_input
(
void
)
{
void
ask_user_input
(
void
)
{
char
buff
[
64
]
=
{
0
};
char
buff
[
USER_INPUT_SIZE
]
=
{
0
};
char
switch_cmd
[]
=
"switch"
;
char
switch_cmd
[]
=
"switch"
;
char
status_cmd
[]
=
"status"
;
char
status_cmd
[]
=
"status"
;
printf
(
"(%s) Would you like to `switch` or display `status` errors : "
,
PRINT
(
"(%s) Would you like to `switch` or display `status` errors : "
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
is_supervisor_mode
?
"Supervisor"
:
"User"
)
fflush
(
stdin
);
;
fscanf
(
stdin
,
"%s"
,
buff
);
// fflush(stdin);
// fscanf(stdin, "%s", buff);
uart_scanf
(
buff
);
if
(
strncmp
(
buff
,
switch_cmd
,
strlen
(
switch_cmd
))
==
0
)
{
if
(
strncmp
(
buff
,
switch_cmd
,
strlen
(
switch_cmd
))
==
0
)
{
// permute through svc depending on flag
// permute through svc depending on flag
...
@@ -79,14 +81,16 @@ void ask_user_input(void) {
...
@@ -79,14 +81,16 @@ void ask_user_input(void) {
if
(
strncmp
(
buff
,
status_cmd
,
strlen
(
status_cmd
))
==
0
)
{
if
(
strncmp
(
buff
,
status_cmd
,
strlen
(
status_cmd
))
==
0
)
{
if
(
idx_error
==
0
)
{
if
(
idx_error
==
0
)
{
printf
(
"No errors have occurred yet
\n
"
);
PRINT
(
"No errors have occurred yet
\n
"
)
;
return
;
return
;
}
}
for
(
int
i
=
0
;
i
<
idx_error
;
i
++
)
{
for
(
int
i
=
0
;
i
<
idx_error
;
i
++
)
{
if
(
i
<
BUF_SIZE
)
{
if
(
i
<
BUF_SIZE
)
{
printf
(
"Address that shat the bed : 0x%x
\t
Error code : 0x%x
\n
"
,
PRINT
(
"Address that shat the bed : 0x%x
\t
Error code : 0x%x
\n
"
,
arr_addr
[
i
],
arr_err_code
[
i
]);
arr_addr
[
i
],
arr_err_code
[
i
])
;
}
}
}
}
}
}
...
@@ -105,6 +109,8 @@ void test_user_mode() {
...
@@ -105,6 +109,8 @@ void test_user_mode() {
}
}
int
main
(
void
)
{
int
main
(
void
)
{
uart0_init_ref
(
9600
,
NULL
,
NULL
);
LPC_GPIO2
->
FIODIR
=
0xFF
;
LPC_GPIO2
->
FIODIR
=
0xFF
;
LPC_GPIO2
->
FIOPIN
=
0
;
LPC_GPIO2
->
FIOPIN
=
0
;
// MPU configuration here...
// MPU configuration here...
...
...
This diff is collapsed.
Click to expand it.
user_cmd.c
+
31
−
8
View file @
9efa67a8
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#define PRINT_SYNTAX_ERROR() PRINT("Syntax error! Expected syntax is either <8 characters hexadecimal address> for reading\n or " \
#define PRINT_SYNTAX_ERROR() PRINT("Syntax error! Expected syntax is either <8 characters hexadecimal address> for reading\n or " \
"<8 characters hexadecimal address>=<8 characters hexadecimal value> for writing
\n
"
);
"<8 characters hexadecimal address>=<8 characters hexadecimal value> for writing
\n
"
);
bool
is_supervisor_mode
=
false
;
bool
is_supervisor_mode
=
false
;
void
switch_to_user_mode
();
void
switch_to_user_mode
();
void
switch_to_supervisor_mode
(
void
);
void
switch_to_supervisor_mode
(
void
);
...
@@ -28,17 +29,35 @@ void SVC_Handler() {
...
@@ -28,17 +29,35 @@ void SVC_Handler() {
is_supervisor_mode
=
!
is_supervisor_mode
;
is_supervisor_mode
=
!
is_supervisor_mode
;
}
}
void
uart_scanf
(
char
*
buff
)
{
char
user_input
[
USER_INPUT_SIZE
]
=
{
0
};
size_t
idx
=
1
;
while
(
user_input
[
idx
-
1
]
!=
'\n'
)
{
idx
--
;
user_input
[
idx
]
=
uart0_rec_byte_ref
();
idx
++
;
}
user_input
[
idx
-
1
]
=
'\0'
;
memcpy
(
buff
,
user_input
,
USER_INPUT_SIZE
);
}
void
exec_user_read_write
()
{
void
exec_user_read_write
()
{
char
str
[
200
];
char
str
[
USER_INPUT_SIZE
];
int
i
=
0
,
coma_nb
=
0
,
value_idx
;
int
i
=
0
,
coma_nb
=
0
,
value_idx
;
unsigned
addr
,
value
;
unsigned
addr
,
value
;
PRINT
(
PRINT
(
"Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):
\n
"
,
"Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):
\n
"
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
is_supervisor_mode
?
"Supervisor"
:
"User"
)
;
// fflush(stdin);
// fscanf(stdin, "%s", str);
fflush
(
stdin
);
uart_scanf
(
str
);
fscanf
(
stdin
,
"%s"
,
str
);
for
(
i
=
0
;
i
<
strlen
(
str
);
i
++
)
{
for
(
i
=
0
;
i
<
strlen
(
str
);
i
++
)
{
if
(
str
[
i
]
==
','
)
{
if
(
str
[
i
]
==
','
)
{
...
@@ -55,17 +74,21 @@ void exec_user_read_write() {
...
@@ -55,17 +74,21 @@ void exec_user_read_write() {
}
}
if
((
coma_nb
&
(
i
<
2
))
||
i
>
17
)
{
if
((
coma_nb
&
(
i
<
2
))
||
i
>
17
)
{
PRINT_SYNTAX_ERROR
();
PRINT_SYNTAX_ERROR
();
PRINT
(
"(Bad length!)"
);
PRINT
(
"(Bad length!)"
)
;
return
;
return
;
}
}
sscanf
(
str
,
"%x"
,
&
addr
);
sscanf
(
str
,
"%x"
,
&
addr
);
if
(
!
coma_nb
)
{
// if read
if
(
!
coma_nb
)
{
// if read
PRINT
(
"reading address: 0x%08x
\n
"
,
addr
);
PRINT
(
"reading address: 0x%08x
\n
"
,
addr
)
PRINT
(
"value read: 0x%08x
\n
"
,
*
(
unsigned
*
)
addr
);
;
PRINT
(
"value read: 0x%08x
\n
"
,
*
(
unsigned
*
)
addr
)
;
}
else
{
// write
}
else
{
// write
sscanf
(
str
+
value_idx
,
"%x"
,
&
value
);
sscanf
(
str
+
value_idx
,
"%x"
,
&
value
);
PRINT
(
"writing address: 0x%08x with 0x%08x
\n
"
,
addr
,
value
);
PRINT
(
"writing address: 0x%08x with 0x%08x
\n
"
,
addr
,
value
)
;
*
(
unsigned
*
)
addr
=
value
;
*
(
unsigned
*
)
addr
=
value
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
user_cmd.h
+
17
−
3
View file @
9efa67a8
...
@@ -4,16 +4,30 @@
...
@@ -4,16 +4,30 @@
* Created on: 12 nov. 2023
* Created on: 12 nov. 2023
* Author: VP
* Author: VP
*/
*/
#ifndef USER_CMD_H_
#ifndef USER_CMD_H_
#define USER_CMD_H_
#define USER_CMD_H_
#include
<string.h>
#include
"uart.h"
#define UART_STDOUT_SIZE 100
#define USER_INPUT_SIZE 200
static
char
uart_stdout
[
UART_STDOUT_SIZE
]
=
{
0
};
#define UART_ENABLE 0 // if 0, the console is MCUXpresso, otherwise the UART (use a terminal on PC side)
#define UART_ENABLE 1 // if 0, the console is MCUXpresso, otherwise the UART (use a terminal on PC side)
#define uart_printf(...) \
snprintf
(
uart_stdout
,
UART_STDOUT_SIZE
,
__VA_ARGS__
);
\
uart0_send_ref
((
uint8_t
*
)
uart_stdout
,
UART_STDOUT_SIZE
);
#if !UART_ENABLE
#if !UART_ENABLE
#define PRINT printf
#define PRINT printf
#else
#define PRINT uart_printf
#endif
#endif
void
exec_user_read_write
();
void
uart_scanf
(
char
*
buff
);
void
exec_user_read_write
(
void
);
#endif
/* USER_CMD_H_ */
#endif
/* USER_CMD_H_ */
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