source: projects/bull-anelex-project/trunk/anelex-interface/src/frontend.h @ 63

Last change on this file since 63 was 63, checked in by sven, 9 years ago

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

File size: 3.4 KB
Line 
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
33#include <stdio.h>
34#include <stdlib.h> // abs, itoa
35#include <string.h>
36#include <stdint.h> // int8_t, uint16_t
37#include <avr/interrupt.h> // ISRs
38
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 (not yet implemented).
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        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
70} builtin_data;
71
72/**** Buffer logic ****/
73
74/**
75 * The Print Buffer:
76 * This is a FIFO ringbuffer for all RS232 input. All texts are saved
77 * by an USART RX ISR and afterwards copied in a simple line based
78 * array for the anelex output driver (anelex.h).
79 **/
80
81#define BUFFER_LEN 20
82
83volatile struct print_buffer_t {
84        char buffer[BUFFER_LEN];
85        uint8_t write_offset;
86        uint8_t read_offset;
87        uint8_t used_elements; // # of occupied elements (this could be also dynamically calculated
88                               // with sth like read_offset - write_offset, but this is faster)
89
90        uint8_t data_loss;     // # of chars recieved which could not be saved (bad!!)
91        uint8_t dirty_write;   // # of chars written while CTS was low (just for notice)
92        uint8_t line_counter;  // # of (new)lines currently in buffer
93} pbuf; // print_buffer shorthand
94
95
96int stdout_transmit(char c, FILE *stream);
97inline void uart_transmit(char c) {
98        loop_until_bit_is_set(UCSR0A, UDRE0);
99        UDR0 = c;
100}
101void uart_init(uint32_t Baud);
102void print_bits(byte_t byte);
103void readline();
104void process_current_line();
105void exec_command();
106
107#endif /* __ANELEX_FRONTEND_H__ */
Note: See TracBrowser for help on using the repository browser.
© 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