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 32

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
 
104 17 nussgipfel
/* prime the pump */
105
  EP0BCH = 0;                    SYNCDELAY;
106
  EP0BCL = 0;                    SYNCDELAY;
107
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY; /* because we use quad buffering */
108
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY; /* we have to flush all for  */
109
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY; /* buffers before use */
110
  OUTPKTEND = bmSKIP | 2;       SYNCDELAY;
111 9 nussgipfel
 
112 17 nussgipfel
  /* configure end point FIFOs */
113 9 nussgipfel
  EP2FIFOCFG = bmWORDWIDE;                      SYNCDELAY;
114
  EP6FIFOCFG = bmWORDWIDE;                      SYNCDELAY;
115
 
116 17 nussgipfel
 
117 9 nussgipfel
 
118
  /* set autoout length for EP2 and autoin length for EP6 */
119
  if(USBCS & bmHSM){
120 29 nussgipfel
    EP6AUTOINLENH = (512) >> 8;    SYNCDELAY;  /* this is the length for */
121
    EP6AUTOINLENL = (512) & 0xff;  SYNCDELAY;  /* high speed */
122 9 nussgipfel
  }
123
  else {
124
    EP6AUTOINLENH = 0;     SYNCDELAY;  /* this is the length for full speed */
125
    EP6AUTOINLENL = 64;   SYNCDELAY;
126
  }
127
}
128
 
129
void
130
gecko3com_system_reset(void)
131
{
132
  /* resets are normaly active low, so we first set RESET to 0 */
133
  RESET &= ~bmRESET;
134
 
135
  /* enable reset output */
136
  RESET_OE |= bmRESET;
137
 
138
  mdelay(1);
139
 
140
  /* disable reset output */
141
  RESET |= bmRESET;
142
  RESET_OE &= ~bmRESET;
143
}
144
 
145
void
146
set_led_0 (const uint8_t on)
147
{
148
  if (!on)                      /* active low */
149
    LED_PORT |= bmPC_LED0;
150
  else
151
    LED_PORT &= ~bmPC_LED0;
152
}
153
 
154
void
155
set_led_1 (const uint8_t on)
156
{
157
  if (!on)                      /* active low */
158
    LED_PORT |= bmPC_LED1;
159
  else
160
    LED_PORT &= ~bmPC_LED1;
161
}
162
 
163
void
164
toggle_led_0 (void)
165
{
166
  LED_PORT ^= bmPC_LED0;
167
}
168
 
169
void
170
toggle_led_1 (void)
171
{
172
  LED_PORT ^= bmPC_LED1;
173
}
174
 
175 32 nussgipfel
/** unused function on GECKO3COM */
176 9 nussgipfel
void
177
set_sleep_bits (uint8_t bits, uint8_t  mask)
178
{
179
  /* NOP on GECKO3COM */
180
}
181
 
182
void
183
init_io_ext (void)
184
{
185
  xdata uint8_t cmd[2];
186 29 nussgipfel
  cmd[0] = 0x03;                /* write to configuration register */
187
  cmd[1] = 0x01;                       /* set Bit 0 (LSB) as input and Bit */
188
  i2c_write(I2C_DEV_IO, cmd, 2);       /* 1,2 as output, others be irrelevant */
189 9 nussgipfel
}
190
 
191
void
192
set_led_ext (const uint8_t color)
193
{
194
  xdata uint8_t cmd[2];
195 29 nussgipfel
  cmd[0] = 0x01;                /* write to output port register */
196
  cmd[1] = color;                      /* set LED */
197 9 nussgipfel
  i2c_write(I2C_DEV_IO, cmd, 2);
198
  flLED = ~LEDS_OFF;
199
}
200
 
201
uint8_t
202
get_switch (void)
203
{
204
  xdata uint8_t cmd[1];
205
 
206 29 nussgipfel
  cmd[0] = 0x00;         /* set command byte to input port register */
207 9 nussgipfel
 
208
  i2c_write(I2C_DEV_IO, cmd, 1);
209
 
210
  i2c_read(I2C_DEV_IO, cmd, 1);
211
 
212 29 nussgipfel
  if((cmd[0] & 0x01) == 1){      /* only bit 0 in the input register is used */
213 9 nussgipfel
    return 1;
214
  }
215
 
216
  return 0;
217
}

powered by: WebSVN 2.1.0

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