sop板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

85 lines
3.0 KiB

#ifndef APP_COMMON_H
#define APP_COMMON_H
#include "../clib/type.h"
#include "../bsp/bsp_config.h"
#define APP_VERSION 0x10
#define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
#define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
//STEP 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Register CONFIG
//寄存器编号从1开始
//#define D_COUNT_WEIGHT(adc) (U32)(1000.0 * R.p.weight_max * (adc) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd))
//#define D_blur_threshold_2_1(threshold) (U32) ( 1.0 * threshold *(2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd) / (1000.0 * R.p.weight_max ))
#define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
#define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
#define ADC_status_chx_Ready_BASE 0x01
#define ADC_status_ch1_Ready 0x01
#define ADC_status_ch2_Ready 0x02
#define ADC_status_ch3_Ready 0x04
#define ADC_status_ch4_Ready 0x08
#define D_ADC_CHANNEL_NUM 4
typedef struct global_register
{
//RO Register
U16 reserved1;
U32 total_weight; //净重(显示重量)*100
U32 total_zweight; //皮重*100
//RW Register
U16 reserved2;
U16 zero; //清0标志,写入任何值清0(去皮)
U16 status_eep_save; //eep写入寄存器,1则写入eep并清0
//U16 reset; //reset标志,写入任何值,所有参数恢复初始值
struct
{ //需要持久化的参数,不能超过72字节,否则会导致eeprom溢出
U16 slaver_id;
U16 adc_ch_status;
U16 weight_max; //量程
U16 lmd; //2mv/v
U16 adc_blur_mid; //中值滤波
U16 adc_blur_avg; //均值滤波
U16 adc_blur_shift[3]; //移位滤波点数
U16 adc_blur_threshold[2]; //移位滤波阀值
}p;
U16 reserved3;
U32 adval[D_ADC_CHANNEL_NUM]; //4路重量
U32 ch_weight[D_ADC_CHANNEL_NUM]; //4路重量
U32 rough_weight; // 毛重
}GlobalRegister;
extern GlobalRegister R;
//寄存器内存基地址
#define REG_MEM_BASE ((U16*)(&R)) //寄存器基础地址(本文件外部不应该使用该宏定义)
//变量地址转寄存器
#define MEM_2_REG(mem) (((U16*)(mem) - REG_MEM_BASE) + 1)
//寄存器转变量地址
#define REG_2_MEM(reg) (REG_MEM_BASE + (U16)((reg) - 1))
//STEP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Register CONFIG End
//STEP 2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Global Variables CONFIG
typedef struct global_param
{
U8 xx;
}GlobalParam;
extern struct global_param G;
//STEP 2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Global Variables CONFIG End
extern void L3_param_init(void);
extern void L3_reg_2_iap(void);
extern void L3_iap_2_reg(void);
extern void L3_reg_reset(void);
extern void L3_reg_init(void);
#endif