• Home • Files • Structures         • Download

Buffer initialisation


The examples in buf_init.c show the initialisation procedure for a receive buffer and a transmit buffer.

//****************************************************************************//
// File:          buf_init.c                                                  //
// Description:   example for buffer initialisation                           //
// Author:        Uwe Koppe                                                   //
// e-mail:        koppe@microcontrol.net                                      //
//                                                                            //
// Copyright (C) MicroControl GmbH & Co. KG                                   //
// 53842 Troisdorf - Germany                                                  //
// www.microcontrol.net                                                       //
//                                                                            //
//----------------------------------------------------------------------------//
// Redistribution and use in source and binary forms, with or without         //
// modification, are permitted provided that the following conditions         //
// are met:                                                                   //
// 1. Redistributions of source code must retain the above copyright          //
//    notice, this list of conditions, the following disclaimer and           //
//    the referenced file 'COPYING'.                                          //
// 2. Redistributions in binary form must reproduce the above copyright       //
//    notice, this list of conditions and the following disclaimer in the     //
//    documentation and/or other materials provided with the distribution.    //
// 3. Neither the name of MicroControl nor the names of its contributors      //
//    may be used to endorse or promote products derived from this software   //
//    without specific prior written permission.                              //
//                                                                            //
// Provided that this notice is retained in full, this software may be        //
// distributed under the terms of the GNU Lesser General Public License       //
// ("LGPL") version 3 as distributed in the 'COPYING' file.                   //
//                                                                            //
//----------------------------------------------------------------------------//
//                                                                            //
// Date        History                                                        //
// ----------  -------------------------------------------------------------- //
// 11.09.2007  Initial version                                                //
//                                                                            //
//****************************************************************************//


#include "cp_core.h"
#include "cp_msg.h"

//----------------------------------------------------------------------------//
// AllocateRcvBuffer()                                                        //
//                                                                            //
//----------------------------------------------------------------------------//
void AllocateRcvBuffer(_TsCpPort * ptsCanPortV)
{
   _TsCpCanMsg tsCanMsgT;    // temporary CAN message


   //----------------------------------------------------------------
   // set message buffer 2 as receive buffer,
   // ID = 211, DLC = 2
   //
   CpMsgClear(&tsCanMsgT);
   CpMsgSetStdId(&tsCanMsgT, 211); // ID = 211
   CpMsgSetDlc(&tsCanMsgT, 2);
   CpCoreBufferInit(ptsCanPortV, &tsCanMsgT,
                    CP_BUFFER_2, CP_BUFFER_DIR_RX);
}


//----------------------------------------------------------------------------//
// AllocateTrmBuffer()                                                        //
//
//----------------------------------------------------------------------------//
void AllocateTrmBuffer(_TsCpPort * ptsCanPortV)
{
   _TsCpCanMsg tsCanMsgT;    // temporary CAN message


   //----------------------------------------------------------------
   // set message buffer 1 as transmit buffer,
   // ID = 120, DLC = 2
   //
   CpMsgClear(&tsCanMsgT);
   CpMsgSetStdId(&tsCanMsgT, 120); // ID = 120
   CpMsgSetDlc(&tsCanMsgT, 2);
   CpCoreBufferInit(ptsCanPortV, &tsCanMsgT,
                    CP_BUFFER_1, CP_BUFFER_DIR_TX);
}





 

© MicroControl GmbH & Co. KG

CANpie - V2.00