From 1253ee88be70e16fe9057b5e1727f8664fa0c4ae Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 6 Dec 2011 09:09:53 +0000 Subject: I2C. Testhal changed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3558 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F1xx/I2C/Makefile | 3 -- testhal/STM32F1xx/I2C/halconf.h | 9 +---- testhal/STM32F1xx/I2C/i2c_pns.c | 27 +-------------- testhal/STM32F1xx/I2C/lis3.c | 12 +++---- testhal/STM32F1xx/I2C/main.c | 56 ++---------------------------- testhal/STM32F1xx/I2C/max1236.c | 75 ----------------------------------------- testhal/STM32F1xx/I2C/max1236.h | 14 -------- testhal/STM32F1xx/I2C/mcuconf.h | 7 ---- testhal/STM32F1xx/I2C/tmp75.c | 52 ---------------------------- testhal/STM32F1xx/I2C/tmp75.h | 13 ------- 10 files changed, 11 insertions(+), 257 deletions(-) delete mode 100644 testhal/STM32F1xx/I2C/max1236.c delete mode 100644 testhal/STM32F1xx/I2C/max1236.h delete mode 100644 testhal/STM32F1xx/I2C/tmp75.c delete mode 100644 testhal/STM32F1xx/I2C/tmp75.h (limited to 'testhal') diff --git a/testhal/STM32F1xx/I2C/Makefile b/testhal/STM32F1xx/I2C/Makefile index dc2441200..f40f6f775 100644 --- a/testhal/STM32F1xx/I2C/Makefile +++ b/testhal/STM32F1xx/I2C/Makefile @@ -82,8 +82,6 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/syscalls.c \ main.c \ i2c_pns.c \ - tmp75.c\ - max1236.c\ lis3.c\ @@ -127,7 +125,6 @@ INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ # Compiler settings # -# -lm �������� ������ �����, ������ ��� ������ ������ MCU = cortex-m3 #TRGT = arm-elf- diff --git a/testhal/STM32F1xx/I2C/halconf.h b/testhal/STM32F1xx/I2C/halconf.h index 31d581932..3960a927c 100644 --- a/testhal/STM32F1xx/I2C/halconf.h +++ b/testhal/STM32F1xx/I2C/halconf.h @@ -192,7 +192,7 @@ * @note Disabling this option saves both code and data space. */ #if !defined(I2C_USE_WAIT) || defined(__DOXYGEN__) -#define I2C_USE_WAIT FALSE +#define I2C_USE_WAIT TRUE #endif /** @@ -202,13 +202,6 @@ #define I2C_USE_MUTUAL_EXCLUSION TRUE #endif -/** - * @brief Switch to asynchronouse driver with callbacks. - */ -#if !defined(I2C_SUPPORTS_CALLBACKS) || defined(__DOXYGEN__) -#define I2C_SUPPORTS_CALLBACKS TRUE -#endif - /*===========================================================================*/ /* MAC driver related settings. */ /*===========================================================================*/ diff --git a/testhal/STM32F1xx/I2C/i2c_pns.c b/testhal/STM32F1xx/I2C/i2c_pns.c index 44f4a8a33..fac6dc965 100644 --- a/testhal/STM32F1xx/I2C/i2c_pns.c +++ b/testhal/STM32F1xx/I2C/i2c_pns.c @@ -4,29 +4,12 @@ #include "i2c_pns.h" #include "lis3.h" -#include "tmp75.h" -#include "max1236.h" /* I2C1 */ static const I2CConfig i2cfg1 = { OPMODE_I2C, 100000, STD_DUTY_CYCLE, - 0, - 0, - 0, - 0, -}; - -/* I2C2 */ -static const I2CConfig i2cfg2 = { - OPMODE_I2C, - 100000, - STD_DUTY_CYCLE, - 0, - 0, - 0, - 0, }; @@ -35,22 +18,14 @@ void I2CInit_pns(void){ i2cInit(); i2cStart(&I2CD1, &i2cfg1); - i2cStart(&I2CD2, &i2cfg2); /* tune ports for I2C1*/ palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); palSetPadMode(IOPORT2, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); - /* tune ports for I2C2*/ - palSetPadMode(IOPORT2, 10, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); - palSetPadMode(IOPORT2, 11, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); - /* startups. Pauses added just to be safe */ - chThdSleepMilliseconds(1000); - init_max1236(); - chThdSleepMilliseconds(1000); + chThdSleepMilliseconds(100); init_lis3(); - chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32F1xx/I2C/lis3.c b/testhal/STM32F1xx/I2C/lis3.c index 401f56199..2300ea5cb 100644 --- a/testhal/STM32F1xx/I2C/lis3.c +++ b/testhal/STM32F1xx/I2C/lis3.c @@ -18,8 +18,8 @@ /* buffers */ -static i2cblock_t accel_rx_data[ACCEL_RX_DEPTH]; -static i2cblock_t accel_tx_data[ACCEL_TX_DEPTH]; +static uint8_t accel_rx_data[ACCEL_RX_DEPTH]; +static uint8_t accel_tx_data[ACCEL_TX_DEPTH]; static int16_t acceleration_x = 0; static int16_t acceleration_y = 0; @@ -42,8 +42,8 @@ static void i2c_lis3_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ /* Accelerometer lis3lv02dq config */ static const I2CSlaveConfig lis3 = { - i2c_lis3_cb, - i2c_lis3_error_cb, + i2c_lis3_cb, + i2c_lis3_error_cb, }; @@ -67,9 +67,9 @@ int init_lis3(void){ */ void request_acceleration_data(void){ accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address - //i2cAcquireBus(&I2CD1); + i2cAcquireBus(&I2CD1); i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 1, accel_rx_data, 6); - //i2cReleaseBus(&I2CD1); + i2cReleaseBus(&I2CD1); acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8); acceleration_y = accel_rx_data[2] + (accel_rx_data[3] << 8); diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index b828953c5..bc241e180 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -17,14 +17,10 @@ * amount of time. */ -#include - #include "ch.h" #include "hal.h" #include "i2c_pns.h" -#include "tmp75.h" -#include "max1236.h" #include "lis3.h" @@ -44,39 +40,9 @@ static msg_t Blink(void *arg) { return 0; } - - -/* Temperature polling thread */ -static WORKING_AREA(PollTmp75ThreadWA, 128); -static msg_t PollTmp75Thread(void *arg) { - (void)arg; - systime_t time = chTimeNow(); - - while (TRUE) { - time += MS2ST(1001); - /* Call reading function */ - request_temperature(); - chThdSleepUntil(time); - } - return 0; -} - -/* MAX1236 polling thread */ -static WORKING_AREA(PollMax1236ThreadWA, 128); -static msg_t PollMax1236Thread(void *arg) { - (void)arg; - systime_t time = chTimeNow(); - - while (TRUE) { - time += MS2ST(200); - /* Call reading function */ - read_max1236(); - chThdSleepUntil(time); - } - return 0; -} - - +/* + * Accelerometer thread + */ static WORKING_AREA(PollAccelThreadWA, 128); static msg_t PollAccelThread(void *arg) { (void)arg; @@ -104,22 +70,6 @@ int main(void) { I2CInit_pns(); - /* Create temperature thread */ - chThdCreateStatic(PollTmp75ThreadWA, - sizeof(PollTmp75ThreadWA), - NORMALPRIO, - PollTmp75Thread, - NULL); - - - /* Create max1236 thread */ - chThdCreateStatic(PollMax1236ThreadWA, - sizeof(PollMax1236ThreadWA), - NORMALPRIO, - PollMax1236Thread, - NULL); - - /* Create accelerometer thread */ chThdCreateStatic(PollAccelThreadWA, sizeof(PollAccelThreadWA), diff --git a/testhal/STM32F1xx/I2C/max1236.c b/testhal/STM32F1xx/I2C/max1236.c deleted file mode 100644 index 09e2c8b35..000000000 --- a/testhal/STM32F1xx/I2C/max1236.c +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Maxim ADC has not so suitable default settings after startup. - * So we will create init function to tune this ADC. - */ - -#include - -#include "ch.h" -#include "hal.h" - -#include "max1236.h" - - -#define max1236_addr 0b0110100 - - -/* Data buffers */ -static i2cblock_t max1236_rx_data[MAX1236_RX_DEPTH]; -static i2cblock_t max1236_tx_data[MAX1236_TX_DEPTH]; -/* ADC results */ -static uint16_t ch1 = 0, ch2 = 0, ch3 = 0, ch4 = 0; - - -/* Error trap */ -static void i2c_max1236_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)i2cscfg; - int status = 0; - status = i2cp->id_i2c->SR1; - while(TRUE); -} - - -/* This callback raise up when transfer finished */ -static void i2c_max1236_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)*i2cp; - (void)*i2cscfg; - /* get ADC data */ -} - - -/* ADC maxim MAX1236 config */ - -static const I2CSlaveConfig max1236 = { - i2c_max1236_cb, - i2c_max1236_error_cb, -}; - - -/** - * Initilization routine. See datasheet on page 13 to understand - * how to initialize ADC. - */ -void init_max1236(void){ - /* this data we must send via IC to setup ADC */ - max1236_tx_data[0] = 0b10000011; /* config register content. Consult datasheet */ - max1236_tx_data[1] = 0b00000111; /* config register content. Consult datasheet */ - - /* transmit out 2 bytes */ - i2cAcquireBus(&I2CD2); - i2cMasterTransmit(&I2CD2, &max1236, max1236_addr, max1236_tx_data, 2, max1236_rx_data, 0); - i2cReleaseBus(&I2CD2); -} - - -/* Now simply read 8 bytes to get all 4 ADC channels */ -void read_max1236(void){ - i2cAcquireBus(&I2CD2); - i2cMasterReceive(&I2CD2, &max1236, max1236_addr, max1236_rx_data, 8); - i2cReleaseBus(&I2CD2); - - ch1 = ((max1236_rx_data[0] & 0xF) << 8) + max1236_rx_data[1]; - ch2 = ((max1236_rx_data[2] & 0xF) << 8) + max1236_rx_data[3]; - ch3 = ((max1236_rx_data[4] & 0xF) << 8) + max1236_rx_data[5]; - ch4 = ((max1236_rx_data[6] & 0xF) << 8) + max1236_rx_data[7]; -} diff --git a/testhal/STM32F1xx/I2C/max1236.h b/testhal/STM32F1xx/I2C/max1236.h deleted file mode 100644 index aff466cf4..000000000 --- a/testhal/STM32F1xx/I2C/max1236.h +++ /dev/null @@ -1,14 +0,0 @@ -#include "ch.h" - -#ifndef MAX1236_H_ -#define MAX1236_H_ - - -#define MAX1236_RX_DEPTH 8 -#define MAX1236_TX_DEPTH 2 - - -void init_max1236(void); -void read_max1236(void); - -#endif /* MAX1236_H_ */ diff --git a/testhal/STM32F1xx/I2C/mcuconf.h b/testhal/STM32F1xx/I2C/mcuconf.h index 6afc97f28..b333e2ce6 100644 --- a/testhal/STM32F1xx/I2C/mcuconf.h +++ b/testhal/STM32F1xx/I2C/mcuconf.h @@ -174,13 +174,6 @@ #define STM32_I2C_I2C2_DMA_PRIORITY 4 #define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt() #define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt() -/* I2C1 */ -#define STM32_I2C_I2C1_USE_GPT_TIM GPTD1 -#define STM32_I2C_I2C1_USE_POLLING_WAIT TRUE -/* I2C2 */ -#define STM32_I2C_I2C2_USE_GPT_TIM GPTD2 -#define STM32_I2C_I2C2_USE_POLLING_WAIT TRUE - /* * USB driver system settings. diff --git a/testhal/STM32F1xx/I2C/tmp75.c b/testhal/STM32F1xx/I2C/tmp75.c deleted file mode 100644 index 72e634527..000000000 --- a/testhal/STM32F1xx/I2C/tmp75.c +++ /dev/null @@ -1,52 +0,0 @@ -/** - * TMP75 is most simple I2C device in our case. It is already useful with - * default settings after powerup. - * You only must read 2 sequential bytes from it. - */ - -#include - -#include "ch.h" -#include "hal.h" - -#include "tmp75.h" - - -/* input buffer */ -static i2cblock_t tmp75_rx_data[TMP75_RX_DEPTH]; - -/* temperature value */ -static int16_t temperature = 0; - -/* Simple error trap */ -static void i2c_tmp75_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)i2cscfg; - int status = 0; - status = i2cp->id_i2c->SR1; - while(TRUE); -} - -/* This callback raise up when transfer finished */ -static void i2c_tmp75_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)*i2cp; - (void)*i2cscfg; - /* store temperature value */ -} - -/* Fill TMP75 config. */ -static const I2CSlaveConfig tmp75 = { - i2c_tmp75_cb, - i2c_tmp75_error_cb, -}; - -#define tmp75_addr 0b1001000 - -/* This is main function. */ -void request_temperature(void){ - i2cAcquireBus(&I2CD2); - i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, tmp75_rx_data, 2); - i2cReleaseBus(&I2CD2); - temperature = (tmp75_rx_data[0] << 8) + tmp75_rx_data[1]; -} - - diff --git a/testhal/STM32F1xx/I2C/tmp75.h b/testhal/STM32F1xx/I2C/tmp75.h deleted file mode 100644 index ab4b5fa9b..000000000 --- a/testhal/STM32F1xx/I2C/tmp75.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TMP75_H_ -#define TMP75_H_ - - - -/* buffers depth */ -#define TMP75_RX_DEPTH 2 -#define TMP75_TX_DEPTH 2 - -void init_tmp75(void); -void request_temperature(void); - -#endif /* TMP75_H_ */ -- cgit v1.2.3 From 60e97e1c62c615c9e07042ec20fc8d354245aba9 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 6 Dec 2011 13:38:47 +0000 Subject: I2C. Haltest for stm32f1x updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3560 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F1xx/I2C/Makefile | 4 ++-- testhal/STM32F1xx/I2C/halconf.h | 6 +++--- testhal/STM32F1xx/I2C/i2c_pns.c | 4 ++-- testhal/STM32F1xx/I2C/lis3.c | 2 ++ testhal/STM32F1xx/I2C/main.c | 1 + testhal/STM32F1xx/I2C/mcuconf.h | 18 +++++++++--------- 6 files changed, 19 insertions(+), 16 deletions(-) (limited to 'testhal') diff --git a/testhal/STM32F1xx/I2C/Makefile b/testhal/STM32F1xx/I2C/Makefile index f40f6f775..37db54251 100644 --- a/testhal/STM32F1xx/I2C/Makefile +++ b/testhal/STM32F1xx/I2C/Makefile @@ -31,7 +31,7 @@ endif # Enable this if you want to see the full log while compiling. ifeq ($(USE_VERBOSE_COMPILE),) - USE_VERBOSE_COMPILE = no + USE_VERBOSE_COMPILE = yes endif # @@ -63,7 +63,7 @@ LDSCRIPT= $(PORTLD)/STM32F103xB.ld # Imported source files CHIBIOS = ../../.. -include $(CHIBIOS)/boards/OLIMEX_STM32_P103/board.mk +include $(CHIBIOS)/boards/OLIMEX_STM32_103STK/board.mk include $(CHIBIOS)/os/hal/platforms/STM32F1xx/platform.mk include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F1xx/port.mk diff --git a/testhal/STM32F1xx/I2C/halconf.h b/testhal/STM32F1xx/I2C/halconf.h index 3960a927c..54a69c2f7 100644 --- a/testhal/STM32F1xx/I2C/halconf.h +++ b/testhal/STM32F1xx/I2C/halconf.h @@ -44,7 +44,7 @@ * @brief Enables the ADC subsystem. */ #if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) -#define HAL_USE_ADC TRUE +#define HAL_USE_ADC FALSE #endif /** @@ -100,7 +100,7 @@ * @brief Enables the PWM subsystem. */ #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) -#define HAL_USE_PWM TRUE +#define HAL_USE_PWM FALSE #endif /** @@ -121,7 +121,7 @@ * @brief Enables the SERIAL subsystem. */ #if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL TRUE +#define HAL_USE_SERIAL FALSE #endif /** diff --git a/testhal/STM32F1xx/I2C/i2c_pns.c b/testhal/STM32F1xx/I2C/i2c_pns.c index fac6dc965..95218b583 100644 --- a/testhal/STM32F1xx/I2C/i2c_pns.c +++ b/testhal/STM32F1xx/I2C/i2c_pns.c @@ -8,8 +8,8 @@ /* I2C1 */ static const I2CConfig i2cfg1 = { OPMODE_I2C, - 100000, - STD_DUTY_CYCLE, + 400000, + FAST_DUTY_CYCLE_16_9, }; diff --git a/testhal/STM32F1xx/I2C/lis3.c b/testhal/STM32F1xx/I2C/lis3.c index 2300ea5cb..0cd42a02f 100644 --- a/testhal/STM32F1xx/I2C/lis3.c +++ b/testhal/STM32F1xx/I2C/lis3.c @@ -58,7 +58,9 @@ int init_lis3(void){ accel_tx_data[3] = 0b00000000; /* sending */ + i2cAcquireBus(&I2CD1); i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 4, accel_rx_data, 0); + i2cReleaseBus(&I2CD1); return 0; } diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index bc241e180..3179c488a 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -68,6 +68,7 @@ int main(void) { halInit(); chSysInit(); + chThdSleepMilliseconds(1000); I2CInit_pns(); /* Create accelerometer thread */ diff --git a/testhal/STM32F1xx/I2C/mcuconf.h b/testhal/STM32F1xx/I2C/mcuconf.h index b333e2ce6..dc4d3960c 100644 --- a/testhal/STM32F1xx/I2C/mcuconf.h +++ b/testhal/STM32F1xx/I2C/mcuconf.h @@ -47,7 +47,7 @@ /* * ADC driver system settings. */ -#define STM32_ADC_USE_ADC1 TRUE +#define STM32_ADC_USE_ADC1 FALSE #define STM32_ADC_ADC1_DMA_PRIORITY 3 #define STM32_ADC_ADC1_IRQ_PRIORITY 5 #define STM32_ADC_ADC1_DMA_ERROR_HOOK() chSysHalt() @@ -122,8 +122,8 @@ /* * SERIAL driver system settings. */ -#define STM32_SERIAL_USE_USART1 TRUE -#define STM32_SERIAL_USE_USART2 TRUE +#define STM32_SERIAL_USE_USART1 FALSE +#define STM32_SERIAL_USE_USART2 FALSE #define STM32_SERIAL_USE_USART3 FALSE #define STM32_SERIAL_USE_UART4 FALSE #define STM32_SERIAL_USE_UART5 FALSE @@ -138,8 +138,8 @@ /* * SPI driver system settings. */ -#define STM32_SPI_USE_SPI1 TRUE -#define STM32_SPI_USE_SPI2 TRUE +#define STM32_SPI_USE_SPI1 FALSE +#define STM32_SPI_USE_SPI2 FALSE #define STM32_SPI_USE_SPI3 FALSE #define STM32_SPI_SPI1_DMA_PRIORITY 1 #define STM32_SPI_SPI2_DMA_PRIORITY 1 @@ -167,18 +167,18 @@ * I2C driver system settings. */ #define STM32_I2C_USE_I2C1 TRUE -#define STM32_I2C_USE_I2C2 TRUE +#define STM32_I2C_USE_I2C2 FALSE #define STM32_I2C_I2C1_IRQ_PRIORITY 10 #define STM32_I2C_I2C2_IRQ_PRIORITY 10 -#define STM32_I2C_I2C1_DMA_PRIORITY 4 -#define STM32_I2C_I2C2_DMA_PRIORITY 4 +#define STM32_I2C_I2C1_DMA_PRIORITY 1 +#define STM32_I2C_I2C2_DMA_PRIORITY 1 #define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt() #define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt() /* * USB driver system settings. */ -#define STM32_USB_USE_USB1 TRUE +#define STM32_USB_USE_USB1 FALSE #define STM32_USB_LOW_POWER_ON_SUSPEND FALSE #define STM32_USB_USB1_HP_IRQ_PRIORITY 6 #define STM32_USB_USB1_LP_IRQ_PRIORITY 14 -- cgit v1.2.3 From b9df6d7c801d711fda3d83cd9a2eb7b456f60276 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 17:58:42 +0000 Subject: I2C. Testhal switch to synchronous driver model. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3571 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F1xx/I2C/lis3.c | 25 ++----------------------- testhal/STM32F1xx/I2C/main.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 23 deletions(-) (limited to 'testhal') diff --git a/testhal/STM32F1xx/I2C/lis3.c b/testhal/STM32F1xx/I2C/lis3.c index 0cd42a02f..d52d526e2 100644 --- a/testhal/STM32F1xx/I2C/lis3.c +++ b/testhal/STM32F1xx/I2C/lis3.c @@ -25,27 +25,6 @@ static int16_t acceleration_x = 0; static int16_t acceleration_y = 0; static int16_t acceleration_z = 0; -/* Error trap */ -static void i2c_lis3_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)i2cscfg; - int status = 0; - status = i2cp->id_i2c->SR1; - while(TRUE); -} - -/* This callback raise up when transfer finished */ -static void i2c_lis3_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)i2cp; - (void)i2cscfg; -} - - -/* Accelerometer lis3lv02dq config */ -static const I2CSlaveConfig lis3 = { - i2c_lis3_cb, - i2c_lis3_error_cb, -}; - /** * Init function. Here we will also start personal serving thread. @@ -59,7 +38,7 @@ int init_lis3(void){ /* sending */ i2cAcquireBus(&I2CD1); - i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 4, accel_rx_data, 0); + i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 4, accel_rx_data, 0); i2cReleaseBus(&I2CD1); return 0; } @@ -70,7 +49,7 @@ int init_lis3(void){ void request_acceleration_data(void){ accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address i2cAcquireBus(&I2CD1); - i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 1, accel_rx_data, 6); + i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 1, accel_rx_data, 6); i2cReleaseBus(&I2CD1); acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8); diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index 3179c488a..ae1bea5af 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -57,6 +57,22 @@ static msg_t PollAccelThread(void *arg) { } +/* + * Accelerometer thread + */ +static WORKING_AREA(PollAccelThreadWA, 128); +static msg_t PollAccelThread(void *arg) { + (void)arg; + systime_t time = chTimeNow(); + + while (TRUE) { + time += MS2ST(20); + request_acceleration_data(); + chThdSleepUntil(time); + } + return 0; +} + /* -- cgit v1.2.3 From 2fbafd292a430fef8a16bc0c8cbe53e1a6a53bd0 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 19:26:30 +0000 Subject: I2C. Testhal updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3573 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F1xx/I2C/Makefile | 4 ++- testhal/STM32F1xx/I2C/fake.c | 38 +++++++++++++++++++++++++ testhal/STM32F1xx/I2C/fake.h | 6 ++++ testhal/STM32F1xx/I2C/main.c | 63 ++++++++++++++++++++++++++++++------------ testhal/STM32F1xx/I2C/tmp75.c | 37 +++++++++++++++++++++++++ testhal/STM32F1xx/I2C/tmp75.h | 13 +++++++++ 6 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 testhal/STM32F1xx/I2C/fake.c create mode 100644 testhal/STM32F1xx/I2C/fake.h create mode 100644 testhal/STM32F1xx/I2C/tmp75.c create mode 100644 testhal/STM32F1xx/I2C/tmp75.h (limited to 'testhal') diff --git a/testhal/STM32F1xx/I2C/Makefile b/testhal/STM32F1xx/I2C/Makefile index 37db54251..08494928a 100644 --- a/testhal/STM32F1xx/I2C/Makefile +++ b/testhal/STM32F1xx/I2C/Makefile @@ -82,7 +82,9 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/syscalls.c \ main.c \ i2c_pns.c \ - lis3.c\ + lis3.c \ + tmp75.c \ + fake.c diff --git a/testhal/STM32F1xx/I2C/fake.c b/testhal/STM32F1xx/I2C/fake.c new file mode 100644 index 000000000..75f242207 --- /dev/null +++ b/testhal/STM32F1xx/I2C/fake.c @@ -0,0 +1,38 @@ +/** + * Not responding slave test + */ + +#include + +#include "ch.h" +#include "hal.h" + +#include "fake.h" + + +/* input buffer */ +static uint8_t rx_data[2]; + +/* temperature value */ +static int16_t temperature = 0; + + +#define addr 0b1001100 + +/* This is main function. */ +void request_fake(void){ + i2cflags_t errors = 0; + + i2cAcquireBus(&I2CD1); + errors = i2cMasterReceive(&I2CD1, addr, rx_data, 2); + i2cReleaseBus(&I2CD1); + + if (errors == I2CD_ACK_FAILURE){ + __NOP(); + } + else{ + temperature = (rx_data[0] << 8) + rx_data[1]; + } +} + + diff --git a/testhal/STM32F1xx/I2C/fake.h b/testhal/STM32F1xx/I2C/fake.h new file mode 100644 index 000000000..a83652e29 --- /dev/null +++ b/testhal/STM32F1xx/I2C/fake.h @@ -0,0 +1,6 @@ +#ifndef FAKE_H_ +#define FAKE_H_ + +void request_fake(void); + +#endif /* FAKE_H_ */ diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index ae1bea5af..0ca040e88 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -17,12 +17,15 @@ * amount of time. */ +#include + #include "ch.h" #include "hal.h" #include "i2c_pns.h" #include "lis3.h" - +#include "tmp75.h" +#include "fake.h" /* @@ -45,35 +48,45 @@ static msg_t Blink(void *arg) { */ static WORKING_AREA(PollAccelThreadWA, 128); static msg_t PollAccelThread(void *arg) { + chRegSetThreadName("PollAccel"); (void)arg; - systime_t time = chTimeNow(); - while (TRUE) { - time += MS2ST(20); +// chThdSleepMilliseconds(rand() & 31); + chThdSleepMilliseconds(32); request_acceleration_data(); - chThdSleepUntil(time); } return 0; } -/* - * Accelerometer thread - */ -static WORKING_AREA(PollAccelThreadWA, 128); -static msg_t PollAccelThread(void *arg) { +/* Temperature polling thread */ +static WORKING_AREA(PollTmp75ThreadWA, 128); +static msg_t PollTmp75Thread(void *arg) { + chRegSetThreadName("PollTmp75"); (void)arg; - systime_t time = chTimeNow(); - while (TRUE) { - time += MS2ST(20); - request_acceleration_data(); - chThdSleepUntil(time); +// chThdSleepMilliseconds(rand() & 31); + chThdSleepMilliseconds(15); + /* Call reading function */ + request_temperature(); } return 0; } +/* Temperature polling thread */ +static WORKING_AREA(PollFakeThreadWA, 128); +static msg_t PollFakeThread(void *arg) { + chRegSetThreadName("PollFake"); + (void)arg; + while (TRUE) { + chThdSleepMilliseconds(16); + /* Call reading function */ + request_fake(); + } + return 0; +} + /* * Entry point, note, the main() function is already a thread in the system @@ -84,18 +97,32 @@ int main(void) { halInit(); chSysInit(); - chThdSleepMilliseconds(1000); + chThdSleepMilliseconds(200); I2CInit_pns(); /* Create accelerometer thread */ chThdCreateStatic(PollAccelThreadWA, sizeof(PollAccelThreadWA), - HIGHPRIO, + NORMALPRIO, PollAccelThread, NULL); + /* Create temperature thread */ + chThdCreateStatic(PollTmp75ThreadWA, + sizeof(PollTmp75ThreadWA), + NORMALPRIO, + PollTmp75Thread, + NULL); + + /* Create not responding thread */ + chThdCreateStatic(PollFakeThreadWA, + sizeof(PollFakeThreadWA), + NORMALPRIO, + PollFakeThread, + NULL); + /* Creates the blinker thread. */ - chThdCreateStatic(BlinkWA, sizeof(BlinkWA), LOWPRIO, Blink, NULL); + chThdCreateStatic(BlinkWA, sizeof(BlinkWA), HIGHPRIO, Blink, NULL); /* main loop that do nothing */ while (TRUE) { diff --git a/testhal/STM32F1xx/I2C/tmp75.c b/testhal/STM32F1xx/I2C/tmp75.c new file mode 100644 index 000000000..7acc8c668 --- /dev/null +++ b/testhal/STM32F1xx/I2C/tmp75.c @@ -0,0 +1,37 @@ +/** + * TMP75 is most simple I2C device in our case. It is already useful with + * default settings after powerup. + * You only must read 2 sequential bytes from it. + */ + +#include + +#include "ch.h" +#include "hal.h" + +#include "tmp75.h" + + +/* input buffer */ +static uint8_t tmp75_rx_data[TMP75_RX_DEPTH]; + +/* temperature value */ +static int16_t temperature = 0; + + +#define tmp75_addr 0b1001000 + +/* This is main function. */ +void request_temperature(void){ + int16_t t_int = 0, t_frac = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterReceive(&I2CD1, tmp75_addr, tmp75_rx_data, 2); + i2cReleaseBus(&I2CD1); + + t_int = tmp75_rx_data[0] * 100; + t_frac = (tmp75_rx_data[1] * 100) >> 8; + temperature = t_int + t_frac; +} + + diff --git a/testhal/STM32F1xx/I2C/tmp75.h b/testhal/STM32F1xx/I2C/tmp75.h new file mode 100644 index 000000000..ab4b5fa9b --- /dev/null +++ b/testhal/STM32F1xx/I2C/tmp75.h @@ -0,0 +1,13 @@ +#ifndef TMP75_H_ +#define TMP75_H_ + + + +/* buffers depth */ +#define TMP75_RX_DEPTH 2 +#define TMP75_TX_DEPTH 2 + +void init_tmp75(void); +void request_temperature(void); + +#endif /* TMP75_H_ */ -- cgit v1.2.3 From f1d3f298955eec396bcc1e791f3e6fbbb6c4c3e0 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 20:15:19 +0000 Subject: I2C. F1x testhal clean ups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3575 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F1xx/I2C/fake.c | 20 ++++++++++++++++++++ testhal/STM32F1xx/I2C/fake.h | 20 ++++++++++++++++++++ testhal/STM32F1xx/I2C/i2c_pns.c | 22 +++++++++++++++++++++- testhal/STM32F1xx/I2C/i2c_pns.h | 20 ++++++++++++++++++++ testhal/STM32F1xx/I2C/lis3.c | 25 ++++++++++++++++++++++--- testhal/STM32F1xx/I2C/lis3.h | 20 ++++++++++++++++++++ testhal/STM32F1xx/I2C/main.c | 37 +++++++++++++++++++------------------ testhal/STM32F1xx/I2C/main.h | 19 ------------------- testhal/STM32F1xx/I2C/tmp75.c | 20 ++++++++++++++++++++ testhal/STM32F1xx/I2C/tmp75.h | 20 ++++++++++++++++++++ 10 files changed, 182 insertions(+), 41 deletions(-) delete mode 100644 testhal/STM32F1xx/I2C/main.h (limited to 'testhal') diff --git a/testhal/STM32F1xx/I2C/fake.c b/testhal/STM32F1xx/I2C/fake.c index 75f242207..53779893e 100644 --- a/testhal/STM32F1xx/I2C/fake.c +++ b/testhal/STM32F1xx/I2C/fake.c @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * Not responding slave test */ diff --git a/testhal/STM32F1xx/I2C/fake.h b/testhal/STM32F1xx/I2C/fake.h index a83652e29..04f4206bf 100644 --- a/testhal/STM32F1xx/I2C/fake.h +++ b/testhal/STM32F1xx/I2C/fake.h @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #ifndef FAKE_H_ #define FAKE_H_ diff --git a/testhal/STM32F1xx/I2C/i2c_pns.c b/testhal/STM32F1xx/I2C/i2c_pns.c index 95218b583..1c73482e3 100644 --- a/testhal/STM32F1xx/I2C/i2c_pns.c +++ b/testhal/STM32F1xx/I2C/i2c_pns.c @@ -1,10 +1,30 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #include "ch.h" #include "hal.h" #include "i2c_pns.h" - #include "lis3.h" + /* I2C1 */ static const I2CConfig i2cfg1 = { OPMODE_I2C, diff --git a/testhal/STM32F1xx/I2C/i2c_pns.h b/testhal/STM32F1xx/I2C/i2c_pns.h index 4dfdf320e..dae359ecf 100644 --- a/testhal/STM32F1xx/I2C/i2c_pns.h +++ b/testhal/STM32F1xx/I2C/i2c_pns.h @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #ifndef I2C_PNS_H_ #define I2C_PNS_H_ diff --git a/testhal/STM32F1xx/I2C/lis3.c b/testhal/STM32F1xx/I2C/lis3.c index d52d526e2..d3369ac82 100644 --- a/testhal/STM32F1xx/I2C/lis3.c +++ b/testhal/STM32F1xx/I2C/lis3.c @@ -1,7 +1,26 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** - * This is most complex and difficult device. - * It realize "read through write" paradigm. This is not standard, but - * most of I2C devices use this paradigm. + * This is device realize "read through write" paradigm. This is not + * standard, but most of I2C devices use this paradigm. * You must write to device reading address, send restart to bus, * and then begin reading process. */ diff --git a/testhal/STM32F1xx/I2C/lis3.h b/testhal/STM32F1xx/I2C/lis3.h index e50359bde..0c2eefa5d 100644 --- a/testhal/STM32F1xx/I2C/lis3.h +++ b/testhal/STM32F1xx/I2C/lis3.h @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #include #include "ch.h" diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index 0ca040e88..60cb1f3ae 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -1,21 +1,22 @@ -/** - * Lets imagine that we have board with LIS3LV02DL accelerometer on channel #1 - * and MAX1236 ADC, TMP75 thermometer on channel #2. - * - * NOTE: I assume, that you have datasheets on all this stuff. - * - * NOTE: Also, I assume, that you know how to I2C works. - * - * In order from simplicity to complexity: - * TMP75 - * MAX1236 - * LIS3LV02DL - * - * Project splitted to separate source files for each device. - * - * Data from sensors we will be read from different thread sleeping different - * amount of time. - */ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include diff --git a/testhal/STM32F1xx/I2C/main.h b/testhal/STM32F1xx/I2C/main.h deleted file mode 100644 index 1435a05e5..000000000 --- a/testhal/STM32F1xx/I2C/main.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * main.h - * - * Created on: 25.03.2011 - * Author: barthess - */ - -#ifndef MAIN_H_ -#define MAIN_H_ - - -// ãëîáàëüíûå ôëàãè -#define GET_FILTERED_RAW_GYRO TRUE -#define GET_FILTERED_RAW_ACCEL TRUE - - - - -#endif /* MAIN_H_ */ diff --git a/testhal/STM32F1xx/I2C/tmp75.c b/testhal/STM32F1xx/I2C/tmp75.c index 7acc8c668..630a76dac 100644 --- a/testhal/STM32F1xx/I2C/tmp75.c +++ b/testhal/STM32F1xx/I2C/tmp75.c @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * TMP75 is most simple I2C device in our case. It is already useful with * default settings after powerup. diff --git a/testhal/STM32F1xx/I2C/tmp75.h b/testhal/STM32F1xx/I2C/tmp75.h index ab4b5fa9b..13648b154 100644 --- a/testhal/STM32F1xx/I2C/tmp75.h +++ b/testhal/STM32F1xx/I2C/tmp75.h @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #ifndef TMP75_H_ #define TMP75_H_ -- cgit v1.2.3