J1939 Documentation
Version 4.16.00
Loading...
Searching...
No Matches
Complete Startup Process

//====================================================================================================================//
// File: j1939_main.c //
// Description: Example for integration of 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. //
// //
//====================================================================================================================//
/*--------------------------------------------------------------------------------------------------------------------*\
** Include files **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------------------------------
// J1939 header files
//
#include "j1939_pgn.h"
#include "j1939_mgr.h"
#include "j1939_tmr.h"
//------------------------------------------------------------------------------------------------------
// HAL header files
//
#include "mc_cpu.h"
#include "mc_tmr.h"
#include "mc_tmr.h"
#include "mc_wdt.h"
//------------------------------------------------------------------------------------------------------
// J1939 demo application
//
#include "j1939_demo_app.h"
/*--------------------------------------------------------------------------------------------------------------------*\
** Definitions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
#ifndef TMPL_J1939_ADDRESS
#define TMPL_J1939_ADDRESS 0
#endif
#ifndef TMPL_J1939_TEST_MAIN
#define TMPL_J1939_TEST_MAIN 0
#endif
#ifndef TMPL_J1939_USE_CAN_IF
#define TMPL_J1939_USE_CAN_IF eCP_CHANNEL_1
#endif
//--------------------------------------------------------------------------------------------------------------------//
// main() //
// //
//--------------------------------------------------------------------------------------------------------------------//
int main(void)
{
uint32_t ulLastTimerTickT = 0; // value from timer tick
//---------------------------------------------------------------------------------------------------
// Initialise the target CPU
//
//---------------------------------------------------------------------------------------------------
// Initialise the timer resource on the target CPU
//
//---------------------------------------------------------------------------------------------------
// Initialise the J1939 stack on ECU address 0
// Attach physical CAN channel defined by TMPL_J1939_USE_CAN_IF to logical J1939 channel 1
//
J1939_MgrInit(TMPL_J1939_USE_CAN_IF, eJ1939_NET_1, TMPL_J1939_ADDRESS, J1939_CONF_BITRATE_250K);
//---------------------------------------------------------------------------------------------------
// Initialise the J1939 demo application, this is individual for every target
//
//---------------------------------------------------------------------------------------------------
// Initialise the watchdog timer on the target CPU
//
//---------------------------------------------------------------------------------------------------
// start the J1939 stack
//
//---------------------------------------------------------------------------------------------------
// this is the main loop of the embedded application
//
while (1)
{
//-------------------------------------------------------------------------------------------
// handle timer tick for the stack, we assume a 1 ms timer tick here
//
if ((McTmrTick() - ulLastTimerTickT) > 0)
{
ulLastTimerTickT = McTmrTick();
}
//-------------------------------------------------------------------------------------------
// check the result of the J1939 manager call
//
{
//-----------------------------------------------------------------------------------
// trigger the watch-dog timer each time we run successful through the loop
//
}
else
{
//-----------------------------------------------------------------------------------
// Release all CAN resources and wait for the watchdog timer to restart the
// application
//
}
//-------------------------------------------------------------------------------------------
// The following code is for automatic testing only
//
#if TMPL_J1939_TEST_MAIN > 0
static uint32_t ulTestMainCounterS = TMPL_J1939_TEST_MAIN;
if (ulTestMainCounterS == 0) break;
ulTestMainCounterS--;
#endif
} // end while (1)
return(0);
}
#define J1939_CONF_BITRATE_250K
Definition j1939_mgr.h:79
@ eJ1939_ERR_RESET
Definition j1939_defs.h:389
@ eJ1939_NET_1
Definition j1939_defs.h:117
J1939 demo application.
void J1939_DemoAppInit(uint8_t ubNetV)
J1939 Management Functions .
J1939_Status_tv J1939_MgrProcess(void)
J1939_Status_tv J1939_MgrInit(uint8_t ubCanIfV, uint8_t ubNetV, uint8_t ubAddressV, uint16_t uwConfigV)
J1939_Status_tv J1939_MgrRelease(uint8_t ubNetV)
J1939_Status_tv J1939_MgrStart(uint8_t ubNetV)
J1939 Parameter Groups .
J1939 timing functions .
void J1939_TmrEvent(void)
Execute Timer-based Services.
MCL - CPU control .
void McCpuInit(void)
MCL - timer control .
uint32_t McTmrTick(void)
Get timer tick.
void McTmrInit(void)
Initialise Timer.
MCL - Watchdog support functions .
void McWdtTrigger(void)
Status_tv McWdtInit(void)
Initialize watchdog.