Commenting through most of the remaining files.

Fixing logic errors throughout as well
This commit is contained in:
Ben V. Brown
2016-09-13 23:50:51 +10:00
parent 0b4068976c
commit 624fbe8e3f
19 changed files with 348 additions and 602 deletions

View File

@@ -10,3 +10,14 @@ This is implimented using a ram buffer for the disk.
# Future improvements to be made
These features are things I would like to add to the firmware
* Use hardware PWM for driving the heating element.
* Use the sysTick hardware for timing of events
* Move all the settings to an on device menu system instead of usb link
* Move error codes into a unified struct
* Rewrite most of the OLED stack to not require hardcoded values
* Rework the modes of the unit to be neater

View File

@@ -14,7 +14,7 @@
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1236130657" name="Debug" parent="fr.ac6.managedbuild.config.gnu.cross.exe.debug" postannouncebuildStep="Generating binary and Printing size information:" postbuildStep="arm-none-eabi-objcopy -O binary &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${BuildArtifactFileBaseName}.bin&quot;; arm-none-eabi-size &quot;${BuildArtifactFileName}&quot; &amp; arm-none-eabi-size --format=berkeley ${BuildArtifactFileName}"> <configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1236130657" name="Debug" parent="fr.ac6.managedbuild.config.gnu.cross.exe.debug" postannouncebuildStep="Generating binary and Printing size information:" postbuildStep="arm-none-eabi-objcopy -O binary &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${BuildArtifactFileBaseName}.bin&quot;; arm-none-eabi-size &quot;${BuildArtifactFileName}&quot; ">
<folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1236130657." name="/" resourcePath=""> <folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1236130657." name="/" resourcePath="">
<toolChain id="fr.ac6.managedbuild.toolchain.gnu.cross.exe.debug.2123758208" name="Ac6 STM32 MCU GCC" superClass="fr.ac6.managedbuild.toolchain.gnu.cross.exe.debug"> <toolChain id="fr.ac6.managedbuild.toolchain.gnu.cross.exe.debug.2123758208" name="Ac6 STM32 MCU GCC" superClass="fr.ac6.managedbuild.toolchain.gnu.cross.exe.debug">
<option id="fr.ac6.managedbuild.option.gnu.cross.mcu.1416828544" name="Mcu" superClass="fr.ac6.managedbuild.option.gnu.cross.mcu" value="STM32F103T8Ux" valueType="string"/> <option id="fr.ac6.managedbuild.option.gnu.cross.mcu.1416828544" name="Mcu" superClass="fr.ac6.managedbuild.option.gnu.cross.mcu" value="STM32F103T8Ux" valueType="string"/>
@@ -22,7 +22,7 @@
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="fr.ac6.managedbuild.targetPlatform.gnu.cross.1811524023" isAbstract="false" osList="all" superClass="fr.ac6.managedbuild.targetPlatform.gnu.cross"/> <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="fr.ac6.managedbuild.targetPlatform.gnu.cross.1811524023" isAbstract="false" osList="all" superClass="fr.ac6.managedbuild.targetPlatform.gnu.cross"/>
<builder buildPath="${workspace_loc:/ts100}/Debug" id="fr.ac6.managedbuild.builder.gnu.cross.727350462" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="fr.ac6.managedbuild.builder.gnu.cross"/> <builder buildPath="${workspace_loc:/ts100}/Debug" id="fr.ac6.managedbuild.builder.gnu.cross.727350462" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="fr.ac6.managedbuild.builder.gnu.cross"/>
<tool id="fr.ac6.managedbuild.tool.gnu.cross.c.compiler.1500724168" name="MCU GCC Compiler" superClass="fr.ac6.managedbuild.tool.gnu.cross.c.compiler"> <tool id="fr.ac6.managedbuild.tool.gnu.cross.c.compiler.1500724168" name="MCU GCC Compiler" superClass="fr.ac6.managedbuild.tool.gnu.cross.c.compiler">
<option id="fr.ac6.managedbuild.gnu.c.compiler.option.optimization.level.963224364" name="Optimization Level" superClass="fr.ac6.managedbuild.gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="fr.ac6.managedbuild.gnu.c.optimization.level.size" valueType="enumerated"/> <option id="fr.ac6.managedbuild.gnu.c.compiler.option.optimization.level.963224364" name="Optimization Level" superClass="fr.ac6.managedbuild.gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="fr.ac6.managedbuild.gnu.c.optimization.level.more" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.400507088" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/> <option id="gnu.c.compiler.option.debugging.level.400507088" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.1436405353" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option id="gnu.c.compiler.option.include.paths.1436405353" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/inc&quot;"/> <listOptionValue builtIn="false" value="&quot;${ProjDirPath}/inc&quot;"/>

View File

@@ -1,35 +1,41 @@
/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ******************** /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************
File Name : APP_Version.h File Name : APP_Version.h
Version : S100 APP Ver 2.11 Version : S100 APP Ver 2.11
Description: Description:
Author : bure & Celery Author : bure & Celery
Data: 2015/08/03 Data: 2015/08/03
History: History:
2015/08/03 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2015/08/03 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************************************/ *******************************************************************************/
#ifndef __VERSION_H #ifndef __VERSION_H
#define __VERSION_H #define __VERSION_H
#define M_VER 'V','0' #define M_VER 'V','0'
#define S_VER '0','1' #define S_VER '0','1'
#define OEM_TYPE "0" #define OEM_TYPE "0"
#define APP_BASE 0x0800C000 #define APP_BASE 0x0800C000
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#ifdef TYPE_DS201 #ifdef TYPE_DS201
#define PRODUCT_INFO "DS201" #define PRODUCT_INFO "DS201"
#define SCH_VER "1.7B" #define SCH_VER "1.7B"
#elif TYPE_DS202 #else
#include "DS202V1_6.h" #ifdef TYPE_DS202
#define FLASH_PAGE 0x0800 #include "DS202V1_6.h"
#elif TYPE_DS203 #define FLASH_PAGE 0x0800
#define PRODUCT_INFO "DS203" #else
#define SCH_VER "2.70" #ifdef TYPE_DS203
#elif TYPE_S100 #define PRODUCT_INFO "DS203"
#define PRODUCT_INFO "TS100" #define SCH_VER "2.70"
#include "S100V0_1.h" #else
#endif #ifdef TYPE_S100
#define PRODUCT_INFO "TS100"
#include "S100V0_1.h"
#endif
#endif
#endif
#endif
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#define DFU_VER {M_VER,'.',S_VER,LCD_M, 0} #define DFU_VER {M_VER,'.',S_VER,LCD_M, 0}

View File

@@ -1,16 +1,16 @@
/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. **********************
File Name : Disk.h File Name : Disk.h
Version : S100 APP Ver 2.11 Version : S100 APP Ver 2.11
Description: Description:
Author : Celery Author : Celery
Data: 2015/08/03 Data: 2015/08/03
History: History:
2015/08/03 : 2016/09/13 : Ben V. Brown - english comments
*******************************************************************************/ 2015/08/03 :
*******************************************************************************/
#ifndef __DISK_H #ifndef __DISK_H
#define __DISK_H #define __DISK_H
#include "stm32f10x_flash.h" #include "stm32f10x_flash.h"
#include "usb_scsi.h" #include "usb_scsi.h"
#include "usb_regs.h" #include "usb_regs.h"
@@ -31,7 +31,6 @@ History:
#define FILE_SECTOR &gDisk_buff[0x600] #define FILE_SECTOR &gDisk_buff[0x600]
#define Root (u8*)ROOT_SECTOR #define Root (u8*)ROOT_SECTOR
//#define APP_BASE 0x0800C000 //#define APP_BASE 0x0800C000
#define HEX 0 #define HEX 0
@@ -53,9 +52,9 @@ History:
//#define FAT_DATA 0x00FFFFF8 //#define FAT_DATA 0x00FFFFF8
#define VOLUME 0x40DD8D18 //0x3E645C29 #define VOLUME 0x40DD8D18 //0x3E645C29
#define BUFF 0 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD> #define BUFF 0 //
#define V32_BASE SECTOR_SIZE // V32 <20>ܹ<EFBFBD> 8*4=32 <20>ֽ<EFBFBD> #define V32_BASE SECTOR_SIZE // V32 8*4=32
#define W_ADDR 0 #define W_ADDR 0
#define ADDR 1 #define ADDR 1
#define H_ADDR 2 #define H_ADDR 2
@@ -65,7 +64,7 @@ History:
#define RD_CNT 6 #define RD_CNT 6
#define WR_CNT 7 #define WR_CNT 7
#define VAR_BASE V32_BASE + 32 // VAR <20>ܹ<EFBFBD> 9+17=26 <20>ֽ<EFBFBD> #define VAR_BASE V32_BASE + 32 // VAR 9+17=26
#define USB_ST 0 #define USB_ST 0
#define SEG_KIND 1 #define SEG_KIND 1
#define SEG_LEN 2 #define SEG_LEN 2
@@ -75,10 +74,9 @@ History:
#define DATA_CNT 6 #define DATA_CNT 6
#define F_TYPE 7 #define F_TYPE 7
#define F_FLAG 8 #define F_FLAG 8
#define SEG_DATA 9 // ͨ<>Ű<EFBFBD><C5B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 9~26 <20><>17<31>ֽ<EFBFBD> #define SEG_DATA 9 //9~26
u8 Cal_Val(u8 str[], u8 k, u8 flag);
u8 Cal_Val(u8 str[],u8 k,u8 flag);
void Disk_BuffInit(void); void Disk_BuffInit(void);
u8 ReWrite_All(void); u8 ReWrite_All(void);
u8 Config_Analysis(void); u8 Config_Analysis(void);
@@ -86,12 +84,12 @@ void Disk_BuffInit(void);
void Disk_SecWrite(u8* pbuffer, u32 disk_addr); void Disk_SecWrite(u8* pbuffer, u32 disk_addr);
void Close_File(void); void Close_File(void);
void Write_Memory(u32 w_offset, u32 w_length); void Write_Memory(u32 w_offset, u32 w_length);
void Read_Memory (u32 r_offset, u32 r_length); void Read_Memory(u32 r_offset, u32 r_length);
void Set_Ver(u8 str[],u8 i); void Set_Ver(u8 str[], u8 i);
void Erase(void); void Erase(void);
char * Get_Line(char *dst,char *src, int n,int m); char * Get_Line(char *dst, char *src, int n, int m);
void Upper(u8* str, u16 len); void Upper(u8* str, u16 len);
u8* SearchFile(u8* pfilename, u16* pfilelen,u16* root_addr); u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr);
u8 ReWriteFlsash(void); u8 ReWriteFlsash(void);
#endif #endif
/********************************* END OF FILE ******************************/ /********************************* END OF FILE ******************************/

