SAMV71 Xplained Ultra Software Package 1.0

can.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /** \file
00031  *  Definitions and prototypes for Controller Area Network (CAN)
00032  *  peripheral operations.
00033  */
00034 
00035 /** \ingroup lib_chip
00036  *  \ingroup cand_module
00037  *  \addtogroup can_module Working with CAN
00038  *
00039  *  \section Purpose
00040  *  Interface for Controller Area Network (CAN).
00041  *
00042  *  \section Usage
00043  *
00044  *  Before CAN operation, its peripheral clock should be enabled, see
00045  *  PMC_EnablePeripheral().
00046  *
00047  *  Modify CAN registers or register fields with API functions:
00048  *  - Modify CAN Mode register with CAN_ConfigureMode().
00049  *    - Enable/Disable CAN with CAN_Enable().
00050  *  - Change CAN interrupt settings with CAN_EnableIt(), CAN_DisableIt(),
00051  *    get interrupt mask by CAN_GetItMask().
00052  *  - Get CAN status with CAN_GetStatus().
00053  *  - Setup CAN baudrate via CAN_CalcBaudrate().
00054  *  - Start several mailbox transmission through CAN_Command().
00055  *  - The following functions setup mailboxes for message transfer:
00056  *    - CAN_ConfigureMessageMode() : setup _MMRx.
00057  *    - CAN_ConfigureMessageAcceptanceMask() : setup _MARx.
00058  *    - CAN_ConfigureMessageID() : setup _MIDx.
00059  *    - CAN_SetMessage() : setup _MDLx and _MDHx.
00060  *    - CAN_MessageControl() : setup _MCRx.
00061  *  - The following get status and data from mailbox:
00062  *    - CAN_GetMessage() : 
00063  *    - CAN_GetMessageStatus() : 
00064  */
00065 
00066 #ifndef _CAN_H_
00067 #define _CAN_H_
00068 /**@{*/
00069 
00070 /*----------------------------------------------------------------------------
00071  *        Headers
00072  *----------------------------------------------------------------------------*/
00073 
00074 #include <stdint.h>
00075 
00076 /*----------------------------------------------------------------------------
00077  *        Definitions
00078  *----------------------------------------------------------------------------*/
00079 
00080 /** Number of mailboxes in a CAN controller */
00081 #define CAN_NUM_MAILBOX     8
00082 
00083 /*----------------------------------------------------------------------------
00084  *        Exported functions
00085  *----------------------------------------------------------------------------*/
00086 
00087 void CAN_ConfigureMode(Can * pCan,uint32_t dwMr);
00088 void CAN_Enable(Can * pCan,uint8_t bEnDis);
00089 void CAN_EnableLowPower(Can * pCan,uint8_t bEnDis);
00090 void CAN_EnableAutobaud(Can * pCan,uint8_t bEnDis);
00091 void CAN_EnableOverloadFrame(Can * pCan,uint8_t bEnDis);
00092 void CAN_EnableTimeStampEof(Can * pCan,uint8_t bEofSof);
00093 void CAN_EnableTimeTriggerMode(Can * pCan,uint8_t bEnDis);
00094 void CAN_EnableTimerFreeze(Can * pCan,uint8_t bEnDis);
00095 void CAN_DisableRepeat(Can * pCan,uint8_t bDisEn);
00096 
00097 void CAN_EnableIt(Can * pCan,uint32_t dwSources);
00098 void CAN_DisableIt(Can * pCan,uint32_t dwSources);
00099 uint32_t CAN_GetItMask(Can * pCan);
00100 uint32_t CAN_GetStatus(Can * pCan);
00101 
00102 uint8_t CAN_CalcBaudrate(Can * pCan, uint32_t dwBaud, uint32_t dwMck);
00103 void CAN_ConfigureBaudrate(Can * pCan,uint32_t dwBr);
00104 void CAN_SetSamplingMode(Can * pCan,uint8_t bAvg3);
00105 
00106 uint32_t CAN_GetTimer(Can * pCan);
00107 uint32_t CAN_GetTimestamp(Can * pCan);
00108 
00109 uint32_t CAN_GetErrorCount(Can * pCan);
00110 uint32_t CAN_GetRxErrorCount(Can * pCan);
00111 uint32_t CAN_GetTxErrorCount(Can * pCan);
00112 
00113 void CAN_Command(Can * pCan,uint32_t dwRequests);
00114 void CAN_ResetTimer(Can * pCan);
00115 void CAN_Tx(Can * pCan,uint8_t bMb);
00116 
00117 void CAN_Abort(Can * pCan,uint32_t dwAborts);
00118 void CAN_AbortMailbox(Can * pCan,uint8_t bMb);
00119 
00120 void CAN_ConfigureMessageMode(Can * pCan,uint8_t bMb,uint32_t dwMr);
00121 uint32_t CAN_GetMessageMode(Can * pCan,uint8_t bMb);
00122 void CAN_SetTimemark(Can * pCan,uint8_t bMb,uint8_t bTimemarks);
00123 void CAN_SetPriority(Can * pCan,uint8_t bMb,uint8_t bPriority);
00124 void CAN_SetObjectType(Can * pCan,uint8_t bMb,uint8_t bType);
00125 
00126 void CAN_ConfigureMessageAcceptanceMask(Can * pCan,uint8_t bMb,uint32_t dwMAM);
00127 uint32_t CAN_GetMessageAcceptanceMask(Can * pCan,uint8_t bMb);
00128 void CAN_ConfigureIdentifierMask(Can * pCan,uint8_t bMb,uint8_t bIdCfg);
00129 void CAN_SetMIDvAMask(Can * pCan,uint8_t bMb,uint32_t dwIDvA);
00130 void CAN_SetMIDvBMask(Can * pCan,uint8_t bMb,uint32_t dwIDvA);
00131 
00132 void CAN_ConfigureMessageID(Can * pCan,uint8_t bMb,uint32_t dwMID);
00133 uint32_t CAN_GetMessageID(Can * pCan,uint8_t bMb);
00134 void CAN_ConfigureIdVer(Can * pCan,uint8_t bMb,uint8_t bIdVer);
00135 void CAN_SetMIDvA(Can * pCan,uint8_t bMb,uint32_t dwIDvA);
00136 void CAN_SetMIDvB(Can * pCan,uint8_t bMb,uint32_t dwIDvA);
00137 
00138 uint32_t CAN_GetFamilyID(Can * pCan,uint8_t bMb);
00139 
00140 uint32_t CAN_GetMessageStatus(Can * pCan,uint8_t bMb);
00141 
00142 void CAN_SetMessageDataL(Can * pCan,uint8_t bMb,uint32_t dwL);
00143 uint32_t CAN_GetMessageDataL(Can * pCan,uint8_t bMb);
00144 void CAN_SetMessageDataH(Can * pCan,uint8_t bMb,uint32_t dwH);
00145 uint32_t CAN_GetMessageDataH(Can * pCan,uint8_t bMb);
00146 void CAN_SetMessage(Can * pCan,uint8_t bMb,uint32_t * pDwData);
00147 void CAN_GetMessage(Can * pCan,uint8_t bMb,uint32_t * pDwData);
00148 void CAN_SetMessageData64(Can * pCan,uint8_t bMb,uint64_t u64);
00149 uint64_t CAN_GetMessageData64(Can * pCan,uint8_t bMb);
00150 
00151 void CAN_MessageControl(Can * pCan,uint8_t bMb,uint32_t dwCtrl);
00152 void CAN_MessageRemote(Can * pCan,uint8_t bMb);
00153 void CAN_MessageAbort(Can * pCan,uint8_t bMb);
00154 void CAN_MessageTx(Can * pCan,uint8_t bMb,uint8_t bLen);
00155 void CAN_MessageRx(Can * pCan,uint8_t bMb);
00156 
00157 /**@}*/
00158 #endif /* #ifndef _CAN_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines