123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- /**
- ******************************************************************************
- * @file eeprom.c
- * @author Vincent
- * @version V1.0.0
- * @date 23-12-2015
- * @brief AT24C02 eeprom read and write function.
- ******************************************************************************
- *
- * COPYRIGHT(c) 2015 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "can_driver.h"
- /* Private variables ---------------接收缓存区------------------------------------------*/
- #if CAN_RxBufSize1 != 0
- CD_UINT8 CAN_RxBuf1[CAN_RxBufSize1];
- CAN_Buf_TypeDef CAN_RxBuf_Struct1={0x0715,CAN_RxBufSize1,0,0,0,0,CAN_RxBuf1};
- #endif
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- static void CAN_Rx_ISR(CAN_Buf_TypeDef*ptCANRx,CD_UINT8 ucLength);
- /*******************************************************************************
- * Function:
- * Discrible:
- * Input:
- * Output:
- * Return:
- * Others:
- * date version author record
- * -----------------------------------------------
- * 20151107 V1.0 VINCENT Create
- *********************************************************************************/
- CD_UINT8 cd_GetChar(CAN_Buf_TypeDef * ptCANRx)
- {
- CD_UINT8 ucData;
- ucData = *((*ptCANRx).pcBufAddr + (*ptCANRx).ucBufRdInde);
- if ((*ptCANRx).ucBufCnt != 0)
- {
- if (++(*ptCANRx).ucBufRdInde == (*ptCANRx).ucBufSize)
- {
- (*ptCANRx).ucBufRdInde = 0;
- }
- __HAL_CAN_DISABLE_IT(&hcan, CAN_IT_FMP0);
- --(*ptCANRx).ucBufCnt;
- __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);
- }
- return ucData;
- }
- /*******************************************************************************
- * Function:
- * Discrible:
- * Input:
- * Output:
- * Return:
- * Others:
- * date version author record
- * -----------------------------------------------
- * 20151107 V1.0 VINCENT Create
- *********************************************************************************/
- CD_UINT8 cd_ReadChar(CAN_Buf_TypeDef * ptCANRx, CD_UINT16 uwNum)
- {
- CD_UINT8 ucData;
- CD_UINT16 i;
- i = uwNum;
- if ((*ptCANRx).ucBufCnt >= uwNum)
- {
- i += (*ptCANRx).ucBufRdInde;
- if (i >= (*ptCANRx).ucBufSize)
- {
- i -=((*ptCANRx).ucBufSize);
- }
- }
- else
- {
- i=0;
- }
- ucData = *((*ptCANRx).pcBufAddr + i);
- return ucData;
- }
- /*******************************************************************************
- * Function:
- * Discrible:
- * Input:
- * Output:
- * Return:
- * Others:
- * date version author record
- * -----------------------------------------------
- * 20151107 V1.0 VINCENT Create
- *********************************************************************************/
- void cd_DelChar(CAN_Buf_TypeDef * ptCANRx, CD_UINT16 uwNum)
- {
- CD_UINT16 i;
- if ((*ptCANRx).ucBufCnt >= uwNum)
- {
- __HAL_CAN_DISABLE_IT(&hcan, CAN_IT_FMP0);
- (*ptCANRx).ucBufCnt -= uwNum;
- __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);
- i = uwNum;
- i += (*ptCANRx).ucBufRdInde;
- if (i >= (*ptCANRx).ucBufSize)
- {
- i -= (*ptCANRx).ucBufSize;
- }
- (*ptCANRx).ucBufRdInde = i;
- }
- else
- {
- __HAL_CAN_DISABLE_IT(&hcan, CAN_IT_FMP0);
- i = (*ptCANRx).ucBufCnt;
- (*ptCANRx).ucBufCnt = 0;
- __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);
- i += (*ptCANRx).ucBufRdInde;
- if (i >= (*ptCANRx).ucBufSize)
- {
- i -= (*ptCANRx).ucBufSize;
- }
- (*ptCANRx).ucBufRdInde = i;
- }
- }
- /*******************************************************************************
- * Function:
- * Discrible:
- * Input:
- * Output:
- * Return:
- * Others:
- * date version author record
- * -----------------------------------------------
- * 20151107 V1.0 VINCENT Create
- *********************************************************************************/
- void CAN_Rx_ISR(CAN_Buf_TypeDef*ptCANRx,CD_UINT8 ucLength)
- {
- for(CD_UINT8 i=0;i<ucLength;i++)
- {
- *((* ptCANRx).pcBufAddr + (* ptCANRx).ucBufWrInde) = hcan.pRxMsg->Data[i];
- if(++(* ptCANRx).ucBufWrInde >= (* ptCANRx).ucBufSize)
- {
- (* ptCANRx).ucBufWrInde = 0;
- }
- if(++(* ptCANRx).ucBufCnt > (* ptCANRx).ucBufSize)
- {
- (* ptCANRx).ucBufCnt = (* ptCANRx).ucBufSize;
- (* ptCANRx).ucBufOvf = 1;
- }
- }
- }
- /*******************************************************************************
- * Function:void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *CanHandle)
- * Discrible:接收总段回调函数,进入中断后,中断就被清零了,所以在执行完回调函数后需要开中断
- * Input:
- * Output:
- * Return:
- * Others:
- * date version author record
- * -----------------------------------------------
- * 20151107 V1.0 VINCENT Create
- *********************************************************************************/
- void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *CanHandle)
- {
- if((CanHandle->pRxMsg->IDE != CAN_ID_STD)||(CanHandle->pRxMsg->DLC == 0))
- {
- __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);//开接收中断
- return;
- }
-
- if(CanHandle->pRxMsg->StdId == 0x0751)
- {
- CAN_Rx_ISR(&CAN_RxBuf_Struct1,CanHandle->pRxMsg->DLC);
- }
- __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);//开接收中断
- }
- void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan)
- {
- __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0);
- }
- /************************ (C) END OF FILE *********************************/
|