[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-233-gb795039
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-03-10 18:12:28
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via b795039a39ad4b3470d1ef7eb7c30610edb12d32 (commit)
via 2254dc3452203ef6042a1dec1fe29b843bff9d7b (commit)
via d66207896d59250512335867d75d839609ea7d7a (commit)
from c42c8e2da1c3197b381ac1ddd36afd5f26d51f33 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b795039a39ad4b3470d1ef7eb7c30610edb12d32
Merge: 2254dc3452203ef6042a1dec1fe29b843bff9d7b c42c8e2da1c3197b381ac1ddd36afd5f26d51f33
Author: Fabien Marteau <fab...@ar...>
Date: Wed Mar 10 19:11:36 2010 +0100
Merge branch 'master' of ssh://fabm@armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 2254dc3452203ef6042a1dec1fe29b843bff9d7b
Author: Fabien Marteau <fab...@ar...>
Date: Wed Mar 10 19:09:14 2010 +0100
[asdevices] Adding test for max1027
commit d66207896d59250512335867d75d839609ea7d7a
Author: Fabien Marteau <fab...@ar...>
Date: Wed Mar 10 14:25:14 2010 +0100
[as_devices] fix makefile platform variable
-----------------------------------------------------------------------
Summary of changes:
.../package/armadeus/as_devices/as_devices.mk | 3 +-
target/packages/as_devices/c/Makefile | 17 +-
target/packages/as_devices/c/as_max1027.c | 197 +++++++++++++++++++-
target/packages/as_devices/c/as_max1027.h | 51 ++++-
target/packages/as_devices/main.c | 3 +
target/packages/as_devices/test_c.h | 101 ++++++++++-
6 files changed, 351 insertions(+), 21 deletions(-)
diff --git a/buildroot/package/armadeus/as_devices/as_devices.mk b/buildroot/package/armadeus/as_devices/as_devices.mk
index d1adee1..714161d 100644
--- a/buildroot/package/armadeus/as_devices/as_devices.mk
+++ b/buildroot/package/armadeus/as_devices/as_devices.mk
@@ -42,7 +42,8 @@ $(AS_DEVICES_DIR)/Makefile:
# Compile as_devices library using the makefile
$(AS_DEVICES_DIR)/c/$(AS_DEVICES_BINARY): $(AS_DEVICES_DIR)/Makefile
- $(TARGET_CONFIGURE_OPTS) $(MAKE) CC=$(TARGET_CC) -C $(AS_DEVICES_DIR)/c
+ #XXX: BR2_TARGET_UBOOT_BOARDNAME is wrong, to be fixed
+ $(TARGET_CONFIGURE_OPTS) $(MAKE) CC=$(TARGET_CC) -C $(AS_DEVICES_DIR)/c ARMADEUS_BOARD_NAME=$(BR2_TARGET_UBOOT_BOARDNAME)
# install library on target
$(TARGET_DIR)/$(AS_DEVICES_TARGET_BINARY): $(AS_DEVICES_DIR)/c/$(AS_DEVICES_BINARY)
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index 6ab4854..bf59fa8 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -1,20 +1,25 @@
# Default values for local compiling:
#
+ifeq ($(KERNEL_INCLUDE),)
ARMADEUS_BASE_DIR=../../../../
include $(ARMADEUS_BASE_DIR)/Makefile.in
+KERNEL_INCLUDE=$(ARMADEUS_LINUX_DIR)/include/
+CFLAGS+= -Wall -g -O0
+CFLAGS+= -I$(KERNEL_INCLUDE)
+endif
+
+LDFLAGS=
+CC:=$(ARMADEUS_TOOLCHAIN_PATH)/arm-linux-gcc
+STRIP:=$(ARMADEUS_TOOLCHAIN_PATH)arm-linux-sstrip
ifeq ($(ARMADEUS_BOARD_NAME),apf9328)
-CFLAGS=-Wall -g -O0 -DAPF9328
+CFLAGS+= -DAPF9328
endif
ifeq ($(ARMADEUS_BOARD_NAME),apf27)
-CFLAGS=-Wall -g -O0 -DAPF27
+CFLAGS+= -DAPF27
endif
-LDFLAGS=
-CC:=$(ARMADEUS_TOOLCHAIN_PATH)/arm-linux-gcc
-STRIP:=$(ARMADEUS_TOOLCHAIN_PATH)arm-linux-sstrip
-
OBJ=as_pwm.o
OBJ+= as_i2c.o
OBJ+= as_gpio.o
diff --git a/target/packages/as_devices/c/as_max1027.c b/target/packages/as_devices/c/as_max1027.c
index b243188..2ea9d14 100644
--- a/target/packages/as_devices/c/as_max1027.c
+++ b/target/packages/as_devices/c/as_max1027.c
@@ -3,26 +3,217 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
- *
+ *
* This library 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
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
- * Copyright (C) 2010 Fabien Marteau <fab...@ar...>
+ * Copyright (C) 2010 Fabien Marteau <fab...@ar...>
*
*/
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+
+///XXX: find where u8 is defined under linux
+typedef unsigned char u8;
+#include <linux/spi/max1027.h>
#include "as_max1027.h"
+#define BUFFER_SIZE (70)
+#define PATH_SIZE (50)
+#define SYS_PATH "/sys/bus/spi/devices/spi%d.0/"
+#define TEMP_NAME "temp1_input"
+#define SLOW_INPUT_NAME "in%d_input"
+#define FAST_INPUT_PATH "/dev/max1027/AIN%d"
+
+int32_t as_max1027_write_buffer(int aFile_handler, int aValue)
+{
+ int ret;
+ char buffer[50];
+ int buffer_len;
+
+ ret = snprintf(buffer, 50, "%d", aValue);
+ if (ret < 0)
+ return -1;
+ buffer_len = strlen(buffer);
+ ret = write(aFile_handler, buffer, buffer_len);
+ if (ret < 0)
+ {
+ perror("Can't write file ");
+ return -1;
+ }
+ ret = lseek(aFile_handler,0,SEEK_SET);
+ if (ret < 0)
+ {
+ perror("lseek error ");
+ return -1;
+ }
+
+ return buffer_len;
+}
+
+struct as_max1027_device *as_max1027_open(int aSpiNum,
+ AS_max1027_mode aMode)
+{
+ struct as_max1027_device *dev;
+ int i;
+ int fConversion, fSetup, fAveraging;
+ int fTemperature;
+ int fLowSpeed[8];
+ int fHighSpeed[8];
+ char path[PATH_SIZE];
+ char buffer[BUFFER_SIZE];
+ char slow_input_name[20];
+ int ret;
+
+ ret = snprintf(path, PATH_SIZE, SYS_PATH, aSpiNum);
+ if (ret<0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+
+ /* Open file handler register */
+ /* conversion */
+ ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "conversion");
+ if (ret<0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+ fConversion = open(buffer, O_RDWR);
+ if (fConversion < 0){
+ printf("Error, can't open conversion file. Is max1027 modprobed ?\n");
+ return NULL;
+ }
+ /* setup */
+ ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "setup");
+ if (ret<0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+ fSetup = open(buffer, O_RDWR);
+ if (fSetup < 0){
+ printf("Error, can't open setup file.\n");
+ return NULL;
+ }
+ /* setup */
+ ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "averaging");
+ if (ret<0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+ fAveraging = open(buffer, O_RDWR);
+ if (fAveraging < 0){
+ printf("Error, can't open averaging file.\n");
+ return NULL;
+ }
+
+ /* temperature */
+ ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "temperature");
+ if (ret<0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+ fTemperature = open(buffer, O_RDWR);
+ if (fAveraging < 0){
+ printf("Error, can't open temperature file.\n");
+ return NULL;
+ }
+
+ for( i=0 ; i<8 ; i++){
+ fLowSpeed[i] = -1;
+ fHighSpeed[i] = -1;
+ if (aMode == AS_MAX1027_SLOW)
+ {
+ ret = snprintf(slow_input_name, 20, SLOW_INPUT_NAME, i);
+ if (ret < 0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+
+ ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, slow_input_name);
+ if (ret < 0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+
+ fLowSpeed[i] = open(buffer, O_RDONLY);
+ if (fLowSpeed[i] < 0){
+ printf("Error, can't open %s\n", buffer);
+ return NULL;
+ }
+ }else if((aMode == AS_MAX1027_FAST) && (i<7)){
+ ret = snprintf(buffer, BUFFER_SIZE, FAST_INPUT_PATH, i);
+ if (ret < 0) {
+ printf("Error in path writing\n");
+ return NULL;
+ }
+
+ fHighSpeed[i] = open(buffer, O_RDONLY);
+ if (fHighSpeed[i] < 0){
+ printf("Error, can't open %s\nIs loadmax.sh launched ?\n", buffer);
+ return NULL;
+ }
+
+ }
+ }
+
+ dev = (struct as_max1027_device *)malloc(sizeof(struct as_max1027_device));
+
+ dev->mode = aMode;
+ dev->fConversion = fConversion;
+ dev->fSetup = fSetup;
+ dev->fAveraging = fAveraging;
+ for( i=0 ; i<8 ; i++){
+ dev->fLowSpeed[i] = fLowSpeed[i];
+ dev->fHighSpeed[i] = fHighSpeed[i];
+ }
+ dev->fTemperature = fTemperature;
+ return dev;
+}
+
+int32_t as_max1027_close(struct as_max1027_device *aDev)
+{
+ int i;
+
+ if (aDev->fConversion > 0) close(aDev->fConversion);
+ if (aDev->fSetup > 0) close(aDev->fSetup);
+ if (aDev->fAveraging > 0) close(aDev->fAveraging);
+
+ if (aDev->fTemperature > 0) close(aDev->fTemperature);
+
+ for (i=0 ; i<8; i++){
+ if (aDev->fLowSpeed[i] > 0) close(aDev->fLowSpeed[i]);
+ if (aDev->fHighSpeed[i] > 0) close(aDev->fHighSpeed[i]);
+ }
+
+ free(aDev);
+ return 0;
+}
+
+int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev)
+{
+ uint8_t setup_value;
+
+ /* temperature is read only on slow mode */
+ if (aDev->mode != AS_MAX1027_SLOW)
+ return -1;
+
+ return 0;
+}
diff --git a/target/packages/as_devices/c/as_max1027.h b/target/packages/as_devices/c/as_max1027.h
index 524f060..7f4d1ff 100644
--- a/target/packages/as_devices/c/as_max1027.h
+++ b/target/packages/as_devices/c/as_max1027.h
@@ -41,25 +41,58 @@ typedef enum {
*/
struct as_max1027_device {
AS_max1027_mode mode;
+ int fConversion; /**< File handler for conversion register */
+ int fSetup; /**< File handler for setup register */
+ int fAveraging; /**< File handler for averaging register */
+ int fLowSpeed[8]; /**< Files handlers for lowspeed input interface */
+ int fHighSpeed[8]; /**< Files handlers for high speed input interface */
+ int fTemperature; /**< File handler for temperature */
};
-
/** @brief Open max1027
*
- * @param aSpiNum spi bus number used
+ * @param aSpiNum spi bus number used
+ * @param aMode enum to set mode (fast or slow)
*
* @return as_max1027_device structure pointer, NULL if error
*/
struct as_max1027_device *as_max1027_open(int aSpiNum,
- AS_max1027_mode mode);
+ AS_max1027_mode aMode);
+
+/** @brief Close max1027
+ *
+ * @param aDev structure device pointer
+ *
+ * @return negative value on error
+ */
+int32_t as_max1027_close(struct as_max1027_device *aDev);
-//setAveraging();
-//readTemperature_mC();
-//readTemperature_C();
-//
-//getValueInMilliVolt();
-//getValueInVolt();
+/** @brief set averaging measurement
+ *
+ * @param
+ *
+ * @return negative value on error
+ */
+int32_t as_max1027_set_averaging(struct as_max1027_device *aDev);
+
+/** @brief read temperature in milidegree â°C
+ *
+ * @param
+ *
+ * @return negative value on error
+ *
+ * @note Only slow mode can read temperature value.
+ */
+int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev);
+
+/** @brief read milivoltage value
+ *
+ * @param
+ *
+ * @return negative value on error
+ */
+int32_t as_max1027_get_value_milliVolt(struct as_max1027_device *aDev);
#ifdef __cplusplus
}
diff --git a/target/packages/as_devices/main.c b/target/packages/as_devices/main.c
index e74c9b9..f261c14 100644
--- a/target/packages/as_devices/main.c
+++ b/target/packages/as_devices/main.c
@@ -42,6 +42,7 @@ int main(int argc, char ** argv)
printf(" 3) Testing spi\n");
printf(" 4) Testing 93LCxx eprom\n");
printf(" 5) Testing gpio\n");
+ printf(" 6) Testing max1027\n");
printf("> ");
scanf("%s",buffer);
@@ -57,6 +58,8 @@ int main(int argc, char ** argv)
break;
case '5' : test_gpio();
break;
+ case '6' : test_max1027();
+ break;
default : break;
}
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index 54be388..6f6aa5f 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -27,14 +27,15 @@
#include "as_93lcxx.h"
#include "as_i2c.h"
#include "as_gpio.h"
+#include "as_max1027.h"
#define PWM_NUM 0
void pressEnterToContinue(void)
{
printf("\nPress enter to continue\n");
- getc(stdin);//XXX
- while( getc(stdin) != '\n') ;
+ while( getc(stdin) != '\n');
+ while( getc(stdin) != '\n');
}
/* pwm test */
@@ -552,4 +553,100 @@ void test_gpio()
}
}
+#ifdef APF9328
+# define MAX1027_SPI_NUM (1)
+#elif defined(APF27)
+# define MAX1027_SPI_NUM (0)
+#else
+#error Error no platform defined
+#endif
+
+#define NUM_OF_CHANNEL (8)
+
+void test_max1027()
+{
+ char buffer[50];
+ int ret;
+ char c_value[10];
+ int value;
+ struct as_max1027_device *max1027_dev;
+ int channel=0;
+ AS_max1027_mode mode= AS_MAX1027_SLOW;
+
+ max1027_dev = as_max1027_open(MAX1027_SPI_NUM, mode);
+ if (max1027_dev == NULL)
+ {
+ printf("Error, can't open max1027. Is max1027 modprobed ?\n");
+ pressEnterToContinue();
+ return ;
+ }
+
+ while(buffer[0] != 'q')
+ {
+ system("clear");
+ printf("**************************\n");
+ printf(" Testing max1027 *\n");
+ printf("**************************\n");
+ printf("Choose ('q' to quit):\n");
+ printf(" 1) Change mode (%s)\n",(mode == AS_MAX1027_SLOW)?"SLOW":"FAST");
+ printf(" 2) Select channel (%d)\n", channel);
+ printf(" 3) Read channel value\n");
+ printf(" 4) Read temperature\n");
+
+ printf("> ");
+ scanf("%s",buffer);
+
+ switch(buffer[0])
+ {
+ case '1' : printf("Give mode wanted (s:SLOW, f:FAST): ");
+ scanf("%s",c_value);
+ if ((c_value[0]=='s') && (mode == AS_MAX1027_FAST)){
+ as_max1027_close(max1027_dev);
+ max1027_dev = as_max1027_open(MAX1027_SPI_NUM,
+ AS_MAX1027_SLOW);
+ if (max1027_dev == NULL){
+ printf("Error, can't open max1027 in slow mode\n");
+ pressEnterToContinue();
+ break;
+ }
+ mode = AS_MAX1027_SLOW;
+ printf("Mode changed to Slow\n");
+ } else if((c_value[0] == 'f') && (mode == AS_MAX1027_SLOW)){
+ as_max1027_close(max1027_dev);
+ max1027_dev = as_max1027_open(MAX1027_SPI_NUM,
+ AS_MAX1027_FAST);
+ if (max1027_dev == NULL){
+ printf("Error, can't open max1027 in fast mode\n");
+ pressEnterToContinue();
+ break;
+ }
+ mode = AS_MAX1027_FAST;
+ printf("Mode changed to Fast\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '2' : printf("Give channel you want to read (0-8): ");
+ scanf("%d",&value);
+ if ((value >= NUM_OF_CHANNEL) || (value < 0)){
+ printf("Channel num wrong\n");
+ break;
+ }
+ channel = value;
+ break;
+ case '3' : printf("TODO");
+ break;
+ case '4' : printf("TODO");
+ break;
+
+ default : break;
+ }
+ }
+
+ ret = as_max1027_close(max1027_dev);
+ if (ret < 0) {
+ printf("Error on closing max1027\n");
+ pressEnterToContinue();
+ }
+}
+
hooks/post-receive
--
armadeus
|