Platform/ECM3532/M3/framework/serial_proto/src/serial_proto.c
/**
 * form and send Data packet
 *
 * @param buf data pointer
 * @param dataLen data length
 * @return 0 on success, non-zero error code on failure
 *
 */
form and send Data packet
@param buf data pointer
@param dataLen data length
@return 0 on success, non-zero error code on failure
form and send Data packet @param buf data pointer @param dataLen data length @return 0 on success non - zero error code on failure
int sendData(uint8_t *buf, uint16_t dataLen)
{
  uint16_t pktLen, pktCnt, pktOffset = 0;
  static uint16_t pktSeq = 0;
  uint8_t reXmit = 0, mod;
  uint8_t *bufIdxPtr;
  bool waitForRsp = 0;
  if (!buf || !dataLen)
    return -EINVAL;
  mod  = dataLen % CONFIG_DATA_PKT_LEN;
  pktCnt  =  dataLen / CONFIG_DATA_PKT_LEN;
  if (mod)
  {
    pktCnt++;
  }
  else
  {
    mod = CONFIG_DATA_PKT_LEN;
  }
  xSemaphoreTake(spDev.xSPLock, portMAX_DELAY);
  spDev.st = DATA_ST;
  do
  {
    if (dataLen > CONFIG_DATA_PKT_LEN)
    {
      pktLen =  CONFIG_DATA_PKT_LEN;
    }
    else
    {
      pktLen =  dataLen;
#ifdef CONFIG_DATA_CRC_CHECK
      waitForRsp = 1;
#endif
    }
    bufIdxPtr = buf + (pktOffset * CONFIG_DATA_PKT_LEN);
    sendDataPkt(bufIdxPtr, pktLen, waitForRsp, pktSeq, pktOffset++);
#ifdef CONFIG_DATA_CRC_CHECK
    if (waitForRsp)
    {
      xSemaphoreTake(spDev.xRespLock, portMAX_DELAY);
      if ((spDev.dataResp.respVal == CRC_FAIL))
      {
        reXmit = 1;
      }
    }
    else  if (xSemaphoreTake(spDev.xRespLock, 0) == pdTRUE)
    {
      if ((spDev.pendResp) && (spDev.dataResp.respVal == CRC_FAIL))
      {
        ecm35xx_printf("Asysc Resp recv for DATA Pkt\r\n");
        reXmit = 1;
      }
    }
    if (reXmit && (spDev.dataResp.pktOffSet < pktCnt))
    {
      pktOffset = spDev.dataResp.pktOffSet;
      reXmit = 0;
      spDev.pendResp = 0;
    }
#endif
    dataLen =  ((pktCnt - (pktOffset + 1)) * CONFIG_DATA_PKT_LEN) + mod;
  } while (pktOffset <  pktCnt);
  spDev.st = DONE;
  ecm35xx_printf("sent data pkt seq %d \r\n", pktSeq);
  pktSeq++;
  xSemaphoreGive(spDev.xSPLock);
  return  0;
}
int sendData ( uint8_t * buf , uint16_t dataLen ) { uint16_t pktLen , pktCnt , pktOffset = 0 ; static uint16_t pktSeq = 0 ; uint8_t reXmit = 0 , mod ; uint8_t * bufIdxPtr ; bool waitForRsp = 0 ; if ( ! buf || ! dataLen ) return - EINVAL ; mod = dataLen % CONFIG_DATA_PKT_LEN ; pktCnt = dataLen / CONFIG_DATA_PKT_LEN ; if ( mod ) { pktCnt ++ ; } else { mod = CONFIG_DATA_PKT_LEN ; } xSemaphoreTake ( spDev . xSPLock , portMAX_DELAY ) ; spDev . st = DATA_ST ; do { if ( dataLen > CONFIG_DATA_PKT_LEN ) { pktLen = CONFIG_DATA_PKT_LEN ; } else { pktLen = dataLen ; #ifdef CONFIG_DATA_CRC_CHECK waitForRsp = 1 ; #endif } bufIdxPtr = buf + ( pktOffset * CONFIG_DATA_PKT_LEN ) ; sendDataPkt ( bufIdxPtr , pktLen , waitForRsp , pktSeq , pktOffset ++ ) ; #ifdef CONFIG_DATA_CRC_CHECK if ( waitForRsp ) { xSemaphoreTake ( spDev . xRespLock , portMAX_DELAY ) ; if ( ( spDev . dataResp . respVal == CRC_FAIL ) ) { reXmit = 1 ; } } else if ( xSemaphoreTake ( spDev . xRespLock , 0 ) == pdTRUE ) { if ( ( spDev . pendResp ) && ( spDev . dataResp . respVal == CRC_FAIL ) ) { ecm35xx_printf ( " \r \n " ) ; reXmit = 1 ; } } if ( reXmit && ( spDev . dataResp . pktOffSet < pktCnt ) ) { pktOffset = spDev . dataResp . pktOffSet ; reXmit = 0 ; spDev . pendResp = 0 ; } #endif dataLen = ( ( pktCnt - ( pktOffset + 1 ) ) * CONFIG_DATA_PKT_LEN ) + mod ; } while ( pktOffset < pktCnt ) ; spDev . st = DONE ; ecm35xx_printf ( " \r \n " , pktSeq ) ; pktSeq ++ ; xSemaphoreGive ( spDev . xSPLock ) ; return 0 ; }
form and send Data packet
 @param buf data pointer
 @param dataLen data length
 @return 0 on success, non-zero error code on failure
form and send Data packet @param buf data pointer @param dataLen data length @return 0 on success non - zero error code on failure
/**
   * last packet to be xmit will be == mod
   */ /**
   * last packet to be xmit will be always mod, assing moe to packet lenght
   * when mod is actually zero, to have come code for both case
   */ /* last packet in seq, request for response */ /*Sync Respose of Datapacket */ /*Asysc Respose of Datapacket, check if response is recv without waiting for
     * it
     * */