inline void write_char( char c ) 
 {
     buf2[ bufL2++ ] = c ;//bufL2 points to current index in the output buffer array(buf2)  
     if( bufL2 == SIZE ) 
     {
         //array full so let's flush it
         write_flush() ;
     }
 }
 inline void write_Int(int n)
 {
     if(n<0)
     {
         write_char('-');
         write_flush();
         n *= (-1);
     }
     write_int(n);
 }
Пример #3
0
/**
 * Block until the sequence of bytes
 *
 *    "[^$]*\$[^#]*#.*"
 *
 * has been read from the client fd.  This is one (or more) gdb
 * packet(s).
 */
static void read_packet(struct dbg_context* dbg)
{
    byte* p;
    size_t checkedlen;

    /* Read and discard bytes until we see the start of a
     * packet.
     *
     * NB: we're ignoring "+/-" responses from gdb.  There doesn't
     * seem to be any sane reason why we would send a damaged
     * packet to gdb over TCP, then see a "-" reply from gdb and
     * somehow magically fix our bug that led to the malformed
     * packet in the first place.
     */
    while (skip_to_packet_start(dbg)) {
        read_data_once(dbg);
    }

    if (dbg->inbuf[0] == INTERRUPT_CHAR) {
        /* Interrupts are kind of an ugly duckling in the gdb
         * protocol ... */
        dbg->packetend = 1;
        return;
    }

    /* Read until we see end-of-packet. */
    for (checkedlen = 0;
            !(p = memchr(dbg->inbuf + checkedlen, '#', dbg->inlen));
            checkedlen = dbg->inlen) {
        read_data_once(dbg);
    }
    dbg->packetend = (p - dbg->inbuf);
    /* NB: we're ignoring the gdb packet checksums here too.  If
     * gdb is corrupted enough to garble a checksum over TCP, it's
     * not really clear why asking for the packet again might make
     * the bug go away. */
    assert('$' == dbg->inbuf[0] && dbg->packetend < dbg->inlen);

    /* Acknowledge receipt of the packet. */
    if (!dbg->no_ack) {
        write_data_raw(dbg, (byte*)"+", 1);
        write_flush(dbg);
    }
}
Пример #4
0
ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
        const void *buffer, size_t len) {
    mgs_handle_t *ctxt = ptr;

    /* pass along the encrypted data
     * need to flush since we're using SSL's malloc-ed buffer
     * which will be overwritten once we leave here
     */
    apr_bucket *bucket = apr_bucket_transient_create(buffer, len,
            ctxt->output_bb->
            bucket_alloc);
    ctxt->output_length += len;
    APR_BRIGADE_INSERT_TAIL(ctxt->output_bb, bucket);

    if (write_flush(ctxt) < 0) {
        return -1;
    }
    return len;
}
Пример #5
0
void adafruit22fb_set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
	u16 *p = (u16 *)par->buf;
	int i = 0;

	fbtft_dev_dbg(DEBUG_SET_ADDR_WIN, par->info->device, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);

	write_cmd(par, FBTFT_CASET);
	write_data(par, 0x00);
	write_data(par, xs);
	write_data(par, 0x00);
	write_data(par, xe);

	write_cmd(par, FBTFT_RASET);
	write_data(par, 0x00);
	write_data(par, ys);
	write_data(par, 0x00);
	write_data(par, ye);

	write_cmd(par, FBTFT_RAMWR);

	write_flush(par);
}
Пример #6
0
static int write_nodes(struct WRITEINFO *info)
{
	unsigned dep_index;
	unsigned string_index;
	
	struct NODE *node;
	struct GRAPH *graph = info->graph;
		
	/* write the cache nodes */	
	dep_index = 0;
	string_index = 0;
	for(node = graph->first; node; node = node->next)
	{
		/* fetch cache node */
		struct CACHEINFO_DEPS *cacheinfo = &info->buffers.nodes[info->index++];

		/* count dependencies */
		struct NODELINK *dep;
		
		memset(cacheinfo, 0, sizeof(struct CACHEINFO_DEPS));
		
		cacheinfo->deps_num = 0;
		for(dep = node->firstdep; dep; dep = dep->next)
			cacheinfo->deps_num++;
		
		cacheinfo->hashid = node->hashid;
		cacheinfo->cached = node->cached;
		cacheinfo->timestamp_raw = node->timestamp_raw;
		cacheinfo->deps = (unsigned*)((long)dep_index);
		cacheinfo->filename = (char*)((long)string_index);
		
		string_index += node->filename_len;
		dep_index += cacheinfo->deps_num;
		
		if(info->index == WRITE_BUFFERNODES && write_flush(info, sizeof(struct CACHEINFO_DEPS)))
			return -1;
	}

	/* flush the remainder */
	if(info->index && write_flush(info, sizeof(struct CACHEINFO_DEPS)))
		return -1;

	/* write the cache nodes deps */
	for(node = graph->first; node; node = node->next)
	{
		struct NODELINK *dep;
		for(dep = node->firstdep; dep; dep = dep->next)
		{
			info->buffers.deps[info->index++] = dep->node->id;
			if(info->index == WRITE_BUFFERDEPS && write_flush(info, sizeof(unsigned)))
				return -1;
		}
	}

	/* flush the remainder */
	if(info->index && write_flush(info, sizeof(unsigned)))
		return -1;
		
	/* write the strings */
	for(node = graph->first; node; node = node->next)
	{
		if(info->index+node->filename_len > sizeof(info->buffers.strings))
		{
			if(write_flush(info, sizeof(char)))
				return -1;
		}
		memcpy(info->buffers.strings + info->index, node->filename, node->filename_len);
		info->index += node->filename_len;
	}	

	/* flush the remainder */
	if(info->index && write_flush(info, sizeof(char)))
		return -1;
		
	return 0;
}
Пример #7
0
static int ili9341fb_init_display(struct fbtft_par *par)
{
    u16 *p = (u16 *)par->buf;
    int i = 0;

    fbtft_dev_dbg(DEBUG_INIT_DISPLAY, par->info->device, "%s()\n", __func__);

    par->fbtftops.reset(par);

    /* startup sequence for Watterott's MI0283QT9 */

#if 0
    // not needed
    write_cmd(par, LCD_CMD_RESET);
    write_flush(par);
    mdelay(120);
#endif

    write_cmd(par, LCD_CMD_DISPLAY_OFF);
    write_flush(par);
    mdelay(20);

    //send init commands
    write_cmd(par, LCD_CMD_POWER_CTRLB);
    write_data(par, 0x00);
    write_data(par, 0x83); //83 81 AA
    write_data(par, 0x30);

    write_cmd(par, LCD_CMD_POWERON_SEQ_CTRL);
    write_data(par, 0x64); //64 67
    write_data(par, 0x03);
    write_data(par, 0x12);
    write_data(par, 0x81);

    write_cmd(par, LCD_CMD_DRV_TIMING_CTRLA);
    write_data(par, 0x85);
    write_data(par, 0x01);
    write_data(par, 0x79); //79 78

    write_cmd(par, LCD_CMD_POWER_CTRLA);
    write_data(par, 0x39);
    write_data(par, 0X2C);
    write_data(par, 0x00);
    write_data(par, 0x34);
    write_data(par, 0x02);

    write_cmd(par, LCD_CMD_PUMP_RATIO_CTRL);
    write_data(par, 0x20);

    write_cmd(par, LCD_CMD_DRV_TIMING_CTRLB);
    write_data(par, 0x00);
    write_data(par, 0x00);

    write_cmd(par, LCD_CMD_POWER_CTRL1);
    write_data(par, 0x26); //26 25

    write_cmd(par, LCD_CMD_POWER_CTRL2);
    write_data(par, 0x11);

    write_cmd(par, LCD_CMD_VCOM_CTRL1);
    write_data(par, 0x35);
    write_data(par, 0x3E);

    write_cmd(par, LCD_CMD_VCOM_CTRL2);
    write_data(par, 0xBE); //BE 94

    write_cmd(par, LCD_CMD_FRAME_CTRL);
    write_data(par, 0x00);
    write_data(par, 0x1B); //1B 70

    write_cmd(par, LCD_CMD_DISPLAY_CTRL);
    write_data(par, 0x0A);
    write_data(par, 0x82);
    write_data(par, 0x27);
    write_data(par, 0x00);

    write_cmd(par, LCD_CMD_ENTRY_MODE);
    write_data(par, 0x07);

    write_cmd(par, LCD_CMD_PIXEL_FORMAT);
    write_data(par, 0x55); //16bit

    // orientation
    write_cmd(par, LCD_CMD_MEMACCESS_CTRL);
    switch (par->info->var.rotate) {
    case 0:
        write_data(par, (1<<MEM_X) | (!par->bgr << MEM_BGR));
        break;
    case 1:
        write_data(par, (1<<MEM_V) | (1<<MEM_L) | (!par->bgr << MEM_BGR));
        break;
    case 2:
        write_data(par, (1<<MEM_Y) | (!par->bgr << MEM_BGR));
        break;
    case 3:
        write_data(par, (1<<MEM_Y) | (1<<MEM_X)| (1<<MEM_V) | (!par->bgr << MEM_BGR));
        break;
    }

    write_cmd(par, LCD_CMD_SLEEPOUT);
    write_flush(par);
    mdelay(120);

    write_cmd(par, LCD_CMD_DISPLAY_ON);
    write_flush(par);
    mdelay(20);

    return 0;
}
Пример #8
0
static void consume_request(struct dbg_context* dbg)
{
    memset(&dbg->req, 0, sizeof(dbg->req));
    write_flush(dbg);
}
Пример #9
0
static int flush_writer(lua_State* L)
{
	writer_t* writer 	= lua_touserdata(L, 1);
	write_flush(writer);
	return 0;
}
Пример #10
0
static int adafruit22fb_init_display(struct fbtft_par *par)
{
	u16 *p = (u16 *)par->buf;
	int i = 0;

	fbtft_dev_dbg(DEBUG_INIT_DISPLAY, par->info->device, "%s()\n", __func__);

	par->fbtftops.reset(par);

	/* BTL221722-276L startup sequence, from datasheet */

	/*	SETEXTCOM: Set extended command set (C1h)
		This command is used to set extended command set access enable.
		Enable: After command (C1h), must write 3 parameters (ffh,83h,40h) by order	*/
	write_cmd(par, 0xC1);
	write_data(par, 0xFF);
	write_data(par, 0x83);
	write_data(par, 0x40);

    /*	Sleep out
		This command turns off sleep mode. 
		In this mode the DC/DC converter is enabled, Internal oscillator is started, 
		and panel scanning is started. 	*/
	write_cmd(par, 0x11);

	write_flush(par);
	mdelay(150);

    /* Undoc'd register? */
	write_cmd(par, 0xCA);
	write_data(par, 0x70);
	write_data(par, 0x00);
	write_data(par, 0xD9);

    /*	SETOSC: Set Internal Oscillator (B0h)
		This command is used to set internal oscillator related settings	*/
	write_cmd(par, 0xB0);
	write_data(par, 0x01);	/* OSC_EN: Enable internal oscillator */
	write_data(par, 0x11);	/* Internal oscillator frequency: 125% x 2.52MHz */

    /* Drive ability setting */
	write_cmd(par, 0xC9);
	write_data(par, 0x90);
	write_data(par, 0x49);
	write_data(par, 0x10);
	write_data(par, 0x28);
	write_data(par, 0x28);
	write_data(par, 0x10);
	write_data(par, 0x00);
	write_data(par, 0x06);

	write_flush(par);
	mdelay(20);

	/*	SETGAMMAP: Set "+" polarity Gamma Curve GC0 Related Setting (C2h) */
	write_cmd(par, 0xC2);
	write_data(par, 0x60);
	write_data(par, 0x71);
	write_data(par, 0x01);
	write_data(par, 0x0E);
	write_data(par, 0x05);
	write_data(par, 0x02);
	write_data(par, 0x09);
	write_data(par, 0x31);
	write_data(par, 0x0A);

	/*	SETGAMMAN: Set "-" polarity Gamma Curve GC0 Related Setting (C3h) */
	write_cmd(par, 0xC3);
	write_data(par, 0x67);
	write_data(par, 0x30);
	write_data(par, 0x61);
	write_data(par, 0x17);
	write_data(par, 0x48);
	write_data(par, 0x07);
	write_data(par, 0x05);
	write_data(par, 0x33);

	write_flush(par);
	mdelay(10);

	/*	SETPWCTR5: Set Power Control 5(B5h)
		This command is used to set VCOM Voltage include VCOM Low and VCOM High Voltage	*/
	write_cmd(par, 0xB5);
	write_data(par, 0x35);	/* VCOMH 0110101 :  3.925 */
	write_data(par, 0x20);	/* VCOML 0100000 : -1.700 */
	write_data(par, 0x45);	/* 45h=69  VCOMH: "VMH" + 5d   VCOML: "VMH" + 5d */

	/*	SETPWCTR4: Set Power Control 4(B4h)
		VRH[4:0]:  Specify the VREG1 voltage adjusting. VREG1 voltage is for gamma voltage setting.
		BT[2:0]: Switch the output factor of step-up circuit 2 for VGH and VGL voltage generation.	*/
	write_cmd(par, 0xB4);
	write_data(par, 0x33);
	write_data(par, 0x25);
	write_data(par, 0x4C);

	write_flush(par);
	mdelay(10);

	/* MADCTL - Memory data access control */
	/*   Mode select pin SRGB: RGB direction select H/W pin for Color filter default setting: 0=BGR, 1=RGB   */
	/*   MADCTL RGB bit: RGB-BGR ORDER: 0=RGB color filter panel, 1=BGR color filter panel              */
	#define MY (1 << 7)
	#define MX (1 << 6)
	#define MV (1 << 5)
	write_cmd(par, 0x36);
	switch (rotate) {
	case 0:
		write_data(par, (!bgr << 3));
		break;
	case 1:
		write_data(par, MX | MV | (!bgr << 3));
		break;
	case 2:
		write_data(par, MX | MY | (!bgr << 3));
		break;
	case 3:
		write_data(par, MY | MV | (!bgr << 3));
		break;
	}

	/*	Interface Pixel Format (3Ah)
		This command is used to define the format of RGB picture data, 
		which is to be transfer via the system and RGB interface.		*/
	write_cmd(par, 0x3A);
	write_data(par, 0x05);	/* RGB interface: 16 Bit/Pixel	*/

	/*	Display on (29h)
		This command is used to recover from DISPLAY OFF mode. 
		Output from the Frame Memory is enabled.				*/
	write_cmd(par, 0x29);

	write_flush(par);
	mdelay(10);

	return 0;
}
Пример #11
0
apr_status_t mgs_filter_output(ap_filter_t * f, apr_bucket_brigade * bb) {
    apr_size_t ret;
    mgs_handle_t *ctxt = (mgs_handle_t *) f->ctx;
    apr_status_t status = APR_SUCCESS;
    apr_read_type_e rblock = APR_NONBLOCK_READ;

    if (f->c->aborted) {
        apr_brigade_cleanup(bb);
        return APR_ECONNABORTED;
    }

    if (ctxt->status == 0) {
        gnutls_do_handshake(ctxt);
    }

    if (ctxt->status < 0) {
        return ap_pass_brigade(f->next, bb);
    }

    while (!APR_BRIGADE_EMPTY(bb)) {
        apr_bucket *bucket = APR_BRIGADE_FIRST(bb);

        if (APR_BUCKET_IS_EOS(bucket)) {
            return ap_pass_brigade(f->next, bb);
        } else if (APR_BUCKET_IS_FLUSH(bucket)) {
            /* Try Flush */
            if (write_flush(ctxt) < 0) {
                /* Flush Error */
                return ctxt->output_rc;
            }
            /* cleanup! */
            apr_bucket_delete(bucket);
        } else if (AP_BUCKET_IS_EOC(bucket)) {
            /* End Of Connection */
            if (ctxt->session != NULL) {
                /* Try A Clean Shutdown */
                do {
                    ret = gnutls_bye(ctxt->session, GNUTLS_SHUT_WR);
                } while (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN);
                /* De-Initialize Session */
                gnutls_deinit(ctxt->session);
                ctxt->session = NULL;
            }
            /* cleanup! */
            apr_bucket_delete(bucket);
            /* Pass next brigade! */
            return ap_pass_brigade(f->next, bb);
        } else {
            /* filter output */
            const char *data;
            apr_size_t len;

            status = apr_bucket_read(bucket, &data, &len, rblock);

            if (APR_STATUS_IS_EAGAIN(status)) {
                /* No data available so Flush! */
                if (write_flush(ctxt) < 0) {
                    return ctxt->output_rc;
                }
                /* Try again with a blocking read. */
                rblock = APR_BLOCK_READ;
                continue;
            }

            rblock = APR_NONBLOCK_READ;

            if (!APR_STATUS_IS_EOF(status)
                    && (status != APR_SUCCESS)) {
                return status;
            }

            if (len > 0) {

                if (ctxt->session == NULL) {
                    ret = GNUTLS_E_INVALID_REQUEST;
                } else {
                    do {
                        ret =
                                gnutls_record_send
                                (ctxt->session, data,
                                len);
                    } while (ret == GNUTLS_E_INTERRUPTED
                            || ret == GNUTLS_E_AGAIN);
                }

                if (ret < 0) {
                    /* error sending output */
                    ap_log_error(APLOG_MARK,
                            APLOG_INFO,
                            ctxt->output_rc,
                            ctxt->c->base_server,
                            "GnuTLS: Error writing data."
                            " (%d) '%s'",
                            (int) ret,
                            gnutls_strerror(ret));
                    if (ctxt->output_rc == APR_SUCCESS) {
                        ctxt->output_rc =
                                APR_EGENERAL;
                        return ctxt->output_rc;
                    }
                } else if (ret != len) {
                    /* Not able to send the entire bucket,
                       split it and send it again. */
                    apr_bucket_split(bucket, ret);
                }
            }

            apr_bucket_delete(bucket);
        }
    }

    return status;
}