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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
pro
G4_mpu
Commits
5da5d725
Commit
5da5d725
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: conditional compilation based on UART_ENABLE macro
parent
a464db86
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mpu_user_console_etu.c
+13
-5
13 additions, 5 deletions
mpu_user_console_etu.c
user_cmd.c
+17
-12
17 additions, 12 deletions
user_cmd.c
user_cmd.h
+4
-4
4 additions, 4 deletions
user_cmd.h
with
34 additions
and
21 deletions
mpu_user_console_etu.c
+
13
−
5
View file @
5da5d725
...
@@ -67,11 +67,17 @@ void ask_user_input(void) {
...
@@ -67,11 +67,17 @@ void ask_user_input(void) {
char
status_cmd
[]
=
"status"
;
char
status_cmd
[]
=
"status"
;
PRINT
(
"
\r\n
(%s) Would you like to `switch` or display `status` errors : "
,
PRINT
(
"
\r\n
(%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);
#if UART_ENABLE
uart_scanf
(
buff
);
uart_scanf
(
buff
);
PRINT
(
"
\r\n
"
);
PRINT
(
"
\r\n
"
)
;
#else
fflush
(
stdin
);
fscanf
(
stdin
,
"%s"
,
buff
);
#endif
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
...
@@ -88,7 +94,7 @@ void ask_user_input(void) {
...
@@ -88,7 +94,7 @@ void ask_user_input(void) {
for
(
int
i
=
0
;
i
<
idx_error
;
i
++
)
{
for
(
int
i
=
0
;
i
<
idx_error
;
i
++
)
{
if
(
i
<
BUF_SIZE
)
{
if
(
i
<
BUF_SIZE
)
{
PRINT
(
"Address
that shat the b
ed : 0x%x
\t
Error code : 0x%x
\r\n
"
,
PRINT
(
"Address
where error occurr
ed : 0x%x
\t
Error code : 0x%x
\r\n
"
,
arr_addr
[
i
],
arr_err_code
[
i
])
arr_addr
[
i
],
arr_err_code
[
i
])
;
;
}
}
...
@@ -109,7 +115,9 @@ void test_user_mode() {
...
@@ -109,7 +115,9 @@ void test_user_mode() {
}
}
int
main
(
void
)
{
int
main
(
void
)
{
#if UART_ENABLE
uart0_init_ref
(
9600
,
NULL
,
NULL
);
uart0_init_ref
(
9600
,
NULL
,
NULL
);
#endif
LPC_GPIO2
->
FIODIR
=
0xFF
;
LPC_GPIO2
->
FIODIR
=
0xFF
;
LPC_GPIO2
->
FIOPIN
=
0
;
LPC_GPIO2
->
FIOPIN
=
0
;
...
...
This diff is collapsed.
Click to expand it.
user_cmd.c
+
17
−
12
View file @
5da5d725
...
@@ -12,19 +12,21 @@
...
@@ -12,19 +12,21 @@
#include
<stdarg.h>
#include
<stdarg.h>
#include
"uart.h"
#include
"uart.h"
#include
"user_cmd.h"
#include
"user_cmd.h"
#include
"macro.h"
#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_mode
(
int
control_value
);
//void switch_to_supervisor_mode(void);
void
SVC_Handler
()
{
void
SVC_Handler
()
{
if
(
!
is_supervisor_mode
)
{
// If user mode
if
(
is_supervisor_mode
)
{
switch_
to_supervisor_mode
(
);
switch_
mode
(
USER_CONTROL_VALUE
);
}
else
{
// If supervisor
}
else
{
switch_
to_user_mode
(
);
switch_
mode
(
SUPERVISOR_CONTROL_VALUE
);
}
}
is_supervisor_mode
=
!
is_supervisor_mode
;
is_supervisor_mode
=
!
is_supervisor_mode
;
}
}
...
@@ -50,13 +52,16 @@ void exec_user_read_write() {
...
@@ -50,13 +52,16 @@ void exec_user_read_write() {
int
i
=
0
,
coma_nb
=
0
,
value_idx
;
int
i
=
0
,
coma_nb
=
0
,
value_idx
;
unsigned
addr
,
value
;
unsigned
addr
,
value
;
PRINT
(
"Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):
\r\n
"
,
PRINT
(
"(%s) Write an hexadecimal address for reading <addr> or <addr>,<value> for writing :
\r\n
"
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
is_supervisor_mode
?
"Supervisor"
:
"User"
)
;
// fflush(stdin);
// fscanf(stdin, "%s", str);
#if UART_ENABLE
uart_scanf
(
str
);
uart_scanf
(
str
);
#else
fflush
(
stdin
);
fscanf
(
stdin
,
"%s"
,
str
);
#endif
for
(
i
=
0
;
i
<
strlen
(
str
);
i
++
)
{
for
(
i
=
0
;
i
<
strlen
(
str
);
i
++
)
{
if
(
str
[
i
]
==
','
)
{
if
(
str
[
i
]
==
','
)
{
...
...
This diff is collapsed.
Click to expand it.
user_cmd.h
+
4
−
4
View file @
5da5d725
...
@@ -14,17 +14,17 @@
...
@@ -14,17 +14,17 @@
static
char
uart_stdout
[
UART_STDOUT_SIZE
]
=
{
0
};
static
char
uart_stdout
[
UART_STDOUT_SIZE
]
=
{
0
};
#define UART_ENABLE
1
// if 0, the console is MCUXpresso, otherwise the UART (use a terminal on PC side)
#define UART_ENABLE
0
// if 0, the console is MCUXpresso, otherwise the UART (use a terminal on PC side)
#define uart_printf(...) \
#define uart_printf(...) \
snprintf
(
uart_stdout
,
UART_STDOUT_SIZE
,
__VA_ARGS__
);
\
snprintf
(
uart_stdout
,
UART_STDOUT_SIZE
,
__VA_ARGS__
);
\
uart0_send_ref
((
uint8_t
*
)
uart_stdout
,
UART_STDOUT_SIZE
);
\
uart0_send_ref
((
uint8_t
*
)
uart_stdout
,
UART_STDOUT_SIZE
);
\
memset
(
uart_stdout
,
0
,
UART_STDOUT_SIZE
);
memset
(
uart_stdout
,
0
,
UART_STDOUT_SIZE
);
#if !UART_ENABLE
#if UART_ENABLE
#define PRINT printf
#else
#define PRINT uart_printf
#define PRINT uart_printf
#else
#define PRINT printf
#endif
#endif
void
uart_scanf
(
char
*
buff
);
void
uart_scanf
(
char
*
buff
);
...
...
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