Пример #1
0
void vscp_goBootloaderMode( uint8_t algo )
{
    writeEEPROM( VSCP_EEPROM_BOOTLOADER_FLAG, BTL_LOAD );
	#ifdef PRINT_VSCP_EVENTS
	uart_puts( "\n #####jumping to bootloader!\n" );
	#endif
	//reboot using WD
	cli();
	wdt_enable(WDTO_1S);
	while(1);
}
Пример #2
0
void LOG_DEBUG(const char* format, ...)
{
#ifdef DEBUG_LOGS_ENABLED
	va_list args;
	va_start(args,format);
	vsprintf(g_message, format, args);
	strcat(g_message, "\n\r");
	uart_puts(g_message);
	va_end(args);
#endif
}
Пример #3
0
int rac_setting(int value)
{
	unsigned long	rac_value;
	char 	msg[256];

	switch(value) {
		case 0:		/* RAC disabled, PF_D='0'b, PF_I='0'b, RAC_D='0'b, RAC_I='0'b */
			rac_value = 0x00000000;		
			break;

		case 1:		/* I-RAC enabled, PF_D='0'b, PF_I='1'b, RAC_D='0'b, RAC_I='1'b */
			bcm_inv_rac_all();
			rac_value = 0x00000005;	
			break;

		case 2:		/* D-RAC enabled, PF_D='1'b, PF_I='0'b, RAC_D='1'b, RAC_I='0'b */
			bcm_inv_rac_all();
			rac_value = 0x0000000A;
			break;

		case 3:		/* I/D-RAC enabled, PF_D='1'b, PF_I='1'b, RAC_D='1'b, RAC_I='1'b */
			bcm_inv_rac_all();
			rac_value = 0x0000000F;	
			break;

		default:	/* unspecified value, set to default */
			rac_value = 0x00000000;			
			sprintf(msg, "Invalid input for 3560b0 RAC mode setting. Default setting(RAC disabled) applied.\n");
			uart_puts(msg);
			break;
	}

	*((volatile unsigned long *)RAC_ADDRESS_RANGE_REGISTER) = par_val2;  /* 0x04000000; 64M for 3560b0 */
	*((volatile unsigned long *)RAC_CONFIGURATION_REGISTER) |= rac_value;

	sprintf(msg, "after init RAC 0x%08x    0x%08x\n", 
			*((volatile unsigned long *)RAC_CONFIGURATION_REGISTER), 
			*((volatile unsigned long *)RAC_ADDRESS_RANGE_REGISTER));

	uart_puts(msg);
}
Пример #4
0
int main(void)
{
    /* Replace with your application code */
	volatile int16_t gyro_x;
	volatile int16_t gyro_y;
	volatile int16_t gyro_z;

	volatile int16_t accel_x;
	volatile int16_t accel_y;
	volatile int16_t accel_z;

	volatile int16_t temp;

	char buffer[6];

    i2c_init();
	uart_init(256000);

	mpu_wakeup();
	

	while (1) 
    {
		gyro_x = mpu_read_gyro_x();
		gyro_y = mpu_read_gyro_y();
		gyro_z = mpu_read_gyro_z();

		accel_x = mpu_read_accel_x();
		accel_y = mpu_read_accel_y();
		accel_z = mpu_read_accel_z();

		temp = mpu__read_temp();

		itoa(temp, buffer, 10);
		uart_puts(buffer);
		uart_puts("  ");

		
		_delay_ms(10);			
    }
}
Пример #5
0
int main() {
    uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU));
    sei();
    uart_puts("begin\r\n");

    nrfInit();

    writeReg(RF_SETUP, SET_RF_SETUP);
    writeAddr(RX_ADDR_P0, SET_RX_ADDR_P0);
    writeAddr(TX_ADDR, SET_TX_ADDR);
    writeReg(DYNPD, SET_DYNPD);
    writeReg(FEATURE, SET_FEATURE);
    writeReg(RF_CH, SET_RF_CH);
    writeReg(CONFIG, SET_CONFIG);

    startRadio();


    uint8_t worked;
    uint8_t size;
    char sendbuffer[] = "Testing 1..2..3.. Testing.";
    size = sizeof (sendbuffer);
    char receivebuffer[33];
    char c;
    char count[10];
    int charbuffer;
    char payloadlength;
    //   uart_puts(sendbuffer);
    worked = transmit(sendbuffer, size);
    if (worked == 1) {
        uart_puts("Transmit Worked!\r\n");
    } else {
        uart_puts("Transmit Failed.\r\n");
    }
    startRx();

    while (1) {
        payloadlength = dynReceive(receivebuffer);
        if (payloadlength > 0) {
            uart_puts("Got something:");
            uart_puts(receivebuffer);
            uart_puts("\r\n");
        } else {
            uart_puts("nothin received\r\n");
        }

        c = uart_getc();
        if (!(c & UART_NO_DATA)) {
            uart_putc(c);
        }
        printRegisters();
        _delay_ms(2000);
    }


}
Пример #6
0
void uart_out(void)
{
	char adcDisplay[4];
	char cellDisplay;
	//Outputs BMS information and measurements to computer
	uart_puts("Start");
	uart_putc('\n');
	uart_putc(*utoa(cellNumber, &cellDisplay, 10));
	uart_putc('\n');
	for (uint8_t x = 0; x < cellNumber; x++)
	{
		uart_puts(dtostrf(adcConvert(adcReadings[x], cellReading), 4, 2, adcDisplay));
		uart_putc('\n');
		uart_putc(*utoa(balanceByte[x], &cellDisplay, 10));
		uart_putc('\n');
	}
	uart_puts(dtostrf(adcConvert(adcReadings_I, mainReading), 4, 2, adcDisplay));
	uart_putc('\n');
	uart_putc(*utoa(charger, &cellDisplay, 10));
	uart_putc('\n');
}
Пример #7
0
static void three_bytes_opcode(void)
{
    param1 = mos6502_read_mem(base++);
    param2 = mos6502_read_mem(base++);
    uart_puthex_padded(2, opcode);
    uart_putc(' ');
    uart_puthex_padded(2, param1);
    uart_putc(' ');
    uart_puthex_padded(2, param2);
    uart_putnc(9, ' ');
    uart_puts(cmd);
}
Пример #8
0
unsigned char send_sms(unsigned char *phone, unsigned char *message) {
	uart_puts("AT+CMGS=\"");
	uart_puts(phone);
	uart_puts("\"\r\n");
	start_get_data();
	while (!doneGetData)
		;
	doneGetData = 0;
	unsigned char i = 0;
	for (i = 0; i < index_data; i++)
		if (data[i] == '>') {
			uart_puts(message);
			uart_putc(0x1a);
		}
	start_get_data();
	while (!doneGetData)
		;
	doneGetData = 0;
	blink_led(LED_RED,3);
	return check_ok();
}
Пример #9
0
// handleMessage(char* msgbuf) -- main command router
//
// msgbuf[] is 8 bytes long
//  byte0 = report-id
//  byte1 = command
//  byte2..byte7 = args for command
//
// Available commands:
//  - Set time                  format: { 1, 'T', H,M,S, ...
//  - Send byte to watch        format: { 1, 'S', n, b, ...
//  - Receive byte from watch   format: { 1, 'R', ...
//  - 
//  - Set Base LED              format: { 1, 'l', ...
//  - Get Base Button State     format: { 1, 'b', ...
//  - Get Base Version          format: { 1, 'v', 0,0,0
//
//
void handleMessage(const char* msgbuf)
{
    // pre-load response with request, contains report id
    memcpy( hid_send_buf, msgbuf, 8 );

    uint8_t cmd = msgbuf[1];

    //
    //  Set Time                  format: { 1, 'T', H,M,S,      0,0,0 }
    //
    if(      cmd == 'T' ) {
        uint8_t H = msgbuf[2];
        uint8_t M = msgbuf[3];
        //uint8_t S = msgbuf[4];
        
        char buf[10];
        sprintf(buf, "F%2.2d:%2.2d", H,M);
     
        uart_puts( buf );  // send command to watch
        
    }
    //
    // Send bytes to watch        format: { 1, 'S', n, b1,b2,b3,b4,b5,b6 }
    //
    else if( cmd == 'S' ) { 
        uint8_t cnt = msgbuf[2];
        for( int i=0; i< cnt; i++ ) { 
            uart_putc( msgbuf[3+i] );
        }
    }
    //
    // Get last byte from watch   format: { 1, 'R', 0,0,0, 0,0,0 }
    //
    else if( cmd == 'R' ) { 
        hid_send_buf[3] = lastRxByte;
    }
    //
    // Base Station button state  format: { 1, 'b' 0,0,0, 0,0,0 }
    // 
    else if( cmd == 'b' ) {
        hid_send_buf[3] =  PORTA;  // just return all of PORTA because why not?
    }
    //
    //  Get version               format: { 1, 'v', 0,0,0,        0,0, 0 }
    //
    else if( cmd == 'v' ) {
        hid_send_buf[3] = cstbase_ver_major;
        hid_send_buf[4] = cstbase_ver_minor;
    }
    else {

    }
}
Пример #10
0
void *fn_sayHello(int init){
    lcd_gotoxy(0, 0);
    lcd_puts(("hello world."));
    lcd_gotoxy(0, 2);
    lcd_puts(("                "));
    lcd_gotoxy(hello_position, 2);
    lcd_puts(" -");
    ++hello_position;
    if(hello_position > 15){
        hello_position = 0;
    }
    if(opt_send_data_via_uart){
        LIGHT_ON(LED_RED);
        itoa(hello_position, buf, 10);
        uart_puts( buf );
        uart_puts( "\n" );
        LIGHT_OFF(LED_RED);
    }
    _delay_ms(200);
    return (void *) NULL;
}
Пример #11
0
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();
	uart_puts("Hello, kernel World!\r\n");
 
	while ( true )
		uart_putc(uart_getc());
}
Пример #12
0
uint8_t sd_read_block(uint32_t block_offset, uint8_t block[512]) {
  int r;
  uint16_t i;

  sd_select();
	if (sd_type == SD_TYPE_SDHC) {
		r = sd_cmd(CMD_READ_SINGLE_BLOCK, block_offset);
	} else {
		r = sd_cmd(CMD_READ_SINGLE_BLOCK, block_offset << 9);
	}

  if (r != 0) {
    uart_puts("CMD_READ_SINGLE_BLOCK command failed for offset");
    uart_puthex32(block_offset);
    uart_puts("\r\n");
      if(sd_channel==1)
    sd_deselectx(1);
  else
    sd_deselectx(0);
    sdok = 0;
    return r;
  }

  while (sd_recv() != 0xfe); // TODO: use timeout?

	//UART_TxStr("Block:\r\n");
  for (i = 0; i < 512; i++) {
    uint8_t c = sd_recv();
    block[i] = c;
		//UART_TxUint8(c);
  }
	//UART_TxStr("\r\n");

  sd_recv(); sd_recv(); // skip CRC

  sd_deselect();
  sd_recv();

  return 0;
}
Пример #13
0
	int init_motors(void){


		set_throtle(MOTOR_D8,MOTOR_MAX_VALUE);
		set_throtle(MOTOR_D5,MOTOR_MAX_VALUE);
		set_throtle(MOTOR_D6,MOTOR_MAX_VALUE);
		set_throtle(MOTOR_D7,MOTOR_MAX_VALUE);

		sprintf(buffer, "Setting Max Throttle value ...");
		uart_puts (UART,buffer);
		uart_puts (UART,"\n\r");

		sprintf(buffer, "Connect Battery connector now");
		uart_puts (UART,buffer);
		uart_puts (UART,"\n\r");

		_delay_ms(5000); //wait 7 seconds until ESC get max value stored.


		sprintf(buffer, "Setting Min Throttle value ...");
		uart_puts (UART,buffer);
		uart_puts (UART,"\n\r");

		set_throtle(MOTOR_D8,MOTOR_MIN_VALUE);
		set_throtle(MOTOR_D5,MOTOR_MIN_VALUE);
		set_throtle(MOTOR_D6,MOTOR_MIN_VALUE);
		set_throtle(MOTOR_D7,MOTOR_MIN_VALUE);


		_delay_ms(5000); //wait 4 seconds until ESC get min value stored.
		return 0;
	}
