summaryrefslogtreecommitdiff
path: root/test_general/ecos/src/exception.c
diff options
context:
space:
mode:
Diffstat (limited to 'test_general/ecos/src/exception.c')
-rw-r--r--test_general/ecos/src/exception.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/test_general/ecos/src/exception.c b/test_general/ecos/src/exception.c
new file mode 100644
index 0000000000..09f6dbd55f
--- /dev/null
+++ b/test_general/ecos/src/exception.c
@@ -0,0 +1,72 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file exception.c
+ * \brief how to catch an exception
+ * \ingroup
+ *
+ * this is a test program to check eCos well work
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+#include <cyg/hal/hal_intr.h>
+#include "common/std.h"
+
+void system_call_exception(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info)
+{
+ switch(number)
+ {
+ case CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION:
+ diag_printf("eCos: Exception Error (Illegal Instruction)!!!\n");
+ break;
+
+ case CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS:
+ diag_printf("eCos: Exception Error (Data Access Unaligned)!!!\n");
+ break;
+ default:
+ diag_printf("eCos: Exception Error (Unknown)!!!\n");
+ }
+// cyg_hal_sys_exit(1);
+}
+
+void cyg_user_start(void)
+{
+ unsigned int *ptr = (unsigned int*)0x00000001;
+ cyg_exception_handler_t *oldHandler;
+ cyg_addrword_t oldData;
+
+ //config UART
+ unsigned int *uart_scaler = (unsigned int*)0x8000007C;
+ unsigned int *uart_ctrl = (unsigned int*)0x80000078;
+ *uart_scaler = 0xF4; //soit 75MHz / (8 * 38400)
+ *uart_ctrl = 0x3; //enable TX and RX
+
+ diag_write_string("debut du main\n");
+
+ cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION,
+ &system_call_exception,
+ 0,
+ &oldHandler,
+ &oldData);
+ cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS,
+ &system_call_exception,
+ 0,
+ &oldHandler,
+ &oldData);
+
+ diag_write_string("exception enregistrees\n");
+
+ // 1st exception : undefined instruction
+ asm volatile ("unimp 0\n\t");
+ // 2nd exception : unaligned address
+ *ptr = 12;
+
+ diag_write_string("fin du main\n");
+}
+