Ejemplo n.º 1
0
/**
 * @brief   Low level serial driver configuration and (re)start.
 *
 * @param[in] sdp       pointer to a @p SerialDriver object
 * @param[in] config    the architecture-dependent serial driver configuration.
 *                      If this parameter is set to @p NULL then a default
 *                      configuration is used.
 *
 * @notapi
 */
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {

  if (config == NULL)
    config = &default_config;

  osalDbgAssert(
      (config->rx_pad < TOTAL_GPIO_PADS) || (config->tx_pad < TOTAL_GPIO_PADS),
      "must configure at least an RX or TX pad");

  if (sdp->state == SD_STOP) {

#if NRF51_SERIAL_USE_UART0 == TRUE
    if (sdp == &SD1) {
      configure_uart(config);

      // Enable UART interrupt
      NRF_UART0->INTENCLR = (uint32_t)-1;
      NRF_UART0->INTENSET = UART_INTENSET_ERROR_Msk;
      if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED)
          NRF_UART0->INTENSET |= UART_INTENSET_RXDRDY_Msk;
      if (config->tx_pad != NRF51_SERIAL_PAD_DISCONNECTED)
          NRF_UART0->INTENSET |= UART_INTENSET_TXDRDY_Msk;

      nvicEnableVector(UART0_IRQn, NRF51_SERIAL_UART0_PRIORITY);

      if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED)
        NRF_UART0->TASKS_STARTRX = 1;
    }
