コード例 #1
0
ファイル: codegen.c プロジェクト: james276657/code
unsigned char * generate(treenode * root)
{
	unsigned char * program = (unsigned char *)malloc(MAX_PROGRAM);
	int pc = 0;

	// header
	pc += 8;
	
	// static variables
	program[2] = hibyte(pc);
	program[3] = lobyte(pc);
	pc = generate_static_variables(program, pc);
	 
	// program
	program[4] = hibyte(pc);
	program[5] = lobyte(pc);
	pc = generateBLOCK(program, pc, root);
	program[pc++] = OPCODE_EXIT;

	// stack
	program[6] = hibyte(pc);
	program[7] = lobyte(pc);
	pc += STACK_SIZE;
	
	// fix up header's size member
	program[0] = hibyte(pc);
	program[1] = lobyte(pc);

	return program;
}
コード例 #2
0
// Send data from LCD to PC via RS-232 using the XMODEM protocol
static inline void SendBMP(void) {
    uint8_t rx,data,Packet=1, n=0,i,j;
    uint16_t crc=0;

    // First Block
    send(SOH);
    send(Packet);       // Send Packet number
    send(255-Packet);   // Send Packet number 1's complement
    // Send BMP Header
    for(i=0; i<62; i++) {
        n++;
        data = pgm_read_byte_near(BMP+i);
        crc=_crc_xmodem_update(crc,data);
        send(data);
    }

    // Send LCD data, 64 lines
    for(i=63; i!=255; i--) {
        // Each LCD line consists of 16 bytes
        for(j=0; j<16; j++) {
            data=transpose(j*8,i);
            crc=_crc_xmodem_update(crc,data);
            send(data);
            n++;
            if(n==128)  {   // end of 128byte block
                n=0;
                send(hibyte(crc));
                send(lobyte(crc));
                // Wait for ACK
                rx = read();
                if(rx!=ACK) return; // Error -> cancel transmission
                Packet++;
                send(SOH);
                send(Packet);
                send(255-Packet);
                crc=0;
            }
        }
    }

    // End of last block
    for(; n<128; n++) { // send remainder of block
        data= 0x1A;     // pad with 0x1A which marks the end of file
        crc=_crc_xmodem_update(crc,data);
        send(data);
    }
    send(hibyte(crc));
    send(lobyte(crc));
    rx = read();
    if(rx!=ACK) return;
    send(EOT);
    rx = read();
    if(rx!=NAK) return;
    send(EOT);
    rx = read();
    if(rx!=ACK) return;
}
コード例 #3
0
ファイル: codegen.c プロジェクト: james276657/code
int generateIF(unsigned char * program, int pc, treenode * root)
{
	int temppc, calcpc;
	
	//Go process the boolean operator first J. Brooks
	
	treenode * child = firstchild(root);
	pc = generateOPERATOR(program, pc, child);
	
	//Pop the exteraneous push first
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;
	
	//Jump around the the false parameter load if bool is true (True cmp val is already loaded by Operator processing)
	program[pc++] = OPCODE_JEq;
	program[pc++] = hibyte(4);
	program[pc++] = lobyte(4);

    //Load for false process jmp
	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G2;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);
	program[pc++] = OPCODE_CMP_RR;
	program[pc++] = REGISTER_G1;
	program[pc++] = REGISTER_G2;

	//jmp around block if test was false
	program[pc++] = OPCODE_JEq;
    temppc = pc;
	//Reserve jump relative param spots
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);

	//Process the block
	child = nextchild(root,child);
	pc = generateBLOCK(program, pc, child);

	//calc the block size
	calcpc = pc - temppc - 2;
	
	//fix up the jump relative
	program[temppc++] = hibyte(calcpc);
	program[temppc++] = lobyte(calcpc);
	
	return pc;
}
コード例 #4
0
ファイル: ARPDUMP.C プロジェクト: HenkVanAsselt/ax25-packmon
/*-#+func----------------------------------------------------------
    FUNCTION: inet_ntoa()
     PURPOSE: Convert an internet address (in host byte order)
              to a dotted decimal ascii string, e.g., 255.255.255.255\0
      SYNTAX:
 DESCRIPTION:
     RETURNS:
     HISTORY:
--#-func----------------------------------------------------------*/
char *inet_ntoa(int32 a)
{
  static char buf[25];

  sprintf(buf,"%u.%u.%u.%u",
              hibyte(hiword(a)),
              lobyte(hiword(a)),
              hibyte(loword(a)),
              lobyte(loword(a)) );
  return buf;
}
コード例 #5
0
void PAS_SetSampleRateTimer
   (
   void
   )

   {
   int LoByte;
   int HiByte;
   int data;
   unsigned flags;

   flags = DisableInterrupts();

   // Disable the Sample Rate Timer
   data = PAS_State->audiofilt;
   data &= ~SampleRateTimerGateFlag;
   PAS_Write( AudioFilterControl, data );
   PAS_State->audiofilt = data;

   // Select the Sample Rate Timer
   data = SelectSampleRateTimer;
   PAS_Write( LocalTimerControl, data );
   PAS_State->tmrctlr = data;

   LoByte = lobyte( PAS_TimeInterval );
   HiByte = hibyte( PAS_TimeInterval );

   // Program the Sample Rate Timer
   PAS_Write( SampleRateTimer, LoByte );
   PAS_Write( SampleRateTimer, HiByte );
   PAS_State->samplerate = PAS_TimeInterval;

   RestoreInterrupts( flags );
   }
