Simple Ping test causing repeating reset


#1

I have constructed a very simple test application that performs the following operations:

  1. Initialize WIP
  2. Open GPRS bearer
  3. Start bearer
  4. Open ping channel, set to ping a fixed IP address 100 times.

When I execute the application on my hardware (SL6087 based design), the unit resets at step 3. Occasionally, it will make it step 4, and even execute several pings prior to resetting, but it has never completed the process.

At startup, I check the adl_InitType_e, and it always indicates Initial Power-On, never Reboot From Exception. I have even verified that there are not backtraces stored on the processor.

Below is the code, the APN and IP address of the host to ping are set as consts at the top of the file.

#include "adl_global.h"
#include "wip.h"

const u16 wm_apmCustomStackSize = 1024 * 3;
const char* APN = "eagle02";
const char* HOST = "140.239.222.43";

void init();
void openBearer();
void startBearer();
void stopBearer();
void connectToServer();
void getFile();
void wipBearerHandler(wip_bearer_t bearer, s8 event, void* context);
void wipPingHandler(wip_event_t* event, void* context);
bool atWIND15ResponseHandler(adl_atUnsolicited_t* atResponse);

wip_bearer_t bearer;
wip_channel_t pingChannel;

void init() {
  TRACE((1, "Initializing WIP library..."));
  s8 resultCode = 0;
  // Initialise the WIP library
  resultCode = wip_netInit();
  if (resultCode != OK) {
    switch (resultCode) {
      case WIP_NET_ERR_NO_MEM:
        TRACE((1, "wip_netInit failed: No Memory"));
        break;
      case WIP_NET_ERR_OPTION:
        TRACE((1, "wip_netInit failed: Invalid Option."));
        break;
      case WIP_NET_ERR_PARAM:
        TRACE((1, "wip_netInit failed: Bad Parameter."));
        break;
      case WIP_NET_ERR_INIT_FAILED:
        TRACE((1, "wip_netInit failed: Initialization Failed."));
        break;
      default:
        TRACE((1, "wip_netInit failed: Unknown error code %d", resultCode));
        break;
    }
  }
}

void openBearer() {
  TRACE((1, "Opening bearer..."));
  s8 resultCode = wip_bearerOpen(&bearer, "GPRS", wipBearerHandler, NULL);
  if (resultCode != 0) {
    switch (resultCode) {
      case WIP_BERR_NO_DEV:
        TRACE((1, "wip_bearerOpen failed: Device does not exist."));
        break;
      case WIP_BERR_ALREADY:
        TRACE((1, "wip_bearerOpen failed: Already open."));
        break;
      case WIP_BERR_NO_IF:
        TRACE((1, "wip_bearerOpen failed: Network interface not available."));
        break;
      case WIP_BERR_NO_HDL:
        TRACE((1, "wip_bearerOpen failed: No free handle."));
        break;
      default:
        TRACE((1, "wip_bearerOpen failed: Unknown error code %d", resultCode));
        break;
    }
  }
}

void startBearer() {
  TRACE((1, "Setting bearer options..."));
  s8 resultCode = wip_bearerSetOpts(bearer, WIP_BOPT_GPRS_APN, APN,
      WIP_BOPT_END);
  if (resultCode < 0) {
    switch (resultCode) {
      case WIP_BERR_BAD_HDL:
        TRACE((1, "Failed to set bearer options - Bad handle."));
        break;
      case WIP_BERR_OPTION:
        TRACE((1, "Failed to set bearer options - Invalid option."));
        break;
      case WIP_BERR_PARAM:
        TRACE((1, "Failed to set bearer options - Invalid option value."));
        break;
      default:
        TRACE((1, "Failed to set bearer options - Unknown error code %d", resultCode));
        break;
    }
    stopBearer();
    return;
  }

  TRACE((1, "Starting bearer..."));
  resultCode = wip_bearerStart(bearer);
  if (resultCode < 0 && resultCode != WIP_BERR_OK_INPROGRESS) {
    switch (resultCode) {
      case WIP_BERR_BAD_HDL:
        TRACE((1, "Failed to start bearer - Bad handle."));
        break;
      case WIP_BERR_BAD_STATE:
        TRACE((1, "Failed to start bearer - Bearer is not stopped."));
        break;
      case WIP_BERR_DEV:
        TRACE((1, "Failed to start bearer - Error from link layer initialization."));
        break;
      default:
        TRACE((1, "Failed to start bearer - Unknown error code %d", resultCode));
        break;
    }
  }
}

