int main(int argc, char **argv) { struct fifo *f; uint8_t i, count, d[5], d2[6]; assert((f = fifo_alloc(8)) != NULL); for (count = 0; fifo_put(f, &count, 1) == 1; count++) ; printf("Wrote %d items into the FIFO\n", count); fifo_dump(f); for (i = 0; i < sizeof(d); i++) d[i] = i; printf("Wrote %d bytes [0..4]\n", fifo_put(f, d, sizeof(d))); printf("Wrote %d bytes [0..2]\n", fifo_put(f, d, sizeof(d))); printf("Read %d bytes\n", fifo_get(f, d2, sizeof(d2))); for (i = 0; i < sizeof(d2); i++) printf("Got %d\n", d2[i]); printf("Unread %d bytes\n", fifo_unget(f, d2, sizeof(d2))); fifo_dump(f); exit(0); }
int __stdio_write_flush(FILE * f) { unsigned char * p; size_t size; ssize_t ret; if(!f) return -1; p = f->buf; size = fifo_get(f->fifo_write, p, f->bufsz); while(size > 0) { ret = f->write(f, p, size); if(ret <= 0) { f->error = 1; fifo_put(f->fifo_write, p, size); return -1; } size -= ret; p += ret; }; f->rwflush = &__stdio_no_flush; return 0; }
void alp_append_write_file_data_action(fifo_t* fifo, uint8_t file_id, uint32_t offset, uint32_t length, uint8_t* data, bool resp, bool group) { uint8_t op = ALP_OP_WRITE_FILE_DATA | (resp << 6) | (group << 7); assert(fifo_put_byte(fifo, op) == SUCCESS); alp_append_file_offset_operand(fifo, file_id, offset); alp_append_length_operand(fifo, length); assert(fifo_put(fifo, data, length) == SUCCESS); }
void inthandler21(int *esp) { unsigned char data; data = io_in8(PORT_KEYDATA); //键盘输入的信息从0x0060传入一个字节,由data接收到(键盘电路设计一次只能传入一个字节) io_out8(PIC0_OCW2,0x61); //CPU通知PIC0“IRQ1已经受理完毕” fifo_put(&keyFIFO, data); }
void alp_append_return_file_data_action(fifo_t* fifo, uint8_t file_id, uint32_t offset, uint32_t length, uint8_t* data) { assert(fifo_put_byte(fifo, ALP_OP_RETURN_FILE_DATA) == SUCCESS); assert(fifo_put_byte(fifo, file_id) == SUCCESS); alp_append_length_operand(fifo, offset); alp_append_length_operand(fifo, length); assert(fifo_put(fifo, data, length) == SUCCESS); }
void uart_rx_cb(uint8_t data) { error_t err; err = fifo_put(&uart_rx_fifo, &data, 1); assert(err == SUCCESS); // parse command in read_rssi() task use_manual_channel_switching = true; }
// IRQ-20 : Timer interrupt. void inthandler20(int* esp) { (void)esp; char switch_task = FALSE; io_out8(PIC0_OCW2, 0x60); // Notify IRQ-00 recv to PIC ++timerctl.count; if (timerctl.next_time > timerctl.count) return; TIMER* timer = timerctl.t0; for (;;) { if (timer->timeout > timerctl.count) break; timer->flags = TIMER_FLAGS_ALLOCATED; if (timer != task_timer) { fifo_put(timer->fifo, timer->data); } else { switch_task = TRUE; } timer = timer->next_timer; } timerctl.t0 = timer; timerctl.next_time = timerctl.t0->timeout; if (switch_task) task_switch(); }
int user_logoff( unsigned int userId ) { struct user_t *user, *search; struct list_t *change; struct message_t message; user = users; while ( user != NULL ) { if ( user->id == userId ) { user->status = 0; free( user->address ); search = users; while ( search != NULL ) { change = search->list; while (change != NULL) { if (change->id == userId) { message.from = userId; message.to = search->id; message.type = 6; fifo_put(&messages,&message); } change = change->next; } search = search->next; } // Notifica a alteração de estados para todos os usuários que // incluem este usuário em sua lista // TODO return 1; } user = user->next; } return -1; }
/* store a received message in the incoming queue, returns 1 if successful, * 0 otherwise */ uint8_t lwb_in_buffer_put(const uint8_t * const data, uint8_t len) { if(len > LWB_CONF_MAX_DATA_PKT_LEN) { len = LWB_CONF_MAX_DATA_PKT_LEN; DEBUG_PRINT_WARNING("received data packet is too big"); } /* received messages will have the max. length LWB_CONF_MAX_DATA_PKT_LEN */ uint32_t pkt_addr = fifo_put(&in_buffer); if(FIFO_ERROR != pkt_addr) { #if !LWB_CONF_USE_XMEM /* copy the data into the queue */ memcpy((uint8_t*)(uint16_t)pkt_addr, data, len); /* last byte holds the payload length */ *(uint8_t*)((uint16_t)pkt_addr + LWB_CONF_MAX_DATA_PKT_LEN) = len; #else /* LWB_CONF_USE_XMEM */ /* write the data into the queue in the external memory */ xmem_write(pkt_addr, len, data); xmem_write(pkt_addr + LWB_CONF_MAX_DATA_PKT_LEN, 1, &len); #endif /* LWB_CONF_USE_XMEM */ return 1; } stats.rxbuf_drop++; DEBUG_PRINT_VERBOSE("in queue full"); return 0; }
/* puts a message into the outgoing queue, returns 1 if successful, * 0 otherwise */ uint8_t lwb_send_pkt(uint16_t recipient, uint8_t stream_id, const uint8_t * const data, uint8_t len) { /* data has the max. length LWB_DATA_PKT_PAYLOAD_LEN, lwb header needs * to be added before the data is inserted into the queue */ if(len > LWB_DATA_PKT_PAYLOAD_LEN || !data) { DEBUG_PRINT_ERROR("invalid payload length"); return 0; } uint32_t pkt_addr = fifo_put(&out_buffer); if(FIFO_ERROR != pkt_addr) { #if !LWB_CONF_USE_XMEM /* assume pointers are 16-bit */ uint8_t* next_msg = (uint8_t*)(uint16_t)pkt_addr; *(next_msg) = (uint8_t)recipient; /* recipient L */ *(next_msg + 1) = recipient >> 8; /* recipient H */ *(next_msg + 2) = stream_id; *(next_msg + LWB_CONF_MAX_DATA_PKT_LEN) = len + LWB_CONF_HEADER_LEN; memcpy(next_msg + LWB_CONF_HEADER_LEN, data, len); #else /* LWB_CONF_USE_XMEM */ *(data_buffer) = (uint8_t)recipient; /* recipient L */ *(data_buffer + 1) = recipient >> 8; /* recipient H */ *(data_buffer + 2) = stream_id; *(data_buffer + LWB_CONF_MAX_DATA_PKT_LEN) = len + LWB_CONF_HEADER_LEN; memcpy(data_buffer + LWB_CONF_HEADER_LEN, data, len); /* always read the max length since we don't know how long the packet is */ xmem_write(pkt_addr, LWB_CONF_MAX_DATA_PKT_LEN + 1, data_buffer); #endif /* LWB_CONF_USE_XMEM */ return 1; }
uint32_t app_fifo_write(app_fifo_t * p_fifo, uint8_t const * p_byte_array, uint32_t * p_size) { VERIFY_PARAM_NOT_NULL(p_fifo); VERIFY_PARAM_NOT_NULL(p_size); const uint32_t available_count = p_fifo->buf_size_mask - fifo_length(p_fifo) + 1; const uint32_t requested_len = (*p_size); uint32_t index = 0; uint32_t write_size = MIN(requested_len, available_count); (*p_size) = available_count; // Check if the FIFO is FULL. if (available_count == 0) { return NRF_ERROR_NO_MEM; } // Check if application has requested only the size. if (p_byte_array == NULL) { return NRF_SUCCESS; } //Fetch bytes from the FIFO. while (index < write_size) { fifo_put(p_fifo, p_byte_array[index++]); } (*p_size) = write_size; return NRF_SUCCESS; }
/** * @fn void interrupt ISR_handle(void) * @brief * * @param none * @return nothing */ void interrupt ISR_handle(void) { uint8_t ui8_slave_state = 0; uint8_t ui8_i2c_value = 0; if(SSPIF == 1) { SSPIF = 0; // Reset IRQ flag i2c_slave_state(&ui8_slave_state); if((ui8_slave_state == 1) || (ui8_slave_state == 3)) { i2c_slave_read(); // Read SSPBUF to clear BF bit but don't care about returned value gui8_recv_byte_idx = 0; gui8_frame_recv_size = 0; } else if(ui8_slave_state == 2) { ui8_i2c_value = i2c_slave_read(); // Read SSPBUF to clear BF bit and read data from master fifo_put(ui8_i2c_value); // copy frame size byte if(gui8_recv_byte_idx == 1) { gui8_frame_recv_size = ui8_i2c_value - 1; } /* else nothing to do */ // indicate that is the last byte received if((gui8_frame_recv_size == gui8_recv_byte_idx) && (gui8_recv_byte_idx != 0)) { gui8_token ++; // increase the number of frames received } /* else nothing to do */ gui8_recv_byte_idx ++; } /* else nothing to do */ CKP = 1; } /* else nothing to do */ }
int C_put_fifo (int argc, char **argv) { int value = 0; int i = 1; /* value start index in argv */ if (_G_p_fifo == NULL) { _G_p_fifo = fifo_create (_FIFO_NUM, sizeof (int)); } /* create FIFO failed */ if (_G_p_fifo == NULL) { serial_printf("Create FIFO failed!"); return CMD_ERROR; } /* read the put values */ for (; i < argc; i++) { value = 0; sscanf (argv[i], "%d", (unsigned int *)&value); if (fifo_put (_G_p_fifo, &value) == OS_STATUS_ERROR) { serial_printf("The FIFO is full!"); return CMD_ERROR; } serial_printf("Put: %d\n", value); } serial_printf("The put operation is Done."); return CMD_OK; }
static int serial_write(struct dev *dev, void *buffer, size_t count, blkno_t blkno, int flags) { struct serial_port *sp = (struct serial_port *) dev->privdata; unsigned int n; unsigned char *bufp; if (wait_for_object(&sp->tx_lock, sp->cfg.tx_timeout) < 0) return -ETIMEOUT; bufp = (unsigned char *) buffer; for (n = 0; n < count; n++) { // Wait until tx queue is not full if (wait_for_object(&sp->tx_sem, sp->cfg.tx_timeout) < 0) break; // Insert next char in transmit queue cli(); fifo_put(&sp->txq, *bufp++); sti(); //kprintf("serial: write %02X\n", bufp[-1]); //kprintf("fifo put: h:%d t:%d c:%d\n", sp->txq.head, sp->txq.tail, sp->txq.count); // If transmitter idle then queue a DPC to restart transmission //if (!sp->tx_busy) queue_dpc(&sp->dpc, serial_dpc, sp); // If transmitter idle then restart transmission if (!sp->tx_busy) drain_tx_queue(sp); } release_mutex(&sp->tx_lock); return count; }
int main(int argc, char * argv[]) { unsigned int i = 0; char b[32]; int ret = 0; fifo_t fifo; fifo_init(&fifo); for(i = 0; i < 2600; i++) { if(!fifo_put(&fifo, i + 'a')) { printf("buffer full at %d\n", i); break; } } unsigned int out = -1; unsigned int in = out + 10; printf("%u - %u = %u\n", in, out, in - out); ret = fifo_out(&fifo, b, 7); b[ret] = 0; printf("%d - %s\n", ret, b); }
void interrupt_handler20(int* esp) { timer_t* timer; char ts = 0; io_out8(PIC0_OCW2, 0x60); /* send sign to PIC from IRQ-00 */ ++g_timerctl.count; if (g_timerctl.next > g_timerctl.count) return; /* not the next timeout timer, break */ timer = g_timerctl.timer0; for ( ; ; ) { /* timers are all using, donot need to check flags */ if (timer->timeout > g_timerctl.count) break; /* timeout */ timer->flags = TIMER_FLAGS_ALLOC; if (timer != g_task_timer) fifo_put(timer->fifo, timer->data); else ts = 1; /* g_task_timer timeout */ timer = timer->next; } g_timerctl.timer0 = timer; g_timerctl.next = timer->timeout; /* task switch */ if (0 != ts) task_switch(); }
void fifo__write(fifo_t *fifo,const uint8_t *p_dat,int len) { int i; for(i=0;i<len;i++) { fifo_put(fifo,*(p_dat+i)); } }
/** * Moves the data into an internal buffer and sends it out on the fifo queue * * Here we deal with the difference in buffer sizes between what comes in from the * network, and what we use internally on the gst pipeline [via the fifo queue]. * We keep track of space available, and partially filled buffers as needed. * * \param me source context for the bytes coming in to this element * \param data pointer to the new buffer of data * \param data_size number of bytes to transfer * \param b_last flag telling us that this is the last block of data */ static void process_segment (Gstccnxsrc * me, const guchar * data, const size_t data_size, const gboolean b_last) { size_t start_offset = 0; if (data_size > 0) { start_offset = me->i_pos % CCN_CHUNK_SIZE; if (start_offset > data_size) { GST_LOG_OBJECT (me, "start_offset %zu > data_size %zu", start_offset, data_size); } else { if ((data_size - start_offset) + me->i_bufoffset > CCN_FIFO_BLOCK_SIZE) { /* won't fit in buffer, release the buffer upstream via the fifo queue */ GST_DEBUG ("pushing data"); GST_BUFFER_SIZE (me->buf) = me->i_bufoffset; fifo_put (me, me->buf); me->buf = gst_buffer_new_and_alloc (CCN_FIFO_BLOCK_SIZE); me->i_bufoffset = 0; } /* will fit in buffer */ memcpy (GST_BUFFER_DATA (me->buf) + me->i_bufoffset, data + start_offset, data_size - start_offset); me->i_bufoffset += (data_size - start_offset); } } /* if we're done, indicate so with a 0-byte block, release any buffered data upstream, * and don't express an interest */ if (b_last) { GST_DEBUG ("handling last block"); if (me->i_bufoffset > 0) { // flush out any last bits we had GST_BUFFER_SIZE (me->buf) = me->i_bufoffset; fifo_put (me, me->buf); me->buf = gst_buffer_new_and_alloc (CCN_FIFO_BLOCK_SIZE); me->i_bufoffset = 0; } /* * \todo should emit an eos here instead of the empty buffer */ GST_BUFFER_SIZE (me->buf) = 0; fifo_put (me, me->buf); me->i_bufoffset = 0; } }
void inthandler2c(int *esp) { unsigned char data; data = io_in8(PORT_KEYDATA); //读取数据方式与键盘一样,所以只能到主程序中通过各自的缓冲区判断是鼠标的数据还是键盘的数据 io_out8(PIC1_OCW2,0x64); //必须先通知从PIC的IRQ12已经处理完毕,然后再通知主PIC(从PIC控制IRQ8到15,IRQ12是第4个,所以是0x64) io_out8(PIC0_OCW2,0x62); //因为主从PIC的协调不能靠自己完成,必须由主程序教给他们怎么做 fifo_put(&mouseFIFO, data); }
// ******************************************************************** // copy data to fifo for sending // ******************************************************************** /// copy mem to software fifo for endpoint void _USBNMemFIFO(fifo_t *fifo,char* data,int size) { int i; for(i=0;i<size;i++) { fifo_put (fifo, (char)data[i]); } }
int fifo_roll (fifo_t *f, uint8_t len) { uint8_t i; for (i=0;i<len;i++) fifo_put( f, fifo_get(f) ); return 0; }
// send a char on line int usartPutchar(char c, FILE* f) { uint8_t ret = 0; while (!ret) { ret= fifo_put(&usartTxFifo, c); } UCSR0B |= _BV(UDRIE0); return ret; }
static InterruptMemberNumber hard_irq( InterruptSetMember ISTmember, void *ref_con, UInt32 the_int_count ) { channel_t *ch = channels; /* fixme */ int running, compl_cnt, event; request_t *r; /* Note: Q & A DV 34 explicitly forbids the usage of secondary * interrupts on the page-fault path (it leads to deadlocks). */ /* Note: The OSI call _always_ modifies the return arguments */ if( !OSI_ABlkIRQAck( ch->channel, &compl_cnt, &running, &event ) ) return kIsrIsNotComplete; ch->running = running; if( event ) handle_events( ch ); /* handle overflow buffer */ if( ch->obuf_cnt && compl_cnt - ch->obuf_completion >= 0 ) { if( ch->obuf_dest ) { char *dest = ch->obuf_dest, *src = ch->obuf; int cnt = ch->obuf_cnt; while( cnt-- ) *dest++ = *src++; } /* XXX: insert optimization barrier here */ *(volatile int*)&ch->obuf_cnt = 0; } /* process completions */ while( (r=(request_t*)dequeue(&ch->compl_queue)) ) { IOCommandID cmdID; if( r->req_num - compl_cnt > 0 ) { enqueue_tail( &ch->compl_queue, (queue_el_t*)r ); break; } /* free resources... */ if( r->mem_prepared ) CheckpointIO( r->ioprep.preparationID, 0 ); if( r->ablk_req & (ABLK_READ_REQ | ABLK_WRITE_REQ) ) ((IOParam*)r->pb)->ioActCount = r->xfer_cnt; cmdID = r->cmdID; fifo_put( &ch->free_fifo, (fifo_el_t*)r ); /* ...and complete */ IOCommandIsComplete( cmdID, noErr ); } process_request_queue( ch ); return kIsrIsComplete; }
static void add_interface_status_action(fifo_t* alp_response_fifo, d7ap_session_result_t* d7asp_result) { fifo_put_byte(alp_response_fifo, ALP_OP_RETURN_STATUS + (1 << 6)); fifo_put_byte(alp_response_fifo, ALP_ITF_ID_D7ASP); fifo_put_byte(alp_response_fifo, d7asp_result->channel.channel_header_raw); uint16_t center_freq_index_be = __builtin_bswap16(d7asp_result->channel.center_freq_index); fifo_put(alp_response_fifo, (uint8_t*)¢er_freq_index_be, 2); fifo_put_byte(alp_response_fifo, d7asp_result->rx_level); fifo_put_byte(alp_response_fifo, d7asp_result->link_budget); fifo_put_byte(alp_response_fifo, d7asp_result->target_rx_level); fifo_put_byte(alp_response_fifo, d7asp_result->status.raw); fifo_put_byte(alp_response_fifo, d7asp_result->fifo_token); fifo_put_byte(alp_response_fifo, d7asp_result->seqnr); fifo_put_byte(alp_response_fifo, d7asp_result->response_to); fifo_put_byte(alp_response_fifo, d7asp_result->addressee.ctrl.raw); fifo_put_byte(alp_response_fifo, d7asp_result->addressee.access_class); uint8_t address_len = alp_addressee_id_length(d7asp_result->addressee.ctrl.id_type); fifo_put(alp_response_fifo, d7asp_result->addressee.id, address_len); }
void do_kb_interupt() { char data; PIC_sendEOI(1); //outb(0x61, 0x20); data = inb(KB_DATA); fifo_put(kbFIFO, offset + data); //draw_char(0xe0000000, 1024, 15, 0,0, data); }
uint8_t fifo_transfer (fifo_t *f1, fifo_t *f2, uint8_t len) { uint8_t real_len = f2->count; if (real_len < len) len = real_len; uint8_t i; for (i=0;i<len;i++) fifo_put( f1, fifo_get(f2) ); return len; }
void interrupt_handler21(int* esp) { unsigned char data; io_out8(PIC0_OCW2, 0x61); /* call PIC that IRQ-01 is finished */ data = io_in8(PORT_KEYDATA); fifo_put(&g_keybuf, data); }
uint32_t app_fifo_put(app_fifo_t * p_fifo, uint8_t byte) { if (FIFO_LENGTH() <= p_fifo->buf_size_mask) { fifo_put(p_fifo, byte); return NRF_SUCCESS; } return NRF_ERROR_NO_MEM; }
void keywindow_off(LAYER *key_to_window) { //先改变这个窗口的标题栏的状态 change_titlebar(key_to_window, 0); //如果是应用窗口的话,它的flags的0x20位设置成1了;应用窗口是不需要显示光标的 if(0 != (key_to_window->flags & 0x20)) { fifo_put(&key_to_window->task->fifo, 3); //命令行窗口的光标OFF掉,因为当前是应用程序窗口在接收键盘输入 } return ; }
uint8_t fifo_put_var_p (fifo_t *f, const uint8_t *data, uint8_t len) { uint8_t i, ret = 0; for (i=0;i < len; i++) { ret = fifo_put (f, pgm_read_byte(data++)); if (ret == 0) return ret; } return ret; }