コード例 #1
0
ファイル: dmpobjmd.c プロジェクト: jossk/open-watcom-v2
static DUMP_INFO* dumpStruct(   // DUMP A STRUCTURE
    TYPE type,                  // - structure type
    DUMP_INFO* di,              // - dump information
    char* title,                // - title for dump
    ds_control control )        // - control word
{
    CLASSINFO* info;            // - class information
    NAME *parent;               // - where parent ptr is stored

    control = control;
    type = StructType( type );
    info = type->u.c.info;
    parent = VstkPush( &di->stack );
    *parent = info->name;
    di = dumpTitle( di, title, NameStr( info->name ) );
    if( type != di->original ) {
        di = bufferInit( di );
        di = bufferStr( di, "embedded size: " );
        di = bufferNmb( di, info->vsize );
        di = bufferWrite( di );
        di = dumpOffset( di );
        di = dumpParentage( di );
    } else {
        di = bufferInit( di );
        di = bufferStr( di, "size: " );
        di = bufferNmb( di, info->size );
        di = bufferWrite( di );
    }
    if( info->has_vbptr ) {
        di = dumpDataMemb( di
                           , "[virtual"
                           , "base pointer]"
                           , info->vb_offset + di->offset
                           , CgMemorySize( TypePtrToVoid() ) );
    }
    if( info->has_vfptr ) {
        di = dumpDataMemb( di
                           , "[virtual"
                           , "functions pointer]"
                           , info->vf_offset + di->offset
                           , CgMemorySize( TypePtrToVoid() ) );
    }
    ScopeWalkDataMembers( type->u.c.scope, dumpMember, di );
    if( type == di->original ) {
        ScopeWalkVirtualBases( type->u.c.scope, dumpVirtual, di );
    }
    ScopeWalkDirectBases( type->u.c.scope, dumpDirect, di );
    VstkPop( &di->stack );
    return di;
}
コード例 #2
0
ファイル: owbuffer.c プロジェクト: ABratovic/open-watcom-v2
void OWLENTRY OWLBufferWrite( owl_buffer *buffer, const char *src, owl_offset len ) {
//***********************************************************************************

    if( buffer->location > buffer->size ) {
        bufferPad( buffer, buffer->location );
    }
    bufferWrite( buffer, src, len );
}
コード例 #3
0
ファイル: mq.c プロジェクト: 0omega/platform_system_core
/**
 * Buffers output sent to a peer. May be called multiple times until the entire
 * buffer is filled. Returns true when the buffer is empty.
 */
