Add the Target Library to your microcontroller application code

To use ONEinspect, you need at least one communication line where ONEinspect will be able to communicate with your embedded system by using the selected communication protocol. This communication line can be serial port (COM), USB, Ethernet or any other communication media between your embedded system and computer. To implement Basic communication protocol (the one shipped with ONEinspect) into your embedded system, Target Library shipped with ONEinspect can be used. For starters we recommend to use this protocol, later you may implement your own communication protocol and corresponding protocol plugin which can be simply loaded into ONEinspect.

Note: If you already use your custom communication protocol on given communication line (typically UART) then you must adapt the sample protocol plugin which is shipped with ONEinspect. You can either use escape sequences that temporarily disable your own protocol or use techniques such as protocol tunneling (known from TCP/IP communications). Refer to this chapter for more info about communication protocols.

Target Library shipped with ONEinspect implements the Basic communication protocol and can be used to configure both asynchronous lines (eg. interrupt driven UART interfaces) or synchronous lines (eg. polled TCP/IP stacks).

Adding Target Library to interrupt driven UART interface

You can select the Serial port (COM) driver for such communication in ONEinspect.

  1. Add Target Library sources to your project (_lib folder in the Samples). The files are diagnostic.*, diag_arch.*, diag_crc.*, diag_date.*. You may also use the sources from the Samples (folders example/src/lib) that matches your embedded platform or is similar. Include following header file into each module in which you intend to use the Target Library:

#include "diagnostic.h"

  1. Initialize the Target Library by adding following code to your main initialization routine (code being executed once after reset):

diagInit();

  1. Ensure following code is executed in your periodic timer interrupt routine (systick timer or any other periodic timer). The calling period is 10 ms by default (as shown in all Samples) but may be chosen arbitrary (see DIAG_MS2TICKS macro in diag_arch.h):

diagReal();

  1. Declare diagnostic interface handle as static variable:

static DIAG_HANDLE_T diagUart;

  1. Open the diagnostic interface by adding following code to your UART module initialization (code being executed once after reset):

diagUart = diagOpen(INTF_ASYNC);

  1. Insert following code into your UART receive interrupt handler (here we suppose data parameter is the input character read from UART):

diagReceiveAsync(diagUart, data);

  1. Insert following code into your UART transmit interrupt handler (here we suppose UART_REG_TX is the UART transmit register):

uint8_t data;

if (diagSendAsync(diagUart, &data) == DIAG_OK) {

 UART_REG_TX = data;

} else {

 /* disable transmitter */

}

  1. Insert following code into your idle time module handler (code being executed in the forever loop):

uint8_t data;

if (diagProcess(diagUart) == DIAG_OK) {

 /* initiate transmission */

 if (diagSendAsync(diagUart, &data) == DIAG_OK) {

   /* enable transmitter */

   UART_REG_TX = data;

 }

}

  1. Review the configuration in diag_arch.h and diag_arch.c to suit your needs.

Adding Target Library to UDP protocol handler (eg. uIP or lwIP TCP/IP stacks)

You can select the LAN (UDP datagram) driver for such communication in ONEinspect.

  1. This step is the same as above.
  2. This step is the same as above.
  3. This step is the same as above.
  4. Declare diagnostic interface handle as static variable:

static DIAG_HANDLE_T diagUdp;

  1. Open the diagnostic interface by adding following code to your Ethernet module initialization (code being executed once after reset):

diagUdp = diagOpen(INTF_SYNC);

  1. Insert following code into your UDP protocol callback handler (here we suppose uIP TCP/IP stack is used, uip_sappdata points to the received UDP packet payload and uip_datalen() is the size of the UDP packet payload):

uint32_t cnt;

if (diagReceiveSync(diagUdp, (uint8_t *)uip_sappdata, uip_datalen()) == DIAG_OK) {

 if (diagProcess(diagUdp) == DIAG_OK) {

   if (diagSendSync(diagUdp, (uint8_t*)uip_sappdata, &cnt) == DIAG_OK) {

     uip_send_data(uip_sappdata, cnt);

   }

 }

}

  1. Review the configuration in diag_arch.h and diag_arch.c to suit your needs.