コード例 #6
0
ファイル: trace.c プロジェクト: dieterdeyke/WAMPES
/* Print a buffer up to 16 bytes long in formatted hex with ascii
 * translation, e.g.,
 * 0000: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f  0123456789:;<=>?
 */
static void
fmtline(
FILE *fp,
uint addr,
uint8 *buf,
uint len)
{
	char line[80];
	char *aptr,*cptr;
	uint8 c;

	memset(line,' ',sizeof(line));
	ctohex(line,(uint)hibyte(addr));
	ctohex(line+2,(uint)lobyte(addr));
	aptr = &line[6];
	cptr = &line[55];
	while(len-- != 0){
		c = *buf++;
		ctohex(aptr,(uint)c);
		aptr += 3;
		*cptr++ = isprint(c) ? c : '.';
	}
	*cptr++ = '\n';
	fwrite(line,1,(unsigned)(cptr-line),fp);
}
コード例 #7
0
ファイル: UIDropMsg.cpp プロジェクト: CecilHarvey/BlueDJGames
void UIDropMsg::on_okButton_clicked()
{
	djDebug()<<"UIDropMsg::on_okButton_clicked";
	
	QString broadcastMsg	= lineEdit->text();
    QByteArray	utf8	= broadcastMsg.toUtf8();
    	
	QByteArray	buf(sizeof(DJGameProtocol)+sizeof(ChatContent) + utf8.size() + 1,0);
    DJGameProtocol *protocol	= reinterpret_cast<DJGameProtocol *>(buf.data());
    protocol->chTotalLen	= buf.size();
    protocol->chType = DJGAME_PROTOCOL_TYPE_CHAT;
    protocol->chLanguage = m_gameController->language();     
        
    ChatContent	*chat	= reinterpret_cast<ChatContent *>(protocol->chBuf);
    setle4( &chat->userid_speaker, m_gameController->selfUserId() );
    setle4( &chat->userid_listener, DJGAME_PLAYER_BROADCAST );
    chat->chGameClass = hibyte(m_gameController->gameId());
    chat->chGame = lobyte(m_gameController->gameId());
    
    qstrcpy( chat->szSentence, utf8.data() );
    
	DJClientRequest request( buf );
	m_gameController->sendRequest( request );
	
	close();
}
コード例 #8
0
ファイル: 6510.c プロジェクト: trieck/source
void _jsr(void)
{
    word addr;
    push(hibyte(cpu.pc + 3));
    push(lobyte(cpu.pc + 3));
    addr = fetch_word((word)(cpu.pc + 1));
    cpu.pc = addr;
}
コード例 #9
0
ファイル: 6510.c プロジェクト: trieck/source
void _brk(void)
{
    push(hibyte(cpu.pc + sizeof(word)));
    push(lobyte(cpu.pc + sizeof(word)));
    push(cpu.sr);
    set_brk_flag();

    set_int_disable_flag();
    cpu.pc = fetch_word(IRQ_VECTOR);
}
コード例 #10
0
ファイル: codegen.c プロジェクト: james276657/code
int generateNUMBER(unsigned char * program, int pc, treenode * root)
{
	// LOAD_R G1 value
	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = hibyte(root->attribute.value);
	program[pc++] = lobyte(root->attribute.value);

	// PUSH_R G1
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;

	return pc;
}
コード例 #11
0
ファイル: codegen.c プロジェクト: james276657/code
int generateCOLOR_NAME(unsigned char * program, int pc, treenode * root)
{
	//Push a value representing a color (0-15) on the stack  J. Brooks

	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = hibyte(root->attribute.color);
	program[pc++] = lobyte(root->attribute.color);

	// PUSH_R G1
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;
	
	return pc;
}
コード例 #12
0
ファイル: clkinit.c プロジェクト: 9MMMinor/avrXinu-V7
/*
 *------------------------------------------------------------------------
 * clkinit - initialize the clock and sleep queue (called at startup)
 *------------------------------------------------------------------------
 */
