Changeset 63 in projects


Ignore:
Timestamp:
Jan 7, 2011, 4:49:07 AM (9 years ago)
Author:
sven
Message:

Anelex-Interface: Finalized the Builtin memory text printing (which actually was a lot of work...).

Location:
bull-anelex-project/trunk/anelex-interface/src
Files:
5 edited

Legend:

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

    r62 r63  
    6262                        // normales zeichen
    6363                        char transformed = anelex_code[ orig ];
    64                         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);
    6565                        //printf("%d", current_counter, orig);
    6666                        //_delay_us(100);
     
    9797
    9898        //printf("Zeile wird gedruckt...\n");
    99         puts("printing");
    100         while(!is_ready());
    101         puts("finished");
     99        //puts("printing");
     100        while(!is_ready()); // das ist jetzt ziemlicher ... quatsch
     101        puts("line finished");
    102102        //printf("Zeile fertig gedruckt\n");
    103103
  • bull-anelex-project/trunk/anelex-interface/src/data.c

    r62 r63  
    3232#include "data.h"
    3333
    34 char string_helloworld[] PROGMEM = "HELLO WORLD";
     34// make sure that every teststring contains a \n at the end!
     35// Otherwise the last line at least won't be printed.
     36
     37char string_helloworld[] PROGMEM = "HELLO WORLD\n";
    3538
    3639char string_simple[] PROGMEM =
  • bull-anelex-project/trunk/anelex-interface/src/frontend.c

    r62 r63  
    3232#include "data.h"
    3333
    34 
    35 // das hier ist write_advance fuer den print_buffer (pbuf)
    36 // nicht ISR, sondern INTERRUPTABLE machen! also selbst unterbrechbar!
     34// weil wir kein math.h haben...
     35#define min(a,b) ((a)<(b) ? (a) : (b))
     36
     37/**
     38 * The USART recieve interrupt vector.
     39 * This function is the write_advance for the pbuf input ring buffer.
     40 * TODO: Not ISR but make INTERRUPTABLE! (selbst unterbrechbar!)
     41 **/
    3742ISR(USART0_RX_vect) {
    3843        char c = UDR0;
     
    8287}
    8388
    84 
    85 
     89/**
     90 * builtin_readline: Does the work when the builtin reading system
     91 * is active. Function is called by readline().
     92 **/
     93void builtin_readline() {
     94        // read text from builtin memory (data.c).
     95        //printf("Builtin system runnig, index=%d, roffset=%d\n", builtin_data.index, builtin_data.read_offset);
     96        // just a shorthand:
     97        PGM_P string = builtin_strings[builtin_data.index - 1];
     98        // search next newline char (returns NULL if not found):
     99        PGM_P nlpos = strchr_P(string + builtin_data.read_offset, '\n');
     100        if(nlpos == NULL) {
     101                //puts("Reached end of string! (No more newline)");
     102                builtin_data.index = 0;
     103                builtin_data.read_offset = 0;
     104                return;
     105        }
     106
     107        uint8_t nloffset = min(nlpos - string - builtin_data.read_offset, LINE_LENGTH);
     108        //printf("Detected NL at offset %d. Currrent Line:\n", nloffset);
     109        strncpy_P(current_line, string + builtin_data.read_offset, nloffset);
     110        // RS232 feedback: Print text out (like readline() gives feedback)
     111        puts(current_line);
     112
     113        builtin_data.read_offset += nloffset + 1; // one behind the newline
     114        // important: read offset counts from 0, strlen from 1.
     115        if(builtin_data.read_offset + 1 >= strlen_P(string)) {
     116                //puts("Reached end of string!");
     117                builtin_data.index = 0;
     118                builtin_data.read_offset = 0;
     119        }
     120}
     121
     122/**
     123 * The readline function reads one line from RS232 and puts it into the driver
     124 * output text buffer current_line[] (anelex.h). The real work is done asynchronously
     125 * by the USART RX ISR. Alternatively the next line from the builtin program memory text
     126 * is copied to current_line[] by builtin_readline().
     127 *
     128 * This function is called by main().
     129 **/
    86130void readline() {
    87131        memset(&current_line, 0, LINE_LENGTH); // null the output buffer (important)
    88132
     133        printf("Readline!\n");
     134        // check if we get the text from ROM
    89135        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                 }
     136                builtin_readline();
    103137                return;
    104138        }
     
    163197
    164198
     199/**
     200 * Parses the current_line[] and executes a command. Expects current_line[] to be
     201 * a command, which is checked in the main() loop.
     202 * Function is called by main().
     203 **/
    165204void exec_command() {
    166205        char* command = current_line + 1; // strip leading '?'
     
    189228                        return; // read new line, all work is done in readline()
    190229                }
     230        } else if(strcasecmp(command, "ping") == 0) {
     231                puts("Pong :-)");
    191232        } else {
    192233                puts("! Command not understood. Please type ?help");
     
    194235} // exec_command
    195236
     237/**
     238 * USART TX function for avr-libc stdio.h toolchain. This function
     239 * prints out exactly one character and converts on the fly NL to
     240 * CR NL. See uart_transmit() for the function without conversion.
     241 **/
    196242int stdout_transmit(char c, FILE *stream) {
    197243        if (c == '\n')
     
    201247}
    202248
     249/**
     250 * UART initialisation, called at main() start. In this program we also
     251 * set up the RX interrupt enable flag.
     252 **/
    203253void uart_init(uint32_t Baud) {
    204254    int BaudRate = F_CPU / (16 * Baud) - 1;
     
    222272}
    223273
    224 
     274/**
     275 * Helper function to print out a byte as binary representation to STDOUT.
     276 **/
    225277void print_bits(byte_t byte) {
    226278        char str[10];
  • bull-anelex-project/trunk/anelex-interface/src/frontend.h

    r62 r63  
    5050 * We are internally working all Unix style (\n only) in the print_buffer
    5151 * (pbuf). Output is always with full Windows \r\n encoding.
    52  * Change settings with ?lineend.
     52 * Change settings with ?lineend (not yet implemented).
    5353 **/
    5454enum line_end_t {
     
    6666struct builtin_options_t {
    6767        uint8_t index;
    68         uint8_t read_offset;   
     68        uint16_t read_offset;  // ATTENTION: using uint8_t, strings could not be bigger than 2^8=256byte,
     69                               // (otherwise counter just wraps), uint16_t increases to 64kByte which is ok
    6970} builtin_data;
    7071
  • bull-anelex-project/trunk/anelex-interface/src/main.c

    r62 r63  
    6666        input_line_end = CR;
    6767
    68         _delay_ms(2000);
     68        _delay_ms(800);
    6969       
    7070        puts("ANELEX Interface Microcontroller  (c) 2010 Sven Koeppel");
     
    8989                while(line_state != LINE_FINISHED) {
    9090                        puts("Wait for printer finished...");
    91                         _delay_ms(2000);
     91                        _delay_ms(200);
    9292                }
    9393
     
    9595
    9696                while(line_state == LINE_TRANSMITTING);
    97                 puts("printing - accepting new line");
     97                puts("accepting new line");
    9898        }
    9999
     100        printf("End of main!\n");
    100101        return 0; // ende.
    101102}
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