static void null_reader(struct driver_data *drv_data) { u8 n_bytes = drv_data->n_bytes; dummy_read(drv_data); while (drv_data->rx < drv_data->rx_end) { while (!(read_STAT(drv_data) & BIT_STAT_RXS)) cpu_relax(); dummy_read(drv_data); drv_data->rx += n_bytes; } }
int pcf_read(device_t dev, char *buf, int len, int *read, int last, int delay /* us */) { struct pcf_softc *sc = DEVTOSOFTC(dev); int bytes, error = 0; #ifdef PCFDEBUG char *obuf = buf; device_printf(dev, " << reading %d bytes\n", len); #endif PCF_LOCK(sc); /* trig the bus to get the first data byte in S0 */ if (len) { if (len == 1 && last) /* just one byte to read */ pcf_set_S1(sc, ESO); /* no ack */ dummy_read(sc); } bytes = 0; while (len) { /* XXX delay needed here */ /* wait for trigged byte */ if ((error = pcf_wait_byte(sc))) { pcf_stop_locked(sc); goto error; } if (len == 1 && last) /* ok, last data byte already in S0, no I2C activity * on next pcf_get_S0() */ pcf_stop_locked(sc); else if (len == 2 && last) /* next trigged byte with no ack */ pcf_set_S1(sc, ESO); /* receive byte, trig next byte */ *buf++ = pcf_get_S0(sc); len --; bytes ++; }; error: *read = bytes; PCF_UNLOCK(sc); #ifdef PCFDEBUG device_printf(dev, " << %d bytes read (%d): %#x%s\n", bytes, error, (unsigned)obuf[0], bytes > 1? "...": ""); #endif return (error); }
LLDSPEC void gdisp_lld_read_start(GDisplay *g) { acquire_bus(g); set_viewport(g); set_cursor(g); setreadmode(g); dummy_read(g); }
LLDSPEC void gdisp_lld_read_start(GDisplay *g) { acquire_bus(g); set_viewport(g); write_index(g, 0x2E); setreadmode(g); dummy_read(g); }
static void u16_cs_chg_reader(struct driver_data *drv_data) { struct chip_data *chip = drv_data->cur_chip; /* poll for SPI completion before start */ while (!(read_STAT(drv_data) & BIT_STAT_SPIF)) cpu_relax(); /* clear TDBR buffer before read(else it will be shifted out) */ write_TDBR(drv_data, 0xFFFF); cs_active(drv_data, chip); dummy_read(drv_data); while (drv_data->rx < drv_data->rx_end - 2) { cs_deactive(drv_data, chip); while (!(read_STAT(drv_data) & BIT_STAT_RXS)) cpu_relax(); cs_active(drv_data, chip); *(u16 *) (drv_data->rx) = read_RDBR(drv_data); drv_data->rx += 2; } cs_deactive(drv_data, chip); while (!(read_STAT(drv_data) & BIT_STAT_RXS)) cpu_relax(); *(u16 *) (drv_data->rx) = read_SHAW(drv_data); drv_data->rx += 2; }
static void u16_reader(struct driver_data *drv_data) { dev_dbg(&drv_data->pdev->dev, "cr-16 is 0x%x\n", read_STAT(drv_data)); /* poll for SPI completion before start */ while (!(read_STAT(drv_data) & BIT_STAT_SPIF)) cpu_relax(); /* clear TDBR buffer before read(else it will be shifted out) */ write_TDBR(drv_data, 0xFFFF); dummy_read(drv_data); while (drv_data->rx < (drv_data->rx_end - 2)) { while (!(read_STAT(drv_data) & BIT_STAT_RXS)) cpu_relax(); *(u16 *) (drv_data->rx) = read_RDBR(drv_data); drv_data->rx += 2; } while (!(read_STAT(drv_data) & BIT_STAT_RXS)) cpu_relax(); *(u16 *) (drv_data->rx) = read_SHAW(drv_data); drv_data->rx += 2; }
int main(int argc, char *argv[]) { int nargs; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_head.c,v 1.7 2011/03/02 00:04:16 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; prog_name = argv[0]; short_prog_name = strrchr(prog_name, '/'); short_prog_name = (short_prog_name == NULL ? prog_name : short_prog_name + 1); Progname = short_prog_name; get_options(argc, argv); if (action == ACTION_USAGE) usage(0); else if (action == ACTION_IDENTIFY) dummy_identify(); else if (action == ACTION_READ) dummy_read(); else usage(1); exit(0); } /* end main() */
static int pcf_read(device_t pcfdev, char *buf, int len, int *read, int last, int delay /* us */) { struct pcf_softc *pcf = DEVTOSOFTC(pcfdev); int bytes, error = 0; #ifdef PCFDEBUG kprintf("pcf%d: << reading %d bytes\n", device_get_unit(pcfdev), len); #endif /* trig the bus to get the first data byte in S0 */ if (len) { if (len == 1 && last) /* just one byte to read */ PCF_SET_S1(pcf, ES0); /* no ack */ dummy_read(pcf); } bytes = 0; while (len) { /* XXX delay needed here */ /* wait for trigged byte */ if ((error = pcf_wait_byte(pcf))) { pcf_stop(pcfdev); goto error; } if (len == 1 && last) /* ok, last data byte already in S0, no I2C activity * on next PCF_GET_S0() */ pcf_stop(pcfdev); else if (len == 2 && last) /* next trigged byte with no ack */ PCF_SET_S1(pcf, ES0); /* receive byte, trig next byte */ *buf++ = PCF_GET_S0(pcf); len --; bytes ++; } error: *read = bytes; #ifdef PCFDEBUG kprintf("pcf%d: << %d bytes read (%d)\n", device_get_unit(pcfdev), bytes, error); #endif return (error); }
int main () { int rval; int size; struct file my_file; char *buffer; /* we do not model this buffer */ struct inode inode; unsigned int count; unsigned char random; int lock_held = 0; dummy_major = register_chrdev (0, "dummy"); inode.i_rdev = dummy_major << MINORBITS; init_module (); /* assign arbitrary values */ my_file.f_mode = nondet_uint (); my_file.f_pos = nondet_uint (); do { random = nondet_uchar (); __CPROVER_assume (0 <= random && random <= 3); switch (random) { case 1: rval = dummy_open (&inode, &my_file); if (rval == 0) lock_held = TRUE; break; case 2: __CPROVER_assume (lock_held); count = dummy_read (&my_file, buffer, BUF_SIZE); break; case 3: dummy_release (&inode, &my_file); lock_held = FALSE; break; default: break; } } while (random || lock_held); cleanup_module (); unregister_chrdev (dummy_major, "dummy"); return 0; }
void pcf_intr(void *arg) { struct pcf_softc *sc = arg; char data, status, addr; char error = 0; PCF_LOCK(sc); status = pcf_get_S1(sc); if (status & PIN) { printf("pcf: spurious interrupt, status=0x%x\n", status & 0xff); goto error; } if (status & LAB) printf("pcf: bus arbitration lost!\n"); if (status & BER) { error = IIC_EBUSERR; iicbus_intr(sc->iicbus, INTR_ERROR, &error); goto error; } do { status = pcf_get_S1(sc); switch(sc->pcf_slave_mode) { case SLAVE_TRANSMITTER: if (status & LRB) { /* ack interrupt line */ dummy_write(sc); /* no ack, don't send anymore */ sc->pcf_slave_mode = SLAVE_RECEIVER; iicbus_intr(sc->iicbus, INTR_NOACK, NULL); break; } /* get data from upper code */ iicbus_intr(sc->iicbus, INTR_TRANSMIT, &data); pcf_set_S0(sc, data); break; case SLAVE_RECEIVER: if (status & AAS) { addr = pcf_get_S0(sc); if (status & AD0) iicbus_intr(sc->iicbus, INTR_GENERAL, &addr); else iicbus_intr(sc->iicbus, INTR_START, &addr); if (addr & LSB) { sc->pcf_slave_mode = SLAVE_TRANSMITTER; /* get the first char from upper code */ iicbus_intr(sc->iicbus, INTR_TRANSMIT, &data); /* send first data byte */ pcf_set_S0(sc, data); } break; } /* stop condition received? */ if (status & STS) { /* ack interrupt line */ dummy_read(sc); /* emulate intr stop condition */ iicbus_intr(sc->iicbus, INTR_STOP, NULL); } else { /* get data, ack interrupt line */ data = pcf_get_S0(sc); /* deliver the character */ iicbus_intr(sc->iicbus, INTR_RECEIVE, &data); } break; default: panic("%s: unknown slave mode (%d)!", __func__, sc->pcf_slave_mode); } } while ((pcf_get_S1(sc) & PIN) == 0); PCF_UNLOCK(sc); return; error: /* unknown event on bus...reset PCF */ pcf_set_S1(sc, PIN|ESO|ENI|ACK); sc->pcf_slave_mode = SLAVE_RECEIVER; PCF_UNLOCK(sc); return; }
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { uint16_t cver; // No private area for this controller g->priv = 0; // Initialise the board interface init_board(g); /* Hardware reset */ setpin_reset(g, TRUE); gfxSleepMicroseconds(1000); setpin_reset(g, FALSE); gfxSleepMicroseconds(1000); acquire_bus(g); write_index(g, 0); // Get controller version setreadmode(g); dummy_read(g); cver = read_data(g); setwritemode(g); /* initializing funciton */ write_reg(g, 0xe5,0x8000); /* Set the internal vcore voltage */ write_reg(g, 0x00,0x0001); /* start OSC */ write_reg(g, 0x2b,0x0010); /* Set the frame rate as 80 when the internal resistor is used for oscillator circuit */ write_reg(g, 0x01,0x0100); /* s720 to s1 ; G1 to G320 */ write_reg(g, 0x02,0x0700); /* set the line inversion */ write_reg(g, 0x03,0x1018); /* 65536 colors */ write_reg(g, 0x04,0x0000); write_reg(g, 0x08,0x0202); /* specify the line number of front and back porch periods respectively */ write_reg(g, 0x09,0x0000); write_reg(g, 0x0a,0x0000); write_reg(g, 0x0c,0x0000); /* select internal system clock */ write_reg(g, 0x0d,0x0000); write_reg(g, 0x0f,0x0000); write_reg(g, 0x50,0x0000); /* set windows adress */ write_reg(g, 0x51,0x00ef); write_reg(g, 0x52,0x0000); write_reg(g, 0x53,0x013f); write_reg(g, 0x60,0x2700); write_reg(g, 0x61,0x0001); write_reg(g, 0x6a,0x0000); write_reg(g, 0x80,0x0000); write_reg(g, 0x81,0x0000); write_reg(g, 0x82,0x0000); write_reg(g, 0x83,0x0000); write_reg(g, 0x84,0x0000); write_reg(g, 0x85,0x0000); write_reg(g, 0x90,0x0010); write_reg(g, 0x92,0x0000); write_reg(g, 0x93,0x0003); write_reg(g, 0x95,0x0110); write_reg(g, 0x97,0x0000); write_reg(g, 0x98,0x0000); /* power setting function */ write_reg(g, 0x10,0x0000); write_reg(g, 0x11,0x0000); write_reg(g, 0x12,0x0000); write_reg(g, 0x13,0x0000); gfxSleepMicroseconds(100); write_reg(g, 0x10,0x17b0); write_reg(g, 0x11,0x0004); gfxSleepMicroseconds(50); write_reg(g, 0x12,0x013e); gfxSleepMicroseconds(50); write_reg(g, 0x13,0x1f00); write_reg(g, 0x29,0x000f); gfxSleepMicroseconds(50); write_reg(g, 0x20,0x0000); write_reg(g, 0x21,0x0000); /* initializing function */ write_reg(g, 0x30,0x0204); write_reg(g, 0x31,0x0001); write_reg(g, 0x32,0x0000); write_reg(g, 0x35,0x0206); write_reg(g, 0x36,0x0600); write_reg(g, 0x37,0x0500); write_reg(g, 0x38,0x0505); write_reg(g, 0x39,0x0407); write_reg(g, 0x3c,0x0500); write_reg(g, 0x3d,0x0503); /* display on */ write_reg(g, 0x07,0x0173); gfxSleepMicroseconds(50); // Finish Init post_init_board(g); // Release the bus release_bus(g); // Turn on the backlight set_backlight(g, GDISP_INITIAL_BACKLIGHT); /* Initialise the GDISP structure */ g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; g->g.Orientation = GDISP_ROTATE_0; g->g.Powermode = powerOn; g->g.Backlight = GDISP_INITIAL_BACKLIGHT; g->g.Contrast = GDISP_INITIAL_CONTRAST; return TRUE; }
static void pcfintr(void *arg) { device_t pcfdev = (device_t)arg; struct pcf_softc *pcf = DEVTOSOFTC(pcfdev); char data, status, addr; char error = 0; status = PCF_GET_S1(pcf); if (status & PIN) { device_printf(pcfdev, "spurious interrupt, status=0x%x\n", status & 0xff); goto error; } if (status & LAB) device_printf(pcfdev, "bus arbitration lost!\n"); if (status & BER) { error = IIC_EBUSERR; iicbus_intr(pcf->iicbus, INTR_ERROR, &error); goto error; } do { status = PCF_GET_S1(pcf); switch(pcf->pcf_slave_mode) { case SLAVE_TRANSMITTER: if (status & LRB) { /* ack interrupt line */ dummy_write(pcf); /* no ack, don't send anymore */ pcf->pcf_slave_mode = SLAVE_RECEIVER; iicbus_intr(pcf->iicbus, INTR_NOACK, NULL); break; } /* get data from upper code */ iicbus_intr(pcf->iicbus, INTR_TRANSMIT, &data); PCF_SET_S0(pcf, data); break; case SLAVE_RECEIVER: if (status & AAS) { addr = PCF_GET_S0(pcf); if (status & AD0) iicbus_intr(pcf->iicbus, INTR_GENERAL, &addr); else iicbus_intr(pcf->iicbus, INTR_START, &addr); if (addr & LSB) { pcf->pcf_slave_mode = SLAVE_TRANSMITTER; /* get the first char from upper code */ iicbus_intr(pcf->iicbus, INTR_TRANSMIT, &data); /* send first data byte */ PCF_SET_S0(pcf, data); } break; } /* stop condition received? */ if (status & STS) { /* ack interrupt line */ dummy_read(pcf); /* emulate intr stop condition */ iicbus_intr(pcf->iicbus, INTR_STOP, NULL); } else { /* get data, ack interrupt line */ data = PCF_GET_S0(pcf); /* deliver the character */ iicbus_intr(pcf->iicbus, INTR_RECEIVE, &data); } break; default: panic("%s: unknown slave mode (%d)!", __func__, pcf->pcf_slave_mode); } } while ((PCF_GET_S1(pcf) & PIN) == 0); return; error: /* unknown event on bus...reset PCF */ PCF_SET_S1(pcf, PIN|ES0|ENI|ACK); pcf->pcf_slave_mode = SLAVE_RECEIVER; return; }
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { uint16_t cver; // No private area for this controller g->priv = 0; // Initialise the board interface init_board(g); /* Hardware reset */ setpin_reset(g, TRUE); gfxSleepMicroseconds(1000); setpin_reset(g, FALSE); gfxSleepMicroseconds(1000); acquire_bus(g); write_index(g, 0); // Get controller version setreadmode(g); dummy_read(g); cver = read_data(g); setwritemode(g); // chinese code starts here write_reg(g, 0x00, 0x0001); gfxSleepMilliseconds(10); write_reg(g, 0x15, 0x0030); write_reg(g, 0x11, 0x0040); write_reg(g, 0x10, 0x1628); write_reg(g, 0x12, 0x0000); write_reg(g, 0x13, 0x104d); gfxSleepMilliseconds(10); write_reg(g, 0x12, 0x0010); gfxSleepMilliseconds(10); write_reg(g, 0x10, 0x2620); write_reg(g, 0x13, 0x344d); //304d gfxSleepMilliseconds(10); write_reg(g, 0x01, 0x0100); write_reg(g, 0x02, 0x0300); write_reg(g, 0x03, 0x1038);//0x1030 write_reg(g, 0x08, 0x0604); write_reg(g, 0x09, 0x0000); write_reg(g, 0x0A, 0x0008); write_reg(g, 0x41, 0x0002); write_reg(g, 0x60, 0x2700); write_reg(g, 0x61, 0x0001); write_reg(g, 0x90, 0x0182); write_reg(g, 0x93, 0x0001); write_reg(g, 0xa3, 0x0010); gfxSleepMilliseconds(10); //################# void Gamma_Set(void) ####################// write_reg(g, 0x30, 0x0000); write_reg(g, 0x31, 0x0502); write_reg(g, 0x32, 0x0307); write_reg(g, 0x33, 0x0305); write_reg(g, 0x34, 0x0004); write_reg(g, 0x35, 0x0402); write_reg(g, 0x36, 0x0707); write_reg(g, 0x37, 0x0503); write_reg(g, 0x38, 0x1505); write_reg(g, 0x39, 0x1505); gfxSleepMilliseconds(10); //################## void Display_ON(void) ####################// write_reg(g, 0x07, 0x0001); gfxSleepMilliseconds(10); write_reg(g, 0x07, 0x0021); write_reg(g, 0x07, 0x0023); gfxSleepMilliseconds(10); write_reg(g, 0x07, 0x0033); gfxSleepMilliseconds(10); write_reg(g, 0x07, 0x0133); // chinese code ends here // Finish Init post_init_board(g); // Release the bus release_bus(g); // Turn on the backlight set_backlight(g, GDISP_INITIAL_BACKLIGHT); /* Initialise the GDISP structure */ g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; g->g.Orientation = GDISP_ROTATE_0; g->g.Powermode = powerOn; g->g.Backlight = GDISP_INITIAL_BACKLIGHT; g->g.Contrast = GDISP_INITIAL_CONTRAST; return TRUE; }