| | 1 | = Création de l'exemple SplitMsg = |
| | 2 | |
| | 3 | Allez dans un nouveau répertoire pour y créer des fichiers. |
| | 4 | |
| | 5 | == Fichier de description DSX == |
| | 6 | |
| | 7 | Pour celui-ci, choisissez vous-même un nom explicite. |
| | 8 | Ce fichier est le '''fichier de description DSX''' et sera nommé comme tel par la suite. |
| | 9 | |
| | 10 | Collez dedans le texte suivant: |
| | 11 | |
| | 12 | {{{ |
| | 13 | #!/usr/bin/env python |
| | 14 | |
| | 15 | from dsx import * |
| | 16 | |
| | 17 | producer_model = TaskModel( |
| | 18 | 'producer', |
| | 19 | outfifos = ['output'], |
| | 20 | impl = [ |
| | 21 | SwTask('prod_func', |
| | 22 | stack_size = 128, |
| | 23 | sources = ['producer.c']) |
| | 24 | ] ) |
| | 25 | |
| | 26 | consumer_model = TaskModel( |
| | 27 | 'consumer', |
| | 28 | outfifos = ['input'], |
| | 29 | impl = [ |
| | 30 | SwTask('cons_func', |
| | 31 | stack_size = 128, |
| | 32 | sources = ['consumer.c']) |
| | 33 | ] ) |
| | 34 | |
| | 35 | fifo0 = Mwmr('fifo0', 4, 4) |
| | 36 | |
| | 37 | tcg = Tcg( |
| | 38 | Task('prod0', producer_model, |
| | 39 | {'output':fifo0} ), |
| | 40 | Task('cons0', consumer_model, |
| | 41 | {'input':fifo0} ), |
| | 42 | ) |
| | 43 | |
| | 44 | posix = Posix() |
| | 45 | tcg.generate(posix) |
| | 46 | TopMakefile(posix) |
| | 47 | }}} |
| | 48 | |
| | 49 | Important: La ligne {{{#!/usr/bin/env python}}} doit être la ''première ligne'' du fichier. |
| | 50 | |
| | 51 | Rendez ce fichier exécutable |
| | 52 | {{{ |
| | 53 | $ chmod +x le_nom_de_fichier |
| | 54 | }}} |
| | 55 | |
| | 56 | == Fichier producer.c == |
| | 57 | |
| | 58 | Dans {{{producer.c}}}, mettez: |
| | 59 | |
| | 60 | {{{ |
| | 61 | #include <srl.h> |
| | 62 | #include "producer_proto.h" |
| | 63 | |
| | 64 | FUNC(prod_func) |
| | 65 | { |
| | 66 | srl_mwmr_t output = GET_ARG(output); |
| | 67 | char buf[32] = "!dlrow olleH"; |
| | 68 | |
| | 69 | srl_log_printf(NONE, "Sending \"%s\"\n", buf); |
| | 70 | srl_mwmr_write(output, buf, 8); |
| | 71 | } |
| | 72 | }}} |
| | 73 | |
| | 74 | == Fichier consumer.c == |
| | 75 | |
| | 76 | Dans {{{consumer.c}}}, mettez: |
| | 77 | |
| | 78 | {{{ |
| | 79 | #include <srl.h> |
| | 80 | #include "consumer_proto.h" |
| | 81 | |
| | 82 | FUNC(cons_func) |
| | 83 | { |
| | 84 | srl_mwmr_t input = GET_ARG(input); |
| | 85 | char buf_in[32]; |
| | 86 | char buf_out[32]; |
| | 87 | int i, last_char; |
| | 88 | |
| | 89 | srl_mwmr_read(input, buf_in, 8); |
| | 90 | srl_log_printf(NONE, "Received \"%s\"\n", buf_in); |
| | 91 | |
| | 92 | for ( last_char=0; buf_in[last_char]; ++last_char ) |
| | 93 | ; |
| | 94 | for ( i = 0; i<last_char; ++i ) |
| | 95 | buf_out[i] = buf_in[last_char-1-i]; |
| | 96 | buf_out[last_char] = '\0'; |
| | 97 | |
| | 98 | srl_log_printf(NONE, "Most readable when \"%s\"\n", buf_out); |
| | 99 | } |
| | 100 | }}} |