#endif

  }
}
Ejemplo n.º 2
0
static void __init setup_early_console(char port, int baud)
{
	if (configure_uart_pins(port))
		return;

	console_port = port;
	configure_uart(console_port, baud);
}
Ejemplo n.º 3
0
void gsm_configure_serial()
{
    uart_parameters params_uart1;

    //TODO: Clock enter high-speed mode

    peripheral_enable(kUART1Module);

    params_uart1.baud = 115200;
    params_uart1.hw_flowcontrol = 0;
    params_uart1.parity = NoParity;
    configure_uart( U1, &params_uart1 );
}
Ejemplo n.º 4
0
/**
 * @brief   Low level serial driver configuration and (re)start.
 *
 * @param[in] sdp       pointer to a @p SerialDriver object
 * @param[in] config    the architecture-dependent serial driver configuration.
 *                      If this parameter is set to @p NULL then a default
 *                      configuration is used.
 *
 * @notapi
 */
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {

  if (config == NULL)
    config = &default_config;

  if (sdp->state == SD_STOP) {
    /* Enables the peripheral.*/

#if KINETIS_SERIAL_USE_UART0
    if (sdp == &SD1) {
      SIM->SCGC4 |= SIM_SCGC4_UART0;
      configure_uart(sdp->uart, config);
      nvicEnableVector(UART0Status_IRQn, KINETIS_SERIAL_UART0_PRIORITY);
    }
#endif /* KINETIS_SERIAL_USE_UART0 */

#if KINETIS_SERIAL_USE_UART1
    if (sdp == &SD2) {
      SIM->SCGC4 |= SIM_SCGC4_UART1;
      configure_uart(sdp->uart, config);
      nvicEnableVector(UART1Status_IRQn, KINETIS_SERIAL_UART1_PRIORITY);
    }
#endif /* KINETIS_SERIAL_USE_UART1 */

#if KINETIS_SERIAL_USE_UART2
    if (sdp == &SD3) {
      SIM->SCGC4 |= SIM_SCGC4_UART2;
      configure_uart(sdp->uart, config);
      nvicEnableVector(UART2Status_IRQn, KINETIS_SERIAL_UART2_PRIORITY);
    }
#endif /* KINETIS_SERIAL_USE_UART2 */

  }
  /* Configures the peripheral.*/

}
Ejemplo n.º 5
0
int main()
{
    configure_pinout();
    configure_oscillator();
    configure_uart();



    /*Initialize Timer 1 for Period Interrupts*/

    Init_Timer1();
    
    U1TXREG = 'a'; // Transmit one character

	while(1)
	{

	}
}
/// \cond
int main(int argc, char **argv)
{
    int fd;
    char *s;
    unsigned char ope_code;
    unsigned char prev_code;
    unsigned char data_size;
    unsigned char prev_size;
    int len;
    int baud;
    char ret;
    
    printf("bcm2835_for_java ver1.01 start priority=%d\n", nice(1) );
    if( argc != 2 )
    {
        printf("bcm2835_for_java needs 1 parameter like as /tmp/shared_mem\n");
      exit ( -1 );
    }
    else
    {
      fd = open( argv[1], O_RDWR);
      if( fd == -1 )
      {
        printf("file %s can't open\n",argv[1]);
        exit(-1);
      }
      else
      {
         s = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
         if( s == MAP_FAILED )
         {
            printf("we can't create mapping file\n");
         }
      }
    }

  
    r_buff = (struct ring_buff *)s;
    w_buff = (struct ring_buff *)(s+sizeof(struct ring_buff) );
    bi_send_buff = (char *)( s + 2*sizeof(struct ring_buff) );
    bi_rec_buff = (char *)( bi_send_buff + TEMP_BUFF_SIZE );
    sync_code = (int *)( bi_rec_buff + TEMP_BUFF_SIZE );
    reply_code = (int *)( sync_code + 1 );
    
    init_ring_buff(w_buff,WRITER_INIT);
    init_ring_buff(r_buff,READER_INIT);
    
    bi_status = STATUS_FINE;
    
    while( 1 )
    {
        if( calc_data_size( r_buff ) != 0 )
        {
          prev_code = ope_code;
          prev_size = data_size;
          get_ope_code();
          ope_code = buff[0];
          data_size = calc_data_size( r_buff );
          switch( ope_code )
            {
                case OPE_INIT:
                    bcm_init();
                    break;
                case OPE_CLOSE:
                    bcm_close();
                    break;
                case OPE_SET_DEBUG:
                    ope_set_debug();
                    break;
                case OPE_PERI_READ:
                    ope_peri_read();
                    break;
                case OPE_PERI_READ_NB:
                    ope_peri_read_nb();
                    break;
                case OPE_PERI_WRITE:
                    ope_peri_write();
                    break;
                case OPE_PERI_WRITE_NB:
                    ope_peri_write_nb();
                    break;
                case OPE_PERI_SET_BITS:
                    ope_peri_set_bits();
                    break;
                case OPE_GPIO_FSEL:
                    ope_gpio_fsel();
                    break;
                case OPE_GPIO_SET:
                    ope_gpio_set();
                    break;
                case OPE_GPIO_CLR:
                    ope_gpio_clr();
                    break;
                case OPE_GPIO_SET_MULTI:
                    ope_gpio_set_multi();
                    break;
                case OPE_GPIO_CLR_MULTI:
                    ope_gpio_clr_multi();
                    break;
                case OPE_GPIO_LEV:
                    ope_gpio_lev();
                    break;
                case OPE_GPIO_EDS:
                    ope_gpio_eds();
                    break;
                case OPE_GPIO_SET_EDS:
                    ope_gpio_set_eds();
                    break;
                case OPE_GPIO_REN:
                    ope_gpio_ren();
                    break;
                case OPE_GPIO_CLR_REN:
                    ope_gpio_clr_ren();
                    break;
                case OPE_GPIO_FEN:
                    ope_gpio_fen();
                    break;
                case OPE_GPIO_CLR_FEN:
                    ope_gpio_clr_fen();
                    break;
                case OPE_GPIO_HEN:
                    ope_gpio_hen();
                    break;
                case OPE_GPIO_CLR_HEN:
                    ope_gpio_clr_hen();
                    break;
                case OPE_GPIO_LEN:
                    ope_gpio_len();
                    break;
                case OPE_GPIO_CLR_LEN:
                    ope_gpio_clr_len();
                    break;
                case OPE_GPIO_AREN:
                    ope_gpio_aren();
                    break;
                case OPE_GPIO_CLR_AREN:
                    ope_gpio_clr_aren();
                    break;
                case OPE_GPIO_AFEN:
                    ope_gpio_afen();
                    break;
                case OPE_GPIO_CLR_AFEN:
                    ope_gpio_clr_afen();
                    break;
                case OPE_GPIO_PUD:
                    ope_gpio_pud();
                    break;
                case OPE_GPIO_PUDCLK:
                    ope_gpio_pudclk();
                    break;
                case OPE_GPIO_WRITE:
                    ope_gpio_write();
                    break;
                case OPE_GPIO_PAD:
                    ope_gpio_pad();
                    break;
                case OPE_GPIO_SET_PAD:
                    ope_gpio_set_pad();
                    break;
                case OPE_DELAY:
                    ope_delay();
                    break;
                case OPE_DELAYMICROSECONDS:
                    ope_delaymicroseconds();
                    break;
                case OPE_GPIO_WRITE_MULTI:
                    ope_gpio_write_multi();
                    break;
                case OPE_GPIO_WRITE_MASK:
                    ope_gpio_write_mask();
                    break;
                case OPE_GPIO_SET_PUD:
                    ope_gpio_set_pud();
                    break;
                case OPE_SPI_BEGIN:
                    ope_spi_begin();
                    break;
                case OPE_SPI_END:
                    ope_spi_end();
                    break;
                case OPE_SPI_SETBITORDER:
                    ope_spi_setbitorder();
                    break;
                case OPE_SPI_SETCLOCKDIVIDER:
                    ope_spi_setclockdivider();
                    break;
                case OPE_SPI_SETDATAMODE:
                    ope_spi_setdatamode();
                    break;
                case OPE_SPI_CHIPSELECT:
                    ope_spi_chipselect();
                    break;
                case OPE_SPI_SETCHIPSELECTPOLARITY:
                    ope_spi_setchipselectpolarity();
                    break;
                case OPE_SPI_TRANSFER:
                    ope_spi_transfer();
                    break;
                case OPE_SPI_TRANSFERNB:
                    ope_spi_transfernb();
                    break;
                case OPE_SPI_TRANSFERN:
                    ope_spi_transfern();
                    break;
                case OPE_SPI_WRITENB:
                    ope_spi_writenb();
                    break;
                case OPE_I2C_BEGIN:
                    ope_i2c_begin();
                    break;
                case OPE_I2C_END:
                    ope_i2c_end();
                    break;
                case OPE_I2C_SETSLAVEADDRESS:
                    ope_i2c_setslaveaddress();
                    break;
                case OPE_I2C_SETCLOCKDIVIDER:
                    ope_i2c_setclockdivider();
                    break;
                case OPE_I2C_SET_BAUDRATE:
                    ope_i2c_set_baudrate();
                    break;
                case OPE_I2C_WRITE:
                    ope_i2c_write();
                    break;
                case OPE_I2C_READ:
                    ope_i2c_read();
                    break;
                case OPE_I2C_READ_REGISTER_RS:
                    ope_i2c_read_register_rs();
                    break;
                case OPE_ST_READ:
                    ope_st_read();
                    break;
                case OPE_ST_DELAY:
                    ope_st_delay();
                    break;
                case OPE_HELLO:
                    get_int_code();
                    len = *(int *)(buff+1);
                    set_ope_code( OPE_REPLY );
                    strcpy( bi_rec_buff, "Nice to meet you." );
                    set_int_code( strlen(bi_rec_buff) );
                    put_reply();
                    mark_sync();
                    usleep(5000);
                    break;
                case OPE_SYNC:
                    mark_sync();
                    break;
                case OPE_EXIT:
                    goto BREAK_LINE;
                    break;
                case OPE_OPEN_UART:
                    open_uart();
                    break;
                case OPE_CONFIG_UART:
                    configure_uart();
                    break;
                case OPE_SEND_UART:
                    send_uart();
                    break;
                case OPE_RECEIVE_UART:
                    receive_uart();
                    break;
                case OPE_CLOSE_UART:
                    close_uart();
                    break;
            default:
              printf("prev_code %02x \n",prev_code);
              printf("prev_size %d \n",prev_size);
              printf("ope_code error %02x \n",ope_code);
              printf("data_size=%d \n",data_size);
              break;
            }
        }
        else
        {
            usleep(5000);
        }
    }
BREAK_LINE:
    printf("Close bcm2835_for_java\n");
    exit(0);
}
Ejemplo n.º 7
0
int main(void)
{
    /* Initialize the SAM system */
    SystemInit();

	/* Initialize pins */
	Pin_Configuration();
	/* Initialize PWM generator */
	InitPWMController_MCLK(); 
	/* Initialize timers */
	Configure_Timers();
	
	InitMotors();
	
	/* Configre UART */
	configure_uart();
	
	sendString("###ON \n", 7);
	sendString("###Initializing\n", 16);
	
	
	
	/* Disable watchdog */
	WDT->WDT_MR |=  WDT_MR_WDDIS;

	//selfTest();
	
	// Set variables 
	initializeMotors = 0;
	flag12 = 0;
	
	// ----- TASK_1
	#if defined(TASK_1)
		while (1)
		{			
			if(getNewSpeed())
			{
				sendString("###New Speed\n", 14);
				newSpeed = 0;
				ControlledDrive(percentage_ST,percentage_DR);
				flag12 = 0;
			}
		}
		
	// ----- TASK_2
	#elif defined(TASK_2)
	
		while (1)
		{
			
			
		}
	
	// ----- TASK_3
	#elif defined(TASK_3)
		
		startStop_Camera = 0;
		
		while (1)
		{
			if(initializeMotors)
			{
				sendString("###Initializing\n", 16);
				InitMotors();
				initializeMotors = 0;
			}

			if(startStop_Camera)
			{ // Stop motors and ignore lidar values 
				WriteMotors(0,0);
			}
			else
			{ // Start and go based on lidar values
				
				if(getNewSpeed())
				{
					sendString("###New Speed\n", 14);
					newSpeed = 0;
					ControlledDrive(percentage_ST,percentage_DR);
					flag12 = 0;
				}
				
				//ForwardDrive();
			}
		}
	
	// ----- TASK_4
	#elif defined(TASK_4)
	
		while (1)
		{
			
		}	
	
	#endif

}