static void init(void) { /* Initialize debugging module (allow kprintf(), etc.) */ // kdbg_init(); /* Initialize system timer */ timer_init(); /* * XXX: Arduino has a single UART port that was previously * initialized for debugging purpose. * In order to activate the serial driver you should disable * the debugging module. */ /* Initialize UART0 */ ser_init(&serial, SER_UART0); /* Configure UART0 to work at 115.200 bps */ ser_setbaudrate(&serial, 115200); /* Enable all the interrupts now the basic stuff is initialised */ IRQ_ENABLE; // set clock up using last values from eeprom rtc_init(); // read a few more values out of eeprom and init the display etc load_eeprom_values(); ui_init(); measure_init(); control_init(); rpm_init(); graph_init(); log_init(); }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize LED driver */ LED_INIT(); ser_init(&ser_port, SER_UART2); ser_setbaudrate(&ser_port, 115200L); afsk_init(&afsk, 0, 0); // timer period = 24000000 hz /100/25 = 9600hz AD_Init(&afsk); AD_SetTimer(100, 25); AD_Start(); DA_Init(&afsk); DA_SetTimer(100, 25); kiss_init(&ser_port, &ax25, &afsk); ax25_init(&ax25, &afsk.fd, 1, ax25_message_callback); }
// Simple initialization function. static void init(void) { // Enable interrupts IRQ_ENABLE; // Initialize hardware timers timer_init(); // Initialize serial comms on UART0, // which is the hardware serial on arduino ser_init(&ser, SER_UART0); ser_setbaudrate(&ser, 9600); // For some reason BertOS sets the serial // to 7 bit characters by default. We set // it to 8 instead. UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); // Create a modem context afsk_init(&afsk, ADC_CH); // ... and a protocol context with the modem mp1Init(&mp1, &afsk.fd, mp1Callback); // That's all! }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize UART1 */ ser_init(&out, SER_UART1); /* Configure UART1 to work at 115.200 bps */ ser_setbaudrate(&out, 115200); /* Initialize LED driver */ LED_INIT(); /* Initialize the OLED display (RIT128x96) */ rit128x96_init(); /* Draw an empty Bitmap on the screen */ gfx_bitmapInit(&lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT); /* Refresh the display */ rit128x96_blitBitmap(&lcd_bitmap); /* Initialize the keypad driver */ kbd_init(); /* Initialize the internal flash memory */ flash_init(&flash, 0); /* * Kernel initialization: processes (allow to create and dispatch * processes using proc_new()). */ proc_init(); }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* * XXX: Arduino has a single UART port that was previously * initialized for debugging purpose. * In order to activate the serial driver you should disable * the debugging module. */ #if 0 /* Initialize UART0 */ ser_init(&out, SER_UART0); /* Configure UART0 to work at 115.200 bps */ ser_setbaudrate(&out, 115200); #else (void)out; #endif /* Initialize LED driver */ LED_INIT(); }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize UART0 */ ser_init(&out, SER_UART0); /* Configure UART0 to work at 115.200 bps */ ser_setbaudrate(&out, 115200); /* Initialize LED driver */ LED_INIT(); /* * Kernel initialization: processes (allow to create and dispatch * processes using proc_new()). */ proc_init(); /* Initialize TCP/IP stack */ tcpip_init(NULL, NULL); /* Bring up the network interface */ netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input); netif_set_default(&netif); netif_set_up(&netif); }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize LED driver */ LED_INIT(); LED_OFF(); /* Kernel initialization */ proc_init(); /* Initialize the serial driver */ ser_init(&ser_port, SER_UART2); /* * Hard-code the baud rate to 115.200 bps. * * TODO: implement the baud rate settings as well as other UART * settings over the USB connection. */ ser_setbaudrate(&ser_port, 115200); /* Initialize usb-serial driver */ usbser_init(&usb_port, 0); }
void arch_init(void) { k_stacks = (void*) &k_stacks_start; assert(!((vir_bytes) k_stacks % K_STACK_SIZE)); #ifndef CONFIG_SMP /* * use stack 0 and cpu id 0 on a single processor machine, SMP * configuration does this in smp_init() for all cpus at once */ tss_init(0, get_k_stack_top(0)); #endif #if !CONFIG_OXPCIE ser_init(); #endif #ifdef USE_ACPI acpi_init(); #endif #if defined(USE_APIC) && !defined(CONFIG_SMP) if (config_no_apic) { BOOT_VERBOSE(printf("APIC disabled, using legacy PIC\n")); } else if (!apic_single_cpu_init()) { BOOT_VERBOSE(printf("APIC not present, using legacy PIC\n")); } #endif /* Reserve some BIOS ranges */ cut_memmap(&kinfo, BIOS_MEM_BEGIN, BIOS_MEM_END); cut_memmap(&kinfo, BASE_MEM_TOP, UPPER_MEM_END); }
void init() { start.pressed = FALSE; /* Initialise all push buttons to not being pressed */ start.released = TRUE; /* but rather released */ eepromSerial.pressed = FALSE; eepromSerial.released = TRUE; init_adc(); lcd_init(); TRISB = 0b00000011; /* PORTB I/O designation */ //timer0 OPTION_REG = 0b00000100; //enable timer0 interrupt TMR0IE = 1; SSPSTAT = 0b01000000; /* Transmit on active -> idle state, sample input at middle of output */ SSPCON = 0b00100010; /* Enable serial port, Fosc/64 */ TRISC = 0b10010000; /* RX and SPI_SDI inputs, rest outputs */ PORTC = 0b00000000; /* No module selected, no SM pulse, etc. */ //Enable all interrupts PEIE = 1; GIE = 1; ser_init(); //initialize UART initIRobot(); initSongs(); }
int my_open(struct inode *inode, struct file *filp) { ser_init();//初始化串口设备 printk("my serial init ok!\n"); return 0; }
int main( void ) { FILE mystdout = FDEV_SETUP_STREAM(ser_putch, NULL, _FDEV_SETUP_RW); uint16_t ubrr; stdout = stderr = &mystdout; /* Start bit measurement, press ENTER to generate right pattern * for measurement (00001101) * ----+ +--+ +--+--+ +--+------- * |__| |__| |__.__.__.__| * ^ * ^ ^ ^ +--- stop bit(s) * | +---------------------+------ data bits (LSB first) * +------------------------------- start bit */ TCCR1B = 0; /* stop timer */ TCNT1 = 0; /* reset the counter */ while (PINE & _BV(PORTE0)); /* wait for begin of the start bit */ TCCR1B = (1<<CS10); /* start timer (no prescaling) */ while (!(PINE & _BV(PORTE0))); /* wait for end of start bit */ TCCR1B = 0; /* stop timer */ /* * USART0 is used in asynchronous normal mode * * The baud rate generator is a down-counter, running at system clock * (fosc). A clock is generated each time the counter reaches zero. This * clock is the baud rate generator clock output (= fosc/(UBRR+1)). The * transmitter divides the baud rate generator clock output by 2, 8, or 16 * depending on mode. For asynchronous normal mode * * BAUD = fosc/(16*(UBRR+1)) * UBRR = (fosc/(16*BAUD))-1 * * With TCNT1 we will measure the length of start bit (number of system * tics). This value divided by 2,8, or 16 depending on mode is equal to * UBBR value. */ ubrr = TCNT1 >> 4; /* measured UBRR value */ ser_init( ubrr ); /* open UART0 - xxxx,N,8,1 */ printf("\n--== Auto Baud Rate Detector ==--\n\n"); printf("F_CPU = %ld Hz\n", F_CPU); printf("UBRR = %d\n", ubrr); printf("BAUD = %ld Bd\n\n", F_CPU/(16*(ubrr+1))); printf("Press ENTER to test again baud rate detection.\n"); reboot(); /* reboot AVR microcontroller */ while(1) {}; }
void hadarp_init(unsigned port, unsigned long baudrate) { ser_init(&ser, port); ser_setbaudrate(&ser, baudrate); hadarp_cnt = -1; hadarp_proc = proc_new(hadarp_process, NULL, KERN_MINSTACKSIZE * 3, NULL); ASSERT(hadarp_proc); }
int test_invalidDevice() /* We want to test the behavior of the ser_init procedure when trying to open an invalid device. We expect the procedure to fail. Our non-existing device will have the name "/dev/nodevice". */ { int retValue = ser_init("/dev/nodevice", 9600); if (retValue != -1) exit(TESTFAIL); return(TESTPASS); }
/** * @brief Initializes MemoryTester * @param mt pointer to MemoryTester instance */ void MemoryTester_init(struct MemoryTester *mt) { /* open UART0 - 9600,N,8,1 */ ser_init(UART_BAUD_SELECT(9600, F_CPU)); // mt->inouterr = FDEV_SETUP_STREAM(ser_putch, ser_getch, _FDEV_SETUP_RW); FILE f = FDEV_SETUP_STREAM(ser_putch, ser_getch, _FDEV_SETUP_RW); mt->inouterr = f; stdin = stdout = stderr = &mt->inouterr; mt->window_base = NULL; mt->window_size = 0; puts_P(ver_str_pgm); }
int main(void) { FILE mystdout = FDEV_SETUP_STREAM(ser_putch, ser_getch, _FDEV_SETUP_RW); uint8_t key; /* pressed key */ stdout = stderr = stdin = &mystdout; /* open UART0 - 9600,N,8,1 - interrupt driven RxD */ ser_init( UART_BAUD_SELECT(9600, F_CPU) ); printf("\r\n---== Watchdog Timer ==---\r\n\n"); printf("MCU reset flags - 0x%02x\n\n", MCUCSR); printf(" Power-On Reset %s\n", MCUCSR & _BV(PORF) ? "1" : "0"); printf(" External Reset %s\n", MCUCSR & _BV(EXTRF) ? "1" : "0"); printf(" Brown-out Reset %s\n", MCUCSR & _BV(BORF) ? "1" : "0"); printf(" Watchdog Reset %s\n", MCUCSR & _BV(WDRF) ? "1" : "0"); printf(" JTAG Reset %s\n\n", MCUCSR & _BV(JTRF) ? "1" : "0"); if(MCUCSR & _BV(PORF) || MCUCSR & _BV(JTRF)) bootctr = 0; /* clear boot counter after power-on reset */ printf("Boot counter %d\n\n", bootctr++); MCUCSR = 0x00; /* clear information which reset source caused an MCU reset */ printf( "Press 's' for SW reset or 'h' for HW reset.\n\n"); while(1) { key = toupper(getchar()); /* read a key */ DDRD = 0xFF; /* set port D as output */ PORTD = 0x00; /* turn on LEDs on port D */ printf("Key pressed -> LEDs will be turned ON.\n"); switch(key) { case 'H' : reboot(HW_RESET); /* force HW reset */ break; case 'S' : reboot(SW_RESET); /* force SW reset */ break; default: break; } } }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize UART0 */ ser_init(&out, SER_UART0); /* Configure UART0 to work at 115.200 bps */ ser_setbaudrate(&out, 115200); /* Initialize LED driver */ LED_INIT(); }
void arch_init(void) { #ifdef USE_APIC /* * this is setting kernel segments to cover most of the phys memory. The * value is high enough to reach local APIC nad IOAPICs before paging is * turned on. */ prot_set_kern_seg_limit(0xfff00000); reload_ds(); #endif idt_init(); /* FIXME stupid a.out * align the stacks in the stack are to the K_STACK_SIZE which is a * power of 2 */ k_stacks = (void*) (((vir_bytes)&k_stacks_start + K_STACK_SIZE - 1) & ~(K_STACK_SIZE - 1)); #ifndef CONFIG_SMP /* * use stack 0 and cpu id 0 on a single processor machine, SMP * configuration does this in smp_init() for all cpus at once */ tss_init(0, get_k_stack_top(0)); #endif #if !CONFIG_OXPCIE ser_init(); #endif #ifdef USE_ACPI acpi_init(); #endif #if defined(USE_APIC) && !defined(CONFIG_SMP) if (config_no_apic) { BOOT_VERBOSE(printf("APIC disabled, using legacy PIC\n")); } else if (!apic_single_cpu_init()) { BOOT_VERBOSE(printf("APIC not present, using legacy PIC\n")); } #endif }
int main(void) { FILE mystdout = FDEV_SETUP_STREAM(ser_putch, NULL, _FDEV_SETUP_RW); stdout = stdin = stderr = &mystdout; DDRD = 0xFF; /* set port D as output */ PORTD = 0xFF; /* turn off all port D LEDs */ /* open UART0 - 9600,N,8,1 - interrupt driven RxD */ ser_init( UART_BAUD_SELECT(9600, F_CPU) ); sei(); /* global interrupt enable */ printf("\n--== Press any key to see ATmega128 response ==--\n\n"); while(1){}; /* loop for ever */ }
void main (void) { unsigned char x; unsigned int i,ip; bit err; ser_init(); printf("varapokuthu"); x = 0xff; err = rtrd (); // display hh.mm.ss if (TIMBUF[0]!=x) // check second change { printf("%c",TIMBUF[0]); x = TIMBUF[0]; } TIMBUF[0] = TIMBUF[0] & 0x7F; // enable oscillator (bit 7=0) TIMBUF[1] = 0x59; // minute = 59 TIMBUF[2] = 0x05; // hour = 05 ,24-hour mode(bit 6=0) TIMBUF[3] = 0x01; // Day = 1 or sunday TIMBUF[4] = 0x30; // Date = 30 TIMBUF[5] = 0x08; // month = August TIMBUF[6] = 0x05; // year = 05 or 2005 rtset (); rtwr (); ip=0; while(ip<4) { ip++; rtrd(); putchar(0x0C); // clear Hyper terminal printf("Day : %c\r\n",TIMBUF[3]); printf("Time : %c:%c:%c\r\n",TIMBUF[2],TIMBUF[1],TIMBUF[0]); printf("Data : %c-%c-%c",TIMBUF[4],TIMBUF[5],TIMBUF[6]); for(i=0;i<10;i++) delay_50ms(); // delay about 1 second } while(1); }
int main( void ) { FILE mystdout = FDEV_SETUP_STREAM(ser_putch, ser_getch, _FDEV_SETUP_RW); uint8_t t = 0; stdout = stdin = stderr = &mystdout; /* open UART0 - 9600,N,8,1 */ ser_init( UART_BAUD_SELECT(9600, F_CPU) ); while(1) { if(getchar() == '#') /* temp sting request ? */ { /* send temperature string */ printf("\rTemperature = %3d.%1d %cC", t/10, t%10, DEGREE_SIGN); t++; /* increment temperature */ } } }
int main( void ) { uint16_t adc_val0, adc_val1; uint8_t i; FILE mystdout = FDEV_SETUP_STREAM(ser_putch, ser_getch, _FDEV_SETUP_RW); stdout = stdin = stderr = &mystdout; /* open UART0 - 9600,N,8,1 */ ser_init( UART_BAUD_SELECT(9600, F_CPU) ); /* display program version */ printf_P(PSTR("\rATmega128 A/D single ended and differential example\n" "Build on %s, %s with AVR-GCC %d.%d\n\n"), __DATE__, __TIME__, __GNUC__, __GNUC_MINOR__); adc_init(); /* Configure a2d port (PORTF) as input so we can receive analog signals */ DDRF = 0x00; /* make sure pull-up resistors are turned off (else we’ll just read 0xCFF) */ PORTF = 0x00; while(1) { ADMUX &= 0b11100000; /* selects conversion on PF0 */ ADCSRA |= _BV(ADSC); /* start a conversion by writing a one to the ADSC bit (bit 6) */ while(ADCSRA & 0b01000000); /* wait for conversion to complete (bit 6 will change to 0) */ adc_val0 = ((ADCL) | ((ADCH)<<8)); /* 10-bit conversion for channel 0 (PF0) */ ADMUX |= 0x10; /* selects conversion on PF1 */ _delay_ms(1); ADCSRA |= _BV(ADSC); /* start a conversion by writing a one to the ADSC bit (bit 6) */ while(ADCSRA & 0b01000000); /* wait for conversion to complete (bit 6 will change to 0) */ adc_val1 = ((ADCL) | ((ADCH)<<8)); /* 10-bit conversion for channel 1 (PF1) */ /* Ch0 - single ended ADC0, Ch1 - differential ADC0 possitive, ADC1 negative input */ printf("Ch0 = %d, | Ch1 = %d \n",adc_val0, adc_val1); for (i = 0; i < 10; i++) _delay_ms(10); } return (0); }
Errcode init_wacom(Idriver *idr) { SHORT port = idr->comm_port; Errcode err; if (wac_initted) return(Success); /* set things up to the right baud rate */ if ((err = ser_init(port, BAUD_9600+PARITY_NONE+STOP_1+BITS_8)) < Success) return(err); /* Don't emulate anybody, be a Wacom 2 */ if ((err = slow_to_wacom(port, "$\r\n")) < Success) return(err); /* Ascii mode packets */ if ((err = slow_to_wacom(port, "AS0\r\n")) < Success) return(err); /* Send reply even if pen out of proximity */ if ((err = slow_to_wacom(port, "AL1\r\n")) < Success) return(err); if (idr->options[0].mode == PSTYLUS) { if ((err = slow_to_wacom(port,"PH1\r\n"))< Success) return(err); /* Enable pressure sensitivity */ } else { if ((err = slow_to_wacom(port, "PH0\r\n"))< Success) return(err); } /* Send scale signal. Somehow tablet doesn't seem to get real margins, so have to make scale a little bigger for tablet than Animator */ /* set up scale */ if ((err = slow_to_wacom(port, "SC2304,2304\r\n")) < Success) return(err); wac_initted = TRUE; return(Success); }
struct libserial_port *libserial_open(const char *dev, tcflag_t baudrate) { struct libserial_port *port; port = malloc(sizeof (struct libserial_port) + strlen(dev) + 1); /* malloc failed */ if (port == NULL) return NULL; /* look for file type */ if (stat(dev, &port->st)) goto err; /* try to lock serial port (char device) */ if (S_ISCHR(port->st.st_mode) && try_lock(dev)) goto err; /* open serial port */ port->fd = open(dev, O_RDWR); if (port->fd < 0) goto err1; if (ser_init(port->fd, baudrate)) goto err2; strcpy(port->dev, dev); return port; err2: close(port->fd); err1: if (S_ISCHR(port->st.st_mode)) release_lock(dev); err: free(port); return NULL; }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize UART1 */ ser_init(&out, SER_UART1); /* Configure UART1 to work at 115.200 bps */ ser_setbaudrate(&out, 115200); /* Initialize LED driver */ LED_INIT(); /* * Kernel initialization: processes (allow to create and dispatch * processes using proc_new()). */ proc_init(); }
void serial_test(void) { // serial communication ser_init(ser115200); // init char* console = (char*) "\nlightOs> "; // console message char* buffer; int buffer_len = 64; // size of buffer char* recString; ser_puts((const signed char*) "\n welcome to lightOS\n"); while(1) { buffer = (char*) malloc(sizeof(char)*buffer_len); ser_puts((const signed char*) console); recString = ser_gets(buffer, buffer_len); ser_puts((const signed char*) recString); free(buffer); } }
void main() { sysini(); /* システム初期化 */ BSC.ABWCR.BIT.ABW2 = 0; /* CS2 16bit ACCESS */ BSC.PFCR.BIT.AE0 = 0; BSC.PFCR.BIT.AE1 = 0; BSC.PFCR.BIT.AE2 = 0; BSC.PFCR.BIT.AE3 = 0; PG.DDR = 0x1C; /* CS0,1,2 Active */ // cre_tsk(ID_TASK1, &_ID_TASK1); /* Task1作成 */ cre_tsk(ID_TASK2, &_ID_TASK2); /* Task2作成 */ cre_tsk(ID_TASK3, &_ID_TASK3); /* Task3作成 */ cre_tsk(ID_TASK4, &_ID_TASK4); /* Task4作成 */ sta_tsk(ID_TASK3, 0); /* Task3起動 */ // sta_tsk(ID_TASK2, 0); /* Task2起動 */ // sta_tsk(ID_TASK1, 0); /* Task1起動 */ sta_tsk(ID_TASK4, 0); /* Task4起動 */ ser_init(); /* SCI0初期化 */ intsta(); /* クロック起動 */ syssta(); /* システム起動 */ }
static void init(void) { IRQ_ENABLE; kdbg_init(); timer_init(); /* * Init afsk demodulator. We need to implement the macros defined in hw_afsk.h, which * is the hardware abstraction layer. * We do not need transmission for now, so we set transmission DAC channel to 0. */ afsk_init(&afsk, ADC_CH, 0); /* * Here we initialize AX25 context, the channel (KFile) we are going to read messages * from and the callback that will be called on incoming messages. */ ax25_init(&ax25, &afsk.fd, message_callback); /* Initialize serial port, we are going to use it to show APRS messages*/ ser_init(&ser, SER_UART0); ser_setbaudrate(&ser, 115200L); }
void NORETURN context_switch(void) { IRQ_ENABLE; timer_init(); proc_init(); #if CONFIG_USE_HP_TIMER ser_init(&out, CONFIG_CTX_DEBUG_PORT); ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE); #endif #if CONFIG_USE_LED LED_INIT(); #endif proc_forbid(); hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack); lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack); main_proc = proc_current(); proc_setPri(hp_proc, 2); proc_setPri(lp_proc, 1); proc_permit(); while (1) { timer_delay(100); sig_send(lp_proc, SIG_USER0); sig_wait(SIG_USER0); #if CONFIG_USE_HP_TIMER kfile_printf(&out.fd, "Switch: %lu.%lu usec\n\r", hptime_to_us((end - start)), hptime_to_us((end - start) * 1000) % 1000); #endif } }
int main( void ) { FILE mystdout = FDEV_SETUP_STREAM(ser_putch, ser_getch, _FDEV_SETUP_RW); stdout = stdin = stderr = &mystdout; /* open UART0 - 9600,N,8,1 */ ser_init( UART_BAUD_SELECT(9600, F_CPU) ); puts_P(ver_str_pgm); while(1) { puts(main_menu); switch( getchar() ) { case 'd': dumpsram(); break; case 'f': fillsram(); break; default: break; } } }
/** * Init SPI serial driver \a unit in master mode. * * Use SER_SPIn for \a unit parameter. * * This interface implements the SPI master protocol over a serial SPI * driver. This is needed because normal serial driver send/receive data * at the same time. SPI slaves like memories and other peripherals * first receive and *then* send response back instead. * To achieve this, when we are master and we are *sending*, * we have to discard all incoming data. Then, when we want to * receive, we must write fake data to SPI to trigger slave devices. */ void spimaster_init(Serial *fds, unsigned int unit) { ser_init(fds, unit); fds->fd.read = spimaster_read; fds->fd.write = spimaster_write; }