void clkinit()
{

	preempt = QUANTUM;		/* initial time quantum		*/
	countTick = TICK;	 	/* TICKs of a sec. counter	*/
	clmutex = screate(1);	/* semaphore for tod clock	*/
	clktime = 0L;			/* initially a low number	*/
	ctr100 = 0L;			/* timer (relative)			*/
	slnempty = FALSE;		/* initially, no process asleep	*/
	clkdiff = 0;			/* zero deferred ticks		*/
	defclk = FALSE;				/* clock is not deferred	*/
	clkruns = 1;
	clockq = newqueue();

	/* Initialize timer 3 (System Clock) */
	/* 100 Hz clock 16000000/256/(1+624) */
	/* OCR3A set to 624 for CTC mode */
	OCR3AH = hibyte(624);	/* 0-624 => divide by 625 */
	OCR3AL = lobyte(624);	/* write high byte first!	*/
	  
    TCNT3L = 0x00;
	TCNT3H = 0x00;
	TCCR3A = 0x00;			/* normal port operation, WGM31=0 WGM30=0 */
	TCCR3B = (1<<CS32) | (0<<CS31) | (0<<CS30);	/* (clock source/256) for 62500Hz */
	TCCR3B |= (1 << WGM32);	/* normal mode 4: CTC w/OCR3A */
	TCCR3C = 0x00;

	TIMSK3 |= (1<<OCF3A);	/* Clear overflow flag bit */
    TIMSK3 |= (1<<OCIE3A);	/* Output Compare A Match Interrupt Enable */
	
	/* Initialize timer 2 (RTC) */
	TIMSK2 &= ~((1<<TOIE2)|(1<<OCIE2A)|(1<<OCIE2B));     //Disable TC2 interrupt
    ASSR |= (1<<AS2);           //set Timer/Counter2 to be asynchronous from the CPU clock
	//with a second external clock(32.768kHz)driving it.
    TCNT2 = 0x00;
	TCCR2A = 0x00;				//normal mode 0
    TCCR2B = 0x05;              //prescale the timer to be clock source / 128
//
//TIMER2 quit working on me 12/21/2013 -- change rtc & MAC Symbol counter!!!!!!!!!!!!!!!!!!
//
//	while(ASSR&0x1F)
		//	while(ASSR&( (1<<TCR2BUB)|(1<<OCR2BUB)|(1<<TCN2UB) ))
//		;	//Wait until TC0 is updated
//	TIFR2 |= (1<<TOV2);			//Clear overflow flag bit
//    TIMSK2 |= (1<<TOIE2);       //set 8-bit Timer/Counter0 Overflow Interrupt Enable
		
}
コード例 #13
0
//    0   1   2   3   4   5   6   7
//  |...|...|...|...|...|...|...|...|
//   ^
//   |
//   sample bit 3 times
//
// Display the HEX value of the digital stream
void HEXSerial(void) {
    int8_t start,end;
    int16_t increment,index;
    // The vertical cursors define the section to decode
    start = M.VcursorA;
    end   = M.VcursorB;
    // If the vertical cursors are off, use the entire screen
    if(!testbit(Mcursors, cursorv)) {
        start = 0;
        end   = 127;
    }
    increment = (end-start);
	increment<<=3;
    if(Srate>=11) {
        increment*=2;
        start=start<<1;
    }
    uint8_t result;							// Does not need to be initialized
    uint8_t data,bit=0,yPos,mask;
    yPos = M.CHDpos>>3;
    for(mask=0x80; mask; mask=mask>>1) {	// Loop 8 digital channels
        index = (start<<8);
        if(Srate<11) index+=(M.HPos<<8);
        index+=increment;
        if(CHDmask&mask) {					// Is this channel on?
            for(uint8_t i=1; i<=32; i++) {	// Scan buffer
                data = DC.CHDdata[hibyte(index)];
                if(!(i&0x03)) {				// Time to check bits when i is multiple of 4
                    result<<=1;
                    if(bit) result+=1;
                    bit=0;
                }
                else {
                    if(data&mask) bit++;
                }
                index+=increment;
            }
            lcd_goto(120,yPos);				// Print on right edge of the screen
            printhex(result);
            yPos++;
        }
    }
}
コード例 #14
0
ファイル: crypt.cpp プロジェクト: Mileslee/wxgis
bool Crypt(const wxString &sText, wxString &sCryptText)
{
    sCryptText.Clear();
    const wxString sPass(PASSWD);
    size_t pos(0);
    for(size_t i = 0; i < sText.Len(); ++i)
    {
        if(pos == sPass.Len())
            pos = 0;
        wxUint32 val1 = sText[i];
        wxUint32 val2 = sPass[pos];
        wxUint32 Symbol = val1 ^ val2;
        char SymbolHi = hibyte(Symbol);
        char SymbolLo = lobyte(Symbol);//(Symbol >> 4) & 0xff;
		sCryptText += wxDecToHex(SymbolHi);
		sCryptText += wxDecToHex(SymbolLo);
        pos++;
    }
	return true;
}
コード例 #15
0
ファイル: yhy632.c プロジェクト: chaplin1999/yhy632
int yhy632_send_command(int fd, unsigned short command, unsigned char * data, int data_len) {
    unsigned short length = 2 + 2 + 1 + data_len;
    unsigned char header0 = YHY632_HEADER_FIRST;
    unsigned char header1 = YHY632_HEADER_SECOND;
    unsigned char zero = 0;
    
    unsigned char checksum = 0x00;
    
    unsigned char * payload;

    do_write(fd, &header0, 1);
    do_write(fd, &header1, 1);

    do_write(fd, &length, 2); 

    do_write(fd, &zero, 1);
    do_write(fd, &zero, 1);
    checksum ^= 0;
    
    do_write(fd, &command, 2); 
    checksum ^= hibyte(command);
    checksum ^= lobyte(command);
    
    int i ;
    for (i = 0; i < data_len; i++) {
        do_write(fd, data + i, 1); 
        checksum ^= data[i];
        if (data[i] == 0xAA) {
           
            do_write(fd, &zero, 1);
        }
    }   
    
    do_write(fd, &checksum, 1); 
    fdatasync(fd);
}
コード例 #16
0
ファイル: awg.c プロジェクト: Roborix/Xproto-Watch-Firmware
// Output Frequency = cycles * 125000 / Period
void BuildWave(void) {
    uint8_t i,j;
    int8_t *p;
    uint16_t step;          // used in duty cycle calculation
    uint16_t d;             // used in duty cycle calculation
    uint32_t Flevel=1600000;
    if(M.AWGamp>0)                  M.AWGamp=0;                 // AWGAmp must be negative
    if(M.AWGduty==0)                M.AWGduty=1;                // Zero is invalid
    if(M.AWGdesiredF<100)           M.AWGdesiredF = 100;        // Minimum Freq= 1Hz
    else if(M.AWGdesiredF>12500000) M.AWGdesiredF = 12500000;	// Maximum Freq= 125KHz

    // Minimum frequency with cycle=32: 61Hz
    // Maximum frequency with cycle=1:  3.906kHz
    // Tradeoff: Frequency resolution  <-> Amplitude resolution
    // Low periods have poor Freq resolution
    // High cycles have poor Amp resolution
    // Determine number of cycles               // F > 16000 -> cycles = 32
    for(i=0, cycles=64; i<6; i++) {             // F >  8000 -> cycles = 16
        if(M.AWGdesiredF>Flevel) break;         // F >  4000 -> cycles =  8
		Flevel=Flevel>>1;                       // F >  2000 -> cycles =  4
        cycles=cycles>>1;                       // F >  1000 -> cycles =  2
    }                                           // F >   500 -> cycles =  1
    // Construct waveform                       // else cycles = 1, prescaler=2
    i=0;
    uint16_t Seed;
    p=(int8_t *)Temp.DATA.AWGTemp1;
    switch(M.AWGtype) {
        case 0: // Random
            Seed = TCD1.CNT;
            do {
                Seed = 25173 * Seed + 1;
                *p++ = hibyte(Seed);
            } while(++i);
        break;
        case 1: // Sine
            do { *p++ = Sin(i+64); } while(++i);
        break;
        case 2: // Square
            do { *p++ = (i<128)?-127:127; } while(++i);
        break;
        case 3: // Triangle
            for(;i<128;i++) *p++ = 127-((i)<<1);
            do { *p++ = -127+(i<<1); } while(++i);
        break;
        case 4: // Exponential
            for(;i<128;i++) *p++ = -pgm_read_byte_near(Exp+i);
            do { *p++ = pgm_read_byte_near(Exp-128+i); } while(++i);
        break;
        case 5: // Custom wave from EEPROM
            eeprom_read_block(Temp.DATA.AWGTemp1, EEwave, 256);
        break;
    }
    // Prepare buffer:
    // ******** Duty cycle ********
    i=0; step=0; d=(256-M.AWGduty)<<1;
	int8_t k;
    p=(int8_t *)Temp.DATA.AWGTemp1;
    do {
        j=hibyte(step);
        Temp.DATA.AWGTemp2[j] = *p;
        k=*p++;
        if(j<255) Temp.DATA.AWGTemp2[j+1] = (k+(*p))/2;
        step+=d;
        if(i==127) d=M.AWGduty<<1;
    } while(++i);
    i=0;
    step = ((6250000 * cycles) / M.AWGdesiredF ) - 1;
    PMIC.CTRL = 0x06;   // Disable low level interrupts
    if(cycles>1) TCD1.CTRLA = 0x01;   // Prescaler: clk/1
    else         TCD1.CTRLA = 0x02;   // Prescaler: clk/2
    // Avoid discontinuity when changing frequency by writing to PERBUF
    TCD1.PERBUF = step;    // Set Period
    uint8_t c;
    c=cycles>>1;
    if(c==0) c++;
    do {
    // ******** Multiply by Gain ********
        j=FMULS8(M.AWGamp,Temp.DATA.AWGTemp2[(uint8_t)(i*c)]);
    // ******** Add Offset ********
        AWGBuffer[i]=saddwsat(j,M.AWGoffset);
    } while(++i);
    clrbit(MStatus, updateawg);
    PMIC.CTRL = 0x07; // Enable all interrupts
}
コード例 #17
0
ファイル: codegen.c プロジェクト: james276657/code
int generateIFELSE(unsigned char * program, int pc, treenode * root)
{
	int temppc, calcpc;

    //Similar to if processing, except a true block and a false block	

	treenode * child = firstchild(root);
	pc = generateOPERATOR(program, pc, child);

	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_JEq;
	program[pc++] = hibyte(4);
	program[pc++] = lobyte(4);
	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G2;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);
	program[pc++] = OPCODE_CMP_RR;
	program[pc++] = REGISTER_G1;
	program[pc++] = REGISTER_G2;
	program[pc++] = OPCODE_JEq;
 
	//Setup to jump the true block
	temppc = pc;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);

	//Make the true block
	child = nextchild(root,child);
	pc = generateBLOCK(program, pc, child);

	//Size the true block
	calcpc = pc - temppc + 1;
	program[temppc++] = hibyte(calcpc);
	program[temppc++] = lobyte(calcpc);

    //Setup to jump the false block
	program[pc++] = OPCODE_JMPRe;
    temppc = pc;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);

	//Make the false block
	child = nextchild(root,child);
	pc = generateBLOCK(program, pc, child);

	//Size the false block
	calcpc = pc - temppc-2;
	program[temppc++] = hibyte(calcpc);
	program[temppc++] = lobyte(calcpc);

	
	return pc;
}
コード例 #18
0
ファイル: util.c プロジェクト: alhazred/onarm
Boolean_t
util_create_guid(char **guid)
{
	eui_16_t	eui;
	/*
	 * We only have room for 32bits of data in the GUID. The hiword/loword
	 * macros will not work on 64bit variables. The work, but produce
	 * invalid results on Big Endian based machines.
	 */
	uint32_t	tval = (uint_t)time((time_t *)0);
	size_t		guid_size;
	int		i, fd;

	if ((mac_len == 0) && (if_find_mac(NULL) == False)) {

		/*
		 * By default strict GUID generation is enforced. This can
		 * be disabled by using the correct XML tag in the configuration
		 * file.
		 */
		if (enforce_strict_guid == True)
			return (False);

		/*
		 * There's no MAC address available and we've even tried
		 * a second time to get one. So fallback to using a random
		 * number for the MAC address.
		 */
		if ((fd = open("/dev/random", O_RDONLY)) < 0)
			return (False);
		if (read(fd, &eui, sizeof (eui)) != sizeof (eui))
			return (False);
		(void) close(fd);

		eui.e_vers		= SUN_EUI_16_VERS;
		eui.e_company_id[0]	= 0;
		eui.e_company_id[1]	= 0;
		eui.e_company_id[2]	= SUN_EN;

	} else {
		bzero(&eui, sizeof (eui));

		eui.e_vers	= SUN_EUI_16_VERS;
		/* ---- [0] & [1] are zero for Sun's IEEE identifier ---- */
		eui.e_company_id[2]	= SUN_EN;
		eui.e_timestamp[0]	= hibyte(hiword(tval));
		eui.e_timestamp[1]	= lobyte(hiword(tval));
		eui.e_timestamp[2]	= hibyte(loword(tval));
		eui.e_timestamp[3]	= lobyte(loword(tval));
		for (i = 0; i < min(mac_len, sizeof (eui.e_mac)); i++) {
			eui.e_mac[i] = mac_addr[i];
		}

		/*
		 * To prevent duplicate GUIDs we need to sleep for one
		 * second here since part of the GUID is a time stamp with
		 * a one second resolution.
		 */
		sleep(1);
	}

	if (tgt_xml_encode((uint8_t *)&eui, sizeof (eui), guid,
	    &guid_size) == False) {
		return (False);
	} else
		return (True);
}
コード例 #19
0
ファイル: codegen.c プロジェクト: james276657/code
int generateOPERATOR(unsigned char * program, int pc, treenode * root)
{
	//Math and boolean operators are handeled here J. Brooks

    //Get values for left and right values out of the tree J. Brooks

	// generate code for each child
	treenode * child = firstchild(root);
	while (child != NULL)
	{
		pc = generate_expression(program, pc, child);
		child = nextchild(root, child);
	}

	// POP_R G2
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G2;
	
	// POP_R G1
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;

	//Process math functions J. Brooks

	if (root->attribute.op == OT_PLUS)
	{
		// ADD_R G1 G2
		program[pc++] = OPCODE_ADD_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
	}

	if (root->attribute.op == OT_MINUS)
	{
		// Sub_R G1 G2
		program[pc++] = OPCODE_SUB_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
	}

	if (root->attribute.op == OT_TIMES)
	{
		// Mul_R G1 G2
		program[pc++] = OPCODE_MUL_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
	}

	if (root->attribute.op == OT_DIVIDE)
	{
		// Divide_R G1 G2
		program[pc++] = OPCODE_DIV_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
	}

	
	//Process boolean functions  J. Brooks
	//Flags are set by the compares for the jumps done by the caller (if/ifelse) 
	
	if (root->attribute.op == OT_EQUALS)
	{
		// Compare G1 G2
		program[pc++] = OPCODE_CMP_RR;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
		program[pc++] = OPCODE_LOAD_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = hibyte(1);
		program[pc++] = lobyte(1);
		
	}

	if (root->attribute.op == OT_LESSTHAN)
	{
		// Compare G1 G2
		program[pc++] = OPCODE_CMP_RR;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
		program[pc++] = OPCODE_LOAD_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = hibyte(1);
		program[pc++] = lobyte(1);
		
	}

	if (root->attribute.op == OT_GREATERTHAN)
	{
		// Compare G1 G2
		program[pc++] = OPCODE_CMP_RR;
		program[pc++] = REGISTER_G1;
		program[pc++] = REGISTER_G2;
		program[pc++] = OPCODE_LOAD_R;
		program[pc++] = REGISTER_G1;
		program[pc++] = hibyte(1);
		program[pc++] = lobyte(1);
		
	}
	
	// PUSH_R G1
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;
	
	return pc;
}
コード例 #20
0
ファイル: util.c プロジェクト: imp/slist
			return (False);
		(void) close(fd);

		eui.e_vers		= SUN_EUI_16_VERS;
		eui.e_company_id[0]	= (SUN_EN >> 16) & 0xff;
		eui.e_company_id[1]	= (SUN_EN >> 8) & 0xff;
		eui.e_company_id[2]	= SUN_EN & 0xff;

	} else {
		bzero(&eui, sizeof (eui));

		eui.e_vers	= SUN_EUI_16_VERS;
		eui.e_company_id[0]	= (SUN_EN >> 16) & 0xff;
		eui.e_company_id[1]	= (SUN_EN >> 8) & 0xff;
		eui.e_company_id[2]	= SUN_EN & 0xff;
		eui.e_timestamp[0]	= hibyte(hiword(tval));
		eui.e_timestamp[1]	= lobyte(hiword(tval));
		eui.e_timestamp[2]	= hibyte(loword(tval));
		eui.e_timestamp[3]	= lobyte(loword(tval));
		for (i = 0; i < min(mac_len, sizeof (eui.e_mac)); i++) {
			eui.e_mac[i] = mac_addr[i];
		}

		/*
		 * To prevent duplicate GUIDs we need to sleep for one
		 * second here since part of the GUID is a time stamp with
		 * a one second resolution.
		 */
		(void) sleep(1);
	}
