Multithreaded-software/external/soem/oshw/rtk/nicdrv.c
static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert timer)
{
   int wkc  = EC_NOFRAME;
   int wkc2 = EC_NOFRAME;
   int primrx, secrx;

   /* if not in redundant mode then always assume secondary is OK */
   if (port->redstate == ECT_RED_NONE)
   {
      wkc2 = 0;
   }
   do
   {
      /* only read frame if not already in */
      if (wkc <= EC_NOFRAME)
      {
         wkc  = ecx_inframe(port, idx, 0);
      }
      /* only try secondary if in redundant mode */
      if (port->redstate != ECT_RED_NONE)
      {
         /* only read frame if not already in */
         if (wkc2 <= EC_NOFRAME)
            wkc2 = ecx_inframe(port, idx, 1);
      }
   /* wait for both frames to arrive or timeout */
   } while (((wkc <= EC_NOFRAME) || (wkc2 <= EC_NOFRAME)) && (osal_timer_is_expired(&timer) == FALSE));
   /* only do redundant functions when in redundant mode */
   if (port->redstate != ECT_RED_NONE)
   {
      /* primrx if the reveived MAC source on primary socket */
      primrx = 0;
      if (wkc > EC_NOFRAME)
      {
         primrx = port->rxsa[idx];
      }
      /* secrx if the reveived MAC source on psecondary socket */
      secrx = 0;
      if (wkc2 > EC_NOFRAME)
      {
         secrx = port->redport->rxsa[idx];
      }
      /* primary socket got secondary frame and secondary socket got primary frame */
      /* normal situation in redundant mode */
      if ( ((primrx == RX_SEC) && (secrx == RX_PRIM)) )
      {
         /* copy secondary buffer to primary */
         memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
         wkc = wkc2;
      }
      /* primary socket got nothing or primary frame, and secondary socket got secondary frame */
      /* we need to resend TX packet */
      if ( ((primrx == 0) && (secrx == RX_SEC)) ||
           ((primrx == RX_PRIM) && (secrx == RX_SEC)) )
      {
         osal_timert read_timer;

         /* If both primary and secondary have partial connection retransmit the primary received
          * frame over the secondary socket. The result from the secondary received frame is a combined
          * frame that traversed all slaves in standard order. */
         if ( (primrx == RX_PRIM) && (secrx == RX_SEC) )
         {
            /* copy primary rx to tx buffer */
            memcpy(&(port->txbuf[idx][ETH_HEADERSIZE]), &(port->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
         }
         osal_timer_start(&read_timer, EC_TIMEOUTRET);
         /* resend secondary tx */
         ecx_outframe(port, idx, 1);
         do
         {
            /* retrieve frame */
            wkc2 = ecx_inframe(port, idx, 1);
         } while ((wkc2 <= EC_NOFRAME) && (osal_timer_is_expired(&read_timer) == FALSE));
         if (wkc2 > EC_NOFRAME)
         {
            /* copy secondary result to primary rx buffer */
            memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
            wkc = wkc2;
         }
      }
   }

   /* return WKC or EC_NOFRAME */
   return wkc;
}
/** Blocking redundant receive frame function. If redundant mode is not active then
 * it skips the secondary stack and redundancy functions. In redundant mode it waits
 * for both (primary and secondary) frames to come in. The result goes in an decision
 * tree that decides, depending on the route of the packet and its possible missing arrival,
 * how to reroute the original packet to get the data in an other try.
 *
 * @param[in] port        = port context struct
 * @param[in] idx = requested index of frame
 * @param[in] timer = absolute timeout time
 * @return Workcounter if a frame is found with corresponding index, otherwise
 * EC_NOFRAME.
 */
Blocking redundant receive frame function. If redundant mode is not active then
it skips the secondary stack and redundancy functions. In redundant mode it waits
for both (primary and secondary) frames to come in. The result goes in an decision
tree that decides, depending on the route of the packet and its possible missing arrival,
how to reroute the original packet to get the data in an other try.

@param[in] port        = port context struct
@param[in] idx = requested index of frame
@param[in] timer = absolute timeout time
@return Workcounter if a frame is found with corresponding index, otherwise
EC_NOFRAME.
Blocking redundant receive frame function . If redundant mode is not active then it skips the secondary stack and redundancy functions . In redundant mode it waits for both ( primary and secondary ) frames to come in . The result goes in an decision tree that decides depending on the route of the packet and its possible missing arrival how to reroute the original packet to get the data in an other try . @param [ in ] port = port context struct @param [ in ] idx = requested index of frame @param [ in ] timer = absolute timeout time @return Workcounter if a frame is found with corresponding index otherwise EC_NOFRAME .
static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert timer)
{
   int wkc  = EC_NOFRAME;
   int wkc2 = EC_NOFRAME;
   int primrx, secrx;
   if (port->redstate == ECT_RED_NONE)
   {
      wkc2 = 0;
   }
   do
   {
      if (wkc <= EC_NOFRAME)
      {
         wkc  = ecx_inframe(port, idx, 0);
      }
      if (port->redstate != ECT_RED_NONE)
      {
         if (wkc2 <= EC_NOFRAME)
            wkc2 = ecx_inframe(port, idx, 1);
      }
   } while (((wkc <= EC_NOFRAME) || (wkc2 <= EC_NOFRAME)) && (osal_timer_is_expired(&timer) == FALSE));
   if (port->redstate != ECT_RED_NONE)
   {
      primrx = 0;
      if (wkc > EC_NOFRAME)
      {
         primrx = port->rxsa[idx];
      }
      secrx = 0;
      if (wkc2 > EC_NOFRAME)
      {
         secrx = port->redport->rxsa[idx];
      }
      if ( ((primrx == RX_SEC) && (secrx == RX_PRIM)) )
      {
         memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
         wkc = wkc2;
      }
      if ( ((primrx == 0) && (secrx == RX_SEC)) ||
           ((primrx == RX_PRIM) && (secrx == RX_SEC)) )
      {
         osal_timert read_timer;
         if ( (primrx == RX_PRIM) && (secrx == RX_SEC) )
         {
            memcpy(&(port->txbuf[idx][ETH_HEADERSIZE]), &(port->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
         }
         osal_timer_start(&read_timer, EC_TIMEOUTRET);
         ecx_outframe(port, idx, 1);
         do
         {
            wkc2 = ecx_inframe(port, idx, 1);
         } while ((wkc2 <= EC_NOFRAME) && (osal_timer_is_expired(&read_timer) == FALSE));
         if (wkc2 > EC_NOFRAME)
         {
            memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
            wkc = wkc2;
         }
      }
   }
   return wkc;
}
static int ecx_waitinframe_red ( ecx_portt * port , int idx , osal_timert timer ) { int wkc = EC_NOFRAME ; int wkc2 = EC_NOFRAME ; int primrx , secrx ; if ( port -> redstate == ECT_RED_NONE ) { wkc2 = 0 ; } do { if ( wkc <= EC_NOFRAME ) { wkc = ecx_inframe ( port , idx , 0 ) ; } if ( port -> redstate != ECT_RED_NONE ) { if ( wkc2 <= EC_NOFRAME ) wkc2 = ecx_inframe ( port , idx , 1 ) ; } } while ( ( ( wkc <= EC_NOFRAME ) || ( wkc2 <= EC_NOFRAME ) ) && ( osal_timer_is_expired ( & timer ) == FALSE ) ) ; if ( port -> redstate != ECT_RED_NONE ) { primrx = 0 ; if ( wkc > EC_NOFRAME ) { primrx = port -> rxsa [ idx ] ; } secrx = 0 ; if ( wkc2 > EC_NOFRAME ) { secrx = port -> redport -> rxsa [ idx ] ; } if ( ( ( primrx == RX_SEC ) && ( secrx == RX_PRIM ) ) ) { memcpy ( & ( port -> rxbuf [ idx ] ) , & ( port -> redport -> rxbuf [ idx ] ) , port -> txbuflength [ idx ] - ETH_HEADERSIZE ) ; wkc = wkc2 ; } if ( ( ( primrx == 0 ) && ( secrx == RX_SEC ) ) || ( ( primrx == RX_PRIM ) && ( secrx == RX_SEC ) ) ) { osal_timert read_timer ; if ( ( primrx == RX_PRIM ) && ( secrx == RX_SEC ) ) { memcpy ( & ( port -> txbuf [ idx ] [ ETH_HEADERSIZE ] ) , & ( port -> rxbuf [ idx ] ) , port -> txbuflength [ idx ] - ETH_HEADERSIZE ) ; } osal_timer_start ( & read_timer , EC_TIMEOUTRET ) ; ecx_outframe ( port , idx , 1 ) ; do { wkc2 = ecx_inframe ( port , idx , 1 ) ; } while ( ( wkc2 <= EC_NOFRAME ) && ( osal_timer_is_expired ( & read_timer ) == FALSE ) ) ; if ( wkc2 > EC_NOFRAME ) { memcpy ( & ( port -> rxbuf [ idx ] ) , & ( port -> redport -> rxbuf [ idx ] ) , port -> txbuflength [ idx ] - ETH_HEADERSIZE ) ; wkc = wkc2 ; } } } return wkc ; }
Blocking redundant receive frame function.
Blocking redundant receive frame function .
/* if not in redundant mode then always assume secondary is OK */ /* only read frame if not already in */ /* only try secondary if in redundant mode */ /* only read frame if not already in */ /* wait for both frames to arrive or timeout */ /* only do redundant functions when in redundant mode */ /* primrx if the reveived MAC source on primary socket */ /* secrx if the reveived MAC source on psecondary socket */ /* primary socket got secondary frame and secondary socket got primary frame */ /* normal situation in redundant mode */ /* copy secondary buffer to primary */ /* primary socket got nothing or primary frame, and secondary socket got secondary frame */ /* we need to resend TX packet */ /* If both primary and secondary have partial connection retransmit the primary received
          * frame over the secondary socket. The result from the secondary received frame is a combined
          * frame that traversed all slaves in standard order. */ /* copy primary rx to tx buffer */ /* resend secondary tx */ /* retrieve frame */ /* copy secondary result to primary rx buffer */ /* return WKC or EC_NOFRAME */