void stopBearer() {
  s8 resultCode = wip_bearerStop(bearer);
  if (resultCode < 0) {
    switch (resultCode) {
      case WIP_BERR_BAD_HDL:
        TRACE((1, "Failed to stop bearer - Bad handle."));
        break;
      default:
        TRACE((1, "Failed to stop bearer - Unknown error code %d", resultCode));
        break;
    }
  }
}

void connectToServer() {
  TRACE((1, "Bearer started - connecting to server..."));
  pingChannel = wip_pingCreateOpts(HOST, wipPingHandler, NULL,
      WIP_COPT_REPEAT, 100,
      WIP_COPT_END);
}


void wipBearerHandler(wip_bearer_t bearer, s8 event, void* context) {
  s8 resultCode = 0;
  int errorCode = 0;
  switch (event) {
    case WIP_BEV_CONN_FAILED:
      TRACE((1, "wipBearerHandler - event: Connection Failed - "));
      resultCode = wip_bearerGetOpts(bearer, WIP_BOPT_ERROR, &errorCode,
          WIP_BOPT_END);
      if (resultCode < 0) {
        TRACE((1, "failed to retrieve error code: "));
        switch (resultCode) {
          case WIP_BERR_BAD_HDL:
            TRACE((1, "Bad handle."));
            break;
          case WIP_BERR_OPTION:
            TRACE((1, "Invalid option."));
            break;
          default:
            TRACE((1, "Unknown result code %d", resultCode));
            break;
        }
      }
      else {
        switch (errorCode) {
          case WIP_BERR_LINE_BUSY:
            TRACE((1, "Line busy"));
            break;
          case WIP_BERR_NO_ANSWER:
            TRACE((1, "No answer"));
            break;
          case WIP_BERR_NO_CARRIER:
            TRACE((1, "No Carrier"));
            break;
          case WIP_BERR_NO_SIM:
            TRACE((1, "No SIM"));
            break;
          case WIP_BERR_PIN_NOT_READY:
            TRACE((1, "PIN code not Entered"));
            break;
          case WIP_BERR_GPRS_FAILED:
            TRACE((1, "GPRS setup failure"));
            break;
          case WIP_BERR_PPP_LCP_FAILED:
            TRACE((1, "LCP negotiation failure"));
            break;
          case WIP_BERR_PPP_AUTH_FAILED:
            TRACE((1, "PPP authentication failure"));
            break;
          case WIP_BERR_PPP_IPCP_FAILED:
            TRACE((1, "IPCP negotiation failure"));
            break;
          case WIP_BERR_PPP_LINK_FAILED:
            TRACE((1, "PPP peer not responding to echo requests"));
            break;
          case WIP_BERR_PPP_TERM_REQ:
            TRACE((1, "PPP session terminated by peer"));
            break;
          case WIP_BERR_CALL_REFUSED:
            TRACE((1, "Incoming Call Refused"));
            break;
          default:
            TRACE((1, "Unknown Error Code:  %d", errorCode));
            break;
        }
      }
      break;
    case WIP_BEV_IP_CONNECTED:
      TRACE((1, "wipBearerHandler - event: IP Connected."));
      connectToServer();
      break;
    case WIP_BEV_IP_DISCONNECTED:
      TRACE((1, "wipBearerHandler - event: IP Disconnected: "));
      stopBearer();
      resultCode = wip_bearerGetOpts(bearer, WIP_BOPT_ERROR, &errorCode,
          WIP_BOPT_END);
      if (resultCode < 0) {
        TRACE((1, "Failed to retrieve error code: "));
        switch (resultCode) {
          case WIP_BERR_BAD_HDL:
            TRACE((1, "Bad handle."));
            break;
          case WIP_BERR_OPTION:
            TRACE((1, "Invalid option."));
            break;
          default:
            TRACE((1, "Unknown result code %d", resultCode));
        }
      }
      else {
        switch (errorCode) {
          case WIP_BERR_LINE_BUSY:
            TRACE((1, "Line busy"));
            break;
          case WIP_BERR_NO_ANSWER:
            TRACE((1, "No answer"));
            break;
          case WIP_BERR_NO_CARRIER:
            TRACE((1, "No Carrier"));
            break;
          case WIP_BERR_NO_SIM:
            TRACE((1, "No SIM"));
            break;
          case WIP_BERR_PIN_NOT_READY:
            TRACE((1, "PIN code not Entered"));
            break;
          case WIP_BERR_GPRS_FAILED:
            TRACE((1, "GPRS setup failure"));
            break;
          case WIP_BERR_PPP_LCP_FAILED:
            TRACE((1, "LCP negotiation failure"));
            break;
          case WIP_BERR_PPP_AUTH_FAILED:
            TRACE((1, "PPP authentication failure"));
            break;
          case WIP_BERR_PPP_IPCP_FAILED:
            TRACE((1, "IPCP negotiation failure"));
            break;
          case WIP_BERR_PPP_LINK_FAILED:
            TRACE((1, "PPP peer not responding to echo requests"));
            break;
          case WIP_BERR_PPP_TERM_REQ:
            TRACE((1, "PPP session terminated by peer"));
            break;
          case WIP_BERR_CALL_REFUSED:
            TRACE((1, "Incoming Call Refused"));
            break;
          default:
            TRACE((1, "Unknown Error Code: %d", errorCode));
            break;
        }
      }
      break;
    case WIP_BEV_STOPPED:
      TRACE((1, "wipBearerHandler - event: Stopped."));
      break;
    case WIP_BEV_LINK_STATUS:
      TRACE((1, "wipBearerHandler - event: Link Status."));
      break;
    case WIP_BEV_DRIVER:
      TRACE((1, "wipBearerHandler - event: Driver."));
      break;
    default:
      TRACE((1, "Unknown event: %d", event));
  }
}

