📄 init.c
字号:
/* * $QNXLicenseC: * Copyright 2007, QNX Software Systems. * * Licensed under the Apache License, Version 2.0 (the "License"). You * may not reproduce, modify or distribute this software except in * compliance with the License. You may obtain a copy of the License * at: http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OF ANY KIND, either express or implied. * * This file may contain contributions from others, either as * contributors under the License or as licensors under other terms. * Please review this entire file for other proprietary rights or license * notices, as well as the QNX Development Suite License Guide at * http://licensing.qnx.com/license-guide/ for other information. * $ */#include "externs.h"#include <sys/mman.h>voidset_port(unsigned port, unsigned mask, unsigned data) { unsigned char c; c = read_8250(port); write_8250(port, (c & ~mask) | (data & mask));}static voidclear_device(const uintptr_t *port) { unsigned char tmp; write_8250(port[REG_IE], 0); // Disable all interrupts tmp = read_8250(port[REG_LS]); // Clear Line Status Interrupt tmp = read_8250(port[REG_RX]); // Clear RX Interrupt tmp = read_8250(port[REG_TX]); // Clear TX Interrupt tmp = read_8250(port[REG_MS]); // Clear Modem Interrupt}//// Clean up the device then add it to the interrupt list and enable it.//voidser_attach_intr(DEV_8250 *dev) { uintptr_t *port = dev->port; struct dev_list **owner; struct dev_list *curr; // According to the National bug sheet you must wait for the transmit // holding register to be empty. do { } while((read_8250(port[REG_LS]) & LSR_TXRDY) == 0); // Clean the device so we get a level change on the intr line to the bus. // Enable out2 (gate intr to bus) set_port(port[REG_MC], MCR_OUT2, MCR_OUT2); clear_device(port); // Add it to the interrupt list owner = &devices; for( ;; ) { curr = *owner; if(curr == NULL) { curr = _smalloc(sizeof(*curr)); *owner = curr; curr->next = NULL; curr->device = NULL; break; } if(curr->device->intr == dev->intr) break; owner = &curr->next; } // Delay interrupts while we're fiddling around with the list InterruptMask(dev->intr, -1); dev->next = curr->device; curr->device = dev; InterruptUnmask(dev->intr, -1); // If first handler, attach the interrupt. if(curr->device->next == NULL) { curr->iid = InterruptAttach(dev->intr, ser_intr, curr, 0, 0); } // Enable ALL interrupt sources. write_8250(port[REG_IE], 0x0f);}voidser_detach_intr(DEV_8250 *dev) { struct dev_list **list_owner; struct dev_list *list_curr; DEV_8250 **dev_owner; DEV_8250 *dev_curr; uintptr_t *port = dev->port; // Disable ALL interrupt sources write_8250(port[REG_IE], 0x00); // Disable interrupts set_port(port[REG_MC], MCR_OUT2, 0x00); // Disable out2 // // Remove from list of devices to scan on an interrupt. // // Find the right interrupt list list_owner = &devices; for( ;; ) { list_curr = *list_owner; if(list_curr->device->intr == dev->intr) break; list_owner = &list_curr->next; } // Find the right device on the list dev_owner = &list_curr->device; for( ;; ) { dev_curr = *dev_owner; if(dev_curr == dev) break; dev_owner = &dev_curr->next; } // Delay interrupts while we're fiddling around with the list InterruptMask(dev->intr, -1); *dev_owner = dev->next; // If no more handlers, detach the interrupt. if((*list_owner)->device == NULL) { InterruptDetach(list_curr->iid); *list_owner = list_curr; _sfree(list_curr, sizeof(*list_curr)); } clear_device(dev->port); InterruptUnmask(dev->intr, -1); dev->intr = _NTO_INTR_SPARE;}voidcreate_device(TTYINIT *dip, unsigned unit) { DEV_8250 *dev; unsigned i; uintptr_t port; unsigned char msr; // Get a device entry and the input/output buffers for it. dev = (void *) _smalloc(sizeof(*dev)); memset(dev, 0, sizeof(*dev)); // Get buffers. dev->tty.ibuf.head = dev->tty.ibuf.tail = dev->tty.ibuf.buff = _smalloc(dev->tty.ibuf.size = dip->isize); dev->tty.obuf.head = dev->tty.obuf.tail = dev->tty.obuf.buff = _smalloc(dev->tty.obuf.size = dip->osize); dev->tty.cbuf.head = dev->tty.cbuf.tail = dev->tty.cbuf.buff = _smalloc(dev->tty.cbuf.size = dip->csize); dev->tty.highwater = dev->tty.ibuf.size - (dev->tty.ibuf.size < 128 ? dev->tty.ibuf.size/4 : 32); strcpy(dev->tty.name, dip->name); dev->tty.baud = dip->baud; dev->tty.fifo = dip->fifo; // If TX fifo is set, set the XMIT override flag if(dev->tty.fifo & 0xF0) { dev->fifo_override = FIFO_XMIT_OVERRIDE; } port = mmap_device_io( (sizeof(dev->port)/sizeof(dev->port[0])) << dip->port_shift, dip->port); for(i = 0; i < sizeof(dev->port)/sizeof(dev->port[0]); ++i) { dev->port[i] = port; port += 1 << dip->port_shift; } dev->intr = dip->intr; dev->clk = dip->clk; dev->div = dip->div; dev->tty.flags = EDIT_INSERT | LOSES_TX_INTR; dev->tty.c_cflag = dip->c_cflag; dev->tty.c_iflag = dip->c_iflag; dev->tty.c_lflag = dip->c_lflag; dev->tty.c_oflag = dip->c_oflag; // Initialize termios cc codes to an ANSI terminal. ttc(TTC_INIT_CC, &dev->tty, 0); // Initialize the device's name. // Assume that the basename is set in device name. This will attach // to the path assigned by the unit number/minor number combination unit = SET_NAME_NUMBER(unit) | NUMBER_DEV_FROM_USER; ttc(TTC_INIT_TTYNAME, &dev->tty, unit); // Initialize power management structures before attaching ISR ttc(TTC_INIT_POWER, &dev->tty, 0); // Only setup IRQ handler for non-pcmcia devices. // Pcmcia devices will have this done later when card is inserted. if(dip->port != 0 && dip->intr != _NTO_INTR_SPARE) { ser_stty(dev); ser_attach_intr(dev); } // get current MSR stat msr = read_8250(dev->port[REG_MS]); if(msr & MSR_DDCD) tti(&dev->tty, (msr & MSR_DCD) ? TTI_CARRIER : TTI_HANGUP); if((msr & MSR_DCTS) && (dev->tty.c_cflag & OHFLOW)) tti(&dev->tty, (msr & MSR_CTS) ? TTI_OHW_CONT : TTI_OHW_STOP); // Attach the resource manager ttc(TTC_INIT_ATTACH, &dev->tty, 0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -