CANDRIVERIMPLv01.docx
- 文档编号:11631491
- 上传时间:2023-03-29
- 格式:DOCX
- 页数:16
- 大小:292.63KB
CANDRIVERIMPLv01.docx
《CANDRIVERIMPLv01.docx》由会员分享,可在线阅读,更多相关《CANDRIVERIMPLv01.docx(16页珍藏版)》请在冰豆网上搜索。
CANDRIVERIMPLv01
CONFIDENTIAL
TJU—IFXAutomotiveElectronicJointLaboratory
StateKeyLaboratoryofEngines
TianJinUniversity,China
GEMS–K1
CANdriverimplementationdocument
Revisionhistory
Version
By
Modifications
V0.1,25thSept2008
Hoangchao.Zhang
Creation
Summary
Revisionhistory2
Summary3
1Introduction4
1.1Overview4
1.2Definitionsandabbreviations4
1.3References4
2APIspecification5
2.1Typesdefinitions5
2.2Functionsdefinitions5
CAN_Init5
CAN_DeInit6
CAN_ReadSync6
CAN_WriteAsync7
CAN_CancelWriteAsync7
CAN_getChannelState8
CAN_NodeEnable8
CAN_NodeDisable9
CAN_GetNodeState9
2.3Notifyfunctions9
CAN_EnableNotify9
CAN_DisableNotify10
CAN_
CAN_
3ResourcesConfiguration11
3.1PeriperalConfig11
3.2InterruptConfig11
4CompileEnvironment12
1Introduction
ThisdocumentdescribestheimplementationofControllerAreaNetwork(CAN)drivertobedevelopedfortheGEMS-K1project.
1.1Overview
TheCANdriverprovidesservicestotransmitandtoreceivemessagesonaCANbus.ItprovidesalsoservicestoinitializeandcontroltheCANmoduleoftheTC1766.Thedriveracceptsbothinterruptdrivenandpollingmodes.Thechoicefromonemodetotheotherismadebyenablingordisablingthenotifyfunctions.
1.2Definitionsandabbreviations
Definition
Description
Channel
AchannelisasoftwarerepresentationofamessageobjectoftheCANmodule
Node
AnodeisaconnectingpointtotheCANbus.TC1766providestwonodes.
Abbreviation
Description
API
ApplicationProgrammingInterface
CAN
ControllerAreaNetwork
1.3References
2
APIspecification
2.1Typesdefinitions
Type
Description
Range
uint8
Unsignedchar
0to127
CAN_MemPtrType
Pointertoamemorylocation
uint8
Sizeofamessageinnumberofbytes
1to8
CAN_ChannelStatusType
Statusofachannel.EachstatusflagrepresentsabitoftheChannelStatusType.
CAN_S_RECEIVE(0x1)
CAN_S_TRANSMIT(0x2)
CAN_S_RX_LOST(0x4)
CAN_S_TX_PENDING(0x8)
CAN_NodeStateType
Stateofthenode
CAN_ENABLE
CAN_DISABLE
CAN_BUSOFF
CAN_StatusType
Standardreturntype
S_OK
S_NOT_OK
S_BUSY
2.2Functionsdefinitions
CAN_Init
Functionname
CAN_Init
Syntax
CAN_StatusTypeCAN_Init
(
void
)
Reentrancy
Nonre-entrant
Inputparameters
None
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
inithasbeenexecutedcorrectly
:
inithasnotbeenexecutedcorrectly
Description
ThisfunctioninitializestheCANdriverandCANhardwaremoduleaccordingtothestaticallydefinedconfiguration.
Note
CAN_DeInit
Functionname
CAN_DeInit
Syntax
CAN_StatusTypeCAN_DeInit
(
void
)
Reentrancy
Nonre-entrant
Inputparameters
None
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
deinithasbeenexecutedcorrectly
:
deinithasnotbeenexecutedcorrectly
Description
ResetallCANregisters
Note
CAN_ReadSync
Functionname
CAN_ReadSync
Syntax
CAN_StatusTypeCAN_ReadSync
(
uint8channel
CAN_MemPtrTypeaddress
uint8size
)
Reentrancy
re-entrant
Inputparameters
channel
address
size
Channelnumber
Addressofthememorylocationwherethedataiswritten
Numberofbytestoread(max8)
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
readhasbeenexecutedcorrectly
:
readhasnotbeenexecutedcorrectly
Description
TransferthereceiveddataofaCANchanneltothespecifiedmemoryaddress.Sizebytesarecopiedfrommessageobjectspecifiedbychanneltothememorylocationataddress.
ThisfunctionmustresettheflagsRXPNDandMSGLSTofthemessageobjectstatusregister.
Note
Ininterrupttriggeredmode,thisfunctionhastobecalledinthenotificationfunctionCAN_
Inpollingmode,thisfunctionhastobecalledinthefunctionmonitoringthereceivedmessages.
CAN_WriteAsync
Functionname
CAN_WriteAsync
Syntax
CAN_StatusTypeCAN_WriteAsync
(
uint8channel
CAN_MemPtrTypemessage
)
Reentrancy
re-entrant
Inputparameters
channel
message
Channelnumber
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
S_BUSY
:
writehasbeenexecutedcorrectly
:
writehasnotbeenexecutedcorrectly
:
requestrejected
Description
Thefunctionsetsthemessageinthespecifiedchannel:
▪Messageobject’sidentifier=message.Id
▪Messageobject’sDLC=message.Dlc
▪AsmanybytesasspecifiedbyDLCarecopiedfromMsg.AdresstoMessageobject’sdatafield.
ThefunctionhandlesallthecontroltasksandsetsallthenecessaryflagssuchasTXRQ,MSGVAL,etc.
IfTXRQisalreadysetforthemessageobject,thefunctionreturnswithS_BUSY.
Note
Whenaframeissuccessfullytransmitted,theflagTXPNDissetbyhardware(itmustberesetbysoftware)andthenotifyfunctionCAN_
CAN_CancelWriteAsync
Functionname
CAN_CancelWriteAsync
Syntax
CAN_StatusTypeCAN_CancelWriteAsync
(
uint8channel
)
Reentrancy
re-entrant
Inputparameters
channel
Channelnumber
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
writehasbeenexecutedcorrectly
:
writehasnotbeenexecutedcorrectly
Description
Thisfunctionresetthetransmitrequestflag(bitTXRQ)ofthemessageobjectcorrespondingtothespecifiedchannel.
Note
CAN_getChannelState
Functionname
CAN_GetChannelState
Syntax
CAN_ChannelStatusTypeCAN_CancelWriteAsync
(
uint8channel
)
Reentrancy
re-entrant
Inputparameters
channel
Channelnumber
Outputparameters
None
Returnvalue
t_CAN_ChannelStatusType
CAN_S_RECEIVE
CAN_S_TRANSMIT
CAN_S_RX_LOST
CAN_S_TX_PENDING
:
successfulreception
:
successfultransmission
:
receivedmessageslost
:
Transmissionpending
Description
Thisfunctionreturnstheinformationfromthemessageobjectstatusregister.
TheflagTXPNDindicatingasuccessfultransmissionisresetbythisfunction.
Thereturnvalueisaconcatenationofthefourstatusflag.Forexampleifasuccessfulreceptionbutalsoreceivedmessageslostareindicated:
Note
Thisfunctionisusedinpollingmodetomonitorchannels’statusbits.
CAN_NodeEnable
Functionname
CAN_NodeEnable
Syntax
CAN_StatusTypeCAN_NodeEnable
(
uint8node
)
Reentrancy
Reentrant
Inputparameters
node
Nodenumber
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
Thefunctionhasbeenexecutedcorrectly
:
Thefunctionhasnotbeenexecutedcorrectly
Description
Thisfunctionmustenableallthefeaturesforthespecifiednode.
CAN_NodeDisable
Functionname
CAN_NodeDisable
Syntax
CAN_StatusTypeCAN_NodeDisable
(
uint8node
)
Reentrancy
Reentrant
Inputparameters
node
Nodenumber
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
Thefunctionhasbeenexecutedcorrectly
:
Thefunctionhasnotbeenexecutedcorrectly
Description
Thisfunctionmustdisableallthefeaturesforthespecifiednode.
CAN_GetNodeState
Functionname
CAN_GetNodeState
Syntax
t_CAN_NodeStateCAN_GetNodeState
(
uint8node
)
Reentrancy
Reentrant
Inputparameters
node
Nodenumber
Outputparameters
None
Returnvalue
t_CAN_NodeState
CAN_ENABLE
CAN_DISABLE
CAN_BUSOFF
Description
Thisfunctionreturnsthecurrentstateofthespecifiednode.
2.3Notifyfunctions
CAN_EnableNotify
Functionname
CAN_EnableNotify
Syntax
CAN_StatusTypeCAN_EnableNotify
(
uint8channel
)
Reentrancy
Reentrant
Inputparameters
channel
Channelnumber
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
Thefunctionhasbeenexecutedcorrectly
:
Thefunctionhasnotbeenexecutedcorrectly
Description
Thisfunctionenablesthealltheinterruptsourcesofthespecifiedchannel.
Eachinterruptmustbeinitializedandlinkedtoaninterruptserviceroutinewhichcallsthecorrespondingnotifyfunction.
CAN_DisableNotify
Functionname
CAN_DisableNotify
Syntax
CAN_StatusTypeCAN_DisableNotify
(
uint8channel
)
Reentrancy
Reentrant
Inputparameters
channel
Channelnumber
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
Thefunctionhasbeenexecutedcorrectly
:
Thefunctionhasnotbeenexecutedcorrectly
Description
Thisfunctiondisablesalltheinterruptsourcesforthischannel.
CAN_
Functionname
CAN_
Syntax
VoidCAN_
(
CAN_MemPtrType*message
)
Reentrancy
Reentrant
Inputparameters
message
MessagestructurecontainingidentifierandDLC
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
Thefunctionhasbeenexecutedcorrectly
:
Thefunctionhasnotbeenexecutedcorrectly
Description
Thebehaviorofthisfunctionisimplementedbytheapplicationdeveloper.
Ifnotifyisenabled,thiscallbackroutinewillbeexecutedbytheinterruptserviceroutinelinkedtotheCANframereceivedinterrupt.
CAN_
Functionname
CAN_
Syntax
VoidCAN_
(
CAN_MemPtrType*message
)
Reentrancy
Reentrant
Inputparameters
message
MessagestructurecontainingidentifierandDLC
Outputparameters
None
Returnvalue
CAN_StatusType
S_OK
S_NOT_OK
:
Thefunctionhasbeenexecutedcorrectly
:
Thefunctionhasnotbeenexecutedcorrectly
Description
Thebehaviorofthisfunctionisimplementedbytheapplicationdeveloper.
Ifnotifyisenabled,thiscallbackroutinewillbeexecutedbytheinterruptserviceroutinelinkedtotheCANframetransmittedinterrupt.
3ResourcesConfiguration
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CANDRIVERIMPLv01