diff options
author | Ben V. Brown <[email protected]> | 2016-09-13 23:50:51 +1000 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2016-09-13 23:50:51 +1000 |
commit | 624fbe8e3f2184c0b2e1e6e6ea27e404c5aace3c (patch) | |
tree | efe779ce0dc0309b490eaefa3fb3c41c47aef0f0 | |
parent | 0b4068976ce98249eb0a603eae5c654b09b97dcd (diff) | |
download | IronOS-624fbe8e3f2184c0b2e1e6e6ea27e404c5aace3c.tar.gz IronOS-624fbe8e3f2184c0b2e1e6e6ea27e404c5aace3c.zip |
Commenting through most of the remaining files.
Fixing logic errors throughout as well
-rw-r--r-- | SystemDesign.md | 11 | ||||
-rw-r--r-- | workspace/ts100/.cproject | 4 | ||||
-rw-r--r-- | workspace/ts100/inc/APP_Version.h | 56 | ||||
-rw-r--r-- | workspace/ts100/inc/Disk.h | 38 | ||||
-rw-r--r-- | workspace/ts100/inc/Flash.h | 6 | ||||
-rw-r--r-- | workspace/ts100/inc/Hardware.h | 2 | ||||
-rw-r--r-- | workspace/ts100/inc/MMA8652FC.h | 6 | ||||
-rw-r--r-- | workspace/ts100/src/2FAT12.c | 37 | ||||
-rw-r--r-- | workspace/ts100/src/Bios.c | 27 | ||||
-rw-r--r-- | workspace/ts100/src/CTRL.c | 4 | ||||
-rw-r--r-- | workspace/ts100/src/Disk.c | 224 | ||||
-rw-r--r-- | workspace/ts100/src/Flash.c | 39 | ||||
-rw-r--r-- | workspace/ts100/src/Hardware.c | 18 | ||||
-rw-r--r-- | workspace/ts100/src/Interrupt.c | 13 | ||||
-rw-r--r-- | workspace/ts100/src/MMA8652FC.c | 164 | ||||
-rw-r--r-- | workspace/ts100/src/Main.c | 33 | ||||
-rw-r--r-- | workspace/ts100/src/STM32F103_System.c | 157 | ||||
-rw-r--r-- | workspace/ts100/src/UI.c | 107 | ||||
-rw-r--r-- | workspace/ts100/src/usb_bot.c | 2 |
19 files changed, 347 insertions, 601 deletions
diff --git a/SystemDesign.md b/SystemDesign.md index 1fcc36b7..2a4d72c0 100644 --- a/SystemDesign.md +++ b/SystemDesign.md @@ -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 + diff --git a/workspace/ts100/.cproject b/workspace/ts100/.cproject index 3c031bc3..a061e4ec 100644 --- a/workspace/ts100/.cproject +++ b/workspace/ts100/.cproject @@ -14,7 +14,7 @@ </extensions> </storageModule> <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 "${BuildArtifactFileBaseName}.elf" "${BuildArtifactFileBaseName}.bin"; arm-none-eabi-size "${BuildArtifactFileName}" & 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 "${BuildArtifactFileBaseName}.elf" "${BuildArtifactFileBaseName}.bin"; arm-none-eabi-size "${BuildArtifactFileName}" "> <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"> <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"/> <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"> - <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.include.paths.1436405353" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <listOptionValue builtIn="false" value=""${ProjDirPath}/inc""/> diff --git a/workspace/ts100/inc/APP_Version.h b/workspace/ts100/inc/APP_Version.h index 9ec781ad..d2893e39 100644 --- a/workspace/ts100/inc/APP_Version.h +++ b/workspace/ts100/inc/APP_Version.h @@ -1,35 +1,41 @@ /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************
-File Name : APP_Version.h
-Version : S100 APP Ver 2.11
-Description:
-Author : bure & Celery
-Data: 2015/08/03
-History:
-2015/08/03 ͳһ������
-*******************************************************************************/
+ File Name : APP_Version.h
+ Version : S100 APP Ver 2.11
+ Description:
+ Author : bure & Celery
+ Data: 2015/08/03
+ History:
+ 2015/08/03 ͳһ������
+ *******************************************************************************/
#ifndef __VERSION_H
#define __VERSION_H
- #define M_VER 'V','0'
- #define S_VER '0','1'
- #define OEM_TYPE "0"
- #define APP_BASE 0x0800C000
+#define M_VER 'V','0'
+#define S_VER '0','1'
+#define OEM_TYPE "0"
+#define APP_BASE 0x0800C000
/*----------------------------------------------------------------------------*/
- #ifdef TYPE_DS201
- #define PRODUCT_INFO "DS201"
- #define SCH_VER "1.7B"
- #elif TYPE_DS202
- #include "DS202V1_6.h"
- #define FLASH_PAGE 0x0800
- #elif TYPE_DS203
- #define PRODUCT_INFO "DS203"
- #define SCH_VER "2.70"
- #elif TYPE_S100
- #define PRODUCT_INFO "TS100"
- #include "S100V0_1.h"
- #endif
+#ifdef TYPE_DS201
+#define PRODUCT_INFO "DS201"
+#define SCH_VER "1.7B"
+#else
+ #ifdef TYPE_DS202
+ #include "DS202V1_6.h"
+ #define FLASH_PAGE 0x0800
+ #else
+ #ifdef TYPE_DS203
+ #define PRODUCT_INFO "DS203"
+ #define SCH_VER "2.70"
+ #else
+ #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}
diff --git a/workspace/ts100/inc/Disk.h b/workspace/ts100/inc/Disk.h index 2199246f..6bc1aacd 100644 --- a/workspace/ts100/inc/Disk.h +++ b/workspace/ts100/inc/Disk.h @@ -1,16 +1,16 @@ /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. **********************
-File Name : Disk.h
-Version : S100 APP Ver 2.11
-Description:
-Author : Celery
-Data: 2015/08/03
-History:
-2015/08/03 :
-*******************************************************************************/
+ File Name : Disk.h
+ Version : S100 APP Ver 2.11
+ Description:
+ Author : Celery
+ Data: 2015/08/03
+ History:
+ 2016/09/13 : Ben V. Brown - english comments
+ 2015/08/03 :
+ *******************************************************************************/
#ifndef __DISK_H
#define __DISK_H
-
#include "stm32f10x_flash.h"
#include "usb_scsi.h"
#include "usb_regs.h"
@@ -31,7 +31,6 @@ History: #define FILE_SECTOR &gDisk_buff[0x600]
#define Root (u8*)ROOT_SECTOR
-
//#define APP_BASE 0x0800C000
#define HEX 0
@@ -53,9 +52,9 @@ History: //#define FAT_DATA 0x00FFFFF8
#define VOLUME 0x40DD8D18 //0x3E645C29
-#define BUFF 0 // �������ݻ�����
+#define BUFF 0 //
-#define V32_BASE SECTOR_SIZE // V32 �ܹ� 8*4=32 �ֽ�
+#define V32_BASE SECTOR_SIZE // V32 8*4=32
#define W_ADDR 0
#define ADDR 1
#define H_ADDR 2
@@ -65,7 +64,7 @@ History: #define RD_CNT 6
#define WR_CNT 7
-#define VAR_BASE V32_BASE + 32 // VAR �ܹ� 9+17=26 �ֽ�
+#define VAR_BASE V32_BASE + 32 // VAR 9+17=26
#define USB_ST 0
#define SEG_KIND 1
#define SEG_LEN 2
@@ -75,10 +74,9 @@ History: #define DATA_CNT 6
#define F_TYPE 7
#define F_FLAG 8
-#define SEG_DATA 9 // ͨ�Ű������� 9~26 ��17�ֽ�
-
+#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);
u8 ReWrite_All(void);
u8 Config_Analysis(void);
@@ -86,12 +84,12 @@ void Disk_BuffInit(void); void Disk_SecWrite(u8* pbuffer, u32 disk_addr);
void Close_File(void);
void Write_Memory(u32 w_offset, u32 w_length);
-void Read_Memory (u32 r_offset, u32 r_length);
-void Set_Ver(u8 str[],u8 i);
+void Read_Memory(u32 r_offset, u32 r_length);
+void Set_Ver(u8 str[], u8 i);
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);
-u8* SearchFile(u8* pfilename, u16* pfilelen,u16* root_addr);
+u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr);
u8 ReWriteFlsash(void);
#endif
/********************************* END OF FILE ******************************/
diff --git a/workspace/ts100/inc/Flash.h b/workspace/ts100/inc/Flash.h index 2bf45f4e..fc5a9271 100644 --- a/workspace/ts100/inc/Flash.h +++ b/workspace/ts100/inc/Flash.h @@ -13,9 +13,9 @@ #define PP 0x02 // Write to Memory instruction
#define PW 0x0A // Page write instruction
-#define OK 0 // �������
-#define SEC_ERR 1 // ���������
-#define TMAX 100000 // ��ʱ����
+#define OK 0 //
+#define SEC_ERR 1 //
+#define TMAX 100000 //
#define WIP_Flag 0x01 // Write In Progress (WIP) flag
#define Dummy_Byte 0xA5
diff --git a/workspace/ts100/inc/Hardware.h b/workspace/ts100/inc/Hardware.h index 1dd39e49..62ae094b 100644 --- a/workspace/ts100/inc/Hardware.h +++ b/workspace/ts100/inc/Hardware.h @@ -40,7 +40,7 @@ u32 Get_AvgAd(void); int Get_SensorTmp(void);
u16 Get_ThermometerTemp(void);
s16 Get_Temp(s16 wk_temp);
-u32 Clear_Watchdog(void);
+void Clear_Watchdog(void);
u32 Start_Watchdog(u32 ms);
u8 Get_AlarmType(void);
void Set_AlarmType(u8 type);
diff --git a/workspace/ts100/inc/MMA8652FC.h b/workspace/ts100/inc/MMA8652FC.h index 508963da..dddb6bdc 100644 --- a/workspace/ts100/inc/MMA8652FC.h +++ b/workspace/ts100/inc/MMA8652FC.h @@ -5,15 +5,15 @@ Description: Author : Celery
Data: 2015/07/07
History:
-2015/07/07 ͳһ������
+2015/07/07 ͳһ������
*******************************************************************************/
#ifndef __MMA8652FC__H
#define __MMA8652FC__H
-//--------------MMA8652 ���岿��----------------------------------------------//
+//--------------MMA8652 Device ID----------------------------------------------//
#define DEVICE_ADDR 0X1D
-//--------------MMA8652 �Ĵ�������-------------------------------------------//
+//--------------MMA8652 Registers-------------------------------------------//
#define STATUS_REG 0x00
#define X_MSB_REG 0X01
#define X_LSB_REG 0X02
diff --git a/workspace/ts100/src/2FAT12.c b/workspace/ts100/src/2FAT12.c index 02404227..424abf82 100644 --- a/workspace/ts100/src/2FAT12.c +++ b/workspace/ts100/src/2FAT12.c @@ -5,7 +5,8 @@ Author : bure & Celery
Data: 2015/08/03
History:
- 2015/08/03 ͳһ������
+ 2016/09/13 Ben V. Brown -> English comments and cleaning up
+ 2015/08/03
*******************************************************************************/
#include <string.h>
#include "FAT12.h"
@@ -16,11 +17,11 @@ #define FAT2_BASE 0x00002800 // FAT2
#define ROOT_BASE 0x00004000 //
#define FILE_BASE 0x00008000 //
-#define SEC_LEN 0x200 //
-#define FAT1_SEC 0x0C // FAT1
-#define FAT2_SEC 0x0C // FAT2
+#define SEC_LEN 512 //length of a sector -> 512 Bytes
+#define FAT1_SEC 0x0C // FAT1 Sector
+#define FAT2_SEC 0x0C // FAT2 Sector
-#define OK 0 //
+#define OK 0 //Error codes
#define SEC_ERR 1 //
#define FAT_ERR 2 //
#define OVER 3 //
@@ -31,7 +32,7 @@ #define RW 1 //
/*******************************************************************************
- Function:
+ Function: NextCluster
Description:
Input:
*******************************************************************************/
@@ -49,25 +50,25 @@ u8 NextCluster(u16* pCluster) { return OK;
}
/*******************************************************************************
- Function:
+ Function: ReadFileSec
Description:
Input:
*******************************************************************************/
u8 ReadFileSec(u8* pBuffer, u16* pCluster) {
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)
- return SEC_ERR; // ��ǰ������
+ return SEC_ERR; //
pBuffer += 256;
ReadAddr += 256;
if (ReadDiskData(pBuffer, ReadAddr, 256) != OK)
return SEC_ERR; // Failed to read the sector
if (NextCluster(pCluster) != 0)
- return FAT_ERR; // ȡ��һ���غ�
+ return FAT_ERR; //
return OK;
}
/*******************************************************************************
- Function:
+ Function: ProgFileSec
Description:
Input:
*******************************************************************************/
@@ -76,30 +77,30 @@ u8 ProgFileSec(u8* pBuffer, u16* pCluster) { u32 ProgAddr = FILE_BASE + SEC_LEN * (*pCluster - 2);
if (ProgDiskPage(pBuffer, ProgAddr) != OK)
- return SEC_ERR; // дǰ������
+ return SEC_ERR; //
pBuffer += 256;
ProgAddr += 256;
if (ProgDiskPage(pBuffer, ProgAddr) != OK)
- return SEC_ERR; // ������
+ return SEC_ERR; //
Tmp = *pCluster;
switch (Tmp) {
- case 0: // ���дغ�
- case 1: // ���дغ�
+ case 0:
+ case 1:
if (SeekBlank(pBuffer, pCluster) != OK)
return OVER;
if (SetCluster(pBuffer, pCluster) != OK)
return SEC_ERR;
*(pCluster + 1) = Tmp;
return OK;
- case END: // ���ӽ���
+ case END:
default:
if (NextCluster(pCluster) != OK)
- return FAT_ERR; // ȡ��һ���غ�
+ return FAT_ERR;
return OK;
}
}
/*******************************************************************************
- Function:
+ Function: SeekBlank
Description:
Input:
*******************************************************************************/
diff --git a/workspace/ts100/src/Bios.c b/workspace/ts100/src/Bios.c index ac3f1265..8539a4f0 100644 --- a/workspace/ts100/src/Bios.c +++ b/workspace/ts100/src/Bios.c @@ -52,10 +52,8 @@ u32 Get_HeatingTime(void) { return gHeat_cnt;
}
/*******************************************************************************
- ������: Init_GTIME
- ��������:��ʼ����ʱ��
- �������:NULL
- ���ز���:NULL
+Function:
+Description: Init the global count down timers
*******************************************************************************/
void Init_Gtime(void) {
u8 i;
@@ -88,10 +86,9 @@ void Delay_HalfMs(u32 ms) { }
/*******************************************************************************
- ������: USB_Port
- ��������:���� USB �豸 IO �˿�
- �������:State = ENABLE / DISABLE
- ���ز���:NULL
+ Function: USB_Port
+ Description: Enables or disables the usb pins
+ Input: state == ENABLE or DISABLE
*******************************************************************************/
void USB_Port(u8 state) {
USB_DN_LOW();
@@ -279,10 +276,8 @@ void Adc_Init(void) { }
/*******************************************************************************
- ������: Init_Timer2
- ��������: ��ʼ�� ��ʱ��2
- �������:NULL
- ���ز���:NULL
+ Function:
+ Description: Setup Timer2 to fire every 10ms
*******************************************************************************/
void Init_Timer2(void) {
NVIC_InitTypeDef NVIC_InitStructure;
@@ -306,10 +301,8 @@ void Init_Timer2(void) { NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
- ������: Init_Timer3
- ��������: ��ʼ�� ��ʱ��3
- �������:NULL
- ���ز���:NULL
+Function:
+Description: Init Timer3 to fire every 50us to be used to control the irons software PWM
*******************************************************************************/
void Init_Timer3(void) {
NVIC_InitTypeDef NVIC_InitStructure;
@@ -334,7 +327,7 @@ void Init_Timer3(void) { }
/*******************************************************************************
Function:TIM2_ISR
- Description:Handles Timer 2 tick.
+ Description:Handles Timer 2 tick. (10mS)
Automatically decrements all >0 values in gTime.
Also reads the buttons every 4 ticks
*******************************************************************************/
diff --git a/workspace/ts100/src/CTRL.c b/workspace/ts100/src/CTRL.c index 1766fd3b..9714b789 100644 --- a/workspace/ts100/src/CTRL.c +++ b/workspace/ts100/src/CTRL.c @@ -31,7 +31,7 @@ s16 gPrev_temp = 250; // u8 gIs_restartkey = 0; //
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
3000, // T_Work; // 350C=3362,
100, //T_Step;
@@ -98,7 +98,7 @@ s16 Get_TempVal(void) { /*******************************************************************************
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
Output:Void
*******************************************************************************/
diff --git a/workspace/ts100/src/Disk.c b/workspace/ts100/src/Disk.c index bae04988..a2b1fb10 100644 --- a/workspace/ts100/src/Disk.c +++ b/workspace/ts100/src/Disk.c @@ -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,
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 *gV32 = (u32*) &gDisk_var[512 / 4];
static u8 *gVar = (u8*) &gDisk_var[512 / 4 + 8];
static u8 *gBuff = (u8*) &gDisk_var[0];
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",
"T_Step", "Turn_Off_v", "TempShowFlag", "ZeroP_Ad" };
+//default settings
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",
"ZeroP_Ad=239" };
+//comments for accepted range
const char *gSet_range[] = { " #(100~400)\r\n", " #(100~400)\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" };
-static u8 gFile_con[512];
-#define CONFIG_CONT 8
-u8 gRewriteflag[16];
+static u8 gFile_con[512]; //file contents buffer
+#define CONFIG_CONT 8 /*Number of variables in config.txt*/
+u8 gRewriteflag[16]; //This flags if this sector has changed and needs to be written to flash
#define ROW_CONT 35
#define FILE_CONT 254
@@ -289,8 +291,8 @@ void Upper(u8* str, u16 len) { /*******************************************************************************
Function: SearchFile
Description:
- Inputs: (pfilename) filename to look for, (pfilelen) length of the filename,(root_addr) root folder to search from
- Outputs: NULL (failed) or
+ Inputs: (pfilename) filename to look for, (pfilelen) length of the file,(root_addr) root folder to search from
+ Outputs: NULL (failed) or pointer to file start
*******************************************************************************/
u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) {
u16 n, sector;
@@ -301,7 +303,7 @@ u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) { for (n = 0; n < 16; n++) {
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) {
memcpy((u8*) pfilelen, pdiraddr + 0x1C, 2);
memcpy((u8*) §or, pdiraddr + 0x1A, 2);
@@ -314,30 +316,6 @@ u8* SearchFile(u8* pfilename, u16* pfilelen, u16* root_addr) { 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
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;
m = 0;
j = 0;
-
- if ((p_file = SearchFile("CONFIG TXT", &file_len, &root_addr))) {
+ //read in the config.txt if it exists
+ if ((p_file = SearchFile((u8*) ("CONFIG TXT"), &file_len, &root_addr))) {
memset(t_p, 0x00, CONFIG_CONT * ROW_CONT);
memcpy((u8*) gFile_con, p_file, 512);
for (k = 0; k < CONFIG_CONT; k++) {
@@ -373,11 +351,11 @@ u8 Config_Analysis(void) { t_p[k][j] = '\0';
m = i + 2;
}
- for (k = 0; k < CONFIG_CONT; k++) { //����CONFIG_CONT ��
- if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) { //�ҵ��ؼ���
+ for (k = 0; k < CONFIG_CONT; k++) {
+ if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) {
flag = 0;
for (i = strlen(gKey_words[k]); i < strlen((char *) t_p[k]);
- i++) { //����ֵ�Ƿ�Ϸ�
+ i++) {
if (t_p[k][i] >= '0' && t_p[k][i] <= '9') {
if (t_p[k][i] == '0') {
if (k == 6) {
@@ -390,12 +368,12 @@ u8 Config_Analysis(void) { }
flag = 1;
break;
- } else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) { //�ո�ϵȺ�
+ } else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) {
flag = 0;
break;
}
}
- if (flag && Cal_Val(t_p[k] + i, k, 0)) { //����ֵ�Ϸ�
+ if (flag && Cal_Val(t_p[k] + i, k, 0)) {
Set_Ver(t_p[k] + i, k);
if (k == 0)
sprintf((char *) t_p[k], "T_Standby=%d",
@@ -404,28 +382,28 @@ u8 Config_Analysis(void) { sprintf((char *) t_p[k], "T_Work=%d",
device_info.t_work / 10);
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);
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);
else if (k == 4)
sprintf((char *) t_p[k], "T_Step=%d",
device_info.t_step / 10);
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);
else if (k == 6)
sprintf((char *) t_p[k], "TempShowFlag=%d",
Get_TemperatureShowFlag());
else if (k == 7)
- sprintf((char *) t_p[k], "ZeroP_Ad=%d", gZerop_ad);
- } else { //����ֵ���Ϸ�
+ sprintf((char *) t_p[k], "ZeroP_Ad=%ld", gZerop_ad);
+ } else {
memset(t_p[k], 0, strlen((char *) t_p[k]));
memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k]));
is_illegality = 1;
}
- } else { //ľ���ҵ��ؼ���
+ } else {
memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k]));
is_illegality = 1;
}
@@ -441,7 +419,7 @@ u8 Config_Analysis(void) { m = strlen((char *) str);
if (m < 256) {
- gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m; //strlen((char *)str);//�ļ���С
+ gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m; //strlen((char *)str);
gDisk_buff[0x400 + root_addr * 32 + 0x1D] = 0;
} else {
gDisk_buff[0x400 + root_addr * 32 + 0x1C] = m % 256;
@@ -453,7 +431,7 @@ u8 Config_Analysis(void) { ReWriteFlsash();
}
} 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);
memset(gDisk_buff, 0x00, 0x2600);
memcpy(ROOT_SECTOR + 32, "LOGOIN BMP", 0xC);
@@ -479,10 +457,10 @@ u8 Config_Analysis(void) { m += strlen((char *) gSet_range[k]);
}
- gDisk_buff[0x40B] = 0x0; //����
+ gDisk_buff[0x40B] = 0x0;
*(u32*) VOLUME_BASE = VOLUME;
- gDisk_buff[0x41A] = 0x02; //�غ�
- gDisk_buff[0x41C] = m; //�ļ���С
+ gDisk_buff[0x41A] = 0x02;
+ gDisk_buff[0x41C] = m;
ReWrite_All();
}
@@ -496,60 +474,52 @@ u8 Config_Analysis(void) { return 0;
}
/*******************************************************************************
- ������: Disk_SecWrite
- ��������:PC �����ļ�ʱд����
- �������:pbuffer �������� diskaddr ��ַ
- ���ز���:NULL
+ Function: Disk_SecWrite
+ Description:
+ Inputs:
*******************************************************************************/
-void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC �������ݵ���
-{
- u8 is_illegality = 0;
+void Disk_SecWrite(u8* pbuffer, u32 diskaddr) {
u32 i, j, k, m, flag;
u8 t_p[CONFIG_CONT][ROW_CONT];
u8 str[FILE_CONT];
u8 ver[20];
static u16 Config_flag = 0;
- static u8 Conf_TxtFlag = 0;
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);
gRewriteflag[0] = 1;
- Conf_TxtFlag = 0;
}
} 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);
gRewriteflag[0] = 1;
- Conf_TxtFlag = 0;
}
} 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);
gRewriteflag[1] = 1;
for (i = 0; i < 16; i++) {
- memcpy((u8*) ver, (u8*) (pbuffer), 12);
- if (memcmp(ver, "CONFIG TXT", 11) == 0) {
+ memcpy((u8*) ver, (u8*) (pbuffer), 12); //copy the filename out for comparison
+ if (memcmp(ver, "CONFIG TXT", 11) == 0) { //if file name matches
Config_flag = pbuffer[0x1A];
- Conf_TxtFlag = 1;
break;
}
- pbuffer += 32;
+ pbuffer += 32; //move to the next chunk of the pbuffer
}
}
} 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);
}
if ((((diskaddr - 0x8000) / 0x200) + 2) == Config_flag) {
-// /*
m = 0;
memset(t_p, 0x00, CONFIG_CONT * ROW_CONT);
memcpy((u8*) (gFile_con), pbuffer, 512);
- for (k = 0; k < CONFIG_CONT; k++) { //ȡ��4 ��
+ for (k = 0; k < CONFIG_CONT; k++) { //
j = 0;
- for (i = m; i < strlen((char *) gFile_con); i++) { //����������ֵ�ַ�������λ��
+ for (i = m; i < strlen((char *) gFile_con); i++) { //
if (gFile_con[i] == 0x0D && gFile_con[i + 1] == 0x0A)
break;
else {
@@ -562,11 +532,11 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC �������ݵ�� m = i + 2;
}
- for (k = 0; k < CONFIG_CONT; k++) { //����k ��
- if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) { //�ҵ��ؼ���
+ for (k = 0; k < CONFIG_CONT; k++) {
+ if (memcmp(t_p[k], gKey_words[k], strlen(gKey_words[k])) == 0) {
flag = 0;
for (i = strlen(gKey_words[k]); i < strlen((char *) t_p[k]);
- i++) { //����ֵ�Ƿ�Ϸ�
+ i++) {
if (t_p[k][i] >= '0' && t_p[k][i] <= '9') {
if (t_p[k][i] == '0') {
if (k == 6) {
@@ -579,14 +549,12 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC �������ݵ�� }
flag = 1;
break;
- } else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) { //�ո�ϵȺ�
+ } else if ((t_p[k][i] != 0x20) && (t_p[k][i] != 0x3d)) {
flag = 0;
break;
}
}
if ((!flag) || (!Cal_Val(t_p[k] + i, k, 1))) {
-
- is_illegality = 1; //���Ϸ�
return;
} else {
Set_Ver(t_p[k] + i, k);
@@ -599,56 +567,44 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC �������ݵ�� sprintf((char *) t_p[k], "T_Work=%d",
device_info.t_work / 10);
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);
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);
else if (k == 4)
sprintf((char *) t_p[k], "T_Step=%d",
device_info.t_step / 10);
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);
else if (k == 6)
sprintf((char *) t_p[k], "TempShowFlag=%d",
Get_TemperatureShowFlag());
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 { //ľ���ҵ��ؼ���
+ } else {
memcpy(t_p[k], gDef_set[k], strlen((char *) gDef_set[k]));
- is_illegality = 1;
return;
}
}
- if (!is_illegality) {
- memset(str, 0, FILE_CONT);
- for (k = 0; k < CONFIG_CONT; k++) {
- strcat((char *) str, (char *) t_p[k]);
- strcat((char *) str, (char *) gSet_range[k]);
- }
- m = strlen((char *) str);
+ memset(str, 0, FILE_CONT);
+ for (k = 0; k < CONFIG_CONT; k++) {
+ strcat((char *) str, (char *) t_p[k]);
+ strcat((char *) str, (char *) gSet_range[k]);
+ }
+ m = strlen((char *) str);
+ gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1C] = m % 256;
+ gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1D] = m / 256;
- if (m < 256) {
- gDisk_buff[0x400 + (Config_flag - 2) * 32 + 0x1C] = m; //strlen((char *)str);//�ļ���С
- 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();
+ return;
- 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;
- }
}
gRewriteflag[1] = 1;
@@ -659,10 +615,8 @@ void Disk_SecWrite(u8* pbuffer, u32 diskaddr) //PC �������ݵ�� }
/*******************************************************************************
- ������: Disk_SecRead
- ��������:PC ��ȡ�ļ�ʱд����
- �������:pbuffer ��ȡ���� diskaddr ��ַ
- ���ز���:NULL
+ Function: Disk_SecRead
+ Description: Reads a sector from the virtual disk
*******************************************************************************/
void Disk_SecRead(u8* pbuffer, u32 disk_addr) {
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
memcpy(pbuffer, (u8*) (APP_BASE + 0x600 + (disk_addr - 0x8000)), 512);
} else {
- memset(pbuffer, 0, 512); //
+ memset(pbuffer, 0, 512); //unknown, return 0's
}
}
/*******************************************************************************
- ������: ReWriteFlsash
- ��������:дFlash
- �������:NULL
- ���ز���:�Ƿ�д���־
+ Function:ReWriteFlsash
+ Description:
+ Output:RDY(all good) or ERR (error)
*******************************************************************************/
u8 ReWriteFlsash(void) {
u32 i, j;
@@ -697,12 +650,12 @@ u8 ReWriteFlsash(void) { gRewriteflag[i] = 0;
FLASH_Erase(APP_BASE + i * 0x400);
f_buff = (u16*) &gDisk_buff[i * 0x400];
- for (j = 0; j < 0x400; j += 2) {
- result = FLASH_Prog((u32) (APP_BASE + i * 0x400 + j),
+ for (j = 0; j < 0x400; j += 2) { //Loop through the 1k block
+ result = FLASH_Prog((u32) (APP_BASE + i * 0x400 + j), //program each 16 bit block
*f_buff++);
- if (result != FLASH_COMPLETE) {
- FLASH_Lock();
- return ERR;
+ if (result != FLASH_COMPLETE) { //something went wrong
+ FLASH_Lock(); //make sure the flash is locked again
+ return ERR; //return ERR
}
}
break;
@@ -712,10 +665,9 @@ u8 ReWriteFlsash(void) { return RDY;
}
/*******************************************************************************
- ������: ReWrite_All
- ��������:��������flash�������
- �������:NULL
- ���ز���:�Ƿ�д���־
+ Function: ReWrite_All
+ Description:
+ Output:
*******************************************************************************/
u8 ReWrite_All(void) {
u16 i;
@@ -734,24 +686,20 @@ u8 ReWrite_All(void) { return RDY;
}
/*******************************************************************************
- ������: Erase
- ��������:��ʽ��Flash
- �������:NULL
- ���ز���:NULL
+ Function:Erase
+ Description: Erase the first 9k from APP_BASE
*******************************************************************************/
void Erase(void) {
u16 i;
- FLASH_Unlock();
+ FLASH_Unlock(); //unlock the mcu flash controller
for (i = 0; i < 9; i++)
- FLASH_Erase(APP_BASE + i * 0x400);
+ FLASH_Erase(APP_BASE + i * 0x400); //erase the flash
FLASH_Lock();
}
/*******************************************************************************
- ������: Read_Memory
- ��������:����microSD���Ķ�������
- �������:r_offset ƫ�� r_length����
- ���ز���:NULL
+ Function: Read_Memory
+ Description:
*******************************************************************************/
void Read_Memory(u32 r_offset, u32 r_length) {
static u32 offset, length, block_offset;
@@ -789,10 +737,8 @@ void Read_Memory(u32 r_offset, u32 r_length) { }
}
/*******************************************************************************
- ������: Write_Memory
- ��������:����microSD���������
- �������:r_offset ƫ�� r_length����
- ���ز���:NULL
+ Function: Write_Memory
+ Description:
*******************************************************************************/
void Write_Memory(u32 w_offset, u32 w_length) {
static u32 offset, length;
diff --git a/workspace/ts100/src/Flash.c b/workspace/ts100/src/Flash.c index ce7ca2e4..ee5b4f73 100644 --- a/workspace/ts100/src/Flash.c +++ b/workspace/ts100/src/Flash.c @@ -1,32 +1,33 @@ /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************
File Name : Flash.c
Version : Author : bure
-*******************************************************************************/
+ *******************************************************************************/
#include "APP_Version.h"
#include "Flash.h"
#include "Bios.h"
-u8 ExtFlashSendByte(u8 byte);
-void ExtFlashWaitForWriteEnd(void);
/*******************************************************************************
- FLASH_Prog:
-*******************************************************************************/
-u8 FLASH_Prog(u32 Address, u16 Data)
-{
- if(FLASH_WaitForLastOperation(WAIT_TIMES)!=FLASH_TIMEOUT)
- FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
- return FLASH_ProgramHalfWord(Address, Data);
+ Function: FLASH_Prog
+ Description: Programs the data into the system flash at the specified address
+ *******************************************************************************/
+u8 FLASH_Prog(u32 Address, u16 Data) {
+ if (FLASH_WaitForLastOperation(WAIT_TIMES) != FLASH_TIMEOUT)
+ FLASH_ClearFlag(
+ FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
+ return FLASH_ProgramHalfWord(Address, Data);
}
/*******************************************************************************
- FLASH_Erase:
-*******************************************************************************/
-void FLASH_Erase(u32 Address)
-{
- if(Address%FLASH_PAGE == 0) { // FLASH Page start (1K/Page)
- if(FLASH_WaitForLastOperation(WAIT_TIMES)!=FLASH_TIMEOUT)
- FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
- FLASH_ErasePage(Address); // FLASH Page erase
- }
+ Function: FLASH_Erase
+ Description: Erases a page of flash
+ Inputs: Starting address for the page to erase
+ *******************************************************************************/
+void FLASH_Erase(u32 Address) {
+ if (Address % FLASH_PAGE == 0) { // FLASH Page start (1K/Page)
+ if (FLASH_WaitForLastOperation(WAIT_TIMES) != FLASH_TIMEOUT) //wait for last op to finish
+ FLASH_ClearFlag(
+ FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
+ FLASH_ErasePage(Address); // FLASH Page erase
+ }
}
/********************************* END OF FILE ******************************/
diff --git a/workspace/ts100/src/Hardware.c b/workspace/ts100/src/Hardware.c index cb284a8e..cef83d46 100644 --- a/workspace/ts100/src/Hardware.c +++ b/workspace/ts100/src/Hardware.c @@ -274,7 +274,7 @@ int Get_SensorTmp(void) { if (gMeas_cnt == 1) {
ad_sum = ad_sum - max - min;
avg_data = ad_sum / 8;
-
+ //^ Removes the two outliers from the data spread
slide_data = Get_TempSlAvg(avg_data);
sensor_temp = (250 + (3300 * slide_data / 4096) - 750); //(25 + ((10*(33*gSlide_data)/4096)-75));
ad_sum = 0;
@@ -356,10 +356,8 @@ s16 Get_Temp(s16 wk_temp) { }
/*******************************************************************************
- ������: Start_Watchdog
- ��������:��ʼ�����Ź�
- �������:ms ���Ź�����
- ���ز���:����1
+ Function:Start_Watchdog
+ Description: Starts the system watchdog timer
*******************************************************************************/
u32 Start_Watchdog(u32 ms) {
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
@@ -378,13 +376,11 @@ u32 Start_Watchdog(u32 ms) { return 1;
}
/*******************************************************************************
- ������: Clear_Watchdog
- ��������:���ÿ��Ź�����
- �������:NULL
- ���ز���:����1
+ Function:Clear_Watchdog
+ Description:Resets the watchdog timer
*******************************************************************************/
-u32 Clear_Watchdog(void) {
+void Clear_Watchdog(void) {
IWDG_ReloadCounter();
- return 1;
+
}
/******************************** END OF FILE *********************************/
diff --git a/workspace/ts100/src/Interrupt.c b/workspace/ts100/src/Interrupt.c index 88fa5114..c99d7373 100644 --- a/workspace/ts100/src/Interrupt.c +++ b/workspace/ts100/src/Interrupt.c @@ -56,17 +56,6 @@ void SysTick_Handler(void) { void USB_LP_CAN1_RX0_IRQHandler(void) {
USB_Istr();
}
-/*
- void I2C1_EV_IRQHandler(void)
- {
- I2C1_EV_ISR();
- }
-
- void I2C1_ER_IRQHandler(void)
- {
- I2C1_ER_ISR();
- }
- */
void TIM2_IRQHandler(void) {
TIM2_ISR();
}
@@ -74,7 +63,7 @@ void TIM2_IRQHandler(void) { void TIM3_IRQHandler(void) {
TIM3_ISR();
}
-
+/*This loop is used for un assigned IRQ's so that the debugger can catch them*/
static void forever()
{
diff --git a/workspace/ts100/src/MMA8652FC.c b/workspace/ts100/src/MMA8652FC.c index c0d71fd3..d8488e99 100644 --- a/workspace/ts100/src/MMA8652FC.c +++ b/workspace/ts100/src/MMA8652FC.c @@ -5,6 +5,7 @@ Author : Celery
Data: 2015/07/07
History:
+ 2016/09/13 Ben V. Brown - English comments and fixing a few errors
2015/07/07 ͳһ������
*******************************************************************************/
#include <stdio.h>
@@ -28,19 +29,15 @@ u8 gMmatxdata; typedef struct {
u8 hi;
u8 lo;
-} DRByte;
-typedef struct {
- DRByte Byte;
} DR_Value;
DR_Value gX_value, gY_value, gZ_value;
/*******************************************************************************
- ������: Get_MmaActive
- ��������:��ȡ���ٶȴ���������״̬
- �������:NULL
- ���ز���:���ٶȴ�����״̬
+ Function:
+ Description:Returns if the unit is actively being moved
+ Output: if the unit is active or not.
*******************************************************************************/
u16 Get_MmaActive(void) {
return gactive;
@@ -53,20 +50,19 @@ u16 Get_MmaShift(void) { return gShift;
}
/*******************************************************************************
- ������: Get_MmaActive
- ��������:XXXXXXXXXXXXXXXXXXXXXX
- �������:XXXXXXXXXXXXXXXXXXXXXX
- ���ز���:XXXXXXXXXXXXXXXXXXXXXX
+ Function: Set_MmaShift
+ Description: Set the Shift Value
+ Input: shift value
*******************************************************************************/
void Set_MmaShift(u16 shift) {
gShift = shift;
}
/*******************************************************************************
- ������: IIC_RegWrite
- ��������:��Reg��ַд��Data
- �������:Reg �����еĵ�ַ��Data����
- ���ز���: �ɹ���
+ Function:IIC_RegWrite
+ Description:Writes a value to a register
+ Input:the register, the data
+ Output: 1 if the write succeeded
*******************************************************************************/
int IIC_RegWrite(u8 reg, u8 data) {
u8 tx_data[20];
@@ -77,10 +73,10 @@ int IIC_RegWrite(u8 reg, u8 data) { return 1;
}
/*******************************************************************************
- ������: IIC_RegRead
- ��������:������Reg����������
- �������:Reg �����еĵ�ַ������gMmatxdata��
- ���ز���: �ɹ���
+ Function:IIC_RegRead
+ Description: Reads a register from I2C, using a single byte addressing scheme
+ Inputs: uint8_t register to read
+ Output: 1 if the read worked.
*******************************************************************************/
int IIC_RegRead(u8 reg) {
u8 tx_data[20];
@@ -91,10 +87,8 @@ int IIC_RegRead(u8 reg) { return 1;
}
/*******************************************************************************
- ������: MMA865x_Standby
- ��������:�������״̬
- �������:NULL
- ���ز���:NULL
+ Function: MMA865x_Standby
+ Description: Put the MMA865 into standby mode
*******************************************************************************/
void MMA865x_Standby(void) {
//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)
}
/*******************************************************************************
- ������: MMA865x_Active
- ��������:��������ģʽ
- �������:NULL
- ���ز���:NULL
+ Function: MMA865x_Active
+ Description: Put the MMA865 into active mode
*******************************************************************************/
void MMA865x_Active(void) {
// 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_RegRead
- ��������:������Reg����������
- �������:NULL
- ���ز���:NULL
+ Function: IIC_RegRead
+ Description:Setup the MMA865x IC settings
*******************************************************************************/
void StartUp_Accelerated(void) {
- //------�������״̬-----------------------//
+ //Put the unit into standby state so we can edit its configuration registers
MMA865x_Standby();
- //---- ���ò�����Χ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)
- //--- ������������ʱ��������100HZ------------------------------------//
+ //Set the unit to the required update rate (eg 100Hz)
IIC_RegWrite(CTRL_REG1, DataRateValue); //IIC_RegRead(CTRL_REG1)|
- //----���ò�������ģʽ------------------------------------------------------//
- IIC_RegWrite(CTRL_REG2, 0); //(IIC_RegRead(CTRL_REG2) & ~MODS_MASK)
- //---------��������ģʽ------------------------------------//
+
+ IIC_RegWrite(CTRL_REG2, 0); //Normal mode
+
+ //Change the unit back to active mode to exit setup and start the readings
MMA865x_Active();
}
/*******************************************************************************
- ������: Read_ZYXDr
- ��������:��ȡXYZ����
- �������:NULL
- ���ز���:x,y,z�ķ���
+ Function: Read_ZYXDr
+ Description:
+ Output: 1 if new data, 0 if not
*******************************************************************************/
int Read_ZYXDr(void) {
u8 reg_flag;
u8 ptr, i;
- u8 value[6];
-
- memset((u8*) &gX_value, 0, 6);
+ u8 value[6] = { 0, 0, 0, 0, 0, 0 };
//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;
- 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
ptr = X_MSB_REG;
for (i = 0; i < 6; i++) {
if (IIC_RegRead(ptr++) == 0)
break;
+
value[i] = gMmatxdata;
//Copy and save each result as a 16-bit left-justified value
- gX_value.Byte.hi = value[0];
- gX_value.Byte.lo = value[1];
- gY_value.Byte.hi = value[2];
- gY_value.Byte.lo = value[3];
- gZ_value.Byte.hi = value[4];
- gZ_value.Byte.lo = value[5];
+ gX_value.hi = value[0];
+ gX_value.lo = value[1];
+ gY_value.hi = value[2];
+ gY_value.lo = value[3];
+ gZ_value.hi = value[4];
+ gZ_value.lo = value[5];
return 1;
}
} else
@@ -168,38 +157,37 @@ int Read_ZYXDr(void) { return 0;
}
/*******************************************************************************
- ������: Cheak_XYData
- ��������:���x��y�ķ���仯
- �������:ǰһxy��������xy����Ա�
- ���ز���:�Ƿ��ƶ�
+ Function: Cheak_XYData
+ Description: Check the input X,Y for a large enough acceleration to wake the unit
+ Inputs:x0,y0,x1,y1 to check
+ Output: if the unit is active
*******************************************************************************/
u16 Cheak_XYData(u16 x0, u16 y0, u16 x1, u16 y1) {
u16 active = 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)))
gShift = 1;
if ((y1 > (y0 + 32)) || (y1 < (y0 - 32)))
gShift = 1;
+ if ((x1 > (x0 + 16)) || (x1 < (x0 - 16)))
+ active = 1;
+ if ((y1 > (y0 + 16)) || (y1 < (y0 - 16)))
+ active = 1;
+
return active;
}
/*******************************************************************************
- ������: Update_X
- ��������:��������
- �������:����x
- ���ز���:NULL
+ Function: Update_X
+ Description: Converts the read value for x into an actual properly located value
+ Output: X
*******************************************************************************/
u16 Update_X(void) {
u16 value, x;
- value = ((gX_value.Byte.hi << 8) | (gX_value.Byte.lo & 0xf0)) >> 4;
- if (gX_value.Byte.hi > 0x7f)
+ value = ((gX_value.hi << 8) | (gX_value.lo & 0xf0)) >> 4;
+ if (gX_value.hi > 0x7f)
x = (~value + 1) & 0xfff;
else
x = value & 0xfff;
@@ -207,16 +195,15 @@ u16 Update_X(void) { return x;
}
/*******************************************************************************
- ������: Update_Y
- ��������:��������
- �������:NULL
- ���ز���:����y
+ Function: Update_Y
+ Description: Converts the read value for y into an actual properly located value
+ Output: Y
*******************************************************************************/
u16 Update_Y(void) {
u16 value, y;
- value = ((gY_value.Byte.hi << 8) | (gY_value.Byte.lo & 0xf0)) >> 4;
- if (gY_value.Byte.hi > 0x7f)
+ value = ((gY_value.hi << 8) | (gY_value.lo & 0xf0)) >> 4;
+ if (gY_value.hi > 0x7f)
y = (~value + 1) & 0xfff;
else
y = value & 0xfff;
@@ -224,16 +211,15 @@ u16 Update_Y(void) { return y;
}
/*******************************************************************************
- ������: Update_z
- ��������:��������
- �������:NULL
- ���ز���:����z
+ Function: Update_Z
+ Description: Converts the read value for z into an actual properly located value
+ Output: Z
*******************************************************************************/
u16 Update_Z(void) {
u16 value, z;
- value = ((gZ_value.Byte.hi << 8) | (gZ_value.Byte.lo & 0xf0)) >> 4;
- if (gZ_value.Byte.hi > 0x7f)
+ value = ((gZ_value.hi << 8) | (gZ_value.lo & 0xf0)) >> 4;
+ if (gZ_value.hi > 0x7f)
z = (~value + 1) & 0xfff;
else
z = value & 0xfff;
@@ -241,22 +227,24 @@ u16 Update_Z(void) { return z;
}
/*******************************************************************************
- ������: Check_Accelerated
- ��������:�����ٶȴ������Ƿ��ƶ�
- �������:NULL
- ���ز���:NULL
+ Function: Check_Accelerated
+ Description:Check if the unit has moved
*******************************************************************************/
void Check_Accelerated(void) {
static u16 x0 = 0, y0 = 0;
u16 x1, y1;
- if (Read_ZYXDr()) { /*�����ݣ���������*/
- x1 = Update_X();
+ if (Read_ZYXDr()) { //Read the new values from the accelerometer
+ x1 = Update_X(); //convert the values into usable form
y1 = Update_Y();
- } else
+ } else {
x1 = x0;
- y1 = y0;
- gactive = Cheak_XYData(x0, y0, x1, y1);/*����Ƿ��ƶ�*/
+ y1 = y0; //use old values
+ gactive = 0;
+ return;
+ }
+
+ gactive = Cheak_XYData(x0, y0, x1, y1); //gactive == If the unit is moving or not
x0 = x1;
y0 = y1;
diff --git a/workspace/ts100/src/Main.c b/workspace/ts100/src/Main.c index 7c3f3cf9..1762b02c 100644 --- a/workspace/ts100/src/Main.c +++ b/workspace/ts100/src/Main.c @@ -24,38 +24,39 @@ int main(void) {
RCC_Config(); //setup system clock
NVIC_Config(0x4000);
- Init_Timer2(); //init the timer
+ Init_Timer2(); //init the timers
Init_Timer3();
- GPIO_Config();
- USB_Port(DISABLE);
- Delay_Ms(200);
- USB_Port(ENABLE);
+ GPIO_Config();//setup all the GPIO pins
+
+ USB_Port(DISABLE);//disable the USB hardware
+ Delay_Ms(200);//pause to let hardware stabilize
+ USB_Port(ENABLE);//enable the USB hardware
USB_Init();
I2C_Configuration(); //init the i2c bus
Adc_Init(); //init adc and dma
if (Get_CtrlStatus() != CONFIG)
- StartUp_Accelerated();
+ StartUp_Accelerated();//start the accelerometer if not in config mode
- System_Init();
- Init_Oled();
- Clear_Screen();
- Init_Gtime();
- APP_Init();
+ System_Init();//load known safe values
+ Init_Oled();//init the OLED display
+ Clear_Screen();//clear the display buffer to black
+ Init_Gtime();//init the count down timers
+ 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
Pid_Init(); //init the pid to starting values
- Set_gKey(NO_KEY); //reset keys
- Start_Watchdog(3000);
+ Set_gKey(NO_KEY); //reset keys to all off
+ Start_Watchdog(3000);//start the system watchdog as 3 seconds
while (1) {
Clear_Watchdog(); //reset the Watchdog
if (Get_CtrlStatus() != CONFIG && LEAVE_WAIT_TIMER== 0) {
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
}
}
diff --git a/workspace/ts100/src/STM32F103_System.c b/workspace/ts100/src/STM32F103_System.c deleted file mode 100644 index a5aff6be..00000000 --- a/workspace/ts100/src/STM32F103_System.c +++ /dev/null @@ -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>© 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****/
diff --git a/workspace/ts100/src/UI.c b/workspace/ts100/src/UI.c index 2aa79eb8..8b1e1c6e 100644 --- a/workspace/ts100/src/UI.c +++ b/workspace/ts100/src/UI.c @@ -21,11 +21,11 @@ #include "MMA8652FC.h"
/******************************************************************************/
u8 gTemp_array[16 * 16 + 16];
-u8 gTemperatureshowflag = 0; /* 0 �����϶�,1�ǻ��϶�*/
+u8 gTemperatureshowflag = 0;
u8 gUp_flag = 0, gDown_flag = 0, gLevel_flag = 0, gTempset_showctrl = 0;
u16 gTemp_array_u16[208];
-u16 gSet_table[2] = { 4000, 1000 }; /*�¶�ѡ��*/
-u32 gCont = 0; /*gCont ��������״̬ת�����ˢ����ʶ*/
+u16 gSet_table[2] = { 4000, 1000 };
+u32 gCont = 0;
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,
@@ -51,48 +51,37 @@ static u8 Ver_s[] = { /*12*16*/0x04, 0x0C, 0x74, 0x80, 0x00, 0x00, 0x00, 0x80, /******************************************************************************/
/*******************************************************************************
- ������: Get_UpdataFlag
- ��������:��ȡ��Ļˢ�±�־
- �������:NULL
- ���ز���:��Ļˢ�±�־
+ Function:
+ Description:
*******************************************************************************/
u32 Get_UpdataFlag(void) {
return gCont;
}
/*******************************************************************************
- ������: Set_UpdataFlag
- ��������:������Ļˢ�±�־
- �������:1 ˢ�£�0 ��ˢ��
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Set_UpdataFlag(u32 cont) {
gCont = cont;
}
/*******************************************************************************
- ������: Set_TemperatureShowFlag
- ��������:�����¶���ʾ��ʽ
- �������:flag ���϶�(0),���϶�(1)��־
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Set_TemperatureShowFlag(u8 flag) {
gTemperatureshowflag = flag;
}
/*******************************************************************************
- ������: Get_TemperatureShowFlag
- ��������:��ȡ�¶���ʾ��ʽ
- �������:NULL
- ���ز���:flag ���϶�(0),���϶�(1)��־
+ Function:
+ Description:־
*******************************************************************************/
u8 Get_TemperatureShowFlag(void) {
return gTemperatureshowflag;
}
/*******************************************************************************
- ������: TemperatureShow_Change
- ��������:���϶Ȼ��϶��ת��
- �������: flag 0,���϶�ת�����϶�
- flag 1,���϶�ת�����϶�
- tmp Ҫת�����¶�
- ���ز���:ת�����ֵ
+ Function:
+ Description: Converts F to C or C to F.
+ Input: flag = if flag==0 converts C to F
*******************************************************************************/
s16 TemperatureShow_Change(u8 flag, s16 tmp) {
if (flag == 0) {
@@ -102,10 +91,8 @@ s16 TemperatureShow_Change(u8 flag, s16 tmp) { }
}
/*******************************************************************************
- ������: APP_Init
- ��������:���ݵ�ѹ��ʼ����ʼ״̬
- �������:NULL
- ���ز���:NULL
+ Function:APP_Init
+ Description:Init the operating mode by looking at input voltage to pick USB or normal
*******************************************************************************/
void APP_Init(void) {
int rev;
@@ -113,13 +100,13 @@ void APP_Init(void) { HEATING_TIMER= 0;
UI_TIMER= 0;
- rev = Read_Vb(0);
- if (rev == 0)
+ rev = Read_Vb(0); //Read input voltage
+ if (rev == 0) //no input volatage == error state
Set_CtrlStatus(ALARM);
- else if (rev >= 4) {
+ else if (rev >= 4) { //We are USB powered (5V approx at input)
Set_LongKeyFlag(1);
Set_CtrlStatus(CONFIG);
- } else {
+ } else { //Normal mode > ~9V at input
Set_CtrlStatus(IDLE);
G6_TIMER= device_info.idle_time;
}
@@ -127,10 +114,8 @@ void APP_Init(void) { }
/*******************************************************************************
- ������: Display_Temp
- ��������:��ʾ�¶�
- �������:x:��ʾλ�� Temp:�¶�
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Display_Temp(u8 x, s16 temp) {
char Str[8];
@@ -179,23 +164,21 @@ void Display_Temp(u8 x, s16 temp) { TEMPSHOW_TIMER= 20; //200ms
}
/*******************************************************************************
- ������: Show_Notice
- ��������:��ʾ������ʾ��Ϣ
- �������:NULL
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Show_Notice(void) {
int j, k;
static u8* ptr0;
static u8 posi = 0, i = 0;
- if (i == 0) { //��1 ��
+ if (i == 0) { //1
ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib);
- } else if (i == 1) { //��2 ��
+ } else if (i == 1) { //2
ptr0 = Oled_DrawArea(0, 0, 96, 16, ptr0);
- } else if (i == 2) { //��3 ��
+ } else if (i == 2) { //3
ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib);
- } else if (i == 3) { //��4 ��
+ } else if (i == 3) { //4
for (j = 0; j < 6; j++) {
k = 84;
while (k >= posi) {
@@ -214,18 +197,16 @@ void Show_Notice(void) { i = 0;
}
/*******************************************************************************
- ������: Show_Ver
- ��������:��ʾ�汾
- �������:ver �汾��flag (0 :������ʾ )(1������)
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Show_Ver(u8 ver[], u8 flag) {
u8 *ptr;
int k, i;
- u8 temp0, temp1, temp2;
+ u8 temp0 = 0, temp1 = 0, temp2 = 0;
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)
temp2 = ver[3] - 0x30;
if (ver[0] >= 0x30 && ver[0] < 0x3a)
@@ -256,10 +237,8 @@ void Show_Ver(u8 ver[], u8 flag) { }
/*******************************************************************************
- ������: Show_Config
- ��������:��ʾCONFIG
- �������:NULL
- ���ز���:NULL
+ Function:
+ Description: Draws the word CONFIG to the screen
*******************************************************************************/
void Show_Config(void) {
u8* ptr;
@@ -272,10 +251,8 @@ void Show_Config(void) { }
/*******************************************************************************
- ������: Show_TempDown
- ��������:��ʾ�¶��½�: ʵ���¶�>>>Ŀ���¶�
- �������:temp ʵ���¶�,dst_temp Ŀ���¶�
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Show_TempDown(s16 temp, s16 dst_temp) {
static u8 guide_ui = 0;
@@ -327,10 +304,8 @@ void Show_TempDown(s16 temp, s16 dst_temp) { Display_Str10(56, str);
}
/*******************************************************************************
- ������: Show_Cal
- ��������:��ʾУ���
- �������:flag = 1 У�ɹ� flag = 2 Уʧ��
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Show_Cal(u8 flag) {
u8 i;
@@ -349,10 +324,8 @@ void Show_Cal(u8 flag) { Clear_Watchdog();
}
/*******************************************************************************
- ������: Show_Warning
- ��������:��ʾ�������
- �������:NULL
- ���ز���:NULL
+ Function:
+ Description:
*******************************************************************************/
void Show_Warning(void) {
u8 i;
diff --git a/workspace/ts100/src/usb_bot.c b/workspace/ts100/src/usb_bot.c index 182f5c9d..055d5832 100644 --- a/workspace/ts100/src/usb_bot.c +++ b/workspace/ts100/src/usb_bot.c @@ -26,7 +26,7 @@ void Mass_Storage_In (void) case BOT_CSW_Send:
case BOT_ERROR:
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;
case BOT_DATA_IN:
switch (CBW.CB[0])
|