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

Last change on this file since 62 was 62, checked in by sven, 13 years ago

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

File size: 3.2 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.
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}
100void uart_init(uint32_t Baud);
101void print_bits(byte_t byte);
102void readline();
103void process_current_line();
104void exec_command();
105
106#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