[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-389-g5557d50
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-06-02 10:16:11
|
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 5557d509449cb09242ee5248db5a7479334df9d1 (commit)
from 68afc4c51799d8c62fa5831923770a7021298149 (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 5557d509449cb09242ee5248db5a7479334df9d1
Author: Fabien Marteau <fab...@ar...>
Date: Wed Jun 2 12:15:36 2010 +0200
[as_devices] some cosmetic modifications and errors messages
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_93lcxx.c | 125 ++++++++++++++++++++++-------
target/packages/as_devices/c/as_gpio.c | 61 +++++++++++++-
target/packages/as_devices/c/as_max1027.c | 113 ++++++++------------------
target/packages/as_devices/c/as_spi.c | 27 ++++---
4 files changed, 204 insertions(+), 122 deletions(-)
diff --git a/target/packages/as_devices/c/as_93lcxx.c b/target/packages/as_devices/c/as_93lcxx.c
index 86926dc..3f463ce 100644
--- a/target/packages/as_devices/c/as_93lcxx.c
+++ b/target/packages/as_devices/c/as_93lcxx.c
@@ -45,6 +45,13 @@
#define TEC (6*MS)
#define TWL (15*MS)
+//#define DEBUG
+#ifdef DEBUG
+# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#else
+# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#endif
+
/** @brief Private functions to ease making spi instructions
*
*/
@@ -68,6 +75,7 @@ static uint8_t address_len(uint8_t aType, uint8_t aWord_size)
}
}
+/*------------------------------------------------------------------------------*/
struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
uint8_t aType,
@@ -80,7 +88,7 @@ struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
/* open spidev bus */
fd = as_spi_open(aSpidev_filename);
if (fd < 0) {
- perror("Can't open spi device");
+ ERROR("Can't open spi device");
return NULL;
}
@@ -92,7 +100,10 @@ struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
dev = (struct as_93lcxx_device *)malloc(sizeof(struct as_93lcxx_device));
if (dev == NULL)
+ {
+ ERROR("Can't allocate memory for eeprom structure device\n");
return NULL;
+ }
/* fill in spidev structure */
dev->spidev_filename = aSpidev_filename;
@@ -104,11 +115,7 @@ struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
return dev;
}
-void as_93lcxx_close(struct as_93lcxx_device *aDev)
-{
- as_spi_close(aDev->fd);
- free(aDev);
-}
+/*------------------------------------------------------------------------------*/
int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress)
{
@@ -124,6 +131,11 @@ int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress)
data_out = as_spi_msg(aDev->fd, msg,
3 + add_length + aDev->word_size,
aDev->speed);
+ if (data_out < 0)
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
if (aDev->word_size == 8)
return data_out & 0xff;
@@ -131,28 +143,37 @@ int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress)
return data_out & 0xffff;
}
+/*------------------------------------------------------------------------------*/
+
int32_t as_93lcxx_ewen(struct as_93lcxx_device *aDev)
{
uint32_t msg=0;
int add_length;
+ int ret;
add_length = address_len(aDev->type, aDev->word_size);
/* forge message */
- msg = ((EWEN << add_length)
- |(EWEN_ADDR << (add_length-2))
- );
+ msg = ((EWEN << add_length) |(EWEN_ADDR << (add_length-2)));
+
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length,
+ aDev->speed);
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
- as_spi_msg(aDev->fd, msg,
- 3 + add_length,
- aDev->speed);
return 0;
}
+/*------------------------------------------------------------------------------*/
+
int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev, uint16_t aAddress)
{
uint32_t msg=0;
int add_length;
+ int ret;
add_length = address_len(aDev->type, aDev->word_size);
@@ -160,19 +181,27 @@ int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev, uint16_t aAddress)
msg = ((ERASE << (add_length + aDev->word_size))
| (aAddress << (aDev->word_size)));
- as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size,
+ aDev->speed);
+ if (ret < 0)
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
usleep(TWC);
return 0;
}
+/*------------------------------------------------------------------------------*/
+
int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev)
{
uint32_t msg=0;
int add_length;
+ int ret;
add_length = address_len(aDev->type, aDev->word_size);
@@ -181,9 +210,14 @@ int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev)
|(ERAL_ADDR << (add_length-2))
);
- as_spi_msg(aDev->fd, msg,
- 3 + add_length,
- aDev->speed);
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length,
+ aDev->speed);
+ if (ret < 0)
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
/* wait for end of erase all */
usleep(TEC);
@@ -191,12 +225,15 @@ int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev)
return 0;
}
+/*------------------------------------------------------------------------------*/
+
int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
uint16_t aAddress,
uint16_t aValue)
{
uint32_t msg=0;
int add_length;
+ int ret;
add_length = address_len(aDev->type, aDev->word_size);
@@ -206,9 +243,14 @@ int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
| aValue
);
- as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size,
+ aDev->speed);
+ if (ret < 0)
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
/* Wait for end of writing */
usleep(TWC);
@@ -216,11 +258,14 @@ int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
return 0;
}
+/*------------------------------------------------------------------------------*/
+
int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
uint16_t aValue)
{
uint32_t msg=0;
int add_length;
+ int ret;
add_length = address_len(aDev->type, aDev->word_size);
@@ -230,9 +275,14 @@ int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
|aValue
);
- as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size,
+ aDev->speed);
+ if (ret < 0)
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
/* Wait for end of write all */
usleep(TWL);
@@ -240,22 +290,37 @@ int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
return 0;
}
+/*------------------------------------------------------------------------------*/
+
int32_t as_93lcxx_ewds(struct as_93lcxx_device *aDev)
{
uint32_t msg=0;
int add_length;
+ int ret;
add_length = address_len(aDev->type, aDev->word_size);
/* forge message */
- msg = ((EWDS << add_length)
- |(EWDS_ADDR << (add_length-2))
- );
+ msg = ((EWDS << add_length) |(EWDS_ADDR << (add_length-2)));
- as_spi_msg(aDev->fd, msg,
- 3 + add_length,
- aDev->speed);
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length,
+ aDev->speed);
+ if (ret < 0)
+ {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
return 0;
}
+/*------------------------------------------------------------------------------*/
+
+void as_93lcxx_close(struct as_93lcxx_device *aDev)
+{
+ as_spi_close(aDev->fd);
+ free(aDev);
+}
+
+
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index 4a4ef3d..737af96 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -58,6 +58,13 @@
#error Error no platform defined
#endif
+//#define DEBUG
+#ifdef DEBUG
+# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#else
+# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#endif
+
/*------------------------------------------------------------------------------*/
struct as_gpio_device *
@@ -70,6 +77,7 @@ as_gpio_open(char aPortChar)
if (((aPortChar-'A') > (NUMBER_OF_PORTS-1)) || ((aPortChar-'A') < 0))
{
+ ERROR("No port named %c\n",aPortChar);
return NULL;
}
@@ -77,18 +85,23 @@ as_gpio_open(char aPortChar)
ret = snprintf(gpio_file_path,50, "%s%c",
GPIO_BASE_PORT, aPortChar);
if (ret < 0) {
+ ERROR("Can't forge gpio port path\n");
return NULL;
}
/* opening gpio port */
ret = open(gpio_file_path, O_RDWR);
if (ret < 0) {
+ ERROR("Can't open file port\n");
return NULL;
}
dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
if (dev == NULL)
+ {
+ ERROR("Can't allocate memory for gpio device structure\n");
return NULL;
+ }
dev->port_letter = aPortChar;
dev->fdev = ret;
@@ -111,9 +124,10 @@ as_gpio_set_pin_direction(struct as_gpio_device *aDev,
int ret=0;
int portval;
- /* Set LED PIN as GPIO; read/modify/write */
+ /* Set PIN as GPIO; read/modify/write */
ret = ioctl(aDev->fdev, GPIORDMODE, &portval);
if (ret < 0) {
+ ERROR("Can't set gpio read mode\n");
return ret;
}
@@ -121,12 +135,14 @@ as_gpio_set_pin_direction(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIOWRMODE, &portval);
if (ret < 0) {
+ ERROR("Can't set gpio write mode\n");
return ret;
}
/* set direction */
ret = ioctl(aDev->fdev, GPIORDDIRECTION, &portval);
if (ret < 0) {
+ ERROR("Can't get gpio direction\n");
return ret;
}
@@ -138,6 +154,7 @@ as_gpio_set_pin_direction(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIOWRDIRECTION, &portval);
if (ret < 0) {
+ ERROR("Can't get gpio direction\n");
return ret;
}
return 0;
@@ -155,6 +172,7 @@ as_gpio_set_pin_value(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIORDDATA, &portval);
if (ret < 0) {
+ ERROR("Can't read gpio data\n");
return ret;
}
@@ -165,6 +183,7 @@ as_gpio_set_pin_value(struct as_gpio_device *aDev,
}
ret = ioctl(aDev->fdev, GPIOWRDATA, &portval);
if (ret < 0) {
+ ERROR("Can't write gpio data\n");
return ret;
}
@@ -181,6 +200,7 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIORDDATA, &portval);
if (ret < 0) {
+ ERROR("Can't read gpio data\n");
return ret;
}
@@ -200,16 +220,28 @@ int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
char value;
if (aPinNum >= PORT_SIZE )
+ {
+ ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
return -1; /* aPinNum wrong */
+ }
if (aPinNum < 0 )
+ {
+ ERROR("Wrong pin number %d\n",aPinNum);
return -1;
+ }
if (aDev->fpin[aPinNum] == -1)
- return -1; /* irq must be configured before */
+ {
+ ERROR("irq must be configured before\n");
+ return -1;
+ }
ret = read(aDev->fpin[aPinNum], &value, 1);
if (ret < 0)
+ {
+ ERROR("can't read pin %d value \n",aPinNum);
return ret;
+ }
if (value != 0)
return 1;
@@ -227,6 +259,7 @@ int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIORDPULLUP, &portval);
if (ret < 0) {
+ ERROR("can't get pullup value\n");
return ret;
}
@@ -249,6 +282,7 @@ int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIORDPULLUP, &portval);
if (ret < 0) {
+ ERROR("Can't get pullup value\n");
return ret;
}
@@ -259,6 +293,7 @@ int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
}
ret = ioctl(aDev->fdev, GPIOWRPULLUP, &portval);
if (ret < 0) {
+ ERROR("Can't set pullup value\n");
return ret;
}
@@ -275,13 +310,17 @@ int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
/* check pin num */
if (aPinNum >= PORT_SIZE)
+ {
+ ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
return -1;
+ }
if (aPinNum < PORT_SIZE/2)
{
ret = ioctl(aDev->fdev, GPIORDIRQMODE_L, &portval);
if (ret < 0) {
+ ERROR("Can't read irq mode L\n");
return ret;
}
@@ -292,6 +331,7 @@ int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIORDIRQMODE_H, &portval);
if (ret < 0) {
+ ERROR("Can't read irq mode H\n");
return ret;
}
@@ -312,11 +352,17 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
/* check mode value */
if (aMode > 3)
+ {
+ ERROR("Wrong mode value %d\n",aMode);
return -1;
+ }
/* check pin num */
if (aPinNum >= PORT_SIZE)
+ {
+ ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
return -1;
+ }
/* close fpin file */
if (aDev->fpin[aPinNum] != -1)
@@ -329,6 +375,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
{
ret = ioctl(aDev->fdev, GPIORDIRQMODE_L, &portval);
if (ret < 0) {
+ ERROR("Can't read irq mode L\n");
return ret;
}
@@ -337,6 +384,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIOWRIRQMODE_L, &portval);
if (ret < 0) {
+ ERROR("Can't write irq mode L\n");
return ret;
}
@@ -344,6 +392,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIORDIRQMODE_H, &portval);
if (ret < 0) {
+ ERROR("Can't read irq mode H\n");
return ret;
}
@@ -352,6 +401,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
ret = ioctl(aDev->fdev, GPIOWRIRQMODE_H, &portval);
if (ret < 0) {
+ ERROR("Can't write irq mode H\n");
return ret;
}
}
@@ -362,16 +412,21 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
ret = snprintf(buffer, BUFF_SIZE, "%s%c%d",
GPIO_BASE_PIN, aDev->port_letter, aPinNum);
if (ret < 0)
+ {
+ ERROR("Can't forge fpin path\n");
return ret;
+ }
ret = open(buffer, O_RDONLY);
if (ret < 0)
+ {
+ ERROR("Can't open %s\n",buffer);
return ret;
+ }
aDev->fpin[aPinNum] = ret;
}
aDev->irq_mode[aPinNum] = aMode;
-
return 0;
}
diff --git a/target/packages/as_devices/c/as_max1027.c b/target/packages/as_devices/c/as_max1027.c
index 57d8200..c6e3aa9 100644
--- a/target/packages/as_devices/c/as_max1027.c
+++ b/target/packages/as_devices/c/as_max1027.c
@@ -43,6 +43,13 @@ typedef unsigned char u8;
#define SLOW_INPUT_NAME "in%d_input"
#define FAST_INPUT_PATH "/dev/max1027/AIN%d"
+//#define DEBUG
+#ifdef DEBUG
+# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#else
+# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#endif
+
/** @brief Function used to write in /sys file
*
* @param aFile_handler /sys file handler
@@ -63,13 +70,13 @@ int32_t as_max1027_write_buffer(int aFile_handler, int aValue)
ret = write(aFile_handler, buffer, buffer_len);
if (ret < 0)
{
- perror("Can't write file ");
+ ERROR("Can't write file ");
return -1;
}
ret = lseek(aFile_handler, 0, SEEK_SET);
if (ret < 0)
{
- perror("lseek error ");
+ ERROR("lseek error ");
return -1;
}
@@ -93,9 +100,7 @@ int32_t as_max1027_read_buffer(int aFile_handler, int *aValueRead)
ret = read(aFile_handler, valueRead, SIZEOFBUFF);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error, reading buffer file\n");
-#endif
+ ERROR("Error, reading buffer file\n");
return -1;
}
valueRead[ret-1] = '\0';
@@ -125,18 +130,14 @@ struct as_max1027_device *as_max1027_open(int aSpiNum,
/** XXX */
if (aMode == AS_MAX1027_FAST)
{
-#ifdef ERROR_MSG
printf("Error, fast mode not supported yet\n");
-#endif
return NULL;
}
ret = snprintf(path, PATH_SIZE, SYS_PATH, aSpiNum);
if (ret<0)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
@@ -145,34 +146,26 @@ struct as_max1027_device *as_max1027_open(int aSpiNum,
ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "conversion");
if (ret<0)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
fConversion = open(buffer, O_RDWR);
if (fConversion < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't open conversion file. Is max1027 modprobed ?\n");
-#endif
+ ERROR("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)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
fSetup = open(buffer, O_RDWR);
if (fSetup < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't open setup file.\n");
-#endif
+ ERROR("Error, can't open setup file.\n");
return NULL;
}
ret = as_max1027_write_buffer(fSetup,
@@ -182,26 +175,20 @@ struct as_max1027_device *as_max1027_open(int aSpiNum,
MAX1027_SETUP_DIFFSEL(0));
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't set default setup parameters\n");
-#endif
+ ERROR("Error, can't set default setup parameters\n");
return NULL;
}
/* averaging */
ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "averaging");
if (ret<0) {
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
fAveraging = open(buffer, O_RDWR);
if (fAveraging < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't open averaging file.\n");
-#endif
+ ERROR("Error, can't open averaging file.\n");
return NULL;
}
@@ -211,17 +198,13 @@ struct as_max1027_device *as_max1027_open(int aSpiNum,
ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "temp1_input");
if (ret<0)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
fTemperature = open(buffer, O_RDONLY);
if (fTemperature < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't open temperature file.\n");
-#endif
+ ERROR("Error, can't open temperature file.\n");
return NULL;
}
} else {
@@ -237,27 +220,21 @@ struct as_max1027_device *as_max1027_open(int aSpiNum,
ret = snprintf(slow_input_name, 20, SLOW_INPUT_NAME, i);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, slow_input_name);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
fLowSpeed[i] = open(buffer, O_RDONLY);
if (fLowSpeed[i] < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't open %s\n", buffer);
-#endif
+ ERROR("Error, can't open %s\n", buffer);
return NULL;
}
}
@@ -266,18 +243,14 @@ struct as_max1027_device *as_max1027_open(int aSpiNum,
ret = snprintf(buffer, BUFFER_SIZE, FAST_INPUT_PATH, i);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error in path writing\n");
-#endif
+ ERROR("Error in path writing\n");
return NULL;
}
fHighSpeed[i] = open(buffer, O_RDONLY);
if (fHighSpeed[i] < 0)
{
-#ifdef ERROR_MSG
- printf("Error, can't open %s\nIs loadmax.sh launched ?\n", buffer);
-#endif
+ ERROR("Error, can't open %s\nIs loadmax.sh launched ?\n", buffer);
return NULL;
}
@@ -318,9 +291,7 @@ int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev,
MAX1027_CONV_TEMP);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error launching conversion\n");
-#endif
+ ERROR("Error launching conversion\n");
return -1;
}
@@ -328,9 +299,7 @@ int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev,
ret = as_max1027_read_buffer(aDev->fTemperature, aTemperature);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error, reading fTemperature\n");
-#endif
+ ERROR("Error, reading fTemperature\n");
return -1;
}
@@ -359,9 +328,7 @@ int32_t as_max1027_set_averaging(struct as_max1027_device *aDev, uint8_t aNbConv
aDev->scan_mode = SCAN_MODE_10; /* scan */
break;
default:
-#ifdef ERROR_MSG
- printf("%s: unsupported setting\n", __func__);
-#endif
+ ERROR("%s: unsupported setting\n", __func__);
return -1;
}
@@ -370,9 +337,7 @@ int32_t as_max1027_set_averaging(struct as_max1027_device *aDev, uint8_t aNbConv
ret = as_max1027_write_buffer(aDev->fAveraging, avg_register);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error, setting averaging\n");
-#endif
+ ERROR("Error, setting averaging\n");
return -1;
}
@@ -386,9 +351,7 @@ int32_t as_max1027_get_value_milliVolt(struct as_max1027_device *aDev,
if ((aChannelNum >= NUMBER_OF_CHANNELS) || (aChannelNum < 0))
{
-#ifdef ERROR_MSG
- printf("Wrong num channel\n");
-#endif
+ ERROR("Wrong num channel\n");
return -1;
}
@@ -401,9 +364,7 @@ int32_t as_max1027_get_value_milliVolt(struct as_max1027_device *aDev,
MAX1027_CONV_SCAN(aDev->scan_mode));
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error launching conversion\n");
-#endif
+ ERROR("Error launching conversion\n");
return -1;
}
@@ -411,24 +372,18 @@ int32_t as_max1027_get_value_milliVolt(struct as_max1027_device *aDev,
ret = as_max1027_read_buffer(aDev->fLowSpeed[aChannelNum], aValue);
if (ret < 0)
{
-#ifdef ERROR_MSG
- printf("Error, reading fLowSpeed[%d]\n", aChannelNum);
-#endif
+ ERROR("Error, reading fLowSpeed[%d]\n", aChannelNum);
return -1;
}
}
else if (aDev->mode == AS_MAX1027_FAST)
{
-#ifdef ERROR_MSG
- printf("TODO: fast mode channel reading\n");
-#endif
+ ERROR("TODO: fast mode channel reading\n");
return -1;
}
else
{
-#ifdef ERROR_MSG
- printf("Unknown mode\n");
-#endif
+ ERROR("Unknown mode\n");
return -1;
}
diff --git a/target/packages/as_devices/c/as_spi.c b/target/packages/as_devices/c/as_spi.c
index 9f4ae30..8537a1c 100644
--- a/target/packages/as_devices/c/as_spi.c
+++ b/target/packages/as_devices/c/as_spi.c
@@ -14,7 +14,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
- * Copyright (C) 2009 Fabien Marteau <fab...@ar...>
+ * Copyright (C) 2009-2010 Fabien Marteau <fab...@ar...>
*
*/
@@ -33,6 +33,12 @@
#include "as_spi.h"
+//#define DEBUG
+#ifdef DEBUG
+# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#else
+# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#endif
int as_spi_open(const unsigned char *aSpidev_name)
{
@@ -40,7 +46,7 @@ int as_spi_open(const unsigned char *aSpidev_name)
fd = open((char *)aSpidev_name, O_RDWR);
if (fd < 0) {
- perror("open");
+ ERROR("spi open.");
return -1;
}
@@ -50,24 +56,28 @@ int as_spi_open(const unsigned char *aSpidev_name)
int as_spi_set_mode(int aFd, uint8_t aMode)
{
/* TODO */
+ printf("TODO\n");
return -1;
}
int as_spi_set_lsb(int aFd, uint8_t aLsb)
{
/* TODO */
+ printf("TODO\n");
return -1;
}
int as_spi_set_bits_per_word(int aFd, uint8_t aBits)
{
/* TODO */
+ printf("TODO\n");
return -1;
}
int as_spi_set_speed(int aFd)
{
/* TODO */
+ printf("TODO\n");
return -1;
}
@@ -76,7 +86,7 @@ int as_spi_get_mode(int aFd)
uint8_t mode;
if (ioctl(aFd, SPI_IOC_RD_MODE, &mode) < 0) {
- perror("SPI rd_mode");
+ ERROR("SPI rd_mode");
return -1;
}
@@ -88,7 +98,7 @@ int as_spi_get_lsb(int aFd)
uint8_t lsb;
if (ioctl(aFd, SPI_IOC_RD_LSB_FIRST, &lsb) < 0) {
- perror("SPI rd_lsb_fist");
+ ERROR("SPI rd_lsb_fist");
return -1;
}
@@ -100,7 +110,7 @@ int as_spi_get_bits_per_word(int aFd)
uint8_t bits;
if (ioctl(aFd, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0) {
- perror("SPI bits_per_word");
+ ERROR("SPI bits_per_word");
return -1;
}
@@ -112,7 +122,7 @@ int as_spi_get_speed(int aFd)
uint8_t speed;
if (ioctl(aFd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0) {
- perror("SPI max_speed_hz");
+ ERROR("SPI max_speed_hz");
return -1;
}
@@ -137,9 +147,6 @@ uint32_t as_spi_msg(int aFd,
msg = aMsg;
len = aLen;
- //msg = msg << 1;/* XXX Last bit is always read at 0 */
- //len = len + 1; /* XXX */
-
memset(xfer, 0, sizeof(xfer));
memset(buf, 0, sizeof(buf));
memset(buf_read, 0, sizeof(buf_read));
@@ -162,7 +169,7 @@ uint32_t as_spi_msg(int aFd,
status = ioctl(aFd, SPI_IOC_MESSAGE(1), xfer);
if (status < 0) {
- perror("SPI_IOC_MESSAGE");
+ ERROR("SPI_IOC_MESSAGE");
return 0;
}
hooks/post-receive
--
armadeus
|