master/master.c
changeset 578 f402b4bd2f4d
parent 576 158c5a3d0a2a
child 579 17c6fd3b076e
equal deleted inserted replaced
577:db34078f34cc 578:f402b4bd2f4d
   114     atomic_set(&master->available, 1);
   114     atomic_set(&master->available, 1);
   115     master->index = index;
   115     master->index = index;
   116 
   116 
   117     master->device = NULL;
   117     master->device = NULL;
   118     master->main_device_id = main_id;
   118     master->main_device_id = main_id;
       
   119     master->backup_device = NULL;
   119     master->backup_device_id = backup_id;
   120     master->backup_device_id = backup_id;
   120     init_MUTEX(&master->device_sem);
   121     init_MUTEX(&master->device_sem);
   121 
   122 
   122     master->mode = EC_MASTER_MODE_ORPHANED;
   123     master->mode = EC_MASTER_MODE_ORPHANED;
   123 
   124 
   847     
   848     
   848     master->thread_id = 0;
   849     master->thread_id = 0;
   849     complete_and_exit(&master->thread_exit, 0);
   850     complete_and_exit(&master->thread_exit, 0);
   850 }
   851 }
   851 
   852 
       
   853 
       
   854 /*****************************************************************************/
       
   855 
       
   856 ssize_t ec_master_device_info(const ec_device_t *device,
       
   857         const ec_device_id_t *dev_id,
       
   858         char *buffer)
       
   859 {
       
   860     unsigned int frames_lost;
       
   861     off_t off = 0;
       
   862     
       
   863     off += ec_device_id_print(dev_id, buffer + off);
       
   864     
       
   865     if (device) {
       
   866         off += sprintf(buffer + off, " (connected).\n");      
       
   867         off += sprintf(buffer + off, "    Frames sent:     %u\n",
       
   868                 device->tx_count);
       
   869         off += sprintf(buffer + off, "    Frames received: %u\n",
       
   870                 device->rx_count);
       
   871         frames_lost = device->tx_count - device->rx_count;
       
   872         if (frames_lost) frames_lost--;
       
   873         off += sprintf(buffer + off, "    Frames lost:     %u\n", frames_lost);
       
   874     }
       
   875     else if (dev_id->type != ec_device_id_empty) {
       
   876         off += sprintf(buffer + off, " (WAITING).\n");      
       
   877     }
       
   878     else {
       
   879         off += sprintf(buffer + off, ".\n");
       
   880     }
       
   881     
       
   882     return off;
       
   883 }
       
   884 
   852 /*****************************************************************************/
   885 /*****************************************************************************/
   853 
   886 
   854 /**
   887 /**
   855    Formats master information for SysFS read access.
   888    Formats master information for SysFS read access.
   856    \return number of bytes written
   889    \return number of bytes written
   861                        )
   894                        )
   862 {
   895 {
   863     off_t off = 0;
   896     off_t off = 0;
   864     ec_eoe_t *eoe;
   897     ec_eoe_t *eoe;
   865     uint32_t cur, sum, min, max, pos, i;
   898     uint32_t cur, sum, min, max, pos, i;
   866     unsigned int frames_lost;
   899 
   867 
       
   868     off += sprintf(buffer + off, "\nVersion: %s", ec_master_version_str);
       
   869     off += sprintf(buffer + off, "\nMode: ");
   900     off += sprintf(buffer + off, "\nMode: ");
   870     switch (master->mode) {
   901     switch (master->mode) {
   871         case EC_MASTER_MODE_ORPHANED:
   902         case EC_MASTER_MODE_ORPHANED:
   872             off += sprintf(buffer + off, "ORPHANED");
   903             off += sprintf(buffer + off, "ORPHANED");
   873             break;
   904             break;
   879             break;
   910             break;
   880     }
   911     }
   881 
   912 
   882     off += sprintf(buffer + off, "\nSlaves: %i\n",
   913     off += sprintf(buffer + off, "\nSlaves: %i\n",
   883                    master->slave_count);
   914                    master->slave_count);
   884     off += sprintf(buffer + off, "\nDevice:\n");
   915 
   885     off += sprintf(buffer + off, "  Frames sent:     %u\n",
   916     off += sprintf(buffer + off, "\nDevices:\n");
   886 		   master->device->tx_count);
   917     
   887     off += sprintf(buffer + off, "  Frames received: %u\n",
   918     if (down_interruptible(&master->device_sem)) {
   888 		   master->device->rx_count);
   919         EC_ERR("Interrupted while waiting for device!\n");
   889     frames_lost = master->device->tx_count - master->device->rx_count;
   920         return -EINVAL;
   890     if (frames_lost) frames_lost--;
   921     }
   891     off += sprintf(buffer + off, "  Frames lost:     %u\n", frames_lost);
   922     
       
   923     off += sprintf(buffer + off, "  Main: ");
       
   924     off += ec_master_device_info(master->device,
       
   925             master->main_device_id, buffer + off);
       
   926     off += sprintf(buffer + off, "  Backup: ");
       
   927     off += ec_master_device_info(master->backup_device,
       
   928             master->backup_device_id, buffer + off);
       
   929 
       
   930     up(&master->device_sem);
   892 
   931 
   893     off += sprintf(buffer + off, "\nTiming (min/avg/max) [us]:\n");
   932     off += sprintf(buffer + off, "\nTiming (min/avg/max) [us]:\n");
   894 
   933 
   895     sum = 0;
   934     sum = 0;
   896     min = 0xFFFFFFFF;
   935     min = 0xFFFFFFFF;