コード例 #21
0
ファイル: initialize.c プロジェクト: 9MMMinor/avrXinu-V7
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL	sysinit()
{

	int i,j,len;
	struct pentry *pptr;	 /* null process entry */
	struct sentry *sptr;
	struct mblock *volatile mptr;

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

	memlist.mnext = mptr =		/* initialize free memory list */
	    (struct mblock *volatile) roundmb(__malloc_heap_start);
	mptr->mnext = (struct mblock *)NULL;
	mptr->mlen = len = (int) truncmb(RAMEND - NULLSTK - (unsigned)&__bss_end);
	__malloc_heap_start = (char *)mptr;
	__malloc_heap_end = __malloc_heap_start + len;
	kprintf_P(PSTR("Heap: %p of length %d\n"), mptr, len);
	
	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;

	/* initialize null process entry */
	pptr = &proctab[NULLPROC];
	pptr->pstate = PRCURR;
	for (j=0; j<6; j++)
		pptr->pname[j] = "nullp"[j];

	pptr->plimit = (unsigned char *)(RAMEND + 1) - NULLSTK;
	pptr->pbase = (unsigned char *) RAMEND;
	*pptr->pbase = (unsigned char)MAGIC; 	/* clobbers return, but proc 0 doesn't return */
	pptr->paddr = (int *) main;
	pptr->pargs = 0;
	pptr->pprio = 0;
	pptr->pregs[SSP_L] = lobyte((unsigned int)pptr->plimit);	/* for error checking */
	pptr->pregs[SSP_H] = hibyte((unsigned int)pptr->plimit);	/* for error checking */
	currpid = NULLPROC;

	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());	/* initialize ready list */

	
#ifdef	MEMMARK
	kprintf("Memory marking\n");
	_mkinit();			/* initialize memory marking */
#else
	kprintf("Pool init\n");
	poolinit();			/* explicitly */
	pinit(MAXMSGS);
#endif

#ifdef	RTCLOCK
	kprintf("init RTC\n");
	clkinit();			/* initialize r.t.clock	*/
#endif

#ifdef NDEVS
	for ( i=0 ; i<NDEVS ; i++ ) {
		if (i>0) kprintf("init dev %d\n", i);
	    init(i);
	}
#endif

#ifdef	NNETS
//	kprintf("net init\n");
	netinit();
#endif

	return (OK);
}
コード例 #22
0
ファイル: uartsun.c プロジェクト: yeonsh/Amoeba
static long	K_ttynum;

/* which device is the console */
static int	Console;

static char z8530Btabl[] =
{
    R(9),	0xC0,		/* force hardware reset */
    R(4),	0x44,		/* x16 clock, 1 stop, no parity */
    R(3),	0xC0,		/* RCV: 8 bits/char */
    R(5),	0x60,		/* XMT: 8 bits/char */
    R(1),	0x53,		/* no WAIT/DMA REQ, R-IRQ, T-IRQ */
    R(10),	0x00,		/* NRZ mode */
    R(11),	0x50,		/* RXC+TXC = BRG output */
    R(12),	lobyte(OSPEED),
    R(13),	hibyte(OSPEED),
    R(15),	0x00,		/* external interrupts disabled */
    R(14),	0x07,		/* BRG = PCLK */
    R(2),	0x40,		/* interrupt vector (couldn't get it to work) */
    R(5),	0x6A,		/* XMT: 8 bits/char, TXD enabled, DTR=L */
    R(3),	0xC1,		/* RCV: 8 bits/char, RXD enabled */
    R(9),	0x00,		/* interrupts disabled */
    0,		0
};

static char z8530Atabl[] =
{
    R(4),	0x44,		/* x16 clock, 1 stop, no parity */
    R(3),	0xC0,		/* RCV: 8 bits/char */
    R(5),	0x60,		/* XMT: 8 bits/char */
    R(1),	0x53,		/* no WAIT/DMA REQ, R-IRQ, T-IRQ */
コード例 #23
0
ファイル: codegen.c プロジェクト: james276657/code
int generateREPEAT(unsigned char * program, int pc, treenode * root)
{
	int temppc, temppc2, calcpc;
	//printf("Entering generateREAPET with root type %i and attribute %i\n",root->type,root->attribute.func);

	//Repeat build.  First get the repeat count
	treenode * child = firstchild(root);
	pc = generate_expression(program, pc, child);
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;
	
	//Bump loop count for pre decrement
	program[pc++] = OPCODE_INC_R; 
	program[pc++] = REGISTER_G1;

	//Push loop count
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;
	
	//Jump to pre decrement processing
	program[pc++] = OPCODE_JMPRe;

    temppc = pc;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);

	child = nextchild(root,child);

	//Process the block
	temppc2 = pc;
	pc = generateBLOCK(program, pc, child);

    //Fix up the jump
	calcpc = pc - temppc-2;
	program[temppc++] = hibyte(calcpc);
	program[temppc++] = lobyte(calcpc);

	//Decr and compare loop count
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_DEC_R; 
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_PUSH_R;
	program[pc++] = REGISTER_G1;
	program[pc++] = OPCODE_LOAD_R;
	program[pc++] = REGISTER_G2;
	program[pc++] = hibyte(0);
	program[pc++] = lobyte(0);
	program[pc++] = OPCODE_CMP_RR;
	program[pc++] = REGISTER_G1;
	program[pc++] = REGISTER_G2;

	//Loop done jump to finish
	program[pc++] = OPCODE_JEq;
	program[pc++] = hibyte(3);
	program[pc++] = lobyte(3);

	//Continue more repeat jump back to top of block
	program[pc++] = OPCODE_JMPRe;
	calcpc = temppc2 - pc - 2;
	program[pc++] = hibyte(calcpc);
	program[pc++] = lobyte(calcpc);

	//Clean the stack
	program[pc++] = OPCODE_POP_R;
	program[pc++] = REGISTER_G1;

	return pc;
}
コード例 #24
0
   // Select the Sample Buffer Count
   data = SelectSampleBufferCount;
   PAS_Write( LocalTimerControl, data );
   PAS_State->tmrctlr = data;

   count = PAS_TransferLength;

   // Check if we're using a 16-bit DMA channel
   if ( PAS_DMAChannel > 3 )
      {
      count >>= 1;
      }

   LoByte = lobyte( count );
   HiByte = hibyte( count );

   // Program the Sample Buffer Count
   PAS_Write( SampleBufferCount, LoByte );
   PAS_Write( SampleBufferCount, HiByte );
   PAS_State->samplecnt = count;

   RestoreInterrupts( flags );
   }


/*---------------------------------------------------------------------
   Function: PAS_SetPlaybackRate

   Sets the rate at which the digitized sound will be played in
   hertz.
コード例 #25
0
ファイル: yhy632.c プロジェクト: chaplin1999/yhy632
// returns count bytes recieved, -1 otherwise
int yhy632_recieve_data(int fd, unsigned short expected_cmd, unsigned char * status, char * data) {
    unsigned char prev_byte = 0;
    unsigned char current_byte = 0;
    unsigned short cmd;
    
    while ( 1 ) { //expected_cmd != cmd
        while (1) {
            if (synchronous_read(fd, &current_byte, 1, YHY632_TIMEOUT) >= 0)  {
                if (( prev_byte  == YHY632_HEADER_FIRST ) && ( current_byte  == YHY632_HEADER_SECOND )) {
                    // header found, stop
                    if (verbose) fprintf(logfd, "header found stop\n");
                    break;
                }
            
                prev_byte = current_byte;
            } else {
                fprintf(logfd, "failed to get header!\n");
                return -2;
            } 
        }
        
        unsigned short length;
        unsigned short reserved;
        
        
        unsigned char checksum = 0;
        unsigned char original_checksum;
        
        if ( synchronous_read(fd, &length, 2, YHY632_TIMEOUT) < 1) return -2;        
        if (verbose) fprintf(logfd, "length: %d\n", length);
        
        if (length == 0x000a && expected_cmd == 0x0212) {
            length = 0x0d;
        }
                
        if ( synchronous_read(fd, &reserved, 2, YHY632_TIMEOUT) < 1) return -2;
        checksum ^= hibyte(reserved);
        checksum ^= lobyte(reserved);
        
        if ( synchronous_read(fd, &cmd, 2, YHY632_TIMEOUT) < 1) return -2;
        
        if (cmd != expected_cmd)  continue ;
        
        
        checksum ^= lobyte(cmd);     checksum ^= hibyte(cmd); 
        
        
        
        if ( synchronous_read(fd, status, 1, YHY632_TIMEOUT) < 1) return -2;
        
        
        
        
        checksum ^= *status;
        

        int i;
        //reading data
        
        if ( synchronous_read(fd, data, length - 6, YHY632_TIMEOUT) < length - 6) return -2;

        for (i=0; i < length -6; i++  ) {
            checksum ^= data[i];        
        }
        
        synchronous_read(fd, &original_checksum, 1, YHY632_TIMEOUT);
        
        
        if (original_checksum == checksum) {            
            return length - 6;
        } else {
            if (*status == 0) {
                fprintf(logfd, "checksum %d should be %d\n", original_checksum, checksum);
            }
            return -1;
        }
    }
        
    
}
コード例 #26
0
ファイル: create.c プロジェクト: 9MMMinor/avrXinu-V7
SYSCALL create(int (*procaddr)(), int ssize, int priority, char *name, int nargs, ...)
{
	STATWORD ps;    
	int pid;				/* stores new process id	*/
	struct pentry *pptr;	/* pointer to proc. table entry */
	int i;
	unsigned char *saddr;			/* stack address		*/
	int INITRET();
	va_list ap;

	disable(ps);
	ssize = (int) roundmb(ssize);
	if ( (saddr = (unsigned char *)getstk(ssize)) == (unsigned char *)SYSERR ) {
	    restore(ps);
	    return (SYSERR);
	}
	if ( ssize < MINSTK || (pid=newpid()) == SYSERR || priority < 1 ) {
	    freestk((unsigned)saddr, (unsigned)ssize);
	    restore(ps);
	    return(SYSERR);
	}
	numproc++;
	pptr = &proctab[pid];
	
	/* stderr set to &kprint_out (see kprintf.c and initialize.c) */
	pptr->fildes[0] = fdopen(CONSOLE, "r");	/* stdin set to console */
	pptr->fildes[1] = fdopen(CONSOLE, "w");	/* stdout set to console */
	pptr->fildes[2] = &kprint_out;			/* stderr set to &kprint_out */

	for (i=2; i < _NFILE; i++)			/* others set to unused */
		pptr->fildes[i] = (FILE *)FDFREE;

	pptr->pstate = PRSUSP;
	for (i=0 ; i<PNMLEN && (int)(pptr->pname[i]=name[i])!=0 ; i++)
		;
	pptr->pprio = priority;
	pptr->pbase = saddr;
	pptr->pstklen = ssize;
	pptr->psem = 0;
	pptr->phasmsg = FALSE;
	pptr->plimit = pptr->pbase - ssize + sizeof (WORD);	
	*saddr-- = (char)MAGIC;		/* Bottom of stack */
	pptr->pargs = nargs;
	for (i=0 ; i<PNREGS ; i++)
		pptr->pregs[i] = INITREG;	
	pptr->paddr = (int *)procaddr;
	pptr->pregs[SPC_L] = lobyte((unsigned) procaddr);
	pptr->pregs[SPC_H] = hibyte((unsigned) procaddr);
	pptr->pregs[SSREG] = INITPS;
	pptr->pnxtkin = BADPID;
	pptr->pdevs[0] = pptr->pdevs[1] = BADDEV;
	
	va_start(ap,nargs);
	for (i=0 ; i < nargs; i++)
		{
	    pptr->parg[i] = va_arg(ap, unsigned int);
		}
	va_end(ap);
	pptr->parg[nargs] = 0;
	
	/* machine/compiler dependent pass arguments to created process */
	pptr->pregs[24] = lobyte((unsigned)pptr->pargs);	/*r24*/
	pptr->pregs[25] = hibyte((unsigned)pptr->pargs);
	pptr->pregs[22] = lobyte((unsigned)&pptr->parg[0]);	/*r22*/
	pptr->pregs[23] = hibyte((unsigned)&pptr->parg[0]);

	*saddr-- = lobyte((unsigned)INITRET);	/* push on initial return address*/
	*saddr-- = hibyte((unsigned)INITRET);
//	*saddr-- = 0;	/* 256Kb memory device */ /*TODO make conditional*/
	*saddr-- = lobyte((unsigned)procaddr);	/* push on procedure address	*/
	*saddr-- = hibyte((unsigned)procaddr);
//	*saddr-- = 0;	/* 256Kb memory device */ /*TODO make conditional*/
	pptr->pregs[SSP_L] = lobyte((unsigned) saddr);
	pptr->pregs[SSP_H] = hibyte((unsigned) saddr);

	restore(ps);
	return(pid);
}