STM32L4xx_HAL_Driver  1.14.0

Interrupts management. More...

Functions

HAL_StatusTypeDef HAL_CAN_ActivateNotification (CAN_HandleTypeDef *hcan, uint32_t ActiveITs)
 Enable interrupts. More...
 
HAL_StatusTypeDef HAL_CAN_DeactivateNotification (CAN_HandleTypeDef *hcan, uint32_t InactiveITs)
 Disable interrupts. More...
 
void HAL_CAN_IRQHandler (CAN_HandleTypeDef *hcan)
 Handles CAN interrupt request. More...
 

Detailed Description

Interrupts management.

  ==============================================================================
                       ##### Interrupts management #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) HAL_CAN_ActivateNotification      : Enable interrupts
      (+) HAL_CAN_DeactivateNotification    : Disable interrupts
      (+) HAL_CAN_IRQHandler                : Handles CAN interrupt request

Function Documentation

◆ HAL_CAN_ActivateNotification()

HAL_StatusTypeDef HAL_CAN_ActivateNotification ( CAN_HandleTypeDef hcan,
uint32_t  ActiveITs 
)

Enable interrupts.

Parameters
hcanpointer to an CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
ActiveITsindicates which interrupts will be enabled. This parameter can be any combination of
  • CAN_Interrupts.
Return values
HALstatus

Definition at line 1631 of file stm32l4xx_hal_can.c.

1632 {
1633  HAL_CAN_StateTypeDef state = hcan->State;
1634 
1635  /* Check function parameters */
1636  assert_param(IS_CAN_IT(ActiveITs));
1637 
1638  if ((state == HAL_CAN_STATE_READY) ||
1639  (state == HAL_CAN_STATE_LISTENING))
1640  {
1641  /* Enable the selected interrupts */
1642  __HAL_CAN_ENABLE_IT(hcan, ActiveITs);
1643 
1644  /* Return function status */
1645  return HAL_OK;
1646  }
1647  else
1648  {
1649  /* Update error code */
1650  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1651 
1652  return HAL_ERROR;
1653  }
1654 }
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_DeactivateNotification()

HAL_StatusTypeDef HAL_CAN_DeactivateNotification ( CAN_HandleTypeDef hcan,
uint32_t  InactiveITs 
)

Disable interrupts.

Parameters
hcanpointer to an CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
InactiveITsindicates which interrupts will be disabled. This parameter can be any combination of
  • CAN_Interrupts.
Return values
HALstatus

Definition at line 1664 of file stm32l4xx_hal_can.c.

1665 {
1666  HAL_CAN_StateTypeDef state = hcan->State;
1667 
1668  /* Check function parameters */
1669  assert_param(IS_CAN_IT(InactiveITs));
1670 
1671  if ((state == HAL_CAN_STATE_READY) ||
1672  (state == HAL_CAN_STATE_LISTENING))
1673  {
1674  /* Disable the selected interrupts */
1675  __HAL_CAN_DISABLE_IT(hcan, InactiveITs);
1676 
1677  /* Return function status */
1678  return HAL_OK;
1679  }
1680  else
1681  {
1682  /* Update error code */
1683  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1684 
1685  return HAL_ERROR;
1686  }
1687 }
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_IRQHandler()

void HAL_CAN_IRQHandler ( CAN_HandleTypeDef hcan)

Handles CAN interrupt request.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None

Definition at line 1695 of file stm32l4xx_hal_can.c.

1696 {
1697  uint32_t errorcode = HAL_CAN_ERROR_NONE;
1698  uint32_t interrupts = READ_REG(hcan->Instance->IER);
1699  uint32_t msrflags = READ_REG(hcan->Instance->MSR);
1700  uint32_t tsrflags = READ_REG(hcan->Instance->TSR);
1701  uint32_t rf0rflags = READ_REG(hcan->Instance->RF0R);
1702  uint32_t rf1rflags = READ_REG(hcan->Instance->RF1R);
1703  uint32_t esrflags = READ_REG(hcan->Instance->ESR);
1704 
1705  /* Transmit Mailbox empty interrupt management *****************************/
1706  if ((interrupts & CAN_IT_TX_MAILBOX_EMPTY) != 0U)
1707  {
1708  /* Transmit Mailbox 0 management *****************************************/
1709  if ((tsrflags & CAN_TSR_RQCP0) != 0U)
1710  {
1711  /* Clear the Transmission Complete flag (and TXOK0,ALST0,TERR0 bits) */
1712  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_RQCP0);
1713 
1714  if ((tsrflags & CAN_TSR_TXOK0) != 0U)
1715  {
1716  /* Transmission Mailbox 0 complete callback */
1717 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1718  /* Call registered callback*/
1719  hcan->TxMailbox0CompleteCallback(hcan);
1720 #else
1721  /* Call weak (surcharged) callback */
1723 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1724  }
1725  else
1726  {
1727  if ((tsrflags & CAN_TSR_ALST0) != 0U)
1728  {
1729  /* Update error code */
1730  errorcode |= HAL_CAN_ERROR_TX_ALST0;
1731  }
1732  else if ((tsrflags & CAN_TSR_TERR0) != 0U)
1733  {
1734  /* Update error code */
1735  errorcode |= HAL_CAN_ERROR_TX_TERR0;
1736  }
1737  else
1738  {
1739  /* Transmission Mailbox 0 abort callback */
1740 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1741  /* Call registered callback*/
1742  hcan->TxMailbox0AbortCallback(hcan);
1743 #else
1744  /* Call weak (surcharged) callback */
1746 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1747  }
1748  }
1749  }
1750 
1751  /* Transmit Mailbox 1 management *****************************************/
1752  if ((tsrflags & CAN_TSR_RQCP1) != 0U)
1753  {
1754  /* Clear the Transmission Complete flag (and TXOK1,ALST1,TERR1 bits) */
1755  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_RQCP1);
1756 
1757  if ((tsrflags & CAN_TSR_TXOK1) != 0U)
1758  {
1759  /* Transmission Mailbox 1 complete callback */
1760 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1761  /* Call registered callback*/
1762  hcan->TxMailbox1CompleteCallback(hcan);
1763 #else
1764  /* Call weak (surcharged) callback */
1766 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1767  }
1768  else
1769  {
1770  if ((tsrflags & CAN_TSR_ALST1) != 0U)
1771  {
1772  /* Update error code */
1773  errorcode |= HAL_CAN_ERROR_TX_ALST1;
1774  }
1775  else if ((tsrflags & CAN_TSR_TERR1) != 0U)
1776  {
1777  /* Update error code */
1778  errorcode |= HAL_CAN_ERROR_TX_TERR1;
1779  }
1780  else
1781  {
1782  /* Transmission Mailbox 1 abort callback */
1783 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1784  /* Call registered callback*/
1785  hcan->TxMailbox1AbortCallback(hcan);
1786 #else
1787  /* Call weak (surcharged) callback */
1789 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1790  }
1791  }
1792  }
1793 
1794  /* Transmit Mailbox 2 management *****************************************/
1795  if ((tsrflags & CAN_TSR_RQCP2) != 0U)
1796  {
1797  /* Clear the Transmission Complete flag (and TXOK2,ALST2,TERR2 bits) */
1798  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_RQCP2);
1799 
1800  if ((tsrflags & CAN_TSR_TXOK2) != 0U)
1801  {
1802  /* Transmission Mailbox 2 complete callback */
1803 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1804  /* Call registered callback*/
1805  hcan->TxMailbox2CompleteCallback(hcan);
1806 #else
1807  /* Call weak (surcharged) callback */
1809 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1810  }
1811  else
1812  {
1813  if ((tsrflags & CAN_TSR_ALST2) != 0U)
1814  {
1815  /* Update error code */
1816  errorcode |= HAL_CAN_ERROR_TX_ALST2;
1817  }
1818  else if ((tsrflags & CAN_TSR_TERR2) != 0U)
1819  {
1820  /* Update error code */
1821  errorcode |= HAL_CAN_ERROR_TX_TERR2;
1822  }
1823  else
1824  {
1825  /* Transmission Mailbox 2 abort callback */
1826 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1827  /* Call registered callback*/
1828  hcan->TxMailbox2AbortCallback(hcan);
1829 #else
1830  /* Call weak (surcharged) callback */
1832 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1833  }
1834  }
1835  }
1836  }
1837 
1838  /* Receive FIFO 0 overrun interrupt management *****************************/
1839  if ((interrupts & CAN_IT_RX_FIFO0_OVERRUN) != 0U)
1840  {
1841  if ((rf0rflags & CAN_RF0R_FOVR0) != 0U)
1842  {
1843  /* Set CAN error code to Rx Fifo 0 overrun error */
1844  errorcode |= HAL_CAN_ERROR_RX_FOV0;
1845 
1846  /* Clear FIFO0 Overrun Flag */
1847  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV0);
1848  }
1849  }
1850 
1851  /* Receive FIFO 0 full interrupt management ********************************/
1852  if ((interrupts & CAN_IT_RX_FIFO0_FULL) != 0U)
1853  {
1854  if ((rf0rflags & CAN_RF0R_FULL0) != 0U)
1855  {
1856  /* Clear FIFO 0 full Flag */
1857  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF0);
1858 
1859  /* Receive FIFO 0 full Callback */
1860 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1861  /* Call registered callback*/
1862  hcan->RxFifo0FullCallback(hcan);
1863 #else
1864  /* Call weak (surcharged) callback */
1866 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1867  }
1868  }
1869 
1870  /* Receive FIFO 0 message pending interrupt management *********************/
1871  if ((interrupts & CAN_IT_RX_FIFO0_MSG_PENDING) != 0U)
1872  {
1873  /* Check if message is still pending */
1874  if ((hcan->Instance->RF0R & CAN_RF0R_FMP0) != 0U)
1875  {
1876  /* Receive FIFO 0 mesage pending Callback */
1877 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1878  /* Call registered callback*/
1879  hcan->RxFifo0MsgPendingCallback(hcan);
1880 #else
1881  /* Call weak (surcharged) callback */
1883 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1884  }
1885  }
1886 
1887  /* Receive FIFO 1 overrun interrupt management *****************************/
1888  if ((interrupts & CAN_IT_RX_FIFO1_OVERRUN) != 0U)
1889  {
1890  if ((rf1rflags & CAN_RF1R_FOVR1) != 0U)
1891  {
1892  /* Set CAN error code to Rx Fifo 1 overrun error */
1893  errorcode |= HAL_CAN_ERROR_RX_FOV1;
1894 
1895  /* Clear FIFO1 Overrun Flag */
1896  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV1);
1897  }
1898  }
1899 
1900  /* Receive FIFO 1 full interrupt management ********************************/
1901  if ((interrupts & CAN_IT_RX_FIFO1_FULL) != 0U)
1902  {
1903  if ((rf1rflags & CAN_RF1R_FULL1) != 0U)
1904  {
1905  /* Clear FIFO 1 full Flag */
1906  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF1);
1907 
1908  /* Receive FIFO 1 full Callback */
1909 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1910  /* Call registered callback*/
1911  hcan->RxFifo1FullCallback(hcan);
1912 #else
1913  /* Call weak (surcharged) callback */
1915 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1916  }
1917  }
1918 
1919  /* Receive FIFO 1 message pending interrupt management *********************/
1920  if ((interrupts & CAN_IT_RX_FIFO1_MSG_PENDING) != 0U)
1921  {
1922  /* Check if message is still pending */
1923  if ((hcan->Instance->RF1R & CAN_RF1R_FMP1) != 0U)
1924  {
1925  /* Receive FIFO 1 mesage pending Callback */
1926 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1927  /* Call registered callback*/
1928  hcan->RxFifo1MsgPendingCallback(hcan);
1929 #else
1930  /* Call weak (surcharged) callback */
1932 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1933  }
1934  }
1935 
1936  /* Sleep interrupt management *********************************************/
1937  if ((interrupts & CAN_IT_SLEEP_ACK) != 0U)
1938  {
1939  if ((msrflags & CAN_MSR_SLAKI) != 0U)
1940  {
1941  /* Clear Sleep interrupt Flag */
1942  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_SLAKI);
1943 
1944  /* Sleep Callback */
1945 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1946  /* Call registered callback*/
1947  hcan->SleepCallback(hcan);
1948 #else
1949  /* Call weak (surcharged) callback */
1950  HAL_CAN_SleepCallback(hcan);
1951 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1952  }
1953  }
1954 
1955  /* WakeUp interrupt management *********************************************/
1956  if ((interrupts & CAN_IT_WAKEUP) != 0U)
1957  {
1958  if ((msrflags & CAN_MSR_WKUI) != 0U)
1959  {
1960  /* Clear WakeUp Flag */
1961  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_WKU);
1962 
1963  /* WakeUp Callback */
1964 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
1965  /* Call registered callback*/
1966  hcan->WakeUpFromRxMsgCallback(hcan);
1967 #else
1968  /* Call weak (surcharged) callback */
1970 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
1971  }
1972  }
1973 
1974  /* Error interrupts management *********************************************/
1975  if ((interrupts & CAN_IT_ERROR) != 0U)
1976  {
1977  if ((msrflags & CAN_MSR_ERRI) != 0U)
1978  {
1979  /* Check Error Warning Flag */
1980  if (((interrupts & CAN_IT_ERROR_WARNING) != 0U) &&
1981  ((esrflags & CAN_ESR_EWGF) != 0U))
1982  {
1983  /* Set CAN error code to Error Warning */
1984  errorcode |= HAL_CAN_ERROR_EWG;
1985 
1986  /* No need for clear of Error Warning Flag as read-only */
1987  }
1988 
1989  /* Check Error Passive Flag */
1990  if (((interrupts & CAN_IT_ERROR_PASSIVE) != 0U) &&
1991  ((esrflags & CAN_ESR_EPVF) != 0U))
1992  {
1993  /* Set CAN error code to Error Passive */
1994  errorcode |= HAL_CAN_ERROR_EPV;
1995 
1996  /* No need for clear of Error Passive Flag as read-only */
1997  }
1998 
1999  /* Check Bus-off Flag */
2000  if (((interrupts & CAN_IT_BUSOFF) != 0U) &&
2001  ((esrflags & CAN_ESR_BOFF) != 0U))
2002  {
2003  /* Set CAN error code to Bus-Off */
2004  errorcode |= HAL_CAN_ERROR_BOF;
2005 
2006  /* No need for clear of Error Bus-Off as read-only */
2007  }
2008 
2009  /* Check Last Error Code Flag */
2010  if (((interrupts & CAN_IT_LAST_ERROR_CODE) != 0U) &&
2011  ((esrflags & CAN_ESR_LEC) != 0U))
2012  {
2013  switch (esrflags & CAN_ESR_LEC)
2014  {
2015  case (CAN_ESR_LEC_0):
2016  /* Set CAN error code to Stuff error */
2017  errorcode |= HAL_CAN_ERROR_STF;
2018  break;
2019  case (CAN_ESR_LEC_1):
2020  /* Set CAN error code to Form error */
2021  errorcode |= HAL_CAN_ERROR_FOR;
2022  break;
2023  case (CAN_ESR_LEC_1 | CAN_ESR_LEC_0):
2024  /* Set CAN error code to Acknowledgement error */
2025  errorcode |= HAL_CAN_ERROR_ACK;
2026  break;
2027  case (CAN_ESR_LEC_2):
2028  /* Set CAN error code to Bit recessive error */
2029  errorcode |= HAL_CAN_ERROR_BR;
2030  break;
2031  case (CAN_ESR_LEC_2 | CAN_ESR_LEC_0):
2032  /* Set CAN error code to Bit Dominant error */
2033  errorcode |= HAL_CAN_ERROR_BD;
2034  break;
2035  case (CAN_ESR_LEC_2 | CAN_ESR_LEC_1):
2036  /* Set CAN error code to CRC error */
2037  errorcode |= HAL_CAN_ERROR_CRC;
2038  break;
2039  default:
2040  break;
2041  }
2042 
2043  /* Clear Last error code Flag */
2044  CLEAR_BIT(hcan->Instance->ESR, CAN_ESR_LEC);
2045  }
2046  }
2047 
2048  /* Clear ERRI Flag */
2049  __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_ERRI);
2050  }
2051 
2052  /* Call the Error call Back in case of Errors */
2053  if (errorcode != HAL_CAN_ERROR_NONE)
2054  {
2055  /* Update error code in handle */
2056  hcan->ErrorCode |= errorcode;
2057 
2058  /* Call Error callback function */
2059 #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
2060  /* Call registered callback*/
2061  hcan->ErrorCallback(hcan);
2062 #else
2063  /* Call weak (surcharged) callback */
2064  HAL_CAN_ErrorCallback(hcan);
2065 #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
2066  }
2067 }
void(* TxMailbox0CompleteCallback)(struct __CAN_HandleTypeDef *hcan)
void(* RxFifo0MsgPendingCallback)(struct __CAN_HandleTypeDef *hcan)
void(* SleepCallback)(struct __CAN_HandleTypeDef *hcan)
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
Rx FIFO 0 message pending callback.
void HAL_CAN_SleepCallback(CAN_HandleTypeDef *hcan)
Sleep callback.
void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan)
Transmission Mailbox 1 complete callback.
void(* RxFifo0FullCallback)(struct __CAN_HandleTypeDef *hcan)
void HAL_CAN_TxMailbox2AbortCallback(CAN_HandleTypeDef *hcan)
Transmission Mailbox 2 Cancellation callback.
void(* RxFifo1FullCallback)(struct __CAN_HandleTypeDef *hcan)
void(* ErrorCallback)(struct __CAN_HandleTypeDef *hcan)
void(* TxMailbox1CompleteCallback)(struct __CAN_HandleTypeDef *hcan)
void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan)
Rx FIFO 0 full callback.
void(* WakeUpFromRxMsgCallback)(struct __CAN_HandleTypeDef *hcan)
void HAL_CAN_RxFifo1FullCallback(CAN_HandleTypeDef *hcan)
Rx FIFO 1 full callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void(* TxMailbox0AbortCallback)(struct __CAN_HandleTypeDef *hcan)
void(* TxMailbox2CompleteCallback)(struct __CAN_HandleTypeDef *hcan)
void(* TxMailbox1AbortCallback)(struct __CAN_HandleTypeDef *hcan)
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
Rx FIFO 1 message pending callback.
void HAL_CAN_WakeUpFromRxMsgCallback(CAN_HandleTypeDef *hcan)
WakeUp from Rx message callback.
void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan)
Transmission Mailbox 0 Cancellation callback.
void(* TxMailbox2AbortCallback)(struct __CAN_HandleTypeDef *hcan)
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan)
Error CAN callback.
void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan)
Transmission Mailbox 0 complete callback.
void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan)
Transmission Mailbox 2 complete callback.
void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan)
Transmission Mailbox 1 Cancellation callback.
void(* RxFifo1MsgPendingCallback)(struct __CAN_HandleTypeDef *hcan)