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

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-fw/] [firmware/] [src/] [gecko3com_common.c] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 nussgipfel
/* GECKO3COM
2
 *
3
 * Copyright (C) 2008 by
4
 *   ___    ____  _   _
5
 *  (  _`\ (  __)( ) ( )
6
 *  | (_) )| (_  | |_| |   Bern University of Applied Sciences
7
 *  |  _ <'|  _) |  _  |   School of Engineering and
8
 *  | (_) )| |   | | | |   Information Technology
9
 *  (____/'(_)   (_) (_)
10
 *
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
 
25
/*********************************************************************/
26
/** \file     gecko3com_common.c
27
 *********************************************************************
28
 * \brief     common defines and prototypes for GECKO3COM
29
 *
30
 * \author    GNUradio, Christoph Zimmermann bfh.ch
31
 * \date
32
 *
33
*/
34
 
35
#include "gecko3com_common.h"
36
#include "delay.h"
37
 
38
volatile uint8_t flLOCAL;
39
volatile uint8_t flLED;
40
 
41
void
42
init_gecko3com (void)
43
{
44
  CPUCS = bmCLKSPD1;    /* CPU runs @ 48 MHz */
45
  CKCON = 0;             /* MOVX takes 2 cycles */
46
 
47
 
48
  /* configure IO ports. */
49
#ifdef PORT_A
50
  PORT_A = bmPORT_A_INITIAL;    /* Port A initial state */
51
  PORT_A_OE = bmPORT_A_OUTPUTS; /* Port A direction register */
52
#endif
53
 
54
#ifdef PORT_B
55
  PORT_B = bmPORT_B_INITIAL;    /* Port B initial state */
56
  PORT_B_OE = bmPORT_B_OUTPUTS; /* Port B direction register */
57
#endif
58
 
59
#ifdef PORT_C
60
  PORT_C = bmPORT_C_INITIAL;    /* Port C initial state */
61
  PORT_C_OE = bmPORT_C_OUTPUTS; /* Port C direction register */
62
#endif
63
 
64
#ifdef PORT_E
65
  PORT_E = bmPORT_E_INITIAL;    /* Port E initial state */
66
  PORT_E_OE = bmPORT_E_OUTPUTS; /* Port E direction register */
67
#endif
68
 
69
#ifdef PORT_CTL
70
  PORT_CTL = bmPORT_CTL_INITIAL;    /* Port GPIF CTL outputs initial state */
71
  PORT_CTL_OE = bmPORT_CTL_OUTPUTS; /* Port GPIF CTL outputs direction register */
72
#endif
73
 
74
  /* ------------------------------------------------------------------------ */
75
  /* Initialize USB interface. Configures endpoints, resets FIFOs and sets
76
   * packet size according to the connection (USB 1.1 or 2.0)
77
   */
78
 
79
  REVCTL = bmDYN_OUT | bmENH_PKT;         /* highly recommended by docs */
80
  SYNCDELAY;
81
 
82
  /* configure end points */
83
 
84
  /* EP1OUTCFG = bmVALID | bmBULK;                              SYNCDELAY; */
85
  EP1OUTCFG = 0;                                         SYNCDELAY;
86
  /* EP1INCFG  = bmVALID | bmBULK | bmIN;                       SYNCDELAY; */
87
  EP1INCFG  = 0;                                         SYNCDELAY;
88
 
89
  EP2CFG    = bmVALID | bmBULK | bmQUADBUF;             SYNCDELAY;      /* 512 quad bulk OUT */
90
  EP4CFG    = 0;                                 SYNCDELAY;      /* disabled */
91
  EP6CFG    = bmVALID | bmBULK | bmQUADBUF | bmIN;      SYNCDELAY;      /* 512 quad bulk IN */
92
  EP8CFG    = 0;                                 SYNCDELAY;      /* disabled */
93
 
94
  /* reset FIFOs */
95
 
96
  FIFORESET = bmNAKALL;                                 SYNCDELAY;
97
  FIFORESET = 2;                                        SYNCDELAY;
98
  /* FIFORESET = 4;                                     SYNCDELAY; */
99
  FIFORESET = 6;                                        SYNCDELAY;
100
  /* FIFORESET = 8;                                     SYNCDELAY; */
101
  FIFORESET = 0;                                 SYNCDELAY;
102
 
103
  /* configure end point FIFOs */
104
 
105
  /* let core see 0 to 1 transistion of autoout bit */
106
 
107
  EP2FIFOCFG = bmWORDWIDE;                      SYNCDELAY;
108
  EP6FIFOCFG = bmWORDWIDE;                      SYNCDELAY;
109
 
110
 
111
 
112
  /* prime the pump */
113
  EP0BCH = 0;                    SYNCDELAY;
114
  EP0BCL = 0;                    SYNCDELAY;
115
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY; /* because we use quad buffering we have to flush all for buffers before use */
116
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY;
117
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY;
118
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY;
119
 
120
 
121
  /* set autoout length for EP2 and autoin length for EP6 */
122
  if(USBCS & bmHSM){
123
    EP6AUTOINLENH = (512) >> 8;    SYNCDELAY;  /* this is the length for high speed */
124
    EP6AUTOINLENL = (512) & 0xff;  SYNCDELAY;
125
  }
126
  else {
127
    EP6AUTOINLENH = 0;     SYNCDELAY;  /* this is the length for full speed */
128
    EP6AUTOINLENL = 64;   SYNCDELAY;
129
  }
130
}
131
 
