fixed some (minor) warnings

This commit is contained in:
Markus Fröschle
2013-04-17 05:24:57 +00:00
parent a3c31dff28
commit 460bfeaa8f
3 changed files with 171 additions and 151 deletions

View File

@@ -12,7 +12,8 @@
#include <inttypes.h> #include <inttypes.h>
typedef struct { typedef struct
{
char * buf; char * buf;
int head; int head;
int tail; int tail;
@@ -33,7 +34,7 @@ int fifo_unused(fifo_t*);
int fifo_full(fifo_t*); int fifo_full(fifo_t*);
int fifo_empty(fifo_t*); int fifo_empty(fifo_t*);
int fifo_read(fifo_t*,char *,int); int fifo_read(fifo_t*, unsigned char *, int);
int fifo_write(fifo_t*,const char*,int); int fifo_write(fifo_t*, const unsigned char*, int);
#endif #endif

View File

@@ -79,7 +79,7 @@ void fifo_advance(fifo_t *f, int *ix)
//This reads at most nbytes bytes from the FIFO //This reads at most nbytes bytes from the FIFO
//The number of bytes read is returned //The number of bytes read is returned
int fifo_read(fifo_t *f, char *buf, int nbytes){ int fifo_read(fifo_t *f, unsigned char *buf, int nbytes){
int n = 0; int n = 0;
while( n < nbytes && !fifo_empty(f) ) while( n < nbytes && !fifo_empty(f) )
@@ -95,7 +95,7 @@ int fifo_read(fifo_t *f, char *buf, int nbytes){
//This writes up to nbytes bytes to the FIFO //This writes up to nbytes bytes to the FIFO
//If the head runs in to the tail, not all bytes are written //If the head runs in to the tail, not all bytes are written
//The number of bytes written is returned //The number of bytes written is returned
int fifo_write(fifo_t *f, const char *buf, int nbytes){ int fifo_write(fifo_t *f, const unsigned char *buf, int nbytes){
int n = 0; int n = 0;
while( n < nbytes && !fifo_full(f) ) while( n < nbytes && !fifo_full(f) )

View File

@@ -8,7 +8,8 @@
#include <fifo.h> #include <fifo.h>
static struct { static struct
{
uint8_t state; uint8_t state;
long delay; long delay;
uint16_t len; uint16_t len;
@@ -49,10 +50,13 @@ void __attribute__ ((interrupt)) I2C_InterruptHandler(void)
switch (i2c_param.state) switch (i2c_param.state)
{ {
case I2C_MXRX: case I2C_MXRX:
if( fifo_used(&i2c_param.fifo)+1 == i2c_param.len ) { if (fifo_used(&i2c_param.fifo) + 1 == i2c_param.len)
{
clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MSTA); clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MSTA);
i2c_param.state = I2C_READY; i2c_param.state = I2C_READY;
} else if( fifo_used(&i2c_param.fifo)+2 == i2c_param.len ) { }
else if (fifo_used(&i2c_param.fifo) + 2 == i2c_param.len)
{
set_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_TXAK); set_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_TXAK);
i2c_param.state = I2C_READY; i2c_param.state = I2C_READY;
} }
@@ -68,18 +72,23 @@ void __attribute__ ((interrupt)) I2C_InterruptHandler(void)
break; break;
} }
case I2C_MXTX: case I2C_MXTX:
if( fifo_empty(&i2c_param.fifo) || (MCF_I2C_I2SR&MCF_I2C_I2SR_RXAK) ) { if (fifo_empty(&i2c_param.fifo)
|| (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK))
{
clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MSTA); clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MSTA);
i2c_param.state = I2C_READY; i2c_param.state = I2C_READY;
} else }
else
MCF_I2C_I2DR = fifo_get(&i2c_param.fifo); MCF_I2C_I2DR = fifo_get(&i2c_param.fifo);
break; break;
} }
} }
} else { // Slave mode. }
else
{ // Slave mode.
int set; int set;
if( set = (MCF_I2C_I2SR & MCF_I2C_I2SR_IAL) ) if ((set = (MCF_I2C_I2SR & MCF_I2C_I2SR_IAL)))
clear_bit(MCF_I2C_I2SR, MCF_I2C_I2SR_IAL); clear_bit(MCF_I2C_I2SR, MCF_I2C_I2SR_IAL);
if (MCF_I2C_I2SR & MCF_I2C_I2SR_IAAS) if (MCF_I2C_I2SR & MCF_I2C_I2SR_IAAS)
{ {
@@ -87,20 +96,27 @@ void __attribute__ ((interrupt)) I2C_InterruptHandler(void)
{ {
set_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MTX); set_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MTX);
fifo_put(&i2c_param.fifo, MCF_I2C_I2DR ); fifo_put(&i2c_param.fifo, MCF_I2C_I2DR );
} else { }
else
{
clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MTX); clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MTX);
ch = MCF_I2C_I2DR; ch = MCF_I2C_I2DR;
} }
} else if( !set ) { }
else if (!set)
{
if (MCF_I2C_I2CR & MCF_I2C_I2CR_MTX) if (MCF_I2C_I2CR & MCF_I2C_I2CR_MTX)
{ {
if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK)
MCF_I2C_I2DR = fifo_get(&i2c_param.fifo); MCF_I2C_I2DR = fifo_get(&i2c_param.fifo);
else { else
{
clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MTX); clear_bit(MCF_I2C_I2CR, MCF_I2C_I2CR_MTX);
ch = MCF_I2C_I2DR; ch = MCF_I2C_I2DR;
} }
} else { }
else
{
fifo_put(&i2c_param.fifo, MCF_I2C_I2DR ); fifo_put(&i2c_param.fifo, MCF_I2C_I2DR );
} }
} }
@@ -117,7 +133,8 @@ void I2C_send(unsigned short device, unsigned char *buf, unsigned short len)
{ {
fifo_put(FIFO, 0b11110 | ((device >> 5) & 6) | I2C_WRITE); fifo_put(FIFO, 0b11110 | ((device >> 5) & 6) | I2C_WRITE);
fifo_put(FIFO, device & 255); fifo_put(FIFO, device & 255);
} else }
else
fifo_put(FIFO, ((device << 1) & 0xFE) | I2C_WRITE); fifo_put(FIFO, ((device << 1) & 0xFE) | I2C_WRITE);
fifo_write(FIFO, buf, len); fifo_write(FIFO, buf, len);
i2c_param.state = I2C_MXTX; i2c_param.state = I2C_MXTX;
@@ -133,7 +150,8 @@ void I2C_receive(unsigned short device, unsigned char *buf, unsigned short len)
{ {
fifo_put(FIFO, 0b11110 | ((device >> 5) & 6) | I2C_READ); fifo_put(FIFO, 0b11110 | ((device >> 5) & 6) | I2C_READ);
fifo_put(FIFO, device & 255); fifo_put(FIFO, device & 255);
} else }
else
fifo_put(FIFO, ((device << 1) & 0xFE) | I2C_READ); fifo_put(FIFO, ((device << 1) & 0xFE) | I2C_READ);
i2c_param.state = I2C_ADDR; i2c_param.state = I2C_ADDR;
} }
@@ -155,7 +173,8 @@ int I2C_ioctl(unsigned int index, unsigned long val)
if (MCF_I2C_I2SR & MCF_I2C_I2SR_IBB) if (MCF_I2C_I2SR & MCF_I2C_I2SR_IBB)
{ {
MCF_I2C_I2CR = 0; /* clear control register */ MCF_I2C_I2CR = 0; /* clear control register */
MCF_I2C_I2CR = MCF_I2C_I2CR_IIEN|MCF_I2C_I2CR_IEN|MCF_I2C_I2CR_MSTA; /* enable module & send a START condition */ MCF_I2C_I2CR = MCF_I2C_I2CR_IIEN | MCF_I2C_I2CR_IEN
| MCF_I2C_I2CR_MSTA; /* enable module & send a START condition */
temp = MCF_I2C_I2DR; /* dummy read */ temp = MCF_I2C_I2DR; /* dummy read */
MCF_I2C_I2SR = 0; /* clear status register */ MCF_I2C_I2SR = 0; /* clear status register */
MCF_I2C_I2CR = 0; /* clear control register */ MCF_I2C_I2CR = 0; /* clear control register */
@@ -165,7 +184,7 @@ int I2C_ioctl(unsigned int index, unsigned long val)
i2c_param._buf = 0; i2c_param._buf = 0;
break; break;
case I2CTLSBUF: case I2CTLSBUF:
i2c_param._buf = (char *)val; i2c_param._buf = (unsigned char *) val;
break; break;
case I2CTLDEV: case I2CTLDEV:
i2c_param.device = val; i2c_param.device = val;