得到错误:我明显拥有正确数字的参数太少

时间:2011-04-14 12:48:33

标签: c linux linux-kernel linux-device-driver embedded-linux

我正在使用“/linux/i2c.h”中的标准接口编写代码来访问i2c驱动程序(来自内核空间)

当我尝试调用如下所示的方法时,我收到一个错误:(参数太少)。附件是“i2c.c”

中定义的方法实现的代码

我的代码:

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中的i2c_transfer代码:

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;

}

2 个答案:

答案 0 :(得分:3)

您与linux/i2c.h中的某个内核函数发生名称冲突:

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

答案 1 :(得分:0)

我可以看到i2c_transfer 签名是

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

在linux内核上