static bool peerProxyWriteFromBuffer(PeerProxy* peerProxy, Buffer* outgoing) {
    ssize_t size = bufferWrite(outgoing, peerProxy->fd->fd);
    if (size < 0) {
        peerProxyHandleError(peerProxy, "write");
        return false;
    } else {
        return bufferWriteComplete(outgoing);
    }
}
コード例 #4
0
ファイル: dmpobjmd.c プロジェクト: jossk/open-watcom-v2
static DUMP_INFO* dumpOffset(   // DUMP OFFSET LINE
    DUMP_INFO* di )             // - dump information
{
    di = bufferInit( di );
    di = bufferStr( di, "offset of class: " );
    di = bufferNmb( di, di->offset );
    di = bufferWrite( di );
    return di;
}
コード例 #5
0
ファイル: Framebuffer.cpp プロジェクト: enki1986/TFT
void Framebuffer::drawVerticalLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
    int16_t w = 1;
    if (!clipToScreen(x, y, w, h)) {
        return;
    }
    for (int y1 = y; y1 < y + h; y1++) {
        uint8_t pcol = color & 0xFF;
        uint32_t pos = y1 * _width + x;
        bufferWrite(pos, pcol);
    }
}
コード例 #6
0
ファイル: Framebuffer.cpp プロジェクト: enki1986/TFT
void Framebuffer::drawHorizontalLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
    int16_t h = 1;
    if (!clipToScreen(x, y, w, h)) {
        return;
    }
    for (int x1 = x; x1 < x + w; x1++) {
        uint8_t pcol = color & 0xFF;
        uint32_t pos = y * _width + x1;
        bufferWrite(pos, pcol);
    }
}
コード例 #7
0
static void bufferPad( owl_buffer *buffer, size_t to )
//****************************************************
{
    size_t      old_location;

    if( to > buffer->size ) {
        old_location = buffer->location;
        buffer->location = buffer->size;
        bufferWrite( buffer, NULL, to - buffer->size );
        buffer->location = old_location;
    }
}
コード例 #8
0
ファイル: owbuffer.c プロジェクト: ABratovic/open-watcom-v2
static void bufferPad( owl_buffer *buffer, owl_offset to ) {
//**********************************************************

    owl_offset          old_location;

    if( to > buffer->size ) {
        old_location = buffer->location;
        buffer->location = buffer->size;
        bufferWrite( buffer, NULL, to - buffer->size );
        buffer->location = old_location;
    }
}
コード例 #9
0
ファイル: producer.c プロジェクト: Cortys/KMS
void generateData(Buffer* buffer) {
	char i = 1;

	printf("[%s] Starting to produce data.\n", getTime());

	while(1) {
		bufferWrite(buffer, i);
		printf("[%s][%d/%d] Wrote '%d' to buffer.\n", getTime(), buffer->size, buffer->maxSize, i);
		i++;
		usleep(getRandom(SPEEDMIN, SPEEDMAX));
	}
}
コード例 #10
0
ファイル: dmpobjmd.c プロジェクト: jossk/open-watcom-v2
static DUMP_INFO* dumpTitle(    // DUMP A TITLE LINE
    DUMP_INFO *di,              // - dump information
    const char *title,          // - title line
    const char *class_name )    // - name of class
{
    di = bufferRewind( di );
    di = bufferChr( di, '\n' );
    di = bufferStr( di, title );
    di = bufferChr( di, ' ' );
    di = bufferStr( di, class_name );
    di = bufferWrite( di );
    return di;
}
コード例 #11
0
ファイル: dmpobjmd.c プロジェクト: jossk/open-watcom-v2
static DUMP_INFO* dumpParentage( // DUMP PARENTAGE
    DUMP_INFO* di )             // - dump information
{
    char**daughter;             // - daughter class

    for( daughter = VstkTop( &di->stack ); ; ) {
        daughter = VstkNext( &di->stack, daughter );
        if( daughter == NULL ) break;
        di = bufferInit( di );
        di = bufferStr( di, "base of: " );
        di = bufferStr( di, *daughter );
        di = bufferWrite( di );
    }
    return di;
}
コード例 #12
0
ファイル: Framebuffer.cpp プロジェクト: enki1986/TFT
void Framebuffer::setPixel(int16_t x, int16_t y, uint16_t color) {
    translateCoordinates(&x, &y);

    if (x < 0 || x >= _width || y < 0 || y >= _height) {
        return;
    }
    
    uint8_t pcol = color & 0xFF;
    uint32_t pos = y * _width + x;
    bufferWrite(pos, pcol);

    if (x < _minX) _minX = x;
    if (x > _maxX) _maxX = x;
    if (y < _minY) _minY = y;
    if (y > _maxY) _maxY = y;
}
コード例 #13
0
ファイル: buffer.cpp プロジェクト: Apister/SilkJS-WIn
/**
 * @function buffer.write64
 *
 * ### Synopsis
 *
 * buffer.write64(buf, base64String)
 *
 * Write a base64 encoded string to buffer, decoding the base64 to binary.  This function writes binary data to the buffer.
 *
 * @param {object} buf - buffer to write to.
 * @param {string} base64Str - base64 encoded binary data to add to buffer as binary.
 */
static JSVAL buffer_write64 (JSARGS args) {
    HandleScope scope;
    Local<External>wrap = Local<External>::Cast(args[0]);
    Buffer *buf = (Buffer *) wrap->Value();
    String::Utf8Value data(args[1]);
#ifdef BUFFER_STRING
    buf->s += Base64Decode(*data);
#else
    //char decodeBuf[len];
    char* decodeBuf = new char[data.length()];
    long decodeLen = decode_base64((unsigned char *) decodeBuf, *data);
    bufferWrite(buf, decodeBuf, decodeLen);
    delete decodeBuf;
#endif
    return Undefined();
}
コード例 #14
0
ファイル: dmpobjmd.c プロジェクト: jossk/open-watcom-v2
static DUMP_INFO* dumpDataMemb( // DUMP A DATA MEMBER
    DUMP_INFO *di,              // - dump information
    const char *kind,           // - kind of field
    const char *name,           // - field name
    target_offset_t offset,     // - field offset
    target_size_t size )        // - field size
{
    di = bufferInit( di );
    di = bufferStr( di, kind );
    di = bufferChr( di, ' ' );
    di = bufferStr( di, name );
    di = bufferStr( di, ", offset = " );
    di = bufferNmb( di, offset );
    di = bufferStr( di, ", size = " );
    di = bufferNmb( di, size );
    di = bufferWrite( di );
    return di;
}
コード例 #15
0
ファイル: buffer.cpp プロジェクト: Apister/SilkJS-WIn
/**
 * @function buffer.write
 *
 * ### Synopsis
 * buffer.write(buf, str);
 *
 * Write a string into the specified buffer.
 *
 * @param {object} buf - buffer to write string to.
 * @param {string{ str - string to add to buffer.
 */
