Пример #1
0
static vs1053_feeder_status_t
pgm_feeder(uint8_t **data, uint16_t *len, void *priv)
{
    struct pgm_feeder_priv *p = priv;
    #ifndef min
    #define min(a,b) ((a) < (b) ? (a) : (b))
    #endif
    uint8_t l = min(p->len, BUFFER_SIZE);

    sprintf(p->buffer, "Fed %d bytes(%s)\r\n", l, (p->len-l == 0)?"l":"c");
    usart_puts(p->buffer);

    memcpy_P(p->buffer, p->data, l);

    p->data += l;
    p->len -= l;

    *data = p->buffer;
    *len = l;

    if (p->len <= sizeof(demo_mp3)/4) {
        static uint8_t display = 1;
        if (display) {
            usart_puts("canceling\r\n");
            display = 0;
        }
        return VS1053_FEEDER_STATUS_CANCEL;
    }

    return (p->len == 0)?VS1053_FEEDER_STATUS_LAST:VS1053_FEEDER_STATUS_CONTINUE;
}
Пример #2
0
/* adc_report()
 * Writes the ADC value to the USART and the LCD */
void adc_report(uint16_t repdata) {
    char s[10];

    //usart_puts("The ADC value is 0x");
    sprintf(s,"%x ",repdata);
    usart_puts(s); // Send to the USART
    usart_puts("\r\n");
    sprintf(s,"0x%x",repdata);
    lcd_puts(s,0); // Send to the LCD
}
Пример #3
0
int serial_proc(void){

	nDUT = atoi(com_data[0]);			// DUT(Dec)
	wSIG = Ascii2Uint(com_data[1]);		// Signal(Hex)
	tgDut=0x0001;						// endo
	if(nDUT<1 || nDUT>1152 || wSIG>0x00ff ) { usart_puts("NG\r\n");	return FALSE;}
	else {
		send_UDT_SerialComb();
		usart_puts("DONE\r\n");
	}
	return 0;
}
void usart_vprintf(const char *fmt, va_list va)
{
	char db[128];
	if (vsnprintf(db, sizeof(db), fmt, va) > 0) {
		usart_puts(db);
	}
}
Пример #5
0
static void shDate(int argc, char **argv)
{
    unsigned char buf[16];

    sprintf(buf, "%lu ms\r\n", wclock_jiffies_to_msec(jiffies));
    usart_puts(buf);
}
Пример #6
0
void lambda_stopmeasurment() {
  if(_status.Systembereit && lambda_state == RUNNING) {
    usart_puts(lambda_fd, END_MEASUREMENT);
    lambda_state = 0;
  }
  
}
Пример #7
0
int main_cm3 ( void ) {

#if 1 // go for 120MHz, built into libopencm3
  // requires: external 8MHz crystal on pin5/6 with associated caps to ground
  rcc_clock_setup_hse_3v3 ( &hse_8mhz_3v3 [ CLOCK_3V3_120MHZ ] );
#endif

  // wait a sec, so we have a reflash opportunity before things get funky
  //
  lame_delay_ms ( 2000 );

  // initialize USART1 @ 9600 baud
  //
  init_usart1 ( 9600 );

  usart_puts ( 1, "Init usart1 complete! Hello World!\r\n" );
  //usart_puts ( 2, "Init usart2 complete! Hello World!\r\n" );

  // PWM setup
#if 0
  usart_puts ( 1, "usart1 pwm test start!\r\n" );
  pwm_test();
  usart_puts ( 1, "usart1 pwm test complete!\r\n" );
#endif

  // MPU setup
#if 0
  mpu_test();
  usart_puts ( 1, "usart1 mpu test complete!\r\n" );
#endif

  // balance!
#if 1
  usart_puts ( 1, "usart1 - enter balance mode!\r\n" );
  balance_or_die();
#endif

  //__enable_irq();
  //cm_enable_interrupts();

  while ( 1 ) {
    __asm__("nop");
  } // while forever

  return 0;
}
Пример #8
0
void adc_task(void) {
    uint8_t update_time = 0;
    adc_init();
    while (1) {
        char light_str[6], temp_str[6], time_str[6];
        uint8_t light = adc_acquire(0);
        uint8_t temperature = adc_acquire(1);
        uint8_t_to_ascii(light, &(light_str[0]));
        uint8_t_to_ascii(temperature, &(temp_str[0]));
        uint8_t_to_ascii(ticks, &(time_str[0]));
        os_semaphore_wait(&lcd_sem);
        lcd_set_cursor(0, 0);
        lcd_putstr("Time: ");
        lcd_putstr(time_str);
        lcd_set_cursor(1, 0);
        lcd_putstr("Light: ");
        lcd_putstr(light_str);
        lcd_set_cursor(2, 0);
        lcd_putstr("Temp: ");
        lcd_putstr(temp_str);
        os_semaphore_signal(&lcd_sem);
        
        os_semaphore_wait(&stt_sem);
        if (state) {
            update_time = 1;
        } else {
            update_time = 0;
        }
        os_semaphore_signal(&stt_sem);
        os_semaphore_wait(&tck_sem);
        if (update_time) {
            ticks++;
        }
        os_semaphore_signal(&tck_sem);
        
        if (state == 1) {
            usart_puts("Time: ");
            usart_puts(time_str);
            usart_puts("\r\n");
            usart_puts("Light: ");
            usart_puts(light_str);
            usart_puts("\r\n");
            usart_puts("Temperature: ");
            usart_puts(temp_str);
            usart_puts("\r\n");
        }
        
        os_delay(os_get_current_pid(), 1000);
    }
}
Пример #9
0
/**
 * @brief  Initialize the USART1 serial port
 * @param  None
 * @retval None
 */
void usart_init() {
	/* Clock configuration -------------------------------------------------------*/
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA,
			ENABLE);

	/* Configure the GPIO ports( USART1 Transmit and Receive Lines) */
	/* Configure the USART1_Tx as Alternate function Push-Pull */
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	/* Configure the USART1_Rx as input floating */
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	/* USART1 configuration ------------------------------------------------------*/
	/* USART1 configured as follow:
	 - BaudRate = 115200 baud
	 - Word Length = 8 Bits
	 - One Stop Bit
	 - No parity
	 - Hardware flow control disabled (RTS and CTS signals)
	 - Receive and transmit enabled
	 */
	USART_InitTypeDef USART_InitStructure;
	USART_InitStructure.USART_BaudRate = 115200;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl =
			USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

	/* Configure the USART1 */
	USART_Init(USART1, &USART_InitStructure);

	/* Enable USART1 interrupt */
	NVIC_InitTypeDef nvic;
	nvic.NVIC_IRQChannel = USART1_IRQn;
	nvic.NVIC_IRQChannelPreemptionPriority = 15;
	nvic.NVIC_IRQChannelSubPriority = 1;
	nvic.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&nvic);

	Queue_init(&txbuf);
	Queue_init(&rxbuf);

	/* Enable the USART1 */
	USART_Cmd(USART1, ENABLE);
	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

	// print invitation
	usart_puts("FS-T6\r\n");
}
Пример #10
0
void usart_printf(const char *pFormat, ...)
{
    va_list ap;

    va_start(ap, pFormat);
    vsprintf(_usart_printf_buff, pFormat, ap);
    va_end(ap);
    usart_puts(_usart_printf_buff);
}
Пример #11
0
unsigned char mpu_test ( void ) {
  usart_puts ( 1, "lib MPU6050 - test - enter!\r\n" );

  usart_puts ( 1, "lib MPU6050 - test - i2c init!\r\n" );
  MPU6050_I2C_Init();

  usart_puts ( 1, "lib MPU6050 - test - mpu init!\r\n" );
  MPU6050_Initialize();

  usart_puts ( 1, "lib MPU6050 - test - test connection!\r\n" );

  if ( MPU6050_TestConnection() == FALSE ) {
    usart_puts ( 1, "Init MPU6050 - FAIL!\r\n" );
    return ( 0 );
  }

  // connection success
  usart_puts ( 1, "Init MPU6050 - success\r\n" );

  // run a looping test
  //
  int16_t AccelGyro[6]={0};
  unsigned char i;
  char b [ 20 ];

  while ( 1 ) {

    MPU6050_GetRawAccelGyro ( AccelGyro );

    usart_puts ( 1, "GyroAccel: " );
    for ( i = 0; i <= 5; i++ ) {
      lame_itoa ( AccelGyro [ i ], b );
      usart_puts ( 1, b );
      usart_puts ( 1, " , " );
    }
    usart_puts ( 1, "\r\n" );

    lame_delay_ms ( 1000 );
  } // while

  return ( 1 );
}
Пример #12
0
static void shPlay(int argc, char **argv)
{
    int i;
    unsigned char buf[16];
    int times = 1;

    if (argc == 1)
        times = atoi(argv[0]);

    usart_puts("Playing ");
    sprintf(buf, "%d bytes ", sizeof(demo_mp3));
    usart_puts(buf);
    sprintf(buf, "%d times ", times);
    usart_puts(buf);

    for (i=0;i<times;++i)
        vs1053_play_pgm(demo_mp3, sizeof(demo_mp3));

    usart_puts("done\r\n");
}
Пример #13
0
int lambda_init(void)
{
	uint8_t i;

	for(i=0;i<128;i++)  O2Mem.Mem[i] = 0;
  
  sprintf(O2Mem.cur_value, "XXX");
  // USART �ffnen
  if((lambda_fd = usart_open( "/dev/ttyAMA0",115200)) == -1)
    return -1;
  
  // Einstellungen senden
  usart_puts(lambda_fd, NORMAL_MODE);
  usart_puts(lambda_fd, LOW_COMMUNICATION);
  usart_puts(lambda_fd, CSVTEXT_MODE);
  
  usart_flush(lambda_fd);
  
  is_Init = true;
}
Пример #14
0
void lambda_startmeasurment() {
  uint8_t i;
  
  if(!lambda_fehler() && _status.Systembereit == 0 ) {
    usart_puts(lambda_fd, START_MEASUREMENT);
  	for(i=0;i<128;i++)  O2Mem.Mem[i] = 0;
  
    sprintf(O2Mem.cur_value, "XXX");
    lambda_state = RUNNING;
  }
}
Пример #15
0
int main(void)
{
	Init();

	usart_init_intr(9600);
	// Timer 0 konfigurieren
	TCCR0 = (1<<CS01); //Prescaler 8 | (1<<CS00); // Prescaler 64
	
	// Overflow Interrupt erlauben
	TIMSK |= (1<<TOIE0);
	
	// Global Interrupts aktivieren
	sei();

	
	
	
    while(1)
    {
//-----------------------------------------------------------------Einlesen
		readData(); 
//-----------------------------------------------------------------WASD Steuerung
		checkData(); 
//-----------------------------------------------------------------Regelung
		
		
		usart_putc('E');
		usart_puti(curr_error, 3);
		usart_puts("\r\n");
	
//-----------------------------------------------------------------Minimal/Maximalwerte
		setMotor(DirLeft, DirRight, IstSpeedLeft, IstSpeedRight);
		
		if (KeyPressed() != 0){
			usart_puts("Taster"); 			
		}
		
	
	}
	//------------------------------------------------------------------------------------------------Ende while
}
Пример #16
0
static void shCancelTest(int argc, char **argv)
{
    struct pgm_feeder_priv p = {.data = demo_mp3, .len = sizeof(demo_mp3)};

    usart_puts("Cancel test\r\n");
    vs1053_play(pgm_feeder, &p);
}
SH_DECLARE_CMD("ct", shCancelTest);

static void shRegs(int argc, char **argv)
{
    int i;
    unsigned int reg;
    unsigned char buf[16];

    for (i=0;i<VS1053_SCI_REG_QTY;++i) {
        vs1053_read_register((vs1053_sci_reg_t)i, &reg);
        sprintf(buf, "%d=0x%04x\r\n", i, reg);
        usart_puts(buf);
    }
}
Пример #17
0
void main(void) {
	unsigned int i;
	unsigned char foo;
	
	unsigned char *ptr;
    OSCCONbits.SCS = 0x10;
//    OSCCONbits.SCS = 0x00;	// external osc
    OSCCONbits.IRCF = 0x7;	// 8 MHz

	fifo_head = 0;
	fifo_tail = 0;
	
	init_system();

#ifdef DEBUG
//	usart_puts("Testo printer emulator... serial working\n\r");
#endif
//	ptr = &fifo_buffer_0[0];
	for (i = 0; i < 1024; i++) {
		//fifo_buffer_0[i] = 'a';
		fifo_put('a');
		//sprintf(buffer, "%c \n", fifo_buffer_0[i]);
		//usart_puts(buffer);
		}
	/*
	fifo_buffer_0[0] = 'a';
	fifo_buffer_0[1] = 'b';
	fifo_buffer_0[2] = 'c';
	fifo_buffer_0[3] = 'd';
	sprintf(buffer, "%c \n", fifo_buffer_0[0]);
	usart_puts(buffer);
	sprintf(buffer, "%c \n", fifo_buffer_0[1]);
	usart_puts(buffer);
	sprintf(buffer, "%c \n", fifo_buffer_0[2]);
	usart_puts(buffer);
	sprintf(buffer, "%c \n", fifo_buffer_0[3]);
	usart_puts(buffer);
	*/
//	fifo_put('0');
//	fifo_put('1');
//	fifo_put('2');
//	fifo_put('a');
	
	while (1) {
		if (fifo_get(&foo)) {
			sprintf(buffer, "%c \n", foo);
			usart_puts(buffer);
			//usart_putc(foo);
		}
	}
}
Пример #18
0
static void shVol(int argc, char **argv)
{
    idBm_t left, right;

    if (argc != 2) {
        usart_puts("usage: vol [left] [right]");
        return;
    } else {
        left = atoi(argv[0]);
        right = atoi(argv[1]);
    }

    vs1053_set_volume(left, right);
}
Пример #19
0
int main(void) {
    uint16_t adc_data = 0;
    
    sei(); // Enable interrupts
    fosc_cal(); // Set calibrated 1MHz system clock
    portb_init(); // Set up port B
    usart_init(); // Set up the USART
    timer2_init();  // Set up, stop, and reset timer2
    timer0_init();
    usart_puts("Initialize ADC\r\n");
    adc_init();
    usart_puts("Initialize LCD\r\n");
    lcd_init(); // From LDC_driver
    usart_puts("Start main loop\r\n");
    lcd_puts("Hello",0); // From LCD_functions
    timer2_start(); // Start stimulus
    adc_mux(1); // Switch to the voltage reader at J407
    for(;;) {
        adc_read(&adc_data);
        adc_report(adc_data);
        OCR0A = (uint8_t)(adc_data);
    }// end main for loop
} // end main
Пример #20
0
void load_image_done(int retval)
{
	char *media;

#if defined(CONFIG_LOAD_NONE)
	media = "NONE: ";
#elif defined(CONFIG_FLASH)
	media = "FLASH: ";
#elif defined(CONFIG_NANDFLASH)
	media = "NAND: ";
#elif defined(CONFIG_DATAFLASH)
	media = "SF: ";
#elif defined(CONFIG_SDCARD)
	media = "SD/MMC: ";
#else
	media = NULL;
#endif

	if (media)
		usart_puts(media);

	if (retval == 0) {
#if defined(CONFIG_LOAD_NONE)
		usart_puts("AT91Bootstrap completed. Can load application via JTAG and jump.\n");
#else
		usart_puts("Done to load image\n");
#endif
	}
	if (retval == -1) {
		usart_puts("Failed to load image\n");
		while(1);
	}
	if (retval == -2) {
		usart_puts("Success to recovery\n");
		while (1);
	}
}
Пример #21
0
/* usart_printf_p() 

   Send a format string stored in flash memory to the USART.
*/
uint8_t usart_printf_p(const char *fmt, ...) {
    va_list args; 
    char printbuffer[USART_TXBUFFERSIZE]; 

    va_start (args, fmt); 
        /* For this to work, printbuffer must be larger than 
        * anything we ever want to print. 
        */ 
        vsnprintf_P (printbuffer, USART_TXBUFFERSIZE, fmt, args); 
    va_end (args); 

    /* Print the string */ 
    usart_puts(printbuffer); 
    return 0; 
}    
Пример #22
0
void debugDisplayArray(FILE *stream,
   const char_t *prepend, const void *data, uint_t length)
{
   uint_t i;

   for(i = 0; i < length; i++)
   {
      //Beginning of a new line?
      if((i % 16) == 0)
    	  usart_puts(prepend);
      //Display current data byte
      usart_printf("%02X ", *((unsigned char *) data + i));
      //End of current line?
      if((i % 16) == 15 || i == (length - 1))
    	  usart_printf("\r\n");
   }
}
Пример #23
0
static void display_banner (void)
{
	char *version = "AT91Bootstrap";
	char *ver_num = " "AT91BOOTSTRAP_VERSION" ("COMPILE_TIME")";

	usart_puts("\n");
	usart_puts("\n");
	usart_puts(version);
	usart_puts(ver_num);
	usart_puts("\n");
	usart_puts("\n");
}
Пример #24
0
int main(void)
{
    int32_t i;

    rcc_periph_clock_enable(RCC_GPIOA);
    gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);

    flash_set_ws(FLASH_ACR_LATENCY_2WS);
	rcc_set_adcpre(RCC_CFGR_ADCPRE_PCLK2_DIV4); /* 14MHz */
	rcc_set_hpre(RCC_CFGR_HPRE_SYSCLK_NODIV); /* 56MHz */
	rcc_set_ppre1(RCC_CFGR_PPRE1_HCLK_DIV2); /* 28MHz */
	rcc_set_ppre2(RCC_CFGR_PPRE2_HCLK_NODIV); /* 56MHz */
    rcc_set_pll_multiplication_factor(RCC_CFGR_PLLMUL_PLL_CLK_MUL14); /* 8MHz/2 x14 = 56MHz */
	rcc_set_pll_source(RCC_CFGR_PLLSRC_HSI_CLK_DIV2);
	rcc_osc_on(PLL);
	rcc_wait_for_osc_ready(PLL);
	rcc_set_sysclk_source(RCC_CFGR_SW_SYSCLKSEL_PLLCLK);

    rcc_periph_clock_enable(RCC_USART2);
    gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
    gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);

    uint32_t baud = 57600;
    uint32_t clock = 28000000;
	USART2_BRR = ((2 * clock) + baud) / (2 * baud);
    
	usart_set_databits(USART2, 8);
	usart_set_stopbits(USART2, USART_STOPBITS_1);
	usart_set_mode(USART2, USART_MODE_TX_RX);
	usart_set_parity(USART2, USART_PARITY_NONE);
	usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
	usart_enable(USART2);

    usart_puts(USART2, "ready to receive.\r\n");
    gpio_set(GPIOA, GPIO5);
    while(1)
    {
        uint16_t c;
        c = usart_recv_blocking(USART2);
        usart_send_blocking(USART2, toupper(c));
        gpio_toggle(GPIOA, GPIO5);
    }
}
Пример #25
0
void main()
{
	usart_init(BAUD_115200);
	usart_isr_rx_enable(true); // enable RX interrupt handler

	// configure pins
	as_output(LED);

	// globally enable interrupts (for the USART_RX handler)
	sei();

	while (1) {
		usart_puts("Hello World!\r\n");

		pin_toggle(13); // blink the LED

		_delay_ms(500);
	}
}
Пример #26
0
void dec2hascii(int32_t liczba, uint8_t length){

	/*int32_t buffer;
	int i;
	for (i=length;i > 0;i--)
	{
		buffer = (liczba % (1<< (i*4)) / (1<< ((i*4)-4)));
		if (buffer>=0 && buffer<=9)
			usart_put((uint8_t)buffer+48);
		else if (buffer>=10 && buffer<=15)
			usart_put((uint8_t)buffer+55);

	}*/

	uint8_t buff[20];
	int i;
	int l = sprintf(buff, "%X", liczba);
	if(l < length)
		for(i = 0; i < length - l; i++)
			usart_put('0');

		usart_puts(buff);

}
Пример #27
0
Файл: main.c Проект: degao/test
static void display_banner (void)
{
	usart_puts(BANNER);
}
//*******************************************************************************
//*		This is where we get the chunks of data 
//*		to program to the dataflash
//*******************************************************************************
void image_interface_begin(void)
{
//unsigned int	page_count	=	0;
unsigned char	command		=	0;
unsigned char	*buff;
unsigned int	page_num	=	0;
boolean			keepGoing;
COLOR			black		=	{0,0,0};
COLOR			white		=	{255,255,255};
	/*
		order of operations:
			1.) purge usart buffers
			2.) recv mode byte
			3.) if mode == STORE,
					recv page_count 
					recv all pages
				else mode == READ
					send page_count
					send pages
	*/
	
	arduinoReset();

	usart_init(115200);
 
	cli();

	buff = usart_getBuff_ptr();

	//enough setup, lets begin
	keepGoing	=	TRUE;
	while(keepGoing)
	{
		usart_read_bytes(1); //Wait for us to read a byte
		command = buff[0]; //store or read command
		
		if (command == IMAGE_INTERFACE_ERASE)
		{
			dispPutS("Erasing",0,0,white,black);
			dataflash_erase();
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok
			dispPutS("Erasing Done",0,10,white,black);
		}
		else

		if (command == IMAGE_INTERFACE_STORE)
		{
			uint16_t x;
			unsigned char out_data[DATAFLASH_PAGESIZE],in_data[DATAFLASH_PAGESIZE];	
			char out[10];	
			uint8_t checksum = 0;
			buff = usart_getBuff_ptr();

			
			dispPutS("Store",0,20,white,black);
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok

			//give us the page number to write
			usart_read_bytes(2);
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok
			page_num = (buff[1] << 8) + buff[0];
			dtostrf(page_num,4,0,out);
			dispPutS("Page Number:",0,30,white,black);
			dispPutS(out,100,30,white,black);
			
			//read the whole page
			usart_read_bytes(DATAFLASH_PAGESIZE);
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok
			dispPutS("Page recved",0,40,white,black);
			
			//program the whole page
			for(x=0;x<DATAFLASH_PAGESIZE;x++) { out_data[x] = buff[x]; } //copy the page to the outbound page buffer
			dataflash_program_page(&out_data[0], page_num); 	//program the page
			for(x=0;x<DATAFLASH_PAGESIZE;x++) { in_data[x] = 0x00; } //clear the inbound page buffer

			//wait for checksum command
			usart_read_bytes(1);
			dispPutS("Checksum",0,50,white,black);
			dataflash_cont_read(&in_data[0], page_num, DATAFLASH_PAGESIZE); //read the page out of the chip
			for(x=0;x<DATAFLASH_PAGESIZE;x++) { checksum += in_data[x]; } // build checksum
			checksum = (checksum ^ 0xFF ) + 1; //two's complement
			usart_putc(checksum); //send checksum
			dispPutS("Sent",0,60,white,black);
				
		}
		else if (command == IMAGE_INTERFACE_READ)
		{
			unsigned int x;
			unsigned char out[DATAFLASH_PAGESIZE];


			page_num=0;

			//give us the number of pages you're sending
			usart_read_bytes(2);
			page_num = (buff[0] << 8) + buff[1];	//number of pages
			

			dataflash_cont_read(&out[0], page_num, DATAFLASH_PAGESIZE);


			for (x=0; x<DATAFLASH_PAGESIZE; x++)
				{
				usart_putc(out[x]);
				}

			asm("nop");
		}
		else if (command == IMAGE_INTERFACE_INFO)
		{
			usart_puts("Flasher | ver 001");
			usart_putc(0);
		}
		else if (command == IMAGE_INTERFACE_EXIT)
		{
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok
			bmp_init();
			arduinoRun(); 
			sei(); //enable interrupts

			keepGoing	=	FALSE;
			break;
		}
	
	}//end while
	
} //end function
Пример #29
0
//*******************************************************************************
//*		This is where we get the chunks of data 
//*		to program to the dataflash
//*******************************************************************************
void image_interface_begin(void)
{
unsigned int	page_count	=	0;
unsigned char	command		=	0;
unsigned char	*buff;
unsigned int	page_num	=	0;
boolean			keepGoing;
#ifdef _TOUCH_STEALTH_
COLOR			black 		=	{0,0,0};
COLOR			white		=	{255,255,255};
#endif

	/*
		order of operations:
			1.) purge usart buffers
			2.) recv mode byte
			3.) if mode == STORE,
					recv page_count 
					recv all pages
				else mode == READ
					send page_count
					send pages
	*/

#ifdef _USE_DBBUG_RECT_STATUS_
	DebugRectPrintText("image_interface_begin()");
#endif


	arduinoReset();
	usart_init(115200);
//	usart_init(57600);

#ifdef _USE_DBBUG_RECT_STATUS_
	DebugRectPrintText("usart_init 115200");
#endif


#ifdef _USE_DBBUG_RECT_STATUS_
	DebugRectPrintText("arduino in reset");
#endif

	cli();

	buff	=	usart_getBuff_ptr();

	//enough setup, lets begin
	keepGoing	=	TRUE;
	while(keepGoing)
	{
		usart_read_bytes(1); //	Wait for us to read a byte
		command	=	buff[0]; //	store or read command

#ifdef _TOUCH_STEALTH_
		if (command == IMAGE_INTERFACE_ERASE)
		{
			dispPutS("Erasing",0,0,white,black);
			dataflash_erase();
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok
			dispPutS("Erasing Done",0,10,white,black);
		}
		else
#endif
		if (command == IMAGE_INTERFACE_STORE)
		{
		unsigned int	x;
		unsigned int	ii,wait,wait2;
		unsigned char	out_data[DATAFLASH_PAGESIZE],in_data[DATAFLASH_PAGESIZE];
		

		#ifdef _USE_DBBUG_RECT_STATUS_
			DebugRectPrintText("IMAGE_INTERFACE_STORE");
		#endif

			buff	=	usart_getBuff_ptr();
			
			dataflash_erase();
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //done erasing 

		#ifdef _USE_DBBUG_RECT_STATUS_
			DebugRectPrintText("done erasing ");
		#endif
			//give us the number of pages you're sending
			usart_read_bytes(2);
			page_count	=	(buff[0] << 8) + buff[1];  //number of pages			

			for (ii=0; ii< page_count; ii++)
			{
			unsigned int buffer_count	=	0;

			#ifdef _USE_DBBUG_RECT_STATUS_
			//	DebugRectPrintText("Page");
			#endif

				usart_read_bytes(DATAFLASH_PAGESIZE);	//read the whole page

				buffer_count	=	usart_getBuff_size();



				//program the whole page
				for(x=0;x<DATAFLASH_PAGESIZE;x++)
				{
					out_data[x]	=	buff[x];
				}
				dataflash_program_page(&out_data[0], ii); 	//program the page
            
            				
				for(x=0;x<DATAFLASH_PAGESIZE;x++)
					in_data[x]	=	0x00;
	         
 
				dataflash_cont_read(&in_data[0], ii, DATAFLASH_PAGESIZE);
   

				for (x=0;x<DATAFLASH_PAGESIZE;x++)
				{
					if (x==256)
					{
						for (wait = 0; wait < 254; wait++)
						{
							for (wait2 = 0; wait2 < 254; wait2++)
							{
								asm("nop");
							}
						}
					}
					usart_putc(in_data[x]);
					asm("nop");
				}
			}
		}
		else if (command == IMAGE_INTERFACE_READ)
		{
		unsigned int x;
		unsigned char out[DATAFLASH_PAGESIZE];


		#ifdef _USE_DBBUG_RECT_STATUS_
			DebugRectPrintText("IMAGE_INTERFACE_READ");
		#endif

			page_num=0;

			//give us the number of pages you're sending
			usart_read_bytes(2);
			page_num	=	(buff[0] << 8) + buff[1];  //number of pages
			

			dataflash_cont_read(&out[0], page_num, DATAFLASH_PAGESIZE);


			for (x=0; x<DATAFLASH_PAGESIZE; x++)
			{
				usart_putc(out[x]);
			}
			asm("nop");
		}
		else if (command == IMAGE_INTERFACE_INFO)
		{
		short	ii;
		char	validImage;
		short	bmpWidth;
		short	bmpHeight;
		char	displayLine[64];
		
			usart_puts("\nTouch Shield | ver 002\n");
			usart_putc(0);
			ii			=	0;
			validImage	=	TRUE;

			while (validImage && (ii < BMP_MAXBMP_COUNT))
			{
				bmp_get_entryname(ii, displayLine, &bmpWidth, &bmpHeight);
				usart_puts(displayLine);
				usart_puts("\n");
				ii++;
			}
			
		}
		else if (command == IMAGE_INTERFACE_EXIT)
		{
			usart_puts("Exit Command\n");

			sei(); //enable interrupts
			bmp_init();
			usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok
			arduinoRun();

			keepGoing	=	FALSE;
		//	break;
		}
	}//end while
	
} //end function
Пример #30
0
Файл: main.c Проект: degao/test
int main(void)
{
	struct image_info image;
	char *media_str = NULL;
	int ret;

	char filename[FILENAME_BUF_LEN];
	char of_filename[FILENAME_BUF_LEN];

	memset(&image, 0, sizeof(image));
	memset(filename, 0, FILENAME_BUF_LEN);
	memset(of_filename, 0, FILENAME_BUF_LEN);

	image.dest = (unsigned char *)JUMP_ADDR;
#ifdef CONFIG_OF_LIBFDT
	image.of = 1;
	image.of_dest = (unsigned char *)OF_ADDRESS;
#endif

#ifdef CONFIG_FLASH
	media_str = "FLASH: ";
	image.offset = IMG_ADDRESS;
#if !defined(CONFIG_LOAD_LINUX) && !defined(CONFIG_LOAD_ANDROID)
	image.length = IMG_SIZE;
#endif
#ifdef CONFIG_OF_LIBFDT
	image.of_offset = OF_OFFSET;
#endif
#endif

#ifdef CONFIG_NANDFLASH
	media_str = "NAND: ";
	image.offset = IMG_ADDRESS;
#if !defined(CONFIG_LOAD_LINUX) && !defined(CONFIG_LOAD_ANDROID)
	image.length = IMG_SIZE;
#endif
#ifdef CONFIG_OF_LIBFDT
	image.of_offset = OF_OFFSET;
#endif
#endif

#ifdef CONFIG_DATAFLASH
	media_str = "SF: ";
	image.offset = IMG_ADDRESS;
#if !defined(CONFIG_LOAD_LINUX) && !defined(CONFIG_LOAD_ANDROID)
	image.length = IMG_SIZE;
#endif
#ifdef CONFIG_OF_LIBFDT
	image.of_offset = OF_OFFSET;
#endif
#endif

#ifdef CONFIG_SDCARD
	media_str = "SD/MMC: ";
	image.filename = filename;
	strcpy(image.filename, IMAGE_NAME);
#ifdef CONFIG_OF_LIBFDT
	image.of_filename = of_filename;
#endif
#endif

#ifdef CONFIG_HW_INIT
	hw_init();
#endif

#if defined(CONFIG_SCLK)
#if !defined(CONFIG_SAMA5D4)
	slowclk_enable_osc32();
#endif
#endif

#ifdef CONFIG_HW_DISPLAY_BANNER
	display_banner();
#endif

#ifdef CONFIG_REDIRECT_ALL_INTS_AIC
	redirect_interrupts_to_nsaic();
#endif

#ifdef CONFIG_LOAD_HW_INFO
	/* Load board hw informaion */
	load_board_hw_info();
#endif

#ifdef CONFIG_PM
	at91_board_pm();
#endif

#ifdef CONFIG_DISABLE_ACT8865_I2C
	act8865_workaround();
#endif

	init_loadfunction();

#if defined(CONFIG_SECURE)
	image.dest -= sizeof(at91_secure_header_t);
#endif

	ret = (*load_image)(&image);

#if defined(CONFIG_SECURE)
	if (!ret)
		ret = secure_check(image.dest);
	image.dest += sizeof(at91_secure_header_t);
#endif

	if (media_str)
		usart_puts(media_str);

	if (ret == 0){
		usart_puts("Done to load image\n");
	}
	if (ret == -1) {
		usart_puts("Failed to load image\n");
		while(1);
	}
	if (ret == -2) {
		usart_puts("Success to recovery\n");
		while (1);
	}

#ifdef CONFIG_SCLK
	slowclk_switch_osc32();
#endif

#if defined(CONFIG_ENTER_NWD)
	switch_normal_world();

	/* point never reached with TZ support */
#endif

	return JUMP_ADDR;
}