亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? can.c

?? Luminary cotex-M3 CAN總線 源代碼
?? C
?? 第 1 頁 / 共 5 頁
字號:
//*****************************************************************************
//
// can.c - Driver for the CAN module.
//
// Copyright (c) 2006-2007 Luminary Micro, Inc.  All rights reserved.
// 
// Software License Agreement
// 
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
// 
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws.  All rights are reserved.  Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
// 
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 1387 of the Stellaris Peripheral Driver Library.
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup can_api
//! @{
//
//*****************************************************************************
#include "../hw_ints.h"
#include "../hw_memmap.h"
#include "../hw_types.h"
#include "../hw_nvic.h"
#include "../hw_can.h"
#include "debug.h"
#include "interrupt.h"
#include "sysctl.h"
#include "can.h"

//*****************************************************************************
//
// This is the maximum number that can be stored as an 11bit Message
// identifier
//
//*****************************************************************************
#define CAN_MAX_11BIT_MSG_ID    (0x7ff)

//*****************************************************************************
//
// This is used as the loop delay for accessing the CAN controller registers.
//
//*****************************************************************************
#define CAN_RW_DELAY            (5)

//*****************************************************************************
//
//! Reads a CAN controller register.
//!
//! \param ulRegAddress is the full address of the CAN register to be read.
//!
//! This function takes care of the synchronization necessary to read from a
//! CAN controller register.
//!
//! \note This function takes care of delay required to access CAN registers.
//! This delay is required when accessing CAN registers directly.
//!
//! \return The current value of the register that was requested by
//! ulRegAddress.
//
//*****************************************************************************
unsigned long
CANReadReg(unsigned long ulRegAddress)
{
    volatile int iDelay;
    unsigned long ulRetVal;
    unsigned long ulIntNumber;
    unsigned long ulReenableInts;

    //
    // Get the CAN interrupt number from the register base address.
    //
    ulIntNumber = CANGetIntNumber(ulRegAddress & 0xfffff000);

    //
    // Make sure that the CAN base address was valid.
    //
    ASSERT(ulIntNumber != (unsigned long)-1);

    //
    // Remember current state so that CAN interrupts are only re-enabled if
    // they were already enabled.
    //
    ulReenableInts = HWREG(NVIC_EN1) & (1 << (ulIntNumber - 48));

    //
    // If the CAN interrupt was enabled then disable it.
    //
    if(ulReenableInts)
    {
        IntDisable(ulIntNumber);
    }

    //
    // Trigger the inital read to the CAN controller.  The value returned at
    // this point is not valid.
    //
    HWREG(ulRegAddress);

    //
    // This delay is necessary for the CAN have the correct data on the bus.
    //
    for(iDelay = 0; iDelay < CAN_RW_DELAY; iDelay++)
    {
    }

    //
    // Do the final read that has the valid value of the register.
    //
    ulRetVal = HWREG(ulRegAddress);

    //
    // Reenable CAN interrupts if they were enabled before this call.
    //
    if(ulReenableInts)
    {
        IntEnable(ulIntNumber);
    }

    return(ulRetVal);
}

//*****************************************************************************
//
//! Writes a CAN controller register.
//!
//! \param ulRegAddress is the full address of the CAN register to be written.
//! \param ulRegValue is the value to write into the register specified by
//! ulRegAddress.
//!
//! This function takes care of the synchronization necessary to write to a
//! CAN controller register.
//!
//! \note The delays in this function are required when accessing CAN registers
//! directly.
//!
//! \return None.
//
//*****************************************************************************
void
CANWriteReg(unsigned long ulRegAddress, unsigned long ulRegValue)
{
    volatile int iDelay;

    //
    // Trigger the inital write to the CAN controller.  The value will not make
    // it out to the CAN controller for CAN_RW_DELAY cycles.
    //
    HWREG(ulRegAddress) = ulRegValue;

    //
    // Delay to allow the CAN controller to receive the new data.
    //
    for(iDelay = 0; iDelay < CAN_RW_DELAY; iDelay++)
    {
    }
}

