Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
8947a3c4
Commit
8947a3c4
authored
8 years ago
by
Joakim Nohlgård
Browse files
Options
Downloads
Patches
Plain Diff
cpu/kinetis_common: Add debugging messages to i2c driver
parent
5c823621
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/kinetis_common/periph/i2c.c
+17
-0
17 additions, 0 deletions
cpu/kinetis_common/periph/i2c.c
with
17 additions
and
0 deletions
cpu/kinetis_common/periph/i2c.c
+
17
−
0
View file @
8947a3c4
...
@@ -33,8 +33,15 @@
...
@@ -33,8 +33,15 @@
#include
"periph/i2c.h"
#include
"periph/i2c.h"
#define ENABLE_DEBUG (0)
#define ENABLE_DEBUG (0)
/* Define ENABLE_TRACE to 1 to enable printing of all TX/RX bytes to UART for extra verbose debugging */
#define ENABLE_TRACE (0)
#include
"debug.h"
#include
"debug.h"
#if ENABLE_TRACE
#define TRACE(...) DEBUG(__VA_ARGS__)
#else
#define TRACE(...)
#endif
/* guard file in case no I2C device is defined */
/* guard file in case no I2C device is defined */
#if I2C_NUMOF
#if I2C_NUMOF
...
@@ -76,6 +83,7 @@ int i2c_release(i2c_t dev)
...
@@ -76,6 +83,7 @@ int i2c_release(i2c_t dev)
int
i2c_init_master
(
i2c_t
dev
,
i2c_speed_t
speed
)
int
i2c_init_master
(
i2c_t
dev
,
i2c_speed_t
speed
)
{
{
DEBUG
(
"i2c_init_master: %lu, %lu
\n
"
,
(
unsigned
long
)
dev
,
(
unsigned
long
)
speed
);
I2C_Type
*
i2c
;
I2C_Type
*
i2c
;
PORT_Type
*
i2c_port
;
PORT_Type
*
i2c_port
;
int
pin_scl
=
0
;
int
pin_scl
=
0
;
...
@@ -175,6 +183,7 @@ static inline int _i2c_start(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
...
@@ -175,6 +183,7 @@ static inline int _i2c_start(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
{
{
/* bus free ? */
/* bus free ? */
if
(
dev
->
S
&
I2C_S_BUSY_MASK
)
{
if
(
dev
->
S
&
I2C_S_BUSY_MASK
)
{
DEBUG
(
"i2c:_start: bus busy
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -186,6 +195,7 @@ static inline int _i2c_start(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
...
@@ -186,6 +195,7 @@ static inline int _i2c_start(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
/* wait for bus-busy to be set */
/* wait for bus-busy to be set */
while
(
!
(
dev
->
S
&
I2C_S_BUSY_MASK
))
{
while
(
!
(
dev
->
S
&
I2C_S_BUSY_MASK
))
{
if
(
_i2c_arbitration_lost
(
dev
))
{
if
(
_i2c_arbitration_lost
(
dev
))
{
DEBUG
(
"i2c:_start: arbitration lost
\n
"
);
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -196,11 +206,13 @@ static inline int _i2c_start(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
...
@@ -196,11 +206,13 @@ static inline int _i2c_start(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
dev
->
S
=
I2C_S_IICIF_MASK
;
dev
->
S
=
I2C_S_IICIF_MASK
;
if
(
_i2c_arbitration_lost
(
dev
))
{
if
(
_i2c_arbitration_lost
(
dev
))
{
DEBUG
(
"i2c:_start: arbitration lost late
\n
"
);
return
-
1
;
return
-
1
;
}
}
/* check for receive acknowledge */
/* check for receive acknowledge */
if
(
dev
->
S
&
I2C_S_RXAK_MASK
)
{
if
(
dev
->
S
&
I2C_S_RXAK_MASK
)
{
DEBUG
(
"i2c:_start: no addr ack
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -219,11 +231,13 @@ static inline int _i2c_restart(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
...
@@ -219,11 +231,13 @@ static inline int _i2c_restart(I2C_Type *dev, uint8_t address, uint8_t rw_flag)
dev
->
S
=
I2C_S_IICIF_MASK
;
dev
->
S
=
I2C_S_IICIF_MASK
;
if
(
_i2c_arbitration_lost
(
dev
))
{
if
(
_i2c_arbitration_lost
(
dev
))
{
DEBUG
(
"i2c:_restart: arbitration lost
\n
"
);
return
-
1
;
return
-
1
;
}
}
/* check for receive acknowledge */
/* check for receive acknowledge */
if
(
dev
->
S
&
I2C_S_RXAK_MASK
)
{
if
(
dev
->
S
&
I2C_S_RXAK_MASK
)
{
DEBUG
(
"i2c:_restart: no addr ack
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -251,6 +265,7 @@ static inline int _i2c_receive(I2C_Type *dev, uint8_t *data, int length)
...
@@ -251,6 +265,7 @@ static inline int _i2c_receive(I2C_Type *dev, uint8_t *data, int length)
dev
->
S
=
I2C_S_IICIF_MASK
;
dev
->
S
=
I2C_S_IICIF_MASK
;
if
(
_i2c_arbitration_lost
(
dev
))
{
if
(
_i2c_arbitration_lost
(
dev
))
{
DEBUG
(
"i2c:_receive: arbitration lost (to go=%d)
\n
"
,
length
);
return
-
1
;
return
-
1
;
}
}
...
@@ -268,6 +283,7 @@ static inline int _i2c_receive(I2C_Type *dev, uint8_t *data, int length)
...
@@ -268,6 +283,7 @@ static inline int _i2c_receive(I2C_Type *dev, uint8_t *data, int length)
}
}
data
[
n
]
=
(
char
)
dev
->
D
;
data
[
n
]
=
(
char
)
dev
->
D
;
TRACE
(
"i2c: rx: %02x
\n
"
,
(
unsigned
int
)
data
[
n
]);
n
++
;
n
++
;
}
}
...
@@ -279,6 +295,7 @@ static inline int _i2c_transmit(I2C_Type *dev, uint8_t *data, int length)
...
@@ -279,6 +295,7 @@ static inline int _i2c_transmit(I2C_Type *dev, uint8_t *data, int length)
int
n
=
0
;
int
n
=
0
;
while
(
length
>
0
)
{
while
(
length
>
0
)
{
TRACE
(
"i2c: tx: %02x
\n
"
,
(
unsigned
int
)
data
[
n
]);
dev
->
D
=
data
[
n
];
dev
->
D
=
data
[
n
];
while
(
!
(
dev
->
S
&
I2C_S_IICIF_MASK
));
while
(
!
(
dev
->
S
&
I2C_S_IICIF_MASK
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment