56 void ec_fsm_master_wait(ec_fsm_t *); |
56 void ec_fsm_master_wait(ec_fsm_t *); |
57 void ec_fsm_master_scan(ec_fsm_t *); |
57 void ec_fsm_master_scan(ec_fsm_t *); |
58 void ec_fsm_master_conf(ec_fsm_t *); |
58 void ec_fsm_master_conf(ec_fsm_t *); |
59 |
59 |
60 void ec_fsm_slave_start_reading(ec_fsm_t *); |
60 void ec_fsm_slave_start_reading(ec_fsm_t *); |
|
61 void ec_fsm_slave_read_status(ec_fsm_t *); |
61 void ec_fsm_slave_read_base(ec_fsm_t *); |
62 void ec_fsm_slave_read_base(ec_fsm_t *); |
62 void ec_fsm_slave_read_dl(ec_fsm_t *); |
63 void ec_fsm_slave_read_dl(ec_fsm_t *); |
63 void ec_fsm_slave_prepare_sii(ec_fsm_t *); |
64 void ec_fsm_slave_prepare_sii(ec_fsm_t *); |
64 void ec_fsm_slave_read_sii(ec_fsm_t *); |
65 void ec_fsm_slave_read_sii(ec_fsm_t *); |
65 void ec_fsm_slave_category_header(ec_fsm_t *); |
66 void ec_fsm_slave_category_header(ec_fsm_t *); |
423 |
424 |
424 // write station address |
425 // write station address |
425 ec_command_apwr(command, fsm->slave->ring_position, 0x0010, 2); |
426 ec_command_apwr(command, fsm->slave->ring_position, 0x0010, 2); |
426 EC_WRITE_U16(command->data, fsm->slave->station_address); |
427 EC_WRITE_U16(command->data, fsm->slave->station_address); |
427 ec_master_queue_command(fsm->master, command); |
428 ec_master_queue_command(fsm->master, command); |
428 fsm->slave_state = ec_fsm_slave_read_base; |
429 fsm->slave_state = ec_fsm_slave_read_status; |
429 } |
430 } |
430 |
431 |
431 /*****************************************************************************/ |
432 /*****************************************************************************/ |
432 |
433 |
433 /** |
434 /** |
434 Slave state: Read base. |
435 Slave state: Read status. |
435 */ |
436 */ |
436 |
437 |
437 void ec_fsm_slave_read_base(ec_fsm_t *fsm) |
438 void ec_fsm_slave_read_status(ec_fsm_t *fsm) |
438 { |
439 { |
439 ec_command_t *command = &fsm->command; |
440 ec_command_t *command = &fsm->command; |
440 |
441 |
441 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
442 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
442 EC_ERR("FSM failed to write station address of slave %i.\n", |
443 EC_ERR("FSM failed to write station address of slave %i.\n", |
443 fsm->slave->ring_position); |
444 fsm->slave->ring_position); |
444 fsm->slave_state = ec_fsm_slave_end; |
445 fsm->slave_state = ec_fsm_slave_end; |
445 return; |
446 return; |
|
447 } |
|
448 |
|
449 // read AL status |
|
450 ec_command_nprd(command, fsm->slave->station_address, 0x0130, 2); |
|
451 ec_master_queue_command(fsm->master, command); |
|
452 fsm->slave_state = ec_fsm_slave_read_base; |
|
453 } |
|
454 |
|
455 /*****************************************************************************/ |
|
456 |
|
457 /** |
|
458 Slave state: Read base. |
|
459 */ |
|
460 |
|
461 void ec_fsm_slave_read_base(ec_fsm_t *fsm) |
|
462 { |
|
463 ec_command_t *command = &fsm->command; |
|
464 ec_slave_t *slave = fsm->slave; |
|
465 |
|
466 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
|
467 EC_ERR("FSM failed to read AL status of slave %i.\n", |
|
468 fsm->slave->ring_position); |
|
469 fsm->slave_state = ec_fsm_slave_end; |
|
470 return; |
|
471 } |
|
472 |
|
473 slave->current_state = EC_READ_U8(command->data); |
|
474 if (slave->current_state & EC_ACK) { |
|
475 EC_WARN("Slave %i has status error bit set (0x%02X)!\n", |
|
476 slave->ring_position, slave->current_state); |
|
477 slave->current_state &= 0x0F; |
446 } |
478 } |
447 |
479 |
448 // read base data |
480 // read base data |
449 ec_command_nprd(command, fsm->slave->station_address, 0x0000, 6); |
481 ec_command_nprd(command, fsm->slave->station_address, 0x0000, 6); |
450 ec_master_queue_command(fsm->master, command); |
482 ec_master_queue_command(fsm->master, command); |