123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /************************************************************************
- Project: Welling Motor Control Paltform
- Filename: flash_master.c
- Partner Filename: flash_master.h
- Description: flash master driver
- Complier: IAR Embedded Workbench for ARM 8.40.2
- CPU TYPE : STM32F30x
- *************************************************************************
- Copyright (c) 20 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- *************************************************************************
- Revising History (ECL of this file):
- M0_20220410, by Ling Baizhou, create this file;
- ************************************************************************/
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
- *************************************************************************/
- #ifndef _FLASH_MASTER_C
- #define _FLASH_MASTER_C_
- #endif
- #ifdef RUN_ARCH_SIM
- #include "flash_master.h"
- FLASH_PARA_TYPE flash_stPara;
- void flash_voWrite(void)
- {}
- void flash_voRead(void)
- {}
- void flash_voParaInit(void)
- {}
- void flash_voErrorWrite(void)
- {}
- void flash_voErrorRead(void)
- {}
- void FLASH_voWriteMoreData(ULONG startAddress, const UWORD writeData[], UWORD countToWrite)
- {}
- void FLASH_voReadMoreData(ULONG startAddress, UWORD readData[], UWORD countToRead)
- {}
- #else
- /************************************************************************
- Included File
- *************************************************************************/
- #include "flash_master.h"
- #include "gd32f30x.h"
- #include "queue.h"
- #include "string.h"
- #include "AssistCurve.h"
- /*************************************************************************
- Exported Functions (N/A)
- *************************************************************************/
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- FLASH_PARA_TYPE flash_stPara;
- //从指定地址开始写入多个数据
- void FLASH_voWriteMoreData(ULONG startAddress, const UWORD writeData[], UWORD countToWrite)
- {
- UWORD dataIndex;
- if (startAddress < FLASH_BASE || ((startAddress + countToWrite * 2) >= (FLASH_END)))
- {
- return; //非法地址
- }
- fmc_unlock(); //解锁写保护
- while (fmc_page_erase((uint32_t)startAddress) != FMC_READY)
- {
- ;
- } //擦除这个扇区
- for (dataIndex = 0; dataIndex < countToWrite; dataIndex++)
- {
- fmc_halfword_program((uint32_t)startAddress + dataIndex * 2, (uint16_t)writeData[dataIndex]);
- }
- fmc_lock();//上锁写保护
- }
- //读取指定地址的半字(16位数据)
- static UWORD FLASH_ReadWord(ULONG address)
- {
- return *(__IO UWORD *)address;
- }
- //从指定地址开始读取多个数据
- void FLASH_voReadMoreData(ULONG startAddress, UWORD readData[], UWORD countToRead)
- {
- UWORD dataIndex;
- for (dataIndex = 0; dataIndex < countToRead; dataIndex++)
- {
- readData[dataIndex] = FLASH_ReadWord(startAddress + dataIndex * 2);
- }
- }
- void flash_voWrite(void)
- {
- UWORD count_len = sizeof(FLASH_PARA_TYPE) / 2;
- FLASH_voWriteMoreData(StartServerManageFlashAddress, (UWORD *)(&flash_stPara), count_len);
- }
- void flash_voRead(void)
- {
- UWORD count_len = sizeof(FLASH_PARA_TYPE) / 2;
- FLASH_voReadMoreData(StartServerManageFlashAddress, (UWORD *)(&flash_stPara), count_len);
- }
- void flash_voParaInit(void)
- {
- memset(&flash_stPara, 0, sizeof(FLASH_PARA_TYPE));
- SLONG Flash_TorqueAssGain[15][4] = TORQUE_ASSIST_DEFAULT;
- SLONG Flash_CadAssGain[5][4] = CADENCE_ASSIST_DEFAULT;
- memcpy(&flash_stPara.slTorqAssGain[0], &Flash_TorqueAssGain[0], sizeof(Flash_TorqueAssGain));
- memcpy(&flash_stPara.slCadAssGain[0], &Flash_CadAssGain[0], sizeof(Flash_CadAssGain));
- flash_voWrite();
- }
- void flash_voErrorWrite(void)
- {
- UWORD count_len = sizeof(ERROR_LOG) * QUEUE_SIZE/ 2;
- que_stFlashErrorLog.stLog[0].ubHead = que_stFlashErrorLog.ubHead;
- que_stFlashErrorLog.stLog[0].ubRear = que_stFlashErrorLog.ubRear;
- FLASH_voWriteMoreData(StartServerManageErrorFlashAddress, (UWORD *)(&que_stFlashErrorLog.stLog), count_len);
- }
- void flash_voErrorRead(void)
- {
- UWORD count_len = sizeof(ERROR_LOG) * QUEUE_SIZE/ 2;
- FLASH_voReadMoreData(StartServerManageErrorFlashAddress, (UWORD *)(&que_stFlashErrorLog.stLog), count_len);
- que_stFlashErrorLog.ubHead = que_stFlashErrorLog.stLog[0].ubHead;
- que_stFlashErrorLog.ubRear = que_stFlashErrorLog.stLog[0].ubRear;
- if(que_stFlashErrorLog.ubHead == 0xFF)
- {
- que_voInit(&que_stFlashErrorLog);
- }
- }
- void flash_voErrorClear(void)
- {
- fmc_unlock(); //解锁写保护
- while (fmc_page_erase((uint32_t)StartServerManageErrorFlashAddress) != FMC_READY)
- {
- ;
- } //擦除这个扇区
- fmc_lock();//上锁写保护
-
- //que_voInit(&que_stFlashErrorLog);
- }
- /************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co., Ltd.
- All rights reserved.
- *************************************************************************/
- #ifdef _FLASH_MASTER_C
- #undef _FLASH_MASTER_C_
- #endif
- #endif
- /*************************************************************************
- End of this File (EOF)
- Do not put anything after this part!
- *************************************************************************/
|