Enhanced CAN driver.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8615 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2015-12-17 13:44:26 +00:00
parent 75967a3288
commit ad6437b784
4 changed files with 80 additions and 1 deletions

View File

@ -127,6 +127,12 @@ extern "C" {
void canObjectInit(CANDriver *canp);
void canStart(CANDriver *canp, const CANConfig *config);
void canStop(CANDriver *canp);
bool canTryTransmitI(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *ctfp);
bool canTryReceiveI(CANDriver *canp,
canmbx_t mailbox,
CANRxFrame *crfp);
msg_t canTransmit(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *ctfp,

View File

@ -139,6 +139,75 @@ void canStop(CANDriver *canp) {
osalSysUnlock();
}
/**
* @brief Can frame transmission attempt.
* @details The specified frame is queued for transmission, if the hardware
* queue is full then the function fails.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
* @param[in] ctfp pointer to the CAN frame to be transmitted
* @return The operation result.
* @retval false Frame transmitted.
* @retval true Mailbox full.
*
* @iclass
*/
bool canTryTransmitI(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *ctfp) {
osalDbgCheckClassI();
osalDbgCheck((canp != NULL) && (ctfp != NULL) &&
(mailbox <= (canmbx_t)CAN_TX_MAILBOXES));
osalDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"invalid state");
/* If the RX mailbox is full then the function fails.*/
if (!can_lld_is_tx_empty(canp, mailbox)) {
return true;
}
/* Transmitting frame.*/
can_lld_transmit(canp, mailbox, ctfp);
return false;
}
/**
* @brief Can frame receive attempt.
* @details The function tries to fetch a frame from a mailbox.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
* @param[out] crfp pointer to the buffer where the CAN frame is copied
* @return The operation result.
* @retval false Frame fetched.
* @retval true Mailbox empty.
*
* @iclass
*/
bool canTryReceiveI(CANDriver *canp,
canmbx_t mailbox,
CANRxFrame *crfp) {
osalDbgCheckClassI();
osalDbgCheck((canp != NULL) && (crfp != NULL) &&
(mailbox <= (canmbx_t)CAN_RX_MAILBOXES));
osalDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"invalid state");
/* If the RX mailbox is empty then the function fails.*/
if (!can_lld_is_rx_nonempty(canp, mailbox)) {
return true;
}
/* Fetching the frame.*/
can_lld_receive(canp, mailbox, crfp);
return false;
}
/**
* @brief Can frame transmission.
* @details The specified frame is queued for transmission, if the hardware
@ -171,6 +240,7 @@ msg_t canTransmit(CANDriver *canp,
osalSysLock();
osalDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"invalid state");
/*lint -save -e9007 [13.5] Right side is supposed to be pure.*/
while ((canp->state == CAN_SLEEP) || !can_lld_is_tx_empty(canp, mailbox)) {
/*lint -restore*/
@ -218,6 +288,7 @@ msg_t canReceive(CANDriver *canp,
osalSysLock();
osalDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"invalid state");
/*lint -save -e9007 [13.5] Right side is supposed to be pure.*/
while ((canp->state == CAN_SLEEP) || !can_lld_is_rx_nonempty(canp, mailbox)) {
/*lint -restore*/

View File

@ -77,6 +77,8 @@
- HAL: Introduced preliminary support for STM32F7xx devices.
- HAL: Introduced preliminary support for STM32L4xx devices.
- HAL: Introduced preliminary support for STM32L0xx devices.
- HAL: Enhanced the CAN driver with I-class functions. Now it is possible
to exchange frames from ISRs.
- HAL: Added watchdog driver model (WDG) and STM32 implementation on IWDG.
- HAL: Added synchronous API and mutual exclusion to the UART driver.
- HAL: Added PAL driver for STM32L4xx GPIOv3 peripheral.

View File

@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;cr2-adc_lld_start_conversion-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;CR2-adc-null-port_wait_for_interrupt-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;CR2-adc-adcp-adc_lld_start_conversion-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;CR2-adc-adcp-adc_lld_start_conversion-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;CR2-adc-null-port_wait_for_interrupt-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;cr2-adc_lld_start_conversion-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>