Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
28
Issues
28
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
172ee7d2
Commit
172ee7d2
authored
Mar 07, 2012
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i2c driver for two interfaces in syscon
parent
7597b055
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
44 deletions
+89
-44
Makefile
Makefile
+1
-1
i2c.c
dev/i2c.c
+54
-41
syscon.c
dev/syscon.c
+3
-0
i2c.h
include/i2c.h
+19
-0
syscon.h
include/syscon.h
+12
-2
No files found.
Makefile
View file @
172ee7d2
PLATFORM
=
lm32
OBJS_WRC
=
wrc_main.o dev/uart.o dev/endpoint.o dev/minic.o dev/pps_gen.o dev/syscon.o dev/onewire.o dev/softpll.o lib/mprintf.o monitor/monitor.o dev/ep_pfilter.o dev/dna.o
OBJS_WRC
=
wrc_main.o dev/uart.o dev/endpoint.o dev/minic.o dev/pps_gen.o dev/syscon.o dev/
i2c.o dev/
onewire.o dev/softpll.o lib/mprintf.o monitor/monitor.o dev/ep_pfilter.o dev/dna.o
D
=
ptp-noposix
PTPD_CFLAGS
=
-ffreestanding
-DPTPD_FREESTANDING
-DWRPC_EXTRA_SLIM
-DPTPD_MSBF
-DPTPD_DBG
...
...
dev/i2c.c
View file @
172ee7d2
...
...
@@ -2,99 +2,112 @@
#include "board.h"
#include "syscon.h"
#define I2C_DELAY
1
00
#define I2C_DELAY
3
00
static
void
mi2c_delay
()
void
mi2c_delay
()
{
int
i
;
for
(
i
=
0
;
i
<
I2C_DELAY
;
i
++
)
asm
volatile
(
"nop"
);
}
#define M_SDA_OUT(
x) { gpio_out(GPIO_SDA
, x); mi2c_delay(); }
#define M_SCL_OUT(
x) { gpio_out(GPIO_SCL
, x); mi2c_delay(); }
#define M_SDA_IN
gpio_in(GPIO_SDA
)
#define M_SDA_OUT(
i, x) { gpio_out(i2c_if[i].sda
, x); mi2c_delay(); }
#define M_SCL_OUT(
i, x) { gpio_out(i2c_if[i].scl
, x); mi2c_delay(); }
#define M_SDA_IN
(i) gpio_in(i2c_if[i].sda
)
void
mi2c_start
()
void
mi2c_start
(
uint8_t
i2cif
)
{
M_SDA_OUT
(
0
);
M_SCL_OUT
(
0
);
M_SDA_OUT
(
i2cif
,
0
);
M_SCL_OUT
(
i2cif
,
0
);
}
void
mi2c_repeat_start
()
void
mi2c_repeat_start
(
uint8_t
i2cif
)
{
M_SDA_OUT
(
1
);
M_SCL_OUT
(
1
);
M_SDA_OUT
(
0
);
M_SCL_OUT
(
0
);
M_SDA_OUT
(
i2cif
,
1
);
M_SCL_OUT
(
i2cif
,
1
);
M_SDA_OUT
(
i2cif
,
0
);
M_SCL_OUT
(
i2cif
,
0
);
}
void
mi2c_stop
()
void
mi2c_stop
(
uint8_t
i2cif
)
{
M_SDA_OUT
(
0
);
M_SCL_OUT
(
1
);
M_SDA_OUT
(
1
);
M_SDA_OUT
(
i2cif
,
0
);
M_SCL_OUT
(
i2cif
,
1
);
M_SDA_OUT
(
i2cif
,
1
);
}
unsigned
char
mi2c_put_byte
(
unsigned
char
data
)
unsigned
char
mi2c_put_byte
(
u
int8_t
i2cif
,
u
nsigned
char
data
)
{
char
i
;
unsigned
char
ack
;
for
(
i
=
0
;
i
<
8
;
i
++
,
data
<<=
1
)
{
M_SDA_OUT
(
data
&
0x80
);
M_SCL_OUT
(
1
);
M_SCL_OUT
(
0
);
M_SDA_OUT
(
i2cif
,
data
&
0x80
);
M_SCL_OUT
(
i2cif
,
1
);
M_SCL_OUT
(
i2cif
,
0
);
}
M_SDA_OUT
(
1
);
M_SCL_OUT
(
1
);
M_SDA_OUT
(
i2cif
,
1
);
M_SCL_OUT
(
i2cif
,
1
);
ack
=
M_SDA_IN
;
/* ack: sda is pulled low ->success. */
ack
=
M_SDA_IN
(
i2cif
)
;
/* ack: sda is pulled low ->success. */
M_SCL_OUT
(
0
);
M_SDA_OUT
(
0
);
M_SCL_OUT
(
i2cif
,
0
);
M_SDA_OUT
(
i2cif
,
0
);
return
ack
!=
0
;
}
void
mi2c_get_byte
(
u
nsigned
char
*
data
)
void
mi2c_get_byte
(
u
int8_t
i2cif
,
unsigned
char
*
data
,
uint8_t
last
)
{
int
i
;
unsigned
char
indata
=
0
;
M_SDA_OUT
(
i2cif
,
1
);
/* assert: scl is low */
M_SCL_OUT
(
0
);
M_SCL_OUT
(
i2cif
,
0
);
for
(
i
=
0
;
i
<
8
;
i
++
)
{
M_SCL_OUT
(
1
);
M_SCL_OUT
(
i2cif
,
1
);
indata
<<=
1
;
if
(
M_SDA_IN
)
indata
|=
0x01
;
M_SCL_OUT
(
0
);
if
(
M_SDA_IN
(
i2cif
)
)
indata
|=
0x01
;
M_SCL_OUT
(
i2cif
,
0
);
}
M_SDA_OUT
(
1
);
if
(
last
)
{
M_SDA_OUT
(
i2cif
,
1
);
//noack
M_SCL_OUT
(
i2cif
,
1
);
M_SCL_OUT
(
i2cif
,
0
);
}
else
{
M_SDA_OUT
(
i2cif
,
0
);
//ack
M_SCL_OUT
(
i2cif
,
1
);
M_SCL_OUT
(
i2cif
,
0
);
}
*
data
=
indata
;
}
void
mi2c_init
()
void
mi2c_init
(
uint8_t
i2cif
)
{
M_SCL_OUT
(
1
);
M_SDA_OUT
(
1
);
M_SCL_OUT
(
i2cif
,
1
);
M_SDA_OUT
(
i2cif
,
1
);
}
void
mi2c_scan
()
void
mi2c_scan
(
uint8_t
i2cif
)
{
int
i
;
for
(
i
=
0
;
i
<
0x80
;
i
++
)
{
mi2c_start
(
);
mprintf
(
"scan %d
\n
"
,
i
);
if
(
!
mi2c_put_byte
(
i
<<
1
))
mprintf
(
"found : %x
\n
"
,
i
);
mi2c_stop
(
);
mi2c_start
(
i2cif
);
// mprintf("scan %x
\n",i);
if
(
!
mi2c_put_byte
(
i2cif
,
i
<<
1
))
mprintf
(
"found : %x
\n
"
,
i
);
mi2c_stop
(
i2cif
);
}
}
dev/syscon.c
View file @
172ee7d2
#include "syscon.h"
struct
s_i2c_if
i2c_if
[
2
]
=
{
{
SYSC_GPSR_FMC_SCL
,
SYSC_GPSR_FMC_SDA
},
{
SYSC_GPSR_SFP_SCL
,
SYSC_GPSR_SFP_SDA
}
};
/****************************
* TIMER
***************************/
...
...
include/i2c.h
0 → 100644
View file @
172ee7d2
#ifndef __I2C_H
#define __I2C_H
void
mi2c_init
(
uint8_t
i2cif
);
void
mi2c_start
(
uint8_t
i2cif
);
void
mi2c_repeat_start
(
uint8_t
i2cif
);
void
mi2c_stop
(
uint8_t
i2cif
);
void
mi2c_get_byte
(
uint8_t
i2cif
,
unsigned
char
*
data
,
uint8_t
last
);
unsigned
char
mi2c_put_byte
(
uint8_t
i2cif
,
unsigned
char
data
);
void
mi2c_delay
();
void
mi2c_scan
(
uint8_t
i2cif
);
int
eeprom_read
(
uint8_t
i2cif
,
uint8_t
i2c_addr
,
uint32_t
offset
,
uint8_t
*
buf
,
size_t
size
);
uint16_t
eeprom_sfp_section
(
uint8_t
i2cif
,
uint8_t
i2c_addr
,
size_t
size
,
uint16_t
*
section_sz
);
int
eeprom_write
(
uint8_t
i2cif
,
uint8_t
i2c_addr
,
uint32_t
offset
,
uint8_t
*
buf
,
size_t
size
);
#endif
include/syscon.h
View file @
172ee7d2
...
...
@@ -19,10 +19,20 @@ struct SYSCON_WB
/*GPIO pins*/
#define GPIO_LED_LINK SYSC_GPSR_LED_LINK
#define GPIO_LED_STAT SYSC_GPSR_LED_STAT
#define GPIO_SCL SYSC_GPSR_FMC_SCL
#define GPIO_SDA SYSC_GPSR_FMC_SDA
#define GPIO_BTN1 SYSC_GPSR_BTN1
#define GPIO_BTN2 SYSC_GPSR_BTN2
#define GPIO_SFP_DET SYSC_GPSR_SFP_DET
#define WRPC_FMC_I2C 0
#define WRPC_SFP_I2C 1
struct
s_i2c_if
{
uint32_t
scl
;
uint32_t
sda
;
};
struct
s_i2c_if
i2c_if
[
2
];
void
timer_init
(
uint32_t
enable
);
uint32_t
timer_get_tics
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment