00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00052 #include "trap.h"
00053
00054 #ifdef USE_INTERRUPT_TABLE
00055
00056
00057
00058
00059
00060
00061
00062 struct interrupt_vectors __attribute__((section(".vectors"))) vectors =
00063 {
00064 res0_handler: fatal_interrupt,
00065 res1_handler: fatal_interrupt,
00066 res2_handler: fatal_interrupt,
00067 res3_handler: fatal_interrupt,
00068 res4_handler: fatal_interrupt,
00069 res5_handler: fatal_interrupt,
00070 res6_handler: fatal_interrupt,
00071 res7_handler: fatal_interrupt,
00072 res8_handler: fatal_interrupt,
00073 res9_handler: fatal_interrupt,
00074 res10_handler: fatal_interrupt,
00075 sci_handler: fatal_interrupt,
00076 spi_handler: fatal_interrupt,
00077 acc_overflow_handler: fatal_interrupt,
00078 acc_input_handler: fatal_interrupt,
00079 timer_overflow_handler: fatal_interrupt,
00080 output5_handler: fatal_interrupt,
00081 output4_handler: fatal_interrupt,
00082 output3_handler: fatal_interrupt,
00083 output2_handler: fatal_interrupt,
00084 output1_handler: fatal_interrupt,
00085 capture3_handler: fatal_interrupt,
00086 capture2_handler: fatal_interrupt,
00087 capture1_handler: fatal_interrupt,
00088 rtii_handler: fatal_interrupt,
00089 irq_handler: fatal_interrupt,
00090 xirq_handler: fatal_interrupt,
00091 illegal_handler: fatal_interrupt,
00092 cop_fail_handler: fatal_interrupt,
00093 cop_clock_handler: fatal_interrupt,
00094
00095
00096 swi_handler: os_trap_handler,
00097 reset_handler: _start
00098 };
00099
00100 #endif
00101
00102 extern int global_result;
00103
00104 int
00105 main()
00106 {
00107 int result;
00108 int failed;
00109
00110 serial_init ();
00111
00112 #ifndef USE_INTERRUPT_TABLE
00113
00114
00115
00116 set_interrupt_handler (SWI_VECTOR, (interrupt_t) simple_trap_handler);
00117 print ("Using simple trap handler: ");
00118 failed = 0;
00119 simple_trap_handler (1);
00120 if (global_result != 1)
00121 {
00122 print (" Simple trap handler failed, didn't returned 1\r\n");
00123 failed = 1;
00124 }
00125
00126 simple_trap_handler (2);
00127 if (global_result != 4)
00128 {
00129 print (" Simple trap handler failed, didn't returned 4\r\n");
00130 failed = 1;
00131 }
00132 if (failed == 0)
00133 print ("OK\r\n");
00134
00135
00136 set_interrupt_handler (SWI_VECTOR, (interrupt_t) add_trap_handler);
00137 failed = 0;
00138 print ("Using add trap handler: ");
00139 result = add_trap_handler (1, 2, 3, 4);
00140 if (result != 10)
00141 {
00142 print ("Add trap handler didn't returned 10\r\n");
00143 failed = 1;
00144 }
00145 result = add_trap_handler (5, 6, 7, 8);
00146 if (result != 26)
00147 {
00148 print ("Add trap handler didn't returned 26\r\n");
00149 failed = 1;
00150 }
00151 if (failed == 0)
00152 print ("OK\r\n");
00153 #endif
00154
00155 set_interrupt_handler (SWI_VECTOR, (interrupt_t) os_trap_handler);
00156 failed = 0;
00157 print ("Using OS trap handler...\r\n");
00158 result = os_trap_handler (0, " Hello World from os_trap_handler...\r\n");
00159 if (result != 0)
00160 {
00161 print (" OS call 0 failed\r\n");
00162 failed = 1;
00163 }
00164
00165 result = os_trap_handler (0, " Type a character ");
00166 if (result != 0)
00167 {
00168 print (" OS call 0 failed\r\n");
00169 failed = 1;
00170 }
00171
00172 result = os_trap_handler (1);
00173
00174 result = os_trap_handler (2, 23, 44);
00175 if (result != 23 + 44)
00176 {
00177 print (" OS add system call failed\r\n");
00178 failed = 1;
00179 }
00180
00181 if (failed == 0)
00182 print ("OS trap call test ok.\r\n");
00183
00184 print ("Trap handler test finished.\r\n");
00185 return 0;
00186 }