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: |
---|
43 | typedef unsigned char byte_t; |
---|
44 | typedef 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 | **/ |
---|
54 | enum 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 | **/ |
---|
66 | struct 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 | |
---|
82 | volatile 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 | |
---|
95 | int stdout_transmit(char c, FILE *stream); |
---|
96 | inline void uart_transmit(char c) { |
---|
97 | loop_until_bit_is_set(UCSR0A, UDRE0); |
---|
98 | UDR0 = c; |
---|
99 | } |
---|
100 | void uart_init(uint32_t Baud); |
---|
101 | void print_bits(byte_t byte); |
---|
102 | void readline(); |
---|
103 | void process_current_line(); |
---|
104 | void exec_command(); |
---|
105 | |
---|
106 | #endif /* __ANELEX_FRONTEND_H__ */ |
---|