10
#include <drivers/diag.h>
13
#define CTL0 (USCI_BASE + 0)
14
#define CTL1 (USCI_BASE + 1)
15
#define BR0 (USCI_BASE + 2)
16
#define BR1 (USCI_BASE + 3)
17
#define MCTL (USCI_BASE + 4)
18
#define STAT (USCI_BASE + 5)
19
#define RXB (USCI_BASE + 6)
20
#define TXB (USCI_BASE + 7)
25
#define CTL1_RST (1 << 0)
26
#define CTL1_SMCLK (2 << 6)
37
#define P1_PORTSEL1 0x26
38
#define P1_PORTSEL2 0x41
40
#define UARTRXD (1 << 1)
41
#define UARTTXD (1 << 2)
49
static int msp430usci_diag_init(const struct diag *diag) {
52
REG_STORE(CTL1, 0x01);
53
REG_ORIN(CTL1, CTL1_SMCLK);
61
REG_STORE(BR0, PAR_BR & 0xff);
62
REG_STORE(BR1, PAR_BR >> 8);
63
REG_STORE(MCTL, (PAR_BRF << MCTL_BRF_OFF) |
64
(PAR_BRS << MCTL_BRS_OFF) |
65
(PAR_UCO << MCTL_UCOS16O));
68
REG_ORIN(P1_PORTSEL1, UARTRXD);
69
REG_ORIN(P1_PORTSEL2, UARTRXD);
70
REG_ORIN(P1_IN, UARTRXD);
72
REG_ORIN(P1_PORTSEL1, UARTTXD);
73
REG_ORIN(P1_PORTSEL2, UARTTXD);
74
REG_ORIN(P1_OUT, UARTTXD);
82
static void msp430usci_diag_putc(const struct diag *diag, char ch) {
86
while (!(REG_LOAD(IFG2) & TXIFG));
89
static char msp430usci_diag_getc(const struct diag *diag) {
93
static int msp430usci_diag_kbhit(const struct diag *diag) {
94
return (REG_LOAD(IFG2) & RXIFG);
98
.init = msp430usci_diag_init,
99
.putc = msp430usci_diag_putc,
100
.getc = msp430usci_diag_getc,
101
.kbhit = msp430usci_diag_kbhit,