static JSVAL buffer_write (JSARGS args) {
    HandleScope scope;
    Local<External>wrap = Local<External>::Cast(args[0]);
    Buffer *buf = (Buffer *) wrap->Value();
    String::Utf8Value data(args[1]);
    bufferWrite(buf, *data, data.length());
    //#ifdef BUFFER_STRING
    //	buf->s += *data;
    //#else
    //	long len = args[2]->IntegerValue();
    //    if (buf->pos + len >= buf->size) {
    //		while (buf->pos + len >= buf->size) {
    //			buf->size *= 2;
    //		}
    //		buf->mem = (unsigned char *)realloc(buf->mem, buf->size);
    //    }
    //    memcpy(&buf->mem[buf->pos], *data, len);
    //    buf->pos += len;
    //    buf->mem[buf->pos] = '\0';
    //#endif
    return Undefined();
}
コード例 #16
0
ファイル: Framebuffer.cpp プロジェクト: enki1986/TFT
void Framebuffer::copyRect(int16_t dx, int16_t dy, int16_t sx, int16_t sy, uint16_t w, uint16_t h) {
    uint32_t dpos;
    uint32_t spos;
    translateCoordinates(&dx, &dy);
    for (int y = 0; y < w; y++) {
        for (int x = 0; x < h; x++) {
            if (sx > dx && sy > dy) {
                dpos = (y + dy) * _width + (x + dx);
                spos = (y + sy) * _width + (x + sx);
            } else if(sx <= dx && sy > dy) {
                dpos = (y + dy) * _width + ((w - x) + dx);
                spos = (y + sy) * _width + ((w - x) + sx);
            } else if(sx > dx && sy <= dy) {
                dpos = ((h - y) + dy) * _width + (x + dx);
                spos = ((h - y) + sy) * _width + (x + sx);
            } else if(sx <= dx && sy <= dy) {
                dpos = ((h - y) + dy) * _width + ((w - x) + dx);
                spos = ((h - y) + sy) * _width + ((w - x) + sx);
            }
            bufferWrite(dpos, bufferRead(spos));
        }
    }
}
コード例 #17
0
int main(void) {

	initUSART();
	_delay_ms(200);

	uint8_t i;
	uint8_t tempCharStorage;

	while (1) {

		dumpBuffer();
		printString("  Demo: adding characters to buffer\n");
		uint8_t coolString[] = "Howdy";
		i = 0;
		while(i < sizeof(coolString) - 1){
			bufferWrite(coolString[i]);
			++i;
			dumpBuffer();
		}

		printString("  Demo: reading out the first three characters\n");
		for (i = 0; i<3 ; i++){	
			bufferRead(&tempCharStorage);
			transmitByte(tempCharStorage);	
			printString("\n");
			dumpBuffer();
		}

		printString("  Demo: adding more characters to buffer\n");
		uint8_t anotherString[] = "Hello";	
		i = 0;
		while(i < sizeof(anotherString) - 1){
			bufferWrite(anotherString[i]);
			++i;
			dumpBuffer();
		}

		// And read it back out using return code
		printString("  Demo: reading everything back out\n");
		while (bufferRead(&tempCharStorage) == BUFFER_OK){
			transmitByte(tempCharStorage);	
		}
		printString("\n");
		
		dumpBuffer();
		printString("  Demo: empty! (newest = oldest)\n");

		// Fill up buffer, using return code
		i = 0;
		while(bufferWrite('A'+i) == BUFFER_OK){
			++i;
			dumpBuffer();
		}

		printString("  Note: never fills up whole buffer\n");
		printString("  it's full when first index equals last\n");

		return 0;

	}                                                  /* End event loop */
	return 0;                              /* This line is never reached */
}
コード例 #18
0
ファイル: main.c プロジェクト: Armannas/TMS
int main(void) {
	PORTE.DIRSET |= 0xFF;
	PORTD.DIRSET = 0x00;
	PORTD.PIN1CTRL = 0b00011010;
	PORTC.DIRSET |= 0x01;

	
	
  while(1)
  {
    /* Read the next incoming event. Usually this is a blocking function. */
   // EVENTS event = readEventFromMessageQueue();
	
	if((flag.HARDWARE_ERROR_FLAG == 1 || flag.OVERTEMP_FLAG == 1) && flag.DISCHARGED_FLAG == 0)
	{
		state = DISCHARGE;
	}   
	
	/* Finite State Machine */
	switch(state)
    {
		
	case INIT:
		init_clock();
		init();
		interrupt_init();
		UART_init();
		AC_init();
		init_DAC();
		init_GPIO_interrupt();
//		init_counter();
		
		// Start by using capbank 1
		flag.CAPBANK_FLAG = 0;
		PORTE.OUT = 0x00;
		//_delay_ms(4000);
		
		// comparator reference voltages
		
		// Desired voltage reference level expressed in Capacitor voltage
		// TODO: high_trigger_cap is based on user_settings.voltage_amplitude which is in percent but should be converted to absolute.

		double low_trigger_cap = 0.3;
		
		// Voltage divided, digital version of capacitor voltage
		uint16_t high_trigger_b;
		uint16_t low_trigger_b;

//		high_trigger_b = voltage_to_DAC(voltage_to_vdac(high_trigger_cap));


		low_trigger_b = voltage_to_DAC(low_trigger_cap);
		
		state = STANDBY;
        break;

	case STANDBY:
		PORTE.OUT = 0x01;

		if (flag.PRECHARGE_FLAG)
		{
			state = PRECHARGE;
// 			PORTE.OUT = 0x04;
// 			_delay_ms(3000);
			break;
		}
		
		else if(flag.WRITE_FLAG)
		{
			state = WRITE;
			//delay_ms(3000);
			break;
		}
		
		else if(flag.READ_FLAG)
		{
			state = READ;
			// PORTE.OUT = 0x05;
			//_delay_ms(3000);
			break;
		}
		
		else if(!(PORTD.IN & (1 << 1)))
		{
			PORTE.OUT = 0x06;
			//_delay_ms(3000);
			if(user_settings.mode == 0)
			{
				state = SINGLE_PULSE;
				break;
			}
			else if(user_settings.mode == 1)
			{
				state = PAIRED_PULSE;
				break;
			}
		}
		
		else
		{
			state = STANDBY;
			break;
		}
		break;
		
	case PRECHARGE:
		// Clear precharge flag
		flag.PRECHARGE_FLAG = 0;
		flag.DISCHARGED_FLAG = 0;
		
		PORTE.OUT = 0x03;
		//_delay_ms(3000);
		// Set AC trigger high
//		write_DAC(high_trigger_b);
		write_DAC(voltage_to_DAC(voltage_to_vdac(user_settings.voltage_amplitude * V_MAX)));	
		
			// Go to pulse state, single or paired depending on user settings
			if (user_settings.mode == 0) // single pulse mode
			{
				// Capbank 1
				if (flag.CAPBANK_FLAG == 0)
				{
					// Close precharge switch Capbank 1
					PRECHARGE1_ON;
					PORTC.OUT |= (1 << 0);
					// check if precharge reference triggered
					if(ACA.STATUS & (1 << 4) )
					{
						// TODO: Open precharge switch
						PRECHARGE1_OFF;
						PORTC.OUT &= ~(1 << 0);
						PORTE.OUT = 0x04;
						//_delay_ms(3000);
						
						// Send precharge ready ACK
						USARTF0.DATA = 0x06;
						
						state = STANDBY;
						break;
					}
				}
				
				// Capbank 2
				else if (flag.CAPBANK_FLAG == 1)
				{
					// Close precharge switch Capbank 2
					PRECHARGE2_ON;
					//PORTC.OUT |= (1 << 0);
					// check if precharge reference triggered
//					if(ACA.STATUS & (1 << 5) )
					if(ACA.STATUS & (1 << 4) )
					{
						// TODO: Open precharge switch
						PRECHARGE2_OFF;
						//PORTC.OUT &= ~(1 << 0);
						PORTE.OUT = 0x04;
						//_delay_ms(3000);
						
						// Send precharge ready ACK
						USARTF0.DATA = 0x06;
						
						state = STANDBY;
					}
				}
			}
			
			else if (user_settings.mode == 1) // paired pulse mode
			{
				PRECHARGE1_ON;
				//PORTC.OUT |= (1 << 0);
				// check if precharge reference capbank 1 triggered
				if (ACA.STATUS & (1 << 4) )
				{
					// Open precharge switch capbank 1
					PRECHARGE1_OFF;
					//PORTC.OUT &= ~(1 << 0);
					PORTE.OUT = 0x04;
					//_delay_ms(1500);
					
					PRECHARGE2_ON;
					//PORTC.OUT |= (1 << 0);
					// check if precharge reference capbank 2 triggered
//					if (ACA.STATUS & (1 << 5) )
					if (ACA.STATUS & (1 << 4) )
					{
						// Open precharge switch capbank 2
						PRECHARGE2_OFF;
						//PORTC.OUT &= ~(1 << 0);
						PORTE.OUT = 0x05;
						//_delay_ms(1500);
						
						// Send precharge ready ACK
						USARTF0.DATA = 0x06;
						state = STANDBY;
					}	
				}
			}
		
		else
		{
			PORTE.OUT = 0x07;
			//_delay_ms(1500);
			// stay in precharge if trigger level not reached
			state = PRECHARGE;
		}

		break;

	case READ:
		//_delay_ms(3000);
		PORTE.OUT = 0x03;
		// read stuff here
		// TODO: read not possible yet
		
		state = STANDBY;
		break;
		
	case WRITE:
		PORTE.OUT = 0x02;
		// write stuff here
		bufferWrite(&UART_buffer_write, USARTF0.DATA);
		// Get  char from RX buffer
		flag.WRITE_FLAG = 0;
		//_delay_ms(1500);
		
		state = STANDBY;
		break;


		
	case SINGLE_PULSE:
		// set reference for AC with DAC
		write_DAC(low_trigger_b);
		
		// single pulse here
		PORTE.OUT = 0x05;
		//_delay_ms(3000);
		

		if (flag.CAPBANK_FLAG == 0)
		{
			// Pulse using capbank 1
			single_pulse(CAPBANK1);
			// TODO: Wait for pulse to damp out
			_delay_ms(1);
		}
		
		else
		{
			// Pulse using capbank 2
			single_pulse(CAPBANK2);
			// TODO: Wait for pulse to damp out
			_delay_ms(1);
		}
		
		
		// Toggle capbank used
		flag.CAPBANK_FLAG ^= (1 << 0);
		break;
		
	case PAIRED_PULSE:
		// paired pulse here
		PORTE.OUT = 0x05;
		//_delay_ms(3000);
		// set reference for AC with DAC
		write_DAC(low_trigger_b);
		state = STANDBY;
		// Pulse using capbank 1
		single_pulse(CAPBANK1);
		
// 		_delay_us(50);
		delay_in_ms(user_settings.interstimulus_interval);
		// Pulse using capbank 2
		single_pulse(CAPBANK2);
		_delay_us(50);
		// TODO: Wait for pulse to damp out
		//_delay_ms(1);
		// When finished, go to precharge state again to wait for new pulse
		state = STANDBY;
		break;
		
	case DISCHARGE:
	PORTE.OUT = 0x08;
	//_delay_ms(3000);
	// set reference for AC with DAC
	write_DAC(low_trigger_b);
	DISCHARGE1_ON;
	DISCHARGE2_ON;
	
	// Discharge complete when both capbank voltages below AC reference
	//		if ( (ACA.STATUS & (1 << 4)) && (ACA.STATUS & (1 << 5)) )
	if ( !(ACA.STATUS & (1 << 4)))

	{
		DISCHARGE1_OFF;
		DISCHARGE2_OFF;
		flag.DISCHARGED_FLAG = 1;
		flag.HARDWARE_ERROR_FLAG = 0;
		flag.OVERTEMP_FLAG = 0;
// 		_delay_ms(5000);
		state = STANDBY;
	}
	
	else
	{
		// Keep discharging
		state = DISCHARGE;
	}
	break;

    }
  } 
}