NULL
This commit is contained in:
138
user/Utility/CRC.c
Executable file
138
user/Utility/CRC.c
Executable file
@@ -0,0 +1,138 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
const u8 CRC_TABLE[]={
|
||||
0x000,0x007,0x00E,0x009,0x01C,0x01B,0x012,0x015,0x038,0x03F,0x036,0x031,0x024,0x023,0x02A,0x02D,
|
||||
0x070,0x077,0x07E,0x079,0x06C,0x06B,0x062,0x065,0x048,0x04F,0x046,0x041,0x054,0x053,0x05A,0x05D,
|
||||
0x0E0,0x0E7,0x0EE,0x0E9,0x0FC,0x0FB,0x0F2,0x0F5,0x0D8,0x0DF,0x0D6,0x0D1,0x0C4,0x0C3,0x0CA,0x0CD,
|
||||
0x090,0x097,0x09E,0x099,0x08C,0x08B,0x082,0x085,0x0A8,0x0AF,0x0A6,0x0A1,0x0B4,0x0B3,0x0BA,0x0BD,
|
||||
0x0C7,0x0C0,0x0C9,0x0CE,0x0DB,0x0DC,0x0D5,0x0D2,0x0FF,0x0F8,0x0F1,0x0F6,0x0E3,0x0E4,0x0ED,0x0EA,
|
||||
0x0B7,0x0B0,0x0B9,0x0BE,0x0AB,0x0AC,0x0A5,0x0A2,0x08F,0x088,0x081,0x086,0x093,0x094,0x09D,0x09A,
|
||||
0x027,0x020,0x029,0x02E,0x03B,0x03C,0x035,0x032,0x01F,0x018,0x011,0x016,0x003,0x004,0x00D,0x00A,
|
||||
0x057,0x050,0x059,0x05E,0x04B,0x04C,0x045,0x042,0x06F,0x068,0x061,0x066,0x073,0x074,0x07D,0x07A,
|
||||
0x089,0x08E,0x087,0x080,0x095,0x092,0x09B,0x09C,0x0B1,0x0B6,0x0BF,0x0B8,0x0AD,0x0AA,0x0A3,0x0A4,
|
||||
0x0F9,0x0FE,0x0F7,0x0F0,0x0E5,0x0E2,0x0EB,0x0EC,0x0C1,0x0C6,0x0CF,0x0C8,0x0DD,0x0DA,0x0D3,0x0D4,
|
||||
0x069,0x06E,0x067,0x060,0x075,0x072,0x07B,0x07C,0x051,0x056,0x05F,0x058,0x04D,0x04A,0x043,0x044,
|
||||
0x019,0x01E,0x017,0x010,0x005,0x002,0x00B,0x00C,0x021,0x026,0x02F,0x028,0x03D,0x03A,0x033,0x034,
|
||||
0x04E,0x049,0x040,0x047,0x052,0x055,0x05C,0x05B,0x076,0x071,0x078,0x07F,0x06A,0x06D,0x064,0x063,
|
||||
0x03E,0x039,0x030,0x037,0x022,0x025,0x02C,0x02B,0x006,0x001,0x008,0x00F,0x01A,0x01D,0x014,0x013,
|
||||
0x0AE,0x0A9,0x0A0,0x0A7,0x0B2,0x0B5,0x0BC,0x0BB,0x096,0x091,0x098,0x09F,0x08A,0x08D,0x084,0x083,
|
||||
0x0DE,0x0D9,0x0D0,0x0D7,0x0C2,0x0C5,0x0CC,0x0CB,0x0E6,0x0E1,0x0E8,0x0EF,0x0FA,0x0FD,0x0F4,0x0F3 };
|
||||
//;---------------------------------------------------------------------------------------------
|
||||
//;8λCRCУ<43><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//;dataLen:У<><D0A3><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>dataPoint:<3A><>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ(LSB)
|
||||
//;CRC_CODE:CRCУ<43><D0A3><EFBFBD><EFBFBD>
|
||||
//;---------------------------------------------------------------------------------------------
|
||||
/******************************************************************************/
|
||||
u8 CRC8(u8 *ucDptr, u8 ucLen)
|
||||
{
|
||||
u8 ucIndex; // CRC8У<38><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
u8 ucCRC8 = 0; // CRC8<43>ֽڳ<D6BD>ʼ<EFBFBD><CABC>
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>CRC8λУ<CEBB><D0A3>
|
||||
while(ucLen--)
|
||||
{
|
||||
ucIndex = ucCRC8 ^ (*ucDptr++);
|
||||
ucCRC8 = CRC_TABLE[ucIndex];
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>CRC8У<38><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return (~ucCRC8);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
u16 SlowCRC16(u16 sum, u32 codeAdr, u16 Len) //<2F><>ȡCRC
|
||||
{
|
||||
// while(Len--)
|
||||
// {
|
||||
// u16 I;
|
||||
//
|
||||
// u8 CByte = __data20_read_char(codeAdr++);
|
||||
//
|
||||
// for(I = 0; I<8; ++I)
|
||||
// {
|
||||
// u32 osum = sum;
|
||||
// sum <<= 1;
|
||||
// if(CByte & 0x80) sum |= 1;
|
||||
// if(osum & 0x8000) sum ^= CRC16_POLY;
|
||||
// CByte <<= 1;
|
||||
// }
|
||||
//
|
||||
// Clear_WDT();
|
||||
// }
|
||||
|
||||
// while(Len--)
|
||||
// {
|
||||
// sum = sum ^ ((u16)__data20_read_char(codeAdr++) << 8u);
|
||||
// for(u16 I = 0u; I < 8u; I++)
|
||||
// {
|
||||
// if((sum & 0x8000u) == 0x8000)
|
||||
// {
|
||||
// sum = (sum << 1u) ^ CRC16_POLY;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sum <<= 1u;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Clear_WDT();
|
||||
// }
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u8 CRC8_Talbe_I2CWord(u16 Data)
|
||||
{
|
||||
u8 crc8 = 0;
|
||||
u8 Temp;
|
||||
TypeWord wtData;
|
||||
|
||||
wtData.Word = Data;
|
||||
|
||||
Temp = crc8^wtData.Byte[1];
|
||||
crc8 = CRC_TABLE[Temp];
|
||||
Temp = crc8^wtData.Byte[0];
|
||||
crc8 = CRC_TABLE[Temp];
|
||||
|
||||
return crc8;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u8 I2CWordCrc(u8 crcH, u8 crcL)
|
||||
{
|
||||
u8 crc8 = 0;
|
||||
|
||||
crc8 = crc8 ^ crcH;
|
||||
crc8 = CRC_TABLE[ crc8 ];
|
||||
crc8 = crc8 ^ crcL;
|
||||
crc8 = CRC_TABLE[ crc8 ];
|
||||
|
||||
return crc8;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CodeCheckCRC(void)
|
||||
{
|
||||
// u16 sumAdr;
|
||||
// extern const u16 __checksum;
|
||||
//
|
||||
// // Check update program code
|
||||
// softCRCCode = __checksum;
|
||||
//
|
||||
// // <20><>ȡ CHECKSUM <20><>ַ
|
||||
// // У<><D0A3><EFBFBD><EFBFBD>һ<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD>
|
||||
// sumAdr = (u16)&__checksum; // <20><>ȡ CHECKSUM <20><>ַ
|
||||
// CodeCRC = SlowCRC16(CRC16_INIT_VAL, (u32)APP_CODE1_START, (u16)(sumAdr-APP_CODE1_START));
|
||||
// sumAdr += 2;
|
||||
// CodeCRC = SlowCRC16(CodeCRC, (u32)sumAdr, (u16)(APP_CODE1_END-sumAdr+1));
|
||||
//
|
||||
// // BootLoader<65><72><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
// // У<><D0A3><EFBFBD>ڶ<EFBFBD><DAB6>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CodeCRC = SlowCRC16(CodeCRC, (u32)APP_CODE2_START, (u16)(APP_CODE2_END-APP_CODE2_START+1));
|
||||
// // <20><><EFBFBD><EFBFBD>CHECKSUM
|
||||
// //CodeCRC = SlowCRC16(CodeCRC, (u32)&area, 2);
|
||||
//
|
||||
// CodeCRC = (CodeCRC == __checksum) ? 0 : 0xAA55;
|
||||
}
|
||||
12
user/Utility/CRC.h
Executable file
12
user/Utility/CRC.h
Executable file
@@ -0,0 +1,12 @@
|
||||
#ifndef __CRC_h__
|
||||
#define __CRC_h__
|
||||
|
||||
#define CRC16_POLY 0x1021;
|
||||
#define CRC16_INIT_VAL 0
|
||||
|
||||
//**************************************************************************************************
|
||||
u8 CRC8(u8 *ucDptr, u8 ucLen);
|
||||
u16 SlowCRC16(u16 sum, u32 codeAdr, u16 Len);
|
||||
u8 CRC8_Talbe_I2CWord(u16 Data);
|
||||
u8 I2CWordCrc(u8 crcH, u8 crcL);
|
||||
#endif
|
||||
77
user/Utility/delay.c
Executable file
77
user/Utility/delay.c
Executable file
@@ -0,0 +1,77 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
#include "delay.h"
|
||||
|
||||
void delay_ms(u16 ms)
|
||||
{
|
||||
u16 temp;
|
||||
|
||||
for (; ms > 0; ms--)
|
||||
{
|
||||
#if LOOP_1000US < 65535
|
||||
for (temp = (u16)LOOP_1000US; temp > 0; temp--){
|
||||
__NOP();
|
||||
}
|
||||
#if DELTA_1000US > 0
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_1000US > 1
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_1000US > 2
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_1000US > 3
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_1000US > 4
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_1000US > 5
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Clear_WDT();
|
||||
delay_10us(100);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void delay_10us(u16 us)
|
||||
{
|
||||
u16 temp;
|
||||
|
||||
for (; us > 0; us--)
|
||||
{
|
||||
for (temp = (u16)LOOP_10US; temp > 0; temp--);
|
||||
|
||||
#if DELTA_10US > 0
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_10US > 1
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_10US > 2
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_10US > 3
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_10US > 4
|
||||
__NOP();
|
||||
#endif
|
||||
|
||||
#if DELTA_10US > 5
|
||||
__NOP();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
30
user/Utility/delay.h
Executable file
30
user/Utility/delay.h
Executable file
@@ -0,0 +1,30 @@
|
||||
#ifndef __delay_h__
|
||||
#define __delay_h__
|
||||
|
||||
#define LOOP_BODY 20 //7 //for (iq0 = ms; iq0 > 0; iq0--)
|
||||
#define WDT_CYCLE 0 //19 //clear_WDT();
|
||||
#define LOOP_INIT 1//4 //for (iq1 = LOOP_1MS;
|
||||
#define LOOP_CYCLE 40//14 //6//4 //iq1 > 0; iq1--) // LOOPCNT
|
||||
#define LOOP_JUDGE 5//3 //iq1 > 0;
|
||||
#define LOOP_DEC 1 //iq0--
|
||||
|
||||
#define DELAY_FREQ 55400000//FREQ //4M
|
||||
|
||||
#define US10_CYCLE (DELAY_FREQ/100000) // 10us CYCLE
|
||||
#define TOTAL_CYCLE_10US (US10_CYCLE-LOOP_BODY)
|
||||
#define LOOP_10US (TOTAL_CYCLE_10US/LOOP_CYCLE)
|
||||
#define DELTA_10US (TOTAL_CYCLE_10US-(LOOP_10US*LOOP_CYCLE))
|
||||
|
||||
#define US100_CYCLE (DELAY_FREQ/10000) // 100us CYCLE
|
||||
#define TOTAL_CYCLE_100US (US100_CYCLE-LOOP_BODY)
|
||||
#define LOOP_100US (TOTAL_CYCLE_100US/LOOP_CYCLE)
|
||||
#define DELTA_100US (TOTAL_CYCLE_100US-(LOOP_100US*LOOP_CYCLE))
|
||||
|
||||
#define US1000_CYCLE (DELAY_FREQ/1000) // 100us CYCLE
|
||||
#define TOTAL_CYCLE_1000US (US1000_CYCLE-LOOP_BODY)
|
||||
#define LOOP_1000US (TOTAL_CYCLE_1000US/LOOP_CYCLE)
|
||||
#define DELTA_1000US (TOTAL_CYCLE_1000US-(LOOP_1000US*LOOP_CYCLE))
|
||||
|
||||
void delay_ms(u16 ms);
|
||||
void delay_10us(u16 us);
|
||||
#endif
|
||||
74
user/Utility/filter.c
Executable file
74
user/Utility/filter.c
Executable file
@@ -0,0 +1,74 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//==============================================================================
|
||||
|
||||
//u16 L;
|
||||
u16 SAMPLES[ANX][FILTER_ANX];
|
||||
//u16 tempV, *filterPointer, tempMax=0, tempMin=0xffff;
|
||||
|
||||
//******************************************************************************
|
||||
u16 ReadDataFromMovingAverage(u16 channel)
|
||||
{
|
||||
u16 L;
|
||||
u32 voltageSum;
|
||||
|
||||
// calculate voltageSum
|
||||
voltageSum = 0;
|
||||
//for (L = 1; L <= FILTER_SIZE; L++) voltageSum += (u32)SAMPLES[channel][L];
|
||||
//voltageSum /= (u32)FILTER_SIZE;
|
||||
|
||||
for (L = 0; L < FILTER_ANX; L++) voltageSum += (u32)SAMPLES[channel][L];
|
||||
voltageSum /= (u32)FILTER_ANX;
|
||||
|
||||
return (u16)voltageSum;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u16 MovingAverage(u16 voltageBuffer, u16 updateScale, u16 channel)
|
||||
{
|
||||
u16 L, tempV, *filterPointer, tempMax=0, tempMin=0xffff;
|
||||
u16 voltageFilter;
|
||||
u32 voltageSum;
|
||||
|
||||
voltageFilter = SAMPLES[channel][FILTER_END];
|
||||
voltageSum = (u32)voltageFilter; //
|
||||
voltageSum *= (u32)updateScale; //
|
||||
updateScale = (u16)(voltageSum >> 9); //
|
||||
if(voltageBuffer > voltageFilter) tempV = voltageBuffer - voltageFilter; //
|
||||
else tempV = voltageFilter - voltageBuffer; //
|
||||
|
||||
if(tempV > updateScale)
|
||||
{
|
||||
filterPointer = &SAMPLES[channel][0];
|
||||
for (L = 0; L <= FILTER_END; L++) *filterPointer++ = voltageBuffer;
|
||||
return voltageBuffer ;
|
||||
}
|
||||
|
||||
filterPointer = &SAMPLES[channel][1];
|
||||
voltageSum = 0;
|
||||
for (L = 1; L <= FILTER_END; L++)
|
||||
{
|
||||
voltageFilter = *filterPointer;
|
||||
filterPointer--;
|
||||
*filterPointer = voltageFilter;
|
||||
filterPointer += 2;
|
||||
voltageSum += (u32)voltageFilter;
|
||||
|
||||
if(voltageFilter > tempMax) tempMax = voltageFilter;
|
||||
if(voltageFilter < tempMin) tempMin = voltageFilter;
|
||||
}
|
||||
|
||||
SAMPLES[channel][FILTER_END] = voltageBuffer;
|
||||
voltageSum += (u32)voltageBuffer;
|
||||
|
||||
if(voltageBuffer > tempMax) tempMax = voltageBuffer;
|
||||
if(voltageBuffer < tempMin) tempMin = voltageBuffer;
|
||||
voltageSum -= (u32)tempMax;
|
||||
voltageSum -= (u32)tempMin;
|
||||
voltageSum >>= FILTER_SHIFT;
|
||||
|
||||
return (u16)voltageSum ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
21
user/Utility/filter.h
Executable file
21
user/Utility/filter.h
Executable file
@@ -0,0 +1,21 @@
|
||||
#ifndef __filter_h__
|
||||
#define __filter_h__
|
||||
|
||||
// filter specifications: removing largest and smallest samples
|
||||
#define FILTER_SIZE 2 // size of digital filter
|
||||
#define FILTER_SHIFT 1
|
||||
#define FILTER_END (FILTER_SIZE+1)
|
||||
#define FILTER_ANX (FILTER_SIZE+2)
|
||||
|
||||
// DELTA filter
|
||||
#define DELTA_FILTER_SIZE 4 // size of digital filter
|
||||
#define DELTA_FILTER_SHIFT 2
|
||||
#define DELTA_FILTER_END (DELTA_FILTER_SIZE-1)
|
||||
#define DELTA_TIME_ANX (DELTA_FILTER_SIZE+1)
|
||||
|
||||
extern u16 SAMPLES[][FILTER_ANX];
|
||||
|
||||
u16 ReadDataFromMovingAverage(u16 channel);
|
||||
u16 MovingAverage(u16 voltageBuffer, u16 updateScale, u16 channel);
|
||||
|
||||
#endif
|
||||
73
user/Utility/icclbutl.h
Executable file
73
user/Utility/icclbutl.h
Executable file
@@ -0,0 +1,73 @@
|
||||
/* - ICCLBUTL.H -
|
||||
|
||||
Low-level declarations for non-ANSI functions
|
||||
used by the C library.
|
||||
|
||||
$Revision: 38615 $
|
||||
|
||||
Copyright 1986 - 1999 IAR Systems. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef _ICCLBUTL_INCLUDED
|
||||
#define _ICCLBUTL_INCLUDED
|
||||
|
||||
#ifndef _SYSTEM_BUILD
|
||||
#pragma system_include
|
||||
#endif
|
||||
|
||||
#include "sysmac.h"
|
||||
#include "stdarg.h"
|
||||
|
||||
/*-----------------------------------------*/
|
||||
/* Formatters used by "scanf" and "sscanf" */
|
||||
/*-----------------------------------------*/
|
||||
#if __IAR_SYSTEMS_ICC__ < 2
|
||||
#if __TID__ & 0x8000
|
||||
#pragma function=intrinsic(0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MEMORY_ATTRIBUTE
|
||||
#define MEMORY_ATTRIBUTE
|
||||
#endif
|
||||
|
||||
/* Full ANSI (parameters are line, format, ap) */
|
||||
__INTRINSIC MEMORY_ATTRIBUTE int _formatted_read(const char **,
|
||||
const char **,
|
||||
va_list);
|
||||
|
||||
/* Without floating point */
|
||||
__INTRINSIC MEMORY_ATTRIBUTE int _medium_read(const char **,
|
||||
const char **,
|
||||
va_list);
|
||||
|
||||
|
||||
/*-------------------------------------------*/
|
||||
/* Formatters used by "printf" and "sprintf" */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
/* Full ANSI (parameters are format, output-function, secret-pointer, ap) */
|
||||
__INTRINSIC MEMORY_ATTRIBUTE int _formatted_write(const char *,
|
||||
void (*)(char, void *),
|
||||
void *,
|
||||
va_list);
|
||||
|
||||
/* Without floating point */
|
||||
__INTRINSIC MEMORY_ATTRIBUTE int _medium_write(const char *,
|
||||
void (*)(char, void *),
|
||||
void *,
|
||||
va_list);
|
||||
|
||||
/* Very reduced version */
|
||||
__INTRINSIC MEMORY_ATTRIBUTE int _small_write(const char *,
|
||||
void (*)(char, void *),
|
||||
void *,
|
||||
va_list);
|
||||
|
||||
#if __IAR_SYSTEMS_ICC__ < 2
|
||||
#if __TID__ & 0x8000
|
||||
#pragma function=default
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
113
user/Utility/user_math.c
Executable file
113
user/Utility/user_math.c
Executable file
@@ -0,0 +1,113 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
TypeSecondary Secondary;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BCD<43><44><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>,ÿ<><C3BF><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><F3B6BCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λLSD+3<>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>7,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3,<2C><><EFBFBD><EFBFBD>,<2C><>4λMSD<53><44>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
||||
//void ConvertWordHEXToBCD(u16 convertHex)
|
||||
//{
|
||||
//u32 convertHex;
|
||||
// for(I=0; I<16; I++)
|
||||
// {
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
u8 BCDToHEX(u8 BCDBuffer)
|
||||
{
|
||||
return (((BCDBuffer & 0xf0)>>4)*10 + (BCDBuffer & 0x0f));
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 HEXToBCD(u8 HEXBuffer)
|
||||
{
|
||||
u16 tempBCD;
|
||||
|
||||
tempBCD = HEXBuffer/100;
|
||||
HEXBuffer -= tempBCD * 100;
|
||||
tempBCD <<= 4;
|
||||
tempBCD |= HEXBuffer / 10;
|
||||
HEXBuffer -= (tempBCD & 0x000f) * 10;
|
||||
tempBCD <<= 4;
|
||||
tempBCD |= HEXBuffer;
|
||||
|
||||
return tempBCD;
|
||||
//return ((((u16)HEXBuffer / 100) << 8) | ((HEXBuffer / 10) << 4) | (HEXBuffer % 10));
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ConvertHEXToBCDArray(u32 convertHex, u8 *resultPointer, u16 covertLen, u16 order)
|
||||
{
|
||||
u16 I;
|
||||
s16 adrBuf;
|
||||
u32 covertBuf;
|
||||
|
||||
if(order == LOW_FIRST) adrBuf = 1;
|
||||
else
|
||||
{
|
||||
resultPointer += covertLen-1;
|
||||
adrBuf = -1;
|
||||
}
|
||||
|
||||
for(I=0; I<covertLen; I++)
|
||||
{
|
||||
covertBuf = convertHex / (u32)10;
|
||||
*resultPointer = (u8)(convertHex-covertBuf*10);
|
||||
convertHex = covertBuf;
|
||||
|
||||
resultPointer += adrBuf;
|
||||
//if(order == LOW_FIRST) resultPointer++;
|
||||
//else resultPointer--;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
s32 SecondaryCompute(void)
|
||||
{
|
||||
f32 fTemp;
|
||||
|
||||
tmpSLA = (s32)Secondary.ValueH;
|
||||
tmpSLA -= (s32)Secondary.ValueL;
|
||||
fTemp = (float)tmpSLA;
|
||||
|
||||
tmpSLB = Secondary.NodeX;
|
||||
tmpSLB -= Secondary.NodeL;
|
||||
//tmpSLA *= tmpSLB;
|
||||
fTemp *= (float)tmpSLB;
|
||||
|
||||
tmpSLB = Secondary.NodeH;
|
||||
tmpSLB -= Secondary.NodeL;
|
||||
//tmpSLA /= tmpSLB;
|
||||
if(tmpSLB != 0) fTemp /= (float)tmpSLB;
|
||||
else return 0;
|
||||
|
||||
tmpSLA = (s32)fTemp;
|
||||
tmpSLA += (s32)Secondary.ValueL;
|
||||
|
||||
//if(tmpSLA < 0) return 0;
|
||||
//else return (u16)tmpSLA;
|
||||
return tmpSLA;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD>봦<EFBFBD><EBB4A6>-------------------------------------------------------------
|
||||
u16 WordSubFunction(u16 minuend, u16 subtractor)
|
||||
{
|
||||
u16 subResult;
|
||||
|
||||
subResult = minuend - subtractor;
|
||||
if(minuend >= subtractor)
|
||||
{
|
||||
if(subResult < 32768) subResult += 32768;
|
||||
else subResult = 65535;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(subResult < 32768) subResult = 0;
|
||||
else subResult -= 32768;
|
||||
}
|
||||
|
||||
return subResult;
|
||||
}
|
||||
28
user/Utility/user_math.h
Executable file
28
user/Utility/user_math.h
Executable file
@@ -0,0 +1,28 @@
|
||||
#ifndef __usser_math_h__
|
||||
#define __usser_math_h__
|
||||
|
||||
#define LOW_FIRST 0
|
||||
#define HIGH_FIRST 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 NodeX;
|
||||
u32 NodeH;
|
||||
u32 NodeL;
|
||||
u16 ValueH;
|
||||
u16 ValueL;
|
||||
} TypeSecondary;
|
||||
|
||||
extern TypeSecondary Secondary;
|
||||
|
||||
u8 BCDToHEX(u8 BCDBuffer);
|
||||
u16 HEXToBCD(u8 HEXBuffer);
|
||||
u16 HexCharToBCD(u8 BCDBuffer);
|
||||
u32 HexWORDToBCD(u16 BCDBuffer);
|
||||
u64 HexLongToBCD(u32 BCDBuffer);
|
||||
u64 HexLongLongToBCD(u64 BCDBuffer);
|
||||
void ConvertHEXToBCDArray(u32 convertHex, u8 *resultPointer, u16 covertLen, u16 order);
|
||||
u32 HexWORDToBCD(u16 BCDBuffer);
|
||||
s32 SecondaryCompute(void);
|
||||
u16 WordSubFunction(u16 minuend, u16 subtractor);
|
||||
#endif
|
||||
31
user/Utility/user_stdio.c
Executable file
31
user/Utility/user_stdio.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//#include "icclbutl.h"
|
||||
//#include "user_stdio.h"
|
||||
|
||||
u16 TXDMode;
|
||||
|
||||
//void put_one_char(char c, void *dummy)
|
||||
//{
|
||||
// if(TXDMode == ENABLE_TXD_USE_DMA) RxdData[TX_Length++] = c;
|
||||
// else putc (c);
|
||||
// (void)dummy; /* Warning on this line OK (Optimized Away) */
|
||||
//}
|
||||
|
||||
int putchar(int ch)
|
||||
{
|
||||
if(TXDMode == ENABLE_TXD_USE_DMA) RxdData[TX_Length++] = ch;
|
||||
else putc (ch);
|
||||
return (ch);
|
||||
}
|
||||
|
||||
//int printf(const char *format, ...)
|
||||
//{
|
||||
// va_list ap;
|
||||
// int nr_of_chars;
|
||||
//
|
||||
// va_start(ap, format); // Variable argument begin
|
||||
// nr_of_chars = _formatted_write(format, put_one_char, (void *) 0, ap);
|
||||
// va_end(ap); // Variable argument end
|
||||
//
|
||||
// return nr_of_chars; // According to ANSI
|
||||
//}
|
||||
8
user/Utility/user_stdio.h
Executable file
8
user/Utility/user_stdio.h
Executable file
@@ -0,0 +1,8 @@
|
||||
#ifndef __user_stdio
|
||||
#define __user_stdio
|
||||
|
||||
extern u16 TXDMode;
|
||||
|
||||
void put_one_char(char c, void *dummy);
|
||||
int printf(const char *format, ...);
|
||||
#endif
|
||||
Reference in New Issue
Block a user