OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [ods68302/] [startup/] [m68302scc.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*****************************************************************************/
2
/*
3
  $Id: m68302scc.c,v 1.2 2001-09-27 12:00:23 chris Exp $
4
 
5
  M68302 SCC Polled Driver
6
 
7
 */
8
/*****************************************************************************/
9
 
10
 
11
#include <bsp.h>
12
#include <m68302.h>
13
#include <m68302scc.h>
14
 
15
#define M68302_SCC_COUNT (3)
16
 
17
static volatile m302_SCC_t *scc[M68302_SCC_COUNT] = { 0, 0, 0 };
18
static volatile m302_SCC_Registers_t *scc_reg[M68302_SCC_COUNT] = { 0, 0, 0 };
19
static int scc_translate[M68302_SCC_COUNT] = { 0, 0, 0 };
20
 
21
static const rtems_unsigned16 baud_clocks[] =
22
{
23
  (SYSTEM_CLOCK / (  4800 * 16)),
24
  (SYSTEM_CLOCK / (  9600 * 16)),
25
  (SYSTEM_CLOCK / ( 19200 * 16)),
26
  (SYSTEM_CLOCK / ( 38400 * 16)),
27
  (SYSTEM_CLOCK / ( 57600 * 16)),
28
  (SYSTEM_CLOCK / (115700 * 16))
29
};
30
 
31
void scc_initialise(int channel, int baud, int translate)
32
{
33
  rtems_unsigned16 scon;
34
 
35
  if (channel < M68302_SCC_COUNT)
36
  {
37
    scc[channel] = &m302.scc1 + channel;
38
    scc_reg[channel] = &m302.reg.scc[channel];
39
    scc_translate[channel] = translate;
40
 
41
    scon  = (baud_clocks[baud] & 0xF800) == 0 ? 0 : 1;
42
    scon |= (((baud_clocks[baud] / (1 + scon * 3)) - 1) << 1) & 0x0FFE;
43
 
44
    scc_reg[channel]->scon = scon;
45
    scc_reg[channel]->scm = 0x0171;
46
 
47
    scc[channel]->bd.tx[0].status = 0x2000;
48
    scc[channel]->bd.tx[0].length = 0;
49
    scc[channel]->bd.tx[0].buffer =
50
      (rtems_unsigned8*) &(scc[channel]->bd.tx[1].buffer);
51
 
52
    scc[channel]->bd.rx[0].status = 0x2000;
53
    scc[channel]->bd.rx[0].length = 0;
54
    scc[channel]->bd.rx[0].buffer =
55
      (rtems_unsigned8*) &(scc[channel]->bd.rx[1].buffer);
56
 
57
    scc[channel]->parm.rfcr = 0x50;
58
    scc[channel]->parm.tfcr = 0x50;
59
 
60
    scc[channel]->parm.mrblr = 0x0001;
61
    scc[channel]->prot.uart.max_idl = 0x0004;
62
    scc[channel]->prot.uart.brkcr = 1;
63
    scc[channel]->prot.uart.parec = 0;
64
    scc[channel]->prot.uart.frmec = 0;
65
    scc[channel]->prot.uart.nosec = 0;
66
    scc[channel]->prot.uart.brkec = 0;
67
    scc[channel]->prot.uart.uaddr1 = 0;
68
    scc[channel]->prot.uart.uaddr2 = 0;
69
    scc[channel]->prot.uart.character[0] = 0x0003;
70
    scc[channel]->prot.uart.character[1] = 0x8000;
71
 
72
    scc_reg[channel]->scce = 0xFF;
73
    scc_reg[channel]->sccm = 0x15;
74
 
75
    scc_reg[channel]->scm = 0x17d;
76
  }
77
}
78
 
79
unsigned char scc_status(int channel, unsigned char status)
80
{
81
  rtems_unsigned16 rx_status;
82
 
83
  m302.reg.wcn = 0;
84
 
85
  if ((channel < M68302_SCC_COUNT) && scc[channel])
86
  {
87
    rx_status = scc[channel]->bd.rx[0].status;
88
 
89
    if ((rx_status & 0x8000) == 0)
90
    {
91
      if (rx_status & 0x003B)
92
      {
93
        return 2;
94
      }
95
      if (status == 0)
96
      {
97
        return 1;
98
      }
99
    }
100
  }
101
 
102
  return 0;
103
}
104
 
105
unsigned char scc_in(int channel)
106
{
107
  m302.reg.wcn = 0;
108
 
109
  if ((channel < M68302_SCC_COUNT) && scc[channel])
110
  {
111
    if ((scc[channel]->bd.rx[0].status & 0x8000) == 0)
112
    {
113
      unsigned char c;
114
 
115
      c = *(scc[channel]->bd.rx[0].buffer);
116
 
117
      scc[channel]->bd.rx[0].status = 0xa000;
118
 
119
      return c;
120
    }
121
  }
122
 
123
  return 0;
124
}
125
 
126
void scc_out(int channel, unsigned char character)
127
{
128
  if ((channel < M68302_SCC_COUNT) && scc[channel])
129
  {
130
    do
131
    {
132
      m302.reg.wcn = 0;
133
    }
134
    while (scc[channel]->bd.tx[0].status & 0x8000);
135
 
136
    *(scc[channel]->bd.tx[0].buffer) = character;
137
 
138
    scc[channel]->bd.tx[0].length = 1;
139
    scc[channel]->bd.tx[0].status = 0xa000;
140
 
141
    if (scc_translate[channel])
142
    {
143
      if (character == '\n')
144
      {
145
        scc_out(channel, '\r');
146
      }
147
    }
148
  }
149
}
150
 
151
 
152
 
153
 
154
 
155
 
156
 
157
 
158
 
159
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.