master/mailbox.c
changeset 1989 6aa393418fb3
parent 1921 d9cf40facbc4
child 2045 ff2a13a4603c
child 2488 c0b4c64fcebd
equal deleted inserted replaced
1988:ea38efeeb7b3 1989:6aa393418fb3
    56 {
    56 {
    57     size_t total_size;
    57     size_t total_size;
    58     int ret;
    58     int ret;
    59 
    59 
    60     if (unlikely(!slave->sii.mailbox_protocols)) {
    60     if (unlikely(!slave->sii.mailbox_protocols)) {
    61         EC_ERR("Slave %u does not support mailbox communication!\n",
    61         EC_SLAVE_ERR(slave, "Slave does not support mailbox"
    62                slave->ring_position);
    62                 " communication!\n");
    63         return ERR_PTR(-EPROTONOSUPPORT);
    63         return ERR_PTR(-EPROTONOSUPPORT);
    64     }
    64     }
    65 
    65 
    66     total_size = EC_MBOX_HEADER_SIZE + size;
    66     total_size = EC_MBOX_HEADER_SIZE + size;
    67 
    67 
    68     if (unlikely(total_size > slave->configured_rx_mailbox_size)) {
    68     if (unlikely(total_size > slave->configured_rx_mailbox_size)) {
    69         EC_ERR("Data size (%zu) does not fit in mailbox (%u)!\n",
    69         EC_SLAVE_ERR(slave, "Data size (%zu) does not fit in mailbox (%u)!\n",
    70                 total_size, slave->configured_rx_mailbox_size);
    70                 total_size, slave->configured_rx_mailbox_size);
    71         return ERR_PTR(-EOVERFLOW);
    71         return ERR_PTR(-EOVERFLOW);
    72     }
    72     }
    73 
    73 
    74     ret = ec_datagram_fpwr(datagram, slave->station_address,
    74     ret = ec_datagram_fpwr(datagram, slave->station_address,
   171     size_t data_size;
   171     size_t data_size;
   172 
   172 
   173     data_size = EC_READ_U16(datagram->data);
   173     data_size = EC_READ_U16(datagram->data);
   174 
   174 
   175     if (data_size + EC_MBOX_HEADER_SIZE > slave->configured_tx_mailbox_size) {
   175     if (data_size + EC_MBOX_HEADER_SIZE > slave->configured_tx_mailbox_size) {
   176         EC_ERR("Corrupt mailbox response received from slave %u!\n",
   176         EC_SLAVE_ERR(slave, "Corrupt mailbox response received!\n");
   177                 slave->ring_position);
       
   178         ec_print_data(datagram->data, slave->configured_tx_mailbox_size);
   177         ec_print_data(datagram->data, slave->configured_tx_mailbox_size);
   179         return ERR_PTR(-EPROTO);
   178         return ERR_PTR(-EPROTO);
   180     }
   179     }
   181 
   180 
   182     *type = EC_READ_U8(datagram->data + 5) & 0x0F;
   181     *type = EC_READ_U8(datagram->data + 5) & 0x0F;
   184 
   183 
   185     if (*type == 0x00) {
   184     if (*type == 0x00) {
   186         const ec_code_msg_t *mbox_msg;
   185         const ec_code_msg_t *mbox_msg;
   187         uint16_t code = EC_READ_U16(datagram->data + 8);
   186         uint16_t code = EC_READ_U16(datagram->data + 8);
   188 
   187 
   189         EC_ERR("Mailbox error response received from slave %u - ",
   188         EC_SLAVE_ERR(slave, "Mailbox error response received - ");
   190                 slave->ring_position);
       
   191 
   189 
   192         for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
   190         for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
   193             if (mbox_msg->code != code)
   191             if (mbox_msg->code != code)
   194                 continue;
   192                 continue;
   195             printk("Code 0x%04X: \"%s\".\n",
   193             printk("Code 0x%04X: \"%s\".\n",