void ext_flash_read() { uint32_t address = 0; //uint8_t data [534]; //uint8_t data[80]; uint16_t i; comBuf pkt; for (i = 0; i < sizeof (data); i++) { data[i] = '0'; } dev_ioctl (DEV_ATMEL_FLASH, DEV_SEEK, address); dev_read (DEV_ATMEL_FLASH, data, sizeof (data)); //printf ("%s", (char *)data); pkt.size = 3; pkt.data[0] = 245; for (i = 0; i < sizeof (data); i++) { //printf ("%c", data[i]); *((uint16_t *)&pkt.data[1]) = data[i]; com_send (IFACE_SERIAL, &pkt); } //printf('\n'); }
static int _read_uuids(struct disk_list *data) { unsigned num_read = 0; struct uuid_list *ul; char buffer[NAME_LEN] __attribute((aligned(8))); uint64_t pos = data->pvd.pv_uuidlist_on_disk.base; uint64_t end = pos + data->pvd.pv_uuidlist_on_disk.size; while (pos < end && num_read < data->vgd.pv_cur) { if (!dev_read(data->dev, pos, sizeof(buffer), buffer)) return_0; if (!(ul = dm_pool_alloc(data->mem, sizeof(*ul)))) return_0; memcpy(ul->uuid, buffer, NAME_LEN); ul->uuid[NAME_LEN - 1] = '\0'; dm_list_add(&data->uuids, &ul->list); pos += NAME_LEN; num_read++; } return 1; }
void echo() { static int tty = 1; char name[] = "tty*", buf[256]; Device *dev; lock(); name[3] = '0' + (tty ++); unlock(); while (1) { dev = hal_get(name); if (dev != NULL) { dev_write(dev, 0, name, 4); dev_write(dev, 0, "# ", 2); int i, nread = dev_read(dev, 0, buf, 255); buf[nread] = 0; for (i = 0; i < nread; i ++) { if (buf[i] >= 'a' && buf[i] <= 'z') { buf[i] += 'A' - 'a'; } } dev_write(dev, 0, "Got: ", 5); dev_write(dev, 0, buf, nread); dev_write(dev, 0, "\n", 1); } else { // printf("%s\n", name); } } }
void mbr_rec(device_t *dev, int32_t id_base, uint64_t off, uint64_t base) { /* partition counter */ int32_t i; /* extended boot record? */ int32_t is_ext = !!base; /* create buffer */ mbr_t *buf = kmalloc(512); /* read partition table */ dev_read(dev, off*512, 512, (char *) buf); /* make sure signature is valid */ if (buf->signature == 0xAA55) { /* loop over partition entries */ for (i = 0; i < 4; i++) { /* partition existing? */ if (buf->partents[i].parttype) { /* calc new_id */ int32_t new_id = id_base+i; /* calc new base */ int64_t new_base = is_ext ? base : buf->partents[i].first_lba; /* calc new off */ int64_t new_off; if (is_ext && i == 1) { new_off = buf->partents[i].first_lba + base; } else { new_off = buf->partents[i].first_lba + off; } /* add if primary partition or logical drive (not ebr ptr) */ if (!is_ext || !i) { device_t *t; class_t cls; reslist_t reslist = {0, NULL}; /* setup partition class */ cls.bus = BUS_DISK; cls.base = BASE_DISK_PARTITION; cls.sub = new_id; cls.progif = dev->devid; /* print info */ printk("Entry %d: %d (size: %d)\n", new_id, (int32_t) new_off, buf->partents[i].sectcount); /* add device */ dev_add(&t, dev->child_bus, cls, reslist, &new_off); } /* if extended partition, go into */ if (buf->partents[i].parttype == 0x05 || buf->partents[i].parttype == 0x0F) { mbr_rec(dev, new_id<5?5:new_id, new_off, new_base); } } } } /* deallocate buffer */ kfree(buf); }
// builds a packet in the following format: // [uint8_t] device code // [void* ] device reading // repeat. uint8_t read_sensors(comBuf* out) { uint16_t scratch; uint8_t index = 0; // the first item in the packet will be // a 4-byte hardware ID. uint32_t hid; dev_read(DEV_HARDWARE_ID, &hid, sizeof(hid)); out->data[index++] = DEV_HARDWARE_ID; buf_insert32(out->data, index, hid); index += sizeof(hid); #ifdef PLATFORM_TELOSB // read the temperature value dev_read(DEV_MSP_TEMPERATURE, &scratch, sizeof(scratch)); out->data[index++] = DEV_MSP_TEMPERATURE; buf_insert16(out->data, index, scratch); index += sizeof(scratch); dev_read(DEV_MSP_HUMIDITY, &scratch, sizeof(scratch)); // and the humidity value out->data[index++] = DEV_MSP_HUMIDITY; buf_insert16(out->data, index, scratch); index += sizeof(scratch); #endif #ifdef ARCH_AVR // TODO: Read from MICAZ/MICA2 sensors/GPS, etc. #endif out->data[index] = simple_crc(out->data, index); return ++index; }
int abit_is_on(Dev* device, int inode_idx) { int byteno = inode_idx / 8; int offset = inode_idx % 8; char byte; dev_read(&byte, sizeof(char), ABIT_BYTE_ADDR(byteno), device); return bm_is_on(&byte, offset); }
void get_rssi() { uint16_t rssi_val; dev_open(DEV_AVR_RSSI); dev_read(DEV_AVR_RSSI, &rssi_val, sizeof(rssi_val)); dev_close(DEV_AVR_RSSI); printf("rssi %d\n",rssi_val); }
static void get_cb() { boot_control_block_t cb; dev_ioctl(DEV_AVR_EEPROM, DEV_SEEK, CONTROL_BLOCK_ADDR); dev_read(DEV_AVR_EEPROM, (uint8_t *)&cb, sizeof(cb)); printf("Node id: %d, Byte Count: %l, Start addr: %l, Reprogram: %d\n", cb.node_id, cb.byte_count, cb.start_addr, cb.reprogram); }
void send_thread () { send_pkt.size = 2; //2 bytes com_mode(IFACE_RADIO, IF_LISTEN); while(1) { mos_led_toggle(0); #ifdef PLATFORM_TELOSB dev_read (DEV_MSP_TEMPERATURE, &send_pkt.data[0], 2); #else dev_read (DEV_MICA2_TEMP, &send_pkt.data[0], 1); #endif com_send(IFACE_RADIO, &send_pkt); mos_thread_sleep(1000); } }
static int _read_lvd(struct device *dev, uint64_t pos, struct lv_disk *disk) { if (!dev_read(dev, pos, sizeof(*disk), disk)) return_0; _xlate_lvd(disk); return 1; }
static int _read_pvd(struct device *dev, struct pv_disk *pvd) { if (!dev_read(dev, UINT64_C(0), sizeof(*pvd), pvd)) { log_very_verbose("Failed to read PV data from %s", dev_name(dev)); return 0; } return munge_pvd(dev, pvd); }
void eep_read () { uint16_t address = 100; uint8_t data [20]; memset (data, 0, sizeof (data)); dev_ioctl (DEV_AVR_EEPROM, DEV_SEEK, address); dev_read (DEV_AVR_EEPROM, data, sizeof (data)); printf ("%s", (char *)data); }
int Ext2FS::Init() { int i; i = dev_read( 1024, &superblock, sizeof( struct ext2fs_superblock ) ); if ( i != sizeof( struct ext2fs_superblock ) ) return -1; if ( superblock.s_magic != EXT2FS_MAGIC ) return -1; return 0; }
struct filsys *open_filesystem(vfs_devno_t devno) { struct filsys *fs; struct groupdesc *gd; unsigned int i; // Allocate file system fs = (struct filsys *) malloc(sizeof(struct filsys)); memset(fs, 0, sizeof(struct filsys)); // Allocate and read super block fs->super = (struct superblock *) malloc(SECTORSIZE); memset(fs->super, 0, SECTORSIZE); if (dev_read(devno, fs->super, SECTORSIZE, 1) != SECTORSIZE) panic("unable to read superblock"); fs->super_dirty = 0; // Check signature and version if (fs->super->signature != DFS_SIGNATURE) panic("invalid DFS signature"); if (fs->super->version != DFS_VERSION) panic("invalid DFS version"); // Set device number and block size fs->devno = devno; fs->blocksize = 1 << fs->super->log_block_size; fs->inodes_per_block = fs->blocksize / sizeof(struct inodedesc); // Initialize buffer cache fs->cache = init_buffer_pool(devno, CACHEBUFFERS, fs->blocksize); // Calculate the number of group descriptors blocks fs->groupdescs_per_block = fs->blocksize / sizeof(struct groupdesc); fs->groupdesc_blocks = (fs->super->group_count * sizeof(struct groupdesc) + fs->blocksize - 1) / fs->blocksize; // Calculate the number of block pointers per block directory page fs->log_blkptrs_per_block = fs->super->log_block_size - 2; // Read group descriptors fs->groupdesc_buffers = (struct buf **) malloc(sizeof(struct buf *) * fs->groupdesc_blocks); fs->groups = (struct group *) malloc(sizeof(struct group) * fs->super->group_count); for (i = 0; i < fs->groupdesc_blocks; i++) { fs->groupdesc_buffers[i] = get_buffer(fs->cache, fs->super->groupdesc_table_block + i); } for (i = 0; i < fs->super->group_count; i++) { gd = (struct groupdesc *) fs->groupdesc_buffers[i / fs->groupdescs_per_block]->data; gd += (i % fs->groupdescs_per_block); fs->groups[i].desc = gd; fs->groups[i].first_free_block = -1; fs->groups[i].first_free_inode = -1; } return fs; }
void gps_off(void) { uint8_t i; // set the address from which to read/write dev_ioctl(DEV_AVR_I2C, I2C_DEST_ADDR, SWITCH_1); // read the current value dev_read(DEV_AVR_I2C, &i, sizeof(i)); // mask out the appropriate bits i &= (uint8_t)(~GPS_ENABLE_MASK); // write the value back. dev_write(DEV_AVR_I2C, &i, sizeof(i)); // verify that the bits have been cleared. do { i = 0; dev_read(DEV_AVR_I2C, &i, sizeof(i)); }while((i & (GPS_ENABLE_MASK))); }
int Ext2FS::Test( ) { struct ext2fs_superblock sb; int i; i = dev_read( 1024, &sb, sizeof( struct ext2fs_superblock ) ); if ( i != sizeof( struct ext2fs_superblock ) ) return FS_UNSUPPORTED; if ( sb.s_magic != EXT2FS_MAGIC ) return FS_UNSUPPORTED; return FS_SUPPORTED; }
static int _dev_has_md_magic(struct device *dev, uint64_t sb_offset) { uint32_t md_magic; /* Version 1 is little endian; version 0.90.0 is machine endian */ if (dev_read(dev, sb_offset, sizeof(uint32_t), &md_magic) && ((md_magic == xlate32(MD_SB_MAGIC)) || (md_magic == MD_SB_MAGIC))) return 1; return 0; }
void gps_on(void) { uint8_t i; // set speed dev_ioctl(DEV_AVR_I2C, I2C_SET_BRR, 50); // set the address from which to read/write dev_ioctl(DEV_AVR_I2C, I2C_DEST_ADDR, SWITCH_1); // read the current value dev_read(DEV_AVR_I2C, &i, sizeof(i)); // set the appropriate bits. i |= GPS_ENABLE_MASK; // write the value back dev_write(DEV_AVR_I2C, &i, sizeof(i)); // verify that the bits have been written correctly. do { i = 0; dev_read(DEV_AVR_I2C, &i, sizeof(i)); }while((i & (GPS_ENABLE_MASK)) != GPS_ENABLE_MASK); }
uint32 Ext2FS::read_block( uint32 block, void* data, uint32 num ) { uint32 sector; uint32 count; sector = (block * block_size()); count = (num * block_size()); count = dev_read( sector, data, count ); return count; }
void poll() { uint8_t i; uint16_t j; uint8_t x, y; dev_mode(DEV_ADC, DEV_MODE_ON); for(i = 0; i < 40; i++) { dev_ioctl(DEV_ADC, ADC_SET_CHANNEL, 1); dev_read(DEV_ADC, &x, sizeof(x)); dev_ioctl(DEV_ADC, ADC_SET_CHANNEL, 2); dev_read(DEV_ADC, &y, sizeof(y)); printf("%C\t%C\n",x,y); for(j=0;j<0xffff;j++); for(j=0;j<0xffff;j++); for(j=0;j<0xffff;j++); for(j=0;j<0xffff;j++); } }
void gps_disable_bits(uint8_t mask) { uint8_t i; // set the address from which to read/write dev_ioctl(DEV_AVR_I2C, I2C_DEST_ADDR, SWITCH_2); // read the current value dev_read(DEV_AVR_I2C, &i, sizeof(i)); // clear the RX/TX bits i &= ~(mask); // write the value back dev_write(DEV_AVR_I2C, &i, sizeof(i)); // verify that the bits have been cleared. do { i = 0; dev_read(DEV_AVR_I2C, &i, sizeof(i)); }while(i & (mask)); // disable rx UCSR1B &= ~(1 << RXEN1); }
void start(void) { mos_led_on(1); #ifdef PLATFORM_MICA_ANY dev_mode(DEV_MICA2_LIGHT, DEV_MODE_ON); dev_read(DEV_MICA2_LIGHT,&seed,1); dev_read(DEV_MICA2_LIGHT,(&seed)+1,1); dev_mode(DEV_MICA2_LIGHT, DEV_MODE_OFF); #elif PLATFORM_TELOSB seed = adc_get_conversion16(4); #endif printf("SEED: %x\n", seed); mos_led_off(1); srand(seed); producer1_alarm.func = sem_alarm_func; consumer1_alarm.func = sem_alarm_func; producer2_alarm.func = sem_alarm_func; consumer2_alarm.func = sem_alarm_func; producer1_alarm.data = (void*)&full1; consumer1_alarm.data = (void*)&empty1; producer2_alarm.data = (void*)&full2; consumer2_alarm.data = (void*)&empty2; mos_sem_init(&empty1,5); mos_sem_init(&full1,0); mos_sem_init(&mux1,1); mos_sem_init(&empty2,5); mos_sem_init(&full2,0); mos_sem_init(&mux2,1); mos_thread_new(consumer2, 128, PRIORITY_NORMAL); mos_thread_new(consumer1, 128, PRIORITY_NORMAL); mos_thread_new(producer2, 128, PRIORITY_NORMAL); mos_thread_new(producer1, 128, PRIORITY_NORMAL); }
int WaitByte( unsigned ticks ) { unsigned char data; unsigned timeout; timeout = (ticks * MILLISEC_PER_TICK) / 100; if( ticks > 0 && timeout == 0 ) timeout = 1; if( dev_read( ComPort, &data, 1, 0, timeout, 0, 0, 0 ) != 1 ) { return( SDATA_NO_DATA ); } if( data == 0xff ) { dev_read( ComPort, &data, 1, 0, timeout, 0, 0, 0 ); if( data == 0xff ) return( data ); /* a transmission error has occured */ HadError = true; dev_read( ComPort, &data, 1, 0, timeout, 0, 0, 0 ); return( SDATA_NO_DATA ); } return( data ); }
void xf86KbdEvents() { unsigned char rBuf[64]; int nBytes, i; if ((nBytes = dev_read( QNX_kbd_fd, (char *)rBuf, sizeof(rBuf), 0, 0, 0, 0, NULL)) > 0) { for (i = 0; i < nBytes; i++) xf86PostKbdEvent(rBuf[i]); /* Re-arm proxy */ dev_arm(QNX_kbd_fd, QNX_kbd_proxy, _DEV_EVENT_RXRDY); } }
void gps_enable_bits(uint8_t mask) { // disable uart1 interrupt UCSR1B &= ~((1 << RXCIE1) | (1 << RXEN1)); // enable rx UCSR1B |= (1 << RXEN1); uint8_t i; // set the address from which to read/write dev_ioctl(DEV_AVR_I2C, I2C_DEST_ADDR, SWITCH_2); // read the current value dev_read(DEV_AVR_I2C, &i, sizeof(i)); // set the RX/TX bits i |= (mask); // write the value back dev_write(DEV_AVR_I2C, &i, sizeof(i)); //overwrite value // verify that the bits have been written correctly. do { i = 0; dev_read(DEV_AVR_I2C, &i, sizeof(i)); }while((i & (mask)) != (mask)); }
int dfs_read(struct file *filp, void *data, size_t size, off64_t pos) { struct inode *inode; size_t read; size_t count; off64_t left; char *p; unsigned int iblock; unsigned int start; blkno_t blk; struct buf *buf; inode = (struct inode *) filp->data; read = 0; p = (char *) data; while (pos < inode->desc->size && size > 0) { if (filp->flags & F_CLOSED) return -EINTR; iblock = (unsigned int) (pos / inode->fs->blocksize); start = (unsigned int) (pos % inode->fs->blocksize); count = inode->fs->blocksize - start; if (count > size) count = size; left = inode->desc->size - (size_t) pos; if (count > left) count = (size_t) left; if (count <= 0) break; blk = get_inode_block(inode, iblock); if (blk == NOBLOCK) return -EIO; if (filp->flags & O_DIRECT) { if (start != 0 || count != inode->fs->blocksize) return read; if (dev_read(inode->fs->devno, p, count, blk, 0) != (int) count) return read; } else { buf = get_buffer(inode->fs->cache, blk); if (!buf) return -EIO; memcpy(p, buf->data + start, count); release_buffer(inode->fs->cache, buf); } pos += count; p += count; read += count; size -= count; } return read; }
int diskfs_getuuid(device_t *dev, int8_t *uuid) { diskfs_sb_t *sb; int32_t i; int32_t ret = -1; sb = kmalloc(512); if (dev_read(dev, (int64_t) 2*512, 512, (char *) sb)) return ret; if (sb->magic == QUAFS_MAGIC) { /* diskfs */ for (i = 0; i < 17; i++) uuid[i] = sb->uuid[i]; ret = 0; } kfree(sb); return ret; }
void accel_off () { uint8_t i; dev_ioctl(DEV_AVR_I2C, I2C_SET_BRR, 50); //set speed dev_ioctl(DEV_AVR_I2C, I2C_DEST_ADDR, ADG715_PWR_ADDR); //set dest address dev_read(DEV_AVR_I2C, &i, sizeof(i)); //get current value i &= ~(1 <<5); //turn off accel dev_write(DEV_AVR_I2C, &i, sizeof(i)); //write value back printf("Weatherboard accelerometer off.\n"); }
void get_battery() { uint16_t voltage; uint16_t high_val; uint16_t low_val; dev_open(DEV_MICA2_BATTERY); dev_mode(DEV_MICA2_BATTERY, DEV_MODE_ON); //mos_mdelay(200); dev_read(DEV_MICA2_BATTERY, &voltage, sizeof(voltage)); high_val = voltage / 1000; low_val = (uint16_t)(voltage - (1000 * high_val)); dev_mode(DEV_MICA2_BATTERY, DEV_MODE_OFF); dev_close(DEV_MICA2_BATTERY); printf("Battery is at %d.%d volts, %d\n", high_val, low_val, voltage); //printf("Battery is ADC level is at %d bits\n", voltage); }
trap_retval ReqRead_user_keyboard( void ) { struct _console_ctrl *con; unsigned con_num; int con_hdl; int con_mode; char chr; //NYI: what about QNX windows? static char con_name[] = "/dev/conXX"; unsigned timeout; read_user_keyboard_req *acc; read_user_keyboard_ret *ret; # define FIRST_DIGIT (sizeof( con_name ) - 3) acc = GetInPtr( 0 ); ret = GetOutPtr( 0 ); timeout = acc->wait * 10; if( timeout == 0 ) timeout = -1; ret->key = '\0'; con = console_open( 2, O_WRONLY ); if( con == NULL ) { return( sizeof( *ret ) ); } con_num = console_active( con, -1 ); console_close( con ); con_name[ FIRST_DIGIT + 0 ] = (con_num / 10) + '0'; con_name[ FIRST_DIGIT + 1 ] = (con_num % 10) + '0'; con_hdl = open( con_name, O_RDONLY ); if( con_hdl < 0 ) { if( timeout == -1 ) timeout = 50; sleep( timeout / 10 ); return( sizeof( *ret ) ); } con_mode = dev_mode( con_hdl, 0, _DEV_MODES ); if( dev_read( con_hdl, &chr, 1, 1, 0, timeout, 0, 0 ) == 1 ) { if( chr == 0xff ) { read( con_hdl, &chr, 1 ); chr = '\0'; } ret->key = chr; } dev_mode( con_hdl, con_mode, _DEV_MODES ); close( con_hdl ); return( sizeof( *ret ) ); }