master/slave.c
changeset 113 a3dbd6bc8fce
parent 104 052bc82d5442
child 114 e4b4b5a85e75
equal deleted inserted replaced
112:eec7639c7be9 113:a3dbd6bc8fce
   150     // den Status auslesen, bis das Bit weg ist.
   150     // den Status auslesen, bis das Bit weg ist.
   151 
   151 
   152     start = get_cycles();
   152     start = get_cycles();
   153     timeout = cpu_khz; // 1ms
   153     timeout = cpu_khz; // 1ms
   154 
   154 
   155     do
   155     while (1)
   156     {
   156     {
       
   157         udelay(10);
       
   158 
   157         ec_command_init_nprd(&command, slave->station_address, 0x502, 10);
   159         ec_command_init_nprd(&command, slave->station_address, 0x502, 10);
   158         if (unlikely(ec_master_simple_io(slave->master, &command))) {
   160         if (unlikely(ec_master_simple_io(slave->master, &command))) {
   159             EC_ERR("Getting SII-read status failed on slave %i!\n",
   161             EC_ERR("Getting SII-read status failed on slave %i!\n",
   160                    slave->ring_position);
   162                    slave->ring_position);
   161             return -1;
   163             return -1;
   163 
   165 
   164         end = get_cycles();
   166         end = get_cycles();
   165 
   167 
   166         if (likely((EC_READ_U8(command.data + 1) & 0x81) == 0)) {
   168         if (likely((EC_READ_U8(command.data + 1) & 0x81) == 0)) {
   167             memcpy(target, command.data + 6, 4);
   169             memcpy(target, command.data + 6, 4);
   168             break;
   170             return 0;
   169         }
   171         }
   170     }
   172 
   171     while (likely((end - start) < timeout));
   173         if (unlikely((end - start) >= timeout)) {
   172 
   174             EC_ERR("SSI-read. Slave %i timed out!\n", slave->ring_position);
   173     if (unlikely((end - start) >= timeout)) {
   175             return -1;
   174         EC_ERR("SSI-read. Slave %i timed out!\n", slave->ring_position);
   176         }
   175         return -1;
   177     }
   176     }
       
   177 
       
   178     return 0;
       
   179 }
   178 }
   180 
   179 
   181 /*****************************************************************************/
   180 /*****************************************************************************/
   182 
   181 
   183 /**
   182 /**
   206     }
   205     }
   207 
   206 
   208     start = get_cycles();
   207     start = get_cycles();
   209     timeout = cpu_khz; // 1ms
   208     timeout = cpu_khz; // 1ms
   210 
   209 
   211     do
   210     while (1)
   212     {
   211     {
       
   212         udelay(100); // Dem Slave etwas Zeit lassen...
       
   213 
   213         ec_command_init_nprd(&command, slave->station_address, 0x0130, 2);
   214         ec_command_init_nprd(&command, slave->station_address, 0x0130, 2);
   214         if (unlikely(ec_master_simple_io(slave->master, &command))) {
   215         if (unlikely(ec_master_simple_io(slave->master, &command))) {
   215             EC_WARN("State %02X acknowledge checking failed on slave %i!\n",
   216             EC_WARN("State %02X acknowledge checking failed on slave %i!\n",
   216                     state, slave->ring_position);
   217                     state, slave->ring_position);
   217             return;
   218             return;
   229         if (likely(EC_READ_U8(command.data) == state)) {
   230         if (likely(EC_READ_U8(command.data) == state)) {
   230             EC_INFO("Acknowleged state %02X on slave %i.\n", state,
   231             EC_INFO("Acknowleged state %02X on slave %i.\n", state,
   231                     slave->ring_position);
   232                     slave->ring_position);
   232             return;
   233             return;
   233         }
   234         }
   234     }
   235 
   235     while (likely((end - start) < timeout));
   236         if (unlikely((end - start) >= timeout)) {
   236 
   237             EC_WARN("Could not check state acknowledgement %02X of slave %i -"
   237     if (unlikely((end - start) >= timeout)) {
   238                     " Timeout while checking!\n", state, slave->ring_position);
   238         EC_WARN("Could not check state acknowledgement %02X of slave %i -"
   239             return;
   239                 " Timeout while checking!\n", state, slave->ring_position);
   240         }
   240         return;
       
   241     }
   241     }
   242 }
   242 }
   243 
   243 
   244 /*****************************************************************************/
   244 /*****************************************************************************/
   245 
   245 
   269     }
   269     }
   270 
   270 
   271     start = get_cycles();
   271     start = get_cycles();
   272     timeout = cpu_khz; // 1ms
   272     timeout = cpu_khz; // 1ms
   273 
   273 
   274     do
   274     while (1)
   275     {
   275     {
   276         udelay(100); // Dem Slave etwas Zeit lassen...
   276         udelay(100); // Dem Slave etwas Zeit lassen...
   277 
   277 
   278         ec_command_init_nprd(&command, slave->station_address, 0x0130, 2);
   278         ec_command_init_nprd(&command, slave->station_address, 0x0130, 2);
   279         if (unlikely(ec_master_simple_io(slave->master, &command))) {
   279         if (unlikely(ec_master_simple_io(slave->master, &command))) {
   292             return -1;
   292             return -1;
   293         }
   293         }
   294 
   294 
   295         if (likely(EC_READ_U8(command.data) == (state & 0x0F))) {
   295         if (likely(EC_READ_U8(command.data) == (state & 0x0F))) {
   296             // State change successful
   296             // State change successful
   297             break;
   297             return 0;
   298         }
   298         }
   299     }
   299 
   300     while (likely((end - start) < timeout));
   300         if (unlikely((end - start) >= timeout)) {
   301 
   301             EC_ERR("Could not check state %02X of slave %i - Timeout!\n",
   302     if (unlikely((end - start) >= timeout)) {
   302                    state, slave->ring_position);
   303         EC_ERR("Could not check state %02X of slave %i - Timeout!\n", state,
   303             return -1;
   304                slave->ring_position);
   304         }
   305         return -1;
   305     }
   306     }
       
   307 
       
   308     return 0;
       
   309 }
   306 }
   310 
   307 
   311 /*****************************************************************************/
   308 /*****************************************************************************/
   312 
   309 
   313 /**
   310 /**