Changes between Version 43 and Version 44 of AS6-TME-B5


Ignore:
Timestamp:
Feb 22, 2022, 5:48:55 PM (3 years ago)
Author:
franck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AS6-TME-B5

    v43 v44  
    550550 [[Image(htdocs:img/FIFO_TTY.png,nolink,width=400)]]
    551551
    552 Pour implémenter la FIFO, nous allons utiliser un tableau circulaire et des pointeurs
    553 {{{#!c
     552Pour implémenter la FIFO, nous allons utiliser un tableau circulaire et des pointeurs. Il y a une structure et 2 fonctions d'accès.
     553{{{#!c
     554/**
     555/**
     556 * Simple fifo (1 writer - 1 reader)
     557 *   - data      buffer of data
     558 *   - pt_write  write pointer for L fifos (0 at the beginning)
     559 *   - pt_read   read pointer for L fifos (0 at the beginning)
     560 *
     561 * data[] is used as a circular array. At the beginning (pt_read == pt_write) means an empty fifo
     562 * then when we push a data, we write it at pt_write, the we increment pt_write % fifo_size.
     563 * The fifo is full when it remains only one free cell, then when (pt_write + 1)%size == pt_read
     564 */
    554565struct tty_fifo_s {
    555566        char data [20];
    556         int  pt_read;
    557         int  pt_write;
     567        int  pt_read;        // points to the cell to read   
     568        int  pt_write;       // points to the cell to write
    558569};
    559570/**
     
    565576static int tty_fifo_push (struct tty_fifo_s *fifo, int c)
    566577{
     578  // écrire le code de push
    567579}
    568580/**
     
    574586static int tty_fifo_pull (struct tty_fifo_s *fifo, int *c)
    575587{
    576 }
    577 }}}
    578 
    579 Les schémas ci-dessous
     588    if (fifo->pt_read != fifo->pt_write) {
     589        *c = fifo->data [fifo->pt_read];
     590        fifo->pt_read = (fifo->pt_read + 1)% sizeof(fifo->data);
     591        return 1;
     592    }
     593    return 0;
     594}
     595}}}
     596
     597Les schémas ci-dessous le comportement de la FIFO.
     5981. A l'initialisation comme la structure est dans les variables globales, les pointeur `pt_read` et `pt_write` sont à 0. La fifo est vide puisque `pt_read == pt_write`.
     5991. On écrit `A` et on incrémente `pt_write`, `pt_read` ne bouge pas puisque l'on de lit pas.
     6001. On écrit `B` et `C`.
     6011. On lit `A` et on incrémente `pt_read`, on peut lire parce que `pt_read != pt_write` et donc la FIFO n'est pas vide
     6021. On écrit `D` et `E`. Lors de l'incrément de `pt_write` on revient à 0 à cause du modulo `size`
     6031. On écrit `F` et ce sera fini parce la fifo est pleine `(pt_write + 1)%size == pt_read`, si on veut écrire à nouveau, il faut lire.
     604
    580605 [[Image(htdocs:img/FIFO.png,nolink,width=600)]]
    581606
     607
    582608{{{#!protected
    583609{{{#!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  */
    590610static int tty_fifo_push (struct tty_fifo_s *fifo, int c)
    591611{
     
    598618    return 0;
    599619}
    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 }}}
     620}}}
     621}}}
     622