[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-2-g758def4
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2009-12-03 10:38:53
|
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 758def4102f4238f49fec50ae2fe551842181497 (commit)
via 5da53af9b6f8b7c5aa477124d136263a78798975 (commit)
from d88d22cdfdb533245d908290e7b67f68ec8cfe76 (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 758def4102f4238f49fec50ae2fe551842181497
Merge: 5da53af9b6f8b7c5aa477124d136263a78798975 d88d22cdfdb533245d908290e7b67f68ec8cfe76
Author: Fabien Marteau <fab...@ar...>
Date: Thu Dec 3 11:38:21 2009 +0100
Merge branch 'master' of ssh://fabm@armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 5da53af9b6f8b7c5aa477124d136263a78798975
Author: Fabien Marteau <fab...@ar...>
Date: Thu Dec 3 11:37:12 2009 +0100
[OTHERS] fix as_93lcxx lib bugs and clean indentation
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_93lcxx.c | 160 ++++++++++++++++--------------
target/packages/as_devices/c/as_93lcxx.h | 40 ++++----
target/packages/as_devices/c/as_spi.c | 99 ++++++++++---------
target/packages/as_devices/c/as_spi.h | 2 +-
4 files changed, 159 insertions(+), 142 deletions(-)
diff --git a/target/packages/as_devices/c/as_93lcxx.c b/target/packages/as_devices/c/as_93lcxx.c
index d0d36c6..527906d 100644
--- a/target/packages/as_devices/c/as_93lcxx.c
+++ b/target/packages/as_devices/c/as_93lcxx.c
@@ -22,13 +22,14 @@
#include "as_spi.h"
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
/* define start bits + opcode */
#define READ (6)
#define EWEN (4)
#define EWEN_ADDR (3)
#define ERASE (7)
-#define ERAL (6)
+#define ERAL (4)
#define ERAL_ADDR (2)
#define WRITE (5)
#define WRAL (4)
@@ -36,21 +37,27 @@
#define EWDS (4)
#define EWDS_ADDR (0)
+/* Define timings */
+#define MS (1000)
+#define TWC (6*MS)
+#define TEC (6*MS)
+#define TWL (15*MS)
+
/** @brief Private functions to ease making spi instructions
*/
-uint8_t address_len(uint8_t aType, uint8_t aWord_size)
+uint8_t address_len( uint8_t aType, uint8_t aWord_size )
{
- switch(aType)
+ switch( aType )
{
case 46:
- if( aWord_size == 16)
+ if( aWord_size == 16 )
return 6;
else
return 7;
case 56:
case 66:
- if( aWord_size == 16)
+ if( aWord_size == 16 )
return 8;
else
return 9;
@@ -59,27 +66,27 @@ 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,
- uint32_t aSpeed,
- uint8_t aWord_size)
+struct as_93lcxx_device * as_93lcxx_open( unsigned char *aSpidev_filename,
+ uint8_t aType,
+ uint32_t aSpeed,
+ uint8_t aWord_size )
{
int fd=-1;
struct as_93lcxx_device *dev;
/* open spidev bus */
- fd = as_spi_open(aSpidev_filename);
- if(fd < 0)
+ fd = as_spi_open( aSpidev_filename );
+ if( fd < 0 )
return NULL;
/* verify datas */
- if(!( (aType == 46) || (aType == 56) || (aType == 66)))
+ if( !( ( aType == 46 ) || ( aType == 56 ) || ( aType == 66 ) ) )
return NULL;
- if( (aWord_size < 1) || (aWord_size > 16))
+ if( ( aWord_size < 1 ) || ( aWord_size > 16 ) )
return NULL;
- dev = (struct as_93lcxx_device *)malloc(sizeof(struct as_93lcxx_device));
- if(dev == NULL)
+ dev = ( struct as_93lcxx_device * )malloc( sizeof( struct as_93lcxx_device ) );
+ if( dev == NULL )
return NULL;
/* fill in spidev structure */
@@ -92,154 +99,157 @@ struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
return dev;
}
-void as_93lcxx_close(struct as_93lcxx_device *aDev)
+void as_93lcxx_close( struct as_93lcxx_device *aDev )
{
- as_spi_close(aDev->fd);
- free(aDev);
+ as_spi_close( aDev->fd );
+ free( aDev );
}
-int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress)
+int32_t as_93lcxx_read( struct as_93lcxx_device *aDev, uint16_t aAddress )
{
uint32_t data_out,msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ add_length = address_len( aDev->type,aDev->word_size );
/* forge message */
- msg = ((READ << (add_length+ (aDev->word_size)))
- | (aAddress << (aDev->word_size)));
+ msg = ( ( READ << ( add_length+ ( aDev->word_size ) ) )
+ | ( aAddress << ( aDev->word_size ) ) );
- data_out = as_spi_msg(aDev->fd, msg,
+ data_out = as_spi_msg( aDev->fd, msg,
3 + add_length + aDev->word_size,
- aDev->speed);
+ aDev->speed );
- if( aDev->word_size == 8)
+ if( aDev->word_size == 8 )
return data_out & 0xff;
else
return data_out & 0xffff;
}
-int32_t as_93lcxx_ewen(struct as_93lcxx_device *aDev)
+int32_t as_93lcxx_ewen( struct as_93lcxx_device *aDev )
{
uint32_t msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ 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 ) )
+ );
- as_spi_msg(aDev->fd, msg,
+ as_spi_msg( aDev->fd, msg,
3 + add_length,
- aDev->speed);
+ aDev->speed );
return 0;
}
-int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev, uint16_t aAddress)
+int32_t as_93lcxx_erase( struct as_93lcxx_device *aDev, uint16_t aAddress )
{
uint32_t msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ add_length = address_len( aDev->type,aDev->word_size );
/* forge message */
- msg = ((ERASE << (add_length + aDev->word_size ))
- | (aAddress << (aDev->word_size)));
+ msg = ( ( ERASE << ( add_length + aDev->word_size ) )
+ | ( aAddress << ( aDev->word_size ) ) );
- as_spi_msg(aDev->fd, msg,
+ as_spi_msg( aDev->fd, msg,
3 + add_length + aDev->word_size,
- aDev->speed);
- return 0;
+ aDev->speed );
+ usleep( TWC );
+
+ return 0;
}
-int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev)
+int32_t as_93lcxx_erase_all( struct as_93lcxx_device *aDev )
{
uint32_t msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ add_length = address_len( aDev->type,aDev->word_size );
/* forge message */
- msg = ((ERAL << add_length)
- |(ERAL_ADDR << (add_length-2))
- );
+ msg = ( ( ERAL << add_length )
+ |( ERAL_ADDR << ( add_length-2 ) )
+ );
- as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
+ as_spi_msg( aDev->fd, msg,
+ 3 + add_length,
+ aDev->speed );
- /* TODO: wait for RDY/BSY_n */
+ /* wait for end of erase all */
+ usleep( TEC );
return 0;
-
-
}
-int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
+int32_t as_93lcxx_write( struct as_93lcxx_device *aDev,
uint16_t aAddress,
- uint16_t aValue)
+ uint16_t aValue )
{
uint32_t msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ add_length = address_len( aDev->type,aDev->word_size );
/* forge message */
- msg = ((WRITE << (add_length+ (aDev->word_size)))
- | (aAddress << (aDev->word_size))
+ msg = ( ( WRITE << ( add_length+ ( aDev->word_size ) ) )
+ | ( aAddress << ( aDev->word_size ) )
| aValue
- );
+ );
- as_spi_msg(aDev->fd, msg,
+ as_spi_msg( aDev->fd, msg,
3 + add_length + aDev->word_size,
- aDev->speed);
+ aDev->speed );
- /* TODO: mait for RDY/BSY_n */
+ /* Wait for end of writing */
+ usleep( TWC );
return 0;
}
-int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
- uint16_t aValue)
+int32_t as_93lcxx_write_all( struct as_93lcxx_device *aDev,
+ uint16_t aValue )
{
uint32_t msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ add_length = address_len( aDev->type,aDev->word_size );
/* forge message */
- msg = ((WRAL << (add_length+ (aDev->word_size)))
- |(WRAL_ADDR << ((aDev->word_size) + (add_length-2)))
+ msg = ( ( WRAL << ( add_length+ ( aDev->word_size ) ) )
+ |( WRAL_ADDR << ( ( aDev->word_size ) + ( add_length-2 ) ) )
|aValue
- );
+ );
- as_spi_msg(aDev->fd, msg,
+ as_spi_msg( aDev->fd, msg,
3 + add_length + aDev->word_size,
- aDev->speed);
+ aDev->speed );
- /* TODO: wait for RDY/BSY_n */
+ /* Wait for end of write all */
+ usleep( TWL );
return 0;
}
-int32_t as_93lcxx_ewds(struct as_93lcxx_device *aDev)
+int32_t as_93lcxx_ewds( struct as_93lcxx_device *aDev )
{
uint32_t msg=0;
int add_length;
- add_length = address_len(aDev->type,aDev->word_size);
+ 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,
+ as_spi_msg( aDev->fd, msg,
3 + add_length,
- aDev->speed);
+ aDev->speed );
return 0;
}
diff --git a/target/packages/as_devices/c/as_93lcxx.h b/target/packages/as_devices/c/as_93lcxx.h
index 06ebd7c..b9acfd2 100644
--- a/target/packages/as_devices/c/as_93lcxx.h
+++ b/target/packages/as_devices/c/as_93lcxx.h
@@ -2,7 +2,7 @@
* This software is free software; you can redistribute it and/or modify
* 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.
+ * 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
@@ -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 Fabien Marteau <fab...@ar...>
*
*/
@@ -24,7 +24,7 @@
/** @file
- * @brief Provide standard commands to drive 93LCxx eeprom (from microchip)
+ * @brief Provide standard commands to drive 93LCxx eeprom ( from microchip )
*
*
*/
@@ -42,7 +42,7 @@ extern "C" {
*/
struct as_93lcxx_device {
unsigned char *spidev_filename; /**< filename of the spidev /dev file */
- uint8_t type; /**< type of the eeprom : 46, 56 or 66 (see DS) */
+ uint8_t type; /**< type of the eeprom : 46, 56 or 66 ( see DS ) */
uint32_t speed; /**< SCLK speed, in Hz */
uint8_t word_size; /**< word size for transaction, 8 or 16 */
int fd; /**< File handler for spidev bus */
@@ -57,17 +57,17 @@ struct as_93lcxx_device {
*
* @return as_93lcxx_device struct pointer on success, NULL on error
*/
-struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
- uint8_t aType,
- uint32_t aSpeed,
- uint8_t aWord_size);
+struct as_93lcxx_device * as_93lcxx_open( unsigned char *aSpidev_filename,
+ uint8_t aType,
+ uint32_t aSpeed,
+ uint8_t aWord_size );
/** @brief close the device
*
* @param spidev_filename path to spidev
*
*/
-void as_93lcxx_close(struct as_93lcxx_device *aDev);
+void as_93lcxx_close( struct as_93lcxx_device *aDev );
/** @brief read a value in address given
*
@@ -76,7 +76,8 @@ void as_93lcxx_close(struct as_93lcxx_device *aDev);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress);
+int32_t as_93lcxx_read( struct as_93lcxx_device *aDev,
+ uint16_t aAddress );
/** @brief enable write on eeprom
*
@@ -84,7 +85,7 @@ int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress);
*
* @return positive value on success, negative value on error
*/
-int32_t as_93lcxx_ewen(struct as_93lcxx_device *aDev);
+int32_t as_93lcxx_ewen( struct as_93lcxx_device *aDev );
/** @brief Force all data bits of the specified iaddress to 1
*
@@ -93,7 +94,8 @@ int32_t as_93lcxx_ewen(struct as_93lcxx_device *aDev);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev, uint16_t aAddress);
+int32_t as_93lcxx_erase( struct as_93lcxx_device *aDev,
+ uint16_t aAddress );
/** @brief Force all bits in eeprom to 1
*
@@ -101,7 +103,7 @@ int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev, uint16_t aAddress);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev);
+int32_t as_93lcxx_erase_all( struct as_93lcxx_device *aDev );
/** @brief write a value in given address
*
@@ -111,9 +113,9 @@ int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
- uint16_t aAddress,
- uint16_t aValue);
+int32_t as_93lcxx_write( struct as_93lcxx_device *aDev,
+ uint16_t aAddress,
+ uint16_t aValue );
/** @brief write the entire memory array with value given
*
@@ -122,8 +124,8 @@ int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
- uint16_t aValue);
+int32_t as_93lcxx_write_all( struct as_93lcxx_device *aDev,
+ uint16_t aValue );
/** @brief disable write on eeprom
*
@@ -131,7 +133,7 @@ int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
*
* @return positive value on success, negative value on error
*/
-int32_t as_93lcxx_ewds(struct as_93lcxx_device *aDev);
+int32_t as_93lcxx_ewds( struct as_93lcxx_device *aDev );
#ifdef __cplusplus
diff --git a/target/packages/as_devices/c/as_spi.c b/target/packages/as_devices/c/as_spi.c
index bc70b8c..f4cd29b 100644
--- a/target/packages/as_devices/c/as_spi.c
+++ b/target/packages/as_devices/c/as_spi.c
@@ -2,7 +2,7 @@
* This software is free software; you can redistribute it and/or modify
* 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.
+ * 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
@@ -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 Fabien Marteau <fab...@ar...>
*
*/
@@ -33,136 +33,141 @@
#include <linux/spi/spidev.h>
-int as_spi_open(const unsigned char *spidev_name)
+int as_spi_open( const unsigned char *spidev_name )
{
int fd;
- fd = open((char *)spidev_name, O_RDWR);
- if (fd < 0) {
- perror("open");
+ fd = open( ( char * )spidev_name, O_RDWR );
+ if ( fd < 0 ) {
+ perror( "open" );
return -1;
}
return fd;
}
-int as_spi_set_mode(int fd, uint8_t mode)
+int as_spi_set_mode( int fd, uint8_t mode )
{
/* TODO */
return -1;
}
-int as_spi_set_lsb(int fd, uint8_t lsb)
+int as_spi_set_lsb( int fd, uint8_t lsb )
{
/* TODO */
return -1;
}
-int as_spi_set_bits_per_word(int fd, uint8_t bits)
+int as_spi_set_bits_per_word( int fd, uint8_t bits )
{
/* TODO */
return -1;
}
-int as_spi_set_speed(int fd)
+int as_spi_set_speed( int fd )
{
/* TODO */
return -1;
}
-int as_spi_get_mode(int fd)
+int as_spi_get_mode( int fd )
{
uint8_t mode;
- if (ioctl(fd, SPI_IOC_RD_MODE, &mode) < 0) {
- perror("SPI rd_mode");
+ if ( ioctl( fd, SPI_IOC_RD_MODE, &mode ) < 0 ) {
+ perror( "SPI rd_mode" );
return -1;
}
return mode;
}
-int as_spi_get_lsb(int fd)
+int as_spi_get_lsb( int fd )
{
uint8_t lsb;
- if (ioctl(fd, SPI_IOC_RD_LSB_FIRST, &lsb) < 0) {
- perror("SPI rd_lsb_fist");
+ if ( ioctl( fd, SPI_IOC_RD_LSB_FIRST, &lsb ) < 0 ) {
+ perror( "SPI rd_lsb_fist" );
return -1;
}
return lsb;
}
-int as_spi_get_bits_per_word(int fd)
+int as_spi_get_bits_per_word( int fd )
{
uint8_t bits;
- if (ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0) {
- perror("SPI bits_per_word");
+ if ( ioctl( fd, SPI_IOC_RD_BITS_PER_WORD, &bits ) < 0 ) {
+ perror( "SPI bits_per_word" );
return-1;
}
return bits;
}
-int as_spi_get_speed(int fd)
+int as_spi_get_speed( int fd )
{
uint8_t speed;
- if (ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0) {
- perror("SPI max_speed_hz");
+ if ( ioctl( fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed ) < 0 ) {
+ perror( "SPI max_speed_hz" );
return -1;
}
return speed;
}
-uint32_t as_spi_msg(int aFd,
+uint32_t as_spi_msg( int aFd,
uint32_t aMsg,
size_t aLen,
- uint32_t aSpeed)
+ uint32_t aSpeed )
{
uint32_t msg;
int len;
- struct spi_ioc_transfer xfer[1];
- unsigned char buf[32];
- unsigned char buf_read[32];
+ struct spi_ioc_transfer xfer[1];
+ unsigned char buf[32];
+ unsigned char buf_read[32];
- int status;
+ int status;
int i;
msg = aMsg;
len = aLen;
- memset(xfer, 0, sizeof xfer);
- memset(buf, 0, sizeof buf);
- memset(buf_read, 0, sizeof buf_read);
+ msg = msg<<1;/* XXX Last bit is always read at 0 */
+ len = len+1; /* XXX */
- if (len > sizeof buf)
- len = sizeof buf;
- for (i = len;i > 0;i--)
+ memset( xfer, 0, sizeof xfer );
+ memset( buf, 0, sizeof buf );
+ memset( buf_read, 0, sizeof buf_read );
+
+ if ( len >= sizeof buf )
+ len = (sizeof buf)-1;
+ for ( i = len;i > 0;i-- )
{
buf[i-1] = msg & 0x01;
msg = msg >> 1;
}
- xfer[0].tx_buf = (__u64) buf;
- xfer[0].len = len;
- xfer[0].rx_buf = (__u64) buf_read;
+ xfer[0].tx_buf = buf;
+ xfer[0].len = len;
+ xfer[0].rx_buf = buf_read;
xfer[0].speed_hz = aSpeed;
xfer[0].bits_per_word = 1;
- status = ioctl(aFd, SPI_IOC_MESSAGE(1), xfer);
- if (status < 0) {
- perror("SPI_IOC_MESSAGE");
- return 0;
- }
- for (i = 0;i < len;i++)
+ status = ioctl( aFd, SPI_IOC_MESSAGE( 1 ), xfer );
+ if ( status < 0 ) {
+ perror( "SPI_IOC_MESSAGE" );
+ return 0;
+ }
+
+ msg = msg | buf_read[0];
+ for ( i = 1;i < len;i++ )
{
- msg = msg | buf_read[i];
msg = msg << 1;
+ msg = msg | buf_read[i];
}
- return msg;
+ return msg;
}
-void as_spi_close(int fd)
+void as_spi_close( int fd )
{
- close(fd);
+ close( fd );
return;
}
diff --git a/target/packages/as_devices/c/as_spi.h b/target/packages/as_devices/c/as_spi.h
index bde5890..78b9365 100644
--- a/target/packages/as_devices/c/as_spi.h
+++ b/target/packages/as_devices/c/as_spi.h
@@ -102,7 +102,7 @@ int as_spi_get_speed(int fd);
*/
int as_spi_get_bits_per_word(int fd);
-/** @brief Forge arbitrary length message (32bits max) and send it
+/** @brief Forge arbitrary length message (31bits max) and send it
*
* @param fd spidev file handler
* @param msg right adjusted message
hooks/post-receive
--
armadeus
|