int main(){ WDTCTL = WDTPW | WDTHOLD; clock_config(); serial_config(); serial_print_string("ASCII TABLE:\n"); char strVal[4]; for(char i = ' '; i < 127; i++){ itoa(i, strVal, 10); serial_print_string(strVal); serial_print_string(": "); serial_print_byte((char)i); serial_print_byte('\n'); } serial_print_byte('\n'); __enable_interrupt(); __bis_SR_register(LPM4_bits); return 0; }
/* Serial control functions */ serial_status_t serial_open(configuration_t *config, serial_h *connection) { HANDLE hComm ; configuration_t lconfig = *config ; hComm = CreateFile(lconfig.comport, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, /* File flags */ 0); if (hComm == INVALID_HANDLE_VALUE) return SERIAL_ERROR ; if ( !SetCommMask(hComm, EV_TXEMPTY) ) { printf("Can't set communications mask\n") ; } *connection = (serial_h)hComm ; lconfig.baudrate = XFER_B1200 ; return serial_config((serial_h)hComm, &lconfig) ; }
static int serial_probe(struct pcmcia_device *p_dev) { struct serial_info *info; dev_link_t *link; DEBUG(0, "serial_attach()\n"); /* Create new serial device */ info = kmalloc(sizeof (*info), GFP_KERNEL); if (!info) return -ENOMEM; memset(info, 0, sizeof (*info)); link = &info->link; link->priv = info; link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; link->io.NumPorts1 = 8; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->conf.Attributes = CONF_ENABLE_IRQ; if (do_sound) { link->conf.Attributes |= CONF_ENABLE_SPKR; link->conf.Status = CCSR_AUDIO_ENA; } link->conf.IntType = INT_MEMORY_AND_IO; link->handle = p_dev; p_dev->instance = link; link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; serial_config(link); return 0; }
static int serial_probe(struct pcmcia_device *link) { struct serial_info *info; DEBUG(0, "serial_attach()\n"); /* Create new serial device */ info = kmalloc(sizeof (*info), GFP_KERNEL); if (!info) return -ENOMEM; memset(info, 0, sizeof (*info)); info->p_dev = link; link->priv = info; link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; link->io.NumPorts1 = 8; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->conf.Attributes = CONF_ENABLE_IRQ; if (do_sound) { link->conf.Attributes |= CONF_ENABLE_SPKR; link->conf.Status = CCSR_AUDIO_ENA; } link->conf.IntType = INT_MEMORY_AND_IO; return serial_config(link); }
void initBluetoothCom() { fd=open_port(); //fcntl(fd, F_SETFL|O_NONBLOCK, 0); fcntl(fd, F_SETFL, 0); //fcntl(fd, F_SETFL|O_NDELAY, 0); serial_config(fd); }
static void init_serial_port(char *devname, int iobase, int irq, struct unit *unit) { struct serial_port *sp; dev_t devno; sp = (struct serial_port *) kmalloc(sizeof(struct serial_port)); memset(sp, 0, sizeof(struct serial_port)); sp->iobase = iobase; sp->irq = irq; sp->cfg.speed = 115200; sp->cfg.databits = 8; sp->cfg.parity = PARITY_NONE; sp->cfg.stopbits = 1; sp->cfg.rx_timeout = INFINITE; sp->cfg.tx_timeout = INFINITE; init_dpc(&sp->dpc); sp->dpc.flags |= DPC_NORAND; init_event(&sp->event, 0, 0); init_sem(&sp->tx_sem, QUEUE_SIZE); init_mutex(&sp->tx_lock, 0); init_sem(&sp->rx_sem, 0); init_mutex(&sp->rx_lock, 0); // Disable interrupts outp(sp->iobase + UART_IER, 0); // Determine UART type check_uart_type(sp); // Set baudrate, parity, databits and stopbits serial_config(sp); // Enable FIFO if (sp->type == UART_16550A) { outp(sp->iobase + UART_FCR, FCR_ENABLE | FCR_RCV_RST | FCR_XMT_RST | FCR_TRIGGER_14); } // Turn on DTR, RTS and OUT2 sp->mcr = MCR_DTR | MCR_RTS | MCR_IENABLE; outp(sp->iobase + UART_MCR, sp->mcr); // Create device devno = dev_make(devname, &serial_driver, unit, sp); // Enable interrupts register_interrupt(&sp->intr, IRQ2INTR(sp->irq), serial_handler, sp); enable_irq(sp->irq); outp((unsigned short) (sp->iobase + UART_IER), IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); kprintf(KERN_INFO "%s: %s iobase 0x%x irq %d\n", device(devno)->name, uart_name[sp->type], sp->iobase, sp->irq); }
/*connect the rfid*/ void UhfRfidReader::uhfReaderConnect() { fd = serial_open(0); if(-1 == fd) { perror("UART open error!Please check.\n"); exit (-1); } serial_config(fd, B115200, SERIAL_8N1); FD_ZERO(&set_input); FD_SET(fd, &set_input); }
BOOL serial_init(void) { if (hComm == INVALID_HANDLE_VALUE) { hComm = CreateFile(CommDevice, GENERIC_READ | GENERIC_WRITE, 0, // comm devices must be opened w/exclusive-access NULL, // no security attributes OPEN_EXISTING, // comm devices must use OPEN_EXISTING 0, // not overlapped I/O NULL // hTemplate must be NULL for comm devices ); if (hComm == INVALID_HANDLE_VALUE) { printf("Failed to open comm. port '%s' (%d)\n", CommDevice, GetLastError()); return FALSE; } } if (!serial_config()) { printf("Failed to configure the comm. port '%s' (%d)\n", CommDevice, GetLastError()); return FALSE; } if (hThread == INVALID_HANDLE_VALUE) { DWORD dwId; hThread = CreateThread(NULL, 0, serial_receive_thread, NULL, 0, &dwId); if (hThread == INVALID_HANDLE_VALUE) { printf("Failed to create a thread to simulate the RX ISR (%d)\n", GetLastError()); return FALSE; } } return TRUE; }
extern void gps_init(void) { serial_init(); serial_config(); //Write commands }
static int serial_ioctl(struct dev *dev, int cmd, void *args, size_t size) { struct serial_port *sp = (struct serial_port *) dev->privdata; struct serial_status *ss; switch (cmd) { case IOCTL_GETDEVSIZE: return 0; case IOCTL_GETBLKSIZE: return 1; case IOCTL_SERIAL_SETCONFIG: if (!args || size != sizeof(struct serial_config)) return -EINVAL; memcpy(&sp->cfg, args, sizeof(struct serial_config)); serial_config(sp); return 0; case IOCTL_SERIAL_GETCONFIG: if (!args || size != sizeof(struct serial_config)) return -EINVAL; memcpy(args, &sp->cfg, sizeof(struct serial_config)); return 0; case IOCTL_SERIAL_WAITEVENT: if (!args && size == 0) { return wait_for_object(&sp->event, INFINITE); } else if (args && size == 4) { return wait_for_object(&sp->event, *(unsigned int *) args); } else { return -EINVAL; } case IOCTL_SERIAL_STAT: if (!args || size != sizeof(struct serial_status)) return -EINVAL; ss = (struct serial_status *) args; ss->linestatus = sp->linestatus; sp->linestatus = 0; ss->modemstatus = inp((unsigned short) (sp->iobase + UART_MSR)) & 0xFF; ss->rx_queue_size = sp->rxq.count; ss->tx_queue_size = sp->txq.count; return 0; case IOCTL_SERIAL_DTR: if (!args || size != 4) return -EINVAL; if (*(int *) args) { sp->mcr |= MCR_DTR; } else { sp->mcr &= ~MCR_DTR; } outp(sp->iobase + UART_MCR, sp->mcr); return 0; case IOCTL_SERIAL_RTS: if (!args || size != 4) return -EINVAL; if (*(int *) args) { sp->mcr |= MCR_RTS; } else { sp->mcr &= ~MCR_RTS; } outp(sp->iobase + UART_MCR, sp->mcr); return 0; case IOCTL_SERIAL_FLUSH_TX_BUFFER: cli(); fifo_clear(&sp->txq); set_sem(&sp->tx_sem, QUEUE_SIZE); sp->tx_queue_rel = 0; if (sp->type == UART_16550A) outp(sp->iobase + UART_FCR, FCR_ENABLE | FCR_XMT_RST | FCR_TRIGGER_14); sti(); return 0; case IOCTL_SERIAL_FLUSH_RX_BUFFER: cli(); fifo_clear(&sp->rxq); set_sem(&sp->rx_sem, 0); sp->rx_queue_rel = 0; if (sp->type == UART_16550A) outp(sp->iobase + UART_FCR, FCR_ENABLE | FCR_RCV_RST | FCR_TRIGGER_14); sti(); return 0; } return -ENOSYS; }