| 552 | | |
| 553 | | [[Image(htdocs:img/FIFO.png,nolink,width=600)]] |
| | 552 | Pour implémenter la FIFO, nous allons utiliser un tableau circulaire et des pointeurs |
| | 553 | {{{#!c |
| | 554 | struct tty_fifo_s { |
| | 555 | char data [20]; |
| | 556 | int pt_read; |
| | 557 | int pt_write; |
| | 558 | }; |
| | 559 | /** |
| | 560 | * \brief write to the FIFO |
| | 561 | * \param fifo structure of fifo to store data |
| | 562 | * \param c char to write |
| | 563 | * \return 1 on success, 0 on fealure |
| | 564 | */ |
| | 565 | static int tty_fifo_push (struct tty_fifo_s *fifo, int c) |
| | 566 | { |
| | 567 | } |
| | 568 | /** |
| | 569 | * \brief read from the FIFO |
| | 570 | * \param fifo structure of fifo to store data |
| | 571 | * \param c pointer on char to put the read char |
| | 572 | * \return 1 on success, 0 on fealure |
| | 573 | */ |
| | 574 | static int tty_fifo_pull (struct tty_fifo_s *fifo, int *c) |
| | 575 | { |
| | 576 | } |
| | 577 | }}} |
| | 578 | |
| | 579 | Les schémas ci-dessous |
| | 580 | [[Image(htdocs:img/FIFO.png,nolink,width=600)]] |
| | 581 | |
| | 582 | {{{#!protected |
| | 583 | {{{#!c |
| | 584 | /** |
| | 585 | * \brief write to the FIFO |
| | 586 | * \param fifo structure of fifo to store data |
| | 587 | * \param c char to write |
| | 588 | * \return 1 on success, 0 on fealure |
| | 589 | */ |
| | 590 | static int tty_fifo_push (struct tty_fifo_s *fifo, int c) |
| | 591 | { |
| | 592 | int pt_write_next = (fifo->pt_write + 1) % sizeof(fifo->data); |
| | 593 | if (pt_write_next != fifo->pt_read) { |
| | 594 | fifo->data [fifo->pt_write] = c; |
| | 595 | fifo->pt_write = pt_write_next; |
| | 596 | return 1; |
| | 597 | } |
| | 598 | return 0; |
| | 599 | } |
| | 600 | |
| | 601 | /** |
| | 602 | * \brief read from the FIFO |
| | 603 | * \param fifo structure of fifo to store data |
| | 604 | * \param c pointer on char to put the read char |
| | 605 | * \return 1 on success, 0 on fealure |
| | 606 | */ |
| | 607 | static int tty_fifo_pull (struct tty_fifo_s *fifo, int *c) |
| | 608 | { |
| | 609 | if (fifo->pt_read != fifo->pt_write) { |
| | 610 | *c = fifo->data [fifo->pt_read]; |
| | 611 | fifo->pt_read = (fifo->pt_read + 1)% sizeof(fifo->data); |
| | 612 | return 1; |
| | 613 | } |
| | 614 | return 0; |
| | 615 | } |
| | 616 | }}} |
| | 617 | }}} |