master/canopen.c
changeset 113 a3dbd6bc8fce
parent 111 9963537ec776
child 133 b36d187ecc0b
equal deleted inserted replaced
112:eec7639c7be9 113:a3dbd6bc8fce
   192     // Read "written bit" of Sync-Manager
   192     // Read "written bit" of Sync-Manager
   193 
   193 
   194     start = get_cycles();
   194     start = get_cycles();
   195     timeout = cpu_khz; // 1ms
   195     timeout = cpu_khz; // 1ms
   196 
   196 
   197     do
   197     while (1)
   198     {
   198     {
       
   199         udelay(10);
       
   200 
   199         ec_command_init_nprd(&command, slave->station_address, 0x808, 8);
   201         ec_command_init_nprd(&command, slave->station_address, 0x808, 8);
   200         if (unlikely(ec_master_simple_io(master, &command))) {
   202         if (unlikely(ec_master_simple_io(master, &command))) {
   201             EC_ERR("Mailbox checking failed on slave %i!\n",
   203             EC_ERR("Mailbox checking failed on slave %i!\n",
   202                    slave->ring_position);
   204                    slave->ring_position);
   203             return -1;
   205             return -1;
   206         end = get_cycles();
   208         end = get_cycles();
   207 
   209 
   208         if (EC_READ_U8(command.data + 5) & 8) { // Written bit is high
   210         if (EC_READ_U8(command.data + 5) & 8) { // Written bit is high
   209             break;
   211             break;
   210         }
   212         }
   211     }
   213 
   212     while (likely((end - start) < timeout));
   214         if (unlikely((end - start) >= timeout)) {
   213 
   215             EC_ERR("Mailbox check on slave %i timed out.\n",
   214     if (unlikely((end - start) >= timeout)) {
   216                    slave->ring_position);
   215         EC_ERR("Mailbox check on slave %i timed out.\n", slave->ring_position);
   217             return -1;
   216         return -1;
   218         }
   217     }
   219     }
   218 
   220 
   219     ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6);
   221     ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6);
   220     if (unlikely(ec_master_simple_io(master, &command))) {
   222     if (unlikely(ec_master_simple_io(master, &command))) {
   221         EC_ERR("Mailbox receiving failed on slave %i!\n",
   223         EC_ERR("Mailbox receiving failed on slave %i!\n",