Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • bool diagInit(void);

    Code Block
    languagec
    APP_PRINTF("diag: Initializing application...\r\n");

    This line logs the entry into the function

    along with the calling parameters

    .

    Code Block
    languagec
    bool result = false;

    This line initializes the result of the function to false, which means “Failed to init”.

    Code Block
    languagec
    // Allocate and initialize application context
    applicationContext *ctx = (applicationContext *)malloc(sizeof(applicationContext));
    ctx->templateRegistered = false;
    ctx->done = false;
    resetIsrValues(ctx);

    These lines allocate and initialize the values of the portable application context.

    Code Block
    languagec
    // Register the application
    schedAppConfig config = {
        .name = "diagnostic",
        .activationPeriodSecs = 60 * 10,
        .pollPeriodSecs = 5,
        .activateFn = diagActivate,
        .interruptFn = diagISR,
        .pollFn = diagPoll,
        .responseFn = diagResponse,
        .appContext = ctx,
    };

    These lines initialize the application configuration that will be passed to the scheduler.

    Code Block
    languagec
    if (schedRegisterApp(&config) < 0) {
        // Failure
        result = false;
    } else {
        // Success
        result = true;
    }

    These lines will attempt to register the application with the scheduler. On success, an application identifier greater than or equal to zero is returned, otherwise a negative value is returned to indicate registration failure. For basic usage, it is unnecessary to capture the application identifier, because it is returned as the first parameter of each of the callbacks registered by the application.

    Code Block
    languagec
    return result;

    This line returns the result to the caller.

Internal

  • static void addNote(bool immediate);

  • static const char * diagStateName (int state);

    Code Block
    languagec
    switch (state) {
    case STATE_DIAG_ABORT:
        return "STATE_DIAG_ABORT";
    case STATE_DIAG_CHECK:
        return "STATE_DIAG_CHECK";
    case STATE_DIAG_ISR_XFER:
        return "STATE_DIAG_ISR_XFER";
    default:
    {
        static char undefined_state[20];
        schedStateName(state, undefined_state, sizeof(undefined_state));
        return undefined_state;
    }
    }

    The function translates the int value of an application specific state into a const char * description of the state. In the default case, where a state is unrecognized, it will defer to the analogous system API, which will either transcribe the state or simply print the integer's string representation.

  • static bool registerNotefileTemplate();

  • static inline void resetIsrValues(applicationContext *ctx);

    Code Block
    languagec
    APP_PRINTF("diag: resetting ISR values\r\n");

    This line logs the entry into the function.

    Code Block
    languagec
    ctx->isrCount = 0;
    ctx->isrOverflow = false;
    for (size_t i = 0 ; i < ISR_MAX_CALL_RETENTION ; ++i) {
        ctx->isrParams[i].appID = 0;
        ctx->isrParams[i].pins = 0;
    }

    These lines will reset all metadata and parameters related to the ISR.

...