<ahref="can_8c.html">Go to the documentation of this file.</a><divclass="fragment"><preclass="fragment"><aname="l00001"></a>00001 <spanclass="comment">/*</span>
<aname="l00035"></a>00035 <spanclass="preprocessor">#include "<aclass="code"href="ch_8h.html"title="ChibiOS/RT main include file.">ch.h</a>"</span>
<aname="l00069"></a><aclass="code"href="group___c_a_n.html#gadf8c892ca4bd2544d03be8a690885aef">00069</a><spanclass="keywordtype">void</span><aclass="code"href="group___c_a_n.html#gadf8c892ca4bd2544d03be8a690885aef"title="Initializes the standard part of a CANDriver structure.">canObjectInit</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp) {
<aname="l00073"></a>00073 <aclass="code"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value.">chSemInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#a2d4f41efdd17ff64233fd636873601c7"title="Transmission queue semaphore.">cd_txsem</a>, 0);
<aname="l00074"></a>00074 <aclass="code"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value.">chSemInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#aae5656b95d7632b579d098e95c3c77d4"title="Receive queue semaphore.">cd_rxsem</a>, 0);
<aname="l00075"></a>00075 <aclass="code"href="group__events.html#gab8d0fdc09be629dfb438c32a0523db42"title="Initializes an Event Source.">chEvtInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#af26143d0b9fed9421e79fa4fcb7f3d4b"title="One or more frames become available.">cd_rxfull_event</a>);
<aname="l00076"></a>00076 <aclass="code"href="group__events.html#gab8d0fdc09be629dfb438c32a0523db42"title="Initializes an Event Source.">chEvtInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#a39538106afd16adf6e1b2640458f5fa2"title="One or more transmission slots become available.">cd_txempty_event</a>);
<aname="l00077"></a>00077 <aclass="code"href="group__events.html#gab8d0fdc09be629dfb438c32a0523db42"title="Initializes an Event Source.">chEvtInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#aa4bc47b7806c2414382071f31b0cef89"title="A CAN bus error happened.">cd_error_event</a>);
<aname="l00078"></a>00078 canp-><aclass="code"href="struct_c_a_n_driver.html#a149df5bb5907beae27b8623d432cb20a"title="Error flags set when an error event is broadcasted.">cd_status</a> = 0;
<aname="l00080"></a>00080 <spanclass="preprocessor"></span><aclass="code"href="group__events.html#gab8d0fdc09be629dfb438c32a0523db42"title="Initializes an Event Source.">chEvtInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#a424d4fd0c061b0237803c03c5815b450"title="Entering sleep state event.">cd_sleep_event</a>);
<aname="l00081"></a>00081 <aclass="code"href="group__events.html#gab8d0fdc09be629dfb438c32a0523db42"title="Initializes an Event Source.">chEvtInit</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#ab860f0342e594220bd9428bed397614e"title="Exiting sleep state event.">cd_wakeup_event</a>);
<aname="l00091"></a><aclass="code"href="group___c_a_n.html#ga05d2448864b2cae4674ed7e6f3c576b8">00091</a><spanclass="keywordtype">void</span><aclass="code"href="group___c_a_n.html#ga05d2448864b2cae4674ed7e6f3c576b8"title="Configures and activates the CAN peripheral.">canStart</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp, <spanclass="keyword">const</span><aclass="code"href="struct_c_a_n_config.html"title="Driver configuration structure.">CANConfig</a> *config) {
<aname="l00102"></a>00102 <aclass="code"href="group__threads.html#ga851dc0c4ac72885bf09feebdef4673ac"title="Suspends the invoking thread for the specified time.">chThdSleepS</a>(1);
<aname="l00105"></a>00105 <aclass="code"href="group___c_a_n___l_l_d.html#gafae65e8b034b2c1cda8d46790eb2c3fb"title="Configures and activates the CAN peripheral.">can_lld_start</a>(canp);
<aname="l00116"></a><aclass="code"href="group___c_a_n.html#ga4e89a7d246119e077d27431a02586133">00116</a><spanclass="keywordtype">void</span><aclass="code"href="group___c_a_n.html#ga4e89a7d246119e077d27431a02586133"title="Deactivates the CAN peripheral.">canStop</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp) {
<aname="l00124"></a>00124 <aclass="code"href="group___c_a_n___l_l_d.html#gad6fff809711eb161f9c53acf4f3f8470"title="Deactivates the CAN peripheral.">can_lld_stop</a>(canp);
<aname="l00125"></a>00125 <aclass="code"href="group__semaphores.html#gae7972b6b22b80ac09bac5a186277ab81"title="Performs a reset operation on the semaphore.">chSemResetI</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#aae5656b95d7632b579d098e95c3c77d4"title="Receive queue semaphore.">cd_rxsem</a>, 0);
<aname="l00126"></a>00126 <aclass="code"href="group__semaphores.html#gae7972b6b22b80ac09bac5a186277ab81"title="Performs a reset operation on the semaphore.">chSemResetI</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#a2d4f41efdd17ff64233fd636873601c7"title="Transmission queue semaphore.">cd_txsem</a>, 0);
<aname="l00127"></a>00127 <aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aname="l00129"></a>00129 canp-><aclass="code"href="struct_c_a_n_driver.html#a149df5bb5907beae27b8623d432cb20a"title="Error flags set when an error event is broadcasted.">cd_status</a> = 0;
<aname="l00130"></a>00130 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00151"></a><aclass="code"href="group___c_a_n.html#gad9c686d19b4319ef586af3631b779c6c">00151</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group___c_a_n.html#gad9c686d19b4319ef586af3631b779c6c"title="Can frame transmission.">canTransmit</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp, <spanclass="keyword">const</span><aclass="code"href="struct_c_a_n_tx_frame.html"title="CAN transmission frame.">CANTxFrame</a> *ctfp, <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> timeout) {
<aname="l00159"></a>00159 <spanclass="keywordflow">while</span> ((canp-><aclass="code"href="struct_c_a_n_driver.html#a5ed8f92d00941a212ad798e05c001dcb"title="Driver state.">cd_state</a> == <aclass="code"href="group___c_a_n.html#ggaca62464ffdcedae03d49adf3f6ce870ea7b6ee207a3d1bfec35374f0d3964e6aa"title="Sleep state.">CAN_SLEEP</a>) || !<aclass="code"href="group___c_a_n___l_l_d.html#ga81f2cbcb7b885628bdf54177375b7f9b"title="Determines whether a frame can be transmitted.">can_lld_can_transmit</a>(canp)) {
<aname="l00160"></a>00160 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg = <aclass="code"href="group__semaphores.html#ga924ec5d191bb8debe8727ae4dd5d6d03"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeoutS</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#a2d4f41efdd17ff64233fd636873601c7"title="Transmission queue semaphore.">cd_txsem</a>, timeout);
<aname="l00166"></a>00166 <aclass="code"href="group___c_a_n___l_l_d.html#ga7117eccbe00b5524e55546a4aa688446"title="Inserts a frame into the transmit queue.">can_lld_transmit</a>(canp, ctfp);
<aname="l00167"></a>00167 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00192"></a><aclass="code"href="group___c_a_n.html#ga557d845167f6ab4f224b036860411db5">00192</a><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a><aclass="code"href="group___c_a_n.html#ga557d845167f6ab4f224b036860411db5"title="Can frame receive.">canReceive</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp, <aclass="code"href="struct_c_a_n_rx_frame.html"title="CAN received frame.">CANRxFrame</a> *crfp, <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> timeout) {
<aname="l00200"></a>00200 <spanclass="keywordflow">while</span> ((canp-><aclass="code"href="struct_c_a_n_driver.html#a5ed8f92d00941a212ad798e05c001dcb"title="Driver state.">cd_state</a> == <aclass="code"href="group___c_a_n.html#ggaca62464ffdcedae03d49adf3f6ce870ea7b6ee207a3d1bfec35374f0d3964e6aa"title="Sleep state.">CAN_SLEEP</a>) || !<aclass="code"href="group___c_a_n___l_l_d.html#ga27ca2bb8369163a8be3ebd020522f7b0"title="Determines whether a frame has been received.">can_lld_can_receive</a>(canp)) {
<aname="l00201"></a>00201 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg = <aclass="code"href="group__semaphores.html#ga924ec5d191bb8debe8727ae4dd5d6d03"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeoutS</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#aae5656b95d7632b579d098e95c3c77d4"title="Receive queue semaphore.">cd_rxsem</a>, timeout);
<aname="l00207"></a>00207 <aclass="code"href="group___c_a_n___l_l_d.html#ga5c9d83ee107cfb59880c4bd19a7961bd"title="Receives a frame from the input queue.">can_lld_receive</a>(canp, crfp);
<aname="l00208"></a>00208 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00218"></a><aclass="code"href="group___c_a_n.html#ga377a78b04ad6733e24b31615b76cdada">00218</a><aclass="code"href="group___c_a_n___l_l_d.html#ga4a6894bc11434dfa96263dcd72735330"title="CAN status flags.">canstatus_t</a><aclass="code"href="group___c_a_n.html#ga377a78b04ad6733e24b31615b76cdada"title="Returns the current status mask and clears it.">canGetAndClearFlags</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp) {
<aname="l00219"></a>00219 <aclass="code"href="group___c_a_n___l_l_d.html#ga4a6894bc11434dfa96263dcd72735330"title="CAN status flags.">canstatus_t</a> status;
<aname="l00220"></a>00220
<aname="l00221"></a>00221 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00222"></a>00222 status = canp-><aclass="code"href="struct_c_a_n_driver.html#a149df5bb5907beae27b8623d432cb20a"title="Error flags set when an error event is broadcasted.">cd_status</a>;
<aname="l00223"></a>00223 canp-><aclass="code"href="struct_c_a_n_driver.html#a149df5bb5907beae27b8623d432cb20a"title="Error flags set when an error event is broadcasted.">cd_status</a> = 0;
<aname="l00224"></a>00224 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00234"></a><aclass="code"href="group___c_a_n.html#ga97caf4f277c09588c225ea2328a74cba">00234</a><spanclass="keywordtype">void</span><aclass="code"href="group___c_a_n.html#ga97caf4f277c09588c225ea2328a74cba"title="Enters the sleep mode.">canSleep</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp) {
<aname="l00243"></a>00243 <aclass="code"href="group___c_a_n___l_l_d.html#ga90f2254324f338714bfe1663eb73a2ba"title="Enters the sleep mode.">can_lld_sleep</a>(canp);
<aname="l00245"></a>00245 <aclass="code"href="group__events.html#gaa24d9bed5b676b577200c4a8ebe3b8a3"title="Signals all the Event Listeners registered on the specified Event Source.">chEvtBroadcastI</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#a424d4fd0c061b0237803c03c5815b450"title="Entering sleep state event.">cd_sleep_event</a>);
<aname="l00246"></a>00246 <aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aname="l00247"></a>00247 }
<aname="l00248"></a>00248 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00258"></a><aclass="code"href="group___c_a_n.html#ga09737d4ae5be724bf791a309e8a28dff">00258</a><spanclass="keywordtype">void</span><aclass="code"href="group___c_a_n.html#ga09737d4ae5be724bf791a309e8a28dff"title="Enforces leaving the sleep mode.">canWakeup</a>(<aclass="code"href="struct_c_a_n_driver.html"title="Structure representing an CAN driver.">CANDriver</a> *canp) {
<aname="l00269"></a>00269 <aclass="code"href="group__events.html#gaa24d9bed5b676b577200c4a8ebe3b8a3"title="Signals all the Event Listeners registered on the specified Event Source.">chEvtBroadcastI</a>(&canp-><aclass="code"href="struct_c_a_n_driver.html#ab860f0342e594220bd9428bed397614e"title="Exiting sleep state event.">cd_wakeup_event</a>);
<aname="l00270"></a>00270 <aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aname="l00271"></a>00271 }
<aname="l00272"></a>00272 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
Generated on Sun Nov 28 2010 14:09:48 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>