View File

@@ -13,9 +13,9 @@
#define PP 0x02 // Write to Memory instruction #define PP 0x02 // Write to Memory instruction
#define PW 0x0A // Page write instruction #define PW 0x0A // Page write instruction
#define OK 0 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> #define OK 0 //
#define SEC_ERR 1 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD> #define SEC_ERR 1 //
#define TMAX 100000 // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> #define TMAX 100000 //
#define WIP_Flag 0x01 // Write In Progress (WIP) flag #define WIP_Flag 0x01 // Write In Progress (WIP) flag
#define Dummy_Byte 0xA5 #define Dummy_Byte 0xA5

View File

@@ -40,7 +40,7 @@ u32 Get_AvgAd(void);
int Get_SensorTmp(void); int Get_SensorTmp(void);
u16 Get_ThermometerTemp(void); u16 Get_ThermometerTemp(void);
s16 Get_Temp(s16 wk_temp); s16 Get_Temp(s16 wk_temp);
u32 Clear_Watchdog(void); void Clear_Watchdog(void);
u32 Start_Watchdog(u32 ms); u32 Start_Watchdog(u32 ms);
u8 Get_AlarmType(void); u8 Get_AlarmType(void);
void Set_AlarmType(u8 type); void Set_AlarmType(u8 type);

View File

@@ -5,15 +5,15 @@ Description:
Author : Celery Author : Celery
Data: 2015/07/07 Data: 2015/07/07
History: History:
2015/07/07 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2015/07/07 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************************************/ *******************************************************************************/
#ifndef __MMA8652FC__H #ifndef __MMA8652FC__H
#define __MMA8652FC__H #define __MMA8652FC__H
//--------------MMA8652 <EFBFBD><EFBFBD><EFBFBD>岿<EFBFBD><EFBFBD>----------------------------------------------// //--------------MMA8652 Device ID----------------------------------------------//
#define DEVICE_ADDR 0X1D #define DEVICE_ADDR 0X1D
//--------------MMA8652 <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-------------------------------------------// //--------------MMA8652 Registers-------------------------------------------//
#define STATUS_REG 0x00 #define STATUS_REG 0x00
#define X_MSB_REG 0X01 #define X_MSB_REG 0X01
#define X_LSB_REG 0X02 #define X_LSB_REG 0X02

View File

@@ -5,7 +5,8 @@
Author : bure & Celery Author : bure & Celery
Data: 2015/08/03 Data: 2015/08/03
History: History:
2015/08/03 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2016/09/13 Ben V. Brown -> English comments and cleaning up
2015/08/03
*******************************************************************************/ *******************************************************************************/
#include <string.h> #include <string.h>
#include "FAT12.h" #include "FAT12.h"
@@ -16,11 +17,11 @@
#define FAT2_BASE 0x00002800 // FAT2 #define FAT2_BASE 0x00002800 // FAT2
#define ROOT_BASE 0x00004000 // #define ROOT_BASE 0x00004000 //
#define FILE_BASE 0x00008000 // #define FILE_BASE 0x00008000 //
#define SEC_LEN 0x200 // #define SEC_LEN 512 //length of a sector -> 512 Bytes
#define FAT1_SEC 0x0C // FAT1 #define FAT1_SEC 0x0C // FAT1 Sector
#define FAT2_SEC 0x0C // FAT2 #define FAT2_SEC 0x0C // FAT2 Sector
#define OK 0 // #define OK 0 //Error codes
#define SEC_ERR 1 // #define SEC_ERR 1 //
#define FAT_ERR 2 // #define FAT_ERR 2 //
#define OVER 3 // #define OVER 3 //
@@ -31,7 +32,7 @@
#define RW 1 // #define RW 1 //
/******************************************************************************* /*******************************************************************************
Function: Function: NextCluster
Description: Description:
Input: Input:
*******************************************************************************/ *******************************************************************************/
@@ -49,25 +50,25 @@ u8 NextCluster(u16* pCluster) {
return OK; return OK;
} }
/******************************************************************************* /*******************************************************************************
Function: Function: ReadFileSec
Description: Description:
Input: Input:
*******************************************************************************/ *******************************************************************************/
u8 ReadFileSec(u8* pBuffer, u16* pCluster) { u8 ReadFileSec(u8* pBuffer, u16* pCluster) {
u32 ReadAddr = FILE_BASE + SEC_LEN * (*pCluster - 2); u32 ReadAddr = FILE_BASE + SEC_LEN * (*pCluster - 2);
//This code appears to read the data in two chunks of 256 bytes...
if (ReadDiskData(pBuffer, ReadAddr, 256) != OK) if (ReadDiskData(pBuffer, ReadAddr, 256) != OK)
return SEC_ERR; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> return SEC_ERR; //
pBuffer += 256; pBuffer += 256;
ReadAddr += 256; ReadAddr += 256;
if (ReadDiskData(pBuffer, ReadAddr, 256) != OK) if (ReadDiskData(pBuffer, ReadAddr, 256) != OK)
return SEC_ERR; // Failed to read the sector return SEC_ERR; // Failed to read the sector
if (NextCluster(pCluster) != 0) if (NextCluster(pCluster) != 0)
return FAT_ERR; // ȡ<><C8A1>һ<EFBFBD><D2BB><EFBFBD>غ<EFBFBD> return FAT_ERR; //
return OK; return OK;
} }
/******************************************************************************* /*******************************************************************************
Function: Function: ProgFileSec
Description: Description:
Input: Input:
*******************************************************************************/ *******************************************************************************/
@@ -76,30 +77,30 @@ u8 ProgFileSec(u8* pBuffer, u16* pCluster) {
u32 ProgAddr = FILE_BASE + SEC_LEN * (*pCluster - 2); u32 ProgAddr = FILE_BASE + SEC_LEN * (*pCluster - 2);
if (ProgDiskPage(pBuffer, ProgAddr) != OK) if (ProgDiskPage(pBuffer, ProgAddr) != OK)
return SEC_ERR; // дǰ<D0B4><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> return SEC_ERR; //
pBuffer += 256; pBuffer += 256;
ProgAddr += 256; ProgAddr += 256;
if (ProgDiskPage(pBuffer, ProgAddr) != OK) if (ProgDiskPage(pBuffer, ProgAddr) != OK)
return SEC_ERR; // д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> return SEC_ERR; //
Tmp = *pCluster; Tmp = *pCluster;
switch (Tmp) { switch (Tmp) {
case 0: // <20><><EFBFBD>дغ<D0B4> case 0:
case 1: // <20><><EFBFBD>дغ<D0B4> case 1:
if (SeekBlank(pBuffer, pCluster) != OK) if (SeekBlank(pBuffer, pCluster) != OK)
return OVER; return OVER;
if (SetCluster(pBuffer, pCluster) != OK) if (SetCluster(pBuffer, pCluster) != OK)
return SEC_ERR; return SEC_ERR;
*(pCluster + 1) = Tmp; *(pCluster + 1) = Tmp;
return OK; return OK;
case END: // <20><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD> case END:
default: default:
if (NextCluster(pCluster) != OK) if (NextCluster(pCluster) != OK)
return FAT_ERR; // ȡ<><C8A1>һ<EFBFBD><D2BB><EFBFBD>غ<EFBFBD> return FAT_ERR;
return OK; return OK;
} }
} }
/******************************************************************************* /*******************************************************************************
Function: Function: SeekBlank
Description: Description:
Input: Input:
*******************************************************************************/ *******************************************************************************/

View File

@@ -52,10 +52,8 @@ u32 Get_HeatingTime(void) {
return gHeat_cnt; return gHeat_cnt;
} }
/******************************************************************************* /*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Init_GTIME Function:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> Description: Init the global count down timers
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Init_Gtime(void) { void Init_Gtime(void) {
u8 i; u8 i;
@@ -88,10 +86,9 @@ void Delay_HalfMs(u32 ms) {
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: USB_Port Function: USB_Port
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD> USB <20>豸 IO <20>˿<EFBFBD> Description: Enables or disables the usb pins
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:State = ENABLE / DISABLE Input: state == ENABLE or DISABLE
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void USB_Port(u8 state) { void USB_Port(u8 state) {
USB_DN_LOW(); USB_DN_LOW();
@@ -279,10 +276,8 @@ void Adc_Init(void) {
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Init_Timer2 Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>ʼ<EFBFBD><CABC> <20><>ʱ<EFBFBD><CAB1>2 Description: Setup Timer2 to fire every 10ms
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Init_Timer2(void) { void Init_Timer2(void) {
NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure;
@@ -306,10 +301,8 @@ void Init_Timer2(void) {
NVIC_Init(&NVIC_InitStructure); NVIC_Init(&NVIC_InitStructure);
} }
/******************************************************************************* /*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Init_Timer3 Function:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>ʼ<EFBFBD><CABC> <20><>ʱ<EFBFBD><CAB1>3 Description: Init Timer3 to fire every 50us to be used to control the irons software PWM
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Init_Timer3(void) { void Init_Timer3(void) {
NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure;
@@ -334,7 +327,7 @@ void Init_Timer3(void) {
} }
/******************************************************************************* /*******************************************************************************
Function:TIM2_ISR Function:TIM2_ISR
Description:Handles Timer 2 tick. Description:Handles Timer 2 tick. (10mS)
Automatically decrements all >0 values in gTime. Automatically decrements all >0 values in gTime.
Also reads the buttons every 4 ticks Also reads the buttons every 4 ticks
*******************************************************************************/ *******************************************************************************/

View File

