Skip to content
Snippets Groups Projects
Commit 5da5d725 authored by iliya's avatar iliya
Browse files

feat: conditional compilation based on UART_ENABLE macro

parent a464db86
No related branches found
No related tags found
No related merge requests found
...@@ -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 bed : 0x%x\tError code : 0x%x\r\n", PRINT("Address where error occurred : 0x%x\tError 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;
......
...@@ -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] == ',') {
......
...@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment