Exemplo n.º 1
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	uartSetBaudRate(115200);
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// initialize the timer system
	timerInit();
	// initialize vt100 terminal
	vt100Init();

	timerPause(100);

	// print welcome message
	vt100ClearScreen();
	vt100SetCursorPos(1,0);
	rprintfProgStrM("\r\nWelcome to the MMC Test Suite!\r\n");

	timerPause(1000);

	mmcTest();

	return 0;
}
Exemplo n.º 2
0
void spyglassTest(void)
{
	// initializing Spyglass interface and I2C bus
	rprintf("Initializing Spyglass communication...");
	spyglassInit();
	spyglassLcdInit();
	rprintf("Done!\r\n");
	rprintf("Printing 'Hello World!' message to spyglass LCD.\r\n");

	rprintfInit(spyglassLcdWriteChar);
	spyglassLcdGotoXY(0,0);
	rprintfProgStrM("Hello World!");
	rprintfInit(uartSendByte);

	timerPause(1000);

	// initialize systick timer
	rprintf("Initializing Periodic Timer\r\n");
	timer2SetPrescaler(TIMERRTC_CLK_DIV1024);
	// attach the 'systickHandler' so that it gets called every time Timer2 overflows
	timerAttach(TIMER2OVERFLOW_INT, systickHandler);

	rprintf("Starting local command prompt.  Type '?' to get help.\r\n");
	rprintf("cmd>");

	while(1)
	{
		serviceLocal();
	}
}
Exemplo n.º 3
0
void gpsNmeaTest(void)
{
	// set the baud rate of UART 1 for NMEA
	uartSetBaudRate(1,4800);

	// clear screen
	vt100ClearScreen();
	// initialize gps library
	gpsInit();
	// initialize gps packet decoder 
	nmeaInit();

	// begin gps packet processing loop
	while(1)
	{
		// process received gps packets until receive buffer is exhausted
		while( nmeaProcess(uartGetRxBuffer(1)) );

		// set cursor position to top left of screen
		vt100SetCursorPos(0,0);
		// print/dump current formatted GPS data
		gpsInfoPrint();
		// print UART 1 overflow status to verify that we're processing packets
		// fast enough and that our receive buffer is large enough
		rprintf("Uart1RxOvfl: %d\r\n",uartRxOverflow[1]);
		// pause for 100ms
		timerPause(100);
	}
}
Exemplo n.º 4
0
void ads7870test(void)
{
	u08 i;
	u16 conv=0;

	// initialize a/d converter
	if(ads7870Init())
	{
		rprintf("ADS7870 detected and initialized!\r\n");
	}
	else
	{
		rprintf("Cannot detect ADS7870!\r\n");
		return;
	}
	
	while(1)
	{
		// position cursor
		vt100SetCursorPos(4,1);

		for(i=0; i<8; i++)
		{
			// convert
			conv = ads7870Convert(i);
			// print results
			rprintf("CH#%d: Conversion result is: %d    \r\n", i, conv);
		}
		// pause between readings
		timerPause(100);
	}
}
Exemplo n.º 5
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	uartSetBaudRate(9600);
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	a2dInit();
	// initialize the timer system
	timerInit();
	// initialize vt100 terminal
	vt100Init();

	// configure port B for led output and pushbutton input
	outb(DDRB, 0x0F);
	// all LEDs on
	outb(PORTB, 0x00);
	// wait for hardware to power up
	timerPause(100);
	// all LEDs off
	outb(PORTB, 0x0F);

	// start command line
	goCmdline();

	return 0;
}
Exemplo n.º 6
0
void EtherShield::ES_enc28j60Init(uint8_t* macaddr){
  /*initialize enc28j60*/
  enc28j60Init(macaddr);
  enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
  timerPause(10);

  /* Magjack leds configuration, see enc28j60 datasheet, page 11 */
  // LEDA=greed LEDB=yellow
  //
  // 0x880 is PHLCON LEDB=on, LEDA=on
  // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
  enc28j60PhyWrite(PHLCON,0x880);
  delay(500);
  //
  // 0x990 is PHLCON LEDB=off, LEDA=off
  // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
  enc28j60PhyWrite(PHLCON,0x990);
  delay(500);
  //
  // 0x880 is PHLCON LEDB=on, LEDA=on
  // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
  enc28j60PhyWrite(PHLCON,0x880);
  delay(500);
  //
  // 0x990 is PHLCON LEDB=off, LEDA=off
  // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
  enc28j60PhyWrite(PHLCON,0x990);
  delay(500);
  //
  // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
  // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
  enc28j60PhyWrite(PHLCON,0x476);
  delay(100);
}
Exemplo n.º 7
0
void ataDriveInit(void)
{
	u08 i;
	unsigned char* buffer = (unsigned char*) SECTOR_BUFFER_ADDR;

	// read drive identity
	rprintfProgStrM("\r\nScanning IDE interface...\r\n");
	// Wait for drive to be ready
	ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
	// issue identify command
	ataWriteByte(ATA_REG_CMDSTATUS1, 0xEC);
	// wait for drive to request data transfer
	ataStatusWait(ATA_SR_DRQ, ATA_SR_DRQ);
	timerPause(200);
	// read in the data
	ataReadDataBuffer(buffer, 512);

	// set local drive info parameters
	ataDriveInfo.cylinders =		*( ((unsigned int*) buffer) + ATA_IDENT_CYLINDERS );
	ataDriveInfo.heads =			*( ((unsigned int*) buffer) + ATA_IDENT_HEADS );
	ataDriveInfo.sectors =			*( ((unsigned int*) buffer) + ATA_IDENT_SECTORS );
	ataDriveInfo.LBAsupport =		*( ((unsigned int*) buffer) + ATA_IDENT_FIELDVALID );
	ataDriveInfo.sizeinsectors =	*( (unsigned long*) (buffer + ATA_IDENT_LBASECTORS*2) );
	// copy model string
	for(i=0; i<40; i+=2)
	{
		// correct for byte order
		ataDriveInfo.model[i  ] = buffer[(ATA_IDENT_MODEL*2) + i + 1];
		ataDriveInfo.model[i+1] = buffer[(ATA_IDENT_MODEL*2) + i    ];
	}
	// terminate string
	ataDriveInfo.model[40] = 0;

	// process and print info
	if(ataDriveInfo.LBAsupport)
	{
		// LBA support
		rprintf("Drive 0: %dMB ", ataDriveInfo.sizeinsectors/(1000000/512) );
		rprintf("LBA mode -- MODEL: ");
	}
	else
	{
		// CHS, no LBA support
		// calculate drive size
		ataDriveInfo.sizeinsectors = (unsigned long) ataDriveInfo.cylinders*
												ataDriveInfo.heads*ataDriveInfo.sectors;
		rprintf("Drive 0: %dMB ", ataDriveInfo.sizeinsectors/(1000000/512) );
		rprintf("CHS mode C=%d H=%d S=%d -- MODEL: ", ataDriveInfo.cylinders, ataDriveInfo.heads, ataDriveInfo.sectors );
	}
	// print model information	
	rprintfStr(ataDriveInfo.model); rprintfCRLF();

	// initialize local disk parameters
	//ataDriveInfo.cylinders = ATA_DISKPARM_CLYS;
	//ataDriveInfo.heads = ATA_DISKPARM_HEADS;
	//ataDriveInfo.sectors = ATA_DISKPARM_SECTORS;

}
Exemplo n.º 8
0
int main()
{
	consoleDemoInit();

	uint ticks = 0;
	TimerStates state = timerState_Stop;
	int down = keysDown();

	while(!(down & KEY_START))
	{
		swiWaitForVBlank();
		consoleClear();
		scanKeys();
		down = keysDown();

		if(state == timerState_Running)
		{
			ticks += timerElapsed(0);
		}

		if(down & KEY_A)
		{
			if(state == timerState_Stop)
			{
				timerStart(0, ClockDivider_1024, 0, NULL);
				state = timerState_Running;
			}
			else if(state == timerState_Pause)
			{
				timerUnpause(0);
				state = timerState_Running;
			}
			else if(state == timerState_Running)
			{
				ticks += timerPause(0);
				state = timerState_Pause;
			}
		}
		else if(down & KEY_B)
		{
			timerStop(0);
			ticks = 0;
			state = timerState_Stop;
		}

		iprintf("Press A to start and pause the \ntimer, B to clear the timer \nand start to quit the program.\n\n");
		iprintf("ticks:  %u\n", ticks);
		iprintf("second: %u:%u\n", ticks/TIMER_SPEED, ((ticks%TIMER_SPEED)*1000) /TIMER_SPEED);
	}

	if(state != timerState_Stop)
	{
		timerStop(0);
	}

	return 0;
}
Exemplo n.º 9
0
void servoTest(void)
{
	u08 pos;
	u08 channel;

	// do some examples
	// initialize RC servo system
	servoInit();
	// setup servo output channel-to-I/Opin mapping
	// format is servoSetChannelIO( CHANNEL#, PORT, PIN );
	servoSetChannelIO(0, _SFR_IO_ADDR(PORTC), PC0);
	servoSetChannelIO(1, _SFR_IO_ADDR(PORTC), PC1);
	servoSetChannelIO(2, _SFR_IO_ADDR(PORTC), PC2);
	servoSetChannelIO(3, _SFR_IO_ADDR(PORTC), PC3);

	// set port pins to output
	outb(DDRC, 0x0F);

	pos = 0;

#define SPEED_SERVO	1

	// spin servos sequentially back and forth between their limits
	while(1)
	{
		for(channel=0; channel<SERVO_NUM_CHANNELS; channel++)
		{
			for(pos=0; pos<SERVO_POSITION_MAX; pos++)
			{
				servoSetPosition(channel,pos);
				timerPause(SPEED_SERVO);
			}
		}

		for(channel=0; channel<SERVO_NUM_CHANNELS; channel++)
		{
			for(pos=SERVO_POSITION_MAX; pos>=1; pos--)
			{
				servoSetPosition(channel,pos);
				timerPause(SPEED_SERVO);
			}
		}
	}
}
Exemplo n.º 10
0
void extintTest(void)
{
	u16 temp0, temp1;

	// print a little intro message so we know things are working
	rprintf("\r\n\n\nWelcome to the External Interrupt library test program!\r\n");
	
	// initialize the external interrupt library
	rprintf("Initializing external interrupt library\r\n");
	extintInit();

	// configure external interrupts for rising-edge triggering.
	// when a rising-edge pulse arrives on INT0 or INT1,
	// the interrupt will be triggered
	rprintf("Configuring external interrupts\r\n");
	extintConfigure(EXTINT0, EXTINT_EDGE_RISING);
	extintConfigure(EXTINT1, EXTINT_EDGE_RISING);

	// attach user interrupt routines.
	// when the interrupt is triggered, the user routines will be executed
	rprintf("Attaching user interrupt routines\r\n");
	extintAttach(EXTINT0, myInt0Handler);
	extintAttach(EXTINT1, myInt1Handler);

	// enable the interrupts
	rprintf("Enabling external interrupts\r\n");
	// (support for this has not yet been added to the library)
	sbi(GIMSK, INT0);
	sbi(GIMSK, INT1);

	// In this loop we will count the number of external interrupts,
	// and therefore the number of rising edges, that occur in one second.
	// This is precisely the frequency, in cycles/second or Hz, of the signal
	// that is triggering the interrupt.

	while(1)
	{
		// reset interrupt counters
		Int0Count = 0;
		Int1Count = 0;
		// wait 1 second
		timerPause(1000);
		// get counter values
		temp0 = Int0Count;
		temp1 = Int1Count;
		// print results
		rprintf("Frequency on INT0 pin: %dHz -- On INT1 pin: %dHz\r\n", temp0, temp1);
	}
}
Exemplo n.º 11
0
int main(void)
{
	timerInit();				// initializing timers
	uartInit();					// initializing serial port
	uartSetBaudRate(115200);	// set serial port baud rate
	rprintfInit(uartSendByte);	// direct rprintf() output to go to serial port
	timerPause(100);			// wait for a moment

	// print welcome message
	rprintf("\r\n\n\nWelcome to the Spyglass UI test.\r\n");

	// begin test application
	spyglassTest();

	return 0;
}
Exemplo n.º 12
0
void ads7828test(void)
{
	u08 i;
	u16 conv=0;

	// initialize i2c function library
	i2cInit();
	i2cSetBitrate(30);

	// initialize
	if(ads7828Init(ADS7828_I2C_ADDR))
	{
		rprintf("ADS7828 detected and initialized!\r\n");
	}
	else
	{
		rprintf("Cannot detect ADS7828!\r\n");
		return;
	}
	
	// use the externally applied voltage on REF pin
	ads7828SetReference(0);
	// or use the internal 2.5V voltage reference
	//ads7828SetReference(1);

	while(1)
	{
		// position cursor
		vt100SetCursorPos(4,1);

		for(i=0; i<8; i++)
		{
			// convert
			conv = ads7828Convert(ADS7828_I2C_ADDR, i);
			// print results
			rprintf("CH#%d: Conversion result is: %d    \r\n", i, conv-2048);
		}
		// pause between readings
		timerPause(100);
	}
}
Exemplo n.º 13
0
int main(void)
{
    // initialize processor
    processorInit();
    // initialize timers
    timerInit();
    // initialize uarts
    uart0Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8);
    uart1Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8);
    // initialize rprintf to use UART1 for output
    rprintfInit(uart1SendByte);

    // Wait for a moment to allow hardware to stabilize.
    // This may be important if a serial port level-converter
    // like the MAX232 is used.  Charge-pump based converters
    // need some time after power-up to charge before
    // communication is reliable.
    timerPause(50);		// waits 50 milliseconds

    // run the test
    uartTest();

    return 0;
}
Exemplo n.º 14
0
int main(void)
{
	struct netEthAddr myEthAddress;

	timerInit();
	uartInit();
	uartSetBaudRate(9600);
	rprintfInit(uartSendByte);
	timerPause(100);
	rprintf("\r\nNetwork Stack Example\r\n");

	// initialize systick timer
	rprintf("Initializing Periodic Timer\r\n");
	timer2SetPrescaler(TIMER_CLK_DIV1024);
	timerAttach(TIMER2OVERFLOW_INT, systickHandler);

	// init network stack
	rprintf("Initializing Network Stack\r\n");
	netstackInit(IPADDRESS, NETMASK, GATEWAY);

	nicGetMacAddress(&myEthAddress.addr[0]);
	rprintfProgStrM("Eth Addr is: "); netPrintEthAddr(&myEthAddress); rprintfCRLF();
	rprintfProgStrM("IP  Addr is: "); netPrintIPAddr(ipGetConfig()->ip); rprintfCRLF();

	rprintf("Network Stack is up!\r\n");
	rprintf("Starting packet receive loop\r\n");

	while (1)
	{
		// service local stuff
		serviceLocal();
		// service the network
		netstackService();
	}
	return 0;
}
Exemplo n.º 15
0
void lcdtest(void)
{
	unsigned char key = 0;

	glcdClearScreen();

	glcdSetAddress(4,LINE2);
	glcdPutStr("Graphic LCD Test");
	glcdSetAddress(4,LINE3);
	glcdPutStr("HD61202/3 controller");
	glcdSetAddress(4,LINE4);
	glcdPutStr("KS0108/7 controller");
	glcdSetAddress(4,LINE5);
	glcdPutStr("Press buttons to");
	glcdSetAddress(4,LINE6);
	glcdPutStr("test functions...");
	glcdRectangle(0, 0, 64, 128);
  
	while(1)
	{
		timerPause(10);
		key = ~inb(PINA);
		glcdSetAddress(4,LINE7);
		rprintf("Button status: %x  ", key);

		if(key == KEY1)
		{
			unsigned char i ;
			glcdClearScreen();	
			for ( i=0; i<128; i+=3)
			{
				glcdSetDot(i,63 - i/2);
  				glcdDelay(0x5fff);
			}
			for ( i=0; i<128; i+=3)
			{
				glcdClearDot(i,63 - i/2);
  				glcdDelay(0x5fff);
			}
		}
		
		if(key == KEY2)
		{
			glcdClearScreen();	
  			glcdCircle(25,20,17);
  			glcdDelay(0xffff);
  			glcdCircle(90,30,15);
  			glcdDelay(0xffff);
  			glcdCircle(55,30,23);
  			glcdDelay(0xffff);
  			glcdCircle(100,48,15);
  			glcdDelay(0xffff);
  			glcdCircle(34,50,10);
  			glcdDelay(0xffff);
  			glcdCircle(60,55,8);
		}
      
		if(key == KEY3)
		{
			glcdClearScreen();	
			glcdRectangle(54, 41, 6 , 12);
  			glcdDelay(0xffff);
			glcdRectangle(34, 12, 32, 2);
  			glcdDelay(0xffff);
			glcdRectangle(23, 34, 17, 21);
  			glcdDelay(0xffff);
			glcdRectangle(62, 20, 42, 58);
  			glcdDelay(0xffff);
			glcdRectangle(4 , 30, 12, 12);
		}
		
		if(key == KEY4)
		{
			glcdClearScreen();	
			glcdSetAddress(0,LINE1);	
			glcdPutStr("LINE 1"); glcdDelay(0xffff);
			glcdSetAddress(5,LINE2);
			glcdPutStr("LINE 2"); glcdDelay(0xffff);
			glcdSetAddress(10,LINE3);
			glcdPutStr("LINE 3"); glcdDelay(0xffff);
			glcdSetAddress(15,LINE4);
			glcdPutStr("LINE 4"); glcdDelay(0xffff);
			glcdSetAddress(20,LINE5);
			glcdPutStr("LINE 5"); glcdDelay(0xffff);
			glcdSetAddress(25,LINE6);
			glcdPutStr("LINE 6"); glcdDelay(0xffff);
			glcdSetAddress(30,LINE7);
			glcdPutStr("LINE 7"); glcdDelay(0xffff);
			glcdSetAddress(35,LINE8);
			glcdPutStr("LINE 8"); glcdDelay(0xffff);
		}

		if(key == KEY5)
		{
			glcdClearScreen();	
			glcdSetAddress(0,LINE2);
  			glcdPutStr(" !");
  			glcdWriteChar('"');
  			glcdPutStr("#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  			glcdPutStr("[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
		}
		
		if(key == KEY6)
		{
			unsigned char i;
			for (i=0; i<64; i++)
			{
				glcdStartLine(64- i - 1);
  				glcdDelay(0x5fff);
			}
		}
		
		if(key == KEY7)
		{
			unsigned char i;
			for (i=0; i<64; i++)
			{
				glcdStartLine(i + 1);
  				glcdDelay(0x5fff);
			}
		}
		
		if (key == KEY8)
		{
			//	glcdBackLight(OFF);	
			//	glcdBackLight(ON);	
		}   
	}
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: elzk/nds-ide
static
portTASK_FUNCTION(Key_Press, pvParameters)
{
    int down = keysDown();
        

    while(!(down & KEY_START))
    {int k=0;
        swiWaitForVBlank();
        consoleClear();
        scanKeys();
        down = keysDown();

        if(state == timerState_Running)
        {
            ticks += timerElapsed(0);
        }

        if(down & KEY_A)
        {
            if(state == timerState_Stop)
            {
                timerStart(0, ClockDivider_1024, 0, NULL);
                state = timerState_Running;
            }
            else if(state == timerState_Pause)
            {
                timerUnpause(0);
                state = timerState_Running;
                
            }
            else if(state == timerState_Running)
            {
                ticks += timerPause(0);
                state = timerState_Pause;
                sc[j] = ticks/TIMER_SPEED;
                scp[j] = ((ticks%TIMER_SPEED)*1000) /TIMER_SPEED;
                j++;
                

            }

        }
        else if(down & KEY_B)
        {
            timerStop(0);
            ticks = 0;
            state = timerState_Stop;
            j = 0;
        }

        iprintf("(A)     : Start & Pause Timer.\n(B)     : Clean Timer.\n(Start) : Exit Timer.\n\n");
        iprintf("Time\n");
        iprintf("ticks:  %u\n", ticks);
        iprintf("second: %u:%u\n", ticks/TIMER_SPEED, ((ticks%TIMER_SPEED)*1000) /TIMER_SPEED);
        iprintf("LIST\n");
        for(i = 0; i < j; i++) {
        iprintf(" [%d] :  %u : %u \n",i+1, sc[i],scp[i]);
        }
   	        
	

    }

    if(state != timerState_Stop)
    {
        timerStop(0);
    }
    vTaskDelay(portMAX_DELAY);
}
Exemplo n.º 17
0
void testI2cMemory(void)
{
	u08 i;
	u08 txdata[66];
	u08 rxdata[66];

	rprintfProgStrM("\r\nRunning I2C memory test (24xxyy devices)\r\n");

	// compose address
	txdata[0] = 0;
	txdata[1] = 0;
	// compose data
	for(i=0; i<16; i++)
		txdata[2+i] = localBuffer[i];
	// send address and data
	i2cMasterSendNI(TARGET_ADDR, 18, txdata);
	
	rprintfProgStrM("Stored data: ");
	// null-terminate data
	txdata[18] = 0;
	rprintfStr(&txdata[2]);
	rprintfCRLF();
	
	timerPause(100);

	// send address
	i2cMasterSendNI(TARGET_ADDR, 2, txdata);
	// get data
	i2cMasterReceiveNI(TARGET_ADDR, 16, rxdata);
	// null-terminate received string
	rxdata[16] = 0;

	rprintfProgStrM("Received data: ");
	rprintfStr(rxdata);
	rprintfCRLF();
/*
	u08 c;
	u16 addr=0;

	while(1)
	{
		while(!uartReceiveByte(&c));

		switch(c)
		{
		case '+':
			addr+=64;
			break;
		case '-':
			addr-=64;
			break;
		}
		c = 0;
		txdata[0] = (addr>>8);
		txdata[1] = (addr&0x00FF);
		i2cMasterSendNI(TARGET_ADDR, 2, txdata);
		i2cMasterReceiveNI(TARGET_ADDR, 64, rxdata);
		rprintfProgStrM("Received data at ");
		rprintfu16(addr);
		rprintfProgStrM(":\r\n");
		debugPrintHexTable(64, rxdata);
	}
*/
}
Exemplo n.º 18
0
/*
 * Print a running summary of interface statistics.
 * Repeat display every interval seconds, showing statistics
 * collected over that interval.  Assumes that interval is non-zero.
 * First line printed at top of screen is always cumulative.
 */
static void
sidewaysintpr(unsigned int interval)
{
	register struct iftot *ip, *total;
	register int line;
	struct iftot *lastif, *sum, *interesting, ifnow, *now = &ifnow;
	struct variable_list *var;
	oid varname[MAX_OID_LEN], *instance, *ifentry;
	size_t varname_len;
	int ifnum, cfg_nnets;

	lastif = iftot;
	sum = iftot + MAXIF - 1;
	total = sum - 1;
	interesting = iftot;
	var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid));
	if (var) {
	    cfg_nnets = *var->val.integer;
	    snmp_free_var(var);
	}
	else
	    return;
	memmove(varname, oid_ifname, sizeof(oid_ifname));
	varname_len = sizeof(oid_ifname) / sizeof(oid);
	for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets; ifnum++) {
		char *cp;

		ip->ift_name[0] = '(';
		varname[10] = ifnum;
		var = getvarbyname(Session, varname, varname_len);
		if (var){
		    if (var->val_len >= (sizeof(ip->ift_name) - 3))
		        var->val_len = (sizeof(ip->ift_name) - 4);
		    memmove(ip->ift_name + 1, var->val.string, var->val_len);
		    snmp_free_var(var);
		}
                cp = (char *) strchr(ip->ift_name, ' ');
                if ( cp != NULL )
                  *cp = '\0';
		if (intrface && strcmp(ip->ift_name + 1, intrface) == 0)
			interesting = ip;
		ip->ift_name[15] = '\0';
		cp = (char *) strchr(ip->ift_name, '\0');
		sprintf(cp, ")");
		ip++;
		if (ip >= iftot + MAXIF - 2)
			break;
	}
	lastif = ip;

	timerSet(interval);

banner:
	printf("     input   %-6.6s     output       ", interesting->ift_name);
	if (lastif - iftot > 0)
		printf("                 input  (Total)     output");
	for (ip = iftot; ip < iftot + MAXIF; ip++) {
		ip->ift_ip = 0;
		ip->ift_ie = 0;
		ip->ift_op = 0;
		ip->ift_oe = 0;
		ip->ift_co = 0;
	}
	putchar('\n');
	printf("%10.10s %8.8s %10.10s %8.8s %8.8s ",
		"packets", "errs", "packets", "errs", "colls");
	if (lastif - iftot > 0)
		printf("%10.10s %8.8s %10.10s %8.8s %8.8s ",
			"packets", "errs", "packets", "errs", "colls");
	putchar('\n');
	fflush(stdout);
	line = 0;
loop:
	sum->ift_ip = 0;
	sum->ift_ie = 0;
	sum->ift_op = 0;
	sum->ift_oe = 0;
	sum->ift_co = 0;
	memmove(varname, oid_ifinucastpkts, sizeof(oid_ifinucastpkts));
	varname_len = sizeof(oid_ifinucastpkts) / sizeof(oid);
	ifentry = varname + 9;
	instance = varname + 10;
	for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets && ip < lastif; ip++, ifnum++) {
		memset(now, 0, sizeof(*now));
		*instance = ifnum;
		*ifentry = INUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_ip = *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = INNUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_ip += *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = INERRORS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_ie = *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = OUTUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_op = *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = OUTNUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_op += *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = OUTERRORS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_oe = *var->val.integer;
		    snmp_free_var(var);
		}

		if (ip == interesting)
			printf("%10d %8d %10d %8d %8d ",
				now->ift_ip - ip->ift_ip,
				now->ift_ie - ip->ift_ie,
				now->ift_op - ip->ift_op,
				now->ift_oe - ip->ift_oe,
				now->ift_co - ip->ift_co);
		ip->ift_ip = now->ift_ip;
		ip->ift_ie = now->ift_ie;
		ip->ift_op = now->ift_op;
		ip->ift_oe = now->ift_oe;
		ip->ift_co = now->ift_co;
		sum->ift_ip += ip->ift_ip;
		sum->ift_ie += ip->ift_ie;
		sum->ift_op += ip->ift_op;
		sum->ift_oe += ip->ift_oe;
		sum->ift_co += ip->ift_co;
	}
	if (lastif - iftot > 0)
		printf("%10d %8d %10d %8d %8d ",
			sum->ift_ip - total->ift_ip,
			sum->ift_ie - total->ift_ie,
			sum->ift_op - total->ift_op,
			sum->ift_oe - total->ift_oe,
			sum->ift_co - total->ift_co);
	*total = *sum;
	putchar('\n');
	fflush(stdout);
	line++;

	timerPause();
	timerSet(interval);

	if (line == 21)
		goto banner;
	goto loop;
	/*NOTREACHED*/
}
Exemplo n.º 19
0
void i2cTest(void)
{
	u08 c=0;
	showByte(0x55);

	// initialize i2c function library
	i2cInit();
	// set local device address and allow response to general call
	i2cSetLocalDeviceAddr(LOCAL_ADDR, TRUE);
	// set the Slave Receive Handler function
	// (this function will run whenever a master somewhere else on the bus
	//  writes data to us as a slave)
	i2cSetSlaveReceiveHandler( i2cSlaveReceiveService );
	// set the Slave Transmit Handler function
	// (this function will run whenever a master somewhere else on the bus
	//  attempts to read data from us as a slave)
	i2cSetSlaveTransmitHandler( i2cSlaveTransmitService );

	timerPause(500);
	showByte(0xAA);

	while(1)
	{
		rprintf("Command>");
		while(!c) uartReceiveByte(&c);
		
		switch(c)
		{
		case 's':
			rprintf("Send: ");
			// get string from terminal
			localBufferLength = 0;
			c = 0;
			while((c != 0x0D) && (localBufferLength < 0x20))
			{
				while(!uartReceiveByte(&c));
				localBuffer[localBufferLength++] = c;
				uartSendByte(c);
			}
			// switch CR to NULL to terminate string
			localBuffer[localBufferLength-1] = 0;
			// send string over I2C
			i2cMasterSend(TARGET_ADDR, localBufferLength, localBuffer);
			//i2cMasterSendNI(TARGET_ADDR, localBufferLength, localBuffer);
			rprintfCRLF();
			break;
		case 'r':
			rprintf("Receive: ");
			// receive string over I2C
			i2cMasterReceive(TARGET_ADDR, 0x10, localBuffer);
			//i2cMasterReceiveNI(TARGET_ADDR, 0x10, localBuffer);
			// format buffer
			localBuffer[0x10] = 0;
			rprintfStr(localBuffer);
			rprintfCRLF();
			break;
		case 'm':
			testI2cMemory();
			break;
		default:
			rprintf("Unknown Command!");
			break;
		}
		c = 0;
		rprintfCRLF();
	}

}