Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
fwatch
Commits
6b897bf0
Commit
6b897bf0
authored
Sep 21, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i2c: Transfers are synchronized using semaphores.
parent
882a9150
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
i2cdrv.c
sw/common/drivers/i2cdrv.c
+28
-0
No files found.
sw/common/drivers/i2cdrv.c
View file @
6b897bf0
...
...
@@ -31,12 +31,21 @@
* special damages, or any other relief, or for any claim by any third party,
* arising from your use of this Software.
*
* Modifications:
* Maciej Suminski: added semaphore synchronization.
*
*****************************************************************************/
#include <stddef.h>
#include "em_cmu.h"
#include "em_gpio.h"
#include "i2cdrv.h"
#undef FREERTOS
#ifdef FREERTOS
#include <FreeRTOS.h>
#include <semphr.h>
xSemaphoreHandle
i2c_sem
;
#endif
/* FREERTOS */
/*******************************************************************************
************************** GLOBAL FUNCTIONS *******************************
...
...
@@ -87,6 +96,13 @@ void I2CDRV_Init(const I2C_Init_TypeDef *init)
(
1
<<
_I2C_ROUTE_LOCATION_SHIFT
);
I2C_Init
(
I2C1
,
init
);
#ifdef FREERTOS
i2c_sem
=
xSemaphoreCreateMutex
();
if
(
i2c_sem
==
NULL
)
{
// TODO oops..
}
#endif
/* FREERTOS */
}
...
...
@@ -105,13 +121,25 @@ void I2CDRV_Init(const I2C_Init_TypeDef *init)
I2C_TransferReturn_TypeDef
I2CDRV_Transfer
(
I2C_TransferSeq_TypeDef
*
seq
)
{
I2C_TransferReturn_TypeDef
ret
;
#ifdef FREERTOS
if
(
xSemaphoreTake
(
i2c_sem
,
300000
)
!=
pdTRUE
)
return
i2cTransferInProgress
;
I2C_TransferInit
(
I2C1
,
seq
);
ret
=
I2C_Transfer
(
I2C1
);
xSemaphoreGive
(
i2c_sem
);
#else
uint32_t
timeout
=
300000
;
/* Do a polled transfer */
ret
=
I2C_TransferInit
(
I2C1
,
seq
);
while
(
ret
==
i2cTransferInProgress
&&
timeout
--
)
{
ret
=
I2C_Transfer
(
I2C1
);
}
#endif
return
(
ret
);
}
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