Changeset 56 in projects


Ignore:
Timestamp:
Jan 1, 2010, 1:14:40 PM (14 years ago)
Author:
sven-win
Message:

AVR M200 Card Reader Controller Driver:

  • Improvements on Procotol implementation
  • Introduced cheap solution for uart concurrence - a simple one level fixed length buffer that is flushed after each main loop output.

-- sven @ netbook

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  
    3838
    3939## 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"
     40INCLUDES = -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"
    4141
    4242## Objects that must be built in order to link
  • punch-card/driver/documation-m200/src/driver.c

    r51 r56  
    2525                case (1 << PINB_MOCK): name = "MOCK"; break;
    2626                case 0:
    27                         printf("Too lazy, but not "); // und jetzt nicht breaken :-)
     27                        dprintf("Too lazy, but not "); // und jetzt nicht breaken :-)
    2828                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);
    3030                        status.prev_pinb = pinb_jetzt;
    3131                        return;
    3232        }
    3333
    34         printf("%s %s\n", name, rising_edge ? "raising" : "falling");
     34        dprintf("%s %s\n", name, rising_edge ? "raising" : "falling");
    3535
    3636        status.prev_pinb = pinb_jetzt;
     
    3939
    4040ISR(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
    4342        //  * PINC_RDY : Ready (reader ready for new Pick Command)
    4443        //  * 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
    4545        // to find out what changed, we make a backup of the former
    4646        // PINC at the end of this routine.
     
    5959                                if( check_pin(PINC, PINC_PC) ) {
    6060                                        // 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");
    6263                                } else {
    6364                                        // check if there's space in the buffer to start up
     
    6970                                                        // start. BSY signal will create new card.
    7071                                                        start_reader();
     72                                                        info_puts(M200_SERVER_SIGNAL_PREFIX M200_SERVER_SIGNAL_READY M200_SERVER_SIGNAL_RISE
     73                                                                " firing up\n");
    7174                                                }
    7275                                        }
    7376                                }
    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");
    7579                        } else {
    7680                                // 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");
    7883                        }
    7984                        break;
     
    8590                                        if(card_buffer_write_advance() != SUCCESS) {
    8691                                                // 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");
    93101                                }
    94102                        } else {
    95                                 puts("BSY falling");
    96 
     103                                // BUSY falling.
    97104                                // nochmal sicherheitshalber, wobei das sowieso viel zu spaet ist
    98105                                if( !card_buffer_count_free() ) {
    99106                                        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");
    100112                                }
    101113                        }
     
    104116                case 0:
    105117                        // 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);
    107119                        break;
    108120                default:
    109121                        // 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",
    111123                                status.prev_pinc, pinc_jetzt, pin_changed, rising_edge);
    112124                        break;
     
    125137        if( ! (PINC & (1 << PINC_BSY)) ) {
    126138                // die kann man verwerfen, keine Kartenkante
    127                 puts("IMS");
     139                dprintf("IMS");
    128140                return;
    129141        }
    130142
     143        // check for index bounds
    131144        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");
    135147                }
    136148                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);
    137151                return;
    138152        }
     
    167181                // finalize the current card
    168182                //current_write_card.offset = CARD_READY; // unnoetig, da CARD_READY == CARD_LEN
    169                 puts("wr++");
     183                dprintf("wr++");
    170184
    171185                // try to create a new card
     
    173187                        // no more space! turn off Punch Instruction!
    174188                        stop_reader();
    175                         puts("No more space on buffer.");
     189                        dprintf("No more space on buffer. Waiting for space");
    176190                        status.reader_waits_for_space = 1;
    177191                }
     
    181195
    182196        // und Blinken darf er auch gerne :-)
    183         if (PINB & 0b00000001)
    184                 start_led();
    185         else
    186                 stop_led();
     197        toggle_led();
    187198}
    188199
    189200
    190201// Wird von Hauptschleife aufgerufen
    191 void process_buffer_queue(enum format_t out_format) {
     202void process_card_buffer() {
    192203                // after handling user input, handle buffer
    193204                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,
    195206                                current_read_card.offset, current_write_card.offset);
    196207
     
    200211                        //break; // Karte NICHT komplett ausgeben. Hier stoppen.
    201212
    202                         print_card(out_format);
     213                        print_card();
    203214
    204215
     
    212223                        // Karte zu kommen
    213224                        if( card_buffer_read_advance() != SUCCESS) {
    214                                 puts("output waiting for next");
     225                                dprintf("output waiting for next");
    215226                        } else {
    216                                 puts("cr+");
     227                                dprintf("cr+");
    217228                        }
    218229
     
    228239                                        start_reader();
    229240                                } else {
    230                                         puts("Deadline, writer waits for reader");
     241                                        fatal_printf("Deadline, writer waits for reader");
    231242                                }
    232243                        }
  • punch-card/driver/documation-m200/src/driver.h

    r51 r56  
    3737#include "protocol.h"
    3838
    39 void process_buffer_queue(enum format_t out_format);
     39void process_card_buffer();
     40
     41#define CONCURRENT_PRINTING_BUFFER_LEN 80
    4042
    4143// some kind of global storage for some quick & dirty solutions
     
    4648        } user_instruction;
    4749
     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;
    4858
    4959        // for ISR
  • punch-card/driver/documation-m200/src/main.c

    r51 r56  
    5252
    5353
    54 static FILE uart = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE);
     54static FILE main_thread = FDEV_SETUP_STREAM(uart_transmit_main, NULL, _FDEV_SETUP_WRITE);
     55static FILE interrupt_thread = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE);
    5556
    5657/**
     
    119120
    120121        // 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
    122131
    123132        user_input_loop();
  • punch-card/driver/documation-m200/src/protocol.c

    r51 r56  
    77#include <stdio.h>
    88#include <avr/pgmspace.h> // for all the strings
     9#include <assert.h>
     10#include <string.h>
     11
    912
    1013#include "protocol.h"
     
    3538        M200_SERVER_HELP "    5    Set output to binary output (you don't want to do that in a terminal)\n"
    3639        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
    3842
    3943
    4044void 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",
    4246                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.");
    4448}
    4549
    4650// Haupt-Transmit-Routine, backend von stdio
    47 int uart_transmit(char c, FILE* stream) {
     51int uart_transmit_main(char c, FILE* stream) {
    4852        if(c == '\n')
    49                 uart_transmit('\r', stream);
     53                uart_transmit_main('\r', stream);
    5054
    5155        while (!(UCSR0A & 0b00100000));
     
    5357        UDR0 = c;
    5458        return 0;
     59}
     60
     61// concurrent transmission routine, backend von stderr
     62int 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
     90void 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;
    5599}
    56100
     
    74118}
    75119
    76 void print_card(enum format_t out_format) {
    77         switch(out_format) {
     120void print_card() {
     121        switch(status.out_format) {
    78122                case HEX:
    79123                        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,
    81125                                        (uint8_t) (current_read_card.columns[col] >> 8),
    82126                                        (uint8_t) (current_read_card.columns[col])
     
    86130                case DEBUG:
    87131                        for(uint8_t col = 0; col < CARD_LEN; col++) {
     132                                set_main_loop_printing(TRUE);
    88133                                printf(M200_SERVER_DEBUG_PREFIX "%02d ", col);
    89134                                column_print( &current_read_card.columns[col] );
    90                                 puts(""); // newline?
     135                                // newline done by column print
     136                                set_main_loop_printing(FALSE);
    91137                        }
    92138                        break;
    93139                case BINARY:
     140                        set_main_loop_printing(TRUE);
    94141                        puts(M200_SERVER_BINARY " BINARY");
    95142                        {
     
    107154                        }
    108155                        puts(M200_SERVER_BINARY_PREFIX "08 FINISHED");
     156                        set_main_loop_printing(FALSE);
    109157                        break;
    110158                default:
    111                         puts("550 Illegal Format at runtime");
     159                        main_loop_printf("550 Illegal Format %d\n", status.out_format);
    112160        } // switch out_format
    113161}
    114162
    115163void user_input_loop() {
    116         enum format_t out_format = DEBUG;
    117164        unsigned char input = NO_INPUT;
    118165
     
    126173                                case M200_CLIENT_HELP:
    127174                                        // print out very long help message
    128                                         puts_P(help_message);
    129                                         break;
     175                                        main_loop_puts_P(help_message);
     176                                        break;
     177
    130178                                case M200_CLIENT_PING:
    131179                                        // 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
    134183                                case M200_CLIENT_START:
    135184                                        status.user_instruction = START_READER;
     185                                        main_loop_puts(M200_SERVER_ACK_START " Strobing start signal...");
    136186                                        start_reader();
    137187                                        start_led();
    138188                                        break;
     189
    139190                                case M200_CLIENT_STOP:
    140191                                        status.user_instruction = STOP_READER;
    141192                                        stop_reader();
    142193                                        stop_led();
    143                                         break;
     194                                        main_loop_puts(M200_SERVER_ACK_STOP " Stopped read instruction");
     195                                        break;
     196
    144197                                case M200_CLIENT_HEX:
    145198                                case M200_CLIENT_DEBUG:
    146199                                case M200_CLIENT_BINARY:
    147200                                        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);
    149202                                                break;
    150203                                        }
    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;
    153207
    154208                                case M200_CLIENT_RESET:
     
    157211                                        stop_led();
    158212                                        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");
    160214                                        print_startup_message();
    161215                                        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
    162222                                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);
    164224                        } // switch
    165225                } // if user input
    166226
    167227                // KARTE ABHANDELN
    168                 process_buffer_queue(out_format);
     228                process_card_buffer();
    169229        } // while 1
    170230} // function
  • punch-card/driver/documation-m200/src/protocol.h

    r51 r56  
    3030#include "pc-uc-protocol.h"
    3131#include "punchcard.h"
     32// #include "driver.h"
    3233
    3334#include <stdio.h>
     
    4243#define is_valid_format(f) ( f == HEX || f == DEBUG || f == BINARY )
    4344
    44 // A char value as return value from uart_transmit
     45int uart_transmit(char c, FILE* stream);
     46int uart_transmit_main(char c, FILE* stream);
     47
     48// A char value as return value from uart_recieve
    4549#define NO_INPUT      0
    46 
    47 int uart_transmit(char c, FILE* stream);
    48 
    4950unsigned char uart_recieve();
    5051
    5152void print_bits(byte_t byte);
    5253
    53 void print_card(enum format_t out_format);
     54void print_card();
     55
     56void 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); }
    5469
    5570void user_input_loop();
  • punch-card/driver/documation-m200/src/punchcard.c

    r50 r56  
    55
    66#include "punchcard.h"
     7#include "protocol.h"
     8#include "driver.h"
    79#include <string.h>
    810#include <stdio.h>
     
    4850                // Puffer ist leer!
    4951                // (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,
    5153                                current_read_card.offset, current_write_card.offset);
    5254                return BUFFER_EMPTY;
     
    7274        if( new_offset == card_buffer.read_offset ) {
    7375                // 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,
    7577                                current_read_card.offset, current_write_card.offset);
    7678                return BUFFER_FULL;
  • punch-card/driver/documation-m200/src/wiring.h

    r51 r56  
    9393#define start_reader()  ( PORTC |= (1 << PORTC_PC) )
    9494#define stop_reader()   ( PORTC &= ~(1 << PORTC_PC) )
     95#define is_reading()    ( PINC & (1 << PORTC_PC) )
    9596
    9697// sic! mit ja/nein und so
    9798#define start_led()             ( PORTB &= ~(1 << PORTB_LED) )
    9899#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() )
    99102
    100103#endif /* __M200_WIRING_H__ */
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License