void wipPingHandler(wip_event_t* event, void *context) {
  if (event->kind == WIP_CEV_PING) {
    TRACE((1, "Ping channel - ping."));
  }
  else if (event->kind == WIP_CEV_ERROR) {
    TRACE((1, "Ping channel - error."));
  }
}

bool atWIND15ResponseHandler(adl_atUnsolicited_t* atResponse) {
  char* location = strstr(atResponse->StrData, "+WIND: 15");
  if (location != NULL) {
    TRACE((1, "Network ready - beginning GPRS initialization..."));
    init();
    openBearer();
    startBearer();
  }
  return true;
}

void adl_main(adl_InitType_e initType) {
  TRACE((1, "Starting up Ping test client..."));
  switch (initType) {
    case ADL_INIT_POWER_ON:
      TRACE((1, "Initial Power-On."));
      break;
    case ADL_INIT_REBOOT_FROM_EXCEPTION:
      TRACE((1, "Reboot due to Exception."));
      break;
    case ADL_INIT_DOWNLOAD_SUCCESS:
      TRACE((1, "OTA Download Successful."));
      break;
    case ADL_INIT_DOWNLOAD_ERROR:
      TRACE((1, "OTA Download Error."));
      break;
    case ADL_INIT_RTC:
      TRACE((1, "RTC Alarm."));
      break;
    default:
      TRACE((1, "Unknown Initialization Code %d", initType));
      break;
  }
  TRACE((1, "Waiting for network..."));
  adl_atUnSoSubscribe("+WIND", atWIND15ResponseHandler);
}

I am attaching the Developer Studio project in addition to the code above. Does anyone see anything I am obviously doing wrong on the software side, or have I stumbled across a radio firmware issue?

Cory
Ping.zip (759 KB)


#2

Stack size :question:


#3

Which raises a good question, what would a good stack size be? Is there a rule of thumb or calculation methodology I could use to determine this? So far, I have simply increased it when I get an RTK code indicating it is too small, but it sure would be nice to be able to predict it.


#4

Update:

I have successfully executed the test on a development kit, isolating the error to our PCB. The problem appears to be in our power rails.

Cory