diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-12-30 20:45:56 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-12-30 20:45:56 +0000 |
commit | 2234fd3e31d4ce6e2b3990340b52719951e65731 (patch) | |
tree | 3d8dadab8ab98a46ab2f98ed0b94d648e86ce837 /testhal/STM32F1xx | |
parent | 08feb80580ca82cfebd77a43d14d1197ec7c4f99 (diff) | |
download | ChibiOS-2234fd3e31d4ce6e2b3990340b52719951e65731.tar.gz ChibiOS-2234fd3e31d4ce6e2b3990340b52719951e65731.tar.bz2 ChibiOS-2234fd3e31d4ce6e2b3990340b52719951e65731.zip |
I2C. API changes mostly done.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3692 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32F1xx')
-rw-r--r-- | testhal/STM32F1xx/I2C/Makefile | 5 | ||||
-rw-r--r-- | testhal/STM32F1xx/I2C/fake.c | 9 | ||||
-rw-r--r-- | testhal/STM32F1xx/I2C/i2c_pns.c | 2 | ||||
-rw-r--r-- | testhal/STM32F1xx/I2C/main.c | 39 | ||||
-rw-r--r-- | testhal/STM32F1xx/I2C/tmp75.c | 8 |
5 files changed, 37 insertions, 26 deletions
diff --git a/testhal/STM32F1xx/I2C/Makefile b/testhal/STM32F1xx/I2C/Makefile index 08494928a..12eea9360 100644 --- a/testhal/STM32F1xx/I2C/Makefile +++ b/testhal/STM32F1xx/I2C/Makefile @@ -82,9 +82,10 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/syscalls.c \
main.c \
i2c_pns.c \
- lis3.c \
tmp75.c \
- fake.c
+ fake.c \
+ #lis3.c
+
diff --git a/testhal/STM32F1xx/I2C/fake.c b/testhal/STM32F1xx/I2C/fake.c index b06ffbdfd..9d46f448d 100644 --- a/testhal/STM32F1xx/I2C/fake.c +++ b/testhal/STM32F1xx/I2C/fake.c @@ -42,14 +42,17 @@ static i2cflags_t errors = 0; /* This is main function. */
void request_fake(void){
+ msg_t status = RDY_OK;
+ systime_t tmo = MS2ST(4);
i2cAcquireBus(&I2CD1);
- i2cMasterReceive(&I2CD1, addr, rx_data, 2, &errors, TIME_INFINITE);
+ status = i2cMasterReceiveTimeout(&I2CD1, addr, rx_data, 2, tmo);
i2cReleaseBus(&I2CD1);
- if (errors == I2CD_ACK_FAILURE){
- __NOP();
+ if (status != RDY_OK){
+ errors = i2cGetErrors(&I2CD1);
}
+
else{
temperature = (rx_data[0] << 8) + rx_data[1];
}
diff --git a/testhal/STM32F1xx/I2C/i2c_pns.c b/testhal/STM32F1xx/I2C/i2c_pns.c index 1c73482e3..b773846ba 100644 --- a/testhal/STM32F1xx/I2C/i2c_pns.c +++ b/testhal/STM32F1xx/I2C/i2c_pns.c @@ -45,7 +45,7 @@ void I2CInit_pns(void){ /* startups. Pauses added just to be safe */
chThdSleepMilliseconds(100);
- init_lis3();
+// init_lis3();
}
diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index 60cb1f3ae..760cee229 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -32,8 +32,9 @@ /*
* Red LEDs blinker thread, times are in milliseconds.
*/
-static WORKING_AREA(BlinkWA, 128);
+static WORKING_AREA(BlinkWA, 64);
static msg_t Blink(void *arg) {
+ chRegSetThreadName("Blink");
(void)arg;
while (TRUE) {
palClearPad(IOPORT3, GPIOC_LED);
@@ -47,21 +48,21 @@ static msg_t Blink(void *arg) { /*
* Accelerometer thread
*/
-static WORKING_AREA(PollAccelThreadWA, 128);
-static msg_t PollAccelThread(void *arg) {
- chRegSetThreadName("PollAccel");
- (void)arg;
- while (TRUE) {
-// chThdSleepMilliseconds(rand() & 31);
- chThdSleepMilliseconds(32);
- request_acceleration_data();
- }
- return 0;
-}
+//static WORKING_AREA(PollAccelThreadWA, 256);
+//static msg_t PollAccelThread(void *arg) {
+// chRegSetThreadName("PollAccel");
+// (void)arg;
+// while (TRUE) {
+//// chThdSleepMilliseconds(rand() & 31);
+// chThdSleepMilliseconds(32);
+// request_acceleration_data();
+// }
+// return 0;
+//}
/* Temperature polling thread */
-static WORKING_AREA(PollTmp75ThreadWA, 128);
+static WORKING_AREA(PollTmp75ThreadWA, 256);
static msg_t PollTmp75Thread(void *arg) {
chRegSetThreadName("PollTmp75");
(void)arg;
@@ -76,7 +77,7 @@ static msg_t PollTmp75Thread(void *arg) { /* Temperature polling thread */
-static WORKING_AREA(PollFakeThreadWA, 128);
+static WORKING_AREA(PollFakeThreadWA, 256);
static msg_t PollFakeThread(void *arg) {
chRegSetThreadName("PollFake");
(void)arg;
@@ -102,11 +103,11 @@ int main(void) { I2CInit_pns();
/* Create accelerometer thread */
- chThdCreateStatic(PollAccelThreadWA,
- sizeof(PollAccelThreadWA),
- NORMALPRIO,
- PollAccelThread,
- NULL);
+// chThdCreateStatic(PollAccelThreadWA,
+// sizeof(PollAccelThreadWA),
+// NORMALPRIO,
+// PollAccelThread,
+// NULL);
/* Create temperature thread */
chThdCreateStatic(PollTmp75ThreadWA,
diff --git a/testhal/STM32F1xx/I2C/tmp75.c b/testhal/STM32F1xx/I2C/tmp75.c index 23410843f..9d41e0a0f 100644 --- a/testhal/STM32F1xx/I2C/tmp75.c +++ b/testhal/STM32F1xx/I2C/tmp75.c @@ -45,11 +45,17 @@ static i2cflags_t errors = 0; /* This is main function. */
void request_temperature(void){
int16_t t_int = 0, t_frac = 0;
+ msg_t status = RDY_OK;
+ systime_t tmo = MS2ST(4);
i2cAcquireBus(&I2CD1);
- i2cMasterReceive(&I2CD1, tmp75_addr, tmp75_rx_data, 2, &errors, TIME_INFINITE);
+ status = i2cMasterReceiveTimeout(&I2CD1, tmp75_addr, tmp75_rx_data, 2, tmo);
i2cReleaseBus(&I2CD1);
+ if (status != RDY_OK){
+ errors = i2cGetErrors(&I2CD1);
+ }
+
t_int = tmp75_rx_data[0] * 100;
t_frac = (tmp75_rx_data[1] * 100) >> 8;
temperature = t_int + t_frac;
|