提交中控板V2.1源码 zsxfly20240819
This commit is contained in:
parent
c3b26ab592
commit
91135a05fe
|
@ -15,13 +15,13 @@
|
|||
|
||||
#if !defined(DBG_UART_BAUD)
|
||||
#if (SYS_CLK == 1)
|
||||
#define DBG_UART_BAUD BRR_DIV(115200, 32M)
|
||||
#define DBG_UART_BAUD BRR_DIV(9600, 32M)
|
||||
#elif (SYS_CLK == 2)
|
||||
#define DBG_UART_BAUD BRR_DIV(115200, 48M)
|
||||
#define DBG_UART_BAUD BRR_DIV(9600, 48M)
|
||||
#elif (SYS_CLK == 3)
|
||||
#define DBG_UART_BAUD BRR_DIV(115200, 64M)
|
||||
#define DBG_UART_BAUD BRR_DIV(9600, 64M)
|
||||
#else
|
||||
#define DBG_UART_BAUD (BRR_115200)
|
||||
#define DBG_UART_BAUD BRR_DIV(9600, 16M)
|
||||
#endif //SYS_CLK
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -379,8 +379,8 @@
|
|||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\app_buzzer.c</PathWithFileName>
|
||||
<FilenameWithoutPath>app_buzzer.c</FilenameWithoutPath>
|
||||
<PathWithFileName>..\src\app_bat.c</PathWithFileName>
|
||||
<FilenameWithoutPath>app_bat.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
@ -391,8 +391,44 @@
|
|||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\app_bat.c</PathWithFileName>
|
||||
<FilenameWithoutPath>app_bat.c</FilenameWithoutPath>
|
||||
<PathWithFileName>..\..\..\modules\src\CRCxx.c</PathWithFileName>
|
||||
<FilenameWithoutPath>CRCxx.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\app_PAD.c</PathWithFileName>
|
||||
<FilenameWithoutPath>app_PAD.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\app_Time_Event.c</PathWithFileName>
|
||||
<FilenameWithoutPath>app_Time_Event.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\sys_config.c</PathWithFileName>
|
||||
<FilenameWithoutPath>sys_config.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
@ -400,13 +436,13 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>drivers\src</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -418,7 +454,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -430,7 +466,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -442,7 +478,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -454,7 +490,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -466,7 +502,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -478,7 +514,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -490,7 +526,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -502,7 +538,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -514,7 +550,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -526,7 +562,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -538,7 +574,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -550,7 +586,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -562,7 +598,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -574,7 +610,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -586,7 +622,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -598,7 +634,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -610,7 +646,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileType>4</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -630,7 +666,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -650,7 +686,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -670,7 +706,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -682,7 +718,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -694,7 +730,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -706,7 +742,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -718,7 +754,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -730,7 +766,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -750,7 +786,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>7</GroupNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileNumber>41</FileNumber>
|
||||
<FileType>4</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -770,7 +806,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileNumber>42</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -782,7 +818,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileNumber>43</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -431,16 +431,31 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\src\app_radar.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>app_buzzer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\app_buzzer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>app_bat.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\app_bat.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>CRCxx.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\modules\src\CRCxx.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>app_PAD.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\app_PAD.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>app_Time_Event.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\app_Time_Event.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>sys_config.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\sys_config.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
#include "b6x.h"
|
||||
#include "drvs.h"
|
||||
#include "dbg.h"
|
||||
#include "rbuf.h"
|
||||
#include "CRCxx.h"
|
||||
|
||||
#include "sys_config.h"
|
||||
|
||||
#include "app_PAD.h"
|
||||
|
||||
// 用于PAD通信处理
|
||||
|
||||
PAD_daraframe_t PAD_daraframe;
|
||||
volatile uint8_t Rec_state =0;
|
||||
volatile uint8_t Rec_data_cnt =0;
|
||||
|
||||
static void PAD_Data_Hande(void){
|
||||
uint8_t ret_data[MAX_LEN]={0,0};
|
||||
uint8_t length=0;
|
||||
|
||||
switch(PAD_daraframe.cmd_id){
|
||||
case 0x01: // 配置系统参数
|
||||
sys_conf.Manager_sLim= PAD_daraframe.data[0];
|
||||
sys_conf.Tourist_sLim= PAD_daraframe.data[1];
|
||||
sys_conf.Brake_DLimit= PAD_daraframe.data[2];
|
||||
sys_conf.Speed_Cut_DLimit= PAD_daraframe.data[3];
|
||||
sys_conf.Brake_DLimit_B= PAD_daraframe.data[4];
|
||||
sys_conf.Speed_Cut_DLimit_B= PAD_daraframe.data[5];
|
||||
write_cfg(&sys_conf);
|
||||
case 0x02: // 读取系统配置
|
||||
ret_data[length++]=sys_conf.Manager_sLim;
|
||||
ret_data[length++]=sys_conf.Tourist_sLim;
|
||||
ret_data[length++]=sys_conf.Brake_DLimit;
|
||||
ret_data[length++]=sys_conf.Speed_Cut_DLimit;
|
||||
ret_data[length++]=sys_conf.Brake_DLimit_B;
|
||||
ret_data[length++]=sys_conf.Speed_Cut_DLimit_B;
|
||||
|
||||
app_PAD_Sendcmd(PAD_daraframe.cmd_id,0x01,ret_data,length);
|
||||
break;
|
||||
case 0x03: //0 退出模式//1 进入游客模式//2 进入管理员模式
|
||||
sys_sta.Pmode = PAD_daraframe.data[0] & 0x03;
|
||||
app_PAD_Sendcmd(PAD_daraframe.cmd_id,0x01,PAD_daraframe.data,PAD_daraframe.length);
|
||||
break;
|
||||
case 0x04: //0 关闭12V输出//1 开启12V输出
|
||||
sys_sta.O_12V = PAD_daraframe.data[0];
|
||||
app_PAD_Sendcmd(PAD_daraframe.cmd_id,0x01,PAD_daraframe.data,PAD_daraframe.length);
|
||||
break;
|
||||
// case 0x04:
|
||||
|
||||
// break;
|
||||
|
||||
default :
|
||||
app_PAD_Sendcmd(PAD_daraframe.cmd_id,PAD_daraframe.reg_addr,PAD_daraframe.data,PAD_daraframe.length);
|
||||
break;
|
||||
/*
|
||||
其他功能....
|
||||
*/
|
||||
}
|
||||
Rec_state =0;//数据处理完要清零,准备接收下一帧数据
|
||||
}
|
||||
|
||||
void app_PAD_Receive(uint8_t data){
|
||||
uint8_t *frame = (uint8_t *)&PAD_daraframe;
|
||||
|
||||
switch(Rec_state){
|
||||
case 0://header
|
||||
if ((data == (uint8_t)(FRAME_HEADER >> 8)) && (PAD_daraframe.header == 0x0)) {
|
||||
PAD_daraframe.header = (FRAME_HEADER >> 8);
|
||||
} else if ((data == (uint8_t)(FRAME_HEADER & 0x00FF)) && (PAD_daraframe.header == (uint8_t)(FRAME_HEADER >> 8))) {
|
||||
PAD_daraframe.header = ((uint16_t)((FRAME_HEADER << 8)|(FRAME_HEADER >> 8)));//0xA100;
|
||||
PAD_daraframe.length = 0;
|
||||
Rec_state = 1;//to cmd id
|
||||
//debug("header");
|
||||
}
|
||||
break;
|
||||
case 1://cmd_id
|
||||
//debug("rxcmd:%x", data);
|
||||
PAD_daraframe.cmd_id = data;
|
||||
Rec_state = 2;//to device addr
|
||||
break;
|
||||
case 2://reg addr
|
||||
//debug("reg_addr");
|
||||
PAD_daraframe.reg_addr = data;
|
||||
Rec_state = 3;//to data length
|
||||
break;
|
||||
case 3://data length
|
||||
//debug("length");
|
||||
PAD_daraframe.length = (data < MAX_LEN) ? data : MAX_LEN;
|
||||
if (PAD_daraframe.length == 0) {
|
||||
Rec_state = 5;//to crc
|
||||
} else {
|
||||
Rec_state = 4;//to data
|
||||
Rec_data_cnt = 0;
|
||||
}
|
||||
break;
|
||||
case 4://data
|
||||
//debug("data");
|
||||
if (Rec_data_cnt < PAD_daraframe.length) {
|
||||
PAD_daraframe.data[Rec_data_cnt++] = data;
|
||||
}
|
||||
if (Rec_data_cnt == PAD_daraframe.length) {
|
||||
Rec_data_cnt = 0;
|
||||
Rec_state = 5;//to crc
|
||||
}
|
||||
break;
|
||||
case 5://CRC8
|
||||
PAD_daraframe.crc = crc8_maxim(frame, 5 + PAD_daraframe.length);
|
||||
#if PAD_CRC8_EN
|
||||
PAD_daraframe.crc = data;
|
||||
#endif
|
||||
//计算并验证crc8
|
||||
if (PAD_daraframe.crc == data) {
|
||||
Rec_state = 6;//to ack
|
||||
//debug("crc correct cmd:%x", PAD_daraframe.cmd_id);
|
||||
} else {
|
||||
Rec_state = 0;//to haeder
|
||||
PAD_daraframe.header = 0;
|
||||
//debug("crc error cmd:%x-%x", PAD_daraframe.cmd_id, PAD_daraframe.crc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// uart_putc(UART1_PORT,data);//debug
|
||||
// uart_putc(UART1_PORT,'0'+Rec_state);
|
||||
if(Rec_state == 6){
|
||||
PAD_daraframe.header = 0;
|
||||
Rec_state = 7;//数据处理完,需要将状态位归零,才会接收下一帧数据,即:uart1_state =0时。
|
||||
PAD_Data_Hande();
|
||||
Rec_state =0;
|
||||
/*
|
||||
rx handler codes....
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
//发送命令
|
||||
void app_PAD_Sendcmd(volatile uint8_t cmd_id ,volatile uint8_t reg_addr ,volatile uint8_t *data, volatile uint8_t length){
|
||||
PAD_daraframe_t frame;
|
||||
uint8_t *cmd_data =(uint8_t *)&frame;
|
||||
uint8_t i;
|
||||
|
||||
frame.header = ((uint16_t)((FRAME_HEADER << 8)|(FRAME_HEADER >> 8)));//0xA100
|
||||
frame.cmd_id = cmd_id;
|
||||
frame.reg_addr = reg_addr;
|
||||
frame.length = length < MAX_LEN ? length:MAX_LEN;
|
||||
|
||||
for(i = 0;i < frame.length ;i ++){
|
||||
frame.data[i] = * data++;
|
||||
}
|
||||
length =5 + frame.length;
|
||||
frame.crc = crc8_maxim(cmd_data, length);
|
||||
while(length--)
|
||||
uart_putc(UART1_PORT, (uint32_t)(*cmd_data ++));
|
||||
uart_putc(UART1_PORT, (uint32_t)(frame.crc));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef _APP_PAD_H_
|
||||
#define _APP_PAD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "uart.h"
|
||||
|
||||
//数据帧头
|
||||
#define FRAME_HEADER 0xA100
|
||||
|
||||
#define MAX_LEN 32
|
||||
|
||||
//0:失能数据校验
|
||||
#define PAD_CRC8_EN 1
|
||||
|
||||
typedef struct PAD_daraframe
|
||||
{
|
||||
volatile uint16_t header;//0xA100
|
||||
volatile uint8_t cmd_id;
|
||||
volatile uint8_t reg_addr;
|
||||
volatile uint8_t length;
|
||||
volatile uint8_t data[MAX_LEN];
|
||||
volatile uint8_t crc;
|
||||
} PAD_daraframe_t;
|
||||
|
||||
|
||||
|
||||
|
||||
//初始化
|
||||
void app_uart_Init(uint8_t port, uint32_t baudrate, uint8_t io_tx, uint8_t io_rx);
|
||||
// 接收数据
|
||||
void app_PAD_Receive(uint8_t data);
|
||||
//发送命令
|
||||
void app_PAD_Sendcmd(volatile uint8_t cmd_id ,volatile uint8_t reg_addr ,volatile uint8_t *data, volatile uint8_t length);
|
||||
|
||||
#endif
|
|
@ -15,7 +15,7 @@ void Event_Handle(uint16_t Event_List ,bool isOn,void *Parameter){
|
|||
(void)Parameter;
|
||||
switch(Event_List){
|
||||
case Buzzer_Event:
|
||||
Set_Status(OUT_Buzzer,isOn);
|
||||
Set_Status(IO_TTL_TX,isOn);
|
||||
break;
|
||||
case GRB_WS2812_Event:
|
||||
GRB_WS2812_Write_color(WS2812_GRBs.len, isOn ? WS2812_GRBs.GRBs : 0x0);
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _APP_BUZZER_H_
|
||||
#define _APP_BUZZER_H_
|
||||
#ifndef _APP_TIME_EVENT_H_
|
||||
#define _APP_TIME_EVENT_H_
|
||||
|
||||
#define Time_delay_interval 50
|
||||
|
|
@ -28,10 +28,10 @@ void sess_cb_rxd(uint8_t conidx, uint16_t len, const uint8_t *data)
|
|||
|
||||
// app_set_speed(*(int8_t *)(&data[2]));
|
||||
|
||||
Set_Status(OUT_High_brake,(0x01 & (data[1] >> 0)));
|
||||
Set_Status(OUT_Low_brake,(0x01 & (data[1] >> 1)));
|
||||
Set_Status(IO_BACK,(0x01 & (data[1] >> 0)));
|
||||
Set_Status(IO_BRAKE,(0x01 & (data[1] >> 1)));
|
||||
|
||||
Set_Status(OUT_Low_speed,(0x01 & (data[1] >> 4)));
|
||||
// Set_Status(OUT_Low_speed,(0x01 & (data[1] >> 4)));
|
||||
Set_Status(OUT_Door_lock,(0x01 & (data[1] >> 5)));
|
||||
|
||||
|
||||
|
|
|
@ -5,40 +5,63 @@
|
|||
#include "sys_config.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#include "app_control_out.h"
|
||||
|
||||
#define DBG_CONTROL_EN 1
|
||||
|
||||
#if (DBG_CONTROL_EN)
|
||||
#include "dbg.h"
|
||||
#define DEBUG(format, ...) debug("[control]" format "\r\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG(format, ...)
|
||||
#define debugHex(dat, len)
|
||||
#endif
|
||||
|
||||
|
||||
uint16_t ACC_Dmin ;
|
||||
uint16_t ACC_Dmax ;
|
||||
|
||||
//管理员模式速度极限
|
||||
uint8_t M_mode_sLim =M_DEFAULT_sLim;
|
||||
//游客模式速度极限
|
||||
uint8_t U_mode_sLim =U_DEFAULT_sLim;
|
||||
|
||||
// 使能电平
|
||||
bool app_control_en[PA_MAX]={
|
||||
[IN_GPS] =OE_LOW, // GPS输入0 /边沿触发/L:低使能(反)
|
||||
[IN_Back] =OE_LOW, // 倒车 /边沿触发
|
||||
[IN_Brake] =OE_LOW, // 制动 /边沿触发
|
||||
[IN_Manager_Mode] =OE_LOW, // 管理员模式 /边沿触发
|
||||
[OUT_12V_Control] =OE_HIGH, // 12V电源控制输出 /H:12V输出
|
||||
[OUT_Door_lock] =OE_HIGH, // 开锁 /H:开锁(同)
|
||||
[IN_01] =OE_LOW, // 自定义输入
|
||||
[IN_GPS] =OE_LOW, // GPS输入0 /L:低使能/边沿触发
|
||||
[IO_MANAGER_MODE] =OE_LOW, // 管理员模式 /边沿触发
|
||||
[IO_BACK] =OE_LOW, // 倒车 /H:前进/L:后退
|
||||
[IO_BRAKE] =OE_LOW, // 制动 /L:低使能
|
||||
|
||||
[OUT_Buzzer] =OE_HIGH, // 蜂鸣器 /H:高使能
|
||||
[OUT_Low_speed] =OE_HIGH, // 使能低速档位 /L:低使能(反)
|
||||
[OUT_Back_car] =OE_HIGH, // 使能倒车 /L:低使能倒车(反)
|
||||
[OUT_Low_brake] =OE_HIGH, // 使能低制动 /L:低使能(反)
|
||||
[OUT_High_brake] =OE_LOW, // 使能高制动 /H:高使能(反)
|
||||
[OUT_Door_lock] =OE_HIGH, // 开锁 /H:开锁(同)
|
||||
[IO_TTL_TX] =OE_LOW, // 串口发送
|
||||
[IO_TTL_RX] =OE_LOW, // 串口接收
|
||||
};
|
||||
|
||||
sys_sta_t sys_sta;
|
||||
// ={
|
||||
// .Pmode = 0,
|
||||
// .Smode = 0,
|
||||
// .O_12V = 0,
|
||||
// .O_lock = 0,
|
||||
// .I_01 = 0,
|
||||
// .I_brake = 0,
|
||||
// .I_back = 0,
|
||||
// .IO_TX = 0,
|
||||
// .IO_RX = 0,
|
||||
// .A_brake = 0,
|
||||
// .A_Speed_Cut = 0,
|
||||
// .Reserve = 0,
|
||||
// };
|
||||
|
||||
// 油门控制输入初始化/PA08/CH3
|
||||
// 电池电压检测/充电检测/PA04/CH7
|
||||
static void acc_in_bat_in_sadc_init(void)
|
||||
{
|
||||
// Analog Enable
|
||||
GPIO_DIR_CLR(GPIO08 | GPIO04);
|
||||
GPIO_DIR_CLR(GPIO08 | GPIO04 | GPIO02);
|
||||
|
||||
// ADC
|
||||
iom_ctrl(PA04, IOM_ANALOG);//BAT//AIN3//电池电量
|
||||
iom_ctrl(PA08, IOM_ANALOG);//ACC//AIN7//油门
|
||||
iom_ctrl(PA02, IOM_ANALOG);//ACC_FEEDBACK//AIN2//油门反馈
|
||||
iom_ctrl(PA04, IOM_ANALOG);//BAT//AIN3//电池电量
|
||||
|
||||
// sadc init
|
||||
#if SADC_VREF==VREF_VDD
|
||||
|
@ -73,20 +96,22 @@ static void acc_in_bat_in_sadc_init(void)
|
|||
|
||||
// 获取油门输入信号原始ADC值
|
||||
uint16_t get_in_acc_raw(void){
|
||||
return (sadc_read(SADC_CH_AIN7, 0));
|
||||
return (sadc_read(ACC_IN_CH, 0));
|
||||
}
|
||||
|
||||
// 获取油门输入电压信号(unit:mV)
|
||||
uint16_t get_in_acc_voltage(void){
|
||||
return ((((SADC_VREF * sadc_read(SADC_CH_AIN7, 3))/1024)/ACC_DOWN_Res)*(ACC_UP_Res+ACC_DOWN_Res));
|
||||
return ((((SADC_VREF * sadc_read(ACC_IN_CH, 3)) / 1024) / ACC_DOWN_Res) * (ACC_UP_Res + ACC_DOWN_Res));
|
||||
}
|
||||
|
||||
// 获取输入油门百分比(unit:%)(踏板信号)
|
||||
uint16_t get_in_acc_percent(void){
|
||||
uint16_t acc_voltage =get_in_acc_voltage();
|
||||
if(900 > acc_voltage) {return 0;}
|
||||
else if(3800 < acc_voltage){return 100;}
|
||||
else{
|
||||
if(900 > acc_voltage) {
|
||||
return 0;
|
||||
}else if(3800 < acc_voltage){
|
||||
return 100;
|
||||
}else{
|
||||
return ((acc_voltage-900)/29);
|
||||
// return (100*(acc_voltage - 900)/(3800-900));
|
||||
}
|
||||
|
@ -94,7 +119,7 @@ uint16_t get_in_acc_percent(void){
|
|||
|
||||
// 获取电池电压值(unit:V)
|
||||
float get_bat_voltage(void){
|
||||
return (((((SADC_VREF / 1000.0) * sadc_read(SADC_CH_AIN3, 3))/1024.0)/BAT_DOWN_Res)*(BAT_UP_Res+BAT_DOWN_Res));
|
||||
return (((((SADC_VREF / 1000.0) * sadc_read(BAT_IN_CH, 3))/1024.0)/BAT_DOWN_Res)*(BAT_UP_Res+BAT_DOWN_Res));
|
||||
}
|
||||
|
||||
// 油门调节输出初始化/PWM4/PA05
|
||||
|
@ -122,43 +147,67 @@ void set_out_acc_percent(uint8_t percent){
|
|||
//中控控制IO初始化
|
||||
void app_control_init(void){
|
||||
// out
|
||||
gpio_dir_output(OUT_Door_lock,OE_LOW);// 默认锁车
|
||||
gpio_dir_output(OUT_Low_speed,OE_LOW);// 低速档位,默认失能
|
||||
gpio_dir_output(OUT_Back_car,OE_LOW);// 默认前进模式
|
||||
gpio_dir_output(OUT_Low_brake,OE_LOW);// 默认关低制动
|
||||
gpio_dir_output(OUT_High_brake,OE_HIGH);// 默认关高制动
|
||||
gpio_dir_output(OUT_Buzzer,OE_LOW);// 默认关蜂鸣器
|
||||
gpio_dir_output(OUT_12V_Control,OE_LOW);// 12V电源控制输出 /H:12V输出
|
||||
gpio_dir_output(OUT_Door_lock,OE_LOW); // 电门锁 /H:开锁
|
||||
gpio_dir_output(IO_MANAGER_MODE,OE_LOW);// 管理员模式 /边沿触发
|
||||
gpio_dir_output(IO_BACK,OE_HIGH); // 倒车 /H:前进/L:后退
|
||||
gpio_dir_output(IO_BRAKE,OE_LOW); // 制动 /L:低使能
|
||||
|
||||
gpio_dir_output(IO_TTL_TX,OE_HIGH); // 串口发送
|
||||
gpio_dir_output(IO_TTL_RX,OE_LOW); // 串口接收
|
||||
//in
|
||||
gpio_dir_input(OUT_Door_lock,IE_DOWN);// 默认锁车
|
||||
gpio_dir_input(OUT_Low_speed,IE_DOWN);// 低速档位,默认失能
|
||||
gpio_dir_input(OUT_Back_car,IE_DOWN);// 默认前进模式
|
||||
gpio_dir_input(OUT_Low_brake,IE_DOWN);// 默认关低制动
|
||||
gpio_dir_input(OUT_High_brake,IE_UP);// 默认关高制动
|
||||
gpio_dir_input(OUT_Buzzer,IE_DOWN);// 默认关蜂鸣器
|
||||
// gpio_dir_input(OUT_12V_Control,IE_DOWN);// 12V电源控制输出 /H:12V输出
|
||||
gpio_dir_input(OUT_Door_lock,IE_DOWN); // 电门锁 /H:开锁
|
||||
gpio_dir_input(IO_MANAGER_MODE,IE_DOWN);// 管理员模式 /边沿触发
|
||||
gpio_dir_input(IO_BACK,IE_DOWN); // 倒车 /H:前进/L:后退
|
||||
gpio_dir_input(IO_BRAKE,IE_DOWN); // 制动 /L:低使能
|
||||
|
||||
gpio_dir_input(IO_TTL_TX,IE_DOWN); // 串口发送
|
||||
gpio_dir_input(IO_TTL_RX,IE_DOWN); // 串口接收
|
||||
|
||||
//默认都失能
|
||||
Set_Status(OUT_12V_Control,0);
|
||||
Set_Status(OUT_Door_lock,0);
|
||||
Set_Status(OUT_Low_speed,0);
|
||||
Set_Status(OUT_Back_car,0); //失能倒车
|
||||
Set_Status(OUT_Low_brake,0);
|
||||
Set_Status(OUT_High_brake,0);
|
||||
Set_Status(OUT_Buzzer,0);
|
||||
Set_Status(IO_MANAGER_MODE,0);
|
||||
Set_Status(IO_BACK,0); //失能倒车
|
||||
Set_Status(IO_BRAKE,0);
|
||||
|
||||
Set_Status(IO_TTL_TX,0);
|
||||
Set_Status(IO_TTL_RX,0);
|
||||
|
||||
// in
|
||||
gpio_dir_input(IN_GPS, IE_UP); // Input enable, pull-up
|
||||
gpio_dir_input(IN_Back, IE_UP);
|
||||
gpio_dir_input(IN_Brake, IE_UP);
|
||||
gpio_dir_input(IN_Manager_Mode, IE_UP);
|
||||
gpio_dir_input(IN_01,IE_UP); // 自定义输入
|
||||
gpio_dir_input(IN_GPS,IE_UP); // GPS输入0 /边沿触发
|
||||
|
||||
// // EXTI config
|
||||
// exti_init(EXTI_DBC(15, 4));
|
||||
// exti_set(EXTI_FTS, EXTI_SRC(IN_GPS) | EXTI_SRC(IN_Back) | EXTI_SRC(IN_Brake) | EXTI_SRC(IN_Manager_Mode)); // falling
|
||||
// exti_set(EXTI_DBE, EXTI_SRC(IN_GPS) | EXTI_SRC(IN_Back) | EXTI_SRC(IN_Brake) | EXTI_SRC(IN_Manager_Mode));
|
||||
// exti_set(EXTI_IER, EXTI_SRC(IN_GPS) | EXTI_SRC(IN_Back) | EXTI_SRC(IN_Brake) | EXTI_SRC(IN_Manager_Mode));
|
||||
// exti_set(EXTI_FTS, EXTI_SRC(IN_GPS) | EXTI_SRC(IO_BACK) | EXTI_SRC(IO_BRAKE) | EXTI_SRC(IO_MANAGER_MODE)); // falling
|
||||
// exti_set(EXTI_DBE, EXTI_SRC(IN_GPS) | EXTI_SRC(IO_BACK) | EXTI_SRC(IO_BRAKE) | EXTI_SRC(IO_MANAGER_MODE));
|
||||
// exti_set(EXTI_IER, EXTI_SRC(IN_GPS) | EXTI_SRC(IO_BACK) | EXTI_SRC(IO_BRAKE) | EXTI_SRC(IO_MANAGER_MODE));
|
||||
|
||||
// IRQ enable
|
||||
// NVIC_EnableIRQ(EXTI_IRQn);
|
||||
|
||||
// sys_sta.Pmode = 0;
|
||||
sys_sta.Manager =0;
|
||||
sys_sta.Tourist =0;
|
||||
// sys_sta.Smode = 0;
|
||||
sys_sta.IOgps = Get_Status(IN_GPS);
|
||||
sys_sta.IOmanager = Get_Status(IO_MANAGER_MODE);
|
||||
|
||||
sys_sta.O_12V = 0;
|
||||
sys_sta.O_lock = 0;
|
||||
sys_sta.I_01 = Get_Status(IN_01);
|
||||
sys_sta.I_brake = Get_Status(IO_BRAKE);
|
||||
sys_sta.I_back = Get_Status(IO_BACK);
|
||||
sys_sta.IO_TX = Get_Status(IO_TTL_TX);
|
||||
sys_sta.IO_RX = Get_Status(IO_TTL_RX);
|
||||
sys_sta.A_brake = 0;
|
||||
sys_sta.A_Speed_Cut = 0;
|
||||
sys_sta.Reserve = 0;
|
||||
DEBUG("sys_sta_t:lenght=%d",sizeof(sys_sta));
|
||||
DEBUG("sys_sta_t=%#04X",*(uint16_t*)&sys_sta);
|
||||
|
||||
acc_in_bat_in_sadc_init();
|
||||
acc_out_pwm_init();
|
||||
|
||||
|
@ -176,50 +225,101 @@ void EXTI_IRQHandler(void)
|
|||
|
||||
}
|
||||
|
||||
if (irq_sta & EXTI_SRC(IN_Back))
|
||||
if (irq_sta & EXTI_SRC(IO_BACK))
|
||||
{
|
||||
EXTI->ICR.Word = EXTI_SRC(IN_Back);
|
||||
EXTI->ICR.Word = EXTI_SRC(IO_BACK);
|
||||
|
||||
}
|
||||
|
||||
if (irq_sta & EXTI_SRC(IN_Brake))
|
||||
if (irq_sta & EXTI_SRC(IO_BRAKE))
|
||||
{
|
||||
EXTI->ICR.Word = EXTI_SRC(IN_Brake);
|
||||
EXTI->ICR.Word = EXTI_SRC(IO_BRAKE);
|
||||
|
||||
}
|
||||
|
||||
if (irq_sta & EXTI_SRC(IN_Manager_Mode))
|
||||
if (irq_sta & EXTI_SRC(IO_MANAGER_MODE))
|
||||
{
|
||||
EXTI->ICR.Word = EXTI_SRC(IN_Manager_Mode);
|
||||
EXTI->ICR.Word = EXTI_SRC(IO_MANAGER_MODE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// PAD控制进入管理员模式
|
||||
bool PAD_Manager_Mode=0;
|
||||
// PAD控制进入游客模式
|
||||
bool PAD_User_Mode=0;
|
||||
// 系统自动刹车
|
||||
bool SYS_AUTO_brake=0;
|
||||
// 系统自动减速
|
||||
bool SYS_AUTO_Speed_Cut=0;
|
||||
// // PAD控制进入管理员模式
|
||||
// bool PAD_Manager_Mode =0;
|
||||
// // PAD控制进入游客模式
|
||||
// bool PAD_User_Mode =0;
|
||||
// // PAD控制LED开关
|
||||
// bool PAD_LED_ONOFF =0;
|
||||
// // 系统自动刹车
|
||||
// bool SYS_AUTO_brake =0;
|
||||
// // 系统自动减速
|
||||
// bool SYS_AUTO_Speed_Cut =0;
|
||||
|
||||
// uint8_t Get_SYS_Status(void){
|
||||
// return (PAD_Manager_Mode << 3) | (PAD_User_Mode << 2) | (PAD_LED_ONOFF << 1) | (SYS_AUTO_brake << 0) | (SYS_AUTO_Speed_Cut << 4);
|
||||
// }
|
||||
|
||||
// 控制进程,定时调用
|
||||
void Control_procedure(void){
|
||||
|
||||
//电门锁
|
||||
Set_Status(OUT_Door_lock,(PAD_User_Mode || PAD_Manager_Mode || Get_Status(IN_GPS) || Get_Status(IN_Manager_Mode)));
|
||||
|
||||
// 倒车
|
||||
Set_Status(OUT_Back_car,Get_Status(IN_Back));
|
||||
//电门锁
|
||||
// sys_sta.Smode = 0;
|
||||
sys_sta.IOgps = Get_Status(IN_GPS); //更新GPS状态
|
||||
sys_sta.IOmanager = Get_Status(IO_MANAGER_MODE); //更新管理员模式状态
|
||||
sys_sta.O_lock = (0 != (sys_sta.Pmode | sys_sta.Smode));
|
||||
Set_Status(OUT_Door_lock, sys_sta.O_lock);
|
||||
// Set_Status(OUT_Door_lock,(PAD_User_Mode || PAD_Manager_Mode || Get_Status(IN_GPS) || SYS_Manager_STA));
|
||||
|
||||
//12V电源
|
||||
Set_Status(OUT_12V_Control ,sys_sta.O_12V);// 更新12V电源状态
|
||||
// Set_Status(OUT_12V_Control,(PAD_LED_ONOFF));
|
||||
|
||||
// 刹车
|
||||
Set_Status(OUT_Low_brake,(Get_Status(IN_Brake) || SYS_AUTO_brake));
|
||||
Set_Status(OUT_High_brake,(Get_Status(IN_Brake) || SYS_AUTO_brake));
|
||||
Set_Status(IO_BRAKE ,sys_sta.A_brake);// 输出为低电平时,可刹车
|
||||
sys_sta.I_brake = Get_Status(IO_BRAKE); //更新刹车状态// 输出为高电平时,可读取外部刹车状态
|
||||
// Set_Status(IO_BRAKE,SYS_AUTO_brake);
|
||||
|
||||
sys_sta.I_01 = Get_Status(IN_01);
|
||||
sys_sta.I_back = Get_Status(IO_BACK);
|
||||
sys_sta.IO_TX = Get_Status(IO_TTL_TX);
|
||||
sys_sta.IO_RX = Get_Status(IO_TTL_RX);
|
||||
|
||||
//油门控制
|
||||
if(Get_Status(OUT_Door_lock)){
|
||||
set_out_acc_percent((SYS_AUTO_Speed_Cut?0.5:1)*get_in_acc_percent()*((PAD_Manager_Mode || Get_Status(IN_Manager_Mode)) ? sys_conf_info.M_mode_sLim : sys_conf_info.U_mode_sLim) / 100.0);
|
||||
if(0 != (sys_sta.Pmode | sys_sta.Smode)){
|
||||
uint8_t acc_percent =0;
|
||||
if(0x01 == (sys_sta.Pmode | sys_sta.Smode)){//管理员模式
|
||||
acc_percent = (get_in_acc_percent() * sys_conf.Manager_sLim) / 100.0;
|
||||
}else{//游客模式
|
||||
if(sys_sta.A_Speed_Cut){//自动减速
|
||||
acc_percent = (get_in_acc_percent() * sys_conf.Speed_Cut_sLim) / 100.0;
|
||||
}else{
|
||||
acc_percent = (get_in_acc_percent() * sys_conf.Tourist_sLim) / 100.0;
|
||||
}
|
||||
}
|
||||
set_out_acc_percent(acc_percent);
|
||||
}else{
|
||||
set_out_acc_percent(0);
|
||||
}
|
||||
|
||||
// //油门控制
|
||||
// if((PAD_User_Mode || PAD_Manager_Mode || Get_Status(IN_GPS) || SYS_Manager_STA)){
|
||||
// uint8_t acc_percent =0;
|
||||
|
||||
// // acc_percent = get_in_acc_percent() *
|
||||
// // (((PAD_Manager_Mode || SYS_Manager_STA) ? sys_conf.Manager_sLim : (SYS_AUTO_Speed_Cut ? sys_conf.Speed_Cut_sLim : sys_conf.Tourist_sLim)) / 100.0);
|
||||
|
||||
// if(PAD_Manager_Mode || SYS_Manager_STA){//管理员模式
|
||||
// acc_percent = (get_in_acc_percent() * sys_conf.Manager_sLim) / 100.0;
|
||||
// }else{//游客模式
|
||||
// if(SYS_AUTO_Speed_Cut){//自动减速
|
||||
// acc_percent = (get_in_acc_percent() * sys_conf.Speed_Cut_sLim) / 100.0;
|
||||
// }else{
|
||||
// acc_percent = (get_in_acc_percent() * sys_conf.Tourist_sLim) / 100.0;
|
||||
// }
|
||||
// }
|
||||
// set_out_acc_percent(acc_percent);
|
||||
// }else{
|
||||
// set_out_acc_percent(0);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -20,39 +20,89 @@ extern uint16_t ACC_Dmax ;
|
|||
|
||||
#define ACC_PERCENT(s) (ACC_Dmin + ((ACC_Dmax - ACC_Dmin)*(s))/100)
|
||||
|
||||
|
||||
// GPIO的输出需反向
|
||||
enum app_control{
|
||||
IN_GPS =PA09, // GPS输入0 /边沿触发
|
||||
IN_Back =PA10, // 倒车 /边沿触发
|
||||
IN_Brake =PA11, // 制动 /边沿触发
|
||||
IN_Manager_Mode =PA12, // 管理员模式 /边沿触发
|
||||
|
||||
OUT_Buzzer =PA13, // 蜂鸣器 /H:高使能
|
||||
OUT_Low_speed =PA14, // 低速档位 /L:低使能
|
||||
OUT_Back_car =PA15, // 前进后退 /H:前进/L:后退
|
||||
OUT_Low_brake =PA16, // 低制动 /L:低使能
|
||||
OUT_High_brake =PA17, // 高制动 /H:低使能
|
||||
OUT_Door_lock =PA18, // 电门锁 /H:开锁
|
||||
enum app_adc_dac_chx{
|
||||
ACC_IN_CH =SADC_CH_AIN7, // 油门输入
|
||||
ACC_FEED_CH =SADC_CH_AIN2, // 油门输出监测
|
||||
BAT_IN_CH =SADC_CH_AIN3, // 电池输入
|
||||
};
|
||||
|
||||
|
||||
extern bool app_control_en[PA_MAX];
|
||||
enum app_control{
|
||||
OUT_12V_Control =PA17, // 12V电源控制输出 /H:12V输出
|
||||
OUT_Door_lock =PA18, // 电门锁 /H:开锁
|
||||
IN_01 =PA03, // 自定义输入
|
||||
IN_GPS =PA19, // GPS输入0 /边沿触发
|
||||
IO_MANAGER_MODE =PA13, // 管理员模式 /边沿触发
|
||||
IO_BACK =PA14, // 倒车 /H:前进/L:后退
|
||||
IO_BRAKE =PA15, // 制动 /L:低使能
|
||||
|
||||
// PAD控制进入管理员模式
|
||||
extern bool PAD_Manager_Mode;
|
||||
// PAD控制进入游客模式
|
||||
extern bool PAD_User_Mode;
|
||||
// 系统自动刹车
|
||||
extern bool SYS_AUTO_brake;
|
||||
// 系统自动减速
|
||||
extern bool SYS_AUTO_Speed_Cut;
|
||||
IO_TTL_TX =PA11, // 串口发送
|
||||
IO_TTL_RX =PA12, // 串口接收
|
||||
|
||||
RADAR_TXD0 =PA07, // 串口0发送
|
||||
RADAR_RXD0 =PA06, // 串口0接收
|
||||
PAD_TXD1 =PA10, // 串口1发送
|
||||
PAD_RXD1 =PA09, // 串口1接收
|
||||
|
||||
ACC_PA8_ADC7 =PA08, // 油门输入
|
||||
PWM4_DAC =PA05, // 油门输出
|
||||
ACC_FEEDBACK_ADC2 =PA02, // 油门输出监测
|
||||
|
||||
RGB_DATA_IO =PA16, // RGB数据输出
|
||||
|
||||
BAT_PA4_ADC3 =PA04, // 电池电压输入
|
||||
};
|
||||
|
||||
typedef struct sys_sta{
|
||||
// uint16_t Pmode:2;
|
||||
union{
|
||||
uint8_t Pmode:2;
|
||||
struct{
|
||||
uint8_t Tourist:1;
|
||||
uint8_t Manager:1;
|
||||
};
|
||||
};
|
||||
union{
|
||||
uint8_t Smode:2;
|
||||
struct{
|
||||
uint8_t IOgps:1;
|
||||
uint8_t IOmanager:1;
|
||||
};
|
||||
};
|
||||
uint16_t O_12V:1; // 12V电源输出状态
|
||||
uint16_t O_lock:1; // 电门锁输出状态
|
||||
uint16_t I_01:1; // 自定义输入状态
|
||||
uint16_t I_brake:1;// 制动信号输入状态
|
||||
uint16_t I_back:1; // 倒车信号输入状态
|
||||
uint16_t IO_TX :1;
|
||||
uint16_t IO_RX :1;
|
||||
uint16_t A_brake :1; // 自动刹车状态
|
||||
uint16_t A_Speed_Cut :1;// 自动减速状态
|
||||
uint16_t Reserve:7;
|
||||
} sys_sta_t;
|
||||
|
||||
extern sys_sta_t sys_sta;
|
||||
|
||||
|
||||
extern bool app_control_en[PA_MAX];
|
||||
|
||||
// 写1使能,写0失能
|
||||
#define Set_Status(pad,activity) (gpio_put(pad, ((0 == activity) ? !app_control_en[pad] : app_control_en[pad])))
|
||||
// 获取状态 1使能,0失能
|
||||
#define Get_Status(pad) ((app_control_en[pad] == gpio_get(pad)) ? 1 : 0)
|
||||
|
||||
#define SYS_Manager_STA Get_Status(IO_MANAGER_MODE) //管理员输入状态
|
||||
#define SYS_Back_STA Get_Status(IO_BACK) //倒车状态
|
||||
#define SYS_Brake_STA Get_Status(IO_BRAKE) //制动状态
|
||||
|
||||
// // PAD控制进入管理员模式
|
||||
// extern bool PAD_Manager_Mode;
|
||||
// // PAD控制进入游客模式
|
||||
// extern bool PAD_User_Mode;
|
||||
// // 系统自动刹车
|
||||
// extern bool SYS_AUTO_brake;
|
||||
// // 系统自动减速
|
||||
// extern bool SYS_AUTO_Speed_Cut;
|
||||
|
||||
//中控控制IO初始化
|
||||
void app_control_init(void);
|
||||
|
|
|
@ -4,127 +4,118 @@
|
|||
#include "app_radar.h"
|
||||
#include "sftmr.h"
|
||||
|
||||
#include "CRCxx.h"
|
||||
|
||||
#include "sys_config.h"
|
||||
|
||||
#define DBG_RADAR_EN 1
|
||||
|
||||
radar_daraframe_t radar_daraframe;
|
||||
#if (DBG_RADAR_EN)
|
||||
#include "dbg.h"
|
||||
#define DEBUG(format, ...) debug("[RADAR]" format "\r\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG(format, ...)
|
||||
#define debugHex(dat, len)
|
||||
#endif
|
||||
|
||||
// 定时处理数和获取数据
|
||||
tmr_id_t radar_timer_tmr_id;
|
||||
|
||||
bool radar_flag=0;
|
||||
uint8_t radar_flag_cnt=0;
|
||||
static bool radar_NewData_flag=0;// 新数据标志位
|
||||
static uint8_t radar_CMDSend_cnt=0; // 发送命令计数
|
||||
radar_data_t radar_data;
|
||||
|
||||
// uint8_t radar_str[50]={0,0},radar_str_len=0;
|
||||
|
||||
// 自动刹车或减速判断处理函数
|
||||
void radar_AUTO_BrakeORSpeedCut(uint8_t radar_id , uint16_t Car_Distance){ //距离数据30~4500mm
|
||||
// 自动刹车距离
|
||||
uint16_t Brake_Distance = ((radar_id == RADAR_ID_Back )? sys_conf.Brake_DLimit_B : sys_conf.Brake_DLimit);
|
||||
// 自动减速距离
|
||||
uint16_t Speed_Cut_Distance = ((radar_id == RADAR_ID_Back )? sys_conf.Speed_Cut_DLimit_B : sys_conf.Speed_Cut_DLimit);
|
||||
|
||||
if((35 < Car_Distance) && Car_Distance < Brake_Distance){//小于自动刹车距离时
|
||||
if(!sys_sta.A_brake){
|
||||
Time_Event_Blink(Buzzer_Event,100,100,0xffff,NULL);
|
||||
}
|
||||
sys_sta.A_brake =1;//使能自动刹车
|
||||
sys_sta.A_Speed_Cut=1;
|
||||
}else if((35 < Car_Distance) && Car_Distance < Speed_Cut_Distance){//小于自动减速距离时
|
||||
if(sys_sta.A_brake || !sys_sta.A_Speed_Cut){
|
||||
Time_Event_Blink(Buzzer_Event,200,500,0xffff,NULL);
|
||||
}
|
||||
sys_sta.A_brake =0;
|
||||
sys_sta.A_Speed_Cut=1;//使能自动减速
|
||||
}else{
|
||||
if(sys_sta.A_brake || sys_sta.A_Speed_Cut){
|
||||
Time_Event_Off(Buzzer_Event,NULL);
|
||||
}
|
||||
sys_sta.A_brake =0;
|
||||
sys_sta.A_Speed_Cut=0;
|
||||
}
|
||||
}
|
||||
|
||||
// 定时处理数和获取数据
|
||||
static tmr_tk_t radar_timer_handler(tmr_id_t id){
|
||||
(void)(id);
|
||||
uint16_t Car_Distance=0;
|
||||
// uint16_t Car_Distance=0;
|
||||
|
||||
if(Get_Status(OUT_Door_lock)){
|
||||
// 定时发送状态信息
|
||||
if(radar_flag_cnt > 4){
|
||||
uint8_t ret_data[20]={0,0};
|
||||
radar_flag_cnt =0;
|
||||
ret_data[radar_flag_cnt++] =BAT_Message.Bat_STA; // 电池状态
|
||||
ret_data[radar_flag_cnt++] =BAT_Message.Bat_Voltage >> 8; //电池电压
|
||||
ret_data[radar_flag_cnt++] =BAT_Message.Bat_Voltage & 0xff;
|
||||
ret_data[radar_flag_cnt++] =get_in_acc_percent();// 当前油门百分比
|
||||
ret_data[radar_flag_cnt++] =radar_daraframe.Front_data /100;// 前雷达距离信息
|
||||
ret_data[radar_flag_cnt++] =radar_daraframe.Back_data/100;// 后雷达距离信息
|
||||
// 读取系统配置
|
||||
ret_data[radar_flag_cnt++]=sys_conf_info.M_mode_sLim;
|
||||
ret_data[radar_flag_cnt++]=sys_conf_info.U_mode_sLim;
|
||||
ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Brake_Distance;
|
||||
ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Speed_Cut_Distance;
|
||||
ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Brake_Distance_B;
|
||||
ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Speed_Cut_Distance_B;
|
||||
ret_data[radar_flag_cnt++] =(Get_Status(IN_GPS)<<0) | (Get_Status(IN_Back)<<1) | (Get_Status(OUT_Low_brake)<<2)
|
||||
| (Get_Status(IN_Manager_Mode)<<3) | ((PAD_Manager_Mode)<<4)
|
||||
| ((PAD_User_Mode)<<5) | ((SYS_AUTO_Speed_Cut)<<6) | ((SYS_AUTO_brake)<<7);
|
||||
app_uart_Sendcmd(UART1_PORT,0x10,0x01,ret_data,radar_flag_cnt);
|
||||
radar_flag_cnt =0;
|
||||
goto radar_end;
|
||||
}else {
|
||||
radar_flag_cnt++;
|
||||
}
|
||||
// if(Get_Status(OUT_Door_lock)){
|
||||
// // 定时发送状态信息
|
||||
// if(radar_flag_cnt > 4){
|
||||
// uint8_t ret_data[20]={0,0};
|
||||
// radar_flag_cnt =0;
|
||||
// ret_data[radar_flag_cnt++] =BAT_Message.Bat_STA; // 电池状态
|
||||
// ret_data[radar_flag_cnt++] =BAT_Message.Bat_Voltage >> 8; //电池电压
|
||||
// ret_data[radar_flag_cnt++] =BAT_Message.Bat_Voltage & 0xff;
|
||||
// ret_data[radar_flag_cnt++] =get_in_acc_percent();// 当前油门百分比
|
||||
// ret_data[radar_flag_cnt++] =radar_daraframe.Front_data /100;// 前雷达距离信息
|
||||
// ret_data[radar_flag_cnt++] =radar_daraframe.Back_data/100;// 后雷达距离信息
|
||||
// // 读取系统配置
|
||||
// ret_data[radar_flag_cnt++]=sys_conf_info.M_mode_sLim;
|
||||
// ret_data[radar_flag_cnt++]=sys_conf_info.U_mode_sLim;
|
||||
// ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Brake_Distance;
|
||||
// ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Speed_Cut_Distance;
|
||||
// ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Brake_Distance_B;
|
||||
// ret_data[radar_flag_cnt++]=sys_conf_info.AUTO_Speed_Cut_Distance_B;
|
||||
// ret_data[radar_flag_cnt++] =(Get_Status(IN_GPS)<<0) | (SYS_Back_STA<<1) | (Get_Status(IO_BRAKE)<<2)
|
||||
// | (SYS_Manager_STA<<3) | ((PAD_Manager_Mode)<<4)
|
||||
// | ((PAD_User_Mode)<<5) | ((sys_sta.A_Speed_Cut)<<6) | ((sys_sta.A_brake)<<7);
|
||||
// app_PAD_Sendcmd(0x10,0x01,ret_data,radar_flag_cnt);
|
||||
// radar_flag_cnt =0;
|
||||
// goto radar_end;
|
||||
// }else {
|
||||
// radar_flag_cnt++;
|
||||
// }
|
||||
// }
|
||||
// DEBUG("RADAR...");
|
||||
if(radar_NewData_flag == 1){
|
||||
radar_NewData_flag =0; // 清空新数据标志位
|
||||
radar_CMDSend_cnt =0; // 清空发送命令计数
|
||||
DEBUG("ID =%d,distance =%d", radar_data.radar_id ,radar_data.distance);
|
||||
}
|
||||
if((radar_CMDSend_cnt !=0)){
|
||||
DEBUG("Clear:CMD_cnt =%d", radar_CMDSend_cnt);
|
||||
radar_CMDSend_cnt =0; // 清空发送命令计数
|
||||
radar_AUTO_BrakeORSpeedCut(0 , 0);//复位自动刹车和减速状态
|
||||
}
|
||||
|
||||
if(radar_flag == 1){
|
||||
// radar_str_len =sprintf((char *)radar_str, "F=%d,B=%d\n", radar_daraframe.Front_data ,radar_daraframe.Back_data);
|
||||
// uart_send(UART1_PORT,radar_str_len,radar_str);
|
||||
radar_flag = 0;
|
||||
// 进入游客模式开启雷达 //管理员模式优先于游客模式
|
||||
if((1 == (sys_sta.Pmode | sys_sta.Smode))){
|
||||
// 根据倒车状态确定雷达ID
|
||||
DEBUG("SendCMD:ID=%#02x", SYS_Back_STA ? RADAR_ID_Back : RADAR_ID_Front);
|
||||
app_radar_Sendcmd(SYS_Back_STA ? RADAR_ID_Back : RADAR_ID_Front,RADAR_MODE_Real);
|
||||
radar_CMDSend_cnt++;
|
||||
}
|
||||
if(Get_Status(OUT_Door_lock) && !(PAD_Manager_Mode || Get_Status(IN_Manager_Mode))){
|
||||
if(Get_Status(IN_Back)){//如果是倒车状态
|
||||
#if (0 ==RADAR_MODE)
|
||||
// uint8_t data[8]={0x02,0x03,0x01,0x00,0x00,0x01,0x85,0xC5};//读取处理值数据//520ms
|
||||
uint8_t data[8]={0x02,0x03,0x01,0x01,0x00,0x01,0xD4,0x05};////读取实时值数据//120ms
|
||||
#elif (1 ==RADAR_MODE)
|
||||
uint8_t data[8]={0x02,0x03,0x00,0x01,0x00,0x01,0xD5,0xf9};////读取实时值数据//120ms
|
||||
#endif
|
||||
Car_Distance =radar_daraframe.Back_data/100;
|
||||
radar_daraframe.Back_data=0xffff;
|
||||
uart_send(UART1_PORT,8,data);
|
||||
}else{
|
||||
#if (0 ==RADAR_MODE)
|
||||
// uint8_t data[8]={0x01,0x03,0x01,0x00,0x00,0x01,0x85,0xf6};//读取处理值数据//520ms
|
||||
uint8_t data[8]={0x01,0x03,0x01,0x01,0x00,0x01,0xD4,0x36};//读取实时值数据//120ms
|
||||
#elif (1 ==RADAR_MODE)
|
||||
uint8_t data[8]={0x01,0x03,0x00,0x01,0x00,0x01,0xD5,0xCA};////读取实时值数据//120ms
|
||||
#endif
|
||||
Car_Distance =radar_daraframe.Front_data/100;
|
||||
radar_daraframe.Front_data=0xffff;
|
||||
uart_send(UART1_PORT,8,data);
|
||||
}
|
||||
|
||||
if((0 < Car_Distance) && Car_Distance < (Get_Status(IN_Back)?sys_conf_info.AUTO_Brake_Distance_B :sys_conf_info.AUTO_Brake_Distance)){//小于自动刹车距离时
|
||||
if(!SYS_AUTO_brake){
|
||||
Time_Event_Blink(Buzzer_Event,100,100,0xffff,NULL);
|
||||
}
|
||||
SYS_AUTO_brake =1;//使能自动刹车
|
||||
SYS_AUTO_Speed_Cut=1;
|
||||
}else if((0 < Car_Distance) && Car_Distance < (Get_Status(IN_Back)?sys_conf_info.AUTO_Speed_Cut_Distance_B :sys_conf_info.AUTO_Speed_Cut_Distance)){//小于自动减速距离时
|
||||
if(SYS_AUTO_brake || !SYS_AUTO_Speed_Cut){
|
||||
Time_Event_Blink(Buzzer_Event,200,500,0xffff,NULL);
|
||||
}
|
||||
SYS_AUTO_brake =0;
|
||||
SYS_AUTO_Speed_Cut=1;
|
||||
}else{
|
||||
if(SYS_AUTO_brake || SYS_AUTO_Speed_Cut){
|
||||
Time_Event_Off(Buzzer_Event,NULL);
|
||||
}
|
||||
SYS_AUTO_brake =0;
|
||||
SYS_AUTO_Speed_Cut=0;
|
||||
}
|
||||
}else{
|
||||
if(SYS_AUTO_brake || SYS_AUTO_Speed_Cut){
|
||||
Time_Event_Off(Buzzer_Event,NULL);
|
||||
}
|
||||
SYS_AUTO_brake =0;
|
||||
SYS_AUTO_Speed_Cut=0;
|
||||
}
|
||||
radar_end:
|
||||
return _MS(300);//300ms
|
||||
return _MS(160);//300ms
|
||||
}
|
||||
|
||||
// 雷达测离初始化
|
||||
void app_radar_init(void){
|
||||
// sftmr_init(); //main函数中已初始化
|
||||
radar_timer_tmr_id = sftmr_start(10, radar_timer_handler);
|
||||
}
|
||||
|
||||
#if (1 ==BLE_ENABLE)
|
||||
extern uint16_t Front_data;
|
||||
extern uint16_t Back_data;
|
||||
#endif
|
||||
|
||||
uint8_t radar_buff[10],radar_state;
|
||||
uint16_t i;
|
||||
|
||||
// 串口数据接收
|
||||
static uint8_t radar_buff[RADAR_BUFF_MAX];
|
||||
|
||||
// 数据接收
|
||||
void app_radar_Receive(uint8_t data){
|
||||
static uint8_t cnt=0,radar_state=0;
|
||||
switch(radar_state){
|
||||
case 0://dev_addr
|
||||
if (data == 0x01 || data == 0x02) {
|
||||
|
@ -145,44 +136,60 @@ void app_radar_Receive(uint8_t data){
|
|||
if (data == 0x02) {
|
||||
radar_buff[2]=data;
|
||||
radar_state = 3;
|
||||
i=0;
|
||||
cnt=0;
|
||||
}else {
|
||||
radar_state = 0;
|
||||
radar_buff[0]=0;
|
||||
}
|
||||
break;
|
||||
case 3://data
|
||||
radar_buff[3+i] =data;
|
||||
i++;
|
||||
if(i==2){
|
||||
i=0;
|
||||
radar_buff[3+cnt] =data;
|
||||
cnt++;
|
||||
if(cnt==2){
|
||||
cnt=0;
|
||||
radar_state = 4;
|
||||
}
|
||||
|
||||
break;
|
||||
case 4://crc16
|
||||
radar_buff[5+i] =data;
|
||||
i++;
|
||||
if(i==2){
|
||||
uint16_t crc16 =crc16_checkout(radar_buff,5);
|
||||
radar_buff[5+cnt] =data;
|
||||
cnt++;
|
||||
if(cnt==2){
|
||||
uint16_t crc16 =crc16_modbus(radar_buff,5);
|
||||
if(crc16 == (((uint16_t)radar_buff[6] << 8 ) | radar_buff[5])){
|
||||
if(0x01 == radar_buff[0]){
|
||||
radar_daraframe.Front_data = ((uint16_t)radar_buff[3] << 8 ) | radar_buff[4];
|
||||
#if (1 ==BLE_ENABLE)
|
||||
Front_data=radar_daraframe.Front_data;
|
||||
#endif
|
||||
}else if(0x02 == radar_buff[0]){
|
||||
radar_daraframe.Back_data = ((uint16_t)radar_buff[3] << 8 ) | radar_buff[4];
|
||||
#if (1 ==BLE_ENABLE)
|
||||
Back_data=radar_daraframe.Back_data;
|
||||
#endif
|
||||
}
|
||||
radar_flag = 1;
|
||||
radar_data.radar_id = radar_buff[0];
|
||||
radar_data.distance = ((uint16_t)radar_buff[3] << 8 ) | radar_buff[4];
|
||||
radar_AUTO_BrakeORSpeedCut(radar_data.radar_id ,radar_data.distance);
|
||||
radar_NewData_flag = 1;
|
||||
}
|
||||
i=0;
|
||||
cnt=0;
|
||||
radar_state = 0;
|
||||
radar_buff[0]=0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//发送读取实时值数据命令
|
||||
void app_radar_Sendcmd(uint8_t radar_id , uint8_t radar_mode){
|
||||
uint8_t len=0;
|
||||
uint8_t data[8];
|
||||
|
||||
data[len++] = radar_id;
|
||||
data[len++] = 0x03;
|
||||
data[len++] = 0x01;
|
||||
data[len++] = radar_mode ? 0x01 : 0x00; // 0x01:实时值(120ms) 0x00:处理值(520ms)
|
||||
data[len++] = 0x00;
|
||||
data[len++] = 0x01;
|
||||
|
||||
uint16_t crc16 =crc16_modbus(data,len);
|
||||
data[len++] = crc16 & 0xff;
|
||||
data[len++] = (crc16 >> 8) & 0xff;
|
||||
uart_send(UART2_PORT,len,data);
|
||||
}
|
||||
|
||||
// 雷达测离初始化
|
||||
void app_radar_init(void){
|
||||
// sftmr_init(); //main函数中已初始化
|
||||
sftmr_start(10, radar_timer_handler);
|
||||
}
|
||||
|
|
|
@ -2,22 +2,35 @@
|
|||
#define _RADAR_H_
|
||||
#include "sftmr.h"
|
||||
|
||||
#define BUFF_MAX 10
|
||||
|
||||
#define RADAR_BUFF_MAX 9
|
||||
|
||||
typedef struct radar_daraframe{
|
||||
volatile uint16_t Front_data;
|
||||
volatile uint16_t Back_data;
|
||||
} radar_daraframe_t;
|
||||
|
||||
extern radar_daraframe_t radar_daraframe;
|
||||
extern uint8_t radar_buff[];
|
||||
extern uint8_t Rec_lenght;
|
||||
enum RADAR_MODE{
|
||||
RADAR_MODE_Dispose = 0, //处理模式
|
||||
RADAR_MODE_Real = 1, //实时模式
|
||||
};
|
||||
|
||||
enum RADAR_ID{
|
||||
RADAR_ID_Front = 0x01, //前雷达ID
|
||||
RADAR_ID_Back = 0x02, //后雷达ID
|
||||
};
|
||||
|
||||
typedef struct radar_data{
|
||||
uint8_t radar_id;
|
||||
uint16_t distance;
|
||||
} radar_data_t;
|
||||
|
||||
extern radar_data_t radar_data;
|
||||
|
||||
// 雷达测离初始化
|
||||
void app_radar_init(void);
|
||||
|
||||
// 串口数据接收
|
||||
void app_radar_Receive(uint8_t data);
|
||||
|
||||
//发送读取实时值数据命令
|
||||
void app_radar_Sendcmd(uint8_t radar_id , uint8_t radar_mode);
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
#include "drvs.h"
|
||||
#include "dbg.h"
|
||||
#include "rbuf.h"
|
||||
|
||||
#include "sys_config.h"
|
||||
|
||||
#include "app_PAD.h"
|
||||
|
||||
void app_uart_Init(uint8_t port, uint32_t baudrate, uint8_t io_tx, uint8_t io_rx)
|
||||
{
|
||||
uart_init(port, io_tx, io_rx);
|
||||
|
@ -14,171 +17,6 @@ void app_uart_Init(uint8_t port, uint32_t baudrate, uint8_t io_tx, uint8_t io_rx
|
|||
NVIC_EnableIRQ(port==UART1_PORT?UART1_IRQn:UART2_IRQn);
|
||||
}
|
||||
|
||||
|
||||
//CRC-8/MAXIM:x8+X5+X4+1
|
||||
uint8_t crc8_checkout(uint8_t *buff, uint8_t length)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t crc = 0; //initial value
|
||||
|
||||
while (length--) {
|
||||
crc ^= *buff++; //crc ^= *buff; buff++;
|
||||
for(i = 0; i < 8; i++) {
|
||||
if(crc & 1)
|
||||
crc = (crc >> 1) ^ 0x8C; //0x8C = reverse 0x31
|
||||
else
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
// CRC-16/MODBUS polynomial: x^16 + x^15 + x^2 + 1 (0x8005)
|
||||
uint16_t crc16_checkout(uint8_t *buff, uint16_t length) {
|
||||
uint8_t i;
|
||||
uint16_t crc = 0xffff; // Initial value
|
||||
while (length--)
|
||||
{
|
||||
crc ^= *buff++;
|
||||
for (i = 0; i < 8; ++i)
|
||||
{
|
||||
if (crc & 1)
|
||||
crc = (crc >> 1) ^ 0xA001; // 0xA001 = reverse 0x8005
|
||||
else
|
||||
crc = (crc >> 1);
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uart_daraframe_t uart1_daraframe;
|
||||
volatile uint8_t uart1_state =0;
|
||||
volatile uint8_t uart1_data_cnt =0;
|
||||
|
||||
bool uart2_Back_car=0;
|
||||
|
||||
static void app_uart1_hande(void){
|
||||
uint8_t ret_data[MAX_LEN]={0,0};
|
||||
uint8_t length=0;
|
||||
|
||||
switch(uart1_daraframe.cmd_id){
|
||||
case 0x01: // 配置系统参数
|
||||
sys_conf_info.M_mode_sLim= uart1_daraframe.data[0];
|
||||
sys_conf_info.U_mode_sLim= uart1_daraframe.data[1];
|
||||
sys_conf_info.AUTO_Brake_Distance= uart1_daraframe.data[2];
|
||||
sys_conf_info.AUTO_Speed_Cut_Distance= uart1_daraframe.data[3];
|
||||
sys_conf_info.AUTO_Brake_Distance_B= uart1_daraframe.data[4];
|
||||
sys_conf_info.AUTO_Speed_Cut_Distance_B= uart1_daraframe.data[5];
|
||||
write_cfg(&sys_conf_info);
|
||||
case 0x02: // 读取系统配置
|
||||
ret_data[length++]=sys_conf_info.M_mode_sLim;
|
||||
ret_data[length++]=sys_conf_info.U_mode_sLim;
|
||||
ret_data[length++]=sys_conf_info.AUTO_Brake_Distance;
|
||||
ret_data[length++]=sys_conf_info.AUTO_Speed_Cut_Distance;
|
||||
ret_data[length++]=sys_conf_info.AUTO_Brake_Distance_B;
|
||||
ret_data[length++]=sys_conf_info.AUTO_Speed_Cut_Distance_B;
|
||||
|
||||
app_uart_Sendcmd(UART1_PORT,uart1_daraframe.cmd_id,0x01,ret_data,length);
|
||||
break;
|
||||
case 0x03: //0 命令控制进入管理员模式//1 命令控制进入游客模式
|
||||
PAD_Manager_Mode =uart1_daraframe.data[0];
|
||||
PAD_User_Mode =uart1_daraframe.data[1];
|
||||
if(1==PAD_User_Mode && 1==PAD_Manager_Mode){
|
||||
PAD_User_Mode=0;
|
||||
PAD_Manager_Mode=1;
|
||||
}
|
||||
app_uart_Sendcmd(UART1_PORT,uart1_daraframe.cmd_id,0x01,uart1_daraframe.data,uart1_daraframe.length);
|
||||
break;
|
||||
// case 0x04:
|
||||
|
||||
// break;
|
||||
|
||||
default :
|
||||
app_uart_Sendcmd(UART1_PORT,uart1_daraframe.cmd_id,uart1_daraframe.reg_addr,uart1_daraframe.data,uart1_daraframe.length);
|
||||
break;
|
||||
/*
|
||||
其他功能....
|
||||
*/
|
||||
}
|
||||
uart1_state =0;//数据处理完要清零,准备接收下一帧数据
|
||||
}
|
||||
|
||||
static void uart1_Receive(uint8_t data)
|
||||
{
|
||||
uint8_t *frame = (uint8_t *)&uart1_daraframe;
|
||||
|
||||
switch(uart1_state){
|
||||
case 0://header
|
||||
if ((data == (uint8_t)(FRAME_HEADER >> 8)) && (uart1_daraframe.header == 0x0)) {
|
||||
uart1_daraframe.header = (FRAME_HEADER >> 8);
|
||||
} else if ((data == (uint8_t)(FRAME_HEADER & 0x00FF)) && (uart1_daraframe.header == (uint8_t)(FRAME_HEADER >> 8))) {
|
||||
uart1_daraframe.header = ((uint16_t)((FRAME_HEADER << 8)|(FRAME_HEADER >> 8)));//0xA100;
|
||||
uart1_daraframe.length = 0;
|
||||
uart1_state = 1;//to cmd id
|
||||
//debug("header");
|
||||
}
|
||||
break;
|
||||
case 1://cmd_id
|
||||
//debug("rxcmd:%x", data);
|
||||
uart1_daraframe.cmd_id = data;
|
||||
uart1_state = 2;//to device addr
|
||||
break;
|
||||
case 2://reg addr
|
||||
//debug("reg_addr");
|
||||
uart1_daraframe.reg_addr = data;
|
||||
uart1_state = 3;//to data length
|
||||
break;
|
||||
case 3://data length
|
||||
//debug("length");
|
||||
uart1_daraframe.length = (data < MAX_LEN) ? data : MAX_LEN;
|
||||
if (uart1_daraframe.length == 0) {
|
||||
uart1_state = 5;//to crc
|
||||
} else {
|
||||
uart1_state = 4;//to data
|
||||
uart1_data_cnt = 0;
|
||||
}
|
||||
break;
|
||||
case 4://data
|
||||
//debug("data");
|
||||
if (uart1_data_cnt < uart1_daraframe.length) {
|
||||
uart1_daraframe.data[uart1_data_cnt++] = data;
|
||||
}
|
||||
if (uart1_data_cnt == uart1_daraframe.length) {
|
||||
uart1_data_cnt = 0;
|
||||
uart1_state = 5;//to crc
|
||||
}
|
||||
break;
|
||||
case 5://CRC8
|
||||
uart1_daraframe.crc = crc8_checkout(frame, 5 + uart1_daraframe.length);
|
||||
#if DISABLE_CRC8
|
||||
uart1_daraframe.crc = data;
|
||||
#endif
|
||||
//计算并验证crc8
|
||||
if (uart1_daraframe.crc == data) {
|
||||
uart1_state = 6;//to ack
|
||||
//debug("crc correct cmd:%x", uart1_daraframe.cmd_id);
|
||||
} else {
|
||||
uart1_state = 0;//to haeder
|
||||
uart1_daraframe.header = 0;
|
||||
//debug("crc error cmd:%x-%x", uart1_daraframe.cmd_id, uart1_daraframe.crc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// uart_putc(UART1_PORT,data);//debug
|
||||
// uart_putc(UART1_PORT,'0'+uart1_state);
|
||||
if(uart1_state == 6){
|
||||
uart1_daraframe.header = 0;
|
||||
uart1_state = 7;//数据处理完,需要将状态位归零,才会接收下一帧数据,即:uart1_state =0时。
|
||||
app_uart1_hande();
|
||||
uart1_state =0;
|
||||
/*
|
||||
rx handler codes....
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void UART1_IRQHandler(void)
|
||||
{
|
||||
uint32_t state = UART1->IFM.Word; // UART1->RIF.Word;
|
||||
|
@ -187,23 +25,17 @@ void UART1_IRQHandler(void)
|
|||
{
|
||||
UART1->IDR.RXRD = 1; // Disable RXRD Interrupt
|
||||
uint8_t data = UART1->RBR;
|
||||
app_radar_Receive(data);
|
||||
uart1_Receive(data);
|
||||
|
||||
app_PAD_Receive(data);
|
||||
UART1->ICR.RXRD = 1; // Clear RXRD Interrupt Flag
|
||||
UART1->IER.RXRD = 1; // Enable RXRD Interrupt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***************************************UART2*****************************************************
|
||||
*/
|
||||
|
||||
static void uart2_Receive(uint8_t data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UART2_IRQHandler(void)
|
||||
{
|
||||
uint32_t state = UART2->IFM.Word; // UART2->RIF.Word;
|
||||
|
@ -211,33 +43,11 @@ void UART2_IRQHandler(void)
|
|||
if (state & 0x01) //(BIT_RXRD)
|
||||
{
|
||||
UART2->IDR.RXRD = 1; // Disable RXRD Interrupt
|
||||
uint8_t data = UART2->RBR;
|
||||
|
||||
uart2_Receive(UART2->RBR);
|
||||
app_radar_Receive(data);
|
||||
UART2->ICR.RXRD = 1; // Clear RXRD Interrupt Flag
|
||||
UART2->IER.RXRD = 1; // Enable RXRD Interrupt
|
||||
}
|
||||
}
|
||||
|
||||
//发送命令
|
||||
void app_uart_Sendcmd(uint8_t port, volatile uint8_t cmd_id ,volatile uint8_t reg_addr ,volatile uint8_t *data, volatile uint8_t length)
|
||||
{
|
||||
uart_daraframe_t frame;
|
||||
uint8_t *cmd_data =(uint8_t *)&frame;
|
||||
uint8_t i;
|
||||
|
||||
frame.header = ((uint16_t)((FRAME_HEADER << 8)|(FRAME_HEADER >> 8)));//0xA100
|
||||
frame.cmd_id = cmd_id;
|
||||
frame.reg_addr = reg_addr;
|
||||
frame.length = length < MAX_LEN ? length:MAX_LEN;
|
||||
|
||||
for(i = 0;i < frame.length ;i ++){
|
||||
frame.data[i] = * data++;
|
||||
}
|
||||
length =5 + frame.length;
|
||||
frame.crc = crc8_checkout(cmd_data, length);
|
||||
while(length--)
|
||||
uart_putc(port, (uint32_t)(*cmd_data ++));
|
||||
uart_putc(port, (uint32_t)(frame.crc));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#define MAX_LEN 32
|
||||
|
||||
//1:失能数据校验
|
||||
#define DISABLE_CRC8 0
|
||||
//0:失能数据校验
|
||||
#define ENABLE_CRC8 1
|
||||
|
||||
typedef struct uart_daraframe
|
||||
{
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#include "drvs.h"
|
||||
#include "dbg.h"
|
||||
#include "app_ws2812.h"
|
||||
#include "sys_config.h"
|
||||
|
||||
|
||||
#define OUT_GRB_WS2812_DIN PA02
|
||||
#define OUT_GRB_WS2812_DIN RGB_DATA_IO
|
||||
|
||||
uint32_t ___WS2812_DIN___ =1<< OUT_GRB_WS2812_DIN;
|
||||
//0x02 = 1<<PA01
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
/// System Clock(0=16MHz, 1=32MHz, 2=48MHz, 3=64MHz)
|
||||
#define SYS_CLK (0)
|
||||
/// Debug Mode(0=Disable, 1=via UART, 2=via RTT)
|
||||
#define DBG_MODE (0)
|
||||
#define DBG_MODE (1)
|
||||
|
||||
#define UART_IRQ_MODE (0)
|
||||
#define UART_RTS_CTRL (1)
|
||||
|
|
|
@ -9,18 +9,22 @@
|
|||
#include "prf_sess.h"
|
||||
#include "sys_config.h"
|
||||
|
||||
#define DBG_MAIN_EN 1
|
||||
|
||||
#if (DBG_MAIN_EN)
|
||||
#include "dbg.h"
|
||||
#define DEBUG(format, ...) debug("[MAIN]" format "\r\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG(format, ...)
|
||||
#define debugHex(dat, len)
|
||||
#endif
|
||||
|
||||
|
||||
void HardFault_Handler(void){
|
||||
debug("HardFault_Handler\r\n");
|
||||
DEBUG("HardFault_Handler\r\n");
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
#define FLASH_INFO_CODE_ADDR (FLASH_BASE + 0x08)
|
||||
#define OTA_BANK_A_BASE (0x18004000)
|
||||
#define OTA_BANK_B_BASE (0x18020000)
|
||||
#define OTA_BANK_A (OTA_BANK_A_BASE - FLASH_BASE)
|
||||
#define OTA_BANK_B (OTA_BANK_B_BASE - FLASH_BASE)
|
||||
|
||||
|
||||
BLE_GRB_Data_t BLE_WS2812_GRBs;
|
||||
|
||||
|
@ -60,12 +64,14 @@ static void sysInit(void)
|
|||
APBMISC->XOSC16M_CTRL.XOSC16M_CAP_TR = 0x22;
|
||||
}
|
||||
|
||||
static void devInit(void)
|
||||
{
|
||||
static void devInit(void){
|
||||
uint16_t rsn = rstrsn();
|
||||
|
||||
dbgInit();
|
||||
// debug("Start(rsn:0x%X)...\r\n", rsn);
|
||||
iospc_rstpin(true);// 复用为GPIO
|
||||
|
||||
// dbgInit();
|
||||
DEBUG("Start(rsn:0x%X)...\r\n", rsn);// 复位原因
|
||||
|
||||
#if (1 ==BLE_ENABLE)
|
||||
// Init BLE App
|
||||
app_init(rsn);
|
||||
|
@ -120,104 +126,123 @@ static tmr_tk_t test_timer_handler(tmr_id_t id){
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t bank;
|
||||
SYS_CONF_t sys_conf_info;
|
||||
|
||||
__attribute__((section("ram_func.fshc.")))
|
||||
static void flash_sector_erase(uint32_t offset)
|
||||
{
|
||||
GLOBAL_INT_DISABLE();
|
||||
|
||||
while (SYSCFG->ACC_CCR_BUSY);
|
||||
|
||||
fshc_erase(offset, FSH_CMD_ER_SECTOR);
|
||||
|
||||
GLOBAL_INT_RESTORE();
|
||||
}
|
||||
|
||||
void write_cfg(SYS_CONF_t *sys_config_info_t){
|
||||
flash_sector_erase(bank);
|
||||
flash_write(bank, (uint32_t *)sys_config_info_t,sizeof(SYS_CONF_t)/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
sysInit();
|
||||
devInit();
|
||||
sysInit();
|
||||
devInit();
|
||||
|
||||
// Global Interrupt Enable
|
||||
GLOBAL_INT_START();
|
||||
// Global Interrupt Enable
|
||||
GLOBAL_INT_START();
|
||||
/****************
|
||||
bootDelayMs(2000);
|
||||
gpio_dir_output(PA02, OE_HIGH);
|
||||
gpio_dir_output(PA03, OE_HIGH);
|
||||
gpio_dir_output(PA04, OE_HIGH);
|
||||
gpio_dir_output(PA05, OE_HIGH);
|
||||
gpio_dir_output(PA06, OE_HIGH);
|
||||
gpio_dir_output(PA07, OE_HIGH);
|
||||
gpio_dir_output(PA08, OE_HIGH);
|
||||
gpio_dir_output(PA09, OE_HIGH);
|
||||
gpio_dir_output(PA10, OE_HIGH);
|
||||
gpio_dir_output(PA11, OE_HIGH);
|
||||
gpio_dir_output(PA12, OE_HIGH);
|
||||
gpio_dir_output(PA13, OE_HIGH);
|
||||
gpio_dir_output(PA14, OE_HIGH);
|
||||
gpio_dir_output(PA15, OE_HIGH);
|
||||
gpio_dir_output(PA16, OE_HIGH);
|
||||
gpio_dir_output(PA17, OE_HIGH);
|
||||
gpio_dir_output(PA18, OE_HIGH);
|
||||
gpio_dir_output(PA19, OE_HIGH);
|
||||
|
||||
uint32_t curr_code_addr = RD_32(FLASH_INFO_CODE_ADDR);
|
||||
if(curr_code_addr == OTA_BANK_A_BASE)
|
||||
{
|
||||
bank = OTA_BANK_B;
|
||||
while(1){
|
||||
gpio_put(PA02, OE_HIGH);
|
||||
gpio_put(PA03, OE_HIGH);
|
||||
gpio_put(PA04, OE_HIGH);
|
||||
gpio_put(PA05, OE_HIGH);
|
||||
gpio_put(PA06, OE_HIGH);
|
||||
gpio_put(PA07, OE_HIGH);
|
||||
gpio_put(PA08, OE_HIGH);
|
||||
gpio_put(PA09, OE_HIGH);
|
||||
gpio_put(PA10, OE_HIGH);
|
||||
gpio_put(PA11, OE_HIGH);
|
||||
gpio_put(PA12, OE_HIGH);
|
||||
gpio_put(PA13, OE_HIGH);
|
||||
gpio_put(PA14, OE_HIGH);
|
||||
gpio_put(PA15, OE_HIGH);
|
||||
gpio_put(PA16, OE_HIGH);
|
||||
gpio_put(PA17, OE_HIGH);
|
||||
gpio_put(PA18, OE_HIGH);
|
||||
gpio_put(PA19, OE_HIGH);
|
||||
bootDelayMs(200);
|
||||
gpio_put(PA02, OE_LOW);
|
||||
gpio_put(PA03, OE_LOW);
|
||||
gpio_put(PA04, OE_LOW);
|
||||
gpio_put(PA05, OE_LOW);
|
||||
gpio_put(PA06, OE_LOW);
|
||||
gpio_put(PA07, OE_LOW);
|
||||
gpio_put(PA08, OE_LOW);
|
||||
gpio_put(PA09, OE_LOW);
|
||||
gpio_put(PA10, OE_LOW);
|
||||
gpio_put(PA11, OE_LOW);
|
||||
gpio_put(PA12, OE_LOW);
|
||||
gpio_put(PA13, OE_LOW);
|
||||
gpio_put(PA14, OE_LOW);
|
||||
gpio_put(PA15, OE_LOW);
|
||||
gpio_put(PA16, OE_LOW);
|
||||
gpio_put(PA17, OE_LOW);
|
||||
gpio_put(PA18, OE_LOW);
|
||||
gpio_put(PA19, OE_LOW);
|
||||
bootDelayMs(200);
|
||||
}
|
||||
else if(curr_code_addr == OTA_BANK_B_BASE)
|
||||
{
|
||||
bank = OTA_BANK_A;
|
||||
*****************/
|
||||
|
||||
app_uart_Init(UART1_PORT,9600,PAD_TXD1,PAD_RXD1);//上位机PAD
|
||||
app_uart_Init(UART2_PORT,9600,RADAR_TXD0,RADAR_RXD0);//雷达
|
||||
app_control_init();
|
||||
app_radar_init();
|
||||
Time_Event_Init();
|
||||
GRB_WS2812_Init();
|
||||
BAT_Message_Init();
|
||||
|
||||
// read config
|
||||
uint8_t ret = read_cfg(&sys_conf);
|
||||
if(ret || sys_conf.VERSION != SOFTWARE_ID){
|
||||
DEBUG("Read Config ERROR!\r\n");//读取配置文件失败//使用默认配置
|
||||
sys_conf.VERSION =SOFTWARE_ID;
|
||||
sys_conf.Manager_sLim = D_Manager_sLim,
|
||||
sys_conf.Tourist_sLim = D_Tourist_sLim,
|
||||
sys_conf.Speed_Cut_sLim = D_Speed_Cut_sLim,
|
||||
sys_conf.Brake_DLimit = D_Brake_DLimit,//自动刹车距离
|
||||
sys_conf.Speed_Cut_DLimit = D_Speed_Cut_DLimit,//自动减速距离
|
||||
sys_conf.Brake_DLimit_B = D_Brake_DLimit_B,//自动刹车距离
|
||||
sys_conf.Speed_Cut_DLimit_B = D_Speed_Cut_DLimit_B,//自动减速距离
|
||||
sys_conf.Reserve =0;
|
||||
write_cfg(&sys_conf);
|
||||
}
|
||||
// read config
|
||||
// read flash
|
||||
flash_read(bank, (uint32_t *)(&sys_conf_info),sizeof(sys_conf_info)/sizeof(uint32_t));
|
||||
DEBUG("sys_conf:lenght=%d",sizeof(sys_conf));
|
||||
DEBUG("VERSION:%#04X",sys_conf.VERSION);
|
||||
DEBUG("Manager_sLim:%d",sys_conf.Manager_sLim);
|
||||
DEBUG("Tourist_sLim:%d",sys_conf.Tourist_sLim);
|
||||
DEBUG("Speed_Cut_sLim:%d",sys_conf.Speed_Cut_sLim);
|
||||
DEBUG("Brake_DLimit:%d",sys_conf.Brake_DLimit);
|
||||
DEBUG("Speed_Cut_DLimit:%d",sys_conf.Speed_Cut_DLimit);
|
||||
DEBUG("Brake_DLimit_B:%d",sys_conf.Brake_DLimit_B);
|
||||
DEBUG("Speed_Cut_DLimit_B:%d",sys_conf.Speed_Cut_DLimit_B);
|
||||
|
||||
if(0xA5 !=sys_conf_info.HEAD){
|
||||
sys_conf_info.HEAD=0xA5;
|
||||
sys_conf_info.M_mode_sLim = M_DEFAULT_sLim,//read flash
|
||||
sys_conf_info.U_mode_sLim = U_DEFAULT_sLim,//read flash
|
||||
sys_conf_info.AUTO_Brake_Distance =DEF_AUTO_Brake_Distance,//自动刹车距离
|
||||
sys_conf_info.AUTO_Speed_Cut_Distance =DEF_AUTO_Speed_Cut_Distance,//自动减速距离
|
||||
sys_conf_info.AUTO_Brake_Distance_B =DEF_AUTO_Brake_Distance,//自动刹车距离
|
||||
sys_conf_info.AUTO_Speed_Cut_Distance_B =DEF_AUTO_Speed_Cut_Distance,//自动减速距离
|
||||
write_cfg(&sys_conf_info);
|
||||
}
|
||||
|
||||
|
||||
app_uart_Init(UART1_PORT,9600,PA06,PA07);//上位机//倒车雷达
|
||||
// app_uart_Init(UART2_PORT,9600,20,PA03);
|
||||
|
||||
app_control_init();
|
||||
app_radar_init();
|
||||
Time_Event_Init();
|
||||
|
||||
uint8_t str[50]={0,0},str_len=0;
|
||||
|
||||
str_len =sprintf((char *)str, "HEAD=%#X,M_s=%d,U_s=%d\n Brake=%d,Speed_Cut=%d\n Brake_B=%d,Speed_Cut_B=%d\n OKzsxfly",
|
||||
sys_conf_info.HEAD,
|
||||
sys_conf_info.M_mode_sLim,
|
||||
sys_conf_info.U_mode_sLim,
|
||||
sys_conf_info.AUTO_Brake_Distance,
|
||||
sys_conf_info.AUTO_Speed_Cut_Distance,
|
||||
sys_conf_info.AUTO_Brake_Distance_B,
|
||||
sys_conf_info.AUTO_Speed_Cut_Distance_B);
|
||||
uart_send(UART1_PORT,str_len,str);
|
||||
|
||||
GRB_WS2812_Init();
|
||||
|
||||
// GRB_WS2812_Write_color(WS2812_GRBs.len,0xff);
|
||||
// bootDelayMs(1000);
|
||||
// GRB_WS2812_Write_color(WS2812_GRBs.len,0x00);
|
||||
// bootDelayMs(1000);
|
||||
// GRB_WS2812_Write_color(WS2812_GRBs.len,0xff00);
|
||||
// bootDelayMs(1000);
|
||||
// GRB_WS2812_Write_color(WS2812_GRBs.len,0x00);
|
||||
// bootDelayMs(1000);
|
||||
// GRB_WS2812_Write_color(WS2812_GRBs.len,0xff0000);
|
||||
// bootDelayMs(1000);
|
||||
|
||||
BAT_Message_Init();
|
||||
#if (1 ==BLE_ENABLE)
|
||||
// ADC初始化
|
||||
sftmr_start(20, test_timer_handler);
|
||||
#endif
|
||||
|
||||
while(1){
|
||||
// SoftTimer Polling
|
||||
sftmr_schedule();
|
||||
|
||||
#if (1 ==BLE_ENABLE)
|
||||
// Schedule Messages & Events
|
||||
ble_schedule();
|
||||
#endif
|
||||
|
||||
// User's Procedure
|
||||
// app_ble_procedure();
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#include "b6x.h"
|
||||
#include "regs.h"
|
||||
#include "drvs.h"
|
||||
#include "dbg.h"
|
||||
#include "sftmr.h"
|
||||
#include "CRCxx.h"
|
||||
|
||||
#include "bledef.h"
|
||||
#include "app.h"
|
||||
#include "prf_sess.h"
|
||||
|
||||
#include "sys_config.h"
|
||||
|
||||
#define DBG_CONF_EN 1
|
||||
|
||||
#if (DBG_CONF_EN)
|
||||
#include "dbg.h"
|
||||
#define DEBUG(format, ...) debug("[CONF]" format "\r\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG(format, ...)
|
||||
#define debugHex(dat, len)
|
||||
#endif
|
||||
|
||||
|
||||
SYS_CONF_t sys_conf;
|
||||
|
||||
// __attribute__((section("ram_func.fshc.")))
|
||||
// static void flash_sector_erase(uint32_t offset)
|
||||
// {
|
||||
// GLOBAL_INT_DISABLE();
|
||||
|
||||
// while (SYSCFG->ACC_CCR_BUSY);
|
||||
|
||||
// fshc_erase(offset, FSH_CMD_ER_SECTOR);
|
||||
|
||||
// GLOBAL_INT_RESTORE();
|
||||
// }
|
||||
|
||||
|
||||
// 写配置
|
||||
void write_cfg(SYS_CONF_t *sys_config_info_t){
|
||||
flash_page_erase(CONF_OFFSET_ADDR & 0x00FFFF00);
|
||||
|
||||
sys_config_info_t->CRC16 = crc16_modbus((uint8_t *)sys_config_info_t,sizeof(SYS_CONF_t)-2); //计算CRC16
|
||||
DEBUG("Write: CRC16:%#04x",sys_config_info_t->CRC16);
|
||||
flash_write(CONF_OFFSET_ADDR & 0x00FFFF00, (uint32_t *)sys_config_info_t,sizeof(SYS_CONF_t)/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
// 读配置 // 返回 0 成功 1 数据校验错误
|
||||
uint8_t read_cfg(SYS_CONF_t *sys_config_info_t){
|
||||
uint16_t crc16;
|
||||
|
||||
flash_read(CONF_OFFSET_ADDR & 0x00FFFF00, (uint32_t *)sys_config_info_t,sizeof(SYS_CONF_t)/sizeof(uint32_t));
|
||||
|
||||
crc16 = crc16_modbus((uint8_t *)sys_config_info_t,sizeof(SYS_CONF_t)-2); //计算CRC16
|
||||
DEBUG("READ: CRC16:%#04x ,CRC16_CAL:%#04x",sys_config_info_t->CRC16 ,crc16);
|
||||
|
||||
return ((sys_config_info_t->CRC16 == crc16) ? 0 : 1);
|
||||
}
|
||||
|
||||
void conf_init(void){
|
||||
// read config
|
||||
if(read_cfg(&sys_conf)){
|
||||
DEBUG("Read Config :CRC_ERROR ");//读取配置文件失败//使用默认配置
|
||||
sys_conf.VERSION =SOFTWARE_ID;
|
||||
sys_conf.Manager_sLim = D_Manager_sLim,
|
||||
sys_conf.Tourist_sLim = D_Tourist_sLim,
|
||||
sys_conf.Speed_Cut_sLim = D_Speed_Cut_sLim,//(自动减速时油门极限)
|
||||
sys_conf.Brake_DLimit = D_Brake_DLimit,//自动刹车距离(前进)
|
||||
sys_conf.Speed_Cut_DLimit = D_Speed_Cut_DLimit,//自动减速距离
|
||||
sys_conf.Brake_DLimit_B = D_Brake_DLimit_B,//自动刹车距离(后退)
|
||||
sys_conf.Speed_Cut_DLimit_B = D_Speed_Cut_DLimit_B,//自动减速距离
|
||||
sys_conf.Reserve =0;
|
||||
DEBUG("write Default Config!!!");// 写入默认配置
|
||||
write_cfg(&sys_conf);
|
||||
}
|
||||
DEBUG("\nsys_conf:lenght=%d",sizeof(sys_conf));
|
||||
DEBUG("VERSION:%#04X",sys_conf.VERSION);
|
||||
DEBUG("Manager_sLim:%d",sys_conf.Manager_sLim);
|
||||
DEBUG("Tourist_sLim:%d",sys_conf.Tourist_sLim);
|
||||
DEBUG("Speed_Cut_sLim:%d",sys_conf.Speed_Cut_sLim);
|
||||
DEBUG("Brake_DLimit:%d",sys_conf.Brake_DLimit);
|
||||
DEBUG("Speed_Cut_DLimit:%d",sys_conf.Speed_Cut_DLimit);
|
||||
DEBUG("Brake_DLimit_B:%d",sys_conf.Brake_DLimit_B);
|
||||
DEBUG("Speed_Cut_DLimit_B:%d\n",sys_conf.Speed_Cut_DLimit_B);
|
||||
}
|
||||
|
|
@ -5,26 +5,37 @@
|
|||
#include "stdio.h"
|
||||
#include "app_radar.h"
|
||||
#include "app_ws2812.h"
|
||||
#include "app_buzzer.h"
|
||||
#include "app_Time_Event.h"
|
||||
#include "app_bat.h"
|
||||
#include "app_PAD.h"
|
||||
|
||||
|
||||
// 存储在第1扇区第0页
|
||||
#define CONF_OFFSET_BASE (0x18001000) // 配置信息存储地址(以页为单位:0x100)
|
||||
#define CONF_OFFSET_ADDR (CONF_OFFSET_BASE - FLASH_BASE)
|
||||
|
||||
// 必须4字节对齐
|
||||
typedef struct SYS_CONF{
|
||||
uint32_t HEAD;
|
||||
uint32_t M_mode_sLim;
|
||||
uint32_t U_mode_sLim;
|
||||
uint32_t AUTO_Brake_Distance;
|
||||
uint32_t AUTO_Speed_Cut_Distance;
|
||||
uint32_t AUTO_Brake_Distance_B;
|
||||
uint32_t AUTO_Speed_Cut_Distance_B;
|
||||
|
||||
uint16_t VERSION; // 软件版本号
|
||||
uint8_t Manager_sLim; // 管理员模式油门极限(Unit:%)
|
||||
uint8_t Tourist_sLim; // 游客模式油门极限
|
||||
uint8_t Speed_Cut_sLim; // 减速油门极限(Unit:%)(自动减速时油门极限)
|
||||
uint8_t Reserve; // 保留凑足4字节对齐
|
||||
uint16_t Brake_DLimit; // 刹车距离极限(前进)(Unit:mm)
|
||||
uint16_t Speed_Cut_DLimit; // 减速距离极限
|
||||
uint16_t Brake_DLimit_B; // 刹车距离极限(后退)
|
||||
uint16_t Speed_Cut_DLimit_B;// 减速距离极限
|
||||
uint16_t CRC16; // 配置信息CRC16校验码
|
||||
}SYS_CONF_t;
|
||||
|
||||
extern uint32_t bank;
|
||||
extern SYS_CONF_t sys_conf_info;
|
||||
extern SYS_CONF_t sys_conf;
|
||||
extern BAT_Message_t BAT_Message;
|
||||
|
||||
// 写配置
|
||||
void write_cfg(SYS_CONF_t *sys_config_info_t);
|
||||
// 读配置
|
||||
uint8_t read_cfg(SYS_CONF_t *sys_config_info_t);
|
||||
|
||||
|
||||
|
||||
// 油门ADC
|
||||
|
@ -32,29 +43,36 @@ void write_cfg(SYS_CONF_t *sys_config_info_t);
|
|||
#define ACC_DOWN_Res 5.1 //下分压电阻
|
||||
|
||||
// 电池ADC
|
||||
#define BAT_UP_Res 68.0 //上分压电阻(unit:KΩ)
|
||||
#define BAT_DOWN_Res 3.0 //下分压电阻
|
||||
#define BAT_UP_Res 197.0 //上分压电阻(unit:KΩ)
|
||||
#define BAT_DOWN_Res 4.7 //下分压电阻
|
||||
|
||||
|
||||
/*****************************速度************************/
|
||||
// 管理员模式默认速度极限(0-100%)
|
||||
#define M_DEFAULT_sLim 100
|
||||
// 游客模式默认速度极限(0-100%)
|
||||
#define U_DEFAULT_sLim 50
|
||||
|
||||
|
||||
/*****************************刹车************************/
|
||||
// 默认自动刹车距离0~45dm(分米)
|
||||
#define DEF_AUTO_Brake_Distance 10
|
||||
// 默认自动减速距离0~45dm
|
||||
#define DEF_AUTO_Speed_Cut_Distance 16
|
||||
/**************************系统版本**************************/
|
||||
// 软件本号
|
||||
#define SOFTWARE_ID 0x0101
|
||||
/************************油门(Unit:%)************************/
|
||||
// 管理员模式默认油门极限(0-100%)
|
||||
#define D_Manager_sLim 100
|
||||
// 游客模式默认油门极限(0-100%)
|
||||
#define D_Tourist_sLim 50
|
||||
// 减速油门极限(0-100%)(自动减速时油门极限)
|
||||
#define D_Speed_Cut_sLim 50
|
||||
/*****************刹车减速距离(前进)(Unit:mm)*****************/
|
||||
// 默认自动刹车距离35~4500mm(毫米)
|
||||
#define D_Brake_DLimit 1000
|
||||
// 默认自动减速距离35~4500mm
|
||||
#define D_Speed_Cut_DLimit 1600
|
||||
/*****************刹车减速距离(后退)(Unit:mm)*****************/
|
||||
// 默认自动刹车距离35~4500mm(毫米)
|
||||
#define D_Brake_DLimit_B 1000
|
||||
// 默认自动减速距离35~4500mm
|
||||
#define D_Speed_Cut_DLimit_B 1600
|
||||
|
||||
|
||||
/*****************************BLE************************/
|
||||
#define BLE_ENABLE 0
|
||||
|
||||
|
||||
|
||||
/*****************************雷达************************/
|
||||
#define RADAR_MODE 0 // 0:电应普 1:FD07-3
|
||||
|
||||
|
|
Loading…
Reference in New Issue