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
00088 #include <sys/param.h>
00089 #include <sys/ports.h>
00090 #include <sys/interrupts.h>
00091 #include <sys/sio.h>
00092 #include <sys/locks.h>
00093
00094 void output_compare_interrupt (void) __attribute__((interrupt));
00095
00096 #define US_TO_CYCLE(N) ((N) * 2)
00097
00098
00099
00100
00101
00102
00103
00104
00105 static const unsigned short cycle_table[] = {
00106 US_TO_CYCLE (500),
00107 US_TO_CYCLE (500),
00108 US_TO_CYCLE (500),
00109 US_TO_CYCLE (1000),
00110 US_TO_CYCLE (1000),
00111 US_TO_CYCLE (5000),
00112 US_TO_CYCLE (100),
00113 US_TO_CYCLE (500),
00114 US_TO_CYCLE (5000),
00115 US_TO_CYCLE (1000),
00116 US_TO_CYCLE (100),
00117 US_TO_CYCLE (100)
00118 };
00119
00120 #define TABLE_SIZE(T) ((sizeof T / sizeof T[0]))
00121
00122 #ifdef USE_INTERRUPT_TABLE
00123
00124
00125
00126
00127
00128
00129
00130 struct interrupt_vectors __attribute__((section(".vectors"))) vectors =
00131 {
00132 res0_handler: fatal_interrupt,
00133 res1_handler: fatal_interrupt,
00134 res2_handler: fatal_interrupt,
00135 res3_handler: fatal_interrupt,
00136 res4_handler: fatal_interrupt,
00137 res5_handler: fatal_interrupt,
00138 res6_handler: fatal_interrupt,
00139 res7_handler: fatal_interrupt,
00140 res8_handler: fatal_interrupt,
00141 res9_handler: fatal_interrupt,
00142 res10_handler: fatal_interrupt,
00143 sci_handler: fatal_interrupt,
00144 spi_handler: fatal_interrupt,
00145 acc_overflow_handler: fatal_interrupt,
00146 acc_input_handler: fatal_interrupt,
00147 timer_overflow_handler: fatal_interrupt,
00148 output5_handler: fatal_interrupt,
00149 output3_handler: fatal_interrupt,
00150 output2_handler: fatal_interrupt,
00151 output1_handler: fatal_interrupt,
00152 capture3_handler: fatal_interrupt,
00153 capture2_handler: fatal_interrupt,
00154 capture1_handler: fatal_interrupt,
00155 rtii_handler: fatal_interrupt,
00156 irq_handler: fatal_interrupt,
00157 xirq_handler: fatal_interrupt,
00158 swi_handler: fatal_interrupt,
00159 illegal_handler: fatal_interrupt,
00160 cop_fail_handler: fatal_interrupt,
00161 cop_clock_handler: fatal_interrupt,
00162
00163
00164 output4_handler: output_compare_interrupt,
00165 reset_handler: _start
00166 };
00167
00168 #endif
00169
00170 static const unsigned short* cycle_next;
00171 static volatile unsigned char wakeup;
00172 static unsigned short change_time;
00173
00174
00175 void
00176 output_compare_interrupt (void)
00177 {
00178 unsigned short dt;
00179
00180 _io_ports[M6811_TFLG1] |= M6811_OC4F;
00181
00182
00183 dt = *cycle_next;
00184 dt += change_time;
00185 set_output_compare_4 (dt);
00186 change_time = dt;
00187
00188
00189 cycle_next++;
00190 if (cycle_next >= &cycle_table[TABLE_SIZE (cycle_table)])
00191 cycle_next = cycle_table;
00192
00193 wakeup = 1;
00194 }
00195
00196 int
00197 main ()
00198 {
00199 unsigned short j;
00200 unsigned char c = 0;
00201 unsigned char i = 0;
00202
00203 lock ();
00204 serial_init ();
00205
00206
00207 set_interrupt_handler (TIMER_OUTPUT4_VECTOR, output_compare_interrupt);
00208
00209 cycle_next = cycle_table;
00210
00211
00212 _io_ports[M6811_TCTL1] = M6811_OL4;
00213 _io_ports[M6811_TMSK1] = M6811_OC4I;
00214
00215
00216 change_time = get_timer_counter () + 300;
00217 set_output_compare_4 (change_time);
00218 unlock ();
00219
00220 for (j = 0; j < 1000; j++)
00221 {
00222
00223 wakeup = 0;
00224 while (wakeup == 0)
00225 continue;
00226
00227
00228
00229 c++;
00230 if (c == 1)
00231 serial_send ('\b');
00232 else if (c == 128)
00233 serial_send ("-\\|/"[(++i) & 3]);
00234 }
00235 return 0;
00236 }