Changeset 56 in projects
- Timestamp:
- Jan 1, 2010, 1:14:40 PM (14 years ago)
- Location:
- punch-card/driver/documation-m200
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
punch-card/driver/documation-m200/avr-m200-card-reader-controller.aps
r51 r56 1 <AVRStudio><MANAGEMENT><ProjectName>avr-m200-card-reader-controller</ProjectName><Created>03-Dec-2009 19:44:28</Created><LastEdit> 14-Dec-2009 21:39:14</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>03-Dec-2009 19:44:28</Created><Version>4</Version><Build>4, 17, 0, 655</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>bin\avr-m200-card-reader-controller.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>D:\Server\htdocs\paper-tape-project\punch-card\driver\documation-m200\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega644.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>src\main.c</SOURCEFILE><SOURCEFILE>src\punchcard.c</SOURCEFILE><SOURCEFILE>src\protocol.c</SOURCEFILE><SOURCEFILE>src\driver.c</SOURCEFILE><HEADERFILE>src\punchcard.h</HEADERFILE><HEADERFILE>src\wiring.h</HEADERFILE><HEADERFILE>D:\Server\htdocs\paper-tape-project\punch-card\protocols\documation-m200\pc-uc-protocol.h</HEADERFILE><HEADERFILE>src\protocol.h</HEADERFILE><HEADERFILE>src\driver.h</HEADERFILE><OTHERFILE>bin\avr-m200-card-reader-controller.lss</OTHERFILE><OTHERFILE>bin\avr-m200-card-reader-controller.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega644</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>avr-m200-card-reader-controller.elf</OUTPUTFILENAME><OUTPUTDIR>bin\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS/><INCDIRS><INCLUDE>..\protocols\documation-m200\</INCLUDE><INCLUDE>..\..\protocols\documation-m200\</INCLUDE></INCDIRS><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>D:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>D:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="1" ordergroup="0"/></IOView><Files></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>1 <AVRStudio><MANAGEMENT><ProjectName>avr-m200-card-reader-controller</ProjectName><Created>03-Dec-2009 19:44:28</Created><LastEdit>01-Jan-2010 13:04:14</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>03-Dec-2009 19:44:28</Created><Version>4</Version><Build>4, 17, 0, 655</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>bin\avr-m200-card-reader-controller.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega644.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>src\main.c</SOURCEFILE><SOURCEFILE>src\punchcard.c</SOURCEFILE><SOURCEFILE>src\protocol.c</SOURCEFILE><SOURCEFILE>src\driver.c</SOURCEFILE><HEADERFILE>src\punchcard.h</HEADERFILE><HEADERFILE>src\wiring.h</HEADERFILE><HEADERFILE>src\protocol.h</HEADERFILE><HEADERFILE>src\driver.h</HEADERFILE><HEADERFILE>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\protocols\documation-m200\pc-uc-protocol.h</HEADERFILE><OTHERFILE>bin\avr-m200-card-reader-controller.lss</OTHERFILE><OTHERFILE>bin\avr-m200-card-reader-controller.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega644</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>avr-m200-card-reader-controller.elf</OUTPUTFILENAME><OUTPUTDIR>bin\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS/><INCDIRS><INCLUDE>..\protocols\documation-m200\</INCLUDE><INCLUDE>..\..\protocols\documation-m200\</INCLUDE></INCDIRS><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\punchcard.h</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\wiring.h</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\protocol.h</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\driver.h</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\protocols\documation-m200\pc-uc-protocol.h</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\main.c</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\punchcard.c</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\protocol.c</Name><Name>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\src\driver.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="1" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>src\driver.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\protocols\documation-m200\pc-uc-protocol.h</FileName><Status>1</Status></File00001><File00002><FileId>00002</FileId><FileName>src\driver.h</FileName><Status>1</Status></File00002><File00003><FileId>00003</FileId><FileName>src\punchcard.h</FileName><Status>1</Status></File00003><File00004><FileId>00004</FileId><FileName>src\main.c</FileName><Status>1</Status></File00004><File00005><FileId>00005</FileId><FileName>src\wiring.h</FileName><Status>1</Status></File00005><File00006><FileId>00006</FileId><FileName>src\protocol.c</FileName><Status>1</Status></File00006><File00007><FileId>00007</FileId><FileName>src\protocol.h</FileName><Status>1</Status></File00007><File00008><FileId>00008</FileId><FileName>src\punchcard.c</FileName><Status>1</Status></File00008></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio> -
punch-card/driver/documation-m200/bin/Makefile
r51 r56 38 38 39 39 ## Include Directories 40 INCLUDES = -I" D:\Server\htdocs\paper-tape-project\punch-card\driver\documation-m200\..\protocols\documation-m200" -I"D:\Server\htdocs\paper-tape-project\punch-card\driver\documation-m200\..\..\protocols\documation-m200"40 INCLUDES = -I"C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\..\protocols\documation-m200" -I"C:\Dokumente und Einstellungen\Physik\Desktop\paper-tape-project\punch-card\driver\documation-m200\..\..\protocols\documation-m200" 41 41 42 42 ## Objects that must be built in order to link -
punch-card/driver/documation-m200/src/driver.c
r51 r56 25 25 case (1 << PINB_MOCK): name = "MOCK"; break; 26 26 case 0: 27 printf("Too lazy, but not "); // und jetzt nicht breaken :-)27 dprintf("Too lazy, but not "); // und jetzt nicht breaken :-) 28 28 default: 29 printf("Illegal PCINT1 raise: %x=>%x, %x, %x\n", status.prev_pinb, pinb_jetzt, pin_changed, rising_edge);29 dprintf("Illegal PCINT1 raise: %x=>%x, %x, %x\n", status.prev_pinb, pinb_jetzt, pin_changed, rising_edge); 30 30 status.prev_pinb = pinb_jetzt; 31 31 return; 32 32 } 33 33 34 printf("%s %s\n", name, rising_edge ? "raising" : "falling");34 dprintf("%s %s\n", name, rising_edge ? "raising" : "falling"); 35 35 36 36 status.prev_pinb = pinb_jetzt; … … 39 39 40 40 ISR(PCINT2_vect) { 41 // this routine is called for 42 // * PINC_IM : Index Mark (store current column) 41 // this routine is called for low speed lines 43 42 // * PINC_RDY : Ready (reader ready for new Pick Command) 44 43 // * PINC_BSY : Busy (card edge - there is a card) 44 // * no more: PINC_IM : Index Mark (store current column), now has an own interrupt line 45 45 // to find out what changed, we make a backup of the former 46 46 // PINC at the end of this routine. … … 59 59 if( check_pin(PINC, PINC_PC) ) { 60 60 // we have started already... 61 puts("READY rising, starting ASAP"); 61 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_READY M200_SERVER_SIGNAL_RISE 62 " already started\n"); 62 63 } else { 63 64 // check if there's space in the buffer to start up … … 69 70 // start. BSY signal will create new card. 70 71 start_reader(); 72 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_READY M200_SERVER_SIGNAL_RISE 73 " firing up\n"); 71 74 } 72 75 } 73 76 } 74 puts("READY rising"); 77 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_READY M200_SERVER_SIGNAL_RISE 78 " Ready rising, no specific action\n"); 75 79 } else { 76 80 // device is no more ready -- perhaps user shutdown (by button). 77 puts("READY falling"); 81 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_READY M200_SERVER_SIGNAL_FALL 82 " Ready falling\n"); 78 83 } 79 84 break; … … 85 90 if(card_buffer_write_advance() != SUCCESS) { 86 91 // No more space in buffer! VERY BAD! 87 puts("BUSY rising, LOOSING DATA!"); 88 } else 89 printf("BUSY rising, new card %d (reader: %d)\n", 90 card_buffer.write_offset, card_buffer.read_offset); 91 } else { 92 puts("BUSY rising, staying card"); 92 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_BUSY M200_SERVER_SIGNAL_RISE "\n"); 93 fatal_printf("No space! LOOSING DATA"); 94 } else { 95 info_printf(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_BUSY M200_SERVER_SIGNAL_RISE 96 "card %d (r=%d)\n", card_buffer.write_offset, card_buffer.read_offset); 97 } 98 } else { 99 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_BUSY M200_SERVER_SIGNAL_RISE 100 " staying card\n"); 93 101 } 94 102 } else { 95 puts("BSY falling"); 96 103 // BUSY falling. 97 104 // nochmal sicherheitshalber, wobei das sowieso viel zu spaet ist 98 105 if( !card_buffer_count_free() ) { 99 106 stop_reader(); 107 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_BUSY M200_SERVER_SIGNAL_FALL 108 " falling, buffer full\n"); 109 } else { 110 info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_BUSY M200_SERVER_SIGNAL_FALL 111 " falling, OK\n"); 100 112 } 101 113 } … … 104 116 case 0: 105 117 // Signal lag zu kurz an 106 printf("Lost Interrupt, state %x ed=%x\n", pinc_jetzt, rising_edge);118 fatal_printf("Lost Interrupt, state %x ed=%x", pinc_jetzt, rising_edge); 107 119 break; 108 120 default: 109 121 // illegal intterupt! 110 printf("Illegal interrupt! PINC was %x is %x changed %x flanke %x\n",122 fatal_printf("Illegal interrupt! PINC was %x is %x changed %x flanke %x", 111 123 status.prev_pinc, pinc_jetzt, pin_changed, rising_edge); 112 124 break; … … 125 137 if( ! (PINC & (1 << PINC_BSY)) ) { 126 138 // die kann man verwerfen, keine Kartenkante 127 puts("IMS");139 dprintf("IMS"); 128 140 return; 129 141 } 130 142 143 // check for index bounds 131 144 if(current_write_card.offset < 0 || current_write_card.offset >= CARD_LEN ) { 132 puts("BAD card! Stopping reader"); 133 if(PINC & (1 << PORTC_PC)) { 134 puts("Reader wasnt stopped"); 145 if(is_reading()) { 146 fatal_printf("Reader was still running"); 135 147 } 136 148 stop_reader(); 149 // first do the work, then the lengthy error output 150 fatal_printf("BAD card! Stopping reader (current_write_card.offset=%d out of bounds)", current_write_card.offset); 137 151 return; 138 152 } … … 167 181 // finalize the current card 168 182 //current_write_card.offset = CARD_READY; // unnoetig, da CARD_READY == CARD_LEN 169 puts("wr++");183 dprintf("wr++"); 170 184 171 185 // try to create a new card … … 173 187 // no more space! turn off Punch Instruction! 174 188 stop_reader(); 175 puts("No more space on buffer.");189 dprintf("No more space on buffer. Waiting for space"); 176 190 status.reader_waits_for_space = 1; 177 191 } … … 181 195 182 196 // und Blinken darf er auch gerne :-) 183 if (PINB & 0b00000001) 184 start_led(); 185 else 186 stop_led(); 197 toggle_led(); 187 198 } 188 199 189 200 190 201 // Wird von Hauptschleife aufgerufen 191 void process_ buffer_queue(enum format_t out_format) {202 void process_card_buffer() { 192 203 // after handling user input, handle buffer 193 204 if( current_read_card.offset == CARD_READY ) { 194 printf("Karte in rd %d rw %d, cols rd %d rw %d\n", card_buffer.read_offset, card_buffer.write_offset,205 dprintf("Karte in rd %d rw %d, cols rd %d rw %d", card_buffer.read_offset, card_buffer.write_offset, 195 206 current_read_card.offset, current_write_card.offset); 196 207 … … 200 211 //break; // Karte NICHT komplett ausgeben. Hier stoppen. 201 212 202 print_card( out_format);213 print_card(); 203 214 204 215 … … 212 223 // Karte zu kommen 213 224 if( card_buffer_read_advance() != SUCCESS) { 214 puts("output waiting for next");225 dprintf("output waiting for next"); 215 226 } else { 216 puts("cr+");227 dprintf("cr+"); 217 228 } 218 229 … … 228 239 start_reader(); 229 240 } else { 230 puts("Deadline, writer waits for reader");241 fatal_printf("Deadline, writer waits for reader"); 231 242 } 232 243 } -
punch-card/driver/documation-m200/src/driver.h
r51 r56 37 37 #include "protocol.h" 38 38 39 void process_buffer_queue(enum format_t out_format); 39 void process_card_buffer(); 40 41 #define CONCURRENT_PRINTING_BUFFER_LEN 80 40 42 41 43 // some kind of global storage for some quick & dirty solutions … … 46 48 } user_instruction; 47 49 50 enum format_t out_format; 51 52 volatile bool_t main_loop_is_printing; 53 char concurrent_printing_buffer[CONCURRENT_PRINTING_BUFFER_LEN]; 54 volatile bool_t concurrent_printing_buffer_is_just_being_flushed; 55 uint8_t concurrent_printing_buffer_pos; 56 57 bool_t debug_output; 48 58 49 59 // for ISR -
punch-card/driver/documation-m200/src/main.c
r51 r56 52 52 53 53 54 static FILE uart = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE); 54 static FILE main_thread = FDEV_SETUP_STREAM(uart_transmit_main, NULL, _FDEV_SETUP_WRITE); 55 static FILE interrupt_thread = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE); 55 56 56 57 /** … … 119 120 120 121 // nette sachen machen koennen 121 stdout = &uart; 122 stdout = &main_thread; 123 stderr = &interrupt_thread; 124 125 // default-Werte 126 status.out_format = M200_CLIENT_DEBUG; 127 status.debug_output = FALSE; 128 status.main_loop_is_printing = FALSE; 129 status.concurrent_printing_buffer_pos = 0; 130 122 131 123 132 user_input_loop(); -
punch-card/driver/documation-m200/src/protocol.c
r51 r56 7 7 #include <stdio.h> 8 8 #include <avr/pgmspace.h> // for all the strings 9 #include <assert.h> 10 #include <string.h> 11 9 12 10 13 #include "protocol.h" … … 35 38 M200_SERVER_HELP " 5 Set output to binary output (you don't want to do that in a terminal)\n" 36 39 M200_SERVER_HELP " 6 Reset internal buffers, stop punching (same as c...)\n" 37 M200_SERVER_HELP "\n"; 40 M200_SERVER_HELP " 7 Toggle verbose debugging output (comes all the time, for experts only)\n" 41 M200_SERVER_HELP; // puts => no newline 38 42 39 43 40 44 void print_startup_message() { 41 printf(M200_SERVER_STARTUP " v%d.%d Welcome to the M200 Punch Card Reader Microcontroller\n",45 main_loop_printf(M200_SERVER_STARTUP " v%d.%d Welcome to the M200 Punch Card Reader Microcontroller\n", 42 46 M200_PROTOCOL_VERSION_MAJOR, M200_PROTOCOL_VERSION_MINOR); 43 puts(M200_SERVER_HELP " type 'h' for help.");47 main_loop_puts(M200_SERVER_HELP " type 'h' for help."); 44 48 } 45 49 46 50 // Haupt-Transmit-Routine, backend von stdio 47 int uart_transmit (char c, FILE* stream) {51 int uart_transmit_main(char c, FILE* stream) { 48 52 if(c == '\n') 49 uart_transmit ('\r', stream);53 uart_transmit_main('\r', stream); 50 54 51 55 while (!(UCSR0A & 0b00100000)); … … 53 57 UDR0 = c; 54 58 return 0; 59 } 60 61 // concurrent transmission routine, backend von stderr 62 int uart_transmit(char c, FILE* stream) { 63 // use stderr if you are not in main loop and you cannot 64 // be sure that the mainloop is currently printing 65 if(status.main_loop_is_printing) { 66 // save the contents 67 if(status.concurrent_printing_buffer_is_just_being_flushed) { 68 // what a pity. Don't touch it... 69 return -1; 70 } 71 if(status.concurrent_printing_buffer_pos >= CONCURRENT_PRINTING_BUFFER_LEN - 1) { 72 // buffer is full (-1 for space for the '\n\0'), inform the reciever that information was lost 73 assert(CONCURRENT_PRINTING_BUFFER_LEN > 6); 74 // This appends the corresponding error symbol to the buffer 75 // so that the reciever will know that information was lost 76 strcpy(status.concurrent_printing_buffer + CONCURRENT_PRINTING_BUFFER_LEN - 4 , 77 M200_SERVER_FATAL_PRINT_BUFFER); 78 return 1; 79 } 80 // there's still some place in the line 81 status.concurrent_printing_buffer[ status.concurrent_printing_buffer_pos++ ] = c; 82 status.concurrent_printing_buffer[ status.concurrent_printing_buffer_pos ] = '\0'; 83 return 0; 84 } else { 85 // just go ahead and do your work 86 return uart_transmit_main(c, stream); 87 } 88 } 89 90 void flush_concurrent_printing_buffer() { 91 status.concurrent_printing_buffer_is_just_being_flushed = 1; 92 if(status.concurrent_printing_buffer_pos > 0) { 93 // print out buffer contents, with trailing newline 94 puts( status.concurrent_printing_buffer ); 95 } 96 strcpy(status.concurrent_printing_buffer, ""); 97 status.concurrent_printing_buffer_pos = 0; 98 status.concurrent_printing_buffer_is_just_being_flushed = 0; 55 99 } 56 100 … … 74 118 } 75 119 76 void print_card( enum format_t out_format) {77 switch( out_format) {120 void print_card() { 121 switch(status.out_format) { 78 122 case HEX: 79 123 for(uint8_t col = 0; col < CARD_LEN; col++) { 80 printf(M200_SERVER_HEX_PREFIX "%02d 0x%x 0x%x\n", col,124 main_loop_printf(M200_SERVER_HEX_PREFIX "%02d 0x%x 0x%x\n", col, 81 125 (uint8_t) (current_read_card.columns[col] >> 8), 82 126 (uint8_t) (current_read_card.columns[col]) … … 86 130 case DEBUG: 87 131 for(uint8_t col = 0; col < CARD_LEN; col++) { 132 set_main_loop_printing(TRUE); 88 133 printf(M200_SERVER_DEBUG_PREFIX "%02d ", col); 89 134 column_print( ¤t_read_card.columns[col] ); 90 puts(""); // newline? 135 // newline done by column print 136 set_main_loop_printing(FALSE); 91 137 } 92 138 break; 93 139 case BINARY: 140 set_main_loop_printing(TRUE); 94 141 puts(M200_SERVER_BINARY " BINARY"); 95 142 { … … 107 154 } 108 155 puts(M200_SERVER_BINARY_PREFIX "08 FINISHED"); 156 set_main_loop_printing(FALSE); 109 157 break; 110 158 default: 111 puts("550 Illegal Format at runtime");159 main_loop_printf("550 Illegal Format %d\n", status.out_format); 112 160 } // switch out_format 113 161 } 114 162 115 163 void user_input_loop() { 116 enum format_t out_format = DEBUG;117 164 unsigned char input = NO_INPUT; 118 165 … … 126 173 case M200_CLIENT_HELP: 127 174 // print out very long help message 128 puts_P(help_message); 129 break; 175 main_loop_puts_P(help_message); 176 break; 177 130 178 case M200_CLIENT_PING: 131 179 // print out some ping pong thingy 132 puts(M200_SERVER_PONG " Pong"); 133 break; 180 main_loop_puts(M200_SERVER_PONG " Pong"); 181 break; 182 134 183 case M200_CLIENT_START: 135 184 status.user_instruction = START_READER; 185 main_loop_puts(M200_SERVER_ACK_START " Strobing start signal..."); 136 186 start_reader(); 137 187 start_led(); 138 188 break; 189 139 190 case M200_CLIENT_STOP: 140 191 status.user_instruction = STOP_READER; 141 192 stop_reader(); 142 193 stop_led(); 143 break; 194 main_loop_puts(M200_SERVER_ACK_STOP " Stopped read instruction"); 195 break; 196 144 197 case M200_CLIENT_HEX: 145 198 case M200_CLIENT_DEBUG: 146 199 case M200_CLIENT_BINARY: 147 200 if(!is_valid_format(input)) { 148 printf(M200_SERVER_ILLEGAL_FORMAT " Illegal format ''%c'! Type `h` for valid formats\n", input);201 main_loop_printf(M200_SERVER_ILLEGAL_FORMAT " Illegal format ''%c'! Type `h` for valid formats\n", input); 149 202 break; 150 203 } 151 out_format = input; 152 printf(M200_SERVER_ACK_PREFIX "%c input format set okay\n", out_format); 204 status.out_format = input; 205 main_loop_printf(M200_SERVER_ACK_PREFIX "%c input format set okay\n", status.out_format); 206 break; 153 207 154 208 case M200_CLIENT_RESET: … … 157 211 stop_led(); 158 212 card_buffer_flush(); 159 puts(M200_SERVER_ACK_RESET " Resetted instruction storage, pins, cycle memory");213 main_loop_puts(M200_SERVER_ACK_RESET " Resetted instruction storage, pins, cycle memory"); 160 214 print_startup_message(); 161 215 break; 216 217 case M200_CLIENT_VERBOSE: 218 status.debug_output = status.debug_output ? FALSE : TRUE; 219 main_loop_printf(M200_SERVER_ACK_VERBOSE " Verbosity is now %s\n", status.debug_output ? "ON" : "OFF"); 220 break; 221 162 222 default: 163 printf(M200_SERVER_ILLEGAL_COMMAND " Illegal command '%c'! Type `h` for valid commands\n", input);223 main_loop_printf(M200_SERVER_ILLEGAL_COMMAND " Illegal command '%c'! Type `h` for valid commands\n", input); 164 224 } // switch 165 225 } // if user input 166 226 167 227 // KARTE ABHANDELN 168 process_ buffer_queue(out_format);228 process_card_buffer(); 169 229 } // while 1 170 230 } // function -
punch-card/driver/documation-m200/src/protocol.h
r51 r56 30 30 #include "pc-uc-protocol.h" 31 31 #include "punchcard.h" 32 // #include "driver.h" 32 33 33 34 #include <stdio.h> … … 42 43 #define is_valid_format(f) ( f == HEX || f == DEBUG || f == BINARY ) 43 44 44 // A char value as return value from uart_transmit 45 int uart_transmit(char c, FILE* stream); 46 int uart_transmit_main(char c, FILE* stream); 47 48 // A char value as return value from uart_recieve 45 49 #define NO_INPUT 0 46 47 int uart_transmit(char c, FILE* stream);48 49 50 unsigned char uart_recieve(); 50 51 51 52 void print_bits(byte_t byte); 52 53 53 void print_card(enum format_t out_format); 54 void print_card(); 55 56 void flush_concurrent_printing_buffer(); 57 58 #define set_main_loop_printing(val) { status.main_loop_is_printing = val; if(!val) flush_concurrent_printing_buffer(); } 59 #define main_loop_puts(arg) { set_main_loop_printing(TRUE); puts(arg); set_main_loop_printing(FALSE); } 60 #define main_loop_puts_P(arg) { set_main_loop_printing(TRUE); puts_P(arg); set_main_loop_printing(FALSE); } 61 #define main_loop_printf(arg...) { set_main_loop_printing(TRUE); printf(arg); set_main_loop_printing(FALSE); } 62 63 64 #define info_puts(arg) fputs(arg, stderr) 65 #define info_puts_P(arg) fputs_P(arg, stderr) 66 #define info_printf(arg...) fprintf(stderr, arg) 67 #define dprintf(arg...) { if(status.debug_output) { fprintf(stderr, "400 "); fprintf(stderr, arg); fputs("", stderr); } } 68 #define fatal_printf(arg...) { fprintf(stderr, "900"); fprintf(stderr, arg); fputs("", stderr); } 54 69 55 70 void user_input_loop(); -
punch-card/driver/documation-m200/src/punchcard.c
r50 r56 5 5 6 6 #include "punchcard.h" 7 #include "protocol.h" 8 #include "driver.h" 7 9 #include <string.h> 8 10 #include <stdio.h> … … 48 50 // Puffer ist leer! 49 51 // (writer arbeitet noch auf dem aktuellen offset) 50 printf("Read: full new=%d, rd %d rw %d, cols rd %d rw %d\n", new_offset, card_buffer.read_offset, card_buffer.write_offset,52 dprintf("Read: full new=%d, rd %d rw %d, cols rd %d rw %d\n", new_offset, card_buffer.read_offset, card_buffer.write_offset, 51 53 current_read_card.offset, current_write_card.offset); 52 54 return BUFFER_EMPTY; … … 72 74 if( new_offset == card_buffer.read_offset ) { 73 75 // Puffer ist voll! 74 printf("Write: full new=%d, rd %d rw %d, cols rd %d rw %d\n", new_offset, card_buffer.read_offset, card_buffer.write_offset,76 dprintf("Write: full new=%d, rd %d rw %d, cols rd %d rw %d\n", new_offset, card_buffer.read_offset, card_buffer.write_offset, 75 77 current_read_card.offset, current_write_card.offset); 76 78 return BUFFER_FULL; -
punch-card/driver/documation-m200/src/wiring.h
r51 r56 93 93 #define start_reader() ( PORTC |= (1 << PORTC_PC) ) 94 94 #define stop_reader() ( PORTC &= ~(1 << PORTC_PC) ) 95 #define is_reading() ( PINC & (1 << PORTC_PC) ) 95 96 96 97 // sic! mit ja/nein und so 97 98 #define start_led() ( PORTB &= ~(1 << PORTB_LED) ) 98 99 #define stop_led() ( PORTB |= (1 << PORTB_LED) ) 100 #define is_led() ( PINB & (1 << PORTB_LED) ) 101 #define toggle_led() ( is_led() ? stop_led() : start_led() ) 99 102 100 103 #endif /* __M200_WIRING_H__ */
Note: See TracChangeset
for help on using the changeset viewer.