analyzer.c00001
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
00050 #include "analyzer.h"
00051
00052 #define TIMER_DIV (8192L)
00053 #define TIMER_TICK (M6811_CPU_E_CLOCK / TIMER_DIV)
00054
00055
00056
00057 #define USEC_PER_TICK (1)
00058 #define USEC_DIVISOR (2)
00059
00060 void
00061 collect_samples (sample_list_t *samples)
00062 {
00063 unsigned i;
00064 unsigned char current_port;
00065 sample_t *sample;
00066
00067 sample = samples->first;
00068 current_port = _io_ports[M6811_PORTA];
00069 for (i = samples->length; i != 0; i--, sample++) {
00070 unsigned char c;
00071
00072 #ifdef TEST
00073 unsigned k = 0;
00074 #endif
00075 do {
00076 #ifdef TEST
00077 if (k == 0) {
00078 _io_ports[M6811_PORTA] ^= 0x80;
00079 } else {
00080 k++;
00081 }
00082 #endif
00083 c = current_port ^ _io_ports[M6811_PORTA];
00084 } while (c == 0);
00085 sample->tick = get_timer_counter ();
00086 c = c ^ current_port;
00087 sample->port = c;
00088 current_port = c;
00089 }
00090 }
00091
00092 void
00093 report_samples (sample_list_t *samples)
00094 {
00095 sample_t *sample;
00096 unsigned i;
00097 sample_t *prev;
00098
00099 prev = samples->first;
00100 sample = &prev[1];
00101 for (i = samples->length - 1; i != 0; i--, sample++) {
00102 unsigned dt;
00103 unsigned char c;
00104 unsigned long usec;
00105
00106 c = sample->port;
00107 dt = sample->tick - prev->tick;
00108 usec = (((unsigned long) dt) * USEC_PER_TICK) / USEC_DIVISOR;
00109 printf ("%lu %lu %c %c %c\n",
00110 (long) dt, usec,
00111 (int) (c & 1 ? '1' : '0'),
00112 (int) (c & 2 ? '1' : '0'),
00113 (int) (c & 4 ? '1' : '0'));
00114 prev = sample;
00115 }
00116 }
00117
00118 #define MAX_SAMPLES (256)
00119
00120 sample_t sample_buffer[MAX_SAMPLES];
00121
00122 int
00123 main ()
00124 {
00125 sample_list_t list;
00126
00127 serial_init ();
00128
00129 #ifdef TEST
00130 _io_ports[M6811_PACTL] |= M6811_DDRA7;
00131 #endif
00132 list.length = MAX_SAMPLES;
00133 list.first = sample_buffer;
00134 lock ();
00135 while (1)
00136 {
00137 collect_samples (&list);
00138 report_samples (&list);
00139 }
00140 }
|