@@ -31,7 +31,7 @@ s16 gPrev_temp = 250; //
u8 gIs_restartkey = 0; // u8 gIs_restartkey = 0; //
u8 gPre_status = 1; // u8 gPre_status = 1; //
const DEVICE_INFO_SYS info_def = { "2.12", //Ver const DEVICE_INFO_SYS info_def = { "2.13", //Ver
2000, //T_Standby; // 200C=1800 2520 2000, //T_Standby; // 200C=1800 2520
3000, // T_Work; // 350C=3362, 3000, // T_Work; // 350C=3362,
100, //T_Step; 100, //T_Step;
@@ -98,7 +98,7 @@ s16 Get_TempVal(void) {
/******************************************************************************* /*******************************************************************************
Function:System_Init Function:System_Init
Description:Zeros out the device info to be a known start value (blank) Description:Init the device info to be a known start value (as defined at top of CTRL.c)
Input:Void Input:Void
Output:Void Output:Void
*******************************************************************************/ *******************************************************************************/

View File

@@ -68,26 +68,28 @@ const uint8_t BOOT_SEC[512] = { 0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53,
0x74, 0x6F, 0x20, 0x72, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x0D, 0x0A, 0x74, 0x6F, 0x20, 0x72, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x0D, 0x0A,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xCB, 0xD8, 0x55, 0xAA }; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xCB, 0xD8, 0x55, 0xAA };
static u8 gDisk_buff[0x2600]; //Buffer used to implement the virtual disk static u8 gDisk_buff[0x2600]; //RAM Buffer used to implement the virtual disk
static u32 gDisk_var[(512 + 32 + 28) / 4]; // static u32 gDisk_var[(512 + 32 + 28) / 4]; //
static u32 *gV32 = (u32*) &gDisk_var[512 / 4]; static u32 *gV32 = (u32*) &gDisk_var[512 / 4];
static u8 *gVar = (u8*) &gDisk_var[512 / 4 + 8]; static u8 *gVar = (u8*) &gDisk_var[512 / 4 + 8];
static u8 *gBuff = (u8*) &gDisk_var[0]; static u8 *gBuff = (u8*) &gDisk_var[0];
const u8 gFat_data[] = { 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; //{0xF8,0XFF,0XFF,0xff,0X0f};// const u8 gFat_data[] = { 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; //{0xF8,0XFF,0XFF,0xff,0X0f};//
//The options
const char *gKey_words[] = { "T_Standby", "T_Work", "Wait_Time", "Idle_Time", const char *gKey_words[] = { "T_Standby", "T_Work", "Wait_Time", "Idle_Time",
"T_Step", "Turn_Off_v", "TempShowFlag", "ZeroP_Ad" }; "T_Step", "Turn_Off_v", "TempShowFlag", "ZeroP_Ad" };
//default settings
const char *gDef_set[] = { "T_Standby=200", "T_Work=300", "Wait_Time=180", const char *gDef_set[] = { "T_Standby=200", "T_Work=300", "Wait_Time=180",
"Idle_Time=360", "T_Step=10", "Turn_Off_v=10", "TempShowFlag=0", "Idle_Time=360", "T_Step=10", "Turn_Off_v=10", "TempShowFlag=0",
"ZeroP_Ad=239" }; "ZeroP_Ad=239" };
//comments for accepted range
const char *gSet_range[] = { " #(100~400)\r\n", " #(100~400)\r\n", const char *gSet_range[] = { " #(100~400)\r\n", " #(100~400)\r\n",
" #(60~9999)\r\n", " #(300~9999)\r\n", " #(5~25)\r\n", " #(60~9999)\r\n", " #(300~9999)\r\n", " #(5~25)\r\n",
" #(9~12)\r\n", " #(0,1)\r\n", " #ReadOnly\r\n" }; " #(9~12)\r\n", " #(0,1)\r\n", " #ReadOnly\r\n" };
static u8 gFile_con[512]; static u8 gFile_con[512]; //file contents buffer
#define CONFIG_CONT 8 #define CONFIG_CONT 8 /*Number of variables in config.txt*/
u8 gRewriteflag[16]; u8 gRewriteflag[16]; //This flags if this sector has changed and needs to be written to flash
#define ROW_CONT 35 #define ROW_CONT 35
#define FILE_CONT 254 #define FILE_CONT 254
@@ -289,8 +291,8 @@ void Upper(u8* str, u16 len) {
/******************************************************************************* /*******************************************************************************
Function: SearchFile Function: SearchFile
Description: Description:
Inputs: (pfilename) filename to look for, (pfilelen) length of the filename,(root_addr) root folder to search from Inputs: (pfilename) filename to look for, (pfilelen) length of the file,(root_addr) root folder to search from
Outputs: NULL (failed) or Outputs: NULL (failed) or pointer to file start
*******************************************************************************/ *******************************************************************************/
u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) { u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) {
u16 n, sector; u16 n, sector;
@@ -301,7 +303,7 @@ u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) {
for (n = 0; n < 16; n++) { for (n = 0; n < 16; n++) {
memcpy(str_name, pdiraddr, 11); memcpy(str_name, pdiraddr, 11);
Upper(str_name, 11);//ensure path is upper case Upper(str_name, 11); //ensure path is upper case
if (memcmp(str_name, pfilename, 11) == 0) { if (memcmp(str_name, pfilename, 11) == 0) {
memcpy((u8*) pfilelen, pdiraddr + 0x1C, 2); memcpy((u8*) pfilelen, pdiraddr + 0x1C, 2);
memcpy((u8*) &sector, pdiraddr + 0x1A, 2); memcpy((u8*) &sector, pdiraddr + 0x1A, 2);
@@ -314,30 +316,6 @@ u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) {
return NULL; return NULL;
} }
const u8 LOGO[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xC0, 0xFF, 0xFF, 0xFF, 0x80, 0x1F, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFD, 0x80, 0xFF, 0xFF, 0xFF, 0x80, 0x1F, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0x00, 0x00, 0x00,
0x7F, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xF7, 0xFF, 0xFF, 0xF0, 0x00, 0x03, 0xFD,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x07, 0xFF, 0xFC, 0x01,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x07, 0x81, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x9F, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x07, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
/******************************************************************************* /*******************************************************************************
Function:Config_Analysis Function:Config_Analysis
Description:Reads the CONFIG.TXT if file is found and also the LOGIN.BMP file as well Description:Reads the CONFIG.TXT if file is found and also the LOGIN.BMP file as well
@@ -355,8 +333,8 @@ u8 Config_Analysis(void) {
root_addr = 0; root_addr = 0;
m = 0; m = 0;
j = 0; j = 0;
//read in the config.txt if it exists
if ((p_file = SearchFile("CONFIG TXT", &file_len, &root_addr))) { if ((p_file = SearchFile((u8*) ("CONFIG TXT"), &file_len, &root_addr))) {
memset(t_p, 0x00, CONFIG_CONT * ROW_CONT); memset(t_p, 0x00, CONFIG_CONT * ROW_CONT);
memcpy((u8*) gFile_con, p_file, 512); memcpy((u8*) gFile_con, p_file, 512);
for (k = 0; k < CONFIG_CONT; k++) { for (k = 0; k < CONFIG_CONT; k++) {
@@ -373,11 +351,11 @@ u8 Config_Analysis(void) {
t_p[k][j] = '\0'; t_p[k][j] = '\0';
m = i + 2; m = i + 2;
} }
for (k = 0; k < CONFIG_CONT; k++) { //<2F><><EFBFBD><EFBFBD>CONFIG_CONT <20><> for (k = 0; k < CONFIG_CONT; k++) {
if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) { //<2F>ҵ<EFBFBD><D2B5>ؼ<EFBFBD><D8BC><EFBFBD> if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) {
flag = 0; flag = 0;
for (i = strlen(gKey_words[k]); i < strlen((char *) t_p[k]); for (i = strlen(gKey_words[k]); i < strlen((char *) t_p[k]);
i++) { //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƿ<EFBFBD>Ϸ<EFBFBD> i++) {
if (t_p[k][i] >= '0' && t_p[k][i] <= '9') { if (t_p[k][i] >= '0' && t_p[k][i] <= '9') {
if (t_p[k][i] == '0') { if (t_p[k][i] == '0') {
if (k == 6) { if (k == 6) {
@@ -390,12 +368,12 @@ u8 Config_Analysis(void) {
} }
flag = 1; flag = 1;
break; break;
} else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) { //<2F>ո<EFBFBD>ϵȺ<CFB5> } else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) {
flag = 0; flag = 0;
break; break;
} }
} }
if (flag && Cal_Val(t_p[k] + i, k, 0)) { //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>Ϸ<EFBFBD> if (flag && Cal_Val(t_p[k] + i, k, 0)) {
Set_Ver(t_p[k] + i, k); Set_Ver(t_p[k] + i, k);
if (k == 0) if (k == 0)
sprintf((char *) t_p[k], "T_Standby=%d", sprintf((char *) t_p[k], "T_Standby=%d",
@@ -404,28 +382,28 @@ u8 Config_Analysis(void) {
sprintf((char *) t_p[k], "T_Work=%d", sprintf((char *) t_p[k], "T_Work=%d",
device_info.t_work / 10); device_info.t_work / 10);
else if (k == 2) else if (k == 2)
sprintf((char *) t_p[k], "Wait_Time=%d", sprintf((char *) t_p[k], "Wait_Time=%ld",
device_info.wait_time / 100); device_info.wait_time / 100);
else if (k == 3) else if (k == 3)
sprintf((char *) t_p[k], "Idle_Time=%d", sprintf((char *) t_p[k], "Idle_Time=%ld",
device_info.idle_time / 100); device_info.idle_time / 100);
else if (k == 4) else if (k == 4)
sprintf((char *) t_p[k], "T_Step=%d", sprintf((char *) t_p[k], "T_Step=%d",
device_info.t_step / 10); device_info.t_step / 10);
else if (k == 5) else if (k == 5)
sprintf((char *) t_p[k], "Turn_Off_v=%d", sprintf((char *) t_p[k], "Turn_Off_v=%ld",
gTurn_offv / 10); gTurn_offv / 10);
else if (k == 6) else if (k == 6)
sprintf((char *) t_p[k], "TempShowFlag=%d", sprintf((char *) t_p[k], "TempShowFlag=%d",
Get_TemperatureShowFlag()); Get_TemperatureShowFlag());
else if (k == 7) else if (k == 7)
sprintf((char *) t_p[k], "ZeroP_Ad=%d", gZerop_ad); sprintf((char *) t_p[k], "ZeroP_Ad=%ld", gZerop_ad);
} else { //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Ϸ<EFBFBD> } else {
memset(t_p[k], 0, strlen((char *) t_p[k])); memset(t_p[k], 0, strlen((char *) t_p[k]));
memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k])); memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k]));
is_illegality = 1; is_illegality = 1;
} }
} else { //ľ<><C4BE><EFBFBD>ҵ<EFBFBD><D2B5>ؼ<EFBFBD><D8BC><EFBFBD> } else {
memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k])); memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k]));
is_illegality = 1; is_illegality = 1;
} }
@@ -441,7 +419,7 @@ u8 Config_Analysis(void) {
m = strlen((char *) str); m = strlen((char *) str);
if (m < 256) { if (m < 256) {
gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m; //strlen((char *)str);//<2F>ļ<EFBFBD><C4BC><EFBFBD>С gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m; //strlen((char *)str);
gDisk_buff[0x400 + root_addr * 32 + 0x1D] = 0; gDisk_buff[0x400 + root_addr * 32 + 0x1D] = 0;
} else { } else {
gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m % 256; gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m % 256;
@@ -453,7 +431,7 @@ u8 Config_Analysis(void) {
ReWriteFlsash(); ReWriteFlsash();
} }
} else { } else {
if (p_file = SearchFile("LOGOIN BMP", &file_len, &root_addr)) { if ((p_file = SearchFile("LOGOIN BMP", &file_len, &root_addr))) {
memcpy(str, p_file, 254); memcpy(str, p_file, 254);
memset(gDisk_buff, 0x00, 0x2600); memset(gDisk_buff, 0x00, 0x2600);
memcpy(ROOT_SECTOR + 32, "LOGOIN BMP", 0xC); memcpy(ROOT_SECTOR + 32, "LOGOIN BMP", 0xC);
@@ -479,10 +457,10 @@ u8 Config_Analysis(void) {
m += strlen((char *) gSet_range[k]); m += strlen((char *) gSet_range[k]);
} }
gDisk_buff[0x40B] = 0x0; //<2F><><EFBFBD><EFBFBD> gDisk_buff[0x40B] = 0x0;
*(u32*) VOLUME_BASE = VOLUME; *(u32*) VOLUME_BASE = VOLUME;
gDisk_buff[0x41A] = 0x02; //<2F>غ<EFBFBD> gDisk_buff[0x41A] = 0x02;
gDisk_buff[0x41C] = m; //<2F>ļ<EFBFBD><C4BC><EFBFBD>С gDisk_buff[0x41C] = m;
ReWrite_All(); ReWrite_All();
} }
@@ -496,60 +474,52 @@ u8 Config_Analysis(void) {
return 0; return 0;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Disk_SecWrite Function: Disk_SecWrite
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:PC <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱд<CAB1><D0B4><EFBFBD><EFBFBD> Description:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:pbuffer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> diskaddr <20><>ַ Inputs:
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD> void Disk_SecWrite(u8* pbuffer, u32 diskaddr) {
{
u8 is_illegality = 0;
u32 i, j, k, m, flag; u32 i, j, k, m, flag;
u8 t_p[CONFIG_CONT][ROW_CONT]; u8 t_p[CONFIG_CONT][ROW_CONT];
u8 str[FILE_CONT]; u8 str[FILE_CONT];
u8 ver[20]; u8 ver[20];
static u16 Config_flag = 0; static u16 Config_flag = 0;
static u8 Conf_TxtFlag = 0;
if (diskaddr == 0x1000) { // Write FAT1 sector if (diskaddr == 0x1000) { // Write FAT1 sector
if (memcmp(pbuffer, (u8*) FAT1_SECTOR, 512)) { if (memcmp(pbuffer, (u8*) FAT1_SECTOR, 512)) { //check different
memcpy((u8*) FAT1_SECTOR, pbuffer, 512); memcpy((u8*) FAT1_SECTOR, pbuffer, 512);
gRewriteflag[0] = 1; gRewriteflag[0] = 1;
Conf_TxtFlag = 0;
} }
} else if (diskaddr == 0x2800) { // Write FAT2 sector } else if (diskaddr == 0x2800) { // Write FAT2 sector
if (memcmp(pbuffer, (u8*) FAT2_SECTOR, 512)) { if (memcmp(pbuffer, (u8*) FAT2_SECTOR, 512)) { //check different
memcpy((u8*) FAT2_SECTOR, pbuffer, 512); memcpy((u8*) FAT2_SECTOR, pbuffer, 512);
gRewriteflag[0] = 1; gRewriteflag[0] = 1;
Conf_TxtFlag = 0;
} }
} else if (diskaddr == 0x4000) { // Write DIR sector } else if (diskaddr == 0x4000) { // Write DIR sector
if (memcmp(pbuffer, (u8*) ROOT_SECTOR, 512)) { if (memcmp(pbuffer, (u8*) ROOT_SECTOR, 512)) { //check different
memcpy((u8*) ROOT_SECTOR, pbuffer, 512); memcpy((u8*) ROOT_SECTOR, pbuffer, 512);
gRewriteflag[1] = 1; gRewriteflag[1] = 1;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
memcpy((u8*) ver, (u8*) (pbuffer), 12); memcpy((u8*) ver, (u8*) (pbuffer), 12); //copy the filename out for comparison
if (memcmp(ver, "CONFIG TXT", 11) == 0) { if (memcmp(ver, "CONFIG TXT", 11) == 0) { //if file name matches
Config_flag = pbuffer[0x1A]; Config_flag = pbuffer[0x1A];
Conf_TxtFlag = 1;
break; break;
} }
pbuffer += 32; pbuffer += 32; //move to the next chunk of the pbuffer
} }
} }
} else if (diskaddr >= 0x8000 && diskaddr <= 0xA000) { // Write FILE sector } else if (diskaddr >= 0x8000 && diskaddr <= 0xA000) { // Write FILE sector
if (memcmp(pbuffer, (u8*) (FILE_SECTOR + (diskaddr - 0x8000)), 512)) { if (memcmp(pbuffer, (u8*) (FILE_SECTOR + (diskaddr - 0x8000)), 512)) { //check if different
memcpy((u8*) (FILE_SECTOR + (diskaddr - 0x8000)), pbuffer, 512); memcpy((u8*) (FILE_SECTOR + (diskaddr - 0x8000)), pbuffer, 512);
} }
if ((((diskaddr - 0x8000) / 0x200) + 2) == Config_flag) { if ((((diskaddr - 0x8000) / 0x200) + 2) == Config_flag) {
// /*
m = 0; m = 0;
memset(t_p, 0x00, CONFIG_CONT * ROW_CONT); memset(t_p, 0x00, CONFIG_CONT * ROW_CONT);
memcpy((u8*) (gFile_con), pbuffer, 512); memcpy((u8*) (gFile_con), pbuffer, 512);
for (k = 0; k < CONFIG_CONT; k++) { //ȡ<EFBFBD><EFBFBD>4 <20><> for (k = 0; k < CONFIG_CONT; k++) { //
j = 0; j = 0;
for (i = m; i < strlen((char *) gFile_con); i++) { //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD> for (i = m; i < strlen((char *) gFile_con); i++) { //
if (gFile_con[i] == 0x0D && gFile_con[i + 1] == 0x0A) if (gFile_con[i] == 0x0D && gFile_con[i + 1] == 0x0A)
break; break;
else { else {
@@ -562,11 +532,11 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>
m = i + 2; m = i + 2;
} }
for (k = 0; k < CONFIG_CONT; k++) { //<2F><><EFBFBD><EFBFBD>k <20><> for (k = 0; k < CONFIG_CONT; k++) {
if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) { //<2F>ҵ<EFBFBD><D2B5>ؼ<EFBFBD><D8BC><EFBFBD> if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) {
flag = 0; flag = 0;
for (i = strlen(gKey_words[k]); i < strlen((char *) t_p[k]); for (i = strlen(gKey_words[k]); i < strlen((char *) t_p[k]);
i++) { //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƿ<EFBFBD>Ϸ<EFBFBD> i++) {
if (t_p[k][i] >= '0' && t_p[k][i] <= '9') { if (t_p[k][i] >= '0' && t_p[k][i] <= '9') {
if (t_p[k][i] == '0') { if (t_p[k][i] == '0') {
if (k == 6) { if (k == 6) {
@@ -579,14 +549,12 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>
} }
flag = 1; flag = 1;
break; break;
} else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) { //<2F>ո<EFBFBD>ϵȺ<CFB5> } else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) {
flag = 0; flag = 0;
break; break;
} }
} }
if ((!flag) || (!Cal_Val(t_p[k] + i, k, 1))) { if ((!flag) || (!Cal_Val(t_p[k] + i, k, 1))) {
is_illegality = 1; //<2F><><EFBFBD>Ϸ<EFBFBD>
return; return;
} else { } else {
Set_Ver(t_p[k] + i, k); Set_Ver(t_p[k] + i, k);
@@ -599,56 +567,44 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>
sprintf((char *) t_p[k], "T_Work=%d", sprintf((char *) t_p[k], "T_Work=%d",
device_info.t_work / 10); device_info.t_work / 10);
else if (k == 2) else if (k == 2)
sprintf((char *) t_p[k], "Wait_Time=%d", sprintf((char *) t_p[k], "Wait_Time=%ld",
device_info.wait_time / 100); device_info.wait_time / 100);
else if (k == 3) else if (k == 3)
sprintf((char *) t_p[k], "Idle_Time=%d", sprintf((char *) t_p[k], "Idle_Time=%ld",
device_info.idle_time / 100); device_info.idle_time / 100);
else if (k == 4) else if (k == 4)
sprintf((char *) t_p[k], "T_Step=%d", sprintf((char *) t_p[k], "T_Step=%d",
device_info.t_step / 10); device_info.t_step / 10);
else if (k == 5) else if (k == 5)
sprintf((char *) t_p[k], "Turn_Off_v=%d", sprintf((char *) t_p[k], "Turn_Off_v=%ld",
gTurn_offv / 10); gTurn_offv / 10);
else if (k == 6) else if (k == 6)
sprintf((char *) t_p[k], "TempShowFlag=%d", sprintf((char *) t_p[k], "TempShowFlag=%d",
Get_TemperatureShowFlag()); Get_TemperatureShowFlag());
else if (k == 7) else if (k == 7)
sprintf((char *) t_p[k], "ZeroP_Ad=%d", gZerop_ad); sprintf((char *) t_p[k], "ZeroP_Ad=%ld", gZerop_ad);
} }
} else { //ľ<><C4BE><EFBFBD>ҵ<EFBFBD><D2B5>ؼ<EFBFBD><D8BC><EFBFBD> } else {
memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k])); memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k]));
is_illegality = 1;
return; return;
} }
} }
if (!is_illegality) { memset(str, 0, FILE_CONT);
memset(str, 0, FILE_CONT); for (k = 0; k < CONFIG_CONT; k++) {
for (k = 0; k < CONFIG_CONT; k++) { strcat((char *) str, (char *) t_p[k]);
strcat((char *) str, (char *) t_p[k]); strcat((char *) str, (char *) gSet_range[k]);
strcat((char *) str, (char *) gSet_range[k]);
}
m = strlen((char *) str);
if (m < 256) {
gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1C] = m; //strlen((char *)str);//<2F>ļ<EFBFBD><C4BC><EFBFBD>С
gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1D] = 0;
} else {
gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1C] = m % 256;
gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1D] = m / 256;
}
memcpy((u8*) (FILE_SECTOR), (u8*) str, 512);
gRewriteflag[1] = 1;
gRewriteflag[((diskaddr - 0x8000 + 0x200) / 0x400) + 1] = 1;
ReWriteFlsash();
Conf_TxtFlag = 0;
return;
} else {
Conf_TxtFlag = 1;
return;
} }
m = strlen((char *) str);
gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1C] = m % 256;
gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1D] = m / 256;
memcpy((u8*) (FILE_SECTOR), (u8*) str, 512);
gRewriteflag[1] = 1;
gRewriteflag[((diskaddr - 0x8000 + 0x200) / 0x400) + 1] = 1;
ReWriteFlsash();
return;
} }
gRewriteflag[1] = 1; gRewriteflag[1] = 1;
@@ -659,10 +615,8 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Disk_SecRead Function: Disk_SecRead
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:PC <20><>ȡ<EFBFBD>ļ<EFBFBD>ʱд<CAB1><D0B4><EFBFBD><EFBFBD> Description: Reads a sector from the virtual disk
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:pbuffer <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> diskaddr <20><>ַ
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Disk_SecRead(u8* pbuffer, u32 disk_addr) { void Disk_SecRead(u8* pbuffer, u32 disk_addr) {
Soft_Delay(); Soft_Delay();
@@ -677,14 +631,13 @@ void Disk_SecRead(u8* pbuffer, u32 disk_addr) {
} else if (disk_addr >= 0x8000 && disk_addr <= 0xA000) { // Read FILE sector } else if (disk_addr >= 0x8000 && disk_addr <= 0xA000) { // Read FILE sector
memcpy(pbuffer, (u8*) (APP_BASE + 0x600 + (disk_addr - 0x8000)), 512); memcpy(pbuffer, (u8*) (APP_BASE + 0x600 + (disk_addr - 0x8000)), 512);
} else { } else {
memset(pbuffer, 0, 512); // memset(pbuffer, 0, 512); //unknown, return 0's
} }
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ReWriteFlsash Function:ReWriteFlsash
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:дFlash Description:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL Output:RDY(all good) or ERR (error)
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A>Ƿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>־
*******************************************************************************/ *******************************************************************************/
u8 ReWriteFlsash(void) { u8 ReWriteFlsash(void) {
u32 i, j; u32 i, j;
@@ -697,12 +650,12 @@ u8 ReWriteFlsash(void) {
gRewriteflag[i] = 0; gRewriteflag[i] = 0;
FLASH_Erase(APP_BASE + i * 0x400); FLASH_Erase(APP_BASE + i * 0x400);
f_buff = (u16*) &gDisk_buff[i * 0x400]; f_buff = (u16*) &gDisk_buff[i * 0x400];
for (j = 0; j < 0x400; j += 2) { for (j = 0; j < 0x400; j += 2) { //Loop through the 1k block
result = FLASH_Prog((u32) (APP_BASE + i * 0x400 + j), result = FLASH_Prog((u32) (APP_BASE + i * 0x400 + j), //program each 16 bit block
*f_buff++); *f_buff++);
if (result != FLASH_COMPLETE) { if (result != FLASH_COMPLETE) { //something went wrong
FLASH_Lock(); FLASH_Lock(); //make sure the flash is locked again
return ERR; return ERR; //return ERR
} }
} }
break; break;
@@ -712,10 +665,9 @@ u8 ReWriteFlsash(void) {
return RDY; return RDY;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ReWrite_All Function: ReWrite_All
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>flash<73><68><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD> Description:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL Output:
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A>Ƿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>־
*******************************************************************************/ *******************************************************************************/
u8 ReWrite_All(void) { u8 ReWrite_All(void) {
u16 i; u16 i;
@@ -734,24 +686,20 @@ u8 ReWrite_All(void) {
return RDY; return RDY;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Erase Function:Erase
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʽ<EFBFBD><CABD>Flash Description: Erase the first 9k from APP_BASE
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Erase(void) { void Erase(void) {
u16 i; u16 i;
FLASH_Unlock(); FLASH_Unlock(); //unlock the mcu flash controller
for (i = 0; i < 9; i++) for (i = 0; i < 9; i++)
FLASH_Erase(APP_BASE + i * 0x400); FLASH_Erase(APP_BASE + i * 0x400); //erase the flash
FLASH_Lock(); FLASH_Lock();
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Read_Memory Function: Read_Memory
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD>microSD<53><44><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:r_offset ƫ<><C6AB> r_length<74><68><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Read_Memory(u32 r_offset, u32 r_length) { void Read_Memory(u32 r_offset, u32 r_length) {
static u32 offset, length, block_offset; static u32 offset, length, block_offset;
@@ -789,10 +737,8 @@ void Read_Memory(u32 r_offset, u32 r_length) {
} }
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Write_Memory Function: Write_Memory
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD>microSD<53><44><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:r_offset ƫ<><C6AB> r_length<74><68><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Write_Memory(u32 w_offset, u32 w_length) { void Write_Memory(u32 w_offset, u32 w_length) {
static u32 offset, length; static u32 offset, length;

View File

@@ -1,32 +1,33 @@
/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ******************** /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************
File Name : Flash.c File Name : Flash.c
Version : Author : bure Version : Author : bure
*******************************************************************************/ *******************************************************************************/
#include "APP_Version.h" #include "APP_Version.h"
#include "Flash.h" #include "Flash.h"
#include "Bios.h" #include "Bios.h"
u8 ExtFlashSendByte(u8 byte);
void ExtFlashWaitForWriteEnd(void);
/******************************************************************************* /*******************************************************************************
FLASH_Prog: Function: FLASH_Prog
*******************************************************************************/ Description: Programs the data into the system flash at the specified address
u8 FLASH_Prog(u32 Address, u16 Data) *******************************************************************************/
{ u8 FLASH_Prog(u32 Address, u16 Data) {
if(FLASH_WaitForLastOperation(WAIT_TIMES)!=FLASH_TIMEOUT) if (FLASH_WaitForLastOperation(WAIT_TIMES) != FLASH_TIMEOUT)
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR); FLASH_ClearFlag(
return FLASH_ProgramHalfWord(Address, Data); FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
return FLASH_ProgramHalfWord(Address, Data);
} }
/******************************************************************************* /*******************************************************************************
FLASH_Erase: Function: FLASH_Erase
*******************************************************************************/ Description: Erases a page of flash
void FLASH_Erase(u32 Address) Inputs: Starting address for the page to erase
{ *******************************************************************************/
if(Address%FLASH_PAGE == 0) { // FLASH Page start (1K/Page) void FLASH_Erase(u32 Address) {
if(FLASH_WaitForLastOperation(WAIT_TIMES)!=FLASH_TIMEOUT) if (Address % FLASH_PAGE == 0) { // FLASH Page start (1K/Page)
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR); if (FLASH_WaitForLastOperation(WAIT_TIMES) != FLASH_TIMEOUT) //wait for last op to finish
FLASH_ErasePage(Address); // FLASH Page erase FLASH_ClearFlag(
} FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
FLASH_ErasePage(Address); // FLASH Page erase
}
} }
/********************************* END OF FILE ******************************/ /********************************* END OF FILE ******************************/

View File

@@ -274,7 +274,7 @@ int Get_SensorTmp(void) {
if (gMeas_cnt == 1) { if (gMeas_cnt == 1) {
ad_sum = ad_sum - max - min; ad_sum = ad_sum - max - min;
avg_data = ad_sum / 8; avg_data = ad_sum / 8;
//^ Removes the two outliers from the data spread
slide_data = Get_TempSlAvg(avg_data); slide_data = Get_TempSlAvg(avg_data);
sensor_temp = (250 + (3300 * slide_data / 4096) - 750); //(25 + ((10*(33*gSlide_data)/4096)-75)); sensor_temp = (250 + (3300 * slide_data / 4096) - 750); //(25 + ((10*(33*gSlide_data)/4096)-75));
ad_sum = 0; ad_sum = 0;
@@ -356,10 +356,8 @@ s16 Get_Temp(s16 wk_temp) {
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Start_Watchdog Function:Start_Watchdog
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD> Description: Starts the system watchdog timer
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:ms <20><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>1
*******************************************************************************/ *******************************************************************************/
u32 Start_Watchdog(u32 ms) { u32 Start_Watchdog(u32 ms) {
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
@@ -378,13 +376,11 @@ u32 Start_Watchdog(u32 ms) {
return 1; return 1;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Clear_Watchdog Function:Clear_Watchdog
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ÿ<EFBFBD><C3BF>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD> Description:Resets the watchdog timer
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>1
*******************************************************************************/ *******************************************************************************/
u32 Clear_Watchdog(void) { void Clear_Watchdog(void) {
IWDG_ReloadCounter(); IWDG_ReloadCounter();
return 1;
} }
/******************************** END OF FILE *********************************/ /******************************** END OF FILE *********************************/

View File

@@ -56,17 +56,6 @@ void SysTick_Handler(void) {
void USB_LP_CAN1_RX0_IRQHandler(void) { void USB_LP_CAN1_RX0_IRQHandler(void) {
USB_Istr(); USB_Istr();
} }
/*
void I2C1_EV_IRQHandler(void)
{
I2C1_EV_ISR();
}
void I2C1_ER_IRQHandler(void)
{
I2C1_ER_ISR();
}
*/
void TIM2_IRQHandler(void) { void TIM2_IRQHandler(void) {
TIM2_ISR(); TIM2_ISR();
} }
@@ -74,7 +63,7 @@ void TIM2_IRQHandler(void) {
void TIM3_IRQHandler(void) { void TIM3_IRQHandler(void) {
TIM3_ISR(); TIM3_ISR();
} }
/*This loop is used for un assigned IRQ's so that the debugger can catch them*/
static void forever() static void forever()
{ {

View File

@@ -5,6 +5,7 @@
Author : Celery Author : Celery
Data: 2015/07/07 Data: 2015/07/07
History: History:
2016/09/13 Ben V. Brown - English comments and fixing a few errors
2015/07/07 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2015/07/07 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************************************/ *******************************************************************************/
#include <stdio.h> #include <stdio.h>
@@ -28,19 +29,15 @@ u8 gMmatxdata;
typedef struct { typedef struct {
u8 hi; u8 hi;
u8 lo; u8 lo;
} DRByte;
typedef struct {
DRByte Byte;
} DR_Value; } DR_Value;
DR_Value gX_value, gY_value, gZ_value; DR_Value gX_value, gY_value, gZ_value;
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_MmaActive Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD>ٶȴ<D9B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ Description:Returns if the unit is actively being moved
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL Output: if the unit is active or not.
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD>ٶȴ<D9B6><C8B4><EFBFBD><EFBFBD><EFBFBD>״̬
*******************************************************************************/ *******************************************************************************/
u16 Get_MmaActive(void) { u16 Get_MmaActive(void) {
return gactive; return gactive;
@@ -53,20 +50,19 @@ u16 Get_MmaShift(void) {
return gShift; return gShift;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_MmaActive Function: Set_MmaShift
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:XXXXXXXXXXXXXXXXXXXXXX Description: Set the Shift Value
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:XXXXXXXXXXXXXXXXXXXXXX Input: shift value
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:XXXXXXXXXXXXXXXXXXXXXX
*******************************************************************************/ *******************************************************************************/
void Set_MmaShift(u16 shift) { void Set_MmaShift(u16 shift) {
gShift = shift; gShift = shift;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: IIC_RegWrite Function:IIC_RegWrite
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>Reg<65><67>ַд<D6B7><D0B4>Data Description:Writes a value to a register
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:Reg <20><><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5>ַ<EFBFBD><D6B7>Data<74><61><EFBFBD><EFBFBD> Input:the register, the data
<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD>: <20>ɹ<EFBFBD><C9B9><EFBFBD> Output: 1 if the write succeeded
*******************************************************************************/ *******************************************************************************/
int IIC_RegWrite(u8 reg, u8 data) { int IIC_RegWrite(u8 reg, u8 data) {
u8 tx_data[20]; u8 tx_data[20];
@@ -77,10 +73,10 @@ int IIC_RegWrite(u8 reg, u8 data) {
return 1; return 1;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: IIC_RegRead Function:IIC_RegRead
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Reg<65><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description: Reads a register from I2C, using a single byte addressing scheme
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:Reg <20><><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>gMmatxdata<74><61> Inputs: uint8_t register to read
<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD>: <20>ɹ<EFBFBD><C9B9><EFBFBD> Output: 1 if the read worked.
*******************************************************************************/ *******************************************************************************/
int IIC_RegRead(u8 reg) { int IIC_RegRead(u8 reg) {
u8 tx_data[20]; u8 tx_data[20];
@@ -91,10 +87,8 @@ int IIC_RegRead(u8 reg) {
return 1; return 1;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: MMA865x_Standby Function: MMA865x_Standby
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ Description: Put the MMA865 into standby mode
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void MMA865x_Standby(void) { void MMA865x_Standby(void) {
//Put the sensor into Standby Mode by clearing //Put the sensor into Standby Mode by clearing
@@ -102,10 +96,8 @@ void MMA865x_Standby(void) {
IIC_RegWrite(CTRL_REG1, 0); //(IIC_RegRead(CTRL_REG1) & ~ ACTIVE_MASK) IIC_RegWrite(CTRL_REG1, 0); //(IIC_RegRead(CTRL_REG1) & ~ ACTIVE_MASK)
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: MMA865x_Active Function: MMA865x_Active
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ Description: Put the MMA865 into active mode
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void MMA865x_Active(void) { void MMA865x_Active(void) {
// Put the sensor into Active Mode by setting the // Put the sensor into Active Mode by setting the
@@ -113,53 +105,50 @@ void MMA865x_Active(void) {
IIC_RegWrite(CTRL_REG1, ACTIVE_MASK); //(IIC_RegRead(CTRL_REG1) | ACTIVE_MASK) IIC_RegWrite(CTRL_REG1, ACTIVE_MASK); //(IIC_RegRead(CTRL_REG1) | ACTIVE_MASK)
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: IIC_RegRead Function: IIC_RegRead
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Reg<65><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description:Setup the MMA865x IC settings
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void StartUp_Accelerated(void) { void StartUp_Accelerated(void) {
//------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬-----------------------// //Put the unit into standby state so we can edit its configuration registers
MMA865x_Standby(); MMA865x_Standby();
//---- <20><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>Χ4g----------------------// //Set the unit to full scale measurement
IIC_RegWrite(XYZ_DATA_CFG_REG, FULL_SCALE_8G); //(IIC_RegRead(XYZ_DATA_CFG_REG) & ~FS_MASK) IIC_RegWrite(XYZ_DATA_CFG_REG, FULL_SCALE_8G); //(IIC_RegRead(XYZ_DATA_CFG_REG) & ~FS_MASK)
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100HZ------------------------------------// //Set the unit to the required update rate (eg 100Hz)
IIC_RegWrite(CTRL_REG1, DataRateValue); //IIC_RegRead(CTRL_REG1)| IIC_RegWrite(CTRL_REG1, DataRateValue); //IIC_RegRead(CTRL_REG1)|
//----<2D><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ------------------------------------------------------//
IIC_RegWrite(CTRL_REG2, 0); //(IIC_RegRead(CTRL_REG2) & ~MODS_MASK) IIC_RegWrite(CTRL_REG2, 0); //Normal mode
//---------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ------------------------------------//
//Change the unit back to active mode to exit setup and start the readings
MMA865x_Active(); MMA865x_Active();
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Read_ZYXDr Function: Read_ZYXDr
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡXYZ<59><5A><EFBFBD><EFBFBD> Description:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL Output: 1 if new data, 0 if not
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:x,y,z<>ķ<EFBFBD><C4B7><EFBFBD>
*******************************************************************************/ *******************************************************************************/
int Read_ZYXDr(void) { int Read_ZYXDr(void) {
u8 reg_flag; u8 reg_flag;
u8 ptr, i; u8 ptr, i;
u8 value[6]; u8 value[6] = { 0, 0, 0, 0, 0, 0 };
memset((u8*) &gX_value, 0, 6);
//Poll the ZYXDR status bit and wait for it to set //Poll the ZYXDR status bit and wait for it to set
if (IIC_RegRead(STATUS_REG)) { if (IIC_RegRead(STATUS_REG)) { //check we can read the status
reg_flag = gMmatxdata; reg_flag = gMmatxdata;
if ((reg_flag & ZYXDR_BIT) != 0) { if ((reg_flag & ZYXDR_BIT) != 0) { //if new measurement
//Read 12/10-bit XYZ results using a 6 byte IIC access //Read 12/10-bit XYZ results using a 6 byte IIC access
ptr = X_MSB_REG; ptr = X_MSB_REG;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if (IIC_RegRead(ptr++) == 0) if (IIC_RegRead(ptr++) == 0)
break; break;
value[i] = gMmatxdata; value[i] = gMmatxdata;
//Copy and save each result as a 16-bit left-justified value //Copy and save each result as a 16-bit left-justified value
gX_value.Byte.hi = value[0]; gX_value.hi = value[0];
gX_value.Byte.lo = value[1]; gX_value.lo = value[1];
gY_value.Byte.hi = value[2]; gY_value.hi = value[2];
gY_value.Byte.lo = value[3]; gY_value.lo = value[3];
gZ_value.Byte.hi = value[4]; gZ_value.hi = value[4];
gZ_value.Byte.lo = value[5]; gZ_value.lo = value[5];
return 1; return 1;
} }
} else } else
@@ -168,38 +157,37 @@ int Read_ZYXDr(void) {
return 0; return 0;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Cheak_XYData Function: Cheak_XYData
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>x<EFBFBD><78>y<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD> Description: Check the input X,Y for a large enough acceleration to wake the unit
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һxy<78><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>xy<78><79><EFBFBD><EFBFBD>Ա<EFBFBD> Inputs:x0,y0,x1,y1 to check
<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD>:<3A>Ƿ<EFBFBD><C7B7>ƶ<EFBFBD> Output: if the unit is active
*******************************************************************************/ *******************************************************************************/
u16 Cheak_XYData(u16 x0, u16 y0, u16 x1, u16 y1) { u16 Cheak_XYData(u16 x0, u16 y0, u16 x1, u16 y1) {
u16 active = 0; u16 active = 0;
gShift = 0; gShift = 0;
if ((x1 > (x0 + 16)) || (x1 < (x0 - 16)))
active = 1;
if ((y1 > (y0 + 16)) || (y1 < (y0 - 16)))
active = 1;
if ((x1 > (x0 + 32)) || (x1 < (x0 - 32))) if ((x1 > (x0 + 32)) || (x1 < (x0 - 32)))
gShift = 1; gShift = 1;
if ((y1 > (y0 + 32)) || (y1 < (y0 - 32))) if ((y1 > (y0 + 32)) || (y1 < (y0 - 32)))
gShift = 1; gShift = 1;
if ((x1 > (x0 + 16)) || (x1 < (x0 - 16)))
active = 1;
if ((y1 > (y0 + 16)) || (y1 < (y0 - 16)))
active = 1;
return active; return active;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Update_X Function: Update_X
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description: Converts the read value for x into an actual properly located value
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD>x Output: X
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
u16 Update_X(void) { u16 Update_X(void) {
u16 value, x; u16 value, x;
value = ((gX_value.Byte.hi << 8) | (gX_value.Byte.lo & 0xf0)) >> 4; value = ((gX_value.hi << 8) | (gX_value.lo & 0xf0)) >> 4;
if (gX_value.Byte.hi > 0x7f) if (gX_value.hi > 0x7f)
x = (~value + 1) & 0xfff; x = (~value + 1) & 0xfff;
else else
x = value & 0xfff; x = value & 0xfff;
@@ -207,16 +195,15 @@ u16 Update_X(void) {
return x; return x;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Update_Y Function: Update_Y
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description: Converts the read value for y into an actual properly located value
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL Output: Y
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>y
*******************************************************************************/ *******************************************************************************/
u16 Update_Y(void) { u16 Update_Y(void) {
u16 value, y; u16 value, y;
value = ((gY_value.Byte.hi << 8) | (gY_value.Byte.lo & 0xf0)) >> 4; value = ((gY_value.hi << 8) | (gY_value.lo & 0xf0)) >> 4;
if (gY_value.Byte.hi > 0x7f) if (gY_value.hi > 0x7f)
y = (~value + 1) & 0xfff; y = (~value + 1) & 0xfff;
else else
y = value & 0xfff; y = value & 0xfff;
@@ -224,16 +211,15 @@ u16 Update_Y(void) {
return y; return y;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Update_z Function: Update_Z
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description: Converts the read value for z into an actual properly located value
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL Output: Z
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>z
*******************************************************************************/ *******************************************************************************/
u16 Update_Z(void) { u16 Update_Z(void) {
u16 value, z; u16 value, z;
value = ((gZ_value.Byte.hi << 8) | (gZ_value.Byte.lo & 0xf0)) >> 4; value = ((gZ_value.hi << 8) | (gZ_value.lo & 0xf0)) >> 4;
if (gZ_value.Byte.hi > 0x7f) if (gZ_value.hi > 0x7f)
z = (~value + 1) & 0xfff; z = (~value + 1) & 0xfff;
else else
z = value & 0xfff; z = value & 0xfff;
@@ -241,22 +227,24 @@ u16 Update_Z(void) {
return z; return z;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Check_Accelerated Function: Check_Accelerated
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD>ٶȴ<D9B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ƶ<EFBFBD> Description:Check if the unit has moved
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Check_Accelerated(void) { void Check_Accelerated(void) {
static u16 x0 = 0, y0 = 0; static u16 x0 = 0, y0 = 0;
u16 x1, y1; u16 x1, y1;
if (Read_ZYXDr()) { /*<2A><><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/ if (Read_ZYXDr()) { //Read the new values from the accelerometer
x1 = Update_X(); x1 = Update_X(); //convert the values into usable form
y1 = Update_Y(); y1 = Update_Y();
} else } else {
x1 = x0; x1 = x0;
y1 = y0; y1 = y0; //use old values
gactive = Cheak_XYData(x0, y0, x1, y1);/*<2A><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ƶ<EFBFBD>*/ gactive = 0;
return;
}
gactive = Cheak_XYData(x0, y0, x1, y1); //gactive == If the unit is moving or not
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;

View File

@@ -24,38 +24,39 @@
int main(void) { int main(void) {
RCC_Config(); //setup system clock RCC_Config(); //setup system clock
NVIC_Config(0x4000); NVIC_Config(0x4000);
Init_Timer2(); //init the timer Init_Timer2(); //init the timers
Init_Timer3(); Init_Timer3();
GPIO_Config(); GPIO_Config();//setup all the GPIO pins
USB_Port(DISABLE);
Delay_Ms(200); USB_Port(DISABLE);//disable the USB hardware
USB_Port(ENABLE); Delay_Ms(200);//pause to let hardware stabilize
USB_Port(ENABLE);//enable the USB hardware
USB_Init(); USB_Init();
I2C_Configuration(); //init the i2c bus I2C_Configuration(); //init the i2c bus
Adc_Init(); //init adc and dma Adc_Init(); //init adc and dma
if (Get_CtrlStatus() != CONFIG) if (Get_CtrlStatus() != CONFIG)
StartUp_Accelerated(); StartUp_Accelerated();//start the accelerometer if not in config mode
System_Init(); System_Init();//load known safe values
Init_Oled(); Init_Oled();//init the OLED display
Clear_Screen(); Clear_Screen();//clear the display buffer to black
Init_Gtime(); Init_Gtime();//init the count down timers
APP_Init(); APP_Init();//pick operating mode via input voltage
Disk_BuffInit(); Disk_BuffInit();//fill the buffer for the virtual disk
Config_Analysis(); //read in config from virtual disk Config_Analysis(); //read in config from virtual disk
Pid_Init(); //init the pid to starting values Pid_Init(); //init the pid to starting values
Set_gKey(NO_KEY); //reset keys Set_gKey(NO_KEY); //reset keys to all off
Start_Watchdog(3000); Start_Watchdog(3000);//start the system watchdog as 3 seconds
while (1) { while (1) {
Clear_Watchdog(); //reset the Watchdog Clear_Watchdog(); //reset the Watchdog
if (Get_CtrlStatus() != CONFIG && LEAVE_WAIT_TIMER== 0) { if (Get_CtrlStatus() != CONFIG && LEAVE_WAIT_TIMER== 0) {
Check_Accelerated(); //update readings from the accelerometer Check_Accelerated(); //update readings from the accelerometer
LEAVE_WAIT_TIMER = 50; LEAVE_WAIT_TIMER = 50;//reset timer so we dont poll accelerometer for another 500ms
} }
OLed_Display(); //Draw in the Oled display OLed_Display(); //Draw in the Oled display for this mode
Status_Tran(); //Handle user input and mode changing Status_Tran(); //Handle user input and mode changing
} }
} }

View File

@@ -1,157 +0,0 @@
/**
******************************************************************************
* @file system_stm32f10x.c
* @author MCD Application Team
* @version V3.6.1
* @date 09-March-2012
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
*
* 1. This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
* factors, AHB/APBx prescalers and Flash settings).
* This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32f10x_xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32f10x_xx.s" file, to
* configure the system clock before to branch to main program.
*
* 3. If the system clock source selected by user fails to startup, the SystemInit()
* function will do nothing and HSI still used as system clock source. User can
* add some code to deal with this issue inside the SetSysClock() function.
*
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depedning on
* the product used), refer to "HSE_VALUE" define in "stm32f10x.h" file.
* When HSE is used as system clock source, directly or through PLL, and you
* are using different crystal you have to adapt the HSE value to your own
* configuration.
*
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
#include "stm32f10x.h"
#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
static void SetSysClockTo72MHz(void);
/*******************************************************************************
* Clock Definitions
*******************************************************************************/
u32 SystemCoreClock = 72000000; // 72MHz System Clock Frequency
u8 AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
void SystemInit (void)
{
RCC->CR |= 0x00000001;// Set HSION bit
RCC->CFGR &= 0xF8FF0000;// Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits
RCC->CR &= 0xFEF6FFFF;// Reset HSEON, CSSON and PLLON bits
RCC->CR &= 0xFFFBFFFF;// Reset HSEBYP bit
RCC->CFGR &= 0xFF80FFFF;// Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits
RCC->CIR = 0x009F0000;// Disable all interrupts and clear pending bits
/* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
/* Configure the Flash Latency cycles and enable prefetch buffer */
SetSysClockTo72MHz();
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
}
void SystemCoreClockUpdate (void)
{
u32 tmp = 0, pllmull = 0, pllsource = 0;
/* Get SYSCLK source -------------------------------------------------------*/
tmp = RCC->CFGR & RCC_CFGR_SWS;
switch(tmp){
case 0x00: // HSI used as system clock
SystemCoreClock = 8000000; // HSI_VALUE;
break;
case 0x04: // HSE used as system clock
SystemCoreClock = 8000000; // HSE_VALUE;
break;
case 0x08: // PLL used as system clock
// Get PLL clock source and multiplication factor
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
pllmull = ( pllmull >> 18) + 2;
// HSI oscillator clock divided by 2 selected as PLL clock entry
if (pllsource == 0x00) SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
break;
default:
SystemCoreClock = HSI_VALUE;
break;
}
// Compute HCLK clock frequency
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];// Get HCLK prescaler
SystemCoreClock >>= tmp; // HCLK clock frequency
}
static void SetSysClockTo72MHz(void)
{
u32 StartUpCounter = 0, HSEStatus = 0;
// SYSCLK, HCLK, PCLK2 and PCLK1 configuration
RCC->CR |= ((u32)RCC_CR_HSEON);/* Enable HSE */
do { // Wait till HSE is ready and if Time out is reached exit
HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) HSEStatus = 0x01;
else HSEStatus = 0x00;
if (HSEStatus == 0x01){
FLASH->ACR |= FLASH_ACR_PRFTBE;/* Enable Prefetch Buffer */
/* Flash 2 wait state */
FLASH->ACR &= (u32)((u32)~FLASH_ACR_LATENCY);
FLASH->ACR |= (u32)FLASH_ACR_LATENCY_2;
RCC->CFGR |= RCC_CFGR_HPRE_DIV1;/* HCLK = SYSCLK */
RCC->CFGR |= RCC_CFGR_PPRE2_DIV1;/* PCLK2 = HCLK */
RCC->CFGR |= RCC_CFGR_PPRE1_DIV2;/* PCLK1 = HCLK */
/* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
RCC->CFGR &= ~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL);
RCC->CFGR |= (u32)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);
RCC->CR |= RCC_CR_PLLON;/* Enable PLL */
while((RCC->CR & RCC_CR_PLLRDY) == 0){}/* Wait till PLL is ready */
/* Select PLL as system clock source */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
{}/* Wait till PLL is used as system clock source */
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -21,11 +21,11 @@
#include "MMA8652FC.h" #include "MMA8652FC.h"
/******************************************************************************/ /******************************************************************************/
u8 gTemp_array[16 * 16 + 16]; u8 gTemp_array[16 * 16 + 16];
u8 gTemperatureshowflag = 0; /* 0 <20><><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD>,1<>ǻ<EFBFBD><C7BB>϶<EFBFBD>*/ u8 gTemperatureshowflag = 0;
u8 gUp_flag = 0, gDown_flag = 0, gLevel_flag = 0, gTempset_showctrl = 0; u8 gUp_flag = 0, gDown_flag = 0, gLevel_flag = 0, gTempset_showctrl = 0;
u16 gTemp_array_u16[208]; u16 gTemp_array_u16[208];
u16 gSet_table[2] = { 4000, 1000 }; /*<2A><EFBFBD>ѡ<EFBFBD><D1A1>*/ u16 gSet_table[2] = { 4000, 1000 };
u32 gCont = 0; /*gCont <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ת<CCAC><D7AA><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD>ʶ*/ u32 gCont = 0;
static u8 Ver_s[] = { /*12*16*/0x04, 0x0C, 0x74, 0x80, 0x00, 0x00, 0x00, 0x80, static u8 Ver_s[] = { /*12*16*/0x04, 0x0C, 0x74, 0x80, 0x00, 0x00, 0x00, 0x80,
0x74, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1C, 0x60, 0x1C, 0x03, 0x74, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1C, 0x60, 0x1C, 0x03,
@@ -51,48 +51,37 @@ static u8 Ver_s[] = { /*12*16*/0x04, 0x0C, 0x74, 0x80, 0x00, 0x00, 0x00, 0x80,
/******************************************************************************/ /******************************************************************************/
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_UpdataFlag Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1>Ļˢ<C4BB>±<EFBFBD>־ Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><>Ļˢ<C4BB>±<EFBFBD>־
*******************************************************************************/ *******************************************************************************/
u32 Get_UpdataFlag(void) { u32 Get_UpdataFlag(void) {
return gCont; return gCont;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_UpdataFlag Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļˢ<C4BB>±<EFBFBD>־ Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:1 ˢ<>£<EFBFBD>0 <20><>ˢ<EFBFBD><CBA2>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Set_UpdataFlag(u32 cont) { void Set_UpdataFlag(u32 cont) {
gCont = cont; gCont = cont;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_TemperatureShowFlag Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><C2B6><EFBFBD>ʾ<EFBFBD><CABE>ʽ Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:flag <20><><EFBFBD>϶<EFBFBD>(0),<2C><><EFBFBD>϶<EFBFBD>(1)<29><>־
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Set_TemperatureShowFlag(u8 flag) { void Set_TemperatureShowFlag(u8 flag) {
gTemperatureshowflag = flag; gTemperatureshowflag = flag;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_TemperatureShowFlag Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><EFBFBD><C2B6><EFBFBD>ʾ<EFBFBD><CABE>ʽ Description:־
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:flag <20><><EFBFBD>϶<EFBFBD>(0),<2C><><EFBFBD>϶<EFBFBD>(1)<29><>־
*******************************************************************************/ *******************************************************************************/
u8 Get_TemperatureShowFlag(void) { u8 Get_TemperatureShowFlag(void) {
return gTemperatureshowflag; return gTemperatureshowflag;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: TemperatureShow_Change Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>϶Ȼ<CFB6><C8BB>϶<EFBFBD><CFB6>໥ת<E0BBA5><D7AA> Description: Converts F to C or C to F.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: flag 0,<2C><><EFBFBD>϶<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD> Input: flag = if flag==0 converts C to F
flag 1,<2C><><EFBFBD>϶<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD>
tmp Ҫת<D2AA><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><><D7AA><EFBFBD><EFBFBD><EFBFBD>ֵ
*******************************************************************************/ *******************************************************************************/
s16 TemperatureShow_Change(u8 flag, s16 tmp) { s16 TemperatureShow_Change(u8 flag, s16 tmp) {
if (flag == 0) { if (flag == 0) {
@@ -102,10 +91,8 @@ s16 TemperatureShow_Change(u8 flag, s16 tmp) {
} }
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: APP_Init Function:APP_Init
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ݵ<EFBFBD>ѹ<EFBFBD><D1B9>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʼ״̬ Description:Init the operating mode by looking at input voltage to pick USB or normal
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void APP_Init(void) { void APP_Init(void) {
int rev; int rev;
@@ -113,13 +100,13 @@ void APP_Init(void) {
HEATING_TIMER= 0; HEATING_TIMER= 0;
UI_TIMER= 0; UI_TIMER= 0;
rev = Read_Vb(0); rev = Read_Vb(0); //Read input voltage
if (rev == 0) if (rev == 0) //no input volatage == error state
Set_CtrlStatus(ALARM); Set_CtrlStatus(ALARM);
else if (rev >= 4) { else if (rev >= 4) { //We are USB powered (5V approx at input)
Set_LongKeyFlag(1); Set_LongKeyFlag(1);
Set_CtrlStatus(CONFIG); Set_CtrlStatus(CONFIG);
} else { } else { //Normal mode > ~9V at input
Set_CtrlStatus(IDLE); Set_CtrlStatus(IDLE);
G6_TIMER= device_info.idle_time; G6_TIMER= device_info.idle_time;
} }
@@ -127,10 +114,8 @@ void APP_Init(void) {
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Display_Temp Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾ<EFBFBD><EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:x:<3A><>ʾλ<CABE><CEBB> Temp:<3A><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Display_Temp(u8 x, s16 temp) { void Display_Temp(u8 x, s16 temp) {
char Str[8]; char Str[8];
@@ -179,23 +164,21 @@ void Display_Temp(u8 x, s16 temp) {
TEMPSHOW_TIMER= 20; //200ms TEMPSHOW_TIMER= 20; //200ms
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Show_Notice Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ϣ Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Show_Notice(void) { void Show_Notice(void) {
int j, k; int j, k;
static u8* ptr0; static u8* ptr0;
static u8 posi = 0, i = 0; static u8 posi = 0, i = 0;
if (i == 0) { //<EFBFBD><EFBFBD>1 <20><> if (i == 0) { //1
ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib); ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib);
} else if (i == 1) { //<EFBFBD><EFBFBD>2 <20><> } else if (i == 1) { //2
ptr0 = Oled_DrawArea(0, 0, 96, 16, ptr0); ptr0 = Oled_DrawArea(0, 0, 96, 16, ptr0);
} else if (i == 2) { //<EFBFBD><EFBFBD>3 <20><> } else if (i == 2) { //3
ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib); ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib);
} else if (i == 3) { //<EFBFBD><EFBFBD>4 <20><> } else if (i == 3) { //4
for (j = 0; j < 6; j++) { for (j = 0; j < 6; j++) {
k = 84; k = 84;
while (k >= posi) { while (k >= posi) {
@@ -214,18 +197,16 @@ void Show_Notice(void) {
i = 0; i = 0;
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Show_Ver Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾ<EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:ver <20><EFBFBD><E6B1BE>flag (0 :<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ )(1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Show_Ver(u8 ver[], u8 flag) { void Show_Ver(u8 ver[], u8 flag) {
u8 *ptr; u8 *ptr;
int k, i; int k, i;
u8 temp0, temp1, temp2; u8 temp0 = 0, temp1 = 0, temp2 = 0;
if (ver[2] >= 0x30 && ver[2] < 0x3a) if (ver[2] >= 0x30 && ver[2] < 0x3a)
temp1 = ver[2] - 0x30; temp1 = ver[2] - 0x30; //shift from ascii to the raw value
if (ver[3] >= 0x30 && ver[3] < 0x3a) if (ver[3] >= 0x30 && ver[3] < 0x3a)
temp2 = ver[3] - 0x30; temp2 = ver[3] - 0x30;
if (ver[0] >= 0x30 && ver[0] < 0x3a) if (ver[0] >= 0x30 && ver[0] < 0x3a)
@@ -256,10 +237,8 @@ void Show_Ver(u8 ver[], u8 flag) {
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Show_Config Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾCONFIG Description: Draws the word CONFIG to the screen
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Show_Config(void) { void Show_Config(void) {
u8* ptr; u8* ptr;
@@ -272,10 +251,8 @@ void Show_Config(void) {
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Show_TempDown Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾ<EFBFBD><EFBFBD><C2B6>½<EFBFBD>: ʵ<><CAB5><EFBFBD><EFBFBD>>>>Ŀ<><C4BF><EFBFBD><EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:temp ʵ<><CAB5><EFBFBD><EFBFBD>,dst_temp Ŀ<><C4BF><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Show_TempDown(s16 temp, s16 dst_temp) { void Show_TempDown(s16 temp, s16 dst_temp) {
static u8 guide_ui = 0; static u8 guide_ui = 0;
@@ -327,10 +304,8 @@ void Show_TempDown(s16 temp, s16 dst_temp) {
Display_Str10(56, str); Display_Str10(56, str);
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Show_Cal Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾУ׼<D0A3><D7BC><EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:flag = 1 У׼<D0A3>ɹ<EFBFBD> flag = 2 У׼ʧ<D7BC><CAA7>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Show_Cal(u8 flag) { void Show_Cal(u8 flag) {
u8 i; u8 i;
@@ -349,10 +324,8 @@ void Show_Cal(u8 flag) {
Clear_Watchdog(); Clear_Watchdog();
} }
/******************************************************************************* /*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Show_Warning Function:
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Description:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/ *******************************************************************************/
void Show_Warning(void) { void Show_Warning(void) {
u8 i; u8 i;

View File

@@ -26,7 +26,7 @@ void Mass_Storage_In (void)
case BOT_CSW_Send: case BOT_CSW_Send:
case BOT_ERROR: case BOT_ERROR:
Bot_State = BOT_IDLE; Bot_State = BOT_IDLE;
SetEPRxStatus(ENDP2, EP_RX_VALID);/* enable the Endpoint to recive the next cmd*/ SetEPRxStatus(ENDP2, EP_RX_VALID);/* enable the Endpoint to receive the next cmd*/
break; break;
case BOT_DATA_IN: case BOT_DATA_IN:
switch (CBW.CB[0]) switch (CBW.CB[0])