J1939 Documentation
Version 4.16.00
Loading...
Searching...
No Matches
Complete list of callbacks

//====================================================================================================================//
// File: j1939_user.c //
// Description: Application specific functions for J1939 stack //
// //
// Copyright (C) MicroControl GmbH & Co. KG //
// 53844 Troisdorf - Germany //
// www.microcontrol.net //
// //
//--------------------------------------------------------------------------------------------------------------------//
// The copyright to the computer program(s) herein is the property of MicroControl GmbH & Co. KG, Germany. The //
// program(s) may be used and/or copied only with the written permission of MicroControl GmbH & Co. KG or in //
// accordance with the terms and conditions stipulated in the agreement/contract under which the program(s) have //
// been supplied. //
// //
//====================================================================================================================//
/*--------------------------------------------------------------------------------------------------------------------*\
** IMPORTANT NOTE **
** This file provides a template for all functions that need to be adopted to YOUR hardware. Copy this file to **
** <myfile.c> and make your changes in the new file. **
\*--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------*\
** Include files **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
#include "j1939_diag.h" // J1939 diagnosis
#include "j1939_diag_mem.h" // J1939 diagnosis
#include "j1939_mgr.h" // J1939 manager
#include "j1939_msg.h" // J1939 message handling
#include "j1939_nmt.h" // J1939 network management
#include "j1939_pgn.h" // J1939 PGN support
#include "j1939_tmr.h" // J1939 timer support
/*--------------------------------------------------------------------------------------------------------------------*\
** Functions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//--------------------------------------------------------------------------------------------------------------------//
// J1939_DiagHoldEvent() //
// //
//--------------------------------------------------------------------------------------------------------------------//
void J1939_DiagHoldEvent(uint8_t ubNetV, uint8_t ubBroadcastSignalV)
{
if (ubBroadcastSignalV == eJ1939_BROADCAST_START)
{
//-------------------------------------------------------------------------------------------
// re-start DM01 transmission
//
(void) J1939_PgnSetCounter(ubNetV, 65226, 1);
}
if (ubBroadcastSignalV == eJ1939_BROADCAST_STOP)
{
//-------------------------------------------------------------------------------------------
// suspend DM01 transmission for 6 seconds
//
(void) J1939_PgnSetCounter(ubNetV, 65226, J1939_TmrCalcTicks(6000));
}
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_DiagMemRequest() //
// //
//--------------------------------------------------------------------------------------------------------------------//
void J1939_DiagMemRequest(uint8_t ubNetV, uint8_t ubSrcAddrV, J1939_MemAccess_ts * ptsMemoryV)
{
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_MgrEventRcvTimeout() //
// Handler for reception timeout condition //
//--------------------------------------------------------------------------------------------------------------------//
void J1939_MgrEventRcvTimeout(uint8_t ubNetV, uint32_t ulPgnV)
{
//---------------------------------------------------------------------------------------------------
// example for handling of PGN timeouts
//
switch (ulPgnV)
{
case 100:
//--------------------------------------
// handle timeout condition
break;
case 65260:
//--------------------------------------
// handle timeout condition
break;
default:
//--------------------------------------
// handle timeout condition
break;
}
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_MgrOnBusOff() //
// Handler for Bus-Off condition //
//--------------------------------------------------------------------------------------------------------------------//
void J1939_MgrOnBusOff(uint8_t ubNetV)
{
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_NmtEventClaimAddess() //
// handle address claim messages of other nodes //
//--------------------------------------------------------------------------------------------------------------------//
void J1939_NmtEventClaimAddess(uint8_t ubNetV, uint8_t ubSrcAddrV, uint8_t * pubDataV)
{
uint8_t aubNameT[8];
uint8_t ubCntT;
//---------------------------------------------------------------------------------------------------
// ubSrcAddrV - ID of claiming node
// pubDataV - pointer to 8 bytes of NAME
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
// example: check for a specific ECU at address 0
//
if(ubSrcAddrV == 0)
{
for(ubCntT = 0; ubCntT < 8; ubCntT++)
{
aubNameT[ubCntT] = *pubDataV;
pubDataV++;
}
//-------------------------------------------------------------------------------------------
// check the NAME value
//
if (aubNameT[0] == 0x43)
{
}
}
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_NmtGetApplicationName() //
// overwrite NAME value by application //
//--------------------------------------------------------------------------------------------------------------------//
{
//---------------------------------------------------------------------------------------------------
// returning a NULL pointer denotes to use the pre-defined values
//
return ((J1939_Name_ts *) 0L);
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_NmtGetIdentityNumber() //
// read identity number (21 bit value) //
//--------------------------------------------------------------------------------------------------------------------//
uint32_t J1939_NmtGetIdentityNumber(uint8_t ubNetV)
{
uint32_t ulIdentityT;
//---------------------------------------------------------------------------------------------------
// setup identity value, e.g. read from EEPROM
//
ulIdentityT = 0x00223456;
//---------------------------------------------------------------------------------------------------
// make sure that only 21 bit are valid
//
ulIdentityT = ulIdentityT & 0x001FFFFF;
return (ulIdentityT);
}
//--------------------------------------------------------------------------------------------------------------------//
// J1939_NmtGetNewAddress() //
// setup a new address //
//--------------------------------------------------------------------------------------------------------------------//
uint8_t J1939_NmtGetNewAddress(uint8_t ubNetV, uint8_t ubCurrentAddressV)
{
//---------------------------------------------------------------------------------------------------
// this demo adds the value 2 to the current address
//
return (ubCurrentAddressV + 2);
}
J1939 Diagnostic Functions .
@ eJ1939_BROADCAST_START
Definition j1939_diag.h:92
@ eJ1939_BROADCAST_STOP
Definition j1939_diag.h:89
void J1939_DiagHoldEvent(uint8_t ubNetV, uint8_t ubBroadcastSignalV)
J1939 Management Functions .
void J1939_MgrEventRcvTimeout(uint8_t ubNetV, uint32_t ulPgnV)
void J1939_MgrOnBusOff(uint8_t ubNetV)
J1939 Identifier calculation functions .
J1939 Network management .
uint32_t J1939_NmtGetIdentityNumber(uint8_t ubNetV)
void J1939_NmtEventClaimAddess(uint8_t ubNetV, uint8_t ubSrcAddrV, uint8_t *pubDataV)
J1939_Name_ts * J1939_NmtGetApplicationName(uint8_t ubNetV)
uint8_t J1939_NmtGetNewAddress(uint8_t ubNetV, uint8_t ubCurrentAddressV)
J1939 Parameter Groups .
J1939 timing functions .
uint16_t J1939_TmrCalcTicks(uint16_t uwReqTimingV)
Calculate number of timer ticks.
Access to ECU NAME.
Definition j1939_nmt.h:69