예제 #1
0
Uart0::Error Uart0::open() {
  if (is_open())
    return kPortAlreadyOpen;

  /* Initializes the Buffers */
  in_buffer_.create("Uart0 Rx Buffer", kBufferSize);
  out_buffer_.create("Uart0 Tx Buffer", kBufferSize);

  /* Enable the UART0 peripheral. */
  MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK);

  /* Configure Pins. */
  Error pins_ok = init_pins();
  if (pins_ok != kOK)
    return pins_ok;

  /* Configure UART. */
  Error uart_ok = config_uart();
  if (uart_ok != kOK)
    return uart_ok;

  /* Change the status */
  open_ = true;

  g_uart0_object = this;
  return kOK;
}
예제 #2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
	if ( rtl_cryptoEngine_init() != 0 ) {
		DiagPrintf("crypto engine init failed\r\n");
	}

	/* Initialize log uart and at command service */
	console_init();	

	/* pre-processor of application example */
	pre_example_entry();

	/* wlan intialization */
#if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK)
	wlan_network();
#endif

	// setup uart with capability of wakeup system
	config_uart();

	// setup log uart with capability of wakeup system
	config_loguart();

	// By default tickless is disabled because WAKELOCK_OS is locked.
	// Release this wakelock to enable tickless
	release_wakelock(WAKELOCK_OS);

	// Register pre/post sleep callback. They are called when system automatically enter/leave sleep.
	register_pre_sleep_callback(pre_sleep_process_callback);
	register_post_sleep_callback(post_sleep_process_callback);

	/* Execute application example */
	example_entry();

    	/*Enable Schedule, Start Kernel*/
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
	#ifdef PLATFORM_FREERTOS
	vTaskStartScheduler();
	#endif
#else
	RtlConsolTaskRom(NULL);
