/* send a found device info according to passed index */
void conn_send_found_device(uint8_t found_dev_index)
{
	char ascii_address[12];

	uart_send_string((uint8_t *)"OK-", 3);
	/* check required device index */
	if(found_dev_index < devices_list_index)
	{
		/* connvert and send the device address */
		util_address_to_string(found_devices[found_dev_index].gap_addr.addr, ascii_address);
		uart_send_string((uint8_t *)ascii_address, 12);
		app_uart_put('-');
		/* send device name */
		if(found_devices[found_dev_index].name_length > 0)
		{
			uart_send_string(found_devices[found_dev_index].name, found_devices[found_dev_index].name_length-1);
		}
		else
		{
			uart_send_string((uint8_t *)"Unknown", 7);
		}
	}
	else
	{
		uart_send_string((uint8_t *)"ERROR", 5);
	}
	app_uart_put('.');
}
Ejemplo n.º 2
0
void send_command(uint8_t * string) {
	while(!have_carrot);
	have_carrot = 0;

	uart_send_string(string);
	uart_send_string("\n\r");
}
Ejemplo n.º 3
0
int main(void) {

    uart_init();
    adc0_init();

    uint16_t adc_value;
    char adc_value_str[5];

    while(1) {

        // Get the ADC value
        ADCSRA |= (1 << ADSC);                 // Start ADC conversion
        loop_until_bit_is_clear(ADCSRA, ADSC); // Wait until done
        adc_value = ADC;                       // Read ADC in

        // Send the value to UART
        snprintf((char *) &adc_value_str, 5, "%d", adc_value);
        uart_send_string(adc_value_str);       // Send a string to UART
        uart_send_string("\r\n");              // Send a string to UART

        // Wait
        _delay_ms(1000);      // Wait 1000ms

    }

    return(0);
}
Ejemplo n.º 4
0
int main(void)
{
    // board setup stuff
    led_init();
    uart_init();
    floppy_low_init();
    sdpin_init();
    spi_low_cs_init();
    spi_low_mst_init();
    //timer_init();

    // say hello
    uart_send_string((u08 *)"--- dfx-sampler sam7x/SPI ---");
    uart_send_crlf();

    // do initial setup
    rtc_init();
    memory_init();
    floppy_select_on();
    track_init();
    floppy_select_off();
    net_init();

    // print current RTC
    uart_send_string((u08 *)"rtc:  ");
    uart_send_string((u08 *)rtc_get_time_str());
    uart_send_crlf();

    // show network info
    net_info();

    while(1) {
        uart_send_string((u08 *)"> ");
        
        led_green(1);
        
        // get next command via SPI
        u08 *cmd;
        u08 len = cmd_uart_get_next(&cmd);

        led_green(0);
        
        if(len>0) {
            u08 result[CMD_MAX_SIZE];
            u08 res_size = CMD_MAX_SIZE;
            
            // parse and execute command
            cmd_parse(len, cmd, &res_size, result);
            
            // report result
            if(res_size > 0) {
                uart_send_data(result, res_size);
                uart_send_crlf();
            }
        }
    }
}
Ejemplo n.º 5
0
void status_info(void)
{
  uart_send_string((u08 *)"SC: ");
  uart_send_hex_dword_space(status.samples);
  uart_send_hex_dword_space(status.word_values);
  uart_send_hex_dword_crlf(status.timer_overflows);

  uart_send_string((u08 *)"SE: ");
  uart_send_hex_dword_space(status.cell_overruns);
  uart_send_hex_dword_crlf(status.data_overruns);
}
Ejemplo n.º 6
0
void boot_loader()
{
  // load program named "boot"
  long phdrs[128];
  current.phdr = (uintptr_t)phdrs;
  current.phdr_size = sizeof(phdrs);
  uart_send_string("Loadng linux ELF\n");
  load_elf("vmlinux", &current);

  uart_send_string("Linux ELF loaded\n");
  run_loaded_program();
}
Ejemplo n.º 7
0
/*----------------------------
Send one byte data to PC
Input: dat (UART data)
Output:-
----------------------------*/
void uart_send_hex_byte(BYTE dat) {
    char ch;
    
    uart_send_string("BYTE: ");
    
    ch = HEX_TABLE[(dat >> 4) & 0x0f];
    uart_send_data(ch);

    ch = HEX_TABLE[dat & 0x0f];
    uart_send_data(ch);

    uart_send_string("\r\n");
}
Ejemplo n.º 8
0
Archivo: UART.c Proyecto: rubda/KMM
void send_message(char name[], const char *attr[], uint8_t attr_length) {
	//EXAMPLE COMMAND
	//const char * attr[] = {"DATA1", "DATA2"};	
	//send_message("ROTATE", attr, 2)
	
	int i;
	uart_send_char('#');
	uart_send_string(name);
	for(i = 0; i < attr_length; ++i){
		uart_send_char(':');
		uart_send_string(attr[i]);
	}
	uart_send_char(';');
}
Ejemplo n.º 9
0
/**
  * Displays a hex dump on the debug console (16 bytes per line)
  * \param pbData     Pointer to dump data
  * \param ulDataLen  Length of data dump
  */
