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


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

--

Legend:

Unmodified
Added
Removed
Modified
  • AS6-TME-B5

    v42 v43  
    546546 [[Image(htdocs:img/IRQTTY_2.png,nolink,width=600)]]
    547547
    548 Le caractère lu est mis dans une structure FIFO (First In First Out). Le schéma ci-dessous illustre le fonctionnement de la fifo
     548Le caractère lu est mis dans une structure FIFO (First In First Out). Le schéma ci-dessous illustre le fonctionnement de la FIFO. Une fifo simple a un écrivain et un lecteur. L'écrivain écrit des données avec une commande `push()` tant que la FIFO n'est pas pleine. Si elle elle pleine, il y a deux comportements possibles : l'écrivain attend de la place ou l'écrivain jette la donnée, ça dépend ce qu'on veut. Ici, on jettera, parce qu'on n'a pas le moyen de ralentir le flux de données (les frappes du clavier). Le lecteur lit les données avec `pull()` tant que la FIFO n'est pas vide.
    549549
    550550 [[Image(htdocs:img/FIFO_TTY.png,nolink,width=400)]]
    551551
    552 
    553 [[Image(htdocs:img/FIFO.png,nolink,width=600)]]
     552Pour implémenter la FIFO, nous allons utiliser un tableau circulaire et des pointeurs
     553{{{#!c
     554struct 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 */
     565static 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 */
     574static int tty_fifo_pull (struct tty_fifo_s *fifo, int *c)
     575{
     576}
     577}}}
     578
     579Les 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 */
     590static 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 */
     607static 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}}}