Changeset 62 in projects


Ignore:
Timestamp:
Jan 6, 2011, 7:02:14 AM (13 years ago)
Author:
sven
Message:

Bull-Anelex-Project, Anelex Interface:

  • Completely new RS232 I/O with ordinary Ring buffer (against FIFO in PC which still sends when CTS is low)
  • Integrated out-of-memory data printing, on button too (strange bug: uC resets when calling ?print X)
  • removed the toolchain.h (almost completely)
  • several improvements

-- sven @ workstation7

Location:
bull-anelex-project/trunk/anelex-interface/src
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • bull-anelex-project/trunk/anelex-interface/src/anelex.c

    r60 r62  
     1/**
     2 * ANELEX PRINTER Interface Microcontroller
     3 *
     4 * anelex.c: All communication related routines to the anelex device.
     5 *
     6 * This file is part of the Bull Anelex Project
     7 * Copyright (C) 2010, 2011 Sven Köppel, technikum29.de
     8 *
     9 * This program is free software; you can redistribute
     10 * it and/or modify it under the terms of the GNU General
     11 * Public License as published by the Free Software
     12 * Foundation; either version 3 of the License, or (at
     13 * your option) any later version.
     14 *
     15 * This program is distributed in the hope that it will
     16 * be useful, but WITHOUT ANY WARRANTY; without even the
     17 * implied warranty of MERCHANTABILITY or FITNESS FOR A
     18 * PARTICULAR PURPOSE. See the GNU General Public License
     19 * for more details.
     20 *
     21 * You should have received a copy of the GNU General
     22 * Public License along with this program; if not, see
     23 * <http://www.gnu.org/licenses/>.
     24 *
     25 **/
     26
    127#include "toolchain.h"
    228#include "anelex_code.h"
     
    632        // startup line printing
    733        //puts("Starting line transmission");
    8         line_counter = 0;
     34        current_line_cnt = 0;
    935        print_line_feed();
    1036        line_state = LINE_TRANSMITTING;
     
    2551        // Communication Announcement steigende Flanke.
    2652        // je nach zustand
    27 
    2853        if(line_state != LINE_TRANSMITTING)
    2954                return;
    3055
    31         uint8_t current_counter = line_counter; // volatile lokal holen, spaeter unnoetig
     56        uint8_t current_counter = current_line_cnt; // volatile lokal holen, spaeter unnoetig
    3257
    3358        if(current_counter < LINE_LENGTH) {
     
    3762                        // normales zeichen
    3863                        char transformed = anelex_code[ orig ];
    39                         //printf("%d: Zeichen %c, entspricht oktal %o\n", current_counter, orig, transformed);
     64                        printf("%d: Zeichen %c, entspricht oktal %o\n", current_counter, orig, transformed);
    4065                        //printf("%d", current_counter, orig);
    4166                        //_delay_us(100);
     
    4974                        // jetzt bis zum naechsten Zeichen warten
    5075
    51                         line_counter++;
     76                        current_line_cnt++;
    5277                        return;
    5378                }
  • bull-anelex-project/trunk/anelex-interface/src/anelex.h

    r60 r62  
    11#ifndef ANELEX_H
    22#define ANELEX_H
     3
     4/**
     5 * ANELEX PRINTER Interface Microcontroller
     6 * Anelex communication
     7 *
     8 * All I/O with the Anelex device.
     9 *
     10 * Copyright (C) 2010, 2011 Sven Köppel, technikum29.de
     11 *
     12 * This program is free software; you can redistribute
     13 * it and/or modify it under the terms of the GNU General
     14 * Public License as published by the Free Software
     15 * Foundation; either version 3 of the License, or (at
     16 * your option) any later version.
     17 *
     18 * This program is distributed in the hope that it will
     19 * be useful, but WITHOUT ANY WARRANTY; without even the
     20 * implied warranty of MERCHANTABILITY or FITNESS FOR A
     21 * PARTICULAR PURPOSE. See the GNU General Public License
     22 * for more details.
     23 *
     24 * You should have received a copy of the GNU General
     25 * Public License along with this program; if not, see
     26 * <http://www.gnu.org/licenses/>.
     27 *
     28 **/
     29 
     30#include <avr/interrupt.h>
     31#include <util/delay.h>
     32#include <string.h>
     33#include <stdio.h>
     34
     35#include "wiring.h"
     36
     37#define LINE_LENGTH 120
     38char current_line[LINE_LENGTH];
     39volatile uint8_t current_line_cnt;
    340
    441void print_line();
     
    744// + zwei ISRs
    845
    9 volatile uint8_t line_counter;
     46/**
     47 * State of printer driver (anelex.c):
     48 **/
     49volatile enum line_state_t {
     50        LINE_FINISHED,      // Printer has finished printing and is ready for
     51                            // transmit new data from pbuf to printer.
    1052
    11 volatile enum line_state_t {
    12         LINE_FINISHED,
    13         LINE_TRANSMITTING,
    14         LINE_PRINTING
     53        LINE_TRANSMITTING,  // Current line is transmitted from pbuf to printer.
     54                            // so by now the anelex ISRs are working at high speed.
     55                                                // All other work should be avoided (like RS232 rx).
     56
     57        LINE_PRINTING       // Printer is working (no transmission possible),
     58                            // best time to recieve new data via RS232.
     59                                                // This time is about 32ms
    1560} line_state;
    1661
  • bull-anelex-project/trunk/anelex-interface/src/anelex_code.h

    r60 r62  
    11#ifndef ANELEX_CODE_H
    22#define ANELEX_CODE_H
     3
     4/**
     5 * ANELEX PRINTER Interface Microcontroller
     6 * Anelex code character set
     7 *
     8 * This file stores the anelex character set as a mapping
     9 * array:
     10 *    anelex_code(ASCII) -> ANELEX_CHAR
     11 *
     12 * This file is part of the Bull Anelex Project
     13 * Copyright (C) 2010, 2011 Sven Köppel, technikum29.de
     14 *
     15 * This program is free software; you can redistribute
     16 * it and/or modify it under the terms of the GNU General
     17 * Public License as published by the Free Software
     18 * Foundation; either version 3 of the License, or (at
     19 * your option) any later version.
     20 *
     21 * This program is distributed in the hope that it will
     22 * be useful, but WITHOUT ANY WARRANTY; without even the
     23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
     24 * PARTICULAR PURPOSE. See the GNU General Public License
     25 * for more details.
     26 *
     27 * You should have received a copy of the GNU General
     28 * Public License along with this program; if not, see
     29 * <http://www.gnu.org/licenses/>.
     30 *
     31 **/
    332
    433// magic value that indicated non-valid entry
  • bull-anelex-project/trunk/anelex-interface/src/data.c

    r60 r62  
    1 /* Store strings in Program memory. 64KByte of text! :) */
    2 
    3 #include <avr/pgmspace.h>
     1/**
     2 * ANELEX PRINTER Interface Microcontroller
     3 * Test strings
     4 *
     5 * These are 64KByte of text strings, stored in
     6 * program memory.
     7 *
     8 * This file is part of the Bull Anelex Project
     9 * Copyright (C) 2010, 2011 Sven Köppel, technikum29.de
     10 *
     11 * This program is free software; you can redistribute
     12 * it and/or modify it under the terms of the GNU General
     13 * Public License as published by the Free Software
     14 * Foundation; either version 3 of the License, or (at
     15 * your option) any later version.
     16 *
     17 * This program is distributed in the hope that it will
     18 * be useful, but WITHOUT ANY WARRANTY; without even the
     19 * implied warranty of MERCHANTABILITY or FITNESS FOR A
     20 * PARTICULAR PURPOSE. See the GNU General Public License
     21 * for more details.
     22 *
     23 * You should have received a copy of the GNU General
     24 * Public License along with this program; if not, see
     25 * <http://www.gnu.org/licenses/>.
     26 *
     27 **/
     28
     29#include "data.h"
     30
     31//#include <avr/pgmspace.h>
     32#include "data.h"
    433
    534char string_helloworld[] PROGMEM = "HELLO WORLD";
     
    4473"====\n"
    4574"\n"
    46 " This is the ANELEX printer interface microcontroller. Any text which is recieved\n"
    47 " via RS232 will be directly printed out. There is some verbose output (which you\n"
    48 " can ignore), especially for every bad character (which is not in the charset of\n"
    49 " the printer).\n"
     75" This is the ANELEX printer interface microcontroller. Any text which is\n"
     76" recieved via RS232 will be directly printed out. There is some verbose output\n"
     77" (which you can ignore), especially for every bad character (which is not in\n"
     78" the charset of the printer).\n"
    5079"\n"
    5180" Alternatively, you can push the button on the microcontroller board, which will\n"
     
    5382" interpreted as commands. These commands are available:\n"
    5483"\n"
    55 "    help    Prints out this help message\n"
    56 "    ping    Just prints something back\n"
    57 "    test N  Starts the test procedure number N, while N is a number (like ?test 42)\n"
    58 "    list    List all available tests\n"
    59 "    list N  Just output the test string number N on the RS232 terminal\n"
     84"    help     Prints out this help message\n"
     85"    ping     Just prints something back\n"
     86"    print N  Starts the test procedure number N, while N is a number\n"
     87"    list     List all available tests\n"
     88"    list N   Just output the test string number N on the RS232 terminal\n"
     89"\n";
     90
     91// yes, this is the list of strings message
     92char string_list_of_strings[] PROGMEM =
     93"ID NAME             CONTENT\n"
     94"== ==============   =======================================================\n"
     95" 1 helloworld       A simple HELLO WORLD oneliner\n"
     96" 2 simple           A-Z, 0-9 tests, 4 lines\n"
     97" 3 charset          The full character set from the ANELEX printer, 7 lines\n"
     98" 4 pangrams         Pangrams (sentences with each letter), 7 lines\n"
     99" 5 numbers          8 lines of numbers\n"
     100" 6 shortandlong     very short and long lines of numbers\n"
     101" 7 bullhomepagetext An text excerpt from technikum29.de, 19 lines\n"
     102" 8 werther          Die Leiden des jungen Werther, excerpt, 26 lines\n"
     103" 9 pi               120x100 columns, first digits of pi = 2.31...\n"
    60104"\n";
    61105
     
    23127504925485346941469775164932709504934639382432227188515974054702148289711177792376122578873477188196825462981268685817050\n";
    232276
    233 char string_e_81x200[] PROGMEM = "\
    234   2.7182818284590452353602874713526624977572470936999595749669676277240766303535\n\
    235 47594571382178525166427427466391932003059921817413596629043572900334295260595630\n\
    236 73813232862794349076323382988075319525101901157383418793070215408914993488416750\n\
    237 92447614606680822648001684774118537423454424371075390777449920695517027618386062\n\
    238 61331384583000752044933826560297606737113200709328709127443747047230696977209310\n\
    239 14169283681902551510865746377211125238978442505695369677078544996996794686445490\n\
    240 59879316368892300987931277361782154249992295763514822082698951936680331825288693\n\
    241 98496465105820939239829488793320362509443117301238197068416140397019837679320683\n\
    242 28237646480429531180232878250981945581530175671736133206981125099618188159304169\n\
    243 03515988885193458072738667385894228792284998920868058257492796104841984443634632\n\
    244 44968487560233624827041978623209002160990235304369941849146314093431738143640546\n\
    245 25315209618369088870701676839642437814059271456354906130310720851038375051011574\n\
    246 77041718986106873969655212671546889570350354021234078498193343210681701210056278\n\
    247 80235193033224745015853904730419957777093503660416997329725088687696640355570716\n\
    248 22684471625607988265178713419512466520103059212366771943252786753985589448969709\n\
    249 64097545918569563802363701621120477427228364896134225164450781824423529486363721\n\
    250 41740238893441247963574370263755294448337998016125492278509257782562092622648326\n\
    251 27793338656648162772516401910590049164499828931505660472580277863186415519565324\n\
    252 42586982946959308019152987211725563475463964479101459040905862984967912874068705\n\
    253 04895858671747985466775757320568128845920541334053922000113786300945560688166740\n\
    254 01698420558040336379537645203040243225661352783695117788386387443966253224985065\n\
    255 49958862342818997077332761717839280349465014345588970719425863987727547109629537\n\
    256 41521115136835062752602326484728703920764310059584116612054529703023647254929666\n\
    257 93811513732275364509888903136020572481765851180630364428123149655070475102544650\n\
    258 11727211555194866850800368532281831521960037356252794495158284188294787610852639\n\
    259 81395599006737648292244375287184624578036192981971399147564488262603903381441823\n\
    260 26251509748279877799643730899703888677822713836057729788241256119071766394650706\n\
    261 33045279546618550966661856647097113444740160704626215680717481877844371436988218\n\
    262 55967095910259686200235371858874856965220005031173439207321139080329363447972735\n\
    263 59552773490717837934216370120500545132638354400018632399149070547977805669785335\n\
    264 80489669062951194324730995876552368128590413832411607226029983305353708761389396\n\
    265 39177957454016137223618789365260538155841587186925538606164779834025435128439612\n\
    266 94603529133259427949043372990857315802909586313826832914771163963370924003168945\n\
    267 86360606458459251269946557248391865642097526850823075442545993769170419777800853\n\
    268 62730941710163434907696423722294352366125572508814779223151974778060569672538017\n\
    269 18077636034624592787784658506560507808442115296975218908740196609066518035165017\n\
    270 92504619501366585436632712549639908549144200014574760819302212066024330096412704\n\
    271 89439039717719518069908699860663658323227870937650226014929101151717763594460202\n\
    272 32493002804018677239102880978666056511832600436885088171572386698422422010249505\n\
    273 51881694803221002515426494639812873677658927688163598312477886520141174110913601\n\
    274 16499507662907794364600585194199856016264790761532103872755712699251827568798930\n\
    275 27617611461625493564959037980458381823233686120162437365698467037858533052758333\n\
    276 37939907521660692380533698879565137285593883499894707416181550125397064648171946\n\
    277 70834819721448889879067650379590366967249499254527903372963616265897603949857674\n\
    278 13973594410237443297093554779826296145914429364514286171585873397467918975712119\n\
    279 56187385783644758448423555581050025611492391518893099463428413936080383091662818\n\
    280 81150371528496705974162562823609216807515017772538740256425347087908913729172282\n\
    281 86115159156837252416307722544063378759310598267609442032619242853170187817729602\n\
    282 35413060672136046000389661093647095141417185777014180606443636815464440053316087\n\
    283 78314317444081194942297559931401188868331483280270655383300469329011574414756313\n\
    284 99972217038046170928945790962716622607407187499753592127560844147378233032703301\n\
    285 68237193648002173285734935947564334129943024850235732214597843282641421684878721\n\
    286 67336701061509424345698440187331281010794512722373788612605816566805371439612788\n\
    287 87325273738903928905068653241380627960259303877276977837928684093253658807339884\n\
    288 57218746021005311483351323850047827169376218004904795597959290591655470505777514\n\
    289 30817511269898518840871856402603530558373783242292418562564425502267215598027401\n\
    290 26179719280471396006891638286652770097527670697770364392602243728418408832518487\n\
    291 70472638440379530166905465937461619323840363893131364327137688841026811219891275\n\
    292 22305625675625470172508634976536728860596675274086862740791285657699631378975303\n\
    293 46606166698042182677245605306607738996242183408598820718646826232150802882863597\n\
    294 46839654358856685503773131296587975810501214916207656769950659715344763470320853\n\
    295 21560367482860837865680307306265763346977429563464371670939719306087696349532884\n\
    296 68336130388294310408002968738691170666661468000151211434422560238744743252507693\n\
    297 87077775193299942137277211258843608715834835626961661980572526612206797540621062\n\
    298 08064988291845439530152998209250300549825704339055357016865312052649561485724925\n\
    299 73862069174036952135337325316663454665885972866594511364413703313936721185695539\n\
    300 52108458407244323835586063106806964924851232632699514603596037297253198368423363\n\
    301 90463213671011619282171115028280160448805880238203198149309636959673583274202498\n\
    302 82456849412738605664913525267060462344505492275811517093149218795927180019409688\n\
    303 66986837037302200475314338181092708030017205935530520700706072233999463990571311\n\
    304 58709963577735902719628506114651483752620956534671329002599439766311454590268589\n\
    305 89791158370934193704411551219201171648805669459381311838437656206278463104903462\n\
    306 93950029458341164824114969758326011800731699437393506966295712410273239138741754\n\
    307 92307186245454322203955273529524024590380574450289224688628533654221381572213116\n\
    308 32881120521464898051800920247193917105553901139433166815158288436876069611025051\n\
    309 71007392762385553386272553538830960671644662370922646809671254061869502143176211\n\
    310 66814009759528149390722260111268115310838731761732323526360583817315103459573653\n\
    311 82235349929358228368510078108846343499835184044517042701893819942434100905753762\n\
    312 57767571118090088164183319201962623416288166521374717325477727783488774366518828\n\
    313 75215668571950637193656539038944936642176400312152787022236646363575550356557694\n\
    314 88865495002708539236171055021311474137441061344455441921013361729962856948991933\n\
    315 69184729478580729156088510396781959429833186480756083679551496636448965592948187\n\
    316 85178403877332624705194505041984774201418394773120281588684570729054405751060128\n\
    317 52580565947030468363445926525521370080687520095934536073162261187281739280746230\n\
    318 94685367823106097921599360019946237993434210687813497346959246469752506246958616\n\
    319 90917857397659519939299399556754271465491045686070209901260681870498417807917392\n\
    320 40719459963230602547079017745275131868099822847308607665368668555164677029113368\n\
    321 27563107223346726113705490795365834538637196235856312618387156774118738527722922\n\
    322 59474337378569553845624680101390572787101651296663676445187246565373040244368414\n\
    323 08144887329578473484900030194778880204603246608428753518483649591950828883232065\n\
    324 22128104190448047247949291342284951970022601310430062410717971502793433263407995\n\
    325 96053144605323048852897291765987601666781193793237245385720960758227717848336161\n\
    326 35826128962261181294559274627671377944875867536575448614076119311259585126557597\n\
    327 34573015333642630767985443385761715333462325270572005303988289499034259566232975\n\
    328 78248873502925916682589445689465599265845476269452878051650172067478541788798227\n\
    329 68065366506419109734345288783386217261562695826544782056729877564263253215942944\n\
    330 18039943217000090542650763095588465895171709147607437136893319469090981904501290\n\
    331 30709956622662030318264936573369841955577696378762491885286568660760056602560544\n\
    332 57113372868402055744160308370523122425872234388541231794813885500756893811249353\n\
    333 86318635287083799845692619981794523364087429591180747453419551420351726184200845\n\
    334 50917084568236820089773945584267921427347756087964427920270831215015640634134161\n\
    335 71664480698154837644915739001212170415478725919989438253649505147713793991472052\n\
    336 19529079396137621107238494290616357604596231253506068537651423115349665683715116\n\
    337 60422079639446662116325515772907097847315627827759878813649195125748332879377157\n\
    338 14590910648416426783099497236744201758622694021594079244805412553604313179926967\n\
    339 39157542419296607312393763542139230617876753958711436104089409966089471418340698\n\
    340 36299367536262154524729846421375289107988438130609555262272083751862983706678722\n\
    341 44301957937937860721072542772890717328548743743557819665117166183308811291202452\n\
    342 04048682200072344035025448202834254187884653602591506445271657700044521097735585\n\
    343 89762265548494162171498953238342160011406295071849042778925855274303522139683567\n\
    344 90180764060421383073087744601708426882722611771808426643336517800021719034492342\n\
    345 64266292261456004337383868335555343453004264818473989215627086095650629340405264\n\
    346 94324426144566592129122564889356965500915430642613425266847259491431423939884543\n\
    347 24863274618428466559853323122104662598901417121034460842716166190012571958707932\n\
    348 17569698544013397622096749454185407118446433946990162698351607848924514058940946\n\
    349 39526780735457970030705116368251948770118976400282764841416058720618418529718915\n\
    350 40196882532893091496653457535714273184820163846448324990378860690080727093276731\n\
    351 27581966563941148961716832980455139729506687604740915420428429993541025829113502\n\
    352 24169076943166857424252250902693903481485645130306992519959043638402842926741257\n\
    353 34224477655841778861717372654620854982944989467873509295816526320722589923687684\n\
    354 57017823038096567883112289305809140572610865884845873101658151167533327674887014\n\
    355 82916741970151255978257270740643180860142814902414678047232759768426963393577354\n\
    356 29301867394397163886117642090040686633988568416810038723892144831760701166845038\n\
    357 87212364367043314091155733280182977988736590916659612402021778558854876176161989\n\
    358 37079438005666336488436508914480557103976521469602766258359905198704230017946553\n\
    359 67885674302859746001437854832370687011900784994049309189191816493272597740300748\n\
    360 79681484882342932023012128032327460392219687528340516906974194257614673978110715\n\
    361 46418627336909158497318501118396048253351874843892317729261354302493256289637136\n\
    362 19772854566229244616444972845978677115741256703078718851093363444801496752406185\n\
    363 36569532074170533486782754827815415561966911055101472799040386897220465550833170\n\
    364 78239480878599050194756310898412414467282186545997159663901564194175182093593261\n\
    365 63168883801327587526014605076760983926257264111201352885913178482994756824725648\n\
    366 85533357279772205543568126302535748216585414000805314820697137262149755576051890\n\
    367 48162237679041492674260007104592269531483518813746388710427354476762357793399397\n\
    368 06323966049691453032738878745579059349377723201429548033450006952569809352828877\n\
    369 83710670585567749481373858630385762823040694005665340584887527005308832459182183\n\
    370 49431804983419963998145877343586311594057044368351528538360944295596436067609022\n\
    371 17418968835481316439974377641583652422346426195973904554506806952328507518687194\n\
    372 49064767791886720306418630751053512149851051207313846648717547518382979990189317\n\
    373 75155063998101646641459210240683829460320853555405814715927322067756766921366408\n\
    374 15059008069525406106285364082932766219319399338616238360691117677854482361293268\n\
    375 58199965239275488427435414402884536455595124735546139403154952097397051896240157\n\
    376 97683263945063323045219264504965173546677569929571898969047090273028854494541669\n\
    377 97919929480382549802859460290527631455803165140662291712234293758061439934849143\n\
    378 62107993576737317948964252488813720435579287511385856973381976083524423240466778\n\
    379 02094839963994668483377470672548361884827300064831916382602211055522124673332318\n\
    380 44630055044818499169966220877461402161570210296033185887273332987793525701823938\n\
    381 61244026868339555870607758169954398469568540671174444932479519572159419645863736\n\
    382 12691552645757478698596424217659289686238350637043393981167139754473622862550680\n\
    383 36826641355414480489977213731741191999700172939073033508690209225191244473932783\n\
    384 76156321810842898207706974138707053266117683698647741787180202729412982310888796\n\
    385 83188085436732780687977165911165422445380662586171172949803824887998650406156397\n\
    386 56299369628093581897614910171453435566595427570641944088338168411111662007597872\n\
    387 44137082333917886114708228657531078536674695018462140736493917366254937783014074\n\
    388 30266842215033511773647185387232404042103790775026602011481493548222891666364078\n\
    389 24501668153412135052785785393326061102498022730936367402135153864316930152674605\n\
    390 36064351732154701091440650878823636764236831187390937464232609021646365627553976\n\
    391 83401948293279575062439964527257862440037598342205080893512902312247597064410567\n\
    392 83618708771723335554654825989068612014101072224659040085537982352538851716235182\n\
    393 56518482203125214950700378300411216212126052726059944320443056274522916128891766\n\
    394 81416063913123597535039032007752958739241247645185080916391145929607115634420434\n\
    395 71335447209811784614510778723991406062902282766643092649005922498102910687594345\n\
    396 33858330391178747575977065953570979640012224092199031158229259667913153991561438\n\
    397 07012926078019702258966292336815431249941225946002339947222817105660393187722680\n\
    398 04938331489803385489094686851307892920642428191747958661999444111962087304980643\n\
    399 85006852620258432842085582338566936649849720817046135376163584015342840674118587\n\
    400 58154651459827022867667185530931192334019128617061336487318319756081256946008940\n\
    401 29530944291195902959685639230376899763274622839007354571445964141082292859222393\n\
    402 32836210192822937243590283003884445701383771632056518351970100115722010956997890\n\
    403 48496445343461212922496473235612632195115570156582442766159932646315580667205312\n\
    404 75969485380573642083849188870951760522878173394627476446568589009362661233111529\n\
    405 10816041524100214195937349786431661556732702792109593543055579732660554677963552\n\
    406 00537830461954063697184291616858273412221714588587081427409024818544642177487692\n\
    407 50933287856706746773812267528316535592452045780705413525769032535227389638474956\n\
    408 46255940378924925007624386893776475310102323746733771474581625530698032499033676\n\
    409 45543030527456151296121458594443215074905149145395098100138873792637996487372839\n\
    410 64168975551322759620118382486507469854920380976919326064376087432093856028156428\n\
    411 49756549307909733854185583515789409814007691892389063090542534883896831762904120\n\
    412 21294916719581193579120316251434409650313283521672802137241594734409549831613832\n\
    413 25054867081722214751384251667904454166173032008203309028954888085167972584958134\n\
    414 07132180533988828139346049850532340472595097214331492586604248511405819579711564\n\
    415 19145884283300052568477687430591639049430687134311879618963747550336282093994934\n\
    416 36903210319768981120555953694654247041733238953940460353253967583543953505167202\n\
    417 61647961347790912327995264929045151148307923369382166010702872651938143844844532\n\
    418 63951739411013115250275046574934306376654186612891526444692622288436629946273246\n\
    419 79587363835019371427864713980540382155134632237020715331348870831741465914924063\n\
    420 59493020921122052610312390682941345696785958518393491382340884274312419099152870\n\
    421 80433280913299307893686712741392289003306999587592181529761248240911695158778996\n\
    422 40903525773459382482320530555672380950222667904396142318529919891810655544124772\n\
    423 04508510210071522352342792531266930108270633942321762570076323139159349709946933\n\
    424 24101390877916165122680441480976561897973504315139606691325837903374862083669547\n\
    425 50832803187867077511775256639634792592197335779495554986552141933981702686399873\n\
    426 88347010255262052312317215254062571636771270010760912281528326508984359568975961\n\
    427 03837215772683117073455225019412170154131879365181850202087732690613359218200076\n\
    428 23272695032838273912438281981708711681089511878967467070733778695925655427133400\n\
    429 52326706040004348843432902760360498027862160749469654989210474443927871934536701\n\
    430 79867392080384563372331198385586263800851634559719444199434462476112384461761573\n\
    431 62420159350785208256006041015568898995017325543372980735616998611019084720966007\n\
    432 08320280569917042590103876928658336557728758684250492690370934262028022399861803\n\
    433 40021132074219864291738367917623282644464575633033655677737480864410996914182777\n\
    434 42534170109884358531893391759345115740238472929090154685591637926961968410006765\n";
    435 
    436 PGM_P builtin_strings[] PROGMEM = {
     277
     278// this is an array in normal RAM filled with pointers to program space:
     279PGM_P builtin_strings[] = {
     280        // 10 ordinary test strings
    437281        string_helloworld,
    438282        string_simple,
     
    444288        string_werther,
    445289        string_pi_120x100,
    446         string_e_81x200
     290
     291        // 2 meta like strings (which are not listed in the list of strings)
     292        string_help_message,
     293        string_list_of_strings,
    447294};
  • bull-anelex-project/trunk/anelex-interface/src/frontend.c

    r60 r62  
     1/**
     2 * ANELEX PRINTER Interface Microcontroller
     3 * RS232 client interaction
     4 *
     5 * This file collects all routines that directly communicate
     6 * to the computer/PC/user/terminal/other uc/anything that is
     7 * wired via the RS232 port.
     8 *
     9 * This file is part of the Bull Anelex Project
     10 * Copyright (C) 2010, 2011 Sven Köppel, technikum29.de
     11 *
     12 * This program is free software; you can redistribute
     13 * it and/or modify it under the terms of the GNU General
     14 * Public License as published by the Free Software
     15 * Foundation; either version 3 of the License, or (at
     16 * your option) any later version.
     17 *
     18 * This program is distributed in the hope that it will
     19 * be useful, but WITHOUT ANY WARRANTY; without even the
     20 * implied warranty of MERCHANTABILITY or FITNESS FOR A
     21 * PARTICULAR PURPOSE. See the GNU General Public License
     22 * for more details.
     23 *
     24 * You should have received a copy of the GNU General
     25 * Public License along with this program; if not, see
     26 * <http://www.gnu.org/licenses/>.
     27 *
     28 **/
     29
    130#include "frontend.h"
    231#include "anelex.h"
     32#include "data.h"
     33
     34
     35// das hier ist write_advance fuer den print_buffer (pbuf)
     36// nicht ISR, sondern INTERRUPTABLE machen! also selbst unterbrechbar!
     37ISR(USART0_RX_vect) {
     38        char c = UDR0;
     39        // verbose debugging with states:
     40        //printf("read %x, r=%d, w=%d, used=%d, loss=%d, dirt=%d, nl=%d, cts=%s\n",
     41        //      c, pbuf.read_offset, pbuf.write_offset, pbuf.used_elements, pbuf.data_loss, pbuf.dirty_write, pbuf.line_counter, is_cts()?"on":"off");
     42
     43        if(c == '\r') {
     44                switch(input_line_end) {
     45                        case CRNL:
     46                                // Windows default \r\n: Ignore CR, only obey NL
     47                                return;
     48                        case CR:
     49                                // \r only as line end: just convert to ordinary unix style \n
     50                                c = '\n';
     51                        case NL:
     52                                // just NL which is our standard mode.
     53                                break;
     54                } // switch
     55        } // if CR
     56
     57        if(!is_cts()) pbuf.dirty_write++; // just for debugging
     58
     59        int8_t new_offset = (pbuf.write_offset + 1) % BUFFER_LEN;
     60
     61        if(new_offset == pbuf.read_offset) {
     62                // no more space!
     63                pbuf.data_loss++;
     64                // wipe current data! Data Loss!
     65                putchar('@');
     66        } else {
     67                // still space left
     68                pbuf.buffer[new_offset] = c;
     69                pbuf.write_offset = new_offset;
     70                pbuf.used_elements++;
     71                if(c == '\n') {
     72                  pbuf.line_counter++;
     73        }
     74                putchar(c); // vorsicht bei Newlines - hier beabsichtigt (NL->NLCR)
     75        }
     76
     77        // when space is running out then make PC stop sending.
     78        if(pbuf.used_elements > BUFFER_LEN - 10)
     79                stop_cts();
     80
     81        // line_state, number of lines, etc. is checked in readline()!
     82}
     83
     84
    385
    486void readline() {
    5         int position;
    6         memset(&current_line, 0, LINE_LENGTH);
    7         start_cts();
     87        memset(&current_line, 0, LINE_LENGTH); // null the output buffer (important)
     88
     89        if(builtin_data.index) {
     90                // read text from builtin memory (data.c).
     91                PGM_P string = builtin_strings[builtin_data.index - 1];
     92
     93                int nlpos = strchr_P(string[builtin_data.read_offset], '\n');
     94                if(nlpos > LINE_LENGTH) nlpos = LINE_LENGTH;
     95                strncpy_P(current_line, string[builtin_data.read_offset], nlpos - builtin_data.read_offset);
     96
     97                builtin_data.read_offset += nlpos + 1; // one behind the newline
     98                if(builtin_data.read_offset >= strlen_P(string)) {
     99                        puts("Reached end of string!");
     100                        builtin_data.index = 0;
     101                        builtin_data.read_offset = 0;
     102                }
     103                return;
     104        }
     105
     106        start_cts();          // let PC start sending! (important)
     107        pbuf.data_loss = 0;   // reset statistics for
     108        pbuf.dirty_write = 0; // new readline run.
    8109
    9110        // loop for first user input
    10111        for(;;) {
    11                 if(has_character())
    12                         break;
    13                 else if(is_button()) {
    14                         // wait for button press finished
     112                if(line_state == LINE_FINISHED && pbuf.line_counter) {
     113                        // printer finished printing and is ready for new data.
     114                        // and we have detected a full line in the buffer
     115                        //_delay_ms(2000); // zum manuellen testen: schnell viele zeilen eingeben
     116                        stop_cts();
     117                        break;
     118                } else if(is_button()) {
     119                        // button pressed down - wait until raised again
     120                        stop_cts();
    15121                        while(is_button());
     122                        puts("Button pressed.");
    16123                        strcpy(current_line, "?print 1");
    17                         puts("Button pressed.");
    18                         stop_cts();
    19                         return;
    20                 } else if(line_state == LINE_FINISHED) {
    21                         // LINE_PRINTING-Phase ist vorbei, Zeile ist jetzt fertig.
    22                         // Aber wir warten immer noch auf User Interaction...
    23                         // puts("Printer is ready for new cycle, but you haven't even started typing.");
    24                 }
    25         }
    26 
    27         // read in the line
    28         for(position=0; position < LINE_LENGTH; position++) {
    29                 char* c = &current_line[position]; // shortcut
     124                        return; // important: Quit readline now.
     125                } else if(!is_cts()) {
     126                        // apperantly the buffer is full and the ISR made a full stop.
     127                        // Hence we must use current contents as a line (remark that the
     128                        // line is not finished!). Since the buffer should be large, the
     129                        // line is longer than the printer can print, anyway.
     130                        puts("ctsoff");
     131                        break;
     132                }
     133        }
     134
     135        // now copy one line from the buffer to the current_line
     136        // output buffer for the anelex driver (which is already filled with 0x00)
     137        for(int i=0; i < LINE_LENGTH; i++) {
     138                // read advance:
     139                pbuf.read_offset = (pbuf.read_offset + 1) % BUFFER_LEN;
     140
     141                char c = pbuf.buffer[pbuf.read_offset];
     142                pbuf.buffer[pbuf.read_offset] = '\0';
     143                pbuf.used_elements--;
     144                if(c == '\n') {
     145                        // end of line detected
     146                        pbuf.line_counter--;
     147                        break;
     148                } else
     149                        // store char to anelex driver buffer
     150                        current_line[i] = c;
    30151               
    31                 // wait for a character at UART
    32                 while( !has_character() );
    33 
    34                 // got a character
    35                 *c = UDR0;
    36                
    37                 // check the recieved character for line ending
    38                 if(*c == '\n' || *c == '\r')
    39                         break;
    40         }
    41        
    42         stop_cts();
    43         current_line[position+1] = '\0';
    44 
    45         // terminal echo:
    46         puts(current_line);   //        printf("%d: %s\n", strlen(buffer), buffer);
    47 
    48         // done.
    49         return;
    50 }
    51 
    52 bool_t exec_command() {
    53         char* command = current_line + 1;
     152                if(!pbuf.used_elements)
     153                        // buffer is absolutely empty
     154                        break;
     155        } // for
     156
     157        // checkout some statistics
     158        if(pbuf.data_loss) {
     159                printf("Lost %d chars!\n", pbuf.data_loss);
     160        }
     161
     162} // readline()
     163
     164
     165void exec_command() {
     166        char* command = current_line + 1; // strip leading '?'
    54167        printf("Executing command %s\n", command);
    55168
    56         if(strcasecmp(command, "help") >= 0) {
     169        if(strcasecmp(command, "help") == 0) {
     170                builtin_print_help();
     171        } else if(memcmp(command, "list", 4) == 0) { // 4 = strlen("list")
     172                int i = atoi(command + 4); // returns 0 on error
     173                if(i <= 0 || i > builtin_strings_length) {
     174                        printf("! Usage: ?list ID with ID between 0 and %d\n", builtin_strings_length);
     175                        builtin_print_list();
     176                } else {
     177                        // just print out text on terminal
     178                        puts_P(builtin_strings[i-1]);
     179                }
     180        } else if(memcmp(command, "print", 5) == 0) { // 5 = strlen("print")
     181                int i = atoi(command + 5);
     182                if(i <= 0 || i > builtin_strings_length) {
     183                        printf("! Same syntax like ?list, just prints out to the ANELEX.\n"
     184                                "! Make sure you tested before on terminal, e.g ?list 5 => ?print 5\n");
     185                } else {
     186                        // print out text on ANELEX. That is:
     187                        printf("! Now printing text no. %d on ANELEX printer\n", i);
     188                        builtin_data.index = i;
     189                        return; // read new line, all work is done in readline()
     190                }
    57191        } else {
    58192                puts("! Command not understood. Please type ?help");
    59193        }
    60 
    61         return 0;
    62 }
    63 
    64 int uart_transmit(char c, FILE *stream) {
     194} // exec_command
     195
     196int stdout_transmit(char c, FILE *stream) {
    65197        if (c == '\n')
    66                 uart_transmit('\r', stream);
    67         loop_until_bit_is_set(UCSR0A, UDRE0);
    68         UDR0 = c;
     198                stdout_transmit('\r', stream);
     199        uart_transmit(c);
    69200        return 0;
    70201}
     
    85216
    86217    UCSR0C = UCSR0C & 0b11110111;
    87     // 1 Stop bit (Bit 3 = 0)     
     218    // 1 Stop bit (Bit 3 = 0)
     219
     220        UCSR0B = UCSR0B | (1 << RXCIE0);
     221        // Enable Recieve Interrupt (Print Buffer)
    88222}
    89223
  • bull-anelex-project/trunk/anelex-interface/src/frontend.h

    r60 r62  
    1 #include "toolchain.h"
     1#ifndef __ANELEX_FRONTEND_H__
     2#define __ANELEX_FRONTEND_H__
     3/**
     4 * ANELEX PRINTER Interface Microcontroller
     5 * RS232 client interaction
     6 *
     7 * This file collects all routines that directly communicate
     8 * to the computer/PC/user/terminal/other uc/anything that is
     9 * wired via the RS232 port.
     10 *
     11 * This file is part of the Bull Anelex Project
     12 * Copyright (C) 2010, 2011 Sven Köppel, technikum29.de
     13 *
     14 * This program is free software; you can redistribute
     15 * it and/or modify it under the terms of the GNU General
     16 * Public License as published by the Free Software
     17 * Foundation; either version 3 of the License, or (at
     18 * your option) any later version.
     19 *
     20 * This program is distributed in the hope that it will
     21 * be useful, but WITHOUT ANY WARRANTY; without even the
     22 * implied warranty of MERCHANTABILITY or FITNESS FOR A
     23 * PARTICULAR PURPOSE. See the GNU General Public License
     24 * for more details.
     25 *
     26 * You should have received a copy of the GNU General
     27 * Public License along with this program; if not, see
     28 * <http://www.gnu.org/licenses/>.
     29 *
     30 **/
     31
     32
    233#include <stdio.h>
    334#include <stdlib.h> // abs, itoa
     35#include <string.h>
     36#include <stdint.h> // int8_t, uint16_t
     37#include <avr/interrupt.h> // ISRs
    438
    5 int uart_transmit(char c, FILE *stream);
     39#include "toolchain.h"
     40#include "wiring.h"
     41
     42// some versatile defs:
     43typedef unsigned char byte_t;
     44typedef uint8_t bool_t;
     45
     46/**** Frontend parameters ****/
     47
     48/**
     49 * Input Newlines on RS232:
     50 * We are internally working all Unix style (\n only) in the print_buffer
     51 * (pbuf). Output is always with full Windows \r\n encoding.
     52 * Change settings with ?lineend.
     53 **/
     54enum line_end_t {
     55        CR,   // only carrage return (default HyperTerminal on Windows)
     56        NL,   // only newline (other uc, Unix)
     57        CRNL  // "\r\n" (typically Windows... in ordinary ways)
     58} input_line_end;
     59
     60/**
     61 * Builtin program memory test texts:
     62 * set this to [1..builtin_strings_length-1] to print this builtin string
     63 * to the anelex. A value of 0 (default) disables the builtin memory system.
     64 * Attention: Array is counted from 1!
     65 **/
     66struct builtin_options_t {
     67        uint8_t index;
     68        uint8_t read_offset;   
     69} builtin_data;
     70
     71/**** Buffer logic ****/
     72
     73/**
     74 * The Print Buffer:
     75 * This is a FIFO ringbuffer for all RS232 input. All texts are saved
     76 * by an USART RX ISR and afterwards copied in a simple line based
     77 * array for the anelex output driver (anelex.h).
     78 **/
     79
     80#define BUFFER_LEN 20
     81
     82volatile struct print_buffer_t {
     83        char buffer[BUFFER_LEN];
     84        uint8_t write_offset;
     85        uint8_t read_offset;
     86        uint8_t used_elements; // # of occupied elements (this could be also dynamically calculated
     87                               // with sth like read_offset - write_offset, but this is faster)
     88
     89        uint8_t data_loss;     // # of chars recieved which could not be saved (bad!!)
     90        uint8_t dirty_write;   // # of chars written while CTS was low (just for notice)
     91        uint8_t line_counter;  // # of (new)lines currently in buffer
     92} pbuf; // print_buffer shorthand
     93
     94
     95int stdout_transmit(char c, FILE *stream);
     96inline void uart_transmit(char c) {
     97        loop_until_bit_is_set(UCSR0A, UDRE0);
     98        UDR0 = c;
     99}
    6100void uart_init(uint32_t Baud);
    7101void print_bits(byte_t byte);
    8102void readline();
    9103void process_current_line();
    10 bool_t exec_command();
     104void exec_command();
     105
     106#endif /* __ANELEX_FRONTEND_H__ */
  • bull-anelex-project/trunk/anelex-interface/src/main.c

    r60 r62  
    88
    99#include "wiring.h"
     10#include "anelex.h"
    1011#include "toolchain.h"
    1112#include "frontend.h"
    1213
    13 static FILE output = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE);
     14static FILE output = FDEV_SETUP_STREAM(stdout_transmit, NULL, _FDEV_SETUP_WRITE);
    1415
    1516void Initialize()
     
    6061        uart_init(38400);
    6162        stdout = &output;
     63
     64        // startwerte fuer strukturen:
    6265        line_state = LINE_FINISHED; // Startwert
     66        input_line_end = CR;
     67
     68        _delay_ms(2000);
    6369       
    6470        puts("ANELEX Interface Microcontroller  (c) 2010 Sven Koeppel");
     
    6773        puts("3. Press Button to print default text. 4. Obey RS232 hardware flow control.");
    6874        stop_led();
     75
    6976       
    7077        for(;;) {
     
    7582                // process user input
    7683                if(current_line[0] == '?') {
    77                         // if exec_command returns 0, read a new line,
    78                         // else continue processing current_line.
    79                         if(!exec_command())
    80                                 continue;
     84                        exec_command();
     85                        continue;
    8186                }
    8287
  • bull-anelex-project/trunk/anelex-interface/src/toolchain.h

    r60 r62  
    1717// F_CPU wird durch die make file (den Aufruf von AVR Studio) bereits definiert
    1818
    19 #include "wiring.h"
    20 #include "anelex.h"
    2119
    22 #include "avr/io.h"
    23 #include "avr/interrupt.h"
    2420
    25 #include <util/delay.h>
    26 #include <string.h>
    27 #include <stdio.h>
    28 #include <stdint.h> // int8_t, uint16_t
    29 typedef unsigned char byte_t;
    30 typedef uint8_t bool_t;
    31 
    32 // *globale* sachen:
    33 #define LINE_LENGTH 120
    34 char current_line[LINE_LENGTH];
    3521
    3622
  • bull-anelex-project/trunk/anelex-interface/src/wiring.h

    r60 r62  
    7878#define start_cts()              ( PORTD &= ~(1 << PORTD_CTS) )
    7979#define stop_cts()               ( PORTD |= (1 << PORTD_CTS) )
     80#define is_cts()         (!( PIND & (1 << PIND7) ))
    8081
    8182
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