\begin{tikzpicture}

  %Kompatibilita mezi babel a TIKZ |-
  \shorthandoff{-}

  \tikzstyle{block}=[draw, text centered]
  \tikzstyle{cnts}=[block, text width=8em]

  \node(0,0) [cnts] (RCNT) {Řádkový čítač}
    node[cnts,below of=RCNT] (CCNT) {Sloupcový čítač}
    node[cnts, dashed, below of=CCNT, node distance=3em] (WCNT) {Čítač délky datového slova}
    node[cnts, dashed, below of=WCNT, minimum height=3em, node distance=4em] (CTRL) {Řízení}
    node[cnts, dashed, below of=CTRL, node distance=3em] (MC) {Mikrokód}
    node[below of=MC] (C) {Řízení BIST kontroléru};

  \draw[<->] (CCNT.west) to[short, -*] ++(-0.2,0) |- (RCNT.west);
  \draw[->]  (CCNT.west)+(-0.2,0) |- (CTRL.170);
  \draw[<->] (CTRL.-170) -- ++(-1.2,0) node[above, text width=4em] {Řídicí rozhraní};
  %{BISTE,\newline FAIL,\newline DONE,\newline CLK\_DLY,\newline \dots};
  \draw[<->] (WCNT.south) -- (CTRL.north);
  \draw[->]  (MC.north) -- (CTRL.south);

  \path (RCNT.north west)+(-0.4,+0.2) node (a){};
  \path (C.south -| CTRL.east)+(+0.4,-0.2) node (b){};
  \path[draw=black] (a) rectangle (b);

  \draw[-] (RCNT.east) -- ++(0.2,0) |- (CTRL.east)
           (CCNT.east) to[short, -*] ++(.2,0) |- (CTRL.east)
           (CTRL.east) to[short, -*] ++(.2,0);   

  \def\mai[#1][#2][#3][#4]{
    \draw #1 node [anchor=west] (ANCHOR#2) { };
   
    \tikzstyle{MaiBlock}=[block, dashed, minimum width=10em, anchor=west]
 
    \draw (ANCHOR#2.south west)+(-0.25,-0.25) node [MaiBlock] (DATACMP#2) {Komparátor test. dat};
    \draw (ANCHOR#2.north west)+(-0.25, 0.25) node [MaiBlock] (DATAGEN#2) {Generátor test. dat};
    
    \draw (ANCHOR#2.east -| DATACMP#2.east)+(0.25,0) node [block, dashed, anchor=west, minimum height=2*(\heightof{KG}+2*2mm)+0.5] (MUX#2) {MUX};

    \draw [->] (DATAGEN#2.east) -- ( DATAGEN#2.east -| MUX#2.west)
               (DATACMP#2.east -| MUX#2.west) -- (DATACMP#2.east);

    \path [draw=black#3] (DATAGEN#2.north west)+(-0.25, 0.75) rectangle 
                       ($(MUX#2.south east)+(0.25, -0.25)$);

    \draw (DATAGEN#2.north west)+(-0.25, 0.75) node [anchor=north west] (MAI#2) {Interface paměti (MAI) #4};

    \draw[<->] (DATAGEN#2.east -| MUX#2.east) -- ++(0.9,0) node[above] {Paměť};
    \draw[<->] (DATACMP#2.east -| MUX#2.east) -- ++(0.9,0) node[below] {Digitál};
  }

  \mai[(RCNT)+(4,-0.7)][1][][]
  \mai[(CTRL)+(4,-0.3)][2][,dotted][ (opt.)]


  \draw[->] (CTRL.east) -- ++(0.9,0) |- ($(ANCHOR1.west)+(-0.5,0)$) node [near start, right] (TS2MAI){TS2MAI};
  \draw[->] (CTRL.east) to [short, -*] ++(0.9,0) |- ($(ANCHOR2.west)+(-0.5,0)$);

  \draw[->] (DATACMP1.south)+(0,-0.25) -- ($(DATAGEN2.north)+(0,0.75)$) node[midway, right] (MAI2MAI) {MAI2MAI};

  \draw[->] ($(CTRL.east)+(0,0.2)$)
            -- ++(0.7,0)
            -- (DATAGEN1.north -| \currentcoordinate)
            -- ++ (0, 1)
            -| ($(DATAGEN1.north)+(0,0.75)$);

  \draw[->] ($(DATACMP2.south) + (0,-0.25)$)
            -- ++ (0,-1)
            -| ($(CTRL.east)+(0.7,-0.2)$)
            -- ($(CTRL.east)+(0,-0.2)$);

\end{tikzpicture}
