简体   繁体   中英

Getting Error:Too few arguments where i clearly have the correct number

I'm writing code to access the i2c driver(from kernel space) using the standard interface in "/linux/i2c.h"

I'm getting an error:(too few arguments) when I try to call the method as shown below. Attached is the code for the implementation of the method as defined in "i2c.c"

my code:

static inline unsigned char i2cReadByte()
{
    unsigned char retVal = 0x00;
    struct i2c_msg value;
    //TODO Fill in msg
    i2c_transfer((struct i2c_msg*)&value); // Error: too few arguments to function 'i2c_transfer'
    return retVal;
}

i2c_transfer code as defined in i2c.c:

int i2c_transfer(struct i2c_msg *msg)
{
    int ret;

    if (!msg)
        goto transfer_error_msg_empty;

    switch(msg->direction) {

    case I2C_WRITE:

        /* check if bus is not busy */
        if (!i2c_isr_set_cleared(0,ISR_IBB))
            goto transfer_error_bus_busy;

        /* start transmission */
        ICR &= ~ICR_START;
        ICR &= ~ICR_STOP;
        IDBR = msg->data;
        if (msg->condition == I2C_COND_START)     ICR |=  ICR_START;
        if (msg->condition == I2C_COND_STOP)      ICR |=  ICR_STOP;
        if (msg->acknack   == I2C_ACKNAK_SENDNAK) ICR |=  ICR_ACKNAK;
        if (msg->acknack   == I2C_ACKNAK_SENDACK) ICR &= ~ICR_ACKNAK;
        ICR &= ~ICR_ALDIE;
        ICR |= ICR_TB;

        /* transmit register empty? */
        if (!i2c_isr_set_cleared(ISR_ITE,0))
            goto transfer_error_transmit_timeout;

        /* clear 'transmit empty' state */
        ISR |= ISR_ITE;

        /* wait for ACK from slave */
        if (msg->acknack == I2C_ACKNAK_WAITACK)
            if (!i2c_isr_set_cleared(0,ISR_ACKNAK))
                goto transfer_error_ack_missing;
        break;

    case I2C_READ:

        /* check if bus is not busy */
        if (!i2c_isr_set_cleared(0,ISR_IBB))
            goto transfer_error_bus_busy;

        /* start receive */
        ICR &= ~ICR_START;
        ICR &= ~ICR_STOP;
        if (msg->condition == I2C_COND_START)     ICR |= ICR_START;
        if (msg->condition == I2C_COND_STOP)      ICR |= ICR_STOP;
        if (msg->acknack   == I2C_ACKNAK_SENDNAK) ICR |=  ICR_ACKNAK;
        if (msg->acknack   == I2C_ACKNAK_SENDACK) ICR &= ~ICR_ACKNAK;
        ICR &= ~ICR_ALDIE;
        ICR |= ICR_TB;

        /* receive register full? */
        if (!i2c_isr_set_cleared(ISR_IRF,0))
            goto transfer_error_receive_timeout;

        msg->data = IDBR;

        /* clear 'receive empty' state */
        ISR |= ISR_IRF;

        break;

    default:

        goto transfer_error_illegal_param;

    }

    return 0;

transfer_error_msg_empty:
        PRINTD(("i2c_transfer: error: 'msg' is empty\n"));
        ret = -1; goto i2c_transfer_finish;

transfer_error_transmit_timeout:
        PRINTD(("i2c_transfer: error: transmit timeout\n"));
        ret = -2; goto i2c_transfer_finish;

transfer_error_ack_missing:
        PRINTD(("i2c_transfer: error: ACK missing\n"));
        ret = -3; goto i2c_transfer_finish;

transfer_error_receive_timeout:
        PRINTD(("i2c_transfer: error: receive timeout\n"));
        ret = -4; goto i2c_transfer_finish;

transfer_error_illegal_param:
        PRINTD(("i2c_transfer: error: illegal parameters\n"));
        ret = -5; goto i2c_transfer_finish;

transfer_error_bus_busy:
        PRINTD(("i2c_transfer: error: bus is busy\n"));
        ret = -6; goto i2c_transfer_finish;

i2c_transfer_finish:
        PRINTD(("i2c_transfer: ISR: 0x%04x\n",ISR));
        i2c_reset();
        return ret;

}

You've got a name collision with one of the kernel functions in linux/i2c.h :

/* Transfer num messages.
 */
extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
            int num);

I can see i2c_transfer signature is

int i2c_transfer (  struct i2c_adapter * adap,
    struct i2c_msg * msgs,
    int num);

on the linux kernel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM