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.
232 lines
4.9 KiB
232 lines
4.9 KiB
#include "app_config.h"
|
|
#include "../bsp/cs1232.h"
|
|
#include "../bsp/chipid.h"
|
|
#include "../bsp/bsp_rfid.h"
|
|
#include "../msp/eeprom.h"
|
|
|
|
GlobalParam G;
|
|
GlobalRegister R;
|
|
int i;
|
|
|
|
// void L3_param_init(void)
|
|
// {
|
|
// #if 0
|
|
// G.xx = 0;
|
|
// //L3_eeprom_read_param();
|
|
// #endif
|
|
// }
|
|
|
|
|
|
//读取reg内容,写入iap
|
|
// void L3_reg_2_iap(void)
|
|
// {
|
|
// #if 0
|
|
// iapData.slaver_id = R.p.slaver_id;
|
|
// iapData.adc_ch_status = R.p.adc_ch_status;
|
|
// iapData.weight_max = R.p.weight_max;
|
|
// iapData.lmd = R.p.lmd;
|
|
// iapData.adc_blur_mid = R.p.adc_blur_mid;
|
|
// iapData.adc_blur_avg = R.p.adc_blur_avg;
|
|
// iapData.adc_blur_shift[0] = R.p.adc_blur_shift[0];
|
|
// iapData.adc_blur_shift[1] = R.p.adc_blur_shift[1];
|
|
// iapData.adc_blur_shift[2] = R.p.adc_blur_shift[2];
|
|
// iapData.adc_blur_threshold[0] = R.p.adc_blur_threshold[0];
|
|
// iapData.adc_blur_threshold[1] = R.p.adc_blur_threshold[1];
|
|
// //写入eeprom
|
|
// if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData,sizeof(IapData),TRUE) == 0)
|
|
// {
|
|
// L0_uart0_sendstr("e2p write success");
|
|
// }
|
|
// #endif
|
|
// if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p,sizeof(R.p),TRUE) == 0)
|
|
// {
|
|
// L0_uart0_sendstr("e2p write success");
|
|
// return;
|
|
// }
|
|
// L0_uart0_sendstr("e2p write failed");
|
|
// }
|
|
|
|
// //读取iap内容,写入reg
|
|
// void L3_iap_2_reg(void)
|
|
// {
|
|
// #if 0
|
|
// if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData, NULL) == 1)
|
|
// {
|
|
// L0_uart0_sendstr("e2p read failed");
|
|
// }
|
|
// L0_uart0_sendstr("e2p read success");
|
|
// R.p.slaver_id = iapData.slaver_id;
|
|
// R.p.adc_ch_status = iapData.adc_ch_status;
|
|
// R.p.weight_max = iapData.weight_max ;
|
|
// R.p.lmd = iapData.lmd;
|
|
// R.p.adc_blur_mid = iapData.adc_blur_mid;
|
|
// R.p.adc_blur_avg = iapData.adc_blur_avg;
|
|
// R.p.adc_blur_shift[0] = iapData.adc_blur_shift[0];
|
|
// R.p.adc_blur_shift[1] = iapData.adc_blur_shift[1];
|
|
// R.p.adc_blur_shift[2] = iapData.adc_blur_shift[2];
|
|
// R.p.adc_blur_threshold[0] = iapData.adc_blur_threshold[0];
|
|
// R.p.adc_blur_threshold[1] = iapData.adc_blur_threshold[1];
|
|
// #endif
|
|
// if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p, NULL) == 0)
|
|
// {
|
|
// L0_uart0_sendstr("e2p read success");
|
|
// return;
|
|
// }
|
|
// L0_uart0_sendstr("e2p read failed");
|
|
// }
|
|
|
|
void L3_reg_reset(void)
|
|
{
|
|
//设置RFID对照表
|
|
for(i=0; i<LED_BTN_NUM; i++)
|
|
{
|
|
R.rfid_table[i] = 0x0000 + i;
|
|
}
|
|
|
|
//sop板默认不需要授权、未授权
|
|
R.auth_flag = (0<<4) | 0;
|
|
// R.auth_flag = (0<<4) | 0x01;
|
|
|
|
//从机ID
|
|
R.slave_id = 0x03;
|
|
|
|
//功耗模式:正常模式
|
|
R.power_mode = POWER_NORMAL;
|
|
|
|
//功能按键按下状态
|
|
R.func_btn = 0;
|
|
|
|
//设置led灯状态
|
|
L3_led_clear();
|
|
|
|
//nfc编号
|
|
L3_nfc_clear();
|
|
|
|
//4路RFID编号
|
|
L3_rfid_clear();
|
|
|
|
//for test
|
|
// R.slave_id = 0x01;
|
|
// R.power_mode = 0;
|
|
// R.func_btn = 1;
|
|
// R.nfc.nfc_no[0] = 0x01;
|
|
// R.nfc.nfc_no[1] = 0x23;
|
|
// for(i=0;i<4;i++){
|
|
// R.rfids[i].rfid_no[0] = 0xA0;
|
|
// R.rfids[i].rfid_no[1] = 0xB0;
|
|
// R.rfids[i].rssi = 0x61;
|
|
// R.rfids[i].ant = i;
|
|
// };
|
|
}
|
|
|
|
void L3_led_clear(void)
|
|
{
|
|
//设置led灯状态
|
|
for(i=0; i<LED_BTN_NUM; i++)
|
|
{
|
|
R.led_status[i] = 0;
|
|
}
|
|
R.led_status[0] = 1;
|
|
}
|
|
|
|
void L3_nfc_clear(void)
|
|
{
|
|
R.nfc.nfc_no[0] = 0;
|
|
R.nfc.nfc_no[1] = 0;
|
|
}
|
|
|
|
void L3_rfid_clear(void)
|
|
{
|
|
for(i=0; i<4; i++)
|
|
{
|
|
R.rfids[i].rfid_no[0] = 0;
|
|
R.rfids[i].rfid_no[1] = 0;
|
|
R.rfids[i].rssi = 0;
|
|
R.rfids[i].ant = 0;
|
|
};
|
|
}
|
|
|
|
void L3_reg_init(void)
|
|
{
|
|
L3_reg_reset();
|
|
//L3_iap_2_reg();
|
|
}
|
|
|
|
U8 L3_new_rfid_1(U16 rfidno, U8 rssi, U8 ant)
|
|
{
|
|
U8 i = 0;
|
|
for(i=0; i<4; i++)
|
|
{
|
|
if(R.rfids[i].rfid_no[0] == 0 && R.rfids[i].rfid_no[1] == 0)
|
|
{
|
|
//空位置
|
|
R.rfids[i].rfid_no[0] = rfidno >> 8 & 0xFF;
|
|
R.rfids[i].rfid_no[1] = rfidno >> 0 & 0xFF;
|
|
R.rfids[i].rssi = rssi;
|
|
R.rfids[i].ant = ant;
|
|
return 1;
|
|
}
|
|
if(R.rfids[i].rfid_no[0] == (rfidno >> 8 & 0xFF) && R.rfids[i].rfid_no[1] == (rfidno >> 0 & 0xFF))
|
|
{
|
|
//该rfid已经存在
|
|
break;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
U8 L3_new_rfid(U16 rfidno, U8 rssi, U8 ant)
|
|
{
|
|
U8 i = 0;
|
|
for(i=0; i<RFID_BUF_NUM; i++)
|
|
{
|
|
if(R.rfids[i].rfid_no[0] == 0 && R.rfids[i].rfid_no[1] == 0)
|
|
{
|
|
//空位置
|
|
break;
|
|
}
|
|
if(R.rfids[i].rfid_no[0] == (rfidno >> 8 & 0xFF) && R.rfids[i].rfid_no[1] == (rfidno >> 0 & 0xFF))
|
|
{
|
|
//该rfid已经存在
|
|
break;
|
|
}
|
|
}
|
|
if(i == RFID_BUF_NUM)
|
|
{
|
|
i = 0;
|
|
}
|
|
|
|
//放入RFID(空位置、已存在位置[替换为最新的rssi和ant]、0位置[放满了就从头开始放)
|
|
R.rfids[i].rfid_no[0] = rfidno >> 8 & 0xFF;
|
|
R.rfids[i].rfid_no[1] = rfidno >> 0 & 0xFF;
|
|
R.rfids[i].rssi = rssi;
|
|
R.rfids[i].ant = ant;
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
U8 L3_find_rfid_table(U16 rfidno)
|
|
{
|
|
for(i=0; i<LED_BTN_NUM; i++)
|
|
{
|
|
if(rfidno == R.rfid_table[i])
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return LED_BTN_NUM;
|
|
}
|
|
|
|
extern void L3_task_rfid_init(void);
|
|
|
|
void L3_set_power_mode(U8 mode)
|
|
{
|
|
// if(R.power_mode == POWER_NORMAL)
|
|
// {
|
|
// if(mode == POWER_LOW)
|
|
// {
|
|
// }
|
|
// }
|
|
R.power_mode = mode;
|
|
}
|