void    DumpData(uint8_t* pbData, uint32_t ulDataLen)
{
	uint8_t  vl_buf[16];
	uint32_t ulIdx = 0;
	char     word[16];
	uint8_t  i = 0;

	for(ulIdx = 0; ulIdx < ulDataLen; ++ulIdx)
	{
		if(0 == (ulIdx % 16) && ulIdx)
		{
			for (i = 0; i < 16; i++)
			{
				//uart0_send_data(word[i]);
				uart_send_data(UART1_BASE_PTR, word[i]);
			}
			//uart0_send_string("\r\n");
			uart_send_string(UART1_BASE_PTR, "\r\n");
		}

		if (pbData[ulIdx] > 31 && pbData[ulIdx] < 127)
		{
			word[ulIdx%16] = pbData[ulIdx];
		}
		else
		{
			word[ulIdx%16] = '.';
		}

		snprintf((char*)vl_buf, sizeof(vl_buf), "%02X ", pbData[ulIdx]);
		//uart0_send_string(vl_buf);
		uart_send_string(UART1_BASE_PTR, vl_buf);
	}

	if ((ulIdx % 16) == 0)
		ulIdx = 16;
	else
		ulIdx = ulIdx % 16;

	for (i = 0; i < ulIdx; i++)
	{
		//uart0_send_data(word[i]);
		uart_send_data(UART1_BASE_PTR, word[i]);
	}

//	uart0_send_string("\r\n");
	uart_send_string(UART1_BASE_PTR, "\r\n");
}
Ejemplo n.º 10
0
int auswertung()
{
  int result = -1;

  switch(uart_string[0])
  {

    case 's':
      result=set();
      break;

    case 'g':
      result=get();
      break;
    case 'c':
      send_time_sync();
      break;
#if funk == 1
    case 'p':
      packet();
      break;
#endif
#if testing == 1
    case 't':
      test();
      break;
#endif
    default:
      uart_send_pgm_string(cmd_not_fnd);
      uart_send_char(uart_string[0]);
      uart_send_string("\n\r\0");
  }
  return result;

}
Ejemplo n.º 11
0
// clock commands
static void cmd_clock(void)
{
  u08 cmd, value;
  u08 exit = 0;
  rtc_time t;
  while((cmd = get_char()) != 0) {
     switch(cmd) {
     case '?': // get time (raw)
       {
         rtc_get(t);
         for(int i=0;i<7;i++) {
             uart_send_hex_byte_space(t[i]);
         }
         uart_send_crlf();
         set_result(0);
       }
       break;
     case 't': // get time
       {
         u08 *str = (u08 *)rtc_get_time_str();
         uart_send_string(str);
         uart_send_crlf();
       }
       break;
     case 'y': // set year
       value = parse_hex_byte(0);
       rtc_set_entry(RTC_INDEX_YEAR, value);
       break;
     case 'o': // set year
       value = parse_hex_byte(1);
       rtc_set_entry(RTC_INDEX_MONTH, value);
       break;
     case 'd': // set day
       value = parse_hex_byte(1);
       rtc_set_entry(RTC_INDEX_DAY, value);
       break;
     case 'h': // set hour
       value = parse_hex_byte(0);
       rtc_set_entry(RTC_INDEX_HOUR, value);
       break;
     case 'i': // set minute
       value = parse_hex_byte(1);
       rtc_set_entry(RTC_INDEX_MINUTE, value);
       break;
     case 's': // set seconds
       value = parse_hex_byte(1);
       rtc_set_entry(RTC_INDEX_SECOND, value);
       break;
     default:
       set_result(ERROR_SYNTAX);
     case '.':
       exit = 1;
       break;
     }
     if(exit) break;
   }
}
Ejemplo n.º 12
0
int uart_put_char(int n_uart, unsigned char c)
{
	uint8_t buf[1];
	buf[0] = c;

	LPC_UART0->IER = IER_THRE | IER_RLS;			// Disable RBR 
	uart_send_string(n_uart, buf, 1);
	LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR;	// Re-enable RBR
}
Ejemplo n.º 13
0
/*----------------------------
Send one byte data to PC
Input: dat (UART data)
Output:-
----------------------------*/
void uart_send_hex_word(WORD dat) {
    char ch;
    
    uart_send_string("WORD: ");
    
    ch = HEX_TABLE[(dat >> 12) & 0x0f];
    uart_send_data(ch);

    ch = HEX_TABLE[(dat >> 8) & 0x0f];
    uart_send_data(ch);
    
    ch = HEX_TABLE[(dat >> 4) & 0x0f];
    uart_send_data(ch);
    
    ch = HEX_TABLE[(dat >> 0) & 0x0f];
    uart_send_data(ch);

    uart_send_string("\r\n");
}
Ejemplo n.º 14
0
void main(void)
{
    // sample text
    char rc;
    serial_t    sobj;

    // mbed uart test
    serial_init(&sobj,UART_TX,UART_RX);
    serial_baud(&sobj,38400);
    serial_format(&sobj, 8, ParityNone, 1);

    uart_send_string(&sobj, "UART API Demo...\r\n");
    uart_send_string(&sobj, "Hello World!!\r\n");
    while(1){
        uart_send_string(&sobj, "\r\n8195a$");
        rc = serial_getc(&sobj);
        serial_putc(&sobj, rc);
    }
}
Ejemplo n.º 15
0
void uart_socket_example_1(void *param)
{
	    // sample text
    char rc;
    serial_t    sobj;

    // mbed uart test
    serial_init(&sobj,PA_7,PA_6);
    serial_baud(&sobj,9600);
    serial_format(&sobj, 8, ParityNone, 1);

    uart_send_string(&sobj, "UART API Demo...\r\n");
    uart_send_string(&sobj, "Hello World!!\r\n");
    while(1){
        //uart_send_string(&sobj, "\r\n8195a$");
        rc = serial_getc(&sobj);
        //serial_putc(&sobj, rc);
        printf("%x\n",rc);
    }
}
Ejemplo n.º 16
0
/**
  * Displays isr debug messages on the console
  * Note: This function should be called from isr
  */