132
void
133
gecko3com_system_reset(void)
134
{
135
  /* resets are normaly active low, so we first set RESET to 0 */
136
  RESET &= ~bmRESET;
137
 
138
  /* enable reset output */
139
  RESET_OE |= bmRESET;
140
 
141
  mdelay(1);
142
 
143
  /* disable reset output */
144
  RESET |= bmRESET;
145
  RESET_OE &= ~bmRESET;
146
}
147
 
148
void
149
set_led_0 (const uint8_t on)
150
{
151
  if (!on)                      /* active low */
152
    LED_PORT |= bmPC_LED0;
153
  else
154
    LED_PORT &= ~bmPC_LED0;
155
}
156
 
157
void
158
set_led_1 (const uint8_t on)
159
{
160
  if (!on)                      /* active low */
161
    LED_PORT |= bmPC_LED1;
162
  else
163
    LED_PORT &= ~bmPC_LED1;
164
}
165
 
166
void
167
toggle_led_0 (void)
168
{
169
  LED_PORT ^= bmPC_LED0;
170
}
171
 
172
void
173
toggle_led_1 (void)
174
{
175
  LED_PORT ^= bmPC_LED1;
176
}
177
 
178
void
179
set_sleep_bits (uint8_t bits, uint8_t  mask)
180
{
181
  /* NOP on GECKO3COM */
182
}
183
 
184
void
185
init_io_ext (void)
186
{
187
  xdata uint8_t cmd[2];
188
  cmd[0] = 0x03;                 /* write to configuration register */
189
  cmd[1] = 0x01;                        /* set Bit 0 (LSB) as input and Bit 1,2 as output, others be irrelevant */
190
  i2c_write(I2C_DEV_IO, cmd, 2);
191
}
192
 
193
void
194
set_led_ext (const uint8_t color)
195
{
196
  xdata uint8_t cmd[2];
197
  cmd[0] = 0x01;                 /* write to output port register */
198
  cmd[1] = color;                       /* set LED */
199
  i2c_write(I2C_DEV_IO, cmd, 2);
200
  flLED = ~LEDS_OFF;
201
}
202
 
203
uint8_t
204
get_switch (void)
205
{
206
  xdata uint8_t cmd[1];
207
 
208
  cmd[0] = 0x00;                 /* set command byte to input port register */
209
 
210
  i2c_write(I2C_DEV_IO, cmd, 1);
211
 
212
  i2c_read(I2C_DEV_IO, cmd, 1);
213
 
214
  if((cmd[0] & 0x01) == 1){              /* only bit 0 in the input register is used */
215
    return 1;
216
  }
217
 
218
  return 0;
219
}

powered by: WebSVN 2.1.0

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