//*****************************************************************************
//
//! This function copies data from a buffer to the CAN Data registers.
//!
//! \param pucData is a pointer to the data to be written out to the CAN
//! controller's data registers.
//! \param pulRegister is an unsigned long pointer to the first register of
//! the CAN controller's data registers.  For example in order to use the IF1
//! register set on CAN controller 0 the value would be: (CAN0_BASE
//! + CAN_O_IF1DA1).
//! \param iSize is the number of bytes to copy into the CAN controller.
//!
//! This function takes the steps necessary to copy data from a contiguous
//! buffer in memory into the non-contiguous data registers used by the CAN
//! controller. This function is rarely used outside of the CANMessageSet()
//! function.
//!
//! \return None.
//
//*****************************************************************************
void
CANWriteDataReg(unsigned char *pucData, unsigned long *pulRegister, int iSize)
{
    int iIdx;
    unsigned long ulValue;

    //
    // Loop always copies 1 or 2 bytes per iteration.
    //
    for(iIdx = 0; iIdx < iSize; )
    {

        //
        // Write out the data 16 bits at a time since this is how the
        // registers are aligned in memory.
        //
        ulValue = pucData[iIdx++];

        //
        // Only write the second byte if needed otherwise it will be zero.
        //
        if(iIdx < iSize)
        {
            ulValue |= (pucData[iIdx++] << 8);
        }
        CANWriteReg((unsigned long)(pulRegister++), ulValue);
    }
}

//*****************************************************************************
//
//! This function copies data from a buffer to the CAN Data registers.
//!
//! \param pucData is a pointer to location to store the data read from the
//! CAN controller's data registers.
//! \param pulRegister is an unsigned long pointer to the first register of
//! the CAN controller's data registers.  For example in order to use the IF1
//! register set on CAN controller 1 the value would be: (CAN0_BASE
//! + CAN_O_IF1DA1).
//! \param iSize is the number of bytes to copy from the CAN controller.
//!
//! This function takes the steps necessary to copy data to a contiguous
//! buffer in memory from the non-contiguous data registers used by the CAN
//! controller.  This function is rarely used outside of the CANMessageGet()
//! function.
//!
//! \return None.
//
//*****************************************************************************
void
CANReadDataReg(unsigned char *pucData, unsigned long *pulRegister, int iSize)
{
    int iIdx;
    unsigned long ulValue;

    //
    // Loop always copies 1 or 2 bytes per iteration.
    //
    for(iIdx = 0; iIdx < iSize; )
    {
        //
        // Read out the data 16 bits at a time since this is how the
        // registers are aligned in memory.
        //
        ulValue = CANReadReg((unsigned long)(pulRegister++));

        //
        // Store the first byte.
        //
        pucData[iIdx++] = (unsigned char)ulValue;

        //
        // Only read the second byte if needed.
        //
        if(iIdx < iSize)
        {
            pucData[iIdx++] = (unsigned char)(ulValue >> 8);
        }
    }
}

//*****************************************************************************
//
//! Initializes the CAN controller after reset.
//!
//! \param ulBase is the base address of the CAN controller.
//!
//! After reset, the CAN controller is left in the disabled state.  However,
//! the memory used for message objects contains undefined values and must
//! be cleared prior to enabling the CAN controller the first time.
//! This prevents unwanted transmission or reception of data before the message
//! objects are configured.  This function must be called before enabling the
//! controller the first time.
//!
//! \return None.
//
//*****************************************************************************
void
CANInit(unsigned long ulBase)
{
    int iMsg;

    //
    // Make sure that the address passed in is valid.
    //
    ASSERT((ulBase == CAN0_BASE) ||
           (ulBase == CAN1_BASE));

    //
    // Place CAN controller in init state, regardless of previous state
    // This will put controller in idle, and allow the message object
    // RAM to be programmed.
    //
    CANWriteReg(ulBase + CAN_O_CTL, CAN_CTL_INIT);

    //
    // Wait for busy bit to clear
    //
    while(CANReadReg(ulBase + CAN_O_IF1CRQ) & CAN_IFCRQ_BUSY)
    {
    }

    //
    // Clear the message value bit in the arbitration register.
    // This indicates the message is not valid and is a "safe"
    // condition to leave the message object.  The same arb reg
    // is used to program all the message objects.
    //
    CANWriteReg(ulBase + CAN_O_IF1CMSK, CAN_IFCMSK_WRNRD | CAN_IFCMSK_ARB |
                CAN_IFCMSK_CONTROL);
    CANWriteReg(ulBase + CAN_O_IF1ARB2, 0);
    CANWriteReg(ulBase + CAN_O_IF1MCTL, 0);

    //
    // Loop through to program all 32 message objects
    //
    for(iMsg = 1; iMsg <= 32; iMsg++)
    {
        //
        // Wait for busy bit to clear
        //
        while(CANReadReg(ulBase + CAN_O_IF1CRQ) & CAN_IFCRQ_BUSY)
        {
        }

        //
        // Initiate programming the message object
        //
        CANWriteReg(ulBase + CAN_O_IF1CRQ, iMsg);
    }

    //
    // Make sure that the interrupt and new data flags are updated for the
    // message objects.
    //
    CANWriteReg(ulBase + CAN_O_IF1CMSK, CAN_IFCMSK_NEWDAT |
                CAN_IFCMSK_CLRINTPND);

    //
    // Loop through to program all 32 message objects
    //
    for(iMsg = 1; iMsg <= 32; iMsg++)
    {
        //
        // Wait for busy bit to clear.
        //
        while(CANReadReg(ulBase + CAN_O_IF1CRQ) & CAN_IFCRQ_BUSY)
        {
        }

        //
        // Initiate programming the message object
        //
        CANWriteReg(ulBase + CAN_O_IF1CRQ, iMsg);
    }

    //
    // Acknowledge any pending status interrupts.
    //
    CANReadReg(ulBase + CAN_O_STS);
}