void traceInfo_output(const char* fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    vsnprintf((char*)isr_output_msg, sizeof(isr_output_msg), fmt, ap);
    va_end(ap);

   // uart0_send_string(isr_output_msg);
		uart_send_string(UART1_BASE_PTR, isr_output_msg);
}
/* send a number of found devices */
void conn_send_num_found_devices(void)
{
	char string[4];
	/* build the string */
	string[0] = 'O';
	string[1] = 'K';
	string[2] = '-';
	string[3] = (char)(0x30 | devices_list_index);	/* ascii conversion */
	/* send the string */
	uart_send_string((uint8_t *)string, 4);
	app_uart_put('.');
}
Ejemplo n.º 18
0
static bool_t write_fifo( uint8_t *payload,  uint16_t len)
{
	DBG_ASSERT(payload != NULL __DBG_LINE);
	if (len > SEND_SIZE)
	{
		DBG_ASSERT(FALSE __DBG_LINE);
	}
	osel_memset(recv.buf, 0 , SIZE);
	recv.offset = 0;
	uart_send_string(gprs_info.uart_port, payload, len);
	return TRUE;
}
Ejemplo n.º 19
0
void spectrum_info(u16 table[256], int verbose)
{
  // dump range
  // 01234567890123
  // XE: xx: xxxxcr
  static u08 *buf = (u08 *)"XE: xx xxxx\r\n";
  static u08 *sep = (u08 *)"XE: xx ----\r\n";
  u16 sum = 0;
  for(u08 i=0;i<255;i++) {
      sum += table[i];
  }

  if(verbose) {
    for(u08 i=0;i<255;i++) {
        // draw range border
        if((i==B0)||(i==B1)||(i==B2)||(i==B3)) {
            byte_to_hex(i,sep+4);
            uart_send_data(sep,14);
        }
        // draw non zero values
        if(table[i] != 0) {
            byte_to_hex(i,buf+4);
            word_to_hex(table[i],buf+7);
            uart_send_data(buf,14);
        }
    }
  }

  // sort in into ranges
  u16 total = 0;
  u16 zero1Count = 0;
  u16 zero2Count = 0;
  u16 zero3Count = 0;

  for(u08 i=B0;i<B1;i++) {
      zero1Count += table[i];
  }
  for(u08 i=B1;i<B2;i++) {
      zero2Count += table[i];
  }
  for(u08 i=B2;i<B3;i++) {
      zero3Count += table[i];
  }
  total = zero1Count + zero2Count + zero3Count;

  uart_send_string((u08 *)"XS: ");
  uart_send_hex_word_space(sum);
  uart_send_hex_word_space(total);
  uart_send_hex_word_space(zero1Count);
  uart_send_hex_word_space(zero2Count);
  uart_send_hex_word_crlf(zero3Count);
}
Ejemplo n.º 20
0
int Sensor_Ausgabe(void) //Ausgabe der Sensoren
{
	if (irio == 1)
	{
		uart_send_string("SR:");
		uart_send_int(SensorRechts(),2);		// Infrarot Front Sensor ausgeben
		uart_send_string("	SF:");
		uart_send_int(SensorFront(),2);			// Infrarot Rechter Sensor ausgeben
		uart_send_string("	SL:");
		uart_send_int(SensorLinks(),2);			// Infrarot Linker Sensor ausgeben
	}
	if (ulio == 1)
	{
		uart_send_int(SchrittMotor(),2);		// Schrittmotor Referrers signal der Lichtschranke ausgeben
	}
	if (irio == 1 || ulio == 1)
	{
		uart_send_string("\n\r");				// Zeielnumbruch
		_delay_ms(1);
	}
	return 0;
}
Ejemplo n.º 21
0
/**
  * @brief: USE UART2 to output debug message
  *
  */
