Пример #1
0
struct port *__libnet_internal__serial_open(int portnum)
{
    struct port *p;
    int uart, baudrate, cfg;
    
    if ((portnum < 0) || (portnum >= MAX_PORT))
	return NULL;

    p = port_table[portnum];
    memset(p, 0, sizeof *p);

    if (config[portnum].baseaddr == -1) {
	dosmemget(0x400 + portnum * 2, 2, &p->baseaddr);
	if (p->baseaddr == 0)
	    p->baseaddr = fallback_baseaddr[portnum];
    }
    else {
	p->baseaddr = config[portnum].baseaddr;
    }

    uart = detect_uart(p->baseaddr);
    if (!uart)
	return NULL;

    if (uart == UART_16550A)
	enable_fifo(p);
    else 
	disable_fifo(p);

    install_isr(portnum, p, config[portnum].irq);

    set_config(p->baseaddr, config[portnum].baudrate, 
	       (config[portnum].bits 
		| config[portnum].parity 
		| config[portnum].stopbits));

    return p;
}
Пример #2
0
_mqx_int gpio_cpu_open
   (
      /* [IN] the file handle for the device */
      MQX_FILE_PTR fd_ptr,

      /* [IN] the file name */
      char_ptr   file_name,

      /* [IN] pointer to parameters */
      char_ptr   param_ptr
   )
{ /* Body */
    GPIO_DEV_DATA_PTR dev_data_ptr = (GPIO_DEV_DATA_PTR) fd_ptr->DEV_DATA_PTR;
 
    /* if file_name is used, then the user wants to open peripheral */
    if ((file_name != NULL) && (*file_name != 0)) {
        if (!strncmp(file_name, "gpio:write", 11))  /* user wants write access to GPIO */
            dev_data_ptr->type = DEV_OUTPUT;
        else if (!strncmp(file_name, "gpio:output", 12))  /* user wants write access to GPIO */
            dev_data_ptr->type = DEV_OUTPUT;
        else if (!strncmp(file_name, "gpio:read", 10)) /* user wants read access to GPIO */
            dev_data_ptr->type = DEV_INPUT;
        else if (!strncmp(file_name, "gpio:input", 11)) /* user wants read access to GPIO */
            dev_data_ptr->type = DEV_INPUT;
        else
        /* peripherals not used yet */
            return IO_ERROR;
    }
    else
        return IO_ERROR;
    
    /* install interrupt service routine */
    if( IO_OK != install_isr( fd_ptr ) )
    {
        return IO_ERROR;  
    }
    
    /* set pins status before selecting GPIO function */
    if ((param_ptr != NULL) && (dev_data_ptr->type == DEV_OUTPUT)) { 
        /* note that this is similar to GPIO_IOCTL_WRITE function, but no checking 
        ** is performed (was done in io_gpio_open function) */
        GPIO_PIN_STRUCT _PTR_  pin_table;
        uint_32        addr;
        uint_8         pin;
        GPIO_PIN_MAP   temp_pin0_map = {0};
        GPIO_PIN_MAP   temp_pin1_map = {0};
        
        /* prepare pin map */
        for (pin_table = (GPIO_PIN_STRUCT _PTR_) param_ptr; *pin_table != GPIO_LIST_END; pin_table++) {
            /* prepare address of port */
            addr = GPIO_GET_PORT(*pin_table);  
            /* prepare bit mask */
            pin = GPIO_GET_BIT_MASK( *pin_table );  
            if (*pin_table & GPIO_PIN_STATUS)
                temp_pin1_map.memory32[addr] |= pin;
            else
                temp_pin0_map.memory32[addr] |= pin;
        }
        /* ok, now we can apply new map */
        /* note: applying the map after collecting pins is due to have pins applied in one instruction */
        GPIOA_PSOR = temp_pin1_map.memory32[0];
        GPIOA_PCOR = temp_pin0_map.memory32[0];
        GPIOB_PSOR = temp_pin1_map.memory32[1];
        GPIOB_PCOR = temp_pin0_map.memory32[1];
        GPIOC_PSOR = temp_pin1_map.memory32[2];
        GPIOC_PCOR = temp_pin0_map.memory32[2];
        GPIOD_PSOR = temp_pin1_map.memory32[3];
        GPIOD_PCOR = temp_pin0_map.memory32[3];
        GPIOE_PSOR = temp_pin1_map.memory32[4];
        GPIOE_PCOR = temp_pin0_map.memory32[4];
 
    }

    gpio_cpu_configure(dev_data_ptr);
    return IO_OK;
} /* Endbody */