//*****************************************************************************
//
//! Enables the CAN controller.
//!
//! \param ulBase is the base address of the CAN controller to enable.
//!
//! Enables the CAN controller for message processing.  Once enabled, the
//! controller will automatically transmit any pending frames, and process
//! any received frames.  The controller can be stopped by calling
//! CANDisable().  Prior to calling CANEnable(), CANInit() should have been
//! called to initialize the controller and the CAN bus clock should be
//! configured by calling CANSetBitTiming().
//!
//! \return None.
//
//*****************************************************************************
void
CANEnable(unsigned long ulBase)
{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人小视频免费观看| 亚洲婷婷综合色高清在线| 亚洲成av人综合在线观看| 欧美午夜片在线观看| 图片区小说区国产精品视频| 678五月天丁香亚洲综合网| 日韩二区在线观看| 精品国产乱码久久久久久影片| 久久精品99国产精品日本| 久久综合久久99| 国产精品一线二线三线精华| 日本一区二区在线不卡| 91一区一区三区| 丝袜美腿亚洲一区| 欧美v亚洲v综合ⅴ国产v| 成人免费的视频| 亚洲午夜私人影院| 精品国产乱码久久久久久蜜臀| 精品无码三级在线观看视频 | 国产一区二区按摩在线观看| 久久精品一区二区三区av| 99精品一区二区三区| 亚洲国产精品久久久久秋霞影院 | ㊣最新国产の精品bt伙计久久| 一本久久精品一区二区| 蜜桃视频第一区免费观看| 国产精品狼人久久影院观看方式| 欧美午夜电影在线播放| 久久99精品久久久久久久久久久久| 国产精品蜜臀在线观看| 4438x成人网最大色成网站| 成人一区二区三区视频 | 亚洲丝袜制服诱惑| 欧美一级黄色大片| 99精品久久久久久| 蜜臂av日日欢夜夜爽一区| 中文字幕一区在线观看视频| 欧美高清dvd| 91免费在线看| 国产精品亚洲视频| 欧美aaa在线| 亚洲欧美福利一区二区| 欧美一级高清片| 91影院在线观看| 国产高清亚洲一区| 日韩精品一二区| 亚洲色欲色欲www| 国产性色一区二区| 欧美日韩高清一区二区不卡| 国产91精品一区二区麻豆网站| 日韩国产一二三区| 樱桃视频在线观看一区| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 欧美一级久久久| 欧美视频三区在线播放| 99久久免费视频.com| 国产一区二区三区四区五区美女| 亚洲成人av一区二区三区| 中文字幕在线不卡一区二区三区 | 丁香六月综合激情| 国内成+人亚洲+欧美+综合在线 | 亚洲黄色性网站| 亚洲欧洲在线观看av| 国产日韩精品一区二区浪潮av | 国产精品伦一区二区三级视频| 精品伦理精品一区| 精品国产一区二区精华| 欧美大白屁股肥臀xxxxxx| 欧美另类变人与禽xxxxx| 欧美性猛交xxxx乱大交退制版| 色吧成人激情小说| 一本大道久久精品懂色aⅴ | 91麻豆免费看片| 99久久久久免费精品国产| 东方aⅴ免费观看久久av| 国产一区 二区| 国产91精品免费| 成人动漫中文字幕| 99r国产精品| 色狠狠av一区二区三区| 色爱区综合激月婷婷| 色综合久久精品| 欧洲精品视频在线观看| 欧美视频在线播放| 欧美二区乱c少妇| 日韩一级成人av| 国产亚洲综合在线| 亚洲欧洲韩国日本视频| 一区二区三区四区亚洲| 五月天丁香久久| 久草中文综合在线| 国产美女精品一区二区三区| 国产精品影视在线观看| 成人福利视频网站| 日本高清免费不卡视频| 欧美一区三区四区| 精品成人一区二区三区| 国产精品视频麻豆| 亚洲午夜影视影院在线观看| 日韩avvvv在线播放| 激情成人午夜视频| 91小视频在线| 欧美一级欧美三级| 欧美国产精品中文字幕| 亚洲国产综合人成综合网站| 日本视频中文字幕一区二区三区| 狠狠色丁香婷婷综合| 国产成人精品一区二 | 欧美肥大bbwbbw高潮| 亚洲精品一区二区三区福利| 国产精品欧美经典| 午夜精品久久久久久久久| 国产一区二区三区av电影| 一本久久综合亚洲鲁鲁五月天| 欧美一级高清片| 亚洲欧美色一区| 久久er99精品| 欧美专区在线观看一区| 精品国产电影一区二区| 亚洲精品中文在线影院| 精品在线一区二区三区| 91激情五月电影| 久久久噜噜噜久久人人看| 亚洲综合图片区| 国产精品一色哟哟哟| 欧美久久高跟鞋激| 亚洲天堂精品在线观看| 韩国av一区二区三区在线观看| 在线一区二区视频| 国产亚洲午夜高清国产拍精品| 亚洲电影第三页| 波多野结衣中文字幕一区二区三区 | 久久精品日产第一区二区三区高清版 | 国产精品正在播放| 91精品免费观看| 中文字幕一区二区三区在线观看| 蜜臀国产一区二区三区在线播放| 91农村精品一区二区在线| 久久综合久久综合亚洲| 日日夜夜精品视频天天综合网| 99久久99久久久精品齐齐| 欧美mv日韩mv国产网站| 香港成人在线视频| 91在线视频免费观看| 中文字幕久久午夜不卡| 寂寞少妇一区二区三区| 欧美人与禽zozo性伦| 亚洲嫩草精品久久| 不卡影院免费观看| 欧美国产一区在线| 国产主播一区二区| 欧美大片顶级少妇| 免播放器亚洲一区| 欧美日韩dvd在线观看| 一区二区三区中文字幕电影| 99视频国产精品| 国产精品视频九色porn| 岛国精品一区二区| 国产精品久久久久久久浪潮网站 | 97超碰欧美中文字幕| 国产欧美一区二区精品忘忧草 | 夜夜嗨av一区二区三区网页| 国产精品18久久久久久久久久久久| 日韩一区二区在线看| 奇米影视一区二区三区| 欧美一级在线观看| 久久福利视频一区二区| 日韩免费观看高清完整版| 毛片av中文字幕一区二区| 欧美xxxx在线观看| 国产精品综合av一区二区国产馆| 久久亚洲欧美国产精品乐播| 激情综合网天天干| 日韩黄色在线观看| 欧美电视剧免费全集观看| 久久66热re国产| 国产人久久人人人人爽| 成人av午夜电影| 亚洲毛片av在线| 欧美午夜理伦三级在线观看| 同产精品九九九| 日韩视频免费观看高清完整版| 精品影院一区二区久久久| 久久午夜免费电影| 成人av在线网站| 一区二区三区免费看视频| 欧美精品一级二级三级| 久久国产尿小便嘘嘘尿| 中文字幕欧美日韩一区| 91黄色免费看| 成人理论电影网| 亚洲黄色av一区| 欧美一级黄色片| jlzzjlzz国产精品久久| 亚洲国产成人精品视频| 精品免费一区二区三区| 成人高清av在线| 日本女人一区二区三区| 欧美激情一区二区三区四区| 91久久国产最好的精华液|