void app_traceInfo_output(const char* fmt, ...)
{
    va_list     ap;
    _mqx_uint   err;

    err = _mutex_lock(&g_trace_mutex);
    ASSERT_PARAM(MQX_EOK == err);

    va_start(ap, fmt);
    vsnprintf((char*)output_msg, sizeof(output_msg), fmt, ap);
    va_end(ap);

    //uart0_send_string(output_msg);
		uart_send_string(UART1_BASE_PTR, output_msg);
    err = _mutex_unlock(&g_trace_mutex);
    ASSERT_PARAM(MQX_EOK == err);
}
/* CENTRAL: Callback handling NUS Client events.
   Handling events from the ble_nus_c module.
   This function is called to notify the application of NUS client events.
   Parameters: p_ble_nus_c   NUS Client Handle. This identifies the NUS client
               p_ble_nus_evt Pointer to the NUS Client event.
*/
static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, const ble_nus_c_evt_t * p_ble_nus_evt)
{
    uint32_t err_code;
    switch (p_ble_nus_evt->evt_type)
    {
        case BLE_NUS_C_EVT_FOUND_NUS_TX_CHARACTERISTIC:
		{
            /* TX characteristic found */
            break;
        }
        case BLE_NUS_C_EVT_FOUND_NUS_RX_CHARACTERISTIC:
		{
	    	/* RX characteristic found: enable notification on that */
            err_code = ble_nus_c_rx_notif_enable(p_ble_nus_c);
            APP_ERROR_CHECK(err_code);
            break;
        }
        case BLE_NUS_C_EVT_NUS_RX_EVT:
		{
			/* send received data from NUS to uart interface */
            for (uint32_t i = 0; i < p_ble_nus_evt->data_len; i++)
            {
                while(app_uart_put( p_ble_nus_evt->p_data[i]) != NRF_SUCCESS);
            }
			app_uart_put('.');
            break;
        }
        case BLE_NUS_C_EVT_DISCONNECTED:
		{
			/* clear related connection handle */
			active_conn_handles[pending_nus_conn_index] = BLE_CONN_HANDLE_INVALID;

			/* reset pending NUS connection index */
			pending_nus_conn_index = 0xFF;
			/* reset uart */
			uart_reset();
			/* set "connection" pin as disconnected */
			nrf_gpio_pin_write(CONN_PIN_NUMBER, DISCONNECTED_PIN_STATE);
			/* send confirmation string */
			uart_send_string((uint8_t *)"OK.", 3);
		
            break;
		}
    }
}
Ejemplo n.º 23
0
static bool_t lora_reg_write(uint8_t reg, uint8_t *buf, uint8_t len)
{
    uint8_t send_buf[30];
    uint8_t index = 0;

    lora_mode = SETTING_MODE;
//    lora_reg = reg;

    send_buf[index++] = 0xFF;
    send_buf[index++] = 0x56;
    send_buf[index++] = 0xAE;
    send_buf[index++] = 0x35;
    send_buf[index++] = 0xA9;
    send_buf[index++] = 0x55;
    send_buf[index++] = 0x90;
    send_buf[index++] = reg;
    send_buf[index++] = len;
    osel_memcpy(&send_buf[index], buf, len);
    index += len;

    lora_recv_rxok_flag = FALSE;
    uart_send_string(lora_port, send_buf, index);

    vTaskDelay(600 / portTICK_PERIOD_MS);

    if (lora_recv_index!=0)
    {
        if ((lora_recv_index == (len + 1)) &&
                (lora_recv_data[0] == 0x24))
        {
            lora_recv_index = 0;
            osel_memset(lora_recv_data, 0x00, 150);
            return TRUE;
        }
    }

    lora_recv_index = 0;
    osel_memset(lora_recv_data, 0x00, 150);
    return FALSE;
}
Ejemplo n.º 24
0
//-------------------------------------------------------Funktionen fuer das auslesen von Werten------------------------------------------------------
int get()
{
  static const char get_help[] PROGMEM = "Usage: g\n\rt for get time\n\rc for geting color\n\r";
  if(uart_string[1] == 'h')
  {
    uart_send_pgm_string(get_help);
  }
  else
#if rgb == 1
  if(uart_string[1] == 'c')
  {
    uart_send_string("R: ");
    uart_send_var(match[0]);
    uart_send_string(", G: ");
    uart_send_var(match[1]);
    uart_send_string(", B: ");
    uart_send_var(match[2]);
    uart_send_string("R: ");
    uart_send_var(match_tmp[0]);
    uart_send_string(", G: ");
    uart_send_var(match_tmp[1]);
    uart_send_string(", B: ");
    uart_send_var(match_tmp[2]);
  }
  else
#endif
#if time == 1
    if(uart_string[1] == 't')
  {
    uart_send_var_zero_dec(stunde, 2);
    uart_send_char(':');
    uart_send_var_zero_dec(minute, 2);
    uart_send_char(':');
    uart_send_var_zero_dec(sekunde, 2);
    uart_send_char('\n');
    uart_send_char('\r');
  }
  else
#endif
  {
    uart_send_pgm_string(get_help);
    return -1;
  }

  return 0;
}
Ejemplo n.º 25
0
/**
 * @biref the cmd of read the config
 * @param reg  start of read config
 * @param len  how many bytes read
 */