#endif
}
예제 #3
0
int main(void)
{
	uint8_t vetor[TAMANHO+1];
	uint8_t uc_key;
	uint8_t rtn;

	/* Initialize the system */
	sysclk_init();
	board_init();


	/* Initialize debug console */
	config_uart();

	/* Initialize_tc */
	configure_tc();

	/* Initialize Led */
	config_led();
	
	/* frase de boas vindas */
	puts(" ---------------------------- \n\r"
	 	 " Bem vindo terraquio !		\n\r"
		 " ---------------------------- \n\r");
		 
	/* display main menu */
	display_menu();
	
	/* init var */
	vetor[TAMANHO] = STRING_NULL;
	
	while (1) {

		while(!g_UartStrgOk){ 
			pmc_sleep(SAM_PM_SMODE_SLEEP_WFI);
		};

		//rtn = readvec(&vetor[0]);
	
			if (strcmp(g_UartStrg, "LGON") == 0)
			{
				pio_clear(PORT_LED_GREEN, MASK_LED_GREEN);
				puts("Led ON \n\r");
			}
			else if (strcmp(g_UartStrg, "LBPISCA") == 0)
			{
			flagB = 1;	
			puts("Pisca LED azul \n\r");	
			}
			else if (strcmp(g_UartStrg, "LGPISCA") == 0)
			{
				flagG = 2;
			}
			else if (strcmp(g_UartStrg, "LBON") == 0)
			{
				pio_clear(PORT_LED_BLUE, MASK_LED_BLUE);
				puts("Led ON \n\r");
			}
			else if (strcmp(g_UartStrg, "LRON") == 0)
			{
				pio_set(PORT_LED_RED, MASK_LED_RED);
				puts("Led ON \n\r");
			}
			else if (strcmp(g_UartStrg, "LGOFF") == 0)
			{
			pio_set(PORT_LED_GREEN, MASK_LED_GREEN);
			puts("Led OFF \n\r");	
			flagG = 0 ;
			}
			else if (strcmp(g_UartStrg, "LBOFF") == 0)
			{
				pio_set(PORT_LED_BLUE, MASK_LED_BLUE);
				puts("Led OFF \n\r");
				flagB = 0;
			}
			else if (strcmp(g_UartStrg, "LROFF") == 0)
			{
				pio_clear(PORT_LED_RED, MASK_LED_RED);
				puts("Led OFF \n\r");
			}
			else if (strcmp(g_UartStrg, "FREQ1") == 0)
			{
				tc_write_rc(TC0,0,8000);
				puts("Frequencia 8000 \n\r");
			}
			else if (strcmp(g_UartStrg, "FREQ2") == 0)
			{
				tc_write_rc(TC0,0,4000);
				puts("Frequencia 4000 \n\r");
			}
			else if (strcmp(g_UartStrg, "FREQ3") == 0)
			{
				tc_write_rc(TC0,0,2000);
				puts("Frequencia 2000 \n\r");
			}
			
			/* more else if clauses */
			else 
			{
				printf("[INFO] Opcao nao definida: %s \n\r", g_UartStrg);
			}

			//g_UartStrgAck = 1;
			limparvetor();

	}
}
예제 #4
0
파일: main.c 프로젝트: dciliske/projekts
int main(void)
{
	uint32_t i = 0;
	config_clocks();
    /* Write your code here */
	/* Enable Port B */
	SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
	SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
	SIM->SCGC4 |= 1 << 22;
	config_spi();

	PORTA_PCR8 |= PORT_PCR_MUX(3);
	PORTA_PCR9 |= PORT_PCR_MUX(3);
	GPIOA_PDDR |= (1 << SWD_CLK_PIN);// /*(1 << SWD_IO_PIN) |*/ (1 << 12);
	GPIOA_PCOR = 1 << SWD_CLK_PIN; // Make sure the clock is low when shifting to GPIO
#ifdef _DEBUG
	config_uart();
#endif
	/* Enable RED LED as GPIO */
	PORTB_PCR10 |= PORT_PCR_MUX(1);
	/* Set PTB10, PTB11 and PTB13 as outputs */
	GPIOB_PDDR |= 1 << 10;

	/* Turn off LEDs */
	GPIOB_PSOR = 1 << 10;

	uint32_t data = 0x12345678;
	uint8_t ret = 0;
	// Reset the bus and confirm the target is configured
	reset_and_power_debug();

	swd_write(false, DB_REG_SELECT, 0x01000000);
	swd_write(true, MDM_REG_CTL, 0x4);
	swd_read(true, MDM_REG_STAT, &data);
	swd_read(false, DB_REG_RD_BUFF, &data);
	swd_write(false, DB_REG_SELECT, 0x00);
	swd_write(true, AP_REG_CSW, 0x03000042);
	swd_read(true, AP_REG_CSW, &data);
	swd_read(false, DB_REG_RD_BUFF, &data);

	swd_write_mem((uint32_t)&(CoreDebug->DHCSR), 0xA05F0003);

	swd_write_array(SRAM_START,blink_code,blink_code_len);

	swd_write_reg(0xF,SRAM_START);
	swd_write_reg(0xE,SRAM_START+1);

	swd_write_mem((uint32_t)&(CoreDebug->DHCSR), 0xA05F0000);

//	takeover_and_inject();

    while(1){
    	/* Turn on RED LED */
    	GPIOB_PCOR = 1 << 10;
    	for(i = 0; i < delay; i++); /* delay */
    	/* Turn off RED LED */
    	GPIOB_PSOR = 1 << 10;
    	for(i = 0; i < delay; i++); /* delay */

//    	/* Turn on GREEN LED */
//    	GPIOB_PCOR = 1 << 11;
//    	for(i = 0; i < delay; i++); /* delay */
//    	/* Turn off GREEN LED */
//    	GPIOB_PSOR = 1 << 11;
//    	for(i = 0; i < delay; i++); /* delay */
//
//    	/* Turn on BLUE LED */
//    	GPIOB_PCOR = 1 << 13;
//    	for(i = 0; i < delay; i++); /* delay */
//    	/* Turn off BLUE LED */
//    	GPIOB_PSOR = 1 << 13;
//    	for(i = 0; i < delay; i++); /* delay */

////		ret = swd_write(true,AP_REG_DRW,0xFFFF);
////		ret = swd_read(false,DB_REG_CTRL_STAT,&data);
//    	swd_read(false,0x00,&data);
//    	data++;
    	if (!(GPIOB_PDIR & (1 << 5))) {
    		GPIOB_PCOR = 1 << 10 | 1 << 11 | 1 << 12;
        	for(i = 0; i < delay; i++); /* delay */

    		GPIOB_PSOR = 1 << 10 | 1 << 11 | 1 << 12;
        	for(i = 0; i < delay; i++); /* delay */
    	}
    }
    /* Never leave main */
    return 0;
}
예제 #5
0
int main(void)
{
	uint8_t uc_key;

	/* Initialize the system */
	sysclk_init();
	board_init();

	/* Configure LED 1 */
	pmc_enable_periph_clk(PIN_LED_BLUE_ID);
	pio_set_output(PIN_LED_BLUE_PIO , PIN_LED_BLUE_MASK, 1, 0, 0);

	/* Initialize debug console */
	config_uart();
	
	/* frase de boas vindas */
	puts(" ---------------------------- \n\r"
	 	 " Bem vindo terraquio !		\n\r"
		 " ---------------------------- \n\r");
	
	/* Enable peripheral clock */
	pmc_enable_periph_clk(ID_SMC);

	/** Configura o LEDs */
	configure_leds();

	/** Configura o timer */
	configure_tc();


	/* Configuração LCD */
	configure_lcd();
	
	desenhaCabecalho();
	
	/* display main menu */
	display_menu();

	while (1) {
		
		
		usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);	
		switch (uc_key) {
			case '1':
				display_menu();
				break;
			case '2':
				flagLED = 0;
				pio_clear(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Led ON \n\r");
				break;
			case '3' :
				flagLED = 1;
				pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Led OFF \n\r");
				break;
			case '4' :
				flagLED = 2;
				pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Led OFF \n\r");
				break;
			case '5' :
				flagLED = 3;
				pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Defina a o valor da Frequência (0-65356) \n\r");
				usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);
				//tc_write_rc(uc_key);
				break;
				
			default:
				printf("Opcao nao definida: %d \n\r", uc_key);
		}	
	}
}
예제 #6
0
파일: main.c 프로젝트: zearaujo25/Entregas
int main(void)
{
	uint8_t uc_key;

	/* Initialize the system */
	sysclk_init();
	board_init();

	/* Configure LED 1 */
	pmc_enable_periph_clk(ID_LED_BLUE);
	pio_set_output(PORT_LED_BLUE  , MASK_LED_BLUE	,1,0,0);

	/* Initialize debug console */
	config_uart();
	
	/* frase de boas vindas */
	puts(" ---------------------------- \n\r"
	 	 " Bem vindo Corsi  !		\n\r"
		 " ---------------------------- \n\r");
		 
	/* display main menu */
	display_menu();
	configure_tc();
	TC0_Handler();
	
	pio_clear(PORT_LED_RED, MASK_LED_RED);
	pio_set(PORT_LED_GREEN, MASK_LED_GREEN);
	
	PIOA->PIO_PER = (1 << PIN_LED_BLUE );
	PIOA->PIO_OER |=  (1 << PIN_LED_BLUE );
	
	
	PMC->PMC_PCER0 |= ID_PIOC;
	PIOC->PIO_PER |= (1 << PIN_LED_RED );
	PIOC->PIO_OER |=  (1 << PIN_LED_RED );
	
	
	tc_stop(TC0, 0);
	PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
	PIOC->PIO_CODR = (1 << PIN_LED_RED );
	
	while (1) {
		usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);	
		switch (uc_key) {
			case '1':
				display_menu();
				break;
			case '2':
				tc_start(TC0,0);
				PIOA->PIO_CODR = (1 << PIN_LED_BLUE );
				
				puts("Led BLUE ON \n\r");
				break;
			case '3' :
				tc_stop(TC0, 0);
				PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
				puts("Led BLUE OFF \n\r");
			
				break;
			case '4':
				tc_start(TC0,0);
				pio_clear(PORT_LED_GREEN, MASK_LED_GREEN);
				puts("Led GREEN ON \n\r");
				break;
			case '5' :
				tc_stop(TC0, 0);

				pio_set(PORT_LED_GREEN, MASK_LED_GREEN);
				puts("Led GREEN OFF \n\r");
				break;
			case '6':
					tc_start(TC0,0);
					PIOC->PIO_SODR = (1 << PIN_LED_RED );
				
				puts("Led RED ON \n\r");
			break;
			case '7' :
				tc_stop(TC0, 0);
				PIOC->PIO_CODR = (1 << PIN_LED_RED );
				puts("Led RED OFF \n\r");
			break;
			case '8' :
				
				tc_write_rc(TC0, 0, tc_read_rc(TC0,0) * 0.5);
				puts("aumentando \n\r");
				break;
			case '9' :
				
				tc_write_rc(TC0, 0, tc_read_rc(TC0,0) * 1.4);
				puts("diminuindo \n\r");
				break;				
			default:
				printf("Opcao nao definida: %d \n\r", uc_key);
		}	
	}
}
예제 #7
0
int main() {
	// enabled hard float, without it, we get a hardfaults
	SCB->CPACR |= (3UL << 20) | (3UL << 22); __DSB(); __ISB();

	config_uart(8, 6);

	LOGd("Test ADC in separate program");

	Timer::getInstance().init();
	
	//nrf_clock_lf_cfg_t _clock_source = defaultClockSource;

	//! Some apeshit 
//	SOFTDEVICE_HANDLER_APPSH_INIT(&_clock_source, true);
	
	LOGd("Run");

	int i = 1;

	uint32_t counter = 0;

	uint8_t switch_type;

	enum { WITHOUT_LOAD, WITH_LOAD };

	bool trigger_switch = false;
	uint32_t switch_counter = 0;

	// each increment of one corresponds with 0.2 msec, a typical switch might last 5 msec, so that would be a
	// switch_delay value of 25
	uint8_t switch_delay = 25;
	
	uint8_t index;

	uint32_t prev_value;

	while(1) {

		// Add a delay to control the speed of the sine wave
		// 200 microseconds times 100 samples is 20 milliseconds for the entire wave, which is 50 Hz.
		nrf_delay_us(200);

		// value will be overwritten in trigger_switch if necessary
		uint8_t value = sin_table[counter];

		if (i++ % 5304 == 0) {
			trigger_switch = true;
		}
		if (trigger_switch) {
			// Simulate switch event
			switch(switch_type) {
				case WITHOUT_LOAD: default: {
					// We keep the value at [counter - switch_counter]: it stays the same.
					index = (counter - 1 - switch_counter + sizeof(sin_table)) % sizeof(sin_table);
					value = sin_table[index];
				} break;
				case WITH_LOAD: {
					// We go slowly to the middle (255/2)
					uint8_t end_value = 255 >> 1;

					if (switch_counter == 0) {
						index = (counter - 1 - switch_counter + sizeof(sin_table)) % sizeof(sin_table);
						uint8_t start_value = sin_table[index];
						prev_value = start_value;
					}				
	
					// if v is starting point, e is endpoint (255 >> 1), then:
					// x=[v-e round((v-e)*0.8.^[1:19])]+e;
					// plot(1:length(x),x,'o')
					value = (prev_value - end_value) * 80/100 + end_value;

					///nrf_pwm_set_value(0, value);
					prev_value = value;
					
				} break;
			}
			if (switch_counter++ == switch_delay) {
				trigger_switch = false;
				switch_counter = 0;
			}
		} else {
			// Update sine wave with value as is
		}
		counter = (counter + 1) % 100;
//		nrf_pwm_set_value(0, value);
	}