Пример #14
0
void mem_test()
{
 add_l=0;
 add_m=0; //reset sram addresses
 add_h=0;
 char print[10];
 uint32_t mem=0;
 for(mem=0;mem<140000;mem++)
 {
  if(mem>240 && mem<300)
  {
     itoa(add_l,print,10);
     uart_puts(print);
     uart_puts("   ");
     itoa(add_m,print,10);
     uart_puts(print);
     uart_puts("   ");
     itoa(add_h,print,10);
     uart_puts(print);
     uart_putc('\n');
     uart_putc('\n');
     _delay_ms(1000);
   } 
  add_inc();

  if(mem%100==0)
  {
  itoa(mem,print,10);
  uart_puts(print);
  uart_putc('\n');
  }//end if
 }//end for loop
while(1){}
}//end mem_test
Пример #15
0
int set_throtle(uint8_t motor_id, uint16_t value){

	bool ret_err = 0;
	if((motor_id < MOTOR_D8) && (motor_id > MOTOR_D5)){
		ret_err = 1;
	    sprintf(buffer, "Error set_throtle, motor: %d",motor_id);
	    uart_puts (UART,buffer);
	    uart_puts (UART,"\n\r");
		return ret_err;
	}

	value += 1000;

	if(((value < 1000) || (value > 2000)) && (value != 0)){

		ret_err = 1;
	    sprintf(buffer, "Error set_throtle value: %d",value);
	    uart_puts (UART,buffer);
	    uart_puts (UART,"\n\r");
		return ret_err;
	}
	else{
		value = value << 3;
	}
#if 1
    sprintf(buffer, "set_throtle value: %d,  motor: %d",value,motor_id);
    uart_puts (UART,buffer);
    uart_puts (UART,"\n\r");
#endif
	set_pwm(motor_id,value);
	return ret_err;
}
Пример #16
0
void hexdump(void *addr, int len) {
    uint8_t i;
    char buff[17], c[8];
    uint8_t *pc = (uint8_t*) addr;

    // Process every byte in the data.
    for (i = 0; i < len; i++) {
        // Multiple of 16 means new line (with line offset).

        if ((i % 16) == 0) {
            // Just don't print ASCII for the zeroth line.
            if (i != 0) {
                uart_puts("  ");
                uart_puts(buff);
                uart_puts("\r\n");
            }

            // Output the offset.
            sprintf(c, "  %04x  ", i);
            uart_puts(c);
        }

        // Now the hex code for the specific character.
        sprintf(c, " %02x", pc[i]);
        uart_puts(c);

        // And store a printable ASCII character for later.
        if ((pc[i] < 0x20) || (pc[i] > 0x7e))
            buff[i % 16] = '.';
        else
            buff[i % 16] = pc[i];
        buff[(i % 16) + 1] = '\0';
    }

    // Pad out last line if not exactly 16 characters.
    while ((i % 16) != 0) {
        uart_puts("   ");
        i++;
    }

    // And print the final ASCII bit.
    uart_puts("  ");
    uart_puts(buff);
    uart_puts("\r\n");
}
Пример #17
0
/* address must be aligned to 4 and size must be multiple of 4 */
static NOINSTR void emit_core_dump_section(int fd, const char *name,
                                           uint32_t addr, uint32_t size) {
  struct cs_base64_ctx ctx;
  int col_counter = 0;
  uart_puts(fd, ",\"");
  uart_puts(fd, name);
  uart_puts(fd, "\": {\"addr\": ");
  uart_putdec(fd, addr);
  uart_puts(fd, ", \"data\": \"");
  core_dump_emit_char_fd = fd;
  cs_base64_init(&ctx, core_dump_emit_char, &col_counter);

  uint32_t end = addr + size;
  while (addr < end) {
    uint32_t buf;
    buf = *((uint32_t *) addr);
    addr += sizeof(uint32_t);
    cs_base64_update(&ctx, (char *) &buf, sizeof(uint32_t));
  }
  cs_base64_finish(&ctx);
  uart_puts(fd, "\"}");
}
Пример #18
0
static void addr_mode_rel(void)
{
    uart_puts(" $");

    if ( param1 < 0x80 )
    {
        uart_puthex_padded(4, base + param1);
    }
    else
    {
        uart_puthex_padded(4, base - (0x100 - param1) );
    }
}
Пример #19
0
	int init_motor(uint8_t index){


		if((index < MOTOR_D8) && (index > MOTOR_D5)){
			return 1;
		}
		sprintf(buffer, "init_motor MOTOR_MAX_VALUE");
		uart_puts (UART,buffer);
		uart_puts (UART,"\n\r");
		set_throtle(index,MOTOR_MAX_VALUE);

		_delay_ms(5000); //wait 7 seconds until ESC get max value stored.


		sprintf(buffer, "init_motor MOTOR_MIN_VALUE");
		uart_puts (UART,buffer);
		uart_puts (UART,"\n\r");
		set_throtle(index,MOTOR_MIN_VALUE);

		_delay_ms(4000); //wait 4 seconds until ESC get min value stored.
		return 0;
	}
Пример #20
0
void determineBootFromFlashOrRom(void)
{
	char msg[64];
	extern int gFlashSize;

       	if (gFlashSize) 
     	RT_PHYS_FLASH_BASE = (0x20000000 - (gFlashSize << 20));

	sprintf(msg, "BOOTEDFROMFLASH, Base=%08lx\n", RT_PHYS_FLASH_BASE);
	uart_puts(msg);

	return;
}
Пример #21
0
// read in a line, then echo it
int parrot() {
        char *buf = moar(0);
        
        while ((*moar(1) = uart_getc()) != '\r');

        *moar(1) = '\r';
        *moar(1) = '\n';
        *moar(1) = '\0';
        uart_puts(buf);

        mat(buf);
        return 0;
}
Пример #22
0
/**
 * Main routine
 */
int main(void)
{
    WDTCTL  = WDTPW + WDTHOLD; 	// Stop WDT
	BCSCTL1 = CALBC1_1MHZ;      // Set DCO
  	DCOCTL  = CALDCO_1MHZ;

	P1DIR  = BIT0 + BIT6; 		// P1.0 and P1.6 are the red+green LEDs
	P1OUT  = BIT0 + BIT6; 		// All LEDs off

    uart_init();

	// register ISR called when data was received
    uart_set_rx_isr_ptr(uart_rx_isr);

    __bis_SR_register(GIE);

    uart_puts((char *)"\n\r***************\n\r");
    uart_puts((char *)"MSP430 harduart\n\r");
    uart_puts((char *)"***************\n\r\n\r");

	uart_puts((char *)"PRESS any key to start echo example ... ");

	unsigned char c = uart_getc();

	uart_putc(c);
	uart_puts((char *)"\n\rOK\n\r");

    volatile unsigned long i;

    while(1) {

	   P1OUT ^= BIT6; 			// Toggle P1.6 output (green LED) using exclusive-OR
	   i = 50000;             	// Delay

	   do (i--);				// busy waiting (bad)
	   while (i != 0);
    }
}
Пример #23
0
/* bootmain - the entry of bootloader */
void
bootmain(void) {
  extern char __bss_start__[], __bss_end__[];
  char *ptr = __bss_start__;
  const char *booterror = "Unknown";
  for(;ptr<__bss_end__;ptr++)
    *ptr = 0;

  uart_puts("Booting, please wait...\n");

  // is this a valid ELF?
  if (ELFHDR->e_magic != ELF_MAGIC) {
    booterror = "Bad ELF Magic";
    goto bad;
  }

  struct proghdr *ph, *eph;

  // load each program segment (ignores ph flags)
  ph = (struct proghdr *)((uintptr_t)ELFHDR + ELFHDR->e_phoff);
  eph = ph + ELFHDR->e_phnum;
  for (; ph < eph; ph ++) {
    readseg(ph->p_va, ph->p_memsz, ph->p_offset);
  }

  // call the entry point from the ELF header
  // note: does not return
  uart_puts("Jump to kernel\n");
  ((void (*) (void))(ELFHDR->e_entry))();

bad:
  uart_puts("Error: ");
  uart_puts(booterror);
  uart_puts("\n");

  /* do nothing */
  while (1);
}
Пример #24
0
// If THOMSON, assume Flash
void
determineBootFromFlashOrRom(void)
{
   char msg[128];
   unsigned long value;

   // Turn off EBI inversion to simplify MTD setup.
   value = EBI_CS_CONFIG_0;
   value &= ~BCHP_EBI_CS_CONFIG_0_mask_en_MASK;
   EBI_CS_CONFIG_0 = value;
   RT_PHYS_FLASH_BASE = 0x1F000000;
   sprintf(msg, "BOOTEDFROMFLASH, Base=%08lx\n", RT_PHYS_FLASH_BASE);
   uart_puts(msg);
}
Пример #25
0
// kernel main function, it all begins here
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) {
    UNUSED(atags);

    uart_init();

    // Wait a bit
    Wait(1000000);

    uart_puts(ready);
    init_heap(r0, r1);
    print_heap_range();

    pr0 = new_process(fn0);
    uart_puts("pr0 = ");
    puthexint((uint32_t)pr0);
    uart_puts(uart_newline);

    setup_timer();

    interactive_kernel_loop();

    uart_puts(halting);
}
Пример #26
0
void uart_putx(uint32_t x, unsigned digits)
{
	char buf[9];
	int idx = 7;

	buf[8] = 0;

	do {
		buf[idx--] = hex_char(x & 0xf);
		x >>= 4;
	} while (x || ((7 - idx) < digits));

	uart_puts(&buf[idx + 1]);
}
Пример #27
0
static uint8_t parse_int(void) {
  checked_r(char* token = parse_string(), 0);

#ifdef COMMANDLINE_DEBUG
  if ( !is_number(token) ) {
	parse_fail = 1;
	uart_puts_P("ERR: parse_int: no number: >");
	uart_puts(token);
	uart_puts_P("< " NEWLINE);
  }
#endif

  return atoi8(token);
}
Пример #28
0
void DS18X20_uart_put_temp(const uint8_t subzero, 
	const uint8_t cel, 	const uint8_t cel_frac_bits)
{
	uint8_t buffer[sizeof(int)*8+1];
	int i;
	
	uart_putc((subzero)?'-':'+');
	uart_puti((int)cel);
	uart_puts_P(".");
	itoa(cel_frac_bits*DS18X20_FRACCONV,buffer,10);
	for (i=0;i<4-strlen(buffer);i++) uart_puts_P("0");
	uart_puts(buffer);
	uart_puts_P("°C");
}
Пример #29
0
int main()
{
	UART1_init();

	uart_puts("hello stm32!\r\n");

	while(1)
	{
		// loop back test
		uart_putc( uart_getc() );
	}

	return 0;
}
Пример #30
0
NOINSTR void esp_dump_core(int fd, struct regfile *regs) {
  if (fd == -1) {
    fd = ESP_COREDUMP_FILENO;
  }
  uart_puts(fd, "--- BEGIN CORE DUMP ---\n");

  uart_puts(fd, "{\"arch\": \"ESP8266\"");
  emit_core_dump_section(fd, "REGS", (uintptr_t) regs, sizeof(*regs));
  emit_core_dump_section(fd, "DRAM", 0x3FFE8000, 0x18000);
  /* rtos relocates vectors here */
  emit_core_dump_section(fd, "VEC", 0x40100000, 0x1000);
  emit_core_dump_section(fd, "ROM", 0x40000000, 0x10000);
  uart_puts(fd, "}\n");

  /*
   * IRAM and IROM can be obtained from the firmware/ dir.
   * We need the ELF binary anyway to do symbolic debugging anyway
   * so we can avoid sending here huge amount of data that's available
   * on the host where we run GDB.
   */

  uart_puts(fd, "---- END CORE DUMP ----\n");
}