Example #1
0
File: uart.c Project: rozh1/MSP430
void uart_puts(const char *str)
{
     while(*str) uart_putc(*str++);
}
Example #2
0
//-----------------------------------------------------------------------------
static void uart_puts(char *s)
{
  while (*s)
    uart_putc(*s++);
}
Example #3
0
int main()
{

//uint8_t test_result=0;
//************************( 1 )*******************************************************
DDRD|=(1<<6)|(1<<7);//set LED pins as output
//PORTD&=~(1<<3);//vibration off
uart_init();//Keep this as first init so that text can be sent out in others
uart_puts("Starting up....");
_delay_ms(500);
PORTD|=1<<6;
_delay_ms(500);
PORTD&=~(1<<6);
spi_init(); //initialize SPI bus as master
init_tcnt2();//set up timer (RTC)
init_twi(); //initialize TWI interface
sei();
uart_puts("Pre Init...");
  
PORTB&=~(1<<sensor1_cs);//select sensor
SPIinit_MPU(MPU9250_FULL_SCALE_4G,MPU9250_GYRO_FULL_SCALE_500DPS);//init sensor
PORTB|=(1<<sensor1_cs);//deselect sensor
//init_MPU(MPU9250_FULL_SCALE_4G,MPU9250_GYRO_FULL_SCALE_500DPS, MPU9250_DEFAULT_ADDRESS); //initialize the 9axis sensor
//init_MPU(0,0, 0xD1); //initialize the 9axis sensor
//init_MPU(MPU9250_FULL_SCALE_4G,MPU9250_GYRO_FULL_SCALE_500DPS, MPU9250_DEFAULT_ADDRESS); //initialize the 9axis sensor
sram_init();//initialize sram
uart_puts("Post Init...");
//vibrate(100);	//Send feedback showing complete setup
PORTD |=(1<<6)|(1<<7);
PORTD &=~(1<<7);
_delay_ms(200);
PORTD |=(1<<7);
PORTD &=~(1<<6);// blinks both lights to show the program is starting
_delay_ms(200);
PORTD |=(1<<6);
_delay_ms(1000);
record_shot();
while(1){}        //*****************STOP POINT**********************
/*
test_result = test_com(0, MPU9250_DEFAULT_ADDRESS);
if(test_result)
{
uart_puts("MPU Status: OK\n");
}
else
uart_puts("MPU Status: FAILURE... You suck!\n");
*/
char rx_char;
uint16_t i=0;//used for for loops
//*****Fix me*******  
//should set to int 0 not char '0' but the ascii zero prints better for now
for(i=0;i<512;i++){sd_buf[i]='0';}//sets inital buffer to zero values
uint16_t shot_count=0;
while(1)
{
//************************( 2 )*******************************************************

PORTD &=~(1<<7);
_delay_ms(2000);//Show red light for 2 sec, then turn green and start shot
PORTD |=(1<<7);
PORTD &=~(1<<6);
//************************( 3 )*******************************************************
//vibrate(100);

record_shot();//record a shot
char shots_s[10];
itoa(num_records,shots_s,10);
uart_puts("In 20 seconds The number of records was: ");
uart_puts(shots_s);
uart_putc('\n');

print_shot();
shot_count++;
itoa(shot_count,shots_s,10);
uart_puts("Shot Number: ");
uart_puts(shots_s);
uart_putc('\n');
//print_shot();


PORTD |=(1<<6);//turn off light
//vibrate(100);_delay_ms(100);vibrate(100);  //Double vibration showing end of shot
//check_voltage();//Check system voltage
_delay_ms(5000);//wait 60 seconds
//************************( 6 )*******************************************************
continue; //start over and take another shot

  uart_puts("Starting Testing\n\n");
  uart_putc('\r');
  rx_char=uart_getc(); 
  if(rx_char=='c')
  {
    uart_puts("Command line:\n\n");
    rx_char=uart_getc();
    while(rx_char!='c')
    {
      if(rx_char=='s'){}
     if(rx_char=='w'){}
      if(rx_char=='r'){}//buffer gets set to sector!!
      if(rx_char=='i'){}
      rx_char=uart_getc();
    }
  }
 // uint8_t i=0;
  //Load values into 10 memory locations
  //Zero is only skipped to avoid loading zero into the byte
  //since when the byte is read back, zero could also mean communication failed

  for(i=48;i<=57;i++)
  {
    sram_write(i,add_m,add_h,i);//only lower address byte is incremented 
    //uart_putc(i);
  }//end loading for loop

  //change value in one spot in array as build in "error"
  sram_write(50,add_m,add_h,100);

  //check values in first 10 memory locations, one should be "wrong"
  for(i=48;i<57;i++)
  {
    _delay_ms(100);
    PORTB |=(1<<1)|(1<<2);
    _delay_ms(100);
    if (sram_read(i,add_m,add_h)==i)
    {
      PORTB &=~(1<<1);
      uart_puts("passed\n");
    }//Byte read back correct  GREEN light
    else{PORTB &=~(1<<2);uart_puts("FAILED!!\n");}//Byte Read back was incorrect   RED light
  }//end for loop for checking values

  PORTB |=(1<<1)|(1<<2);//both lights off

  uart_puts("****Tesst finished*****\r\r");
  _delay_ms(1500);//wait 1.5 seconds before starting again
} //end while 
} //end main
Example #4
0
int main(void)
{
  dhcp dhcp_session;
  int  dhcp_state;
  http_server http;
  http_socket httpsock[4];
  http_content httpcontent[4];
  char oled_msg[17];
  char *pnt;
  int   step;

  api_init();
  uart_puts(" * eCowLogic firmware \r\n");

  hw_systick( hw_getfreq() / 1000 );

  dhcp_session.socket = 2;
  dhcp_session.buffer = (u8 *)buffer_dhcp;
  dhcp_init(&dhcp_session);
  
  oled_pos(1, 0);
  oled_puts("Reseau (DHCP)   ");
  step = 0;
  while(1)
  {
    dhcp_state = dhcp_run(&dhcp_session);
    if (dhcp_state == DHCP_IP_LEASED)
      break;
    step++;
    oled_pos(1, 13);
    if (step == 1) oled_puts(".  ");
    if (step == 2) oled_puts(".. ");
    if (step == 3) oled_puts("...");
    if (step == 4)
    {
      step = 0;
      dhcp_session.tick_1s++;
      uart_putc('.');
      oled_puts("   ");
    }
    delay(250);
  }
  pnt = oled_msg;
  pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[0]); *pnt++ = '.';
  pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[1]); *pnt++ = '.';
  pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[2]); *pnt++ = '.';
  pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[3]);
  for ( ; pnt < (oled_msg + 16); pnt++)
    *pnt = ' ';
  oled_msg[16] = 0;
  uart_puts("DHCP: LEASED ! ");
  uart_puts(oled_msg); uart_puts("\r\n");
  oled_pos(1, 0);
  oled_puts(oled_msg);
  
  spi_init();
  pld_init();

  //net_init();
  
  /* Init HTTP content */
  strcpy(httpcontent[0].name, "/pld");
  httpcontent[0].wildcard = 0;
  httpcontent[0].cgi = cgi_ng_pld;
  httpcontent[0].next = &httpcontent[1];
  /* Init HTTP content */
  strcpy(httpcontent[1].name, "/spi");
  httpcontent[1].wildcard = 0;
  httpcontent[1].cgi = cgi_spi;
  httpcontent[1].next = &httpcontent[2];
  /* Init HTTP content */
  strcpy(httpcontent[2].name, "/infos");
  httpcontent[2].wildcard = 0;
  httpcontent[2].cgi = cgi_info;
  httpcontent[2].next = &httpcontent[3];
  /* Init HTTP content */
  strcpy(httpcontent[3].name, "/");
  httpcontent[3].wildcard = 1;
  httpcontent[3].cgi = cgi_ng_page;
  httpcontent[3].next = 0;
  /* Init HTTP socket */
  httpsock[0].id = 4;
  httpsock[0].state = 0;
  httpsock[0].server = &http;
  httpsock[0].next = &httpsock[1];
  /* Init HTTP socket */
  httpsock[1].id = 5;
  httpsock[1].state = 0;
  httpsock[1].server = &http;
  httpsock[1].next = &httpsock[2];
  /* Init HTTP socket */
  httpsock[2].id = 6;
  httpsock[2].state = 0;
  httpsock[2].server = &http;
  httpsock[2].next = &httpsock[3];
  /* Init HTTP socket */
  httpsock[3].id = 7;
  httpsock[3].state = 0;
  httpsock[3].server = &http;
  httpsock[3].next = 0;
  /* Init the new HTTP layer */
  http.port   = 80;
  http.err404 = 0;
  http.err403 = 0;
  http.keepalive = 10;
  http.socks  = &httpsock[0];
  http.contents = &httpcontent[0];
  http_init(&http);
  
  while(1)
  {
    http_run(&http);
  }
}
Example #5
0
void uart_putx(int i) {
    uart_putc((i < 10) ? ('0' + i) : ('A' - 10 + i));
}
Example #6
0
int main(void)
{
    RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN);
    RCC->APB1ENR |= (RCC_APB1ENR_SPI2EN | RCC_APB1ENR_USART3EN);

    // PB11 / INT/HOLD
    GPIOB->MODER |= GPIO_MODER_MODER11_0;
	// open drain output
    GPIOB->OTYPER |= GPIO_OTYPER_OT_11;
    GPIOB->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR11_1;

    // PD11 / Chip Select
    GPIOD->MODER |= GPIO_MODER_MODER11_0;
	// open drain output
    GPIOD->OTYPER |= GPIO_OTYPER_OT_11;
    GPIOD->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR11_1;

    // PB13 / SCK
    GPIOB->MODER |= GPIO_MODER_MODER13_1;
	// open drain output
    GPIOB->OTYPER |= GPIO_OTYPER_OT_13;
    GPIOB->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR13_1;
    GPIOB->AFR[1] |= (0x05 << 20);

    // PB14 / MISO
    GPIOB->MODER |= GPIO_MODER_MODER14_1;
    GPIOB->PUPDR |= GPIO_PUPDR_PUPDR14_1;
    GPIOB->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR14_1;
    GPIOB->AFR[1] |= (0x05 << 24);

    // PB15 / MOSI
    GPIOB->MODER |= GPIO_MODER_MODER15_1;
	// open drain output
    GPIOB->OTYPER |= GPIO_OTYPER_OT_15;
    GPIOB->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR15_1;
    GPIOB->AFR[1] |= (0x05 << 28);

    // PD12 / LED
    GPIOD->MODER |= GPIO_MODER_MODER12_0;
    GPIOD->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR12_1;

    // SPI
    SPI2->CR1 |= SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_CPHA | SPI_CR1_MSTR | (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0);
    SPI2->CR1 |= SPI_CR1_SPE;

    // PC10 / TX
    GPIOC->MODER |= GPIO_MODER_MODER10_1;
    GPIOC->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR10_0;
    GPIOC->AFR[1] |= (0x07 << 8);

    // PC11 / RX
    GPIOC->MODER |= GPIO_MODER_MODER11_1;
    GPIOC->PUPDR &= ~GPIO_PUPDR_PUPDR11;
    GPIOC->AFR[1] |= (0x07 << 12);

    // USART
    USART3->BRR = 0x00D9; // 50.0 MHz / 0x00D9 = 115200
    USART3->CR3 |= USART_CR3_DMAT;
    USART3->CR1 |= (USART_CR1_RXNEIE | USART_CR1_TE | USART_CR1_RE);
    USART3->CR1 |= USART_CR1_UE;

    NVIC_SetPriority(USART3_IRQn, 15);
    NVIC_EnableIRQ(USART3_IRQn);

    __enable_irq();

    volatile uint32_t i;
    uint16_t data;

    uart_putc(spi(0b01001100));
    uart_putc(spi(0b01001100));
    uart_putc(spi(0b11100001));

    // SET_ADVANCED_MODE
    uart_putc(spi(0b01110001));

    for (;;) {
        /*data = uart_getc();

        if ((data & 0xFF00) == 0) {
            uart_putc(spi(data));
        }*/

    	// LED on PD12 goes LOW
        GPIOD->BSRRL = GPIO_ODR_ODR_12;
        // delay
        for (i = 0; i < 10000; i++);

        // BAND_PASS_CMD
        uart_putc(spi(0b00000000 | (40 & 0x3F)));
        // Set the gain
        uart_putc(spi(0b10000000 | (49 & 0x3F)));
        // Set the integration time constant
        uart_putc(spi(0b11000000 | (31 & 0x1F)));

        // SET_ADVANCED_MODE
        uart_putc(spi(0b01110001));


        // int/hold LOW
        GPIOB->BSRRL = GPIO_ODR_ODR_11;

    	// LED on PD12 goes HIGH
        GPIOD->BSRRH = GPIO_ODR_ODR_12;
        // delay
        for (i = 0; i < 10000; i++);

        // int/hold HIGH
        GPIOB->BSRRH = GPIO_ODR_ODR_11;
    }

    return 0;
}
Example #7
0
static int putchar__(char c, FILE *stream) {
	uart_putc(c);
	return 0;
}
Example #8
0
static int serial_putchar(char c, FILE *stream) {
	if (c == '\n') serial_putchar('\r', stream);
	uart_putc(c);
	return 0;
}
Example #9
0
void putch(char ch) {
	uart_putc(ch);
}
int main(void)
{
	int i;
	int count = 0;
	
	DDRB = 0;
	DDRC = 0;
	DDRE = 0;
	
	// Enable the pullup on RESET pin.
	#if defined(__AVR_AT90PWM316__)
	PORTE = (1<<PINE0);
	PORTE &= ~(1<<PINE0);
	#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
	PORTC = (1<<PINC6);
	PORTC &= ~(1<<PINC6);
	#else
	#warning "Didn't enable reset pin pullup"
	#endif
	
	// Setup all of port C as inputs, except for pin C5
	SETUP_DEBUG_PINS();
	
	// Set up the ADC single conversion pin.
	DDRC  &= ~(1<<PINC6);
	PORTC &= ~(1<<PINC6);
	
	// Disable all the ADC digital inputs.
	DIDR1 = 0xFF;
	DIDR0 = 0xFF & ~(1<<ADC1D);
	
	// populate the buffer with known values
	ringBuffer_initialize(&txbuffer,txbuffer_storage,TXBUFFER_LEN);
	ringBuffer_initialize(&adcbuffer,adcbuffer_storage,BUFFER_LEN);
	ringBuffer_initialize(&rxbuffer,rxbuffer_storage,RXBUFFER_LEN);
	
	// Populate the ADC read schedule with the mux indices that you want.
	adc_mux_schedule[0] = 2;
	adc_mux_schedule[1] = 10;
	adc_mux_schedule[2] = 6;
	adc_mux_schedule[3] = 3;
	
	
	uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU), &rxbuffer, &txbuffer);
	//uart_config_default_stdio();
	// Translate those indices and the mask specifying which MUXes to turn on,
	// to an encoded mux schedule that the ADC understands.
	adc_encode_muxSchedule(adc_mux_schedule, SCHEDULE_LEN);
	
	
	adc_init(ADC_MODE_MANUAL, &adcbuffer, adc_mux_schedule, SCHEDULE_LEN);
	timer0_init();
	sei();
	uart_puts_P("\f\r\n\r\nADC and UART Demo. Commands:\n"
				"b      Begin 4 channel read bursts at CLK/16K\n"
				"e      End reading.\n"
				"s      Single conversion.\n");
	
	DEBUG_PIN1_OFF();
	while(1)
	{
		do
		{
			i = uart_getc();
		} while (i == UART_NO_DATA);
		DEBUG_PIN1_ON();
		if(i == 'b'){
			uart_puts_P("Begin.\n");
			start_timer0();
		}
		else if(i == 'e'){
			stop_timer0();
			_delay_us(100);
			uart_puts_P("End.\n");
		}
		else if(i == 's'){
			uart_puts_P("ADC");
			uart_put_hex8(count);
			uart_puts_P(": ");
			i = adc_single_conversion(count);
			uart_put_hex8((i >> 8) & 0xFF);
			uart_put_hex8(i & 0xFF);
			uart_putc('\n');
			count = (count + 1) & 0xF;
			if(count == 11)
			{
				count = 13;
			}
		}
		else{
Example #11
0
void uart0_putc(char byte){
	uart_putc(UART_0, byte);
}
Example #12
0
void ieee_mainloop(void) {
  int16_t cmd = 0;

  set_error(ERROR_DOSVERSION);

  ieee_data.bus_state = BUS_IDLE;
  ieee_data.device_state = DEVICE_IDLE;
  for(;;) {
    switch(ieee_data.bus_state) {
      case BUS_SLEEP:                               /* BUS_SLEEP */
        set_atn_irq(0);
        ieee_bus_idle();
        set_error(ERROR_OK);
        set_busy_led(0);
        uart_puts_P(PSTR("ieee.c/sleep ")); set_dirty_led(1);

        /* Wait until the sleep key is used again */
        while (!key_pressed(KEY_SLEEP))
          system_sleep();
        reset_key(KEY_SLEEP);

        set_atn_irq(1);
        update_leds();

        ieee_data.bus_state = BUS_IDLE;
        break;

      case BUS_IDLE:                                /* BUS_IDLE */
        ieee_bus_idle();
        while(IEEE_ATN) {   ;               /* wait for ATN */
          if (key_pressed(KEY_NEXT | KEY_PREV | KEY_HOME)) {
            change_disk();
          } else if (key_pressed(KEY_SLEEP)) {
            reset_key(KEY_SLEEP);
            ieee_data.bus_state = BUS_SLEEP;
            break;
          } else if (display_found && key_pressed(KEY_DISPLAY)) {
            display_service();
            reset_key(KEY_DISPLAY);
          }
          system_sleep();
      }

      if (ieee_data.bus_state != BUS_SLEEP)
        ieee_data.bus_state = BUS_FOUNDATN;
      break;

      case BUS_FOUNDATN:                            /* BUS_FOUNDATN */
        ieee_data.bus_state = BUS_ATNPROCESS;
        cmd = ieee_getc();
      break;

      case BUS_ATNPROCESS:                          /* BUS_ATNPROCESS */
        if(cmd < 0) {
          uart_putc('c');
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else cmd &= 0xFF;
        uart_puts_p("ATN "); uart_puthex(cmd);
        uart_putcrlf();

        if (cmd == 0x3f) {                                  /* UNLISTEN */
          if(ieee_data.device_state == DEVICE_LISTEN) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNLISTEN\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == 0x5f) {                           /* UNTALK */
          if(ieee_data.device_state == DEVICE_TALK) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNTALK\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x40 + device_address)) {        /* TALK */
          uart_puts_p("TALK ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.device_state = DEVICE_TALK;
          /* disk drives never talk immediatly after TALK, so stay idle
             and wait for a secondary address given by 0x60-0x6f DATA */
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x20 + device_address)) {        /* LISTEN */
          ieee_data.device_state = DEVICE_LISTEN;
          uart_puts_p("LISTEN ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0x60) {                  /* DATA */
          /* 8250LP sends data while ATN is still active, so wait
             for bus controller to release ATN or we will misinterpret
             data as a command */
          while(!IEEE_ATN);
          if(ieee_data.device_state == DEVICE_LISTEN) {
            cmd = ieee_listen_handler(cmd);
            cmd_handler();
            break;
          } else if (ieee_data.device_state == DEVICE_TALK) {
            ieee_data.secondary_address = cmd & 0x0f;
            uart_puts_p("DATA T ");
            uart_puthex(ieee_data.secondary_address);
            uart_putcrlf();
            if(ieee_talk_handler() == TIMEOUT_ABORT) {
              ieee_data.device_state = DEVICE_IDLE;
            }
            ieee_data.bus_state = BUS_IDLE;
            break;
          } else {
            ieee_data.bus_state = BUS_IDLE;
            break;
          }
        } else if (ieee_data.device_state == DEVICE_IDLE) {
          ieee_data.bus_state = BUS_IDLE;
          break;
          /* ----- if we reach this, we're LISTENer or TALKer ----- */
        } else if ((cmd & 0xf0) == 0xe0) {                  /* CLOSE */
          ieee_data.secondary_address = cmd & 0x0f;
          uart_puts_p("CLOSE ");
          uart_puthex(ieee_data.secondary_address);
          uart_putcrlf();
          /* Close all buffers if sec. 15 is closed */
          if(ieee_data.secondary_address == 15) {
            free_multiple_buffers(FMB_USER_CLEAN);
          } else {
            /* Close a single buffer */
            buffer_t *buf;
            buf = find_buffer (ieee_data.secondary_address);
            if (buf != NULL) {
              buf->cleanup(buf);
              free_buffer(buf);
            }
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0xf0) {                  /* OPEN */
          cmd = ieee_listen_handler(cmd);
          cmd_handler();
          break;
        } else {
          /* Command for other device or unknown command */
          ieee_data.bus_state = BUS_IDLE;
        }
      break;
    }   /* switch   */
  }     /* for()    */
}
Example #13
0
static int16_t ieee_listen_handler (uint8_t cmd)
/* Receive characters from IEEE-bus and write them to the
   listen buffer adressed by ieee_data.secondary_address.
   If a new command is received (ATN set), return it
*/
{
  buffer_t *buf;
  int16_t c;

  ieee_data.secondary_address = cmd & 0x0f;
  buf = find_buffer(ieee_data.secondary_address);

  /* Abort if there is no buffer or it's not open for writing */
  /* and it isn't an OPEN command                             */
  if ((buf == NULL || !buf->write) && (cmd & 0xf0) != 0xf0) {
    uart_putc('c');
    return -1;
  }

  switch(cmd & 0xf0) {
    case 0x60:
      uart_puts_p("DATA L ");
      break;
    case 0xf0:
      uart_puts_p("OPEN ");
      break;
    default:
      uart_puts_p("Unknown LH! ");
      break;
  }
  uart_puthex(ieee_data.secondary_address);
  uart_putcrlf();

  c = -1;
  for(;;) {
    /* Get a character ignoring timeout but but watching ATN */
    while((c = ieee_getc()) < 0);
    if (c  & FLAG_ATN) return c;

    uart_putc('<');
    if (c & FLAG_EOI) {
      uart_puts_p("EOI ");
      ieee_data.ieeeflags |= EOI_RECVD;
    } else ieee_data.ieeeflags &= ~EOI_RECVD;

    uart_puthex(c); uart_putc(' ');
    c &= 0xff; /* needed for isprint */
    if(isprint(c)) uart_putc(c); else uart_putc('?');
    uart_putcrlf();

    if((cmd & 0x0f) == 0x0f || (cmd & 0xf0) == 0xf0) {
      if (command_length < CONFIG_COMMAND_BUFFER_SIZE)
        command_buffer[command_length++] = c;
      if (ieee_data.ieeeflags & EOI_RECVD)
        /* Filenames are just a special type of command =) */
        ieee_data.ieeeflags |= COMMAND_RECVD;
    } else {
      /* Flush buffer if full */
      if (buf->mustflush) {
        if (buf->refill(buf)) return -2;
        /* Search the buffer again,                     */
        /* it can change when using large buffers       */
        buf = find_buffer(ieee_data.secondary_address);
      }

      buf->data[buf->position] = c;
      mark_buffer_dirty(buf);

      if (buf->lastused < buf->position) buf->lastused = buf->position;
      buf->position++;

      /* Mark buffer for flushing if position wrapped */
      if (buf->position == 0) buf->mustflush = 1;

      /* REL files must be syncronized on EOI */
      if(buf->recordlen && (ieee_data.ieeeflags & EOI_RECVD)) {
        if (buf->refill(buf)) return -2;
      }
    }   /* else-buffer */
  }     /* for(;;) */
}
int main(void)
{
	unsigned int c;
    char buffer[7];
    int  num=134;
    unsigned char i;	
	
	DDRA=0xF0;						//SET DATA DIRECTION REGISTER
									//SET 1 for OUTPUT PORT
									//SET 0 FOR INPUT PORT
									//PA.4, PA.5, PA.6 AND PA.7 ARE OUTPUT
									//ALL OTHERS ARE INPUT
									
	DDRB=0XFB;						//SET DATA DIRECTION REGISTER
									//SET 1 for OUTPUT PORT
									//SET 0 FOR INPUT PORT
									//PB.2 IS  INPUT
									//ALL OTHERS ARE OUTPUT
	
	DDRD=0XF1;						//SET DATA DIRECTION REGISTER
									//SET 1 for OUTPUT PORT
									//SET 0 FOR INPUT PORT
									//PD.1, PD.2 AND PD.3 ARE INPUT
									//ALL OTHERS ARE OUTPUT
	
	DDRC=0xFF;
		
	sbi(PORTB,2);					//ENABLE PULL UP FOR SWITCH INT2
	sbi(PORTD,1);					//ENABLE PULL UP FOR SW1
	sbi(PORTD,2);					//ENABLE PULL UP FOR SWITCH INT0
	sbi(PORTD,3);					//ENABLE PULL UP FOR SWITCH INT1
    
    lcd_init(LCD_DISP_ON);				/* initialize display, cursor off */
	lcd_clrscr();						/* clear display and home cursor */        
	lcd_puts("ROBOKITS INDIA\n");		/* put string to display (line 1) with linefeed */		
	lcd_puts("    ROBOKITS.ORG");		/* cursor is now on second line, write second line */		
	lcd_gotoxy(0,1);  					/* move cursor to position 0 on line 2 */        
	lcd_puts("WWW.");					/* write single char to display */    


	for(i=0;i<15;i++)
		_delay_ms(250);
	
	lcd_clrscr();

	lcd_puts("INT2 FOR OPTION1\n");
	lcd_puts("SW1 FOR OPTION2 ");
	for(i=0;i<15;i++)
		_delay_ms(250);

	lcd_clrscr();

	lcd_puts("INT0 FOR OPTION3\n");
	lcd_puts("INT1 FOR OPTION4 ");
	for(i=0;i<15;i++)
		_delay_ms(250);
   	
	current=0;
	menu();
	
	GICR = _BV(INT1);           	// enable external int0
    MCUCR = _BV(ISC11);          	// falling egde: int0
    
    sei();                       	// enable interrupts 
	
	setjmp (env);

	for(;1;)
	{
		if(bit_is_clear(PINB,2))
		{
			if(current==0)
			{
				subprog();
				while(1)
				{
					PORTA=0X00;						//ALL LED'S OFF
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					PORTA=0xF0;						//ALL LED'S ON
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
					_delay_ms(250);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
				}			
			}
			else if(current==1)
			{
				subprog();
				sbi(PORTC,0);					//MOTOR1 forward
				sbi(PORTC,3);					//MOTOR2 reverse	
		
				TCCR1A =  _BV(WGM10) | _BV(COM1A1) | _BV(COM1A0) | _BV(COM1B1) | _BV(COM1B0);    	// enable 8 bit PWM, select inverted PWM
					
				// timer1 running on 1/8 MCU clock with clear timer/counter1 on Compare Match
				// PWM frequency will be MCU clock / 8 / 512, e.g. with 1Mhz Crystal 244 Hz.
				TCCR1B = _BV(CS11) | _BV(WGM12);
			 
				for (;;)
				{   
					for (i=0; i<150; i++)								/* Decrease speed of motor */
					{
						OCR1AL = i;
						OCR1BL = i;
						_delay_ms(25);									// delay 25 ms
					}
					
					for( i=150; i>0; i--)								/* Increase speed of motor */
					{
						OCR1AL = i;            
						OCR1BL = i;
						_delay_ms(25);									// delay 25 ms
					}
				}			
			}
			else if(current==2)
			{
				subprog();
				uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU)); 
				uart_puts_P("\r\n\nSample code made by Robokits India for ROBOGRID. ");
				uart_puts_P("\r\n\nVisit Us at www.robokits.org. ");
				uart_puts_P("\r\n\nWriting number to UART: ");
			 
				itoa( num, buffer, 10);   // convert interger into string (decimal format)    
				uart_puts(buffer);        // and transmit string to UART     
			
				uart_putc('\r');				
				uart_puts_P("\n\nPress any key on keyboard: ");
				
				for(;;)
				{
					c = uart_getc();
					if (!(c & UART_NO_DATA))
						uart_putc( (unsigned char)c );
				}			
			}
			else if(current==3)
			{
				subprog();
				sbi(PORTA,4);
				TCCR1A = 0x00;               	// disable PWM and Compare Output Mode
				TCCR1B = TMC16_CK1024;       	// use CLK/1024 prescale value
				TCNT1  = TIMER_1_CNT;        	// reset TCNT1
				
				TIMSK  = _BV(TOIE1);         	// enable TCNT1 overflow 
				
				sei();                       	// enable interrupts 
				
				for (;;) 						// loop forever
				{                      
					if (bit_is_clear(PINA, 5))	//BLINK LED2 WITH NORMAL DELAY
						sbi(PORTA,5);			//LED2 ON
					else						//ELSE
						cbi(PORTA,5);			//LED2 OFF
					_delay_ms(250);				
					_delay_ms(250);	
					_delay_ms(250);	
					_delay_ms(250);	
				}			
			}
			else if(current==4)
			{
				subprog();
				sbi(PORTA,4);
				for (;;)								/* loop forever */ 
				{                           
					sbi(PORTA,5);
					wait_debounce();				/* wait until push button sw1 is pressed */
					cbi(PORTA,5);
					wait_debounce();				/* wait until push button sw1 is pressed */
				}				
			}
			else if(current==5)
			{
				subprog();
				sbi(PORTD,4);								//Enable on
				sbi(PORTD,5);								//Enable on
				while(1)
				{
					mainloop:
					if (bit_is_clear(PINB,2))				//IF SW1 IS PRESSED STEPPER1 FORWARD
					{
						while(1)
						{
							PORTC=0x01;						//COIL1 +
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							PORTC=0x02;						//COIL2 +
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							PORTC=0x04;						//COIL1 -
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							PORTC=0x08;						//COIL2 -
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							if (bit_is_set(PINB,2))		//CHECK WHETHER THE SWITCH IS STILL PRESSED
							{
								PORTC=0x00;					//CLEAR PORTC				
								goto mainloop;				//IF NOT GOTO MAINLOOP
							}
						}
					}
					else if (bit_is_clear(PIND,1))			//IF SW2 IS PRESSED STEPPER1 BACKWARD
					{
						while(1)
						{
							PORTC=0x08;						//COIL1 +
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							PORTC=0x04;						//COIL2 -
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							PORTC=0x02;						//COIL1 -
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							PORTC=0x01;						//COIL2 +
							_delay_ms(5);					//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
							if (bit_is_set(PIND,1))
							{
								PORTC=0x00;					//CLEAR PORTC			
								goto mainloop;				//IF NOT GOTO MAINLOOP
							}
						}		
					}
					else
						PORTC=0x00;
				}			
			}	
		}
		else if(bit_is_clear(PIND,1))
		{
			if(current==0)
				current=5;
			else
				current--;
			menu();
			_delay_ms(250);
			_delay_ms(250);
		}
		else if(bit_is_clear(PIND,2))
		{
			if(current==5)
				current=0;
			else
				current++;
			menu();
			_delay_ms(250);
			_delay_ms(250);
		}		
		else
		{
			PORTA=0;	
			cbi(PORTC,0);				
			cbi(PORTC,3);	
			TCCR1A=0;
			TCCR1B=0;
			TCNT1=0;
			OCR1AL=0;
			OCR1BL=0;
			PORTC=0;
		}		
		
	}
}
Example #15
0
void sendCRLF(){
	uart_putc(CR);
	uart_putc(LF);
}
Example #16
0
int main()
{
    /* we will just use ordinary idle mode */
    set_sleep_mode(SLEEP_MODE_IDLE);

    /* setup uart */
    uart_init();

    while(1)
    {
        /* setup sd card slot */
        if(!sd_raw_init())
        {
#if DEBUG
            uart_puts_p(PSTR("MMC/SD initialization failed\n"));
#endif
            continue;
        }

        /* open first partition */
        struct partition_struct* partition = partition_open(sd_raw_read,
                                                            sd_raw_read_interval,
#if SD_RAW_WRITE_SUPPORT
                                                            sd_raw_write,
                                                            sd_raw_write_interval,
#else
                                                            0,
                                                            0,
#endif
                                                            0
                                                           );

        if(!partition)
        {
            /* If the partition did not open, assume the storage device
             * is a "superfloppy", i.e. has no MBR.
             */
            partition = partition_open(sd_raw_read,
                                       sd_raw_read_interval,
#if SD_RAW_WRITE_SUPPORT
                                       sd_raw_write,
                                       sd_raw_write_interval,
#else
                                       0,
                                       0,
#endif
                                       -1
                                      );
            if(!partition)
            {
#if DEBUG
                uart_puts_p(PSTR("opening partition failed\n"));
#endif
                continue;
            }
        }

        /* open file system */
        struct fat_fs_struct* fs = fat_open(partition);
        if(!fs)
        {
#if DEBUG
            uart_puts_p(PSTR("opening filesystem failed\n"));
#endif
            continue;
        }

        /* open root directory */
        struct fat_dir_entry_struct directory;
        fat_get_dir_entry_of_path(fs, "/", &directory);

        struct fat_dir_struct* dd = fat_open_dir(fs, &directory);
        if(!dd)
        {
#if DEBUG
            uart_puts_p(PSTR("opening root directory failed\n"));
#endif
            continue;
        }
        
        /* print some card information as a boot message */
        print_disk_info(fs);

        /* provide a simple shell */
        char buffer[24];
        while(1)
        {
            /* print prompt */
            uart_putc('>');
            uart_putc(' ');

            /* read command */
            char* command = buffer;
            if(read_line(command, sizeof(buffer)) < 1)
                continue;

            /* execute command */
            if(strcmp_P(command, PSTR("init")) == 0)
            {
                break;
            }
            else if(strncmp_P(command, PSTR("cd "), 3) == 0)
            {
                command += 3;
                if(command[0] == '\0')
                    continue;

                /* change directory */
                struct fat_dir_entry_struct subdir_entry;
                if(find_file_in_dir(fs, dd, command, &subdir_entry))
                {
                    struct fat_dir_struct* dd_new = fat_open_dir(fs, &subdir_entry);
                    if(dd_new)
                    {
                        fat_close_dir(dd);
                        dd = dd_new;
                        continue;
                    }
                }

                uart_puts_p(PSTR("directory not found: "));
                uart_puts(command);
                uart_putc('\n');
            }
            else if(strcmp_P(command, PSTR("ls")) == 0)
            {
                /* print directory listing */
                struct fat_dir_entry_struct dir_entry;
                while(fat_read_dir(dd, &dir_entry))
                {
                    uint8_t spaces = sizeof(dir_entry.long_name) - strlen(dir_entry.long_name) + 4;

                    uart_puts(dir_entry.long_name);
                    uart_putc(dir_entry.attributes & FAT_ATTRIB_DIR ? '/' : ' ');
                    while(spaces--)
                        uart_putc(' ');
                    uart_putdw_dec(dir_entry.file_size);
                    uart_putc('\n');
                }
            }
            else if(strncmp_P(command, PSTR("cat "), 4) == 0)
            {
                command += 4;
                if(command[0] == '\0')
                    continue;
                
                /* search file in current directory and open it */
                struct fat_file_struct* fd = open_file_in_dir(fs, dd, command);
                if(!fd)
                {
                    uart_puts_p(PSTR("error opening "));
                    uart_puts(command);
                    uart_putc('\n');
                    continue;
                }

                /* print file contents */
                uint8_t buffer[8];
                uint32_t offset = 0;
                while(fat_read_file(fd, buffer, sizeof(buffer)) > 0)
                {
                    uart_putdw_hex(offset);
                    uart_putc(':');
                    for(uint8_t i = 0; i < 8; ++i)
                    {
                        uart_putc(' ');
                        uart_putc_hex(buffer[i]);
                    }
                    uart_putc('\n');
                    offset += 8;
                }

                fat_close_file(fd);
            }
            else if(strcmp_P(command, PSTR("disk")) == 0)
            {
                if(!print_disk_info(fs))
                    uart_puts_p(PSTR("error reading disk info\n"));
            }
#if FAT_WRITE_SUPPORT
            else if(strncmp_P(command, PSTR("rm "), 3) == 0)
            {
                command += 3;
                if(command[0] == '\0')
                    continue;
                
                struct fat_dir_entry_struct file_entry;
                if(find_file_in_dir(fs, dd, command, &file_entry))
                {
                    if(fat_delete_file(fs, &file_entry))
                        continue;
                }

                uart_puts_p(PSTR("error deleting file: "));
                uart_puts(command);
                uart_putc('\n');
            }
            else if(strncmp_P(command, PSTR("touch "), 6) == 0)
            {
                command += 6;
                if(command[0] == '\0')
                    continue;

                struct fat_dir_entry_struct file_entry;
                if(!fat_create_file(dd, command, &file_entry))
                {
                    uart_puts_p(PSTR("error creating file: "));
                    uart_puts(command);
                    uart_putc('\n');
                }
            }
            else if(strncmp_P(command, PSTR("write "), 6) == 0)
            {
                command += 6;
                if(command[0] == '\0')
                    continue;

                char* offset_value = command;
                while(*offset_value != ' ' && *offset_value != '\0')
                    ++offset_value;

                if(*offset_value == ' ')
                    *offset_value++ = '\0';
                else
                    continue;

                /* search file in current directory and open it */
                struct fat_file_struct* fd = open_file_in_dir(fs, dd, command);
                if(!fd)
                {
                    uart_puts_p(PSTR("error opening "));
                    uart_puts(command);
                    uart_putc('\n');
                    continue;
                }

                int32_t offset = strtolong(offset_value);
                if(!fat_seek_file(fd, &offset, FAT_SEEK_SET))
                {
                    uart_puts_p(PSTR("error seeking on "));
                    uart_puts(command);
                    uart_putc('\n');

                    fat_close_file(fd);
                    continue;
                }

                /* read text from the shell and write it to the file */
                uint8_t data_len;
                while(1)
                {
                    /* give a different prompt */
                    uart_putc('<');
                    uart_putc(' ');

                    /* read one line of text */
                    data_len = read_line(buffer, sizeof(buffer));
                    if(!data_len)
                        break;

                    /* write text to file */
                    if(fat_write_file(fd, (uint8_t*) buffer, data_len) != data_len)
                    {
                        uart_puts_p(PSTR("error writing to file\n"));
                        break;
                    }
                }

                fat_close_file(fd);
            }
            else if(strncmp_P(command, PSTR("mkdir "), 6) == 0)
            {
                command += 6;
                if(command[0] == '\0')
                    continue;

                struct fat_dir_entry_struct dir_entry;
                if(!fat_create_dir(dd, command, &dir_entry))
                {
                    uart_puts_p(PSTR("error creating directory: "));
                    uart_puts(command);
                    uart_putc('\n');
                }
            }
#endif
#if SD_RAW_WRITE_BUFFERING
            else if(strcmp_P(command, PSTR("sync")) == 0)
            {
                if(!sd_raw_sync())
                    uart_puts_p(PSTR("error syncing disk\n"));
            }
#endif
            else
            {
                uart_puts_p(PSTR("unknown command: "));
                uart_puts(command);
                uart_putc('\n');
            }
        }

        /* close directory */
        fat_close_dir(dd);

        /* close file system */
        fat_close(fs);

        /* close partition */
        partition_close(partition);
    }
    
    return 0;
}
Example #17
0
void parser_process_uart(void) {
	
	unsigned int c;
	static char recbuf[BUFFERLENGTH];
	static uint8_t len = 0;
	static bool overflow = false;
	PARSER_RET retval;

	c = uart_getc();

	if (c & UART_NO_DATA) {
		return;
	}

	// check for error
	if (c & UART_FRAME_ERROR) {
		uart_puts_P("ERROR: UART Frame Error\n");
		return;
	}
	if (c & UART_OVERRUN_ERROR) {
		uart_puts_P("ERROR: UART Overrun Error\n");
		return;
	}
	if (c & UART_BUFFER_OVERFLOW) {
		uart_puts_P("ERROR: Buffer overflow error\n");
		return;
	}

	// echo back the received char
	if (echo) {
		uart_putc((unsigned char)c);
	}

	// avoid inserting NULL-Byte in strings
	if (c == 0x00)
		return;

	if (c == '\n' || c == '\r') {
		if (overflow) {
			uart_puts_P("ERROR: PARSER Overflow Error. String is too long.\n");
			overflow = false;
			len = 0;
			return;
		}
		if (len == 0)
			return;
		// add trailing NULL-byte
		recbuf[len] = 0x00;
		retval = process_cmd(recbuf, len);
		len = 0;
		
		if (retval.num == CMD_OK) {
			uart_puts_P("OK");
		} else if (retval.num == CMD_PONG) {
			uart_puts_P("PONG");
		} else if (retval.num == CMD_IGNORE) {
			//uart_puts_P("IGNORE");
			uart_puts_P("OK");
		} else {
			uart_puts_P("ERROR");
		}
		
		if (retval.string != NULL) {
			uart_puts_P(": ");
			uart_puts(retval.string);
		}
		
		uart_puts_P("\n");
	}
	else {
		if (len >= BUFFERLENGTH-1) {
			overflow = true;
			return;
		}
		else {
			recbuf[len++] = c;
		}
	}

}
Example #18
0
uint8_t print_disk_info(const struct fat_fs_struct* fs)
{
    if(!fs)
        return 0;

    struct sd_raw_info disk_info;
    if(!sd_raw_get_info(&disk_info))
        return 0;

    uart_puts_p(PSTR("manuf:  0x")); uart_putc_hex(disk_info.manufacturer); uart_putc('\n');
    uart_puts_p(PSTR("oem:    ")); uart_puts((char*) disk_info.oem); uart_putc('\n');
    uart_puts_p(PSTR("prod:   ")); uart_puts((char*) disk_info.product); uart_putc('\n');
    uart_puts_p(PSTR("rev:    ")); uart_putc_hex(disk_info.revision); uart_putc('\n');
    uart_puts_p(PSTR("serial: 0x")); uart_putdw_hex(disk_info.serial); uart_putc('\n');
    uart_puts_p(PSTR("date:   ")); uart_putw_dec(disk_info.manufacturing_month); uart_putc('/');
                                   uart_putw_dec(disk_info.manufacturing_year); uart_putc('\n');
    uart_puts_p(PSTR("size:   ")); uart_putdw_dec(disk_info.capacity / 1024 / 1024); uart_puts_p(PSTR("MB\n"));
    uart_puts_p(PSTR("copy:   ")); uart_putw_dec(disk_info.flag_copy); uart_putc('\n');
    uart_puts_p(PSTR("wr.pr.: ")); uart_putw_dec(disk_info.flag_write_protect_temp); uart_putc('/');
                                   uart_putw_dec(disk_info.flag_write_protect); uart_putc('\n');
    uart_puts_p(PSTR("format: ")); uart_putw_dec(disk_info.format); uart_putc('\n');
    uart_puts_p(PSTR("free:   ")); uart_putdw_dec(fat_get_fs_free(fs)); uart_putc('/');
                                   uart_putdw_dec(fat_get_fs_size(fs)); uart_putc('\n');

    return 1;
}
Example #19
0
//------------------------------------------------------------------------
void hexstring ( unsigned int d )
{
    hexstrings(d);
    uart_putc(0x0D);
    uart_putc(0x0A);
}
Example #20
0
File: debug.c Project: eieio/lk
void _dputc(char c)
{
	uart_putc(0, c);
}
Example #21
0
/*
 *uart_printf(char*)
 *Converts and formats values to be sent via char UART. Works similar to normal printf function.
 *INPUT: Char* EX: uart_printf("DATA: %i\r\n", datvar);
 *RETURN: None
 */
void uart_printf(char *format, ...)
{
    char c;
    int i;
    long l;

    va_list list;														//Make the arguement list
    va_start(list, format);

    while(c = *format++)												//run through the input till the end.
    {
        if(c == '%')													//% denotes the variable format character
        {
            switch(c = *format++)
            {
                case 's':                       						// strings
                    uart_puts(va_arg(list, char*));
                    break;

                case 'c':                       						// chars
                    uart_putc(va_arg(list, char));
                    break;

                case 'i':                       						// signed ints
                	i = va_arg(list, int);
                    if(i < 0)
                    {
                    	i = -i;
                     	uart_putc('-');
                    }
                    convert_dec((unsigned)i, divider + 5);
                    break;

                case 'u':                      							// unsigned ints
                    i = va_arg(list, int);
                    convert_dec((unsigned)i, divider + 5);
                    break;

                case 'l':                       						// signed longs
                    l = va_arg(list, long);
                    if(l < 0)
                    {
                    	l = -l;
                    	uart_putc('-');
                    }
                    convert_dec((unsigned long)l, divider);
                    break;

                case 'n':                       						// unsigned longs
                    l = va_arg(list, long);
                    convert_dec((unsigned long)l, divider);
                    break;

                case 'x':                       						// 16bit Hex
                    i = va_arg(list, int);
                    uart_putc(convert_hex(i >> 12));
                    uart_putc(convert_hex(i >> 8));
                    uart_putc(convert_hex(i >> 4));
                    uart_putc(convert_hex(i));
                    break;

                case 0:
                	return;
                default:
                	uart_putc(c);										//can't find formating. just print it.
            }
        }
        else
        {
        	uart_putc(c);
        }
    }
Example #22
0
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();

	/** GPIO Register set */
	volatile unsigned int *gpio = led_init();

	/* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
    //gpio = (unsigned int*)GPIO_BASE;

    /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO
       peripheral register to enable GPIO16 as an output */
    //gpio[LED_GPFSEL] |= (1 << LED_GPFBIT);

	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();
	uart_puts("> Hello, World!\r\n");

	int str_len = 80;
	char stringin[str_len];
	int i=0;
	uart_puts("> ");

	int x = 0;
	int *calc = &x;

	while (true){
		//art_puts("hello");
		//led_blink(gpio, .25);
		char x = uart_getc();
		//Checks if current str is being written outside size allotment
		if (i > str_len-1){
			uart_puts(stringin);
			reset_string(stringin, i);
		
			uart_puts("Max string len reached\r\n");
			i = 0;
		}
		// if enter is pressed
		else if (x == '\r')
		{
			uart_puts("\r\n");

			if (memcmp(stringin, "calc", sizeof("calc")) == 0) {
				uart_puts("CALC RECOGNIZED!\r\n");
				calc_init();
				*calc = 1;
			}
			if (memcmp(stringin, "blink", sizeof("blink")) == 0) {
				uart_puts("LEDDDDDD!\r\n");
				led_blink(gpio, 1);
			}
			if (memcmp(stringin, "stop", sizeof("stop")) == 0) {
				uart_puts("LEDDDDDD STOP!\r\n");
				led_blink(gpio, 0);
			}
			else{
				uart_puts(stringin);
				uart_puts("\n");
				// char str[16];
				// int c = -146;
				// uart_puts(itos(c, str));
			}
			
			reset_string(stringin, i);
			uart_puts("> ");
			i = 0;
		}
		else if (x == 127 || x == 8) // backspace character
		{
			if (i>0)
			{
				uart_putc('\b'); // move cursor back
				uart_putc(' '); // insert space in terminal
				uart_putc('\b'); // move cursor back before space
				stringin[i-1] = 0x00; // replace last char with empty
				i--; // decrement length
			}
		}
		else{
			stringin[i] = x;
			uart_putc(stringin[i]);
			i++;
		}

	}

}
void
arch_debug_serial_putchar(const char c)
{
	uart_putc(uart_debug_port(), c);
}
Example #24
0
void putc_escaped(char c){
    if(c == '\\'){
        uart_putc(c);
    }
    uart_putc(c);
}
Example #25
0
File: uart.c Project: moa/bme280
void uart_puts(char *s){
	while(*s){
		uart_putc(*s);
		s++;
	}
}
Example #26
0
File: console.c Project: KoWu/atxos
void writeString(char *str)
{
	while (*str) {
		uart_putc(*str++);
	}
}
int main(void)
{
	init_uart();																			// UART initalisieren und einschalten. Alle n�tigen Schnittstellen-Parameter und -Funktionen werden in rs232.h definiert
	i2c_init();																				// init I2C interface
	sei();
	uart_puts_p(FlashString);																// Demonstriert "rs232.c/uarts_put_p" f�r die Ausgabe eines Strings

	while(1)																				// Main- Endlosschleife
    {
		if (UART_MSG_FLAG==1)																// UART_MSG_FLAG auswerten: gesetzt in Empfangs- Interruptroutine wenn "CR" empfangen oder UART- Puffer voll
		{
			// (1) Daten an RS232 zur�ck
			uart_puts ("Folgende Daten an RS232 empfangen: ");
			uint8_t i;																		// Hilfsvariable f�r For-Next-Schleifenz�hler
			for (i=0;i<UART_RxCount;i++) {uart_putc(UART_RXBuffer[i]);}						// Empfangene Daten aus dem Puffer wieder �ber UART senden
			uart_puts(CR);
			// (2) Daten an I2C- Slave senden im MT-Mode
			if(!(i2c_start(SLAVE_ADRESSE+I2C_WRITE))) //Slave bereit zum schreiben?
				{
					uart_puts ("Daten: ");
					i2c_write(0x00);  // Buffer Startadresse setzen

					for (i=0;i<UART_RxCount;i++)											// Empfangene Daten in Array schreiben
						{
							i2c_write(UART_RXBuffer[i]);									// Bytes schreiben...
							uart_putc(UART_RXBuffer[i]);
						}
					i2c_stop();       // Zugriff beenden
					uart_puts (" an Slave gesendet."CR);
				}
			else
				{
					/* Hier k�nnte eine Fehlermeldung ausgegeben werden... */
					uart_puts("Fehler beim senden der Daten an Slave"CR);
				}
			// (3) Daten von I2C- Slave lesen im MR-Mode
			if(!(i2c_start(SLAVE_ADRESSE+I2C_WRITE))) //Slave bereit zum lesen?
				{
					uart_puts("Daten von Slave lesen: ");
					i2c_write(0x00); //Buffer Startadresse zum Auslesen
					i2c_rep_start(SLAVE_ADRESSE+I2C_READ); //Lesen beginnen

					for (i=0;i<UART_RxCount;i++)											// Empfangene Daten in Array schreiben
						{
							if ((i) < UART_RxCount-1)
							{
								TWI_RXBuffer[i]=i2c_readAck();									// Bytes schreiben...
								uart_putc(TWI_RXBuffer[i]);
							}
							else
							{
								TWI_RXBuffer[i]=i2c_readNak();									// letztes Bytes schreiben...
								uart_putc(TWI_RXBuffer[i]);
							}

						}

					i2c_stop();																// Zugriff beenden
					uart_puts(CR);
				}
			else
				{
					/* Hier k�nnte eine Fehlermeldung ausgegeben werden... */
					uart_puts("Fehler beim lesen der Daten an Slave"CR);
				}

			UART_RxCount=0;
			UART_MSG_FLAG=0;
		}

	}
}
Example #28
0
void kprintf(const char *format, ...) {
	va_list arg;

	va_start(arg, format);

	int c;
	char buf[20];


	while ((c = *format++) != 0) {
		if (c != '%') {
			//ofd->f_ops->write(ofd, &c, 1);
			uart_putc(c);
		} else {
			char *p;
			int long_modifier = 0;

			c = *format++;

			while (c == 'l') {
				long_modifier++;
				c = *format++;
			}

			switch (c) {
			case 'c':
				uart_putc(va_arg(arg, int));
				break;
			case 'd':
			case 'u':
				if (long_modifier == 2) {
					itoa(buf, c, va_arg(arg, long long));
				} else if (long_modifier == 1) {
					itoa(buf, c, va_arg(arg, long));
				} else {
					itoa(buf, c, va_arg(arg, int));
				}
				p = buf;
				goto string;
				break;
			case 'x':
				itox(buf, va_arg(arg, int));
				p = buf;
				goto string;
				break;
			case 's':
				p = va_arg(arg, char*);
				if (!p)
					p = "(null)";

				string:
					//ofd->f_ops->write(ofd, (unsigned char*) p, 1024);
					uart_puts(( char*) p);
					break;

			default:
				//ofd->f_ops->write(ofd, (int *) arg++, 1);
			   	uart_putc(c);
				break;
			}
		}
	}

	va_end(arg);
}
Example #29
0
static void
uart_dbg_putc(int c)
{

	uart_putc(&uart_dbgport, c);
}
void uart_putstr(char *str) {
	while(*str) {
		uart_putc(*str++);
	}
}