static bool_t lora_reg_read(uint8_t reg, uint8_t len)
{
    uint8_t buf[15];
    uint8_t index = 0;

    lora_mode = SETTING_MODE;
//    lora_reg = reg;

    buf[index++] = 0xFF;
    buf[index++] = 0x56;
    buf[index++] = 0xAE;
    buf[index++] = 0x35;
    buf[index++] = 0xA9;
    buf[index++] = 0x55;
    buf[index++] = 0xf0;
    buf[index++] = reg;
    buf[index++] = len;

    lora_recv_rxok_flag = FALSE;
    uart_send_string(lora_port, buf, index);

    vTaskDelay(50 / portTICK_PERIOD_MS);
    
    if (lora_recv_index!=0)
    {
        if ((lora_recv_index == (len + 1)) &&
                (lora_recv_data[0] == 0x24))
        {
            lora_recv_index = 0;
            osel_memset(lora_recv_data, 0x00, 150);
            return TRUE;
        }
    }

    lora_recv_index = 0;
    osel_memset(lora_recv_data, 0x00, 150);
    return FALSE;
}
Ejemplo n.º 26
0
int set_rgb()
{
  unsigned char color;
  unsigned char i;
  color = uart_string[2];
  if(color == 'R')
    match[0] = (uart_string[3] - 0x30) * 100 + (uart_string[4] - 0x30) * 10 + (uart_string[5] - 0x30);
  else if(color == 'G')
    match[1] = (uart_string[3] - 0x30) * 100 + (uart_string[4] - 0x30) * 10 + (uart_string[5] - 0x30);
  else if(color == 'B')
    match[2] = (uart_string[3] - 0x30) * 100 + (uart_string[4] - 0x30) * 10 + (uart_string[5] - 0x30);
  else
  {
    uart_send_string("Fehler\n\r");
    return -1;
  }
  i = 6;
  uart_send_char(uart_string[i]);
  uart_send_char(uart_string[i+1]);
  uart_send_char(uart_string[i+2]);
  uart_send_char(uart_string[i+3]);
  uart_send_var((uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30));
  if(uart_string[i] == 'R' || uart_string[i] == 'G' || uart_string[i] == 'B')
  {
    uart_send_char('r');
    if(uart_string[i] == 'R')
    {
      match[0] = (uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30);
      uart_send_var((uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30));
    }
    else if(uart_string[i] == 'G')
      match[1] = (uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30);
    else
      match[2] = (uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30);
  i=i+4;
  }
  sort_matches();
}
Ejemplo n.º 27
0
u32 cmdline_getline(void)
{
    uart_send_string((u08 *)"> ");
    
    u32 i = 0;
    while(i<CMDLINE_LEN) {
        // wait for next char
        while(!uart_read_ready());
        
        u08 data;
        uart_read(&data);
        uart_send(data);
        
        if(data == '\r') {
            uart_send('\n');
            break;
        }
        if(data == '\n')
            continue;
            
        cmdline[i++] = data;
    }
    return i;
}
Ejemplo n.º 28
0
int main(void)
{
	uart_init();						// Serial Inizialisirung
	DDRC = 0b01111111;
	DDRB = 0b11111111;
	DDRA = 0b11110001;
	DDRD &= ~((1 << PD2)|(1<<PD6));		// INT0 und Schrittmotor Endstop input...
	DDRD |= (1<<PD4)|(1<<PD5);			// PWM Ausgaenge festlegen
	ADCSRA = 0b10000111;				// Prescaler 128
	ADMUX |= (1<<REFS0);				// 5V Referrens spannung
	TCCR1A |= (1<<WGM10)|(1<<COM1A1)|(1<<COM1B1);
	TCCR1B |= (1<<WGM12)|(1<<CS12);		// Prescaler 256
	GICR |= (1<<INT0);					// IRS INT0 externer Interrupt aktiviren
	MCUCR |= (1<<ISC00);				// ISR INT0 Reaktion auf jede aenderung
	PORTB |= (1<<PB0);					// Schrittmotor Endstufe aus schalten
	PORTB &= ~(1<<PB2);					// Microstepps Disable
	PORTB |= (1<<PB6);					// Dir High
	PORTD |= (1<<PD6);					// Setze Pullup fuer Schrittmotor Endstop
	PORTD &= ~(1<<PD2);					// set pulldown for ISR Raspbarry PI check
	TIMSK |= (1<<TOIE0);				// Timer0 Overflow Interrupt erlauben
	
    while(1)
    {
		sei();						// Aktiviren aller interrups
		uart_init();				// Serial Inizialisirung
		if (rPI == 1)				// Wenn INT0 == High dann ...
		{
			PORTC |= (1<<PC1);
			Sensor_Ausgabe();		// Pereperie auswerten
			if (I_Wert == 49)		// Wenn eingabe == 49 dann ...
			{
				cli();						// Deaktiviren aller interrups
				I_Wert = 0;
				PORTC |= (1<<PC6);			// anzeigen das daten jetzt uebertragen werden koennen
				int Motor_R = (uart_get_int()-48);	// Richtungs vorgabe der Motoren 1-2 Vor-Rueckwaerts 5 = Motoren Aus
				int Motor_L = (uart_get_int()-48);	// Richtungs vorgabe der Motoren 3-4 Vor-Rueckwaerts 5 = Motoren Aus
				if(Motor_R > 5 || Motor_L > 5)		// Wenn eingabe groeßer als 5 dann ...
				{
					PORTC &= ~(1<<PC6);		// anzeigen das daten nicht mehr uebertragen werden koennen
					return main();			// Zurueck an denn anfang der main funktion
				}
				if(Motor_R == 5 || Motor_L == 5)	// Wenn eingabe == 5 dann ...
				{
					Motor_richtung(Motor_R,Motor_L);	// uebergabe an Motor_richtung
					PORTC &= ~(1<<PC6);			// anzeigen das daten nicht mehr uebertragen werden koennen
					return main();				// Zurueck an denn anfang der main funktion
				}
				int PWM[4] = {0,(uart_get_int()-48),(uart_get_int()-48),(uart_get_int()-48)};	// Annahmen der Motor geschwindigkein 0-255
				PWM[0] = (PWM[1]*100+PWM[2]*10+PWM[3]);
				int PWM1[4] = {0,(uart_get_int()-48),(uart_get_int()-48),(uart_get_int()-48)};	// Annahmen der Motor geschwindigkein 0-255
				PWM1[0] = (PWM1[1]*100+PWM1[2]*10+PWM1[3]);
				if (PWM[0] <= 255 && PWM1[0] <= 255)		// Wenn PWM kleiner als 255 dann ...
				{
					uart_send_string("MR: ");
					uart_send_int(Motor_R,1);
					uart_send_string(" ");
					uart_send_int(PWM[0],1);
					uart_send_string("\n\r");		// Sende zeielnumbruch
					uart_send_string("ML: ");
					uart_send_int(Motor_L,1);
					uart_send_string(" ");
					uart_send_int(PWM1[0],1);
					uart_send_string("\n\r");		// Sende zeielnumbruch
					if ((uart_get_int()-48) == 1)		// Bestaetigung der uebertragenen werte wenn eingabe == 1 dann ...
					{
						Motor_richtung(Motor_R,Motor_L);
						OCR1B = PWM[0];			// PWM setzen
						OCR1A = PWM1[0];		// PWM setzen
					}
				}
				PORTC &= ~(1<<PC6);		// anzeigen das daten nicht mehr uebertragen werden koennen
			}else
			{
				PORTC &= ~(1<<PC6);		// anzeigen das daten nicht mehr uebertragen werden koennen
			}
			if (I_Wert == 50)
			{
				cli();						// Deaktiviren aller interrups
				I_Wert = 0;
				PORTC |= (1<<PC6);			// anzeigen das daten jetzt uebertragen werden koennen
				int input = (uart_get_int()-48); //serielle eingabe
				Sensor_steuerung(input);
			}else
			{
				PORTC &= ~(1<<PC6);		// anzeigen das daten nicht mehr uebertragen werden koennen
			}
		}
		else
		{
			Sleep_mode();
		}
    }
}
Ejemplo n.º 29
0
int SchrittMotor(void) // Schrittmotor steuerung fuer Ultraschall Radar
{
	PORTB &= ~(1<<PB0);				// Schrittmotor Endstufe ENABLE
	if (firstStart == 1)
	{
		firstStart = 0;
		while (stepperRound < 24)
		{
			if (!(PIND & (1<<PIND6)))
			{
				stepperRound ++;
			} else
			{
				PORTB |= (1<<PB4);
				_delay_ms(20);
				PORTB &= ~(1<<PB4);
				_delay_ms(200);
				stepperRound ++;
			}
		}
		stepperRound = 0;
		PORTB &= ~(1<<PB6);			// Dir Low
	}
	if (stepperRound < 24)
	{
		stepperRound ++;
		PORTB |= (1<<PB4);
		_delay_ms(2);
		PORTB &= ~(1<<PB4);
		if (!(PIND & (1<<PIND6)) && stepperRound >= 3)
		{
			stepperRound = 24;
			_delay_ms(10);
		}
	}
	else
	{
		if (waitRound == 0)
		{
			_delay_ms(100);
			waitRound = 1;
		}
		PORTB |= (1<<PB6);			// Dir High
		stepperRound ++;
		PORTB |= (1<<PB4);
		_delay_ms(2);
		PORTB &= ~(1<<PB4);
		if (!(PIND & (1<<PIND6)) && stepperRound >= 27)
		{
			stepperRound = 49;
			_delay_ms(10);
		}
	}
	_delay_ms(2);
	if (stepperRound >= 48)
	{
		stepperRound = 0;
		waitRound = 0;
		_delay_ms(100);
		PORTB &= ~(1<<PB6);			// Dir low
	}
	_delay_ms(2);
	int ul = Usensor();
	if (ul <= 10)
	{
		_delay_ms(10);
	}
	uart_send_string("	UL:");
	uart_send_int(ul,2);
	uart_send_string("	SM:");
	return stepperRound;
}
Ejemplo n.º 30
0
Archivo: main.c Proyecto: alueger/dAISy
int main(void)
{
	// configure WDT
	WDTCTL = WDTPW | WDTHOLD;				// stop watch dog timer
	_25mhz();


#ifdef TEST
	// when compiled in test mode, use different main
	// disconnect radio when testing to avoid damage!
	test_main();
#endif

	// configure LED1 and turn it off, we'll use that for error and other stuff
	P1DIR |= LED1;
	LED1_OFF;

	P4DIR |= LED2;
	LED2_ON;

	// setup uart
	uart_init();

#ifdef DEBUG_MESSAGES
	uart_send_string("Hola mundo!\r\n");
#endif

	// setup packet handler
	ph_setup();

	// setup an configure radio
	radio_setup();
	radio_configure();

	// self-calibrate image rejection
	radio_calibrate_ir();

	// verify that radio configuration was successful
	radio_get_chip_status(0);
	if (radio_buffer.chip_status.chip_status & RADIO_CMD_ERROR) {	// check for command error
		uart_send_string("Error inicializando radio!!!\r\n");
		while (1) {
			LED1_TOGGLE;
			_delay_cycles(8000000);			// blink LED if there was an error
		}
	}


	// start packet receiving
	ph_start();

#ifdef DEBUG_MESSAGES
	uart_send_string("dAISy 0.2 started\r\n");
	LED2_OFF;
#endif

	while (1) {

		LPM0;	// deep sleep until something worthwhile happens

		__no_operation();

		ph_loop();	// packet handler house-keeping, e.g. channel hopping

#ifdef DEBUG_MESSAGES
		uint8_t channel;
		int16_t rssi;
		// debug code to monitor signal strength (RSSI)
		if (ph_get_state() == PH_STATE_PREFETCH) {											// found preamble and start flag
			// record current channel and signal strength
			channel = ph_get_radio_channel();												// read current channel
			rssi = ph_get_radio_rssi();														// read current RSSI
		}
#endif

		// retrieve last packet handler error
		uint8_t error = ph_get_last_error();
#ifdef DEBUG_MESSAGES
		// report error if packet handler failed
		if (error != PH_ERROR_NONE)	{
			dec_to_str(str_output_buffer, 3, rssi);											// convert to decimal string (reuse radio buffer)
			str_output_buffer[4] = 0;														// terminate string
			uart_send_string("sync ");														// send debug message to UART
			uart_send_byte(channel + 'A');
			uart_send_string(" RSSI=");
			uart_send_string(str_output_buffer);
			uart_send_string("dBm\r\n");
			uart_send_string("error: ");
			switch (error) {
			case PH_ERROR_NOEND:
				uart_send_string("no end flag");
				break;
			case PH_ERROR_STUFFBIT:
				uart_send_string("invalid stuff bit");
				break;
			case PH_ERROR_CRC:
				uart_send_string("CRC error");
				break;
			case PH_ERROR_RSSI_DROP:
				uart_send_string("RSSI drop");
				break;
			}
			uart_send_string("\r\n");
			ph_loop();							// house keeping, sending over UART takes time
		}
#else
		// toggle LED if packet handler failed after finding preamble and start flag
		if (error == PH_ERROR_NOEND || error == PH_ERROR_STUFFBIT || error == PH_ERROR_CRC)
			LED1_TOGGLE;
#endif

		// check if a new valid packet arrived
		uint16_t size = fifo_get_packet();
		if (size > 0) {								// if so, process packet

#ifdef DEBUG_MESSAGES
			dec_to_str(str_output_buffer, 3, rssi);											// convert to decimal string (reuse radio buffer)
			str_output_buffer[4] = 0;														// terminate string
			uart_send_string("sync ");														// send debug message to UART
			uart_send_byte(channel + 'A');
			uart_send_string(" RSSI=");
			uart_send_string(str_output_buffer);
			uart_send_string("dBm\r\n");
#endif
			LED2_ON;
			nmea_process_packet();					// process packet (NMEA message will be sent over UART)
			fifo_remove_packet();					// remove processed packet from FIFO
			LED2_OFF;
		}

		// enter low power mode LPM0 (everything off)
		// TODO: wait for UART to complete transmission

		// TODO: suspend UART
	}
}