/************************************************************************ * Function: int advdrv_init_one * * Description: Pnp to initialize the device, and allocate resource for the device. * Parameters: dev -Points to the pci_dev device ent -Points to pci_device_id including the device info. *************************************************************************/ static int __devinit advdrv_init_one(struct pci_dev *dev, const struct pci_device_id *ent) { private_data *privdata = NULL; adv_device *device = NULL; int err; if ((err = pci_enable_device(dev)) != 0) { KdPrint(KERN_ERR ":pci_enable_device failed\n"); return err; } device = (adv_device *)kmalloc(sizeof(adv_device), GFP_KERNEL); privdata = kmalloc(sizeof(private_data), GFP_KERNEL); if ((!device) || (!privdata)) { kfree(device); kfree(privdata); PCRIT("Could not kmalloc space for device!"); return -ENOMEM; } memset(device, 0, sizeof(adv_device)); memset(privdata, 0, sizeof(private_data) ); /* for new event mechanism */ init_waitqueue_head(&privdata->event_wait); /* get the device type */ privdata->device_type = dev->device; privdata->pci_slot = PCI_SLOT(dev->devfn); privdata->pci_bus = dev->bus->number; if (privdata->device_type == PCI1736) { privdata->iobase = dev->resource[0].start; privdata->iolength = dev->resource[0].end - dev->resource[0].start; } else { privdata->iobase = dev->resource[2].start;// & ~1UL; privdata->iolength = dev->resource[2].end -dev->resource[2].start; } privdata->irq=dev->irq; privdata->sigpid=0; if (request_region(privdata->iobase, privdata->iolength, "PCI-1730" ) == NULL) { kfree(device); kfree(privdata); return -EFAULT; } spin_lock_init(&privdata->spinlock); adv_process_info_header_init(&privdata->ptr_process_info); advOutp(privdata, 0x10, 0x0f); if (request_irq(privdata->irq, pci1730_interrupt_handler, SA_SHIRQ, "adv1730", privdata)) { release_region(privdata->iobase, privdata->iolength); kfree(device); kfree(privdata); return -EFAULT; } /* get the device boardID */ adv_get_device_boardID(privdata); adv_init_device_do_range(privdata); adv_init_device_di_range(privdata); _ADV_SET_DEVICE_PRIVDATA(device, privdata); _ADV_SET_DEVICE_BOARDID(device,privdata->boardID); _ADV_SET_DEVICE_IOBASE(device, privdata->iobase); _ADV_SET_DEVICE_IRQ(device, privdata->irq); _ADV_SET_DEVICE_SLOT(device, privdata->pci_slot); pci_set_drvdata(dev, device); adv_clear_device_int_flag(privdata); adv_disable_device_int(privdata); advOutp(privdata, 0x08, 0); switch(privdata->device_type) { case PCI1730: advdrv_device_set_devname(device, "pci1730"); break; case PCI1733: advdrv_device_set_devname(device, "pci1733"); break; case PCI1734: advdrv_device_set_devname(device, "pci1734"); break; case PCI1736: advdrv_device_set_devname(device, "pci1736up"); break; default: break; } advdrv_add_device( &pci1730_driver, device ); printk("Add a Advantech PCI%x device:boardID=%d;iobase=0x%lx;irq=%x;slot=%x.\n",dev->device,privdata->boardID,privdata->iobase, privdata->irq, privdata->pci_slot ); return SUCCESS; }
/** Evaluation function for 'fprops_Tvsx_ph' @return 0 on success */ int fprops_Tvsx_ph_calc(struct BBoxInterp *bbox, int ninputs, int noutputs, double *inputs, double *outputs, double *jacobian ){ CALCPREPARE(2,4); static const PureFluid *last = NULL; static double p,h,T,v,s,x; if(last == FLUID && p == inputs[0] && h == inputs[1]){ outputs[0] = T; outputs[1] = v; outputs[2] = s; outputs[3] = x; return 0; } p = inputs[0]; h = inputs[1]; double hft, pt, rhoft,rhogt; fprops_triple_point(&pt,&rhoft,&rhogt,FLUID,&err); if(err){ ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to solve triple point for %s.",FLUID->name); return 5; } FluidState Sft = fprops_set_Trho(TTRIP(FLUID),rhoft,FLUID,&err); hft = fprops_h(Sft, &err); if(h < hft){ ERROR_REPORTER_HERE(ASC_PROG_ERR ,"Input enthalpy %f kJ/kg is below triple point liquid enthalpy %f kJ/kg" ,h/1e3,hft/1e3 ); return 6; } if(p < pt){ ERROR_REPORTER_HERE(ASC_PROG_ERR ,"Input pressure %f bar is below triple point pressure %f bar" ,p/1e5,pt/1e5 ); outputs[0] = TTRIP(FLUID); outputs[1] = 1./ rhoft; outputs[2] = FLUID->s_fn(TTRIP(FLUID), rhoft, FLUID->data, &err); outputs[3] = 0; return 7; } if(p < PCRIT(FLUID)){ double T_sat, rho_f, rho_g; fprops_sat_p(p, &T_sat, &rho_f, &rho_g, FLUID, &err); if(err){ ERROR_REPORTER_HERE(ASC_PROG_ERR , "Failed to solve saturation state of %s for p = %f bar < pc (= %f bar)" , FLUID->name, p/1e5,PCRIT(FLUID)/1e5 ); outputs[0] = TTRIP(FLUID); outputs[1] = 1./rhoft; outputs[2] = FLUID->s_fn(TTRIP(FLUID), rhoft, FLUID->data, &err); outputs[3] = 0; return 8; } FluidState Sf = fprops_set_Trho(T_sat,rho_f,FLUID,&err); FluidState Sg = fprops_set_Trho(T_sat,rho_g,FLUID,&err); double hf = fprops_h(Sf, &err); double hg = fprops_h(Sg, &err); if(hf < h && h < hg){ /* saturated */ double vf = 1./rho_f; double vg = 1./rho_g; double sf = fprops_s(Sf, &err); double sg = fprops_s(Sg, &err); T = T_sat; x = (h - hf) /(hg - hf); v = vf + x * (vg-vf); s = sf + x * (sg-sf); last = FLUID; outputs[0] = T; outputs[1] = v; outputs[2] = s; outputs[3] = x; #ifdef ASC_FPROPS_DEBUG ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Saturated state, p=%f bar, h = %f kJ/kg",p/1e5,h/1e3); #endif return 0; } } double rho; fprops_solve_ph(p,h, &T, &rho, 0, FLUID, &err); if(err){ ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to solve for (p,h): %s",fprops_error(err)); return 9; } /* non-saturated */ v = 1./rho; FluidState S = fprops_set_Trho(T,rho,FLUID,&err); s = fprops_s(S, &err); x = (v > 1./RHOCRIT(FLUID)) ? 1 : 0; last = FLUID; outputs[0] = T; outputs[1] = v; outputs[2] = s; outputs[3] = x; #ifdef ASC_FPROPS_DEBUG ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Non-saturated state, p = %f bar, h = %f kJ/kg",p/1e5,h/1e3); #endif return 0; }