int main() { set_gpio(MGCARD_PORT,MGCARD_PORT_NUM,HIGH); //mifate进入工作模式 open_driver(MGCARD,O_RDONLY); //打开磁条卡设备 gettimeofday(&begintime, NULL); //读取系统时间 while(1) { gettimeofday(&endtime, NULL ); //读取系统时间 if(read(Drivers[MGCARD].fd,buf,2112)!=-1) //读取磁条卡信息 { /* printf("\n"); for(i = 753; i < 1035; i++){ if(i%30 == 0)printf("\n"); printf("%x ",buf[i]); } */ covert_data(buf); //转换磁条卡数据 set_gpio(MGCARD_PORT,MGCARD_PORT_NUM,LOW); //mifare进入低功耗模式 return 0; } if((endtime.tv_sec-begintime.tv_sec) > 10) { printf("\n\nCharge overtime!\n\n"); close(Drivers[MGCARD].fd); set_gpio(MGCARD_PORT,MGCARD_PORT_NUM,LOW); //mifare进入低功耗模式 return; } } }
/* The constructor also initialises the rangefinder. Note that this constructor is not called until detect() returns true, so we already know that we should setup the rangefinder */ AP_RangeFinder_PX4::AP_RangeFinder_PX4(RangeFinder &_ranger, uint8_t instance, RangeFinder::RangeFinder_State &_state) : AP_RangeFinder_Backend(_ranger, instance, _state), _last_max_distance_cm(-1), _last_min_distance_cm(-1) { _fd = open_driver(); // consider this path used up num_px4_instances++; if (_fd == -1) { hal.console->printf("Unable to open PX4 rangefinder %u\n", num_px4_instances); state.healthy = false; return; } // average over up to 20 samples if (ioctl(_fd, SENSORIOCSQUEUEDEPTH, 20) != 0) { hal.console->printf("Failed to setup range finder queue\n"); state.healthy = false; return; } state.healthy = true; }
ProcessState::ProcessState() : mDriverFD(open_driver()) , mVMStart(MAP_FAILED) , mManagesContexts(false) , mBinderContextCheckFunc(NULL) , mBinderContextUserData(NULL) , mThreadPoolStarted(false) , mThreadPoolSeq(1) { if (mDriverFD >= 0) { // XXX Ideally, there should be a specific define for whether we // have mmap (or whether we could possibly have the kernel module // availabla). #if !defined(HAVE_WIN32_IPC) // mmap the binder, providing a chunk of virtual address space to receive transactions. mVMStart = mmap(0, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0); if (mVMStart == MAP_FAILED) { // *sigh* ALOGE("Using /dev/binder failed: unable to mmap transaction memory.\n"); close(mDriverFD); mDriverFD = -1; } #else mDriverFD = -1; #endif } LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver could not be opened. Terminating."); }
/* see if the PX4 driver is available */ bool AP_RangeFinder_PX4::detect(RangeFinder &_ranger, uint8_t instance) { int fd = open_driver(); if (fd == -1) { return false; } close(fd); return true; }
int main() { set_gpio('G',9,1); open_driver(PSAM1,O_RDWR); //打开PSAM小卡设备 if(Drivers[PSAM1].fd==-1) { printf("open device error\n"); return; } coldreset(); random_num(); close(Drivers[PSAM1].fd); }
static int usalo_open(SCSI *usalp, char *device) { int busno = usal_scsibus(usalp); int tgt = usal_target(usalp); int tlun = usal_lun(usalp); if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) { errno = EINVAL; if (usalp->errstr) snprintf(usalp->errstr, SCSI_ERRSTR_SIZE, "Illegal value for busno, target or lun '%d,%d,%d'", busno, tgt, tlun); return (-1); } if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2)) { errno = EINVAL; if (usalp->errstr) snprintf(usalp->errstr, SCSI_ERRSTR_SIZE, "Open by 'devname' not supported on this OS"); return (-1); } if (usalp->local == NULL) { usalp->local = malloc(sizeof (struct usal_local)); if (usalp->local == NULL) return (0); } if (!open_driver(usalp)) /* Try to open ASPI-Router */ return (-1); atexit(exit_func); /* Install Exit Function which closes the ASPI-Router */ /* * Success after all */ return (1); }
ProcessState() : mDriverFD(open_driver()) {}
//(DEV_UID *dev_uid, uint32_t device_type, uint32_t device_number) device_t* ressource_open(DEV_UID *virt_dev_uid, int32_t device_type, int32_t device_number){ //DEV_UID* real_UID = malloc(sizeof(DEV_UID)); DEV_UID* temp_UID = malloc(sizeof(DEV_UID)); virtual_dev_t *virtual_dev = (virtual_dev_t*)malloc(sizeof(virtual_dev_t)); virtual_dev->real_uid = (DEV_UID*)malloc(sizeof(DEV_UID)); virtual_dev_t *virtual_temp = NULL; device_t* device; any_t tmp; // virtual_devic zusammen bauen switch(device_type){ case(AP7000_UART_DEVICE): device = open_driver(temp_UID, AP7000_UART_DEVICE, device_number); virtual_dev->requested_device_type = device; virtual_dev->vdev_rxbuf = malloc(sizeof(SerialBuffer)); virtual_dev->vdev_txbuf = malloc(sizeof(SerialBuffer)); SerialBuffer_ctor( (SerialBuffer*)(virtual_dev->vdev_rxbuf) ); SerialBuffer_ctor( (SerialBuffer*)(virtual_dev->vdev_txbuf) ); uart1_set_rx_and_tx_buffer((SerialBuffer*)virtual_dev->vdev_txbuf,(SerialBuffer*)virtual_dev->vdev_rxbuf); break; case(AP7000_LED_DEVICE): break; default: break; } switch (*temp_UID) { case DEV_NOT_FREE: //generate new virtual UID an add to map *virt_dev_uid = generate_Virtual_UID(); //Find real uid in hashmap with key: device_type|device_number //hashmap_get(device_mapm) if(hashmap_get(device_to_real_uid_map,device_type|device_number,&tmp) == MAP_OK){ *temp_UID = *((DEV_UID*)tmp); virtual_dev->real_uid = temp_UID; }else{ while(1){} } if(hashmap_get(device_to_real_uid_map,device_type|device_number,&tmp) == MAP_OK){ hashmap_put(virt_uid_to_virt_dev_map,*virt_dev_uid, virtual_dev); // save pid to virtual_dev hashmap_put(pid_to_virt_dev_map, ptrRunningTask->pid, virtual_dev); virtual_dev->current_device_type = dev_null; return device; }else{ while(1){} } case DEV_NOT_FOUND: //TODO you're f****d... break; } *virt_dev_uid = generate_Virtual_UID(); *virtual_dev->real_uid = *temp_UID; virtual_dev->current_device_type = virtual_dev->requested_device_type; //add as first element hashmap_put(device_to_real_uid_map,device_type|device_number,(any_t)temp_UID); if(hashmap_get(device_to_real_uid_map,device_type|device_number,&tmp) == MAP_OK){ if(*temp_UID!=*(DEV_UID*)tmp){ while(1){}; } hashmap_put(virt_uid_to_virt_dev_map,*virt_dev_uid, virtual_dev); }else{ while(1){} } // save pid to virtual_dev hashmap_put(pid_to_virt_dev_map, ptrRunningTask->pid, virtual_dev); return device; }