/* telnet server */ void telnet_srv() { rt_thread_t tid; if (telnet == RT_NULL) { rt_uint8_t *ptr; telnet = rt_malloc (sizeof(struct telnet_session)); if (telnet == RT_NULL) { rt_kprintf("telnet: no memory\n"); return; } /* init ringbuffer */ ptr = rt_malloc (TELNET_RX_BUFFER); rb_init(&telnet->rx_ringbuffer, ptr, TELNET_RX_BUFFER); /* create rx ringbuffer lock */ telnet->rx_ringbuffer_lock = rt_sem_create("rxrb", 1, RT_IPC_FLAG_FIFO); ptr = rt_malloc (TELNET_TX_BUFFER); rb_init(&telnet->tx_ringbuffer, ptr, TELNET_TX_BUFFER); /* create tx ringbuffer lock */ telnet->tx_ringbuffer_lock = rt_sem_create("txrb", 1, RT_IPC_FLAG_FIFO); /* create network event */ telnet->nw_event = rt_event_create("telnet", RT_IPC_FLAG_FIFO); } tid = rt_thread_create("telnet", telnet_thread, RT_NULL, 2048, 25, 5); if (tid != RT_NULL) rt_thread_startup(tid); }
static int init(void) { unsigned short int i; void *b; lock_static_init(&netif_lock); NET_LOCK_TAKE(); cos_vect_init_static(&tmap); rb_init(&rb1_md_wildcard, &rb1); rb_init(&rb2_md, &rb2); /* Setup the region from which headers will be transmitted. */ if (cos_buff_mgmt(COS_BM_XMIT_REGION, &xmit_headers, sizeof(xmit_headers), 0)) { prints("net: error setting up xmit region."); } /* Wildcard upcall */ if (cos_net_create_net_brand(0, &rb1_md_wildcard)) BUG(); for (i = 0 ; i < NUM_WILDCARD_BUFFS ; i++) { if(!(b = alloc_rb_buff(&rb1_md_wildcard))) { prints("net: could not allocate the ring buffer."); } if(rb_add_buff(&rb1_md_wildcard, b, MTU)) { prints("net: could not populate the ring with buffer"); } } NET_LOCK_RELEASE(); return 0; }
/*================================================================ // 启动串口 //===============================================================*/ void serial::begin(void) { ARM_DRIVER_VERSION version; ARM_USART_CAPABILITIES drv_capabilities; char cmd; static char text_show[20]={"I am Jackey Jiang\n"}; #ifdef DEBUG version = USARTdrv->GetVersion(); if (version.api < 0x200) /* requires at minimum API version 2.00 or higher */ { /* error handling */ return; } drv_capabilities = USARTdrv->GetCapabilities(); if (drv_capabilities.event_tx_complete == 0) { /* error handling */ return; } #endif /*Initialize the USART driver */ USARTdrv->Initialize(myUSART_callback); /*Power up the USART peripheral */ USARTdrv->PowerControl(ARM_POWER_FULL); /*Configure the USART to 115200 Bits/sec */ USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 | ARM_USART_FLOW_CONTROL_NONE, 256000); /* Enable Receiver and Transmitter lines */ USARTdrv->Control (ARM_USART_CONTROL_TX, 1); USARTdrv->Control (ARM_USART_CONTROL_RX, 1); USARTdrv->Send("\n Melzi start \n", 15); //USARTdrv->Send(&text_show[0], 20); rb_init(&rxRingbuf, sizeof(rxBuf),rxBuf); rb_init(&txRingbuf, sizeof(txBuf),txBuf); // osSignalWait(0x01, osWaitForever); // // while (1) // { // USARTdrv->Receive(&cmd, 1); /* Get byte from UART */ // osSignalWait(0x01, osWaitForever); // if (cmd == 13) /* CR, send greeting */ // { // USARTdrv->Send("\nHello World!", 12); // osSignalWait(0x01, osWaitForever); // } // // } }
void usart_setup(const usart_dev *dev, uint32_t baudRate, uint16_t wordLength, uint16_t stopBits, uint16_t parity, uint16_t mode, uint16_t hardwareFlowControl) { /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(dev->USARTx)); assert_param(IS_USART_BAUDRATE(baud)); assert_param(IS_USART_STOPBITS(stopbits)); assert_param(IS_USART_PARITY(parity)); assert_param(IS_USART_WORD_LENGTH(wordLength)); assert_param(IS_USART_MODE(mode)); assert_param(IS_USART_HARDWARE_FLOW_CONTROL(hardwareFlowControl)); memset(dev->state, 0, sizeof(*dev->state)); dev->state->txbusy = 0; dev->state->callback = 0; /* Disable USARTx */ usart_disable(dev); rb_init(dev->txrb, USART_TX_BUF_SIZE, dev->state->tx_buf); rb_init(dev->rxrb, USART_RX_BUF_SIZE, dev->state->rx_buf); /* Enables the USART's 8x oversampling mode. */ USART_OverSampling8Cmd(dev->USARTx, ENABLE); USART_ClockInitTypeDef USART_InitClock; USART_ClockStructInit(&USART_InitClock); USART_ClockInit(dev->USARTx, &USART_InitClock); USART_InitTypeDef USART_config; USART_StructInit(&USART_config); USART_config.USART_BaudRate = baudRate; USART_config.USART_WordLength = wordLength; USART_config.USART_StopBits = stopBits; USART_config.USART_Parity = parity; USART_config.USART_Mode = mode; USART_config.USART_HardwareFlowControl = hardwareFlowControl; USART_Init(dev->USARTx, &USART_config); dev->USARTx->CR1 &= ~(USART_MASK_IDLEIE | USART_MASK_RXNEIE | USART_MASK_TCEIE | USART_MASK_TXEIE | USART_MASK_PEIE); dev->USARTx->CR2 &= ~(USART_MASK2_LBDIE); dev->USARTx->CR3 &= ~(USART_MASK3_CTSIE | USART_MASK3_EIE); if(mode & USART_Mode_Rx) { /* Enable Rx request */ USART_ClearFlag(dev->USARTx, USART_FLAG_RXNE); dev->USARTx->CR1 |= USART_MASK_RXNEIE; } if(mode & USART_Mode_Tx) { USART_ClearFlag(dev->USARTx, USART_FLAG_TC); } enable_nvic_irq(dev->irq, UART_INT_PRIORITY); }
/** * @brief Initialize a serial port. * @param dev Serial port to be initialized */ void usart_init(usart_dev *dev) { /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(dev->USARTx)); rb_init(dev->txrb, USART_TX_BUF_SIZE, dev->tx_buf); rb_init(dev->rxrb, USART_RX_BUF_SIZE, dev->rx_buf); // Turn on peripheral clocks if (dev->USARTx == USART1 || dev->USARTx == USART6 ) RCC_APB2PeriphClockCmd(dev->clk, ENABLE); else RCC_APB1PeriphClockCmd(dev->clk, ENABLE); }
void rb() { printf(">> RB\n"); rb_tree_t tree; rb_init(&tree, NULL); test_rb_t a = { 1 }; test_rb_t b = { 2 }; test_rb_t c = { 3 }; rb_insert(&tree, &a.node, &test_rb_compare); rb_insert(&tree, &b.node, &test_rb_compare); rb_insert(&tree, &c.node, &test_rb_compare); // Display them rb_node_t *node = rb_head(&tree); while (node) { rb_node_t *next = rb_next(node); rb_node_t *prev = rb_prev(node); test_rb_t *c = rb_ref(node, test_rb_t, node); test_rb_t *n = next ? rb_ref(next, test_rb_t, node) : NULL; test_rb_t *p = prev ? rb_ref(prev, test_rb_t, node) : NULL; printf("current: %d, next: %d, prev: %d\n", c->number, n ? n->number : -1, p ? p->number : -1); node = next; } }
int main(int argc, char *argv[]) { struct rb_node sentinel; struct rb_tree rbtree; struct rb_node node[1000]; int i, j; rb_init(&rbtree, &sentinel); srand(time(0)); for (i = 0; i < 10; i++) { for (;;) { node[i].key = rand()%10000; for (j = 0; j < i; j++) { if (node[i].key == node[j].key) break; } if (j < i) continue; else break; } rb_insert(&rbtree, &node[i]); } for (i = 0; i < 10; i++) rb_delete(&rbtree, &node[i]); exit(0); }
int audio_decoder_init(audio_decoder_p decoder, size_t rbuf_size) { assert(decoder != NULL); priv_data_p priv = (priv_data_p) malloc(sizeof(priv_data_t)); RETURN_VAL_IF_FAIL((priv != NULL), AUDIO_DECODER_ERROR); // init private data priv->mCurrentPos = 0; priv->mFixedHeader = 0; // init decoder data decoder->cb_data = NULL; decoder->input_func = NULL; decoder->dec_ext = NULL; decoder->dec_mem = NULL; decoder->priv_data = priv; // init ring-buffer and open it as a stream rb_init(&decoder->ringbuffer, rbuf_size); decoder->rbsp = rbs_open(&decoder->ringbuffer, _input_callback, (void *)decoder); RETURN_VAL_IF_FAIL((decoder->rbsp != NULL), AUDIO_DECODER_ERROR); rbs_ctrl(decoder->rbsp, OPTION_ALLOW_TO_DEQUEUE, 1); return AUDIO_DECODER_OK; }
int semaphore_buffer_worker_init() { /* 初始化ring buffer */ rb_init(&working_rb, working_buffer, BUFFER_SIZE); /* 创建信号量 */ sem = rt_sem_create("sem", 1, RT_IPC_FLAG_FIFO); if (sem == RT_NULL) { tc_stat(TC_STAT_END | TC_STAT_FAILED); return 0; } /* 创建线程1 */ tid = rt_thread_create("thread", thread_entry, RT_NULL, /* 线程入口是thread_entry, 入口参数是RT_NULL */ THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (tid != RT_NULL) rt_thread_startup(tid); else tc_stat(TC_STAT_END | TC_STAT_FAILED); /* 创建线程2 */ worker = rt_thread_create("worker", worker_entry, RT_NULL, /* 线程入口是worker_entry, 入口参数是RT_NULL */ THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (worker != RT_NULL) rt_thread_startup(worker); else tc_stat(TC_STAT_END | TC_STAT_FAILED); return 0; }
/** * @brief Initialize a serial port. * @param dev Serial port to be initialized */ void usart_init(usart_dev *dev, uint8_t *buff, uint16 buff_size) { usart_reg_map *regs = dev->regs; rb_init(dev->rb, buff_size, buff); // Clocking must be enabled to modify registers clk_enable_dev(dev->clk_id); // Configuration: 8-bit, 1stop, no-parity // tx configuration REG_SET_CLR(regs->CONFIG, 0, UART_CFGR_TDATLN_MASK | UART_CFGR_TPAREN_MASK | UART_CFGR_TSTPMD_MASK | UART_CFGR_TINVEN_MASK); REG_SET_CLR(regs->CONFIG, 1, UART_CFGR_TDATLN_8_BITS | UART_CFGR_TSTRTEN_EN | UART_CFGR_TSTPEN_EN | (1 << UART_CFGR_TSTPMD_BIT)); // rx configuration REG_SET_CLR(regs->CONFIG, 0, UART_CFGR_RDATLN_MASK | UART_CFGR_RSTPMD_MASK | UART_CFGR_RINVEN_MASK); REG_SET_CLR(regs->CONFIG, 1, UART_CFGR_RDATLN_8_BITS | UART_CFGR_RSTRTEN_EN | UART_CFGR_RSTPEN_EN | (1 << UART_CFGR_RSTPMD_BIT)); // Interrupt when a single byte is in rx buffer REG_SET_CLR(regs->FIFOCN, 0 , 0x00000030); // Enable IRQ on NVIC nvic_clr_pending_irq(dev->irq_num); nvic_irq_enable(dev->irq_num); }
int main (void) { int i=0; struct buf_info test_buffer; unsigned char real_buf[20]; rb_init (&test_buffer, (unsigned char*)&real_buf, 20); rb_write (&test_buffer, 'a'); rb_write (&test_buffer, 'a'); printf ("got %hhc %hhc\n", rb_read(&test_buffer), rb_read(&test_buffer)); for (i = 0; i<52; i++) { rb_write (&test_buffer, (char)(i+33)); } int chr = rb_read (&test_buffer); char str [21]; int npos = 0; while (chr != EEMPTY) { str[npos++]=(char)chr; chr = rb_read (&test_buffer); } str[npos]=0; printf ("npos=%d, got %s\n", npos, str); return 0; }
void sim900_init(void) { u8 data; GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; if (SIM900_USARTAPB == APB1) { RCC_APB2PeriphClockCmd(RCC_APBxPeriph_SIM900_USART_IO | RCC_APB2Periph_AFIO,ENABLE); RCC_APB1PeriphClockCmd(RCC_APBxPeriph_SIM900_USART,ENABLE); } else { RCC_APB2PeriphClockCmd(RCC_APBxPeriph_SIM900_USART_IO | RCC_APBxPeriph_SIM900_USART | RCC_APB2Periph_AFIO,ENABLE); } if (SIM900_PinRemap == ENABLE) { GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE); } GPIO_InitStructure.GPIO_Pin = SIM900_USART_TXD; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SIM900_USART_IO,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SIM900_USART_RXD; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SIM900_USART_IO,&GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None ; USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; USART_Init(SIM900_USART,&USART_InitStructure); data = data; data = SIM900_USART->DR; data = SIM900_USART->SR; USART_ITConfig(SIM900_USART,USART_IT_RXNE,ENABLE); USART_Cmd(SIM900_USART,ENABLE); rb_init(&rx_rb, &rx_buf[0], sizeof(rx_buf)); rx_semaphore = OSSemCreate(0); //setup recieve thread OSTaskCreate(thread_sim900_rx_entry, (void *)0, &recvTaskStk[RECEIVE_TASK_STK_SIZE - 1], SIM900_RX_PRIO); status = STATUS_POWERON; #if 0 //fake thread to do some emulator printk("create fake thread\r\n"); OSTaskCreate(fake_thread, (void *)0, &fakeTaskStk[FAKE_TASK_STK_SIZE - 1], FAKE_TASK_PRIO); #endif }
static void init_xcode_tree(void) { xcode_tree = rb_init(compare_dbrefs, NULL); if (!xcode_tree) { /* TODO: We could handle this more gracefully... */ exit(EXIT_FAILURE); } }
void setup() { rb = &ring_buf; rb_init(rb, BUF_SIZE, rb_buffer); while (!SerialUSB.available()) ; SerialUSB.println("Beginning test."); SerialUSB.println(); }
void ant_init(ant_configuration config) { rb_init(&rx_ring, 255, buffer); _config = config; reset(); delay_ms(600); ant_config(); }
void plot_rand_sort_rb(int num_vertices, int thres, FILE *gnuplot_ins, FILE *gnuplot_dm, FILE *gnuplot_total){ srandom(97643); printf("Red Black tree: %d elements\n",num_vertices); int MAX = pow(2, 24); struct timespec delmin, ins, start, end; delmin.tv_nsec = 0; delmin.tv_sec = 0; ins.tv_nsec = 0; ins.tv_sec = 0; rb_tree * heap = rb_init(); int i; uint8_t * arr = calloc(MAX, sizeof(uint8_t)); if (arr == NULL){ printf("dang...could not allocate enough memory\n"); exit(1); } rb_node *e; for (i = 0; i < num_vertices; i++){ uint32_t s = random() % MAX; while(arr[s]) s = random() % MAX; arr[s] = 1; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); rb_insert(s, heap); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); increment(&ins, &start, &end); } /*for (i = 0; i < num_vertices; i++){ e = rb_find_min(heap); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); rb_delete(e, heap); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); increment(&delmin, &start, &end); }*/ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); linked_list *ll = rb_prio_inorder_walk(heap); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); increment(&delmin, &start, &end); linked_list_destruct(ll); free(arr); rb_destruct(heap); if(gnuplot_ins) fprintf(gnuplot_ins, "%d %ld\n", num_vertices, ((ins.tv_sec* 1000000000)+(ins.tv_nsec))/num_vertices); if(gnuplot_dm) fprintf(gnuplot_dm, "%d %ld\n", num_vertices, ((delmin.tv_sec*1000000000)+(delmin.tv_nsec))/num_vertices); if(gnuplot_total) fprintf(gnuplot_total, "%d %ld\n", num_vertices, (((ins.tv_sec + delmin.tv_sec) * 1000)+(ins.tv_nsec + delmin.tv_nsec)/1000000)); }
void ring_example() { rb_ringbuffer * buffer; uint64_t seq_num = 0; char * entry; rb_init(&buffer, 4, 1024); rb_claim(buffer, &seq_num, 1); rb_get(buffer, &entry, seq_num); rb_publish(buffer, seq_num, 1); rb_release(buffer, seq_num, 1); rb_free(&buffer); }
void usart0_init(void) { const uint32_t baudrate = 115200; #ifndef NO_USART0_BUFFERED_INPUT rb_init(&usart0_inBuff); USART0_ENABLE_RX_INTERRUPT(); #endif #ifndef NO_USART0_BUFFERED_OUTPUT rb_init(&usart0_outBuff); USART0_ENABLE_TX_INTERRUPT(); #endif //Enable TXen og RXen USART0_ENABLE_RX(); USART0_ENABLE_TX(); USART0_SET_1_STOP_BIT(); USART0_SET_CHAR_SIZE(UART_CHAR_8BIT); // Baud rate usart0_setBaudrate(baudrate, UART_MODE_ASYNC_NORMAL); }
void rb_tree_test() { size_t i; rbtree tree; rb_init(&tree); int temp; for(i = 0; i < 100; i++){ temp = rand()%10000; rb_insert(temp, &tree); } //rb_print(&tree); //printf("\n"); //rb_delete(rb_max(tree.root->rchild->lchild, &tree), &tree); tree_print(&tree); rb_free(&tree); }
void plot_succ_veb(int n, int cutoff, FILE *gnuplot_ins, FILE *gnuplot_succ, FILE *gnuplot_total){ printf("vEB: %d elements\n",n); srandom(235423); struct timespec succ, ins, start, end; succ.tv_nsec = 0; succ.tv_sec = 0; ins.tv_nsec = 0; ins.tv_sec = 0; vebtree * vebt = veb_initialize(24, 64); rb_tree * rbt = rb_init(); int i; for (i = 0; i < n; i++){ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); veb_insert(i, NULL, vebt); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); increment(&ins, &start, &end); rb_insert(i, rbt); } linked_list * ll = get_key_list(rbt, cutoff); linked_list_node * node= ll->first; int ii = 0; while(node){ ii++; int32_t s; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); veb_findsucc(node->data, &s, vebt); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); node = node->next; increment(&succ, &start, &end); } printf("searched %d keys\n", ii); if(gnuplot_ins) fprintf(gnuplot_ins, "%d %ld\n", n, ((ins.tv_sec* 1000000000)+(ins.tv_nsec))/n); if(gnuplot_succ) fprintf(gnuplot_succ, "%d %ld\n", n, ((succ.tv_sec*1000000000)+(succ.tv_nsec))/(ii)); if(gnuplot_total) fprintf(gnuplot_total, "%d %ld\n", n, (((ins.tv_sec + succ.tv_sec) * 1000)+(ins.tv_nsec + succ.tv_nsec)/1000000)); veb_destruct(vebt); rb_destruct(rbt); linked_list_destruct(ll); }
static int __init ringbuf_init(void) { int res; /* Set up non driver specific stuff */ res = rb_init(); if (res < 0) { RINGBUF_LOGGER_ERR("Failed to do rb_init"); rb_stop(); return res; } /* Setting up internal char device. Do this last since after this the devices are "live" */ cdev_init(&ringbuf_cdev, &ringbuf_device_fops); ringbuf_cdev.owner = THIS_MODULE; res = cdev_add(&ringbuf_cdev, rb_get_dev_t(), RB_MAX_NO_TAGS * RB_DEV_PER_TAG); if (res < 0) { RINGBUF_LOGGER_ERR("Failed to add internal char device\n"); return res; } rb_proc_init(); RINGBUF_LOGGER_INFO("Ringbuf character driver Registered\n"); /* atomic_notifier_chain_register(&panic_notifier_list, &ringbuf_panic_notifier); register_klog_proc(); printk(KERN_NOTICE "Registered panic notifier\n"); */ return 0; }
static int __init mymod_init (void) { int rc; dev_t devid; int i; if ((mydev_device = kmalloc(ndev * sizeof *mydev_device, GFP_KERNEL)) == NULL) { return -ENOMEM; } if ((mydev_ring = kmalloc(ndev * sizeof *mydev_ring, GFP_KERNEL)) == NULL) { kfree(mydev_device); return -ENOMEM; } /* Handle static allocation of major number (specified as a module parameter) or otherwise dynamically allocate the major number */ if (major) { /* Use the major number specified */ devid = MKDEV(major, 0); rc = register_chrdev_region(devid, ndev, "mydev"); } else { /* Dynamically allocate a range of ndev major/minor numbers */ rc = alloc_chrdev_region(&devid, 0, ndev, "mydev"); /* save major number component of devid */ major = MAJOR(devid); } if (rc) { /* inability to register major number is fatal */ printk("Trouble registering major number!\n"); kfree(mydev_device); kfree(mydev_ring); return rc; } /* Time to initialize hardware, for this must be done prior to calling cdev_add(), after which time requests can start coming in */ for (i = 0; i < ndev; i++) { rc = rb_init(&mydev_ring[i], MYDEV_RING_SIZE); if (rc) { printk("rb_init(%d) returned error %d\n", i, rc); mydev_ring[i] = NULL; } } /* Initalize the struct cdev structure, and set the table of file operation functions (this function cannot fail) */ cdev_init(&mydev, &mydev_fops); /* Register the char device with the kernel. At this point, driver should be prepared to handle requests (particularly if the device nodes were already created) */ if ((rc = cdev_add(&mydev, devid, ndev))) { /* failure at this point is fatal */ printk("Trouble registering with kernel!\n"); for (i = 0; i < ndev; i++) { if (mydev_ring[i] != NULL) rb_destroy(mydev_ring[i]); } unregister_chrdev_region(devid, ndev); kfree(mydev_device); kfree(mydev_ring); return rc; } /* Establish a class under which we will register our driver with sysfs. Registration with sysfs is nice, but not necessary for the driver to work. Therefore, do not consider failure at this point to be fatal. */ mydev_class = class_create(THIS_MODULE, "mydev"); if (IS_ERR(mydev_class)) { printk("class_create() returned error %ld\n", PTR_ERR(mydev_class)); mydev_class = NULL; } else { /* Register each device with sysfs. Among other things, this will trigger creation of the device nodes in /dev */ for (i = 0; i < ndev; i++) { if (mydev_ring[i] == NULL) { /* don't register devices for which there is no ring buffer */ mydev_device[i] = NULL; } else { mydev_device[i] = device_create(mydev_class, NULL, MKDEV(major, i), NULL, "mydev%d", i); if (IS_ERR(mydev_device[i])) { printk("device_create(%d) returned error %ld\n", i, PTR_ERR(mydev_device[i])); mydev_device[i] = NULL; } } } } printk("Hello from mydev!\n"); return 0; }
/** * @brief Initialize UART buffer. */ void rakmgr_uartbuf_init(void) { rakmgr_uartbuf_lock(); rb_init(&uartbuf, uartbuf_raw, sizeof (uartbuf_raw)); rakmgr_uartbuf_unlock(); }
FsWriterThread::FsWriterThread(SDCDriver& sdcd, Communicator& communicator) : fs(sdcd), fsInfoMessageStream(communicator, 1) { rb_init(&buf, sizeof(_buf), _buf); }
/* VCP_Init * Initializes the Media on the STM32 * @param None * @retval Result of the opeartion (USBD_OK in all cases) */ static U16 VCP_Init(void) { rb_init(rxfifo, rxfifo_size, rx_buf); rb_init(txfifo, txfifo_size, tx_buf); return USBD_OK; }
void output_init( buffered_output_t * out ) { rb_init( &out->buffer ); }
int main(int argc, char *argv[]) { struct rb_tree tree; rb_init(&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_insert(11,&tree); rb_insert(14,&tree); rb_insert(2,&tree); rb_insert(1,&tree); rb_insert(7,&tree); rb_insert(5,&tree); rb_insert(8,&tree); rb_insert(4,&tree); rb_print(&tree); rb_free_elements(&tree); return 0; }
void kipc_init(KPROCESS *kprocess) { rb_init(&(kprocess->process->ipcs), KERNEL_IPC_COUNT); kprocess->kipc.wait_process = (KPROCESS*)INVALID_HANDLE; kprocess->kipc.cmd = ANY_CMD; }
int snd_open_stream() { int samplerate; char info_buf[256]; PaDeviceIndex pa_dev_id; PaStreamParameters pa_params; PaError pa_err; const PaDeviceInfo *pa_dev_info; if(cfg.audio.dev_count == 0) { print_info("ERROR: no sound device with input channels found", 1); return 1; } buf_size = PA_FRAMES * 2; framepacket_size = PA_FRAMES * cfg.audio.channel; pa_pcm_buf = (short*)malloc(buf_size * sizeof(short)); encode_buf = (char*)malloc(buf_size * sizeof(char)); rb_init(&rec_rb, 16 * buf_size * sizeof(short)); rb_init(&stream_rb, 16 * buf_size * sizeof(short)); samplerate = cfg.audio.samplerate; pa_dev_id = cfg.audio.pcm_list[cfg.audio.dev_num]->dev_id; pa_dev_info = Pa_GetDeviceInfo(pa_dev_id); if(pa_dev_info == NULL) { snprintf(info_buf, 127, "Error getting device Info (%d)", pa_dev_id); print_info(info_buf, 1); return 1; } pa_params.device = pa_dev_id; pa_params.channelCount = cfg.audio.channel; pa_params.sampleFormat = paInt16; pa_params.suggestedLatency = pa_dev_info->defaultHighInputLatency; pa_params.hostApiSpecificStreamInfo = NULL; pa_err = Pa_IsFormatSupported(&pa_params, NULL, samplerate); if(pa_err != paFormatIsSupported) { if(pa_err == paInvalidSampleRate) { snprintf(info_buf, sizeof(info_buf), "Samplerate not supported: %dHz\n" "Using default samplerate: %dHz", samplerate, (int)pa_dev_info->defaultSampleRate); print_info(info_buf, 1); if(Pa_IsFormatSupported(&pa_params, NULL, pa_dev_info->defaultSampleRate) != paFormatIsSupported) { print_info("FAILED", 1); return 1; } else { samplerate = (int)pa_dev_info->defaultSampleRate; cfg.audio.samplerate = samplerate; cfg.rec.samplerate = samplerate; update_samplerates(); } } else { snprintf(info_buf, sizeof(info_buf), "PA: Format not supported: %s\n", Pa_GetErrorText(pa_err)); print_info(info_buf, 1); return 1; } } pa_err = Pa_OpenStream(&stream, &pa_params, NULL, samplerate, PA_FRAMES, paNoFlag, snd_callback, NULL); if(pa_err != paNoError) { printf("error opening sound device: \n%s\n", Pa_GetErrorText(pa_err)); return 1; } Pa_StartStream(stream); return 0; }
void scsis_error_init(SCSIS* scsis) { rb_init(&scsis->rb_error, SCSI_SENSE_DEPTH); }