예제 #1
0
void msp430_init_uart(){

  // Serial on P3.4, P3.5
  P3SEL |= BIT4 + BIT5;
  P3DIR |= BIT4;

  //UCA0CTL1 |= UCSWRST;                    /* disable UART */

  UCA0CTL0 = 0x00;
  //UCA0CTL0 |= UCMSB ;

  UCA0CTL1 |= UCSSEL_2;                     // SMCLK

  //UCA0BR0 = BAUD0EN;                        // 115200
  //UCA0BR1 = BAUD1EN;
  setbaud(5);//default baud, 115200

  UCA0MCTL = 0;                             // Modulation UCBRSx = 5
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**


  //Leave this commented!
  //Interrupt is handled by target code, not by bootloader.
  //IE2 |= UCA0RXIE;
}
예제 #2
0
void SERPER (uae_u16 w)
{
	int baud = 0, i, per;
	static int warned;

	if (serper == w)  /* don't set baudrate if it's already ok */
		return;

	ninebit = 0;
	serper = w;
	if (w & 0x8000)
		ninebit = 1;
	w &= 0x7fff;

	if (w < 13)
		w = 13;

	per = w;
	if (per == 0)
		per = 1;
	per = 3546895 / (per + 1);
	if (per <= 0)
		per = 1;
	i = 0;
	while (allowed_baudrates[i] >= 0 && per > allowed_baudrates[i] * 100 / 97)
		i++;
	baud = allowed_baudrates[i];

	serial_period_hsyncs = (((serper & 0x7fff) + 1) * (1 + 8 + ninebit + 1 - 1)) / maxhpos;
	if (serial_period_hsyncs <= 0)
		serial_period_hsyncs = 1;

#if SERIALLOGGING > 0
	serial_period_hsyncs = 1;
	seriallog = 1;
#endif
	if (log_sercon) {
		serial_period_hsyncs = 1;
		seriallog = 1;
	}

	serial_period_hsync_counter = 0;

	write_log (_T("SERIAL: period=%d, baud=%d, hsyncs=%d, bits=%d, PC=%x\n"), w, baud, serial_period_hsyncs, ninebit ? 9 : 8, M68K_GETPC);

	if (ninebit)
		baud *= 2;
	if (currprefs.serial_direct) {
		if (baud != 31400 && baud < 115200)
			baud = 115200;
		serial_period_hsyncs = 1;
	}
	serial_recv_previous = -1;
	serial_send_previous = -1;
#ifdef SERIAL_PORT
	setbaud (baud);
#endif
}
예제 #3
0
int main()
{
	char key;

	// Initialization
	setbaud(BAUD19K);
	rti_init();	
	
	while ( 1 );
	
	return 0;
}
예제 #4
0
파일: sendAPI.c 프로젝트: starnux/libxbee
int main(int argc, char **argv)
{
    char port[100], buf[1024], buf2[2048];
    int fd, size, i;

    if(argc > 1)
        strcpy(port, argv[1]);
    else
        strcpy(port, "/dev/ttyS0");

    ERR(fd = open(port, O_RDWR | O_NOCTTY), "open");
    setbaud(fd);
    setAPI(fd);
    sendAPI(fd);

    return 0;
}
예제 #5
0
파일: monitor.c 프로젝트: cyphunk/sectk
//! Handles a monitor command.
void monitorhandle(unsigned char app,
		   unsigned char verb,
		   unsigned char len){
  switch(verb){
  case PEEK:
    cmddata[0]=memorybyte[cmddataword[0]];
    txdata(app,verb,1);
    break;
  case POKE:
    //Todo, make word or byte.
    memorybyte[cmddataword[0]]=cmddata[2];
    cmddata[0]=memorybyte[cmddataword[0]];
    txdata(app,verb,1);
    break;
  case MONITOR_CHANGE_BAUD:
    //This command, and ONLY this command, does not reply.
    setbaud(cmddata[0]);
    //txdata(app,verb,0);
    break;
  case MONITOR_RAM_PATTERN:
    monitor_ram_pattern();//reboots, will never return
    break;
  case MONITOR_RAM_DEPTH:
    cmddataword[0]=monitor_ram_depth();
    txdata(app,verb,2);
    break;
  case MONITOR_DIR:
    P5DIR=cmddata[0];
    txdata(app,verb,1);
    break;
  case MONITOR_IN:
    cmddata[0]=P5IN;
    txdata(app,verb,1);
    break;
  case MONITOR_OUT:
    P5OUT=cmddata[0];
    txdata(app,verb,1);
    break;
  }
}
void main(void)
{
real4 glat, glong, gspeed;
real2 gangle;
char b1[110], gvalid;

  setbaud(BAUD9600);
  PORTA = 0;
  myprint("\nComplete LATLONG GPS data (binary) v1.0\n\n");
    
  gps_sync();
  while(1) {
    gps_read(b1);
	
	gvalid = b1[18];
	
	glat.c[3] = b1[52];
	glat.c[2] = b1[53];
	glat.c[1] = b1[54];
	glat.c[0] = b1[55];

	glong.c[3] = b1[56];
	glong.c[2] = b1[57];
	glong.c[1] = b1[58];
	glong.c[0] = b1[59];

	gspeed.c[3] = b1[66];
	gspeed.c[2] = b1[67];
	gspeed.c[1] = b1[68];
	gspeed.c[0] = b1[69];
	
	gangle.c[1] = b1[70];
	gangle.c[0] = b1[71];

    PORTA = 0;	  	
    print_latlong(&glat, &glong, &gspeed, &gangle, gvalid);
	PIOC = 0;
	PORTB=glat.c[0];
  }  
  	 }
예제 #7
0
int main()
{
    int cTotal = 0;
    int cState = STATE_READ;

    char toggleOut = FALSE;

    Signal motor1;
    Signal motor2;
    Signal estop;
    Signal rcMode;

    init_coridium();

	setbaud(0, 17);
	
	
    statusMessage[0] = '#';
	statusMessage[1] = '%';
	statusMessage[2] = 0x82;



    INPUT(RC1); motor1.pin = RC1;
    INPUT(RC2); motor2.pin = RC2;
    INPUT(RC3); estop.pin = RC3;
    INPUT(RC4); rcMode.pin = RC4;


    OUTPUT(TX);
    OUTPUT(ESTOP); LOW(ESTOP);
    OUTPUT(RCMode);
    OUTPUT(FreqPin);
    OUTPUT(LIGHT);

    motor1.state = STATE_WAIT;
    motor1.duty = 0;
    motor1.valid = 0;

    motor2.state = STATE_WAIT;
    motor2.duty = 0;
    motor2.valid = 0;

    estop.state = STATE_WAIT;
    estop.duty = 0;
    estop.valid = 0;

    rcMode.state = STATE_WAIT;
    rcMode.duty = 0;
    rcMode.valid = 0;

    SLEEP(2);

    while (TRUE)
    {
        switch (cState)
        {
        case STATE_READ:
            if (toggleOut)
            {
                toggleOut = FALSE;
                HIGH(FreqPin);
            }
            else
            {
                toggleOut = TRUE;
                LOW(FreqPin);
            }

            cTotal += getDuty(&motor1);
            cTotal += getDuty(&motor2);
            cTotal += getDuty(&estop);
            cTotal += getDuty(&rcMode);

            if (cTotal > 8)
            {
                cState = STATE_SERIAL;
                cTotal = 0;
            }
            break;

        case STATE_SERIAL:
			if (estop.lastVal > 0)
            {
                sendESTOP(0);
                gESTOP = FALSE;
				
                if (rcMode.lastVal > 0)
                {
                    HIGH(LIGHT);
                    HIGH(RCMode);

                    // 11 == Manual (teleop) Mode
                    statusMessage[3] = 0x00;
                    statusMessage[4] = 0xFF;
                    statusMessage[5] = 0xFF;
                    statusMessage[6] = 0xFF;

                    calcSum();
					//statusMessage[7] = 0x84;
                    //SEROUT(TXD0,9600, 1, 3, statusMessage);
					TXD0(statusMessage[0]);
					TXD0(statusMessage[1]);
					TXD0(statusMessage[2]);
					TXD0(statusMessage[3]);
					TXD0(statusMessage[4]);
					TXD0(statusMessage[5]);
					TXD0(statusMessage[6]);
					TXD0(statusMessage[7]);
                }
                else
                {
                    if (flashcount > 0)
                    {
                        HIGH(LIGHT);
                    }
                    else
                    {
                        LOW(LIGHT);
                    }

                    if (flashcount > LIGHTDUTY)
                    {
                        flashcount = -LIGHTDUTY;
                    }

                    LOW(RCMode);

                    // 00 == Autonomous Mode
                    statusMessage[3] = 0x00;
                    statusMessage[4] = 0x00;
                    statusMessage[5] = 0x00;
                    statusMessage[6] = 0x00;

                    calcSum();
					//statusMessage[7] = 0x84;
                    //SEROUT(TXD0,9600, 1, 3, statusMessage);
					
					TXD0(statusMessage[0]);
					TXD0(statusMessage[1]);
					TXD0(statusMessage[2]);
					TXD0(statusMessage[3]);
					TXD0(statusMessage[4]);
					TXD0(statusMessage[5]);
					TXD0(statusMessage[6]);
					TXD0(statusMessage[7]);
                }
            }
            else
            {
                HIGH(LIGHT);
                HIGH(RCMode);
                sendESTOP(1);
                gESTOP = TRUE;
				
				// 11 == Manual (teleop) Mode
				statusMessage[3] = 0x00;
				statusMessage[4] = 0xFF;
				statusMessage[5] = 0xFF;
				statusMessage[6] = 0xFF;

				calcSum();
				//statusMessage[7] = 0x84;
				//SEROUT(TXD0,9600, 1, 3, statusMessage);
				TXD0(statusMessage[0]);
				TXD0(statusMessage[1]);
				TXD0(statusMessage[2]);
				TXD0(statusMessage[3]);
				TXD0(statusMessage[4]);
				TXD0(statusMessage[5]);
				TXD0(statusMessage[6]);
				TXD0(statusMessage[7]);
            }

#ifdef DEBUG
            putchar( binToHexstr((char)((motor1.lastVal >> 4) & 0x0F)) );
            putchar( binToHexstr((char)(motor1.lastVal & 0x0F)) );
            putchar(' ');
                        putchar( binToHexstr((char)((motor2.lastVal >> 4) & 0x0F)) );
            putchar( binToHexstr((char)(motor2.lastVal & 0x0F)) );
            putchar('\n');
            //printf("%d\n", estop.lastVal);
#endif
            // motor1 == forward value
            // motor2 == left/right value

            int left_motor = motor1.lastVal/2 - motor2.lastVal/2;
            int right_motor = motor1.lastVal/2 + motor2.lastVal/2;

            sendSerial(right_motor, 1);
            sendSerial(left_motor, 0);

            cState = STATE_READ;

            break;
        }
        flashcount++;
    }

    return 0;
}