⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 task_j1939.c

📁 在Freescale16位单片机MC9s12dp256上移植了J1939源码和操作系统(ucOSII)。
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "includes.h"


#include "PortAB.h"
#include "Types.h"
#include "J1939.h"
//#include "main.h"
#include "JCanCntrl.h"
#include "JTimerDef.h"
#include "JTarget.h"
#include "JBuffer.h"
#include "J1939PGN.h"
#include "J1939TRA.h"
#include "J1939CFG.h"
#include "J1939EXT.h"


static OS_STK  Task_J1939_STK[OS_STK_DEFAULT_SIZE];
#define TASK_J1939_PRIO		0x16 //priority

static unsigned short timeStamp=0;
#define BAUD_RATE 5  /* for 250 kb seet table in "canxxx.c" */

unsigned char gJ1939BootUp = TRUE;
unsigned char bootStep = 0;
unsigned char gEEPROM_Addr;
unsigned short mUsrArray[8] = {0, 8191, 16382, 24573, 32764, 40955, 49146, 57337};
unsigned short mActValue;

/*!
  \brief Callback of the stack to get a configured Address on which it
         can make it's Address Claiming

  The way how the application is spending this address         
  depends 100% to the application (EEPROM, DIP switch or otherwise                                                         
  the stack will never call this callback.
*/
/*!
  \param  -
  \retval Values 0...254; The J1939 device address which was stored in a non
          volatile storage location
*/
unsigned char J1939AppGetAddress(void) /* Callback user-function */
{
  /* [USER DEPENDENT] */
  return gEEPROM_Addr;  /* default node address from dip-switch, eeprom etc. */
} /* J1939AppGetAddress() */


/*!
  \brief Callback function to handle the receiption of a pgn

  This function is called from the stack to signal the application that a
  PG is received. The application can now do something with the receipt data.
  Only allocated pgs will result in a callback. If a PG is not allocated,
  the stack will never call this callback.
*/
/*!
  \param  Pointer to the currently received PG buffer table.
  \retval -
*/
void J1939AppRxIndication(VJ1939PGN* pg) /* Callback user-function */
{
  unsigned short i;
  /* [USER DEPENDENT] */
  /* some user specific handling of the received PG's */
  if(pg == &gRxPGTable[RX_PGN_FE10])
  {
    /* fill in application code here */
    for(i=0;i<gTxPGTable[TX_PGN_FE10].mDataLength;i++)
    {    
      ((struct VJ1939PGN_DATA_FE10*)gTxPGTable[TX_PGN_FE10].mData)->mData[i] = ((struct VJ1939PGN_DATA_FE10*)pg->mData)->mData[i];
    }
    gTxPGTable[TX_PGN_FE10].mPGState = PG_TX_REQ;
  } /* if */
  else if(pg == &gRxPGTable[RX_PGN_FE30])
  {
    /* fill in application code here */
    for(i=0;i<gTxPGTable[TX_PGN_FE30].mDataLength;i++)
    {    
      ((struct VJ1939PGN_DATA_FE30*)gTxPGTable[TX_PGN_FE30].mData)->mData[i] = ((struct VJ1939PGN_DATA_FE30*)pg->mData)->mData[i];
    }
    gTxPGTable[TX_PGN_FE30].mPGState = PG_TX_REQ;
  } /* if */
  else if(pg == &gRxPGTable[RX_PGN_CC00])
  {
    /* fill in application code here */
    for(i=0;i<gTxPGTable[TX_PGN_CC00].mDataLength;i++)
    {    
      ((struct VJ1939PGN_DATA_CC00*)gTxPGTable[TX_PGN_CC00].mData)->mData[i] = ((struct VJ1939PGN_DATA_CC00*)pg->mData)->mData[i];
    }
     gTxPGTable[TX_PGN_CC00].mPGState = PG_TX_REQ;
  } /* if */
  else if(pg == &gRxPGTable[RX_PGN_CB00])
  {
    /* fill in application code here */
    for(i=0;i<gTxPGTable[TX_PGN_CB00].mDataLength;i++)
    {    
      ((struct VJ1939PGN_DATA_CB00*)gTxPGTable[TX_PGN_CB00].mData)->mData[i] = ((struct VJ1939PGN_DATA_CB00*)pg->mData)->mData[i];
    }
    gTxPGTable[TX_PGN_CB00].mPGState = PG_TX_REQ;
  } /* if */
  else
  {
    /* fill in application code here */
  } /* else */
} /* J1939AppRxIndication() */

/*!
  \brief Callback function to handle a timeout of cyclic RX PGNs

  This function is called from the stack to signal the application that a
  PG is timeouted. The application can now something to clear the problem.
  Only allocated and timeouted pgs will result in a callback. If a PG is
  not allocated, the stack will never call this callback.
*/
/*!
  \param  Pointer to the currently timeouted PG buffer table.
  \retval -
*/
void J1939AppRxTimeoutIndication(VJ1939PGN* pg) /* Callback user-function */
{
  /* [USER DEPENDENT] */
  /* do some action on late PG's */
  if (pg == &gRxPGTable[RX_PGN_FE10])
  {
    /* fill application code here */
  }
  else if(pg == &gRxPGTable[RX_PGN_CC00])
  {
    /* fill application code here */
  }
  else
  {/* assert() */}
} /* J1939AppRxTimeoutIndication() */

/*!
  \brief Callback function to handle the J1939 request PG

  This function is called from the stack to signal the application that a  
  PG is requested. The application can now copy new data to the pgn or send
  an acknowledge. Only allocated pgs will result in a callback. If a PG is
  not allocated, the stack will never call this callback.
*/
/*!
  \param  Pointer to the currently requested PG buffer table.
  \retval REQ_SENDPGN:     The requested PGN will be sent by the stack
  \retval REQ_SENDNOTHING: The requested PGN will NOT be sent by the stack
  \retval REQ_SENDNACK:    A negative acknowledge will be sent by the stack
  \retval REQ_SENDPACK:    A positive acknowledge will be sent by the stack
*/
unsigned char J1939AppRequestIndication(VJ1939PGN* pg) /* Callback user-function */
{
  /* [USER DEPENDENT] */
  /* do some application specific, e.g. copy new data */
    if(pg)
    {
      pg = pg;
    }
    return REQ_SENDPGN;  /* send PG! */
} /* J1939AppRequestIndication() */

/*!
  \brief Callback function to handle the J1939 CommandedAddress PG

  This function is called from the stack to signal the application that a 
  new address is assigned to the device. For an normal ECU this should not be happen.
*/
/*!
  \param  Pointer to the received CommandedAddress PG buffer table. The new address
          is stored in the address field of the PG data structure.
  \retval -
*/
void J1939AppCmdAddrIndication(VJ1939PGN* pg) /* Callback user-function */
{
  /* [USER DEPENDENT] */
  /* do some application specific, e.g. copy new data */
  gJ1939BootUp = TRUE;   /* Restart application */
  bootStep = 0;
  gEEPROM_Addr = ((struct VJ1939PGN_DATA_FED8*)pg->mData)->mAddress; /* get new address */
} /* J1939AppCmdAddrIndication() */

/*initilize RxCnxn[] in J1939*/
void InitRxCnxn(void)
{
 gTPRxCnxn[0].mState=BAM_RX_STATE_DATA;
 gTPRxCnxn[0].mSource=0x00;
 gTPRxCnxn[0].mTimer=250;
 gTPRxCnxn[0].mBytes=28;
 gTPRxCnxn[0].mSequence=0;
 gTPRxCnxn[0].mPackets=4;
 gTPRxCnxn[0].mPToSend=0;
 gTPRxCnxn[0].mRxPGTable=11;
}


 void  Task_J1939(void *pdata)
{
   unsigned char i;
   
   pdata=pdata;
 
     gEEPROM_Addr = 1;              /* default device addr. */
     gJ1939BootUp = TRUE;           /* signal first start */
     
     
     
     /*J1939 PGN Initialize*/
      /*PGN_F004  */
     for( i=0;i<8;i++)
     {
     gPGN_DATA_F004.mData[i]=0xFF; 
     }
  
      /*PGN_FEEF*/
     for( i=0;i<8;i++)
     {
      gPGN_DATA_FEEF.mData[i]=0xFF; 
     }
 
     /*PGN_FEEE*/
     for( i=0;i<8;i++)
     {
      gPGN_DATA_FEEE.mData[i]=0xFF; 
     }
 
      /*PGN_FEC0*/
     for( i=0;i<8;i++)
     {
      gPGN_DATA_FEC0.mData[i]=0xFF; 
     }
     
      /*PGN_FE6C*/
     for( i=0;i<8;i++)
     {
      gPGN_DATA_FE6C.mData[i]=0xFF; 
     }
     
      /*PGN_FEE6*/
     for( i=0;i<8;i++)
     {
      gPGN_DATA_FEE6.mData[i]=0xFF; 
     }
     
      /*PGN_FEC1*/
     for( i=0;i<8;i++)
     {
      gPGN_DATA_FEC1.mData[i]=0xFF; 
     }                   
     
     
 /* initialize timers for J1939 , not used because of using ostick*/
     //Tim_InitTimer(BASIC_TIME);
     //Tim_StartTimer();
     
     /* initialize CAN module data structures */
     gCan_Init();
     gCan_CntrlInit(BAUD_RATE);
     InitRxCnxn();
 
 while(1)
 {
   #  ifdef DEBUG_TIMEANALYZE_MAINLOOP    
            DEBUG_TIMER_BEGIN; /* Only for time analyses */
   #  endif

    if(gJ1939BootUp)
    {
      if(bootStep == 0)
      {
        /* initialize internal data structures */
        /* initialize buffer module */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -