4 Copyright 2008, 2011 Michel Pollet <buserror@gmail.com>
5 Copyright 2011 Markus Lampert <mlampert@telus.net>
7 This file is part of simavr.
9 simavr is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 simavr is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with simavr. If not, see <http://www.gnu.org/licenses/>.
34 avr_lin_t *p = (avr_lin_t*) param;
36 if (p->r_linbtr != p->ldisr.reg || p->r_linbtr != p->lbt.reg) { // sanity check
37 printf("Error: LDISR and LBT[x] register different!\n");
41 printf("LIN addr[%04x] = %02x\n", addr, v);
42 if (addr == p->ldisr.reg) {
43 if (avr_regbit_get(avr, p->lena)) {
44 printf("Warning: LENA bit set on changing LBTR\n");
47 if ((v >> p->ldisr.bit) & p->ldisr.mask) {
48 uint8_t lbt = (v >> p->lbt.bit) & p->lbt.mask;
50 v = (1 << p->ldisr.bit) | (lbt << p->lbt.bit);
51 printf("LIN: v=%02x -> LBT = %02x -> LINBT = %02x\n", ov, lbt, v);
56 avr_core_watch_write(avr, addr, v); // actually set the value
58 uint32_t lbt = avr_regbit_get(avr, p->lbt);
59 uint32_t lbrr = (avr->data[p->r_linbrrh] << 8) | avr->data[p->r_linbrrl];
60 printf("LIN-UART LBT/LBRR to %04x/%04x\n", lbt, lbrr);
61 uint32_t baud = avr->frequency / (lbt * (lbrr + 1));
62 uint32_t word_size = 1 /*start*/+ 8 /*data bits*/+ 1 /*parity*/+ 1 /*stop*/;
64 printf("LIN-UART configured to %04x/%04x = %d bps, 8 data 1 stop\n", lbt,
67 p->uart.usec_per_byte = 1000000 / (baud / word_size);
68 printf("Roughly %d usec per bytes\n", (int) p->uart.usec_per_byte);
75 printf("LIN-UART: reset\n");
76 avr_lin_t *p = (avr_lin_t*) port;
77 avr_t * avr = p->io.avr;
79 p->uart.io.reset(&p->uart.io);
80 avr->data[p->r_linbtr] = 0x20;
83 static avr_io_t _io = {
85 .reset = avr_lin_reset,
94 avr_uart_init(avr, &p->uart);
97 avr_register_io_write(avr, p->r_linbtr, avr_lin_baud_write, p);
98 avr_register_io_write(avr, p->r_linbrrl, avr_lin_baud_write, p);
99 avr->data[p->r_linbtr] = 0x20;