第一次提交
This commit is contained in:
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
*.bak
|
||||||
|
*.ddk
|
||||||
|
*.edk
|
||||||
|
*.lst
|
||||||
|
*.lnp
|
||||||
|
*.mpf
|
||||||
|
*.mpj
|
||||||
|
*.obj
|
||||||
|
*.omf
|
||||||
|
*.plg
|
||||||
|
*.rpt
|
||||||
|
*.tmp
|
||||||
|
*.__i
|
||||||
|
*.crf
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
*.axf
|
||||||
|
*.tra
|
||||||
|
*.dep
|
||||||
|
JLinkLog.txt
|
||||||
|
*.iex
|
||||||
|
*.htm
|
||||||
|
*.sct
|
||||||
|
*.map
|
||||||
|
*.Administrator
|
||||||
|
*.uvopt
|
||||||
123
App/app_get_json.c
Normal file
123
App/app_get_json.c
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#include "app_get_json.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "bsp_uart.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include <stdlib.h> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>atoi<6F><69><EFBFBD><EFBFBD>
|
||||||
|
#include "app_scan.h"
|
||||||
|
|
||||||
|
uint8_t uart_rx_buffer[1024];
|
||||||
|
cJSON *cjson = NULL;
|
||||||
|
int Max_resis;
|
||||||
|
int Min_resis;
|
||||||
|
int Div_resis;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD>鵽uint8_t<5F><74><EFBFBD><EFBFBD>
|
||||||
|
// json_arr: cJSON<4F><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, arr: Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, max_len: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
void parse_json_array(cJSON *json_item, uint8_t *arr, int max_len) {
|
||||||
|
// 1. <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
memset(arr, 0, max_len * sizeof(uint8_t));
|
||||||
|
|
||||||
|
// 2. <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>
|
||||||
|
if (json_item == NULL || !cJSON_IsString(json_item) || json_item->valuestring == NULL) {
|
||||||
|
return; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭJSON<4F><4E><EFBFBD>ݣ<EFBFBD>
|
||||||
|
char temp_buf[64] = {0}; // <20>㹻<EFBFBD><E3B9BB><EFBFBD><EFBFBD>12<31><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD>ŵij<C5B5><C4B3><EFBFBD>
|
||||||
|
strncpy(temp_buf, json_item->valuestring, sizeof(temp_buf) - 1);
|
||||||
|
|
||||||
|
// 4. <20><><EFBFBD><EFBFBD><EFBFBD>ŷָ<C5B7><D6B8>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
char *token = strtok(temp_buf, ",");
|
||||||
|
int idx = 0;
|
||||||
|
while (token != NULL && idx < max_len) {
|
||||||
|
// <20>ѷָ<D1B7><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>תΪ<D7AA><CEAA><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
arr[idx++] = (uint8_t)atoi(token);
|
||||||
|
token = strtok(NULL, ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int get_Json_data(json_data_struct * sys){
|
||||||
|
int result = -1; // 1 <20><>ʾ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||||
|
uint16_t uart_get_num = usart_rx_get_rx_data_count(USART_3_TR);
|
||||||
|
|
||||||
|
// ֻ<>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ž<EFBFBD><C5BD>н<EFBFBD><D0BD><EFBFBD>
|
||||||
|
if(uart_get_num > 0 && uart_get_num < sizeof(uart_rx_buffer)){ // <20><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint16_t get_size = usart_rx_recv(USART_3_TR, uart_rx_buffer, uart_get_num);
|
||||||
|
|
||||||
|
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD>ɹ<EFBFBD>
|
||||||
|
if(get_size != uart_get_num){
|
||||||
|
memset(uart_rx_buffer, 0, sizeof(uart_rx_buffer)); // <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
return -2; // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʧ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD>ͷ<EFBFBD>֮ǰ<D6AE><C7B0>cJSON<4F>ڴ棬<DAB4><E6A3AC><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
||||||
|
if(cjson != NULL ){
|
||||||
|
cJSON_Delete(cjson);
|
||||||
|
cjson = NULL; // <20>ͷź<CDB7><C5BA>ÿգ<C3BF><D5A3><EFBFBD><EFBFBD><EFBFBD>Ұָ<D2B0><D6B8>
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>JSON<4F>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תΪcJSON<4F><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
cjson = cJSON_Parse((const char*)uart_rx_buffer);
|
||||||
|
memset(uart_rx_buffer, 0, sizeof(uart_rx_buffer));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if (cjson != NULL) {
|
||||||
|
// 2. <20><><EFBFBD>λ<EFBFBD>ȡJSON<4F>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>
|
||||||
|
cJSON *Max_resis_item = cJSON_GetObjectItem(cjson, "Max_resis");
|
||||||
|
cJSON *Min_resis_item = cJSON_GetObjectItem(cjson, "Min_resis");
|
||||||
|
cJSON *Div_resis_item = cJSON_GetObjectItem(cjson, "Div_resis");
|
||||||
|
|
||||||
|
|
||||||
|
cJSON *x_rank_arr = cJSON_GetObjectItem(cjson, "x_rank");
|
||||||
|
cJSON *y_rank_arr = cJSON_GetObjectItem(cjson, "y_rank");
|
||||||
|
if(x_rank_arr != NULL && y_rank_arr != NULL)
|
||||||
|
{
|
||||||
|
uint8_t x_rank[12] = {0};
|
||||||
|
parse_json_array(x_rank_arr, x_rank, 12);
|
||||||
|
|
||||||
|
// 3. ֱ<>ӽ<EFBFBD><D3BD><EFBFBD>y_rank JSON<4F><4E><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
uint8_t y_rank[12] = {0};
|
||||||
|
parse_json_array(y_rank_arr, y_rank, 12);
|
||||||
|
|
||||||
|
// 4. <20><><EFBFBD>ñ<EFBFBD><C3B1>溯<EFBFBD><E6BAAF>
|
||||||
|
save_config_ranks(x_rank, y_rank);
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ֶ<EFBFBD><D6B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>JSON<4F><4E>ֵ<EFBFBD><D6B5><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>
|
||||||
|
if(Max_resis_item != NULL && cJSON_IsString(Max_resis_item) &&
|
||||||
|
Min_resis_item != NULL && cJSON_IsString(Min_resis_item) &&
|
||||||
|
Div_resis_item != NULL && cJSON_IsString(Div_resis_item))
|
||||||
|
{
|
||||||
|
// 3. <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ֵת<D6B5><D7AA>Ϊint<6E><74><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||||
|
Max_resis = atoi(Max_resis_item->valuestring);
|
||||||
|
Min_resis = atoi(Min_resis_item->valuestring);
|
||||||
|
Div_resis = atoi(Div_resis_item->valuestring);
|
||||||
|
sys->max_trigger_res_value = Max_resis;
|
||||||
|
sys->min_trigger_res_value = Min_resis;
|
||||||
|
sys->div_trigger_res = Div_resis;
|
||||||
|
result = 1; // <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = -3; // <20>ֶ<EFBFBD>ȱʧ<C8B1><CAA7><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. <20><><EFBFBD><EFBFBD>cJSON<4F>ڴ棨<DAB4><E6A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷţ<CDB7><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©<D0B9><C2A9>
|
||||||
|
cJSON_Delete(cjson);
|
||||||
|
cjson = NULL; // <20>ÿգ<C3BF><D5A3><EFBFBD>ֹ<EFBFBD>ظ<EFBFBD><D8B8>ͷ<EFBFBD>
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = -4; // JSON<4F><4E>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><F3A3ACBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD>մ<EFBFBD><D5B4>ڽ<EFBFBD><DABD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD>һ<EFBFBD>ν<EFBFBD><CEBD><EFBFBD>
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = -5; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
31
App/app_get_json.h
Normal file
31
App/app_get_json.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef _APP_GET_JSON_H
|
||||||
|
#define _APP_GET_JSON_H
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
|
||||||
|
#pragma pack (1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t output_mode;
|
||||||
|
uint16_t output_ax;
|
||||||
|
uint16_t output_ay;
|
||||||
|
uint16_t min_trigger_res_value;
|
||||||
|
uint16_t max_trigger_res_value;
|
||||||
|
uint16_t div_trigger_res;
|
||||||
|
}json_data_struct;
|
||||||
|
|
||||||
|
typedef int (*json_cmd_handle)(void *data);
|
||||||
|
|
||||||
|
typedef struct json_callback_struct
|
||||||
|
{
|
||||||
|
char * name; //json<6F><6E>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
||||||
|
json_cmd_handle handle; //<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
struct json_callback_struct *child_ptr; //<2F><>Ŀ¼
|
||||||
|
uint8_t child_num; //<2F><>Ŀ¼<C4BF><C2BC>Ŀ
|
||||||
|
}json_callback_t;
|
||||||
|
#pragma pack ()
|
||||||
|
|
||||||
|
int get_Json_data(json_data_struct * sys);
|
||||||
|
cJSON* creat_body_json(uint8_t style,int coor_x, int coor_y);
|
||||||
|
|
||||||
|
#endif
|
||||||
398
App/app_math_info.c
Normal file
398
App/app_math_info.c
Normal file
@@ -0,0 +1,398 @@
|
|||||||
|
#include "app_math_info.h"
|
||||||
|
|
||||||
|
uint8_t frame_state =0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>֡״̬
|
||||||
|
uint8_t cali_frame_state =0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уָ<D7BC><D6B8>֡״̬
|
||||||
|
|
||||||
|
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ģʽ<C4A3><CABD>Ĭ<EFBFBD><C4AC>״̬ģʽ<C4A3><CABD>
|
||||||
|
ARRAY_RESI_INIT_MODE_TYPE_T resi_init_mode = STATE;
|
||||||
|
|
||||||
|
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уģʽ<C4A3><CABD>Ĭ<EFBFBD>ϳ<EFBFBD>ʼ״̬<D7B4><CCAC>
|
||||||
|
ARRAY_RESI_CALI_MODE_TYPE_T resi_cali_mode = CALI_INIT;
|
||||||
|
|
||||||
|
uint8_t array_resi_init_params_read_buf[MAX_BUF_SIZE] = {0};
|
||||||
|
uint8_t array_resi_init_params_write_buf[MAX_BUF_SIZE] = {0};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD>Y<EFBFBD>ᣩ
|
||||||
|
uint8_t cali_adc_params[CALI_POINT_NUM * AX_NUM * AY_NUM] = {0};
|
||||||
|
|
||||||
|
// ȫ<>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t array_resi_cali_params_write_buf[MAX_BUF_SIZE] = {0};
|
||||||
|
uint8_t array_resi_cali_params_read_buf[MAX_BUF_SIZE] = {0};
|
||||||
|
|
||||||
|
uint8_t success_protocal[ARRAY_RESI_INIT_PARAMS_LEN] = {0x6F,0x6F,0x6F,0x6B,0x6B,0x6B};
|
||||||
|
uint8_t fail_protocal[ARRAY_RESI_INIT_PARAMS_LEN] = {0x6E,0x6E,0x6E,0x6F,0x6F,0x6F};
|
||||||
|
//static uint8_t static_protocal[ARRAY_RESI_INIT_PARAMS_LEN] = {0};
|
||||||
|
//extern uint8_t adc_read_sw;
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>ģʽ
|
||||||
|
* @param state<74><65>ģʽ<C4A3><CABD>STATE/DATA<54><41>
|
||||||
|
*/
|
||||||
|
void set_array_resi_init_mode_type(ARRAY_RESI_INIT_MODE_TYPE_T state)
|
||||||
|
{
|
||||||
|
resi_init_mode = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>ģʽ
|
||||||
|
* @return <20><>ǰģʽ
|
||||||
|
*/
|
||||||
|
ARRAY_RESI_INIT_MODE_TYPE_T get_resi_array_init_mode_type(void)
|
||||||
|
{
|
||||||
|
return resi_init_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уģʽ
|
||||||
|
* @param state<74><65>ģʽ<C4A3><CABD>CALI_SUCCESS/CALI_FAIL<49>ȣ<EFBFBD>
|
||||||
|
*/
|
||||||
|
void set_array_resi_cali_mode_type(ARRAY_RESI_CALI_MODE_TYPE_T state)
|
||||||
|
{
|
||||||
|
resi_cali_mode = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уģʽ
|
||||||
|
* @return <20><>ǰģʽ
|
||||||
|
*/
|
||||||
|
ARRAY_RESI_CALI_MODE_TYPE_T get_resi_array_cali_mode_type(void)
|
||||||
|
{
|
||||||
|
return resi_cali_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t array_resi_params_write(mx_frame_struct *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct frame;
|
||||||
|
|
||||||
|
// 1. <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint16_t min_resi = (buf->data[1] << 8) | buf->data[0];
|
||||||
|
uint16_t max_resi = (buf->data[3] << 8) | buf->data[2];
|
||||||
|
uint16_t ref_resi = (buf->data[5] << 8) | buf->data[4];
|
||||||
|
|
||||||
|
//printf("min_resi is %d, %d %d\n",min_resi,max_resi,ref_resi);
|
||||||
|
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>
|
||||||
|
if(min_resi >= max_resi) {
|
||||||
|
frame.trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(STATE);
|
||||||
|
frame.type = get_resi_array_init_mode_type();
|
||||||
|
frame.data = fail_protocal;
|
||||||
|
frame.datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, &frame);
|
||||||
|
return 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. ? <20><><EFBFBD>µ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>棩
|
||||||
|
g_sys_config.min_trigger_res_value = min_resi;
|
||||||
|
g_sys_config.max_trigger_res_value = max_resi;
|
||||||
|
g_sys_config.div_trigger_res = ref_resi;
|
||||||
|
|
||||||
|
// 4. Ӧ<>õ<EFBFBD><C3B5><EFBFBD>ѧ<EFBFBD><D1A7>
|
||||||
|
// math_resi_init(max_resi, min_resi, ref_resi, MAX_ADC_VALUE, DEFAULT_MAX_DISPLAY_VALUE);
|
||||||
|
// min_trigger_res_value1
|
||||||
|
math_resi_init(g_sys_config.max_trigger_res_value, g_sys_config.min_trigger_res_value, g_sys_config.div_trigger_res, 4096, 255);
|
||||||
|
|
||||||
|
// 5. <20><><EFBFBD>ͳɹ<CDB3>Ӧ<EFBFBD><D3A6>
|
||||||
|
frame.trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(DATA);
|
||||||
|
frame.type = get_resi_array_init_mode_type();
|
||||||
|
frame.data = success_protocal;
|
||||||
|
frame.datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, &frame);
|
||||||
|
|
||||||
|
return 1; // <20>ɹ<EFBFBD>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Flash
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2>־û<D6BE><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
uint8_t array_resi_params_save(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
// 1. <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
static uint16_t min_resi=0;
|
||||||
|
static uint16_t max_resi=0;
|
||||||
|
static uint16_t ref_resi=0;
|
||||||
|
min_resi = (frame->data[1] << 8) | frame->data[0];
|
||||||
|
max_resi = (frame->data[3] << 8) | frame->data[2];
|
||||||
|
ref_resi = (frame->data[5] << 8) | frame->data[4];
|
||||||
|
//printf("%d, %d %d\n",min_resi,max_resi,ref_resi);
|
||||||
|
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>
|
||||||
|
if(min_resi > max_resi) {
|
||||||
|
frame->trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(STATE);
|
||||||
|
frame->type = get_resi_array_init_mode_type();
|
||||||
|
frame->data = fail_protocal;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. ? <20><><EFBFBD>µ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
g_sys_config.min_trigger_res_value = min_resi;
|
||||||
|
g_sys_config.max_trigger_res_value = max_resi;
|
||||||
|
g_sys_config.div_trigger_res = ref_resi;
|
||||||
|
|
||||||
|
// 4. <20><><EFBFBD>浽Flash<73><68>ʹ<EFBFBD><CAB9>ͳһ<CDB3>ӿڣ<D3BF>
|
||||||
|
if(save_sys_config(&g_sys_config) != 0) {
|
||||||
|
frame->trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(STATE);
|
||||||
|
frame->type = get_resi_array_init_mode_type();
|
||||||
|
frame->data = fail_protocal;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay_ms(5); // <20>ȴ<EFBFBD>Flashд<68><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
// 5.<2E><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
if(load_config_params(&g_flash_para) == 1) {
|
||||||
|
// <20><>֤<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>²<EFBFBD><C2B2><EFBFBD>
|
||||||
|
// math_resi_init(max_resi, min_resi, ref_resi, MAX_ADC_VALUE, DEFAULT_MAX_DISPLAY_VALUE);
|
||||||
|
math_resi_init(g_sys_config.max_trigger_res_value, g_sys_config.min_trigger_res_value, g_sys_config.div_trigger_res, 4096, 255);
|
||||||
|
|
||||||
|
frame->trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(STATE);
|
||||||
|
frame->type = get_resi_array_init_mode_type();
|
||||||
|
frame->data = success_protocal;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frame->trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(STATE);
|
||||||
|
frame->type = get_resi_array_init_mode_type();
|
||||||
|
frame->data = fail_protocal;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5>
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD>Flash<73><68><EFBFBD>ָ<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
uint8_t clear_array_init_info(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
|
||||||
|
// 1. ? <><D7BC>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> default_config <20><>ȡ<EFBFBD><C8A1>
|
||||||
|
uint8_t temp_data[6];
|
||||||
|
temp_data[0] = default_config.min_trigger_res_value & 0xFF;
|
||||||
|
temp_data[1] = (default_config.min_trigger_res_value >> 8) & 0xFF;
|
||||||
|
temp_data[2] = default_config.max_trigger_res_value & 0xFF;
|
||||||
|
temp_data[3] = (default_config.max_trigger_res_value >> 8) & 0xFF;
|
||||||
|
temp_data[4] = default_config.div_trigger_res & 0xFF;
|
||||||
|
temp_data[5] = (default_config.div_trigger_res >> 8) & 0xFF;
|
||||||
|
|
||||||
|
// 2. <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> frame->data <20><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD> array_resi_params_write
|
||||||
|
frame->data = temp_data;
|
||||||
|
array_resi_params_write(frame); // Ӧ<><D3A6>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||||
|
|
||||||
|
// 3. ? <20><><EFBFBD><EFBFBD>Flash<73><68><EFBFBD>ã<EFBFBD>ʹ<EFBFBD>õײ<C3B5><D7B2>ӿڣ<D3BF>
|
||||||
|
flash_erase(FMC_WRITE_START_ADDR);
|
||||||
|
|
||||||
|
// 4. <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>
|
||||||
|
uint16_t verify_buf[3];
|
||||||
|
flash_read(FMC_WRITE_START_ADDR, verify_buf, 3);
|
||||||
|
|
||||||
|
frame->trantype = 0x04;
|
||||||
|
set_array_resi_init_mode_type(STATE);
|
||||||
|
frame->type = get_resi_array_init_mode_type();
|
||||||
|
|
||||||
|
if(verify_buf[0] == 0xFFFF && verify_buf[1] == 0xFFFF && verify_buf[2] == 0xFFFF) {
|
||||||
|
frame->data = success_protocal;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
return 1; // <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frame->data = fail_protocal;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
return 0; // <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD>ص<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
uint8_t return_array_resi_init_info(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
|
||||||
|
// 1. ? <><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD> g_sys_config <20><>ȡ<EFBFBD><C8A1>
|
||||||
|
static uint8_t response_data[6];
|
||||||
|
response_data[0] = g_sys_config.min_trigger_res_value & 0xFF;
|
||||||
|
response_data[1] = (g_sys_config.min_trigger_res_value >> 8) & 0xFF;
|
||||||
|
response_data[2] = g_sys_config.max_trigger_res_value & 0xFF;
|
||||||
|
response_data[3] = (g_sys_config.max_trigger_res_value >> 8) & 0xFF;
|
||||||
|
response_data[4] = g_sys_config.div_trigger_res & 0xFF;
|
||||||
|
response_data[5] = (g_sys_config.div_trigger_res >> 8) & 0xFF;
|
||||||
|
|
||||||
|
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
set_array_resi_init_mode_type(DATA);
|
||||||
|
frame->trantype = 0x04;
|
||||||
|
frame->type = get_resi_array_init_mode_type();
|
||||||
|
frame->data = response_data;
|
||||||
|
frame->datalen = ARRAY_RESI_INIT_PARAMS_LEN;
|
||||||
|
mx_serial_tx_frame(USART_3_TR,frame);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 0x03 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/**
|
||||||
|
* @brief д<><D0B4>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱӦ<CAB1>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浽Flash<73><68>
|
||||||
|
* @param buf Э<><D0AD>ָ֡<D6A1><D6B8>
|
||||||
|
*/
|
||||||
|
void math_resi_array_cali_write(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
uint8_t empty_data = 0;
|
||||||
|
|
||||||
|
// 1. ? ֱ<>Ӹ<EFBFBD><D3B8>Ƶ<EFBFBD>map_sys<79><73>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if(frame->datalen == ((CALI_POINT_NUM * AX_NUM*AY_NUM)+ 6)){
|
||||||
|
memcpy(map_sys.map_matrix, frame->data, CALI_POINT_NUM * AX_NUM*AY_NUM);
|
||||||
|
set_array_resi_cali_mode_type(CALI_SUCCESS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set_array_resi_cali_mode_type(CALI_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>
|
||||||
|
frame->trantype = 0x03;
|
||||||
|
frame->type = get_resi_array_cali_mode_type();
|
||||||
|
frame->data = &empty_data;
|
||||||
|
frame->datalen = 1;
|
||||||
|
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Flash
|
||||||
|
* @param buf Э<><D0AD>ָ֡<D6A1><D6B8>
|
||||||
|
*/
|
||||||
|
void math_resi_array_cali_save(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
uint8_t empty_data = 0;
|
||||||
|
flash_map_struct verify_map;
|
||||||
|
|
||||||
|
// 1. ? <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD>ݵ<EFBFBD>map_sys
|
||||||
|
if(frame->datalen != ((CALI_POINT_NUM * AX_NUM*AY_NUM)+6)) {
|
||||||
|
set_array_resi_cali_mode_type(CALI_FAIL);
|
||||||
|
goto send_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(map_sys.map_matrix, frame->data, CALI_POINT_NUM * AX_NUM*AY_NUM);
|
||||||
|
|
||||||
|
// 2. <20><><EFBFBD><EFBFBD>FlashУ<D0A3><D7BC><EFBFBD><EFBFBD>
|
||||||
|
flash_erase(FMC_WRITE_MAP_ADDR);
|
||||||
|
|
||||||
|
// 3. ʹ<><CAB9>ͳһ<CDB3>ӿڱ<D3BF><DAB1>浽Flash
|
||||||
|
if(save_config_maps(&map_sys) != 0) {
|
||||||
|
set_array_resi_cali_mode_type(CALI_FAIL);
|
||||||
|
goto send_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay_ms(2); // <20>ȴ<EFBFBD>Flashд<68><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
// 4. <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ز<EFBFBD><D8B2>ȶ<EFBFBD>
|
||||||
|
if(load_config_maps(&verify_map) != 1) {
|
||||||
|
set_array_resi_cali_mode_type(CALI_FAIL);
|
||||||
|
goto send_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. <20><>֤<EFBFBD>ؼ<EFBFBD>У<D0A3>㣨ǰ3<C7B0><33>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7B8>㣩
|
||||||
|
if(verify_map.map_matrix[0] != 0xFF &&
|
||||||
|
verify_map.map_matrix[AX_NUM*AY_NUM] != 0xFF &&
|
||||||
|
verify_map.map_matrix[2 * AX_NUM*AY_NUM] != 0xFF) {
|
||||||
|
set_array_resi_cali_mode_type(CALI_SUCCESS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set_array_resi_cali_mode_type(CALI_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
send_response:
|
||||||
|
// 6. <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>
|
||||||
|
|
||||||
|
frame->trantype = 0x03;
|
||||||
|
frame->type = get_resi_array_cali_mode_type();
|
||||||
|
frame->data = &empty_data;
|
||||||
|
frame->datalen = 1;
|
||||||
|
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>ӳ<EFBFBD>䣩
|
||||||
|
* @param buf Э<><D0AD>ָ֡<D6A1><D6B8>
|
||||||
|
* @return 1=<3D>ɹ<EFBFBD>, 0=ʧ<><CAA7>
|
||||||
|
*/
|
||||||
|
uint8_t cali_params_clear(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
uint8_t empty_data = 0;
|
||||||
|
uint16_t verify_buf[3];
|
||||||
|
|
||||||
|
frame->trantype = 0x03;
|
||||||
|
frame->data = &empty_data;
|
||||||
|
frame->datalen = 1;
|
||||||
|
|
||||||
|
// 1. ? <20><><EFBFBD><EFBFBD>FlashУ<D0A3><D7BC><EFBFBD><EFBFBD>
|
||||||
|
flash_erase(FMC_WRITE_MAP_ADDR);
|
||||||
|
memset(map_sys.map_matrix, 0, sizeof(map_sys.map_matrix));
|
||||||
|
// 2. ? <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡǰ3<C7B0><33><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>
|
||||||
|
flash_read(FMC_WRITE_MAP_ADDR, verify_buf, 3);
|
||||||
|
|
||||||
|
if(verify_buf[0] == 0xFFFF && verify_buf[1] == 0xFFFF && verify_buf[2] == 0xFFFF) {
|
||||||
|
// 3. ? <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RAM
|
||||||
|
|
||||||
|
memcpy(map_matrix_init, map_sys.map_matrix, sizeof(map_matrix_init));
|
||||||
|
|
||||||
|
set_array_resi_cali_mode_type(CALI_SUCCESS);
|
||||||
|
frame->type = get_resi_array_cali_mode_type();
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set_array_resi_cali_mode_type(CALI_FAIL);
|
||||||
|
frame->type = get_resi_array_cali_mode_type();
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief <20><><EFBFBD>ص<EFBFBD>ǰУ<D0A3><D7BC><EFBFBD><EFBFBD>
|
||||||
|
* @param buf Э<><D0AD>ָ֡<D6A1><D6B8>
|
||||||
|
*/
|
||||||
|
void cali_params_return(void *buf)
|
||||||
|
{
|
||||||
|
mx_frame_struct *frame = (mx_frame_struct *)buf;
|
||||||
|
|
||||||
|
frame->trantype = 0x03;
|
||||||
|
set_array_resi_cali_mode_type(CALI_RETURN);
|
||||||
|
frame->type = get_resi_array_cali_mode_type();
|
||||||
|
|
||||||
|
|
||||||
|
frame->data = map_sys.map_matrix;
|
||||||
|
frame->datalen = CALI_POINT_NUM * AX_NUM * AY_NUM;
|
||||||
|
|
||||||
|
mx_serial_tx_frame(USART_3_TR, frame);
|
||||||
|
}
|
||||||
121
App/app_math_info.h
Normal file
121
App/app_math_info.h
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#ifndef __APP_MATH_INFO_H
|
||||||
|
#define __APP_MATH_INFO_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
#include "at32a423_clock.h"
|
||||||
|
#include "systick.h"
|
||||||
|
#include "sysconfig.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include "bsp_flash.h"
|
||||||
|
|
||||||
|
#include "bsp_uart.h"
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
#include "mx_frame_core.h"
|
||||||
|
#include "mx_serial.h"
|
||||||
|
#include "cali_process.h"
|
||||||
|
#include "resi_math_lib.h"
|
||||||
|
|
||||||
|
#define CALI_POINT_NUM 3
|
||||||
|
#define SINGLE_MATH_CALI_PARAMS_PARAMS_SECTOR_SIZE 1 // flash<73><68>С
|
||||||
|
#define ARRAY_RESI_INIT_PARAMS_LEN 6 //<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||||
|
|
||||||
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||||||
|
#define DEFAULT_MIN_DISPLAY_VALUE 0 // Ĭ<><C4AC><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ʾֵ
|
||||||
|
#define DEFAULT_MAX_DISPLAY_VALUE 255 // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾֵ
|
||||||
|
#define MAX_ADC_VALUE 4095 // ADC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>12λADC<44><43>
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ĭ<EFBFBD><C4AC>ֵ
|
||||||
|
#define DEFAULT_MIN_RESI_INIT_VALUE 2100 // Ĭ<><C4AC><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
||||||
|
#define DEFAULT_MAX_RESI_INIT_VALUE 25000 // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
||||||
|
#define DEFAULT_DIVID_RESI_VALUE 2700 // Ĭ<>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>ѹֵ
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_BUF_SIZE (CALI_POINT_NUM * AX_NUM * AY_NUM)
|
||||||
|
|
||||||
|
|
||||||
|
#define ARRAY_RESI_INIT_PARAMS_ADDRS 0x0800B800
|
||||||
|
|
||||||
|
// ֡ͷ<D6A1><CDB7>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡ͬ<D6A1><CDAC><EFBFBD><EFBFBD>
|
||||||
|
#define HEAD 0xA55A
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD>壨<EFBFBD><E5A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ܵĴ<DCB5><C4B4><EFBFBD>֡<EFBFBD><D6A1>
|
||||||
|
#define ARRAY_RESI_INIT_TRAN_TYPE 0x04 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define ARRAY_RESI_VALUE_RETURN_CMD 0x2F // <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define INIT_RESI_WRITE_CMD 0x3F // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define INIT_RESI_SAVE_CMD 0x3D // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>豣<EFBFBD><E8B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define INIT_RESI_CLEAR_CMD 0x1A // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
#define SINGLE_RESI_CALI_TRAN_TYPE 0x03 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define SINGLE_CALI_RESI_WRITE_CMD 0x3F // <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define SINGLE_CALI_RESI_SAVE_CMD 0x3D // <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD>豣<EFBFBD><E8B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define CALI_RESI_VALUE_RETURN_CMD 0x2F // У<D0A3><D7BC><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define SINGLE_CALI_RESI_CLEAR_CMD 0x1A // <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t array_resi_init_params_read_buf[MAX_BUF_SIZE];
|
||||||
|
extern uint8_t array_resi_init_params_write_buf[MAX_BUF_SIZE];
|
||||||
|
|
||||||
|
extern uint8_t array_resi_cali_params_write_buf[MAX_BUF_SIZE];
|
||||||
|
extern uint8_t array_resi_cali_params_read_buf[MAX_BUF_SIZE];
|
||||||
|
|
||||||
|
extern uint8_t success_protocal[ARRAY_RESI_INIT_PARAMS_LEN];
|
||||||
|
extern uint8_t fail_protocal[ARRAY_RESI_INIT_PARAMS_LEN];
|
||||||
|
|
||||||
|
//extern uint8_t success_protocal[ARRAY_RESI_INIT_PARAMS_LEN];
|
||||||
|
//extern uint8_t fail_protocal[ARRAY_RESI_INIT_PARAMS_LEN];
|
||||||
|
|
||||||
|
extern uint8_t frame_state;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>֡״̬
|
||||||
|
extern uint8_t cali_frame_state;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уָ<D7BC><D6B8>֡״̬
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>ģʽö<CABD>٣<EFBFBD><D9A3><EFBFBD><EFBFBD>ڱ<EFBFBD>ʶ<EFBFBD><CAB6>ʼ<EFBFBD><CABC>״̬<D7B4><CCAC>
|
||||||
|
typedef enum{
|
||||||
|
STATE = 0x73, // ״̬ģʽ<C4A3><CABD>0x73<37><33>'s'<27><>ASCII<49>룩
|
||||||
|
DATA = 0x64, // <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>0x64<36><34>'d'<27><>ASCII<49>룩
|
||||||
|
}ARRAY_RESI_INIT_MODE_TYPE_T;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уģʽö<CABD>٣<EFBFBD><D9A3><EFBFBD><EFBFBD>ڱ<EFBFBD>ʶУ״̬<D7B4><CCAC>
|
||||||
|
typedef enum{
|
||||||
|
CALI_SUCCESS = 0x01, // У<D0A3>ɹ<EFBFBD>
|
||||||
|
CALI_FAIL = 0x02, // Уʧ<D7BC><CAA7>
|
||||||
|
CALI_INIT = 0x00, // У<D0A3><D7BC>ʼ״̬
|
||||||
|
CALI_RETURN = 0x4F, // У<D0A3><D7BC><EFBFBD>أ<EFBFBD>0x4F<34><46>'O'<27><>ASCII<49>룩
|
||||||
|
}ARRAY_RESI_CALI_MODE_TYPE_T;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>֡<EFBFBD>ṹ
|
||||||
|
typedef struct{
|
||||||
|
uint16_t sof; // ֡ͷ
|
||||||
|
uint8_t tran_type; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint16_t len; // <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||||
|
uint8_t mode; // Уģʽ
|
||||||
|
uint8_t cali_params[3 * AX_NUM * AY_NUM]; // У<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD>Y<EFBFBD>ᣩ
|
||||||
|
uint16_t checksum; // У<><D0A3><EFBFBD><EFBFBD>
|
||||||
|
}ARRAY_RESI_CALI_DATA_RETURN_SERIAL_FRAME_T;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>ģʽ
|
||||||
|
void set_array_resi_init_mode_type(ARRAY_RESI_INIT_MODE_TYPE_T state);
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>ģʽ
|
||||||
|
ARRAY_RESI_INIT_MODE_TYPE_T get_resi_array_init_mode_type(void);
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Ϣ
|
||||||
|
uint8_t return_array_resi_init_info(void *buf);
|
||||||
|
|
||||||
|
void set_array_resi_cali_mode_type(ARRAY_RESI_CALI_MODE_TYPE_T state);
|
||||||
|
|
||||||
|
ARRAY_RESI_CALI_MODE_TYPE_T get_resi_array_cali_mode_type(void);
|
||||||
|
|
||||||
|
uint8_t array_resi_params_write(mx_frame_struct *buf);
|
||||||
|
uint8_t array_resi_params_save(void *buf);
|
||||||
|
uint8_t clear_array_init_info(void *buf);
|
||||||
|
void math_resi_array_cali_write(void *buf);
|
||||||
|
void math_resi_array_cali_save(void *buf);
|
||||||
|
uint8_t cali_params_clear(void *buf); // <20><> ͷ<>ļ<EFBFBD><C4BC><EFBFBD> void<69><64>Դ<EFBFBD>ļ<EFBFBD>д<EFBFBD><D0B4> uint8_t
|
||||||
|
void cali_params_return(void *buf);
|
||||||
|
|
||||||
|
#endif
|
||||||
339
App/app_scan.c
Normal file
339
App/app_scan.c
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
#include "app_scan.h"
|
||||||
|
#include "bsp_rs2251.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include "bsp_74hc595.h"
|
||||||
|
#include "bsp_adc.h"
|
||||||
|
#include "resi_math_lib.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "mx_serial.h"
|
||||||
|
#include "app_soft.h"
|
||||||
|
#include "bsp_can.h"
|
||||||
|
#include "systick.h"
|
||||||
|
|
||||||
|
#include "lib_cal_creep_resistance.h"
|
||||||
|
#include "app_calibration.h"
|
||||||
|
#include "mozen_protocol.h"
|
||||||
|
#include "app_mozen_handler.h"
|
||||||
|
#include "flash_port.h"
|
||||||
|
#include "bsp_flash.h"
|
||||||
|
enum scan_ad {
|
||||||
|
changge_low,
|
||||||
|
changge_low1,
|
||||||
|
changge_low2,
|
||||||
|
changge_low3,
|
||||||
|
getAD_L0,
|
||||||
|
getAD_L1,
|
||||||
|
getAD_L2,
|
||||||
|
getAD_L3,
|
||||||
|
getAD_L4,
|
||||||
|
getAD_L5,
|
||||||
|
getAD_L6,
|
||||||
|
getAD_L7,
|
||||||
|
fast_l,
|
||||||
|
changge_hig,
|
||||||
|
changge_hig1,
|
||||||
|
changge_hig2,
|
||||||
|
changge_hig3,
|
||||||
|
getAD_H0,
|
||||||
|
getAD_H1,
|
||||||
|
getAD_H2,
|
||||||
|
getAD_H3,
|
||||||
|
getAD_H4,
|
||||||
|
getAD_H5,
|
||||||
|
getAD_H6,
|
||||||
|
getAD_H7,
|
||||||
|
get_break
|
||||||
|
}state;
|
||||||
|
uint8_t hc595_ranks[] = {7,6,5,4,3,2,1,0,15,14,13,12};//<2F><>ʼ<EFBFBD><CABC>Ĭ<EFBFBD><C4AC>
|
||||||
|
int flag_send = 0;
|
||||||
|
volatile uint8_t scan_num = 0;
|
||||||
|
|
||||||
|
static uint16_t cailed_sensor_data[MT_AX_NUM][MT_AY_NUM];//<2F><>16bit<69><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
static uint8_t frame8bit[MT_AX_NUM][MT_AY_NUM];//<2F><>8bit<69><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
adc_value_frame_struct temp_adc_value;
|
||||||
|
|
||||||
|
uint64_t task_tick = 0;
|
||||||
|
|
||||||
|
uint8_t serial_tx_buffer[AX_NUM][AY_NUM] = {0};//ԭʼ<D4AD><CABC><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
cal_creep_resistance_t creep_strength_value;
|
||||||
|
uint8_t Matrix_Stab[AX_NUM][AY_NUM] = {0};
|
||||||
|
uint8_t Matrix_Creep[AX_NUM][AY_NUM] = {0};
|
||||||
|
uint8_t Matrix_Display[AX_NUM][AY_NUM] = {0};
|
||||||
|
mx_frame_struct mx_sensor_frame;
|
||||||
|
|
||||||
|
int print_counter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void Hc4051Delay(uint32_t num)
|
||||||
|
{
|
||||||
|
while(num --);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usart_event_handler(void)
|
||||||
|
{
|
||||||
|
static uint16_t recv_len = 0;
|
||||||
|
static uint8_t rx_buffer[1024] = {0x00};
|
||||||
|
|
||||||
|
recv_len = usart_rx_recv(USART_3_TR, rx_buffer, sizeof(rx_buffer));
|
||||||
|
|
||||||
|
if(recv_len > 0)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
for (i = 0; i < recv_len; i++)
|
||||||
|
{
|
||||||
|
mozen_protocol_feed_byte(&g_mozen_prot, rx_buffer[i], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @function: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @param: frame: <20><><EFBFBD><EFBFBD>֡
|
||||||
|
* @param: len: <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||||
|
* @return: 0:<3A>ɹ<EFBFBD> -1:ʧ<><CAA7>
|
||||||
|
*/
|
||||||
|
static int mozen_uart_tx(const uint8_t *frame, uint16_t len)
|
||||||
|
{
|
||||||
|
if ((frame == NULL) || (len == 0U)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
usart_tx_push(USART_3_TR, (uint8_t *)frame,len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_user_map_init(void){
|
||||||
|
mx_sensor_frame.trantype = 0x01;
|
||||||
|
mx_sensor_frame.type = 0x01;
|
||||||
|
mx_sensor_frame.datalen = sizeof(serial_tx_buffer);
|
||||||
|
creep_strength_value.x_max = AX_NUM;
|
||||||
|
creep_strength_value.y_max = AY_NUM;
|
||||||
|
|
||||||
|
creep_strength_value.matrix_stab = (uint8_t*)Matrix_Stab;
|
||||||
|
creep_strength_value.matrix_creep = (uint8_t*)Matrix_Creep;
|
||||||
|
creep_strength_value.matrix_display = (uint8_t*)Matrix_Display;
|
||||||
|
|
||||||
|
app_mozen_init(mozen_uart_tx);
|
||||||
|
flash_port_ops_t flash_ops =
|
||||||
|
{
|
||||||
|
.read = flash_read,
|
||||||
|
.write = flash_write,
|
||||||
|
.erase = flash_erase,
|
||||||
|
.is_erased = bsp_flash_is_erased
|
||||||
|
};
|
||||||
|
app_calibration_init(&flash_ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t time_tmr1;
|
||||||
|
void AD_Sacn(){
|
||||||
|
// if(state >= get_break){
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
switch(state){
|
||||||
|
case changge_low:
|
||||||
|
REF_OUT(1);//<2F><>ɨ
|
||||||
|
ic_74hc595_clean_0(32);
|
||||||
|
break;
|
||||||
|
case changge_low1:
|
||||||
|
break;
|
||||||
|
case changge_low2:
|
||||||
|
break;
|
||||||
|
case changge_low3:
|
||||||
|
break;
|
||||||
|
case getAD_L0:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][0] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][8] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(4);
|
||||||
|
break;
|
||||||
|
case getAD_L1:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][1] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][9] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(2);
|
||||||
|
break;
|
||||||
|
case getAD_L2:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][2] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][10] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(1);
|
||||||
|
break;
|
||||||
|
case getAD_L3:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][3] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][11] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(7);
|
||||||
|
break;
|
||||||
|
case getAD_L4:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][7] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(5);
|
||||||
|
break;
|
||||||
|
case getAD_L5:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][6] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(3);
|
||||||
|
break;
|
||||||
|
case getAD_L6:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][5] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(0);
|
||||||
|
break;
|
||||||
|
case getAD_L7:
|
||||||
|
temp_adc_value.sensor_iqr_ref_value[scan_num][4] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(6);
|
||||||
|
state = fast_l;
|
||||||
|
break;
|
||||||
|
case fast_l:
|
||||||
|
REF_OUT(1);//<2F><>ɨ
|
||||||
|
ic_74hc595_clean_0(32);
|
||||||
|
break;
|
||||||
|
case changge_hig:
|
||||||
|
REF_OUT(0);
|
||||||
|
ic_74hc595_io_write_1(hc595_ranks[scan_num]);
|
||||||
|
break;
|
||||||
|
case changge_hig1:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case changge_hig2:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case changge_hig3:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case getAD_H0:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[0] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[8] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(4);
|
||||||
|
break;
|
||||||
|
case getAD_H1:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[1] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[9] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(2);
|
||||||
|
break;
|
||||||
|
case getAD_H2:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[2] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[10] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(1);
|
||||||
|
break;
|
||||||
|
case getAD_H3:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[3] = GetAdcValue(1);
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[11] = GetAdcValue(0);
|
||||||
|
Choose_AX_Channel(7);
|
||||||
|
break;
|
||||||
|
case getAD_H4:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[7] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(5);
|
||||||
|
break;
|
||||||
|
case getAD_H5:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[6] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(3);
|
||||||
|
break;
|
||||||
|
case getAD_H6:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[5] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(0);
|
||||||
|
break;
|
||||||
|
case getAD_H7:
|
||||||
|
temp_adc_value.sensor_iqr_raw_value[4] = GetAdcValue(1);
|
||||||
|
Choose_AX_Channel(6);
|
||||||
|
break;
|
||||||
|
case get_break:
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
state++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRQ_Scan(adc_value_frame_struct *adc_raw_value){
|
||||||
|
static math_resi_cal_t math_resi_cal = {0};
|
||||||
|
static int math_scan_num = 0;
|
||||||
|
__disable_irq();
|
||||||
|
math_scan_num = scan_num;
|
||||||
|
memcpy(adc_raw_value->sensor_raw_value,adc_raw_value->sensor_iqr_raw_value,24);
|
||||||
|
memcpy(adc_raw_value->sensor_ref_value,adc_raw_value->sensor_iqr_ref_value[math_scan_num],24);
|
||||||
|
|
||||||
|
|
||||||
|
scan_num++;
|
||||||
|
if(scan_num == AX_NUM)
|
||||||
|
{
|
||||||
|
scan_num = 0;
|
||||||
|
flag_send= 1;
|
||||||
|
print_counter++;
|
||||||
|
if(print_counter == 10)
|
||||||
|
{
|
||||||
|
print_counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(print_counter >= 9){
|
||||||
|
state = changge_low;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
state = fast_l;
|
||||||
|
__enable_irq();
|
||||||
|
|
||||||
|
math_resi_cal.sensor_adc_value = adc_raw_value->sensor_raw_value;
|
||||||
|
math_resi_cal.resi_adc_value = adc_raw_value->sensor_ref_value;
|
||||||
|
math_resi_cal.math_number = AX_NUM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
math_resi_cali_once(&math_resi_cal,
|
||||||
|
adc_raw_value->sensor_resi_output,
|
||||||
|
AX_NUM,
|
||||||
|
SCAN_LOW_LEVEL);
|
||||||
|
|
||||||
|
math_display_resi(adc_raw_value->sensor_resi_output,
|
||||||
|
adc_raw_value->sensor_display_output,
|
||||||
|
AX_NUM,
|
||||||
|
RESI_BACKWARDS,
|
||||||
|
SINGLE_BYTE);
|
||||||
|
|
||||||
|
memcpy(adc_raw_value->sensor_voltage[math_scan_num],adc_raw_value->sensor_display_output,AX_NUM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void scan_deal(void){
|
||||||
|
if(state >= get_break)
|
||||||
|
{
|
||||||
|
IRQ_Scan(&temp_adc_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TMR1_OVF_TMR10_IRQHandler(void)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ<D6BE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if(tmr_flag_get(TMR1, TMR_OVF_FLAG) != RESET)
|
||||||
|
{
|
||||||
|
AD_Sacn();
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ<D6BE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB4><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
tmr_flag_clear(TMR1, TMR_OVF_FLAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int counter_fps;
|
||||||
|
int counter_fps1;
|
||||||
|
void adc_deal(void){
|
||||||
|
if(flag_send == 1){
|
||||||
|
flag_send = 0;
|
||||||
|
memcpy(frame8bit,temp_adc_value.sensor_voltage,144);
|
||||||
|
mx_sensor_frame.data = (uint8_t *)frame8bit;
|
||||||
|
mx_serial_tx_frame(USART_3_TR,&mx_sensor_frame);
|
||||||
|
counter_fps++;
|
||||||
|
|
||||||
|
}
|
||||||
|
if((get_system_tick() - task_tick) >= 1000){
|
||||||
|
task_tick = get_system_tick();
|
||||||
|
counter_fps1 = counter_fps;
|
||||||
|
counter_fps = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
44
App/app_scan.h
Normal file
44
App/app_scan.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef _BSP_SCAN_H
|
||||||
|
#define _BSP_SCAN_H
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "main.h"
|
||||||
|
/*32x64 Data_Array*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t sensor_iqr_raw_value[AX_NUM];
|
||||||
|
uint16_t sensor_iqr_ref_value[AX_NUM][AY_NUM];
|
||||||
|
uint16_t sensor_raw_value[AX_NUM];
|
||||||
|
uint16_t sensor_ref_value[AX_NUM];
|
||||||
|
|
||||||
|
uint16_t sensor_resi_output[AX_NUM];
|
||||||
|
uint8_t sensor_display_output[AX_NUM];
|
||||||
|
|
||||||
|
uint8_t sensor_voltage[AX_NUM][AY_NUM];
|
||||||
|
|
||||||
|
// uint16_t sensor1_voltage[AX_NUM][AY_NUM];//16bit
|
||||||
|
uint8_t sensor_filter[AX_NUM][AY_NUM];
|
||||||
|
}adc_value_frame_struct;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
REFER_RESISTACE,
|
||||||
|
RAW_RESISTACE
|
||||||
|
}RESISTACE_NAME;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define RANKS_ADDRESS (0x08000000 + 1024 * 68)
|
||||||
|
#define RANKS_HEAD 0XA55AA55A
|
||||||
|
#define RANKS_TAIL 0X5AA55AA5
|
||||||
|
|
||||||
|
void IRQ_Scan(adc_value_frame_struct *adc_raw_value);
|
||||||
|
void u8_cail_deal(void);
|
||||||
|
void adc_deal(void);
|
||||||
|
void scan_deal(void);
|
||||||
|
void app_user_map_init(void);
|
||||||
|
|
||||||
|
//void scan(adc_value_frame_struct *adc_raw_value,uint8_t scan_num);
|
||||||
|
int line_init(void);
|
||||||
|
int save_config_ranks(uint8_t x[12],uint8_t y[12]);
|
||||||
|
#endif
|
||||||
69
App/app_soft.c
Normal file
69
App/app_soft.c
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "app_soft.h"
|
||||||
|
#include "app_scan.h"
|
||||||
|
#include "bsp_flash.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#pragma pack (1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t ax;
|
||||||
|
uint8_t ay;
|
||||||
|
uint16_t compensation_rate;
|
||||||
|
}sort_value_struct;
|
||||||
|
#pragma pack ()
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t scan_X_line[] = {0,1,2,3,4,5,6,7,8,9,10,11};
|
||||||
|
uint8_t scan_Y_line[] = {0,1,2,3,4,5,6,7,8,9,10,11};
|
||||||
|
|
||||||
|
rank_frame_struct ranks;
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>˫·adc<64><63>
|
||||||
|
int read_rank_flash(rank_frame_struct *params){
|
||||||
|
uint32_t *head = (uint32_t*)RANKS_ADDRESS;
|
||||||
|
uint32_t *tail = (uint32_t*)(RANKS_ADDRESS + sizeof(rank_frame_struct) - 4);
|
||||||
|
|
||||||
|
if(*head == RANKS_HEAD && *tail == RANKS_TAIL)
|
||||||
|
{
|
||||||
|
memcpy((uint32_t *)params, head, sizeof(rank_frame_struct));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int line_init(void){
|
||||||
|
if(read_rank_flash(&ranks) == 1){
|
||||||
|
// memcpy(scan_X_line, ranks.x_rank, sizeof(scan_X_line));
|
||||||
|
// memcpy(scan_Y_line, ranks.y_rank, sizeof(scan_Y_line));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // <20><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_config_ranks(uint8_t x[12],uint8_t y[12])
|
||||||
|
{
|
||||||
|
ranks.head = RANKS_HEAD;
|
||||||
|
ranks.tail = RANKS_TAIL;
|
||||||
|
memcpy(ranks.x_rank, x, sizeof(scan_X_line));
|
||||||
|
memcpy(ranks.y_rank, y, sizeof(scan_Y_line));
|
||||||
|
flash_write(RANKS_ADDRESS,(uint16_t *)&ranks, sizeof(rank_frame_struct)/sizeof(uint16_t));
|
||||||
|
line_init();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void soft_sensor(adc_value_frame_struct *adc_raw_value)
|
||||||
|
{
|
||||||
|
for(uint8_t ax = 0; ax < AX_NUM; ax++){
|
||||||
|
for(uint8_t ay = 0; ay < AY_NUM; ay++)
|
||||||
|
{
|
||||||
|
// adc_raw_value->sensor_soft_value[ay][ax] = adc_raw_value->sensor_voltage[scan_Y_line[ay]][scan_X_line[ax]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
App/app_soft.h
Normal file
19
App/app_soft.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef _APP_SOFT_H
|
||||||
|
#define _APP_SOFT_H
|
||||||
|
#include "app_scan.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t head;
|
||||||
|
uint8_t x_rank[12];
|
||||||
|
uint8_t y_rank[12];
|
||||||
|
uint32_t tail;
|
||||||
|
}rank_frame_struct;
|
||||||
|
|
||||||
|
|
||||||
|
void soft_sensor(adc_value_frame_struct *adc_raw_value);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
137
App/main.c
Normal file
137
App/main.c
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************
|
||||||
|
* @file main.c
|
||||||
|
* @brief main program
|
||||||
|
**************************************************************************
|
||||||
|
*
|
||||||
|
*
|
||||||
|
**************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "at32a423.h"
|
||||||
|
#include "at32a423_clock.h"
|
||||||
|
#include "systick.h"
|
||||||
|
#include "sysconfig.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "at32a423_tmr.h" // <20><>ʱ<EFBFBD><CAB1>ר<EFBFBD><D7A8>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#include "at32a423_crm.h" // ʱ<>ӹ<EFBFBD><D3B9><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
|
||||||
|
#include "app_get_json.h"
|
||||||
|
#include "app_scan.h"
|
||||||
|
#include "app_soft.h"
|
||||||
|
|
||||||
|
#include "bsp_led.h"
|
||||||
|
#include "bsp_uart.h"
|
||||||
|
#include "bsp_adc.h"
|
||||||
|
#include "bsp_can.h"
|
||||||
|
|
||||||
|
#include "bsp_spi.h"
|
||||||
|
#include "bsp_rs2251.h"
|
||||||
|
#include "bsp_74hc595.h"
|
||||||
|
#include "bsp_flash.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "mx_spi.h"
|
||||||
|
|
||||||
|
#include "resi_math_lib.h"
|
||||||
|
|
||||||
|
#include "bsp_rs2251.h"
|
||||||
|
|
||||||
|
#include "cali_process.h"
|
||||||
|
#include "lib_cal_creep_resistance.h"
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#define CAL_CREEP_ENABLE 0
|
||||||
|
#define JSON_ENABLE 0
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t serial_tx_buffer2[AX_NUM][AY_NUM] = {0};//У<D0A3><D7BC><EFBFBD><EFBFBD>
|
||||||
|
uint8_t map_matrix[12*12*3];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
crm_clocks_freq_type crm_clocks_freq_struct = {0};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TMR1_init(void);
|
||||||
|
|
||||||
|
|
||||||
|
int line_flag=0;
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
static uint64_t time_ms = 0;
|
||||||
|
|
||||||
|
system_clock_config();//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
systick_config();//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
bsp_led_init(LED2);
|
||||||
|
|
||||||
|
can1_init();
|
||||||
|
adc_init();
|
||||||
|
RS2251_Init();
|
||||||
|
ref_gpio_init();
|
||||||
|
ic_74hc595_init();
|
||||||
|
mx_spi_init();
|
||||||
|
line_flag = line_init();
|
||||||
|
|
||||||
|
app_user_map_init();
|
||||||
|
|
||||||
|
// uart3_init(921600);
|
||||||
|
uart3_init(2000000);
|
||||||
|
delay_ms(1000);
|
||||||
|
|
||||||
|
TMR1_init();
|
||||||
|
// Choose_AX_Channel(5);
|
||||||
|
// REF_OUT(0);
|
||||||
|
// ic_74hc595_io_write_1(7);
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
delay_ms(1);
|
||||||
|
scan_deal();//ɨ<>账<EFBFBD><E8B4A6>
|
||||||
|
adc_deal(); //<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TMR1_init(void){
|
||||||
|
crm_clocks_freq_get(&crm_clocks_freq_struct);
|
||||||
|
/* enable tmr1 clock */
|
||||||
|
crm_periph_clock_enable(CRM_TMR1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* tmr1 configuration */
|
||||||
|
/* time base configuration */
|
||||||
|
tmr_base_init(TMR1, 6, 139);//<2F>˴<EFBFBD>119<31><39><EFBFBD>Ƕ<EFBFBD>ӦϵͳƵ<CDB3><C6B5>
|
||||||
|
tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
|
||||||
|
|
||||||
|
/* overflow interrupt enable */
|
||||||
|
tmr_interrupt_enable(TMR1, TMR_OVF_INT, TRUE);
|
||||||
|
|
||||||
|
/* tmr1 hall interrupt nvic init */
|
||||||
|
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||||
|
nvic_irq_enable(TMR1_OVF_TMR10_IRQn, 1, 0);
|
||||||
|
|
||||||
|
/* enable tmr1 */
|
||||||
|
tmr_counter_enable(TMR1, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
9
App/main.h
Normal file
9
App/main.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef __MAIN_H
|
||||||
|
#define __MAIN_H
|
||||||
|
|
||||||
|
#define AX_NUM 12
|
||||||
|
#define AY_NUM 12
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
248
App/sys.c
Normal file
248
App/sys.c
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief sys.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>йؿ<D0B9><D8BF><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
|
||||||
|
* uwTick <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> HAL_GetTick() <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>uwTick(ֻ<><D6BB>)<29><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>uwTick<63><6B>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* uwTick ÿ<><C3BF>1ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD>ֻҪ#include "main.h"<22><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>uwTick<63><6B><EFBFBD><EFBFBD>hal<61><6C><EFBFBD>Դ<EFBFBD><D4B4>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
|
||||||
|
//<2F>û<EFBFBD>include
|
||||||
|
#include "at32a423.h"
|
||||||
|
#include "systick.h"
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>include<64><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#include "sys.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t enable_flag; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<C7B7><F1B1BBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F1B2BBB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD> (<28><>0Ϊ<30><CEAA><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>)
|
||||||
|
uint16_t interval_time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>ʱ<EFBFBD><CAB1> (<28><>λms)
|
||||||
|
uint32_t last_time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> (<28><>λms)
|
||||||
|
uint8_t ready_flag; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>0Ϊ<30><CEAA><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>)
|
||||||
|
uint32_t out_time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱֹͣ<CDA3><D6B9><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>ʱ<EFBFBD><CAB1> (<28><>λms)
|
||||||
|
int32_t usage_tick; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>VAL(CNT)<29>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD>sys.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD> System_RunTask())
|
||||||
|
float usage_time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC>λΪus<75><73><EFBFBD><EFBFBD>λΪus<75><73><EFBFBD><EFBFBD>λΪus<75><73> (<28><><EFBFBD>㷽<EFBFBD><E3B7BD><EFBFBD><EFBFBD>sys.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD> System_RunTask())
|
||||||
|
float usage_percent; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC>cpu<70>İٷֱ<D9B7> (<28><><EFBFBD>㷽<EFBFBD><E3B7BD><EFBFBD><EFBFBD>sys.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD> System_RunTask())
|
||||||
|
void (*f)(void); // ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>еĺ<D0B5><C4BA><EFBFBD> (<28><>֪<EFBFBD><D6AA><EFBFBD><EFBFBD>ôָ<C3B4><D6B8>sys.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD> System_Init())
|
||||||
|
}TaskStruct;
|
||||||
|
|
||||||
|
TaskStruct task_structs[TASK_NUMBER]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľṹ<C4BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief ϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>enable_flag,interval_time,task_priority,f<><66><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>ص<EFBFBD>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>0
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
void System_TaskInit()
|
||||||
|
{
|
||||||
|
task_structs[TASK1].enable_flag=1;
|
||||||
|
task_structs[TASK1].interval_time=500;
|
||||||
|
task_structs[TASK1].f=task1;
|
||||||
|
|
||||||
|
task_structs[TASK2].enable_flag=1;
|
||||||
|
task_structs[TASK2].interval_time=10000;
|
||||||
|
task_structs[TASK2].f=task2;
|
||||||
|
|
||||||
|
task_structs[TASK3].enable_flag=1;
|
||||||
|
task_structs[TASK3].interval_time=500;
|
||||||
|
task_structs[TASK3].f=task3;
|
||||||
|
|
||||||
|
task_structs[TASK4].enable_flag=1;
|
||||||
|
task_structs[TASK4].interval_time=5;
|
||||||
|
task_structs[TASK4].f=task4;
|
||||||
|
|
||||||
|
task_structs[TASK5].enable_flag=1;
|
||||||
|
task_structs[TASK5].interval_time=5;
|
||||||
|
task_structs[TASK5].f=task5;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> usage_time,usage_percent,<2C>ʹ˺<CDB4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD>total_usage_time
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
int32_t total_usage_tick; // <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ˺<C7B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>tick<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>debug
|
||||||
|
float total_usage_time; // <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ˺<C7B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>ʱ<EFBFBD><CAB1>(<28><>λus)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>debug
|
||||||
|
int32_t total_usage_tick_max_in1s; // total_usage_tick <20><>ij1<C4B3><31><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||||
|
float total_usage_time_max_in1s; // total_usage_time <20><>ij1<C4B3><31><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||||
|
|
||||||
|
void System_TaskRun()
|
||||||
|
{
|
||||||
|
int64_t total_begin_tick = SysTick->VAL - get_system_tick()*(SysTick->LOAD+1); // ˼·ͬ<C2B7><CDAC><EFBFBD><EFBFBD> begin_tick
|
||||||
|
|
||||||
|
for(uint8_t i=0;i<TASK_NUMBER;i++)
|
||||||
|
{
|
||||||
|
if(task_structs[i].ready_flag)
|
||||||
|
{
|
||||||
|
task_structs[i].ready_flag--;
|
||||||
|
// <20><><EFBFBD><EFBFBD> begin_tick <20>Ĺ<EFBFBD>ʽ = <20><> >0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> - <20><>------ <0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-------<2D><> (begin_tick < 0)
|
||||||
|
int64_t begin_tick = SysTick->VAL - get_system_tick()*(SysTick->LOAD+1);
|
||||||
|
|
||||||
|
task_structs[i].f(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD> usage_tick <20>Ĺ<EFBFBD>ʽ = <20><>ʼ<EFBFBD><CABC>tick - <20><>---------------<2D><><EFBFBD>ڵ<EFBFBD>tick--------------<2D><>(<28><><EFBFBD><EFBFBD>tick<63><6B><EFBFBD>Ǹ<EFBFBD><C7B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ʼ<EFBFBD><CABC>tick > <20><><EFBFBD>ڵ<EFBFBD>tick)
|
||||||
|
task_structs[i].usage_tick = begin_tick - (SysTick->VAL - get_system_tick()*(SysTick->LOAD+1));
|
||||||
|
// <20><><EFBFBD><EFBFBD> usage_time <20>Ĺ<EFBFBD>ʽ = <20><>-----------usage_tick----------<2D><> / <20><>1ms<6D><73>tick<63><6B><EFBFBD><EFBFBD>--<2D><> * 1000(<28><>λ<EFBFBD><CEBB><EFBFBD>㣬1ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1000us)
|
||||||
|
task_structs[i].usage_time = (float)task_structs[i].usage_tick / (SysTick->LOAD+1) * 1000.f;
|
||||||
|
// <20><><EFBFBD><EFBFBD> usage_percent <20>Ĺ<EFBFBD>ʽ = <20><>-----<2D><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>(<28><>λHz)-----<2D><> * <20><>---<2D><><EFBFBD><EFBFBD><F1B5A5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>(<28><>λs)----<2D><> * 100(<28><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>%,<2C><><EFBFBD><EFBFBD>*100)
|
||||||
|
task_structs[i].usage_percent = 1000.f/task_structs[i].interval_time * task_structs[i].usage_time/1000000.f * 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total_usage_tick = total_begin_tick - (SysTick->VAL - get_system_tick()*(SysTick->LOAD+1)); // ˼·ͬ<C2B7><CDAC><EFBFBD><EFBFBD> usage_tick
|
||||||
|
total_usage_time = (float)total_usage_tick / (SysTick->LOAD+1) * 1000.f; // ˼·ͬ<C2B7><CDAC><EFBFBD><EFBFBD> usage_time
|
||||||
|
|
||||||
|
if(total_usage_tick_max_in1s < total_usage_tick)
|
||||||
|
{
|
||||||
|
total_usage_tick_max_in1s = total_usage_tick;
|
||||||
|
}
|
||||||
|
if(total_usage_time_max_in1s < total_usage_time)
|
||||||
|
{
|
||||||
|
total_usage_time_max_in1s = total_usage_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief ϵͳ<CFB5><CDB3><EFBFBD>£<EFBFBD>ÿ<EFBFBD><C3BF>1ms<6D>ӵδ<D3B5><CEB4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>жϽ<D0B6><CFBD><EFBFBD>һ<EFBFBD><D2BB> (<28><>stm32f4xx_it.c<><63> System_Update()<29>ﱻ<EFBFBD><EFB1BB><EFBFBD><EFBFBD>)
|
||||||
|
* ͨ<><CDA8>uwTick,enable_flag,stop_time<6D><65>ֵ<EFBFBD><D6B5>ȷ<EFBFBD><C8B7>ready_flag<61><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD>last_time,stop_time
|
||||||
|
* ÿ<><C3BF>1000ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> total_usage_tick_max_in1s <20><> total_usage_time_max_in1s
|
||||||
|
* @changedate 2020.09.15
|
||||||
|
*/
|
||||||
|
void System_TaskUpdate()
|
||||||
|
{
|
||||||
|
for(uint8_t i=0;i<TASK_NUMBER;i++)
|
||||||
|
{
|
||||||
|
if(task_structs[i].out_time != 0)
|
||||||
|
{
|
||||||
|
if(task_structs[i].out_time == 1)
|
||||||
|
{
|
||||||
|
Task_InCallback(i); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>лָ<D0BB><D6B8><EFBFBD><EFBFBD>ָ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
}
|
||||||
|
task_structs[i].out_time--; //<2F><><EFBFBD><EFBFBD> out_time
|
||||||
|
}
|
||||||
|
// ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD>ﵽ<EFBFBD><EFB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7> ready_flag <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> last_time
|
||||||
|
if(task_structs[i].enable_flag &&
|
||||||
|
task_structs[i].out_time == 0 &&
|
||||||
|
task_structs[i].interval_time<=(get_system_tick()-task_structs[i].last_time))
|
||||||
|
{
|
||||||
|
task_structs[i].ready_flag++;
|
||||||
|
task_structs[i].last_time=get_system_tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(get_system_tick()%1000 == 0) // ÿ<><C3BF>1000ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> total_usage_tick_max_in1s <20><> total_usage_time_max_in1s
|
||||||
|
{
|
||||||
|
total_usage_tick_max_in1s = total_usage_tick;
|
||||||
|
total_usage_time_max_in1s = total_usage_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣһ<CDA3><D2BB>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
void System_TaskOut(uint8_t task_number,uint32_t stop_time)
|
||||||
|
{
|
||||||
|
task_structs[task_number].out_time = stop_time;
|
||||||
|
Task_OutCallback(task_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رգ<D8B1><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
void System_TaskDisable(uint8_t task_number)
|
||||||
|
{
|
||||||
|
task_structs[task_number].enable_flag = 0;
|
||||||
|
Task_DisableCallback(task_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
void System_TaskEnable(uint8_t task_number)
|
||||||
|
{
|
||||||
|
task_structs[task_number].enable_flag = 1;
|
||||||
|
Task_EnableCallback(task_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief ϵͳǿ<CDB3><C7BF>ͣ<EFBFBD><CDA3>
|
||||||
|
* @changedate 2020.09.14
|
||||||
|
*/
|
||||||
|
void System_AllTaskDisable()
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
for(uint8_t i=0;i<TASK_NUMBER;i++)
|
||||||
|
{
|
||||||
|
task_structs[i].enable_flag = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʼ<EFBFBD><CABC>
|
||||||
|
* @changedate 2021.04.15
|
||||||
|
*/
|
||||||
|
void System_SoftWatchDogInit(SoftWatchDogStruct *dog,uint32_t time_load,uint8_t default_state)
|
||||||
|
{
|
||||||
|
dog->state = default_state;
|
||||||
|
dog->time_load = time_load;
|
||||||
|
dog->time_cnt = dog->time_load;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>ι<EFBFBD><CEB9>
|
||||||
|
* @changedate 2021.04.15
|
||||||
|
*/
|
||||||
|
void System_SoftWatchDogFeed(SoftWatchDogStruct *dog)
|
||||||
|
{
|
||||||
|
dog->state = 1;
|
||||||
|
dog->time_cnt = dog->time_load;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>״̬
|
||||||
|
* @changedate 2021.04.15
|
||||||
|
*/
|
||||||
|
void System_SoftWatchDogUpdate(SoftWatchDogStruct *dog)
|
||||||
|
{
|
||||||
|
if(dog->time_cnt > 0)
|
||||||
|
{
|
||||||
|
dog->time_cnt--;
|
||||||
|
dog->state = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dog->time_cnt = 0;
|
||||||
|
dog->state = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>״̬
|
||||||
|
* @changedate 2021.04.15
|
||||||
|
*/
|
||||||
|
uint8_t System_GetSoftWatchDogState(SoftWatchDogStruct *dog)
|
||||||
|
{
|
||||||
|
return dog->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
34
App/sys.h
Normal file
34
App/sys.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __SYS_H
|
||||||
|
#define __SYS_H
|
||||||
|
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
#define TASK_NUMBER 6 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define TASK1 0 //<2F><><EFBFBD>ӿɶ<D3BF><C9B6><EFBFBD>
|
||||||
|
#define TASK2 1 //<2F><><EFBFBD>ӿɶ<D3BF><C9B6><EFBFBD>
|
||||||
|
#define TASK3 2 //<2F><><EFBFBD>ӿɶ<D3BF><C9B6><EFBFBD>
|
||||||
|
#define TASK4 3 //<2F><><EFBFBD>ӿɶ<D3BF><C9B6><EFBFBD>
|
||||||
|
#define TASK5 4 //<2F><><EFBFBD>ӿɶ<D3BF><C9B6><EFBFBD>
|
||||||
|
#define TASK6 5 //<2F><><EFBFBD>ӿɶ<D3BF><C9B6><EFBFBD>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t state; //<2F><>ǰ״̬<D7B4><CCAC>1<EFBFBD><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||||
|
uint32_t time_load; //<2F><>װ<EFBFBD><D7B0>ֵ
|
||||||
|
uint32_t time_cnt; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
|
||||||
|
}SoftWatchDogStruct;
|
||||||
|
|
||||||
|
void System_TaskInit(void);
|
||||||
|
void System_TaskUpdate(void);
|
||||||
|
void System_TaskRun(void);
|
||||||
|
void System_TaskOut(uint8_t task_number,uint32_t stop_time);
|
||||||
|
void System_TaskDisable(uint8_t task_number);
|
||||||
|
void System_TaskEnable(uint8_t task_number);
|
||||||
|
|
||||||
|
void System_SoftWatchDogInit(SoftWatchDogStruct *dog,uint32_t time_load,uint8_t default_state);
|
||||||
|
void System_SoftWatchDogFeed(SoftWatchDogStruct *dog);
|
||||||
|
void System_SoftWatchDogUpdate(SoftWatchDogStruct *dog);
|
||||||
|
uint8_t System_GetSoftWatchDogState(SoftWatchDogStruct *dog);
|
||||||
|
|
||||||
|
#endif /* __SYS_H */
|
||||||
|
|
||||||
37
App/task.c
Normal file
37
App/task.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* @auther whlphlg
|
||||||
|
* @brief task.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ɶȽϴ<C8BD>
|
||||||
|
* @changedate 2020.09.13
|
||||||
|
*/
|
||||||
|
|
||||||
|
//<2F>û<EFBFBD>include
|
||||||
|
#include "at32a423.h"
|
||||||
|
#include "bsp_led.h"
|
||||||
|
#include "scan.h"
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>include<64><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#include "task.h"
|
||||||
|
#include "sys.h"
|
||||||
|
|
||||||
|
|
||||||
|
void task1()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void task2()
|
||||||
|
{
|
||||||
|
System_TaskOut(TASK1,4000);
|
||||||
|
}
|
||||||
|
void task3()
|
||||||
|
{
|
||||||
|
bsp_led_toggle(LED2);
|
||||||
|
}
|
||||||
|
void task4()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void task5()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
17
App/task.h
Normal file
17
App/task.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef __TASK_H
|
||||||
|
#define __TASK_H
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
void task1(void);
|
||||||
|
void task2(void);
|
||||||
|
void task3(void);
|
||||||
|
void task4(void);
|
||||||
|
void task5(void);
|
||||||
|
|
||||||
|
__weak void Task_DisableCallback(uint8_t task_number);
|
||||||
|
__weak void Task_EnableCallback(uint8_t task_number);
|
||||||
|
__weak void Task_OutCallback(uint8_t task_number);
|
||||||
|
__weak void Task_InCallback(uint8_t task_number);
|
||||||
|
|
||||||
|
#endif /* __TASK_H */
|
||||||
177
Bsp/bsp_74hc595.c
Normal file
177
Bsp/bsp_74hc595.c
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
/*************************************************************************
|
||||||
|
> File Name: 74hc595.c
|
||||||
|
> Author: ma6174
|
||||||
|
> Mail: ma6174@163.com
|
||||||
|
> Created Time: 2023/9/20 17:48:24
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#include "bsp_74hc595.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define DS_MOS(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_14);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_14)
|
||||||
|
|
||||||
|
#define SHCP_MOS(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOA, GPIO_PINS_8);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOA, GPIO_PINS_8)
|
||||||
|
|
||||||
|
#define STCP_MOS(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_15);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_15)
|
||||||
|
|
||||||
|
#define OE_MOS(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_13);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_13)
|
||||||
|
|
||||||
|
#define MR_MOS(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOA, GPIO_PINS_7);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOA, GPIO_PINS_7)
|
||||||
|
|
||||||
|
inline void ic_74hc595_delay(uint32_t num)
|
||||||
|
{
|
||||||
|
while(num --);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ic_74hc595_init(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
/* enable the led clock */
|
||||||
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK,TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK,TRUE);
|
||||||
|
|
||||||
|
/* set default parameter */
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the led gpio */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_8;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_13 | GPIO_PINS_14 | GPIO_PINS_15;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
ic_74hc595_clean_0(32);
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0;
|
||||||
|
//<2F><>ΪӲ<CEAA><D3B2><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ɨ
|
||||||
|
void ic_74hc595_io_write_1(uint8_t io_num)
|
||||||
|
{
|
||||||
|
|
||||||
|
DS_MOS(1);
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < io_num; i++)
|
||||||
|
{
|
||||||
|
DS_MOS(0);
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
}
|
||||||
|
STCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
STCP_MOS(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>
|
||||||
|
//<2F><>ΪӲ<CEAA><D3B2><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ɨ
|
||||||
|
void ic_74hc595_io_write_0(uint8_t io_num)
|
||||||
|
{
|
||||||
|
DS_MOS(0);
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < io_num; i++)
|
||||||
|
{
|
||||||
|
DS_MOS(1);
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
}
|
||||||
|
STCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
STCP_MOS(0);
|
||||||
|
}
|
||||||
|
//<2F><>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>0
|
||||||
|
//<2F><>ΪӲ<CEAA><D3B2><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ɨ
|
||||||
|
void ic_74hc595_clean_0(uint8_t io_num)
|
||||||
|
{
|
||||||
|
DS_MOS(0);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
STCP_MOS(0);
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < io_num; i++)
|
||||||
|
{
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
|
||||||
|
//<2F><>Ϊ<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>Ϊ<EFBFBD>´<EFBFBD><EFBFBD><D7BC>
|
||||||
|
SHCP_MOS(0);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
STCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
STCP_MOS(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>1;
|
||||||
|
//<2F><>ΪӲ<CEAA><D3B2><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ɨ
|
||||||
|
void ic_74hc595_clean_1(uint8_t io_num)
|
||||||
|
{
|
||||||
|
DS_MOS(1);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
STCP_MOS(0);
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < io_num; i++)
|
||||||
|
{
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
|
||||||
|
//<2F><>Ϊ<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>Ϊ<EFBFBD>´<EFBFBD><EFBFBD><D7BC>
|
||||||
|
SHCP_MOS(0);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
STCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
STCP_MOS(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ic_74hc595_wirte_32bit(uint32_t data)
|
||||||
|
{
|
||||||
|
DS_MOS(0);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
STCP_MOS(0);
|
||||||
|
uint32_t temp = 0;
|
||||||
|
for(uint8_t i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
temp = data & (0x80000000>>i);
|
||||||
|
DS_MOS(temp);
|
||||||
|
SHCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
SHCP_MOS(0);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
}
|
||||||
|
STCP_MOS(1);
|
||||||
|
ic_74hc595_delay(1);
|
||||||
|
STCP_MOS(0);
|
||||||
|
}
|
||||||
|
|
||||||
23
Bsp/bsp_74hc595.h
Normal file
23
Bsp/bsp_74hc595.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*************************************************************************
|
||||||
|
> File Name: 74hc595.h
|
||||||
|
> Author: ma6174
|
||||||
|
> Mail: ma6174@163.com
|
||||||
|
> Created Time: 2023/9/20 17:48:31
|
||||||
|
************************************************************************/
|
||||||
|
#ifndef _BSP_74HC595_H
|
||||||
|
#define _BSP_74HC595_H
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
void ic_74hc595_delay(uint32_t num);
|
||||||
|
void ic_74hc595_init(void);
|
||||||
|
void ic_74hc595_thread(void);
|
||||||
|
void ic_74hc595_clean(void);
|
||||||
|
void ic_74hc595_clean_0(uint8_t io_num);
|
||||||
|
void ic_74hc595_clean_1(uint8_t io_num);
|
||||||
|
void ic_74hc595_io_write_0(uint8_t io_num);
|
||||||
|
void ic_74hc595_io_write_1(uint8_t io_num);
|
||||||
|
void ic_74hc595_wirte_32bit(uint32_t data);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
174
Bsp/bsp_adc.c
Normal file
174
Bsp/bsp_adc.c
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
#include "bsp_adc.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
#define CUMULATIVE_NUM 1
|
||||||
|
#define ADC_CHANNEL_NUM 2
|
||||||
|
|
||||||
|
volatile uint16_t adc_value[CUMULATIVE_NUM][ADC_CHANNEL_NUM];
|
||||||
|
uint16_t adc_v[ADC_CHANNEL_NUM] = { 0 };
|
||||||
|
|
||||||
|
void read_adc_value(void)
|
||||||
|
{
|
||||||
|
uint16_t sum = 0;
|
||||||
|
|
||||||
|
for(uint8_t adc_channel_index = 0; adc_channel_index < ADC_CHANNEL_NUM; ++adc_channel_index)
|
||||||
|
{
|
||||||
|
sum = 0;
|
||||||
|
for(uint8_t cumulative_index = 0; cumulative_index < CUMULATIVE_NUM; ++cumulative_index)
|
||||||
|
{
|
||||||
|
sum += adc_value[cumulative_index][adc_channel_index];
|
||||||
|
}
|
||||||
|
adc_v[adc_channel_index] = sum / CUMULATIVE_NUM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t GetAdcValue(uint8_t index)
|
||||||
|
{
|
||||||
|
if(index < ADC_CHANNEL_NUM)
|
||||||
|
{
|
||||||
|
return adc_v[index];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_init(void)
|
||||||
|
{
|
||||||
|
/* system clocks configuration */
|
||||||
|
rcu_config();
|
||||||
|
/* GPIO configuration */
|
||||||
|
gpio_config();
|
||||||
|
/* DMA configuration */
|
||||||
|
dma_config();
|
||||||
|
/* ADC configuration */
|
||||||
|
adc_config();
|
||||||
|
adc_ordinary_software_trigger_enable(ADC1, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief configure the different system clocks
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
|
void rcu_config(void)
|
||||||
|
{
|
||||||
|
/* enable GPIO clock */
|
||||||
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
/* enable ADC clock */
|
||||||
|
crm_periph_clock_enable(CRM_ADC1_PERIPH_CLOCK, TRUE);
|
||||||
|
/* enable DMA0 clock */
|
||||||
|
crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief configure the GPIO peripheral
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
|
void gpio_config(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the IN8 pin */
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_0;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the IN9 pin */
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_1;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief configure the DMA peripheral
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
|
void dma_config(void)
|
||||||
|
{
|
||||||
|
dma_init_type dma_init_struct;
|
||||||
|
nvic_irq_enable(DMA1_Channel1_IRQn, 0, 0);
|
||||||
|
|
||||||
|
dma_reset(DMA1_CHANNEL3);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)(&adc_v);
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&ADC1->odt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.buffer_size = CUMULATIVE_NUM * ADC_CHANNEL_NUM;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_HIGH;
|
||||||
|
dma_init_struct.loop_mode_enable = TRUE;
|
||||||
|
dma_init(DMA1_CHANNEL3, &dma_init_struct);
|
||||||
|
|
||||||
|
/* dmamux function enable */
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL3, DMAMUX_DMAREQ_ID_ADC1);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL3, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief configure the ADC peripheral
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
|
void adc_config(void)
|
||||||
|
{
|
||||||
|
adc_base_config_type adc_base_struct;
|
||||||
|
adc_common_config_type adc_common_struct;
|
||||||
|
|
||||||
|
//common_settings
|
||||||
|
crm_adc_clock_select(CRM_ADC_CLOCK_SOURCE_HCLK);
|
||||||
|
|
||||||
|
adc_common_default_para_init(&adc_common_struct);
|
||||||
|
/* config adc clock division */
|
||||||
|
adc_common_struct.div = ADC_HCLK_DIV_2;
|
||||||
|
/* config inner temperature sensor and vintrv */
|
||||||
|
adc_common_struct.tempervintrv_state = FALSE;
|
||||||
|
adc_common_config(&adc_common_struct);
|
||||||
|
|
||||||
|
/* adc_settings------------------------------------------------------------------- */
|
||||||
|
adc_base_default_para_init(&adc_base_struct);
|
||||||
|
adc_base_struct.sequence_mode = TRUE;//<2F><><EFBFBD><EFBFBD>ģʽ
|
||||||
|
adc_base_struct.repeat_mode = TRUE;//<2F><><EFBFBD><EFBFBD>ģʽ
|
||||||
|
adc_base_struct.data_align = ADC_RIGHT_ALIGNMENT;//<2F>Ҷ<EFBFBD><D2B6><EFBFBD>
|
||||||
|
adc_base_struct.ordinary_channel_length = ADC_CHANNEL_NUM;
|
||||||
|
adc_base_config(ADC1, &adc_base_struct);
|
||||||
|
adc_resolution_set(ADC1, ADC_RESOLUTION_12B);
|
||||||
|
|
||||||
|
/* adc_ordinary_conversionmode---------------------------------------------------- */
|
||||||
|
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_8, 1, ADC_SAMPLETIME_12_5);
|
||||||
|
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_9, 2, ADC_SAMPLETIME_12_5);
|
||||||
|
|
||||||
|
adc_ordinary_conversion_trigger_set(ADC1, ADC_ORDINARY_TRIG_SOFTWARE, ADC_ORDINARY_TRIG_EDGE_NONE);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
adc_dma_mode_enable(ADC1, TRUE);
|
||||||
|
adc_dma_request_repeat_enable(ADC1, TRUE);
|
||||||
|
|
||||||
|
|
||||||
|
adc_enable(ADC1, TRUE);
|
||||||
|
while(adc_flag_get(ADC1, ADC_RDY_FLAG) == RESET);
|
||||||
|
|
||||||
|
/* adc calibration---------------------------------------------------------------- */
|
||||||
|
adc_calibration_init(ADC1);
|
||||||
|
while(adc_calibration_init_status_get(ADC1));
|
||||||
|
adc_calibration_start(ADC1);
|
||||||
|
while(adc_calibration_status_get(ADC1));
|
||||||
|
}
|
||||||
14
Bsp/bsp_adc.h
Normal file
14
Bsp/bsp_adc.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef __BSP_ADC_h
|
||||||
|
#define __BSP_ADC_h
|
||||||
|
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
void rcu_config(void);
|
||||||
|
void gpio_config(void);
|
||||||
|
void dma_config(void);
|
||||||
|
void adc_config(void);
|
||||||
|
void adc_init(void);
|
||||||
|
void read_adc_value(void);
|
||||||
|
uint16_t GetAdcValue(uint8_t index);
|
||||||
|
#endif
|
||||||
|
|
||||||
157
Bsp/bsp_air.c
Normal file
157
Bsp/bsp_air.c
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
#include "bsp_air.h"
|
||||||
|
#include "bsp_spi.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
static air_staus_struct air_staus;
|
||||||
|
|
||||||
|
void set_single_air_staus(air_num_enum air_num,air_run_action_enum air_run_action)
|
||||||
|
{
|
||||||
|
switch((uint8_t)air_num)
|
||||||
|
{
|
||||||
|
case AIR_1:
|
||||||
|
air_staus.value1 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_2:
|
||||||
|
air_staus.value2 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_3:
|
||||||
|
air_staus.value3 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_4:
|
||||||
|
air_staus.value4 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_5:
|
||||||
|
air_staus.value5 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_6:
|
||||||
|
air_staus.value6 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_7:
|
||||||
|
air_staus.value7 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_8:
|
||||||
|
air_staus.value8 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_9:
|
||||||
|
air_staus.value9 = air_run_action;
|
||||||
|
break;
|
||||||
|
case AIR_10:
|
||||||
|
air_staus.value10 = air_run_action;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_all_air_staus(air_run_action_enum air_run_action)
|
||||||
|
{
|
||||||
|
for(air_num_enum air_num = AIR_1; air_num < AIR_MAX_NUM; air_num++)
|
||||||
|
{
|
||||||
|
set_single_air_staus(air_num,air_run_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static uint16_t CalChecksum(uint8_t * data, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t sum = 0;
|
||||||
|
for(int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
sum += data[i];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*<2A><><EFBFBD><EFBFBD>һ֡*/
|
||||||
|
static uint8_t creat_air_frame(uint8_t device_id, uint8_t message_type, uint8_t error_flag, air_staus_struct air_staus, air_spi_frame_struct *tx_frame)
|
||||||
|
{
|
||||||
|
tx_frame->device_id = device_id;
|
||||||
|
tx_frame->message_type = message_type;
|
||||||
|
tx_frame->error_flag = error_flag;
|
||||||
|
tx_frame->value_1 = air_staus.value1;
|
||||||
|
tx_frame->value_2 = air_staus.value2;
|
||||||
|
tx_frame->value_3 = air_staus.value3;
|
||||||
|
tx_frame->value_4 = air_staus.value4;
|
||||||
|
tx_frame->value_5 = air_staus.value5;
|
||||||
|
tx_frame->value_6 = air_staus.value6;
|
||||||
|
tx_frame->value_7 = air_staus.value7;
|
||||||
|
tx_frame->value_8 = air_staus.value8;
|
||||||
|
tx_frame->value_9 = air_staus.value9;
|
||||||
|
tx_frame->value_10 = air_staus.value10;
|
||||||
|
|
||||||
|
tx_frame->check_sum = CalChecksum((uint8_t *)tx_frame,sizeof(air_spi_frame_struct) - 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*<2A><><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD>*/
|
||||||
|
static uint8_t air_frame_rev(air_spi_frame_struct *tx_frame, air_spi_frame_struct *rx_frame)
|
||||||
|
{
|
||||||
|
if(spi_tx_rx_buffer((uint8_t*)tx_frame,(uint8_t *)rx_frame,sizeof(air_spi_frame_struct)))
|
||||||
|
{
|
||||||
|
if(rx_frame->device_id != 0x01)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(rx_frame->message_type != 0x01)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(rx_frame->check_sum != CalChecksum((uint8_t *)rx_frame, sizeof(air_spi_frame_struct) - 1))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD>봦<EFBFBD><EBB4A6>*/
|
||||||
|
static void air_frame_error_handle(uint8_t error_flag)
|
||||||
|
{
|
||||||
|
if(error_flag & AIR_PUMP_ERROR)
|
||||||
|
{
|
||||||
|
printf("...");
|
||||||
|
}
|
||||||
|
if(error_flag & VALUE_JAM)
|
||||||
|
{
|
||||||
|
printf("...");
|
||||||
|
}
|
||||||
|
if(error_flag & OVER_VOLTAGE_ALARM)
|
||||||
|
{
|
||||||
|
printf("...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//100ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||||
|
void air_handle(void)
|
||||||
|
{
|
||||||
|
static air_spi_frame_struct tx_frame;
|
||||||
|
static air_spi_frame_struct rx_frame;
|
||||||
|
static uint8_t out_time_cnt;
|
||||||
|
creat_air_frame(0x01,0x00,0x00, air_staus, &tx_frame);
|
||||||
|
if(air_frame_rev(&tx_frame, &rx_frame))
|
||||||
|
{
|
||||||
|
if(rx_frame.error_flag == 0)
|
||||||
|
{
|
||||||
|
out_time_cnt = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
air_frame_error_handle(rx_frame.error_flag);
|
||||||
|
out_time_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out_time_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(out_time_cnt >= 30)
|
||||||
|
{
|
||||||
|
printf("ͨ<EFBFBD>ų<EFBFBD>ʱ");
|
||||||
|
spi1_init();
|
||||||
|
out_time_cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
80
Bsp/bsp_air.h
Normal file
80
Bsp/bsp_air.h
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#ifndef _BSP_AIR_H
|
||||||
|
#define _BSP_AIR_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
AIR_1,
|
||||||
|
AIR_2,
|
||||||
|
AIR_3,
|
||||||
|
AIR_4,
|
||||||
|
AIR_5,
|
||||||
|
AIR_6,
|
||||||
|
AIR_7,
|
||||||
|
AIR_8,
|
||||||
|
AIR_9,
|
||||||
|
AIR_10,
|
||||||
|
AIR_MAX_NUM,
|
||||||
|
}air_num_enum;//<2F><><EFBFBD>Һ<EFBFBD>
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CHARGE_AIR = 0x01,
|
||||||
|
STOP_AIR = 0x02,
|
||||||
|
DISCHARGE_AIR = 0x03,
|
||||||
|
}air_run_action_enum;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t value1 : 2;
|
||||||
|
uint8_t value2 : 2;
|
||||||
|
uint8_t value3 : 2;
|
||||||
|
uint8_t value4 : 2;
|
||||||
|
uint8_t value5 : 2;
|
||||||
|
uint8_t value6 : 2;
|
||||||
|
uint8_t value7 : 2;
|
||||||
|
uint8_t value8 : 2;
|
||||||
|
uint8_t value9 : 2;
|
||||||
|
uint8_t value10 : 2;
|
||||||
|
uint8_t : 4;
|
||||||
|
}air_staus_struct;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t : 2; //<2F><><EFBFBD><EFBFBD>λ
|
||||||
|
uint8_t message_type : 2;//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||||||
|
uint8_t device_id : 4;//<2F>豸id
|
||||||
|
//<2F><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
||||||
|
uint8_t value_4 : 2;//<2F><><EFBFBD><EFBFBD>4
|
||||||
|
uint8_t value_3 : 2;//<2F><><EFBFBD><EFBFBD>3
|
||||||
|
uint8_t value_2 : 2;//<2F><><EFBFBD><EFBFBD>2
|
||||||
|
uint8_t value_1 : 2;//<2F><><EFBFBD><EFBFBD>1
|
||||||
|
//<2F>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||||
|
uint8_t value_8 : 2;//<2F><><EFBFBD><EFBFBD>8
|
||||||
|
uint8_t value_7 : 2;//<2F><><EFBFBD><EFBFBD>7
|
||||||
|
uint8_t value_6 : 2;//<2F><><EFBFBD><EFBFBD>6
|
||||||
|
uint8_t value_5 : 2;//<2F><><EFBFBD><EFBFBD>5
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||||
|
uint8_t : 4;//<2F><><EFBFBD><EFBFBD>λ
|
||||||
|
uint8_t value_10 : 2;//<2F><><EFBFBD><EFBFBD>10
|
||||||
|
uint8_t value_9 : 2;//<2F><><EFBFBD><EFBFBD>9
|
||||||
|
//<2F><><EFBFBD>ĸ<EFBFBD><C4B8>ֽ<EFBFBD>
|
||||||
|
uint8_t error_flag : 8;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||||
|
uint8_t check_sum : 8;//У<><D0A3><EFBFBD><EFBFBD>
|
||||||
|
}air_spi_frame_struct;//Э<><D0AD>֡
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
AIR_PUMP_ERROR = 0X01,
|
||||||
|
VALUE_JAM = 0X02,
|
||||||
|
OVER_VOLTAGE_ALARM = 0X04,
|
||||||
|
OVER_TEMPERATURE = 0X08,
|
||||||
|
CHECK_COURSE = 0X10,
|
||||||
|
LOW_VOLTAGE_ERROR = 0X20,
|
||||||
|
COMMUNICATION_OVER_TIME = 0X40,
|
||||||
|
}error_flag_enum;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
void air_handle(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
50
Bsp/bsp_airsac.c
Normal file
50
Bsp/bsp_airsac.c
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include "bsp_airsac.h"
|
||||||
|
#include "bsp_mos.h"
|
||||||
|
#include "bsp_moto.h"
|
||||||
|
void airsac_charge(airsac_num airsac)
|
||||||
|
{
|
||||||
|
mos_union mos_data = {0};
|
||||||
|
|
||||||
|
set_moto_out(1, 1001);
|
||||||
|
mos_data.mos = MOS(airsac + 10);
|
||||||
|
mos_set(mos_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void airsac_discharge(airsac_num airsac)
|
||||||
|
{
|
||||||
|
mos_union mos_data = {0};
|
||||||
|
set_moto_out(1, 0);
|
||||||
|
mos_data.mos = MOS(airsac);
|
||||||
|
mos_set(mos_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void all_airsac_discharge(void)
|
||||||
|
{
|
||||||
|
mos_union mos_data = {0};
|
||||||
|
|
||||||
|
set_moto_out(1,0);
|
||||||
|
mos_data.mos = ALL_PRESSURIZE_MOS;
|
||||||
|
mos_set(mos_data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void all_airsac_charge(void)
|
||||||
|
{
|
||||||
|
mos_union mos_data = {0};
|
||||||
|
|
||||||
|
set_moto_out(1, 1001);
|
||||||
|
mos_data.mos = ALL_INLET_MOS;
|
||||||
|
mos_set(mos_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void airsac_stop(void)
|
||||||
|
{
|
||||||
|
mos_union mos_data = {0};
|
||||||
|
mos_data.mos = ~ALL_MOS;
|
||||||
|
set_moto_out(1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
27
Bsp/bsp_airsac.h
Normal file
27
Bsp/bsp_airsac.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef __BSP_AIRSAC_H
|
||||||
|
#define __BSP_AIRSAC_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
AIRSAC0,
|
||||||
|
AIRSAC1,
|
||||||
|
AIRSAC2,
|
||||||
|
AIRSAC3,
|
||||||
|
AIRSAC4,
|
||||||
|
AIRSAC5,
|
||||||
|
AIRSAC6,
|
||||||
|
AIRSAC7,
|
||||||
|
AIRSAC8,
|
||||||
|
AIRSAC9,
|
||||||
|
AIRSAC_MAX_NUM
|
||||||
|
}airsac_num;
|
||||||
|
|
||||||
|
void airsac_charge(airsac_num airsac);
|
||||||
|
void airsac_discharge(airsac_num airsac);
|
||||||
|
void all_airsac_discharge(void);
|
||||||
|
void all_airsac_charge(void);
|
||||||
|
void airsac_stop(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
315
Bsp/bsp_can.c
Normal file
315
Bsp/bsp_can.c
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
#include "bsp_can.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "systick.h"
|
||||||
|
|
||||||
|
can_rx_message_type can1_receive_message_fifo0;
|
||||||
|
can_tx_message_type can1_transmit_message;
|
||||||
|
volatile Enum_can_mode can1_receive_fifo0_flag;
|
||||||
|
|
||||||
|
uint8_t bit12[8];
|
||||||
|
uint8_t bit13[8];
|
||||||
|
uint8_t bit14[8];
|
||||||
|
uint8_t bit15[8];
|
||||||
|
uint8_t bit16[8];
|
||||||
|
uint8_t bit17[8];
|
||||||
|
uint8_t bit18[8];
|
||||||
|
uint8_t bit19[8];
|
||||||
|
uint8_t bit20[8];
|
||||||
|
|
||||||
|
void TJA1042_STB_Config(void) {
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
/* <20><><EFBFBD><EFBFBD> GPIOA ʱ<><CAB1> */
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_12; // ѡ<><D1A1> PA0
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; // <20><><EFBFBD><EFBFBD>ģʽ
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_12);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void can1_gpio_config(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
/* enable the gpio clock */
|
||||||
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the can tx, rx pin */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_11 | GPIO_PINS_12;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE12, GPIO_MUX_9);
|
||||||
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE11, GPIO_MUX_9);
|
||||||
|
TJA1042_STB_Config();
|
||||||
|
delay_ms(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief can configiguration.
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
static void can1_configuration(void)
|
||||||
|
{
|
||||||
|
can_base_type can_base_struct;
|
||||||
|
can_baudrate_type can_baudrate_struct;
|
||||||
|
can_filter_init_type can_filter_init_struct;
|
||||||
|
/* enable the can clock */
|
||||||
|
crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* can base init */
|
||||||
|
can_default_para_init(&can_base_struct);
|
||||||
|
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
|
||||||
|
can_base_struct.ttc_enable = FALSE;
|
||||||
|
can_base_struct.aebo_enable = FALSE;
|
||||||
|
can_base_struct.aed_enable = FALSE;
|
||||||
|
can_base_struct.prsf_enable = FALSE;
|
||||||
|
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
|
||||||
|
can_base_struct.mmssr_selection = CAN_SENDING_BY_REQUEST;
|
||||||
|
|
||||||
|
can_base_init(CAN1, &can_base_struct);
|
||||||
|
|
||||||
|
/* can baudrate, set boudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size)) */
|
||||||
|
can_baudrate_struct.baudrate_div = 30;
|
||||||
|
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ;
|
||||||
|
can_baudrate_struct.bts1_size = CAN_BTS1_6TQ;
|
||||||
|
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ;
|
||||||
|
can_baudrate_set(CAN1, &can_baudrate_struct);
|
||||||
|
|
||||||
|
|
||||||
|
/*can_filter_0_config--------------------------------------------------------------*/
|
||||||
|
can_filter_init_struct.filter_activate_enable = TRUE;
|
||||||
|
can_filter_init_struct.filter_number = 0;
|
||||||
|
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
|
||||||
|
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
|
||||||
|
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
|
||||||
|
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
|
||||||
|
can_filter_init_struct.filter_id_high = 0x0000;
|
||||||
|
can_filter_init_struct.filter_id_low = 0x0000;
|
||||||
|
can_filter_init_struct.filter_mask_high = 0x0000;
|
||||||
|
can_filter_init_struct.filter_mask_low = 0x0000;
|
||||||
|
|
||||||
|
can_filter_init(CAN1, &can_filter_init_struct);
|
||||||
|
|
||||||
|
/* can interrupt config */
|
||||||
|
//nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00);
|
||||||
|
nvic_irq_enable(CAN1_RX0_IRQn, 2, 0);
|
||||||
|
can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
||||||
|
|
||||||
|
// /* error interrupt enable */
|
||||||
|
// can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE);
|
||||||
|
// can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void can1_init(void)
|
||||||
|
{
|
||||||
|
can1_gpio_config();
|
||||||
|
can1_configuration();
|
||||||
|
delay_ms(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void send_can1_data(uint32_t id, uint8_t *msg, uint8_t msg_len)
|
||||||
|
{
|
||||||
|
// over_time = 600;
|
||||||
|
uint16_t over_time = 600;
|
||||||
|
if(msg_len > 8)
|
||||||
|
{
|
||||||
|
msg_len = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
can1_transmit_message.standard_id = id;
|
||||||
|
can1_transmit_message.extended_id = 0;
|
||||||
|
can1_transmit_message.id_type = CAN_ID_STANDARD;
|
||||||
|
can1_transmit_message.frame_type = CAN_TFT_DATA;
|
||||||
|
can1_transmit_message.dlc = msg_len;
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < msg_len; i++)
|
||||||
|
can1_transmit_message.data[i] = msg[i];
|
||||||
|
|
||||||
|
|
||||||
|
/* transmit message */
|
||||||
|
while((can_message_transmit(CAN1, &can1_transmit_message) == CAN_TX_STATUS_NO_EMPTY) && (over_time))
|
||||||
|
{
|
||||||
|
over_time--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void send_can1_buffer(uint32_t id, uint8_t *buffer, uint16_t buffer_len)
|
||||||
|
{
|
||||||
|
uint8_t temp1 = buffer_len/8;
|
||||||
|
uint8_t temp2 = buffer_len%8;
|
||||||
|
|
||||||
|
|
||||||
|
if(temp1 == 0)
|
||||||
|
{
|
||||||
|
send_can1_data(id, buffer, buffer_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(uint8_t i = 0; i < temp1; i++)
|
||||||
|
{
|
||||||
|
send_can1_data(id, buffer + 8*i, 8);
|
||||||
|
}
|
||||||
|
if(temp2 != 0)
|
||||||
|
{
|
||||||
|
send_can1_data(id, buffer+(buffer_len - temp2), temp2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAN1_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
|
if (can_flag_get(CAN1, CAN_RF0MN_FLAG) == SET)
|
||||||
|
{
|
||||||
|
can_flag_clear(CAN1, CAN_RF0MN_FLAG);
|
||||||
|
can_message_receive(CAN1, CAN_RX_FIFO0, &can1_receive_message_fifo0);
|
||||||
|
|
||||||
|
// ֱ<><D6B1>ʹ<EFBFBD><CAB9> can1_receive_message_fifo0
|
||||||
|
// switch(can1_receive_message_fifo0.standard_id)
|
||||||
|
// {
|
||||||
|
// case 0x014:
|
||||||
|
// // <20><><EFBFBD><EFBFBD>ID 0x020
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit20);
|
||||||
|
// break;
|
||||||
|
// case 0x013:
|
||||||
|
// // <20><><EFBFBD><EFBFBD>ID 0x002
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit19);
|
||||||
|
// break;
|
||||||
|
// case 0x012:
|
||||||
|
// // <20><><EFBFBD><EFBFBD>ID 0x003
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit18);
|
||||||
|
// break;
|
||||||
|
// case 0x11:
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit17);
|
||||||
|
// break;
|
||||||
|
// case 0x10:
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit16);
|
||||||
|
// break;
|
||||||
|
// case 0x00F:
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit15);
|
||||||
|
// break;
|
||||||
|
// case 0x00E:
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit14);
|
||||||
|
// break;
|
||||||
|
// case 0x00D:
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit13);
|
||||||
|
// break;
|
||||||
|
// case 0x00C:
|
||||||
|
// can1_transmit_data_pressure(can1_receive_message_fifo0.standard_id,bit12);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void can_transmit_all_id(){
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x014,bit20);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x013,bit19);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x012,bit18);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x011,bit17);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x010,bit16);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x00F,bit15);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x00E,bit14);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x00D,bit13);
|
||||||
|
|
||||||
|
|
||||||
|
can1_transmit_data_pressure(0x00C,bit12);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
/* can transmit data */
|
||||||
|
|
||||||
|
void can1_transmit_data_pressure(uint32_t id,uint8_t pressure[8])
|
||||||
|
{
|
||||||
|
uint16_t over_time = 600;
|
||||||
|
uint8_t transmit_status;
|
||||||
|
can_tx_message_type tx_message_struct;
|
||||||
|
tx_message_struct.standard_id = id;
|
||||||
|
tx_message_struct.extended_id = 0;
|
||||||
|
tx_message_struct.id_type = CAN_ID_STANDARD;
|
||||||
|
tx_message_struct.frame_type = CAN_TFT_DATA;
|
||||||
|
tx_message_struct.dlc = 8;
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
for(int i = 0; i < 8; i++) {
|
||||||
|
tx_message_struct.data[i] = pressure[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||||
|
transmit_status = can_message_transmit(CAN1, &tx_message_struct);
|
||||||
|
|
||||||
|
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>ʱ
|
||||||
|
while((transmit_status == CAN_TX_STATUS_NO_EMPTY) && (over_time > 0))
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>С<EFBFBD>ӳ٣<D3B3><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||||
|
delay_us(10); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
// <20><><EFBFBD>¼<EFBFBD><C2BC>鷢<EFBFBD><E9B7A2>״̬
|
||||||
|
transmit_status = can_message_transmit(CAN1, &tx_message_struct);
|
||||||
|
over_time--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void copyToBytes(uint8_t externalArray[12][12]) {
|
||||||
|
for(int i=0;i<8;i++){
|
||||||
|
bit20[i]=externalArray[7][i];
|
||||||
|
}
|
||||||
|
for(int i=0;i<7;i++){
|
||||||
|
bit12[i]=externalArray[6-i][0];
|
||||||
|
}
|
||||||
|
for(int i=0;i<7;i++){
|
||||||
|
bit13[i]=externalArray[6-i][7];
|
||||||
|
}
|
||||||
|
for(int i=0;i<4;i++){
|
||||||
|
bit14[i]=externalArray[6][2+i];
|
||||||
|
bit14[4 + i]=externalArray[5][2+i];
|
||||||
|
}
|
||||||
|
for(int i=0;i<2;i++){
|
||||||
|
bit15[i] = externalArray[6-i][1];
|
||||||
|
bit15[2+i] = externalArray[6-i][6];
|
||||||
|
}
|
||||||
|
for(int i=0;i<4;i++){
|
||||||
|
bit15[4+i] = externalArray[4][2+i];
|
||||||
|
}
|
||||||
|
bit16[0] = externalArray[4][1];
|
||||||
|
bit16[1] = externalArray[4][6];
|
||||||
|
for(int i=0;i<6;i++){
|
||||||
|
bit16[2+i] = externalArray[3][i+1];
|
||||||
|
}
|
||||||
|
for(int i =0;i<6;i++){
|
||||||
|
bit17[i] = externalArray[2][i+1];
|
||||||
|
bit18[i] = externalArray[1][i+1];
|
||||||
|
bit19[i] = externalArray[0][i+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
26
Bsp/bsp_can.h
Normal file
26
Bsp/bsp_can.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __BSP_CAN_h
|
||||||
|
#define __BSP_CAN_h
|
||||||
|
|
||||||
|
#include "at32a423.h"
|
||||||
|
#define DEV_CAN1_ID (0x300)
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CAN_DISABLE,
|
||||||
|
CAN_ONCE_TIGGER,
|
||||||
|
CAN_CONTINUE
|
||||||
|
}Enum_can_mode;
|
||||||
|
|
||||||
|
extern volatile Enum_can_mode can1_receive_fifo0_flag;
|
||||||
|
|
||||||
|
void can1_init(void);
|
||||||
|
void send_can1_data(uint32_t id, uint8_t *msg, uint8_t msg_len);
|
||||||
|
void send_can1_buffer(uint32_t id, uint8_t *buffer, uint16_t buffer_len);
|
||||||
|
/* can transmit data */
|
||||||
|
void can1_transmit_data(uint32_t id);
|
||||||
|
void copyToBytes(uint8_t externalArray[12][12]);
|
||||||
|
void can1_transmit_data_pressure(uint32_t id,uint8_t pressure[8]);
|
||||||
|
|
||||||
|
void can_transmit_all_id(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
249
Bsp/bsp_flash.c
Normal file
249
Bsp/bsp_flash.c
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************
|
||||||
|
* @file flash.c
|
||||||
|
* @brief flash program
|
||||||
|
**************************************************************************
|
||||||
|
* Copyright notice & Disclaimer
|
||||||
|
*
|
||||||
|
* The software Board Support Package (BSP) that is made available to
|
||||||
|
* download from Artery official website is the copyrighted work of Artery.
|
||||||
|
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||||
|
* software and its related documentation for the purpose of design and
|
||||||
|
* development in conjunction with Artery microcontrollers. Use of the
|
||||||
|
* software is governed by this copyright notice and the following disclaimer.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||||
|
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||||
|
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||||
|
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||||
|
*
|
||||||
|
**************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bsp_flash.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
/** @addtogroup AT32A423_periph_examples
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined (AT32A423xC)
|
||||||
|
#define SECTOR_SIZE 2048 /* this parameter depends on the specific model of the chip */
|
||||||
|
#else
|
||||||
|
#define SECTOR_SIZE 1024 /* this parameter depends on the specific model of the chip */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FLASH_HEAD 0XA55AA55A
|
||||||
|
#define FLASH_TAIL 0X5AA55AA5
|
||||||
|
|
||||||
|
uint16_t flash_buf[SECTOR_SIZE / 2];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief read data using halfword mode
|
||||||
|
* @param read_addr: the address of reading
|
||||||
|
* @param p_buffer: the buffer of reading data
|
||||||
|
* @param num_read: the number of reading data
|
||||||
|
* @retval 0 = success, 1 = fail
|
||||||
|
*/
|
||||||
|
uint8_t flash_read(uint32_t read_addr, void *p_buffer, uint32_t num_read)
|
||||||
|
{
|
||||||
|
uint16_t *buf = (uint16_t *)p_buffer;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for(i = 0; i < num_read; i++)
|
||||||
|
{
|
||||||
|
buf[i] = *(uint16_t*)(read_addr);
|
||||||
|
read_addr += 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief write data using halfword mode without checking
|
||||||
|
* @param write_addr: the address of writing
|
||||||
|
* @param p_buffer: the buffer of writing data
|
||||||
|
* @param num_write: the number of writing data
|
||||||
|
* @retval 0 = success, 1 = fail
|
||||||
|
*/
|
||||||
|
uint8_t flash_write_nocheck(uint32_t write_addr, const void *p_buffer, uint32_t num_write)
|
||||||
|
{
|
||||||
|
uint16_t *buf = (uint16_t *)p_buffer;
|
||||||
|
uint32_t i;
|
||||||
|
flash_status_type status = FLASH_OPERATE_DONE;
|
||||||
|
|
||||||
|
for(i = 0; i < num_write; i++)
|
||||||
|
{
|
||||||
|
status = flash_halfword_program(write_addr, buf[i]);
|
||||||
|
if(status != FLASH_OPERATE_DONE)
|
||||||
|
return 1;
|
||||||
|
write_addr += 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief write data using halfword mode with checking
|
||||||
|
* @param write_addr: the address of writing
|
||||||
|
* @param p_buffer: the buffer of writing data
|
||||||
|
* @param num_write: the number of writing data
|
||||||
|
* @retval 0 = success, 1 = fail
|
||||||
|
*/
|
||||||
|
uint8_t flash_write(uint32_t write_addr, const void *p_buffer, uint32_t num_write)
|
||||||
|
{
|
||||||
|
uint16_t *buf = (uint16_t *)p_buffer;
|
||||||
|
uint32_t offset_addr;
|
||||||
|
uint32_t sector_position;
|
||||||
|
uint32_t sector_offset;
|
||||||
|
uint32_t sector_remain;
|
||||||
|
uint32_t i;
|
||||||
|
flash_status_type status = FLASH_OPERATE_DONE;
|
||||||
|
|
||||||
|
flash_unlock();
|
||||||
|
offset_addr = write_addr - FLASH_BASE;
|
||||||
|
sector_position = offset_addr / SECTOR_SIZE;
|
||||||
|
sector_offset = (offset_addr % SECTOR_SIZE) / 2;
|
||||||
|
sector_remain = (SECTOR_SIZE / 2) - sector_offset;
|
||||||
|
|
||||||
|
if(num_write <= sector_remain)
|
||||||
|
sector_remain = num_write;
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
flash_read(sector_position * SECTOR_SIZE + FLASH_BASE, flash_buf, SECTOR_SIZE / 2);
|
||||||
|
for(i = 0; i < sector_remain; i++)
|
||||||
|
{
|
||||||
|
if(flash_buf[sector_offset + i] != 0xFFFF)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(i < sector_remain)
|
||||||
|
{
|
||||||
|
status = flash_operation_wait_for(ERASE_TIMEOUT);
|
||||||
|
|
||||||
|
if((status == FLASH_PROGRAM_ERROR) || (status == FLASH_EPP_ERROR))
|
||||||
|
flash_flag_clear(FLASH_PRGMERR_FLAG | FLASH_EPPERR_FLAG);
|
||||||
|
else if(status == FLASH_OPERATE_TIMEOUT)
|
||||||
|
{
|
||||||
|
flash_lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
status = flash_sector_erase(sector_position * SECTOR_SIZE + FLASH_BASE);
|
||||||
|
if(status != FLASH_OPERATE_DONE)
|
||||||
|
{
|
||||||
|
flash_lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
for(i = 0; i < sector_remain; i++)
|
||||||
|
{
|
||||||
|
flash_buf[i + sector_offset] = buf[i];
|
||||||
|
}
|
||||||
|
if(flash_write_nocheck(sector_position * SECTOR_SIZE + FLASH_BASE, flash_buf, SECTOR_SIZE / 2) != 0)
|
||||||
|
{
|
||||||
|
flash_lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(flash_write_nocheck(write_addr, buf, sector_remain) != 0)
|
||||||
|
{
|
||||||
|
flash_lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(num_write == sector_remain)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sector_position++;
|
||||||
|
sector_offset = 0;
|
||||||
|
buf += sector_remain;
|
||||||
|
write_addr += (sector_remain * 2);
|
||||||
|
num_write -= sector_remain;
|
||||||
|
if(num_write > (SECTOR_SIZE / 2))
|
||||||
|
sector_remain = SECTOR_SIZE / 2;
|
||||||
|
else
|
||||||
|
sector_remain = num_write;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flash_lock();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int load_config_params(flash_para_struct *params)
|
||||||
|
{
|
||||||
|
uint32_t *head = (uint32_t*)FMC_WRITE_START_ADDR;
|
||||||
|
uint32_t *tail = (uint32_t*)(FMC_WRITE_START_ADDR + sizeof(flash_para_struct) - 4);
|
||||||
|
|
||||||
|
if(*head == FLASH_HEAD && *tail == FLASH_TAIL)
|
||||||
|
{
|
||||||
|
memcpy((uint32_t *)params, head, sizeof(flash_para_struct));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_config_params(flash_para_struct *params)
|
||||||
|
{
|
||||||
|
params->flash_head = FLASH_HEAD;
|
||||||
|
params->flash_tail = FLASH_TAIL;
|
||||||
|
flash_write(FMC_WRITE_START_ADDR, params, sizeof(flash_para_struct)/sizeof(uint16_t));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
* @param sector_addr <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||||
|
* @param len <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>δʹ<CEB4>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ֽӿڼ<D3BF><DABC>ݣ<EFBFBD>
|
||||||
|
* @return 0 = success, 1 = fail
|
||||||
|
*/
|
||||||
|
uint8_t flash_erase(uint32_t sector_addr, uint32_t len)
|
||||||
|
{
|
||||||
|
flash_status_type status;
|
||||||
|
|
||||||
|
flash_unlock();
|
||||||
|
status = flash_operation_wait_for(ERASE_TIMEOUT);
|
||||||
|
if(status == FLASH_OPERATE_TIMEOUT)
|
||||||
|
{
|
||||||
|
flash_lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((status == FLASH_PROGRAM_ERROR) || (status == FLASH_EPP_ERROR))
|
||||||
|
{
|
||||||
|
flash_flag_clear(FLASH_PRGMERR_FLAG | FLASH_EPPERR_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = flash_sector_erase(sector_addr);
|
||||||
|
flash_lock();
|
||||||
|
|
||||||
|
return (status == FLASH_OPERATE_DONE) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t bsp_flash_is_erased(uint32_t addr, uint32_t size)
|
||||||
|
{
|
||||||
|
const uint8_t *flash_ptr = (const uint8_t *)addr;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for (i = 0U; i < size; i++)
|
||||||
|
{
|
||||||
|
if (flash_ptr[i] != 0xFF)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
72
Bsp/bsp_flash.h
Normal file
72
Bsp/bsp_flash.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************
|
||||||
|
* @file flash.h
|
||||||
|
* @brief flash header file
|
||||||
|
**************************************************************************
|
||||||
|
* Copyright notice & Disclaimer
|
||||||
|
*
|
||||||
|
* The software Board Support Package (BSP) that is made available to
|
||||||
|
* download from Artery official website is the copyrighted work of Artery.
|
||||||
|
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||||
|
* software and its related documentation for the purpose of design and
|
||||||
|
* development in conjunction with Artery microcontrollers. Use of the
|
||||||
|
* software is governed by this copyright notice and the following disclaimer.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||||
|
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||||
|
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||||
|
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||||
|
*
|
||||||
|
**************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __BSP_FLASH_H__
|
||||||
|
#define __BSP_FLASH_H__
|
||||||
|
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
#define FMC_WRITE_START_ADDR (0x08000000 + 1024 * 50)
|
||||||
|
|
||||||
|
#pragma pack (1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t flash_head;
|
||||||
|
uint16_t output_mode;
|
||||||
|
uint16_t output_ax;
|
||||||
|
uint16_t output_ay;
|
||||||
|
uint16_t min_trigger_res_value;
|
||||||
|
uint16_t max_trigger_res_value;
|
||||||
|
uint16_t div_trigger_res;
|
||||||
|
uint32_t flash_tail;
|
||||||
|
}flash_para_struct;
|
||||||
|
#pragma pack ()
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>Ϊƥ<CEAA><C6A5><EFBFBD>ṹ<EFBFBD><E1B9B9>Ҫ<EFBFBD><D2AA><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t flash_read(uint32_t read_addr, void *p_buffer, uint32_t num_read);
|
||||||
|
uint8_t flash_write_nocheck(uint32_t write_addr, const void *p_buffer, uint32_t num_write);
|
||||||
|
uint8_t flash_write(uint32_t write_addr, const void *p_Buffer, uint32_t num_write);
|
||||||
|
|
||||||
|
int load_config_params(flash_para_struct *params);
|
||||||
|
int save_config_params(flash_para_struct *params);
|
||||||
|
|
||||||
|
uint8_t flash_erase(uint32_t sector_addr, uint32_t len);
|
||||||
|
uint8_t bsp_flash_is_erased(uint32_t addr, uint32_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
86
Bsp/bsp_led.c
Normal file
86
Bsp/bsp_led.c
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#include "bsp_led.h"
|
||||||
|
|
||||||
|
gpio_type *led_gpio_port[LED_NUM] =
|
||||||
|
{
|
||||||
|
LED2_GPIO,
|
||||||
|
LED3_GPIO,
|
||||||
|
LED4_GPIO
|
||||||
|
};
|
||||||
|
uint16_t led_gpio_pin[LED_NUM] =
|
||||||
|
{
|
||||||
|
LED2_PIN,
|
||||||
|
LED3_PIN,
|
||||||
|
LED4_PIN
|
||||||
|
};
|
||||||
|
crm_periph_clock_type led_gpio_crm_clk[LED_NUM] =
|
||||||
|
{
|
||||||
|
LED2_GPIO_CRM_CLK,
|
||||||
|
LED3_GPIO_CRM_CLK,
|
||||||
|
LED4_GPIO_CRM_CLK
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void bsp_led_init(led_type led)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
/* enable the led clock */
|
||||||
|
crm_periph_clock_enable(led_gpio_crm_clk[led], TRUE);
|
||||||
|
|
||||||
|
/* set default parameter */
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the led gpio */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||||
|
gpio_init_struct.gpio_pins = led_gpio_pin[led];
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(led_gpio_port[led], &gpio_init_struct);
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_7);
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_7);
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_7);
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bsp_led_on(led_type led)
|
||||||
|
{
|
||||||
|
if(led > (LED_NUM - 1))
|
||||||
|
return;
|
||||||
|
if(led_gpio_pin[led])
|
||||||
|
led_gpio_port[led]->clr = led_gpio_pin[led];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief turns selected led off.
|
||||||
|
* @param led: specifies the led to be set off.
|
||||||
|
* this parameter can be one of following parameters:
|
||||||
|
* @arg LED2
|
||||||
|
* @arg LED3
|
||||||
|
* @arg LED4
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void bsp_led_off(led_type led)
|
||||||
|
{
|
||||||
|
if(led > (LED_NUM - 1))
|
||||||
|
return;
|
||||||
|
if(led_gpio_pin[led])
|
||||||
|
led_gpio_port[led]->scr = led_gpio_pin[led];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief turns selected led toggle.
|
||||||
|
* @param led: specifies the led to be set off.
|
||||||
|
* this parameter can be one of following parameters:
|
||||||
|
* @arg LED2
|
||||||
|
* @arg LED3
|
||||||
|
* @arg LED4
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void bsp_led_toggle(led_type led)
|
||||||
|
{
|
||||||
|
if(led > (LED_NUM - 1))
|
||||||
|
return;
|
||||||
|
if(led_gpio_pin[led])
|
||||||
|
led_gpio_port[led]->odt ^= led_gpio_pin[led];
|
||||||
|
}
|
||||||
35
Bsp/bsp_led.h
Normal file
35
Bsp/bsp_led.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef __BSP_LED_H
|
||||||
|
#define __BSP_LED_H
|
||||||
|
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
#define LED_NUM 3
|
||||||
|
|
||||||
|
#define LED2_PIN GPIO_PINS_7
|
||||||
|
#define LED2_GPIO GPIOB
|
||||||
|
#define LED2_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
|
||||||
|
|
||||||
|
#define LED3_PIN GPIO_PINS_7
|
||||||
|
#define LED3_GPIO GPIOB
|
||||||
|
#define LED3_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
|
||||||
|
|
||||||
|
#define LED4_PIN GPIO_PINS_7
|
||||||
|
#define LED4_GPIO GPIOB
|
||||||
|
#define LED4_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LED2 = 0,
|
||||||
|
LED3 = 1,
|
||||||
|
LED4 = 2
|
||||||
|
} led_type;
|
||||||
|
|
||||||
|
|
||||||
|
void bsp_led_init(led_type led);
|
||||||
|
void bsp_led_on(led_type led);
|
||||||
|
void bsp_led_off(led_type led);
|
||||||
|
void bsp_led_toggle(led_type led);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
235
Bsp/bsp_lin.c
Normal file
235
Bsp/bsp_lin.c
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
#include "bsp_lin.h"
|
||||||
|
#include "circular_buffer.h"
|
||||||
|
|
||||||
|
|
||||||
|
static lin_error_enum lin_error = FIFO_VOID;
|
||||||
|
static lin_rxstate_enum lin_rxstateget = BREAK_GET;
|
||||||
|
static lin_msg_struct lin_msg = {0};
|
||||||
|
static CircBuf_t lin_rx_circbuf = {0};//<2F><><EFBFBD>ջ<EFBFBD><D5BB>ζ<EFBFBD><CEB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
|
||||||
|
void lin_init(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
crm_periph_clock_enable(CRM_USART5_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
// TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_default_para_init(&gpio_init_struct); // <20><><EFBFBD>սṹ<D5BD><E1B9B9>
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; // <20>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; // <20><><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>ģʽ
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_3; // TX<54><58><EFBFBD><EFBFBD>
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct); // <20><>ʼ<EFBFBD><CABC>TX<54><58><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE3, GPIO_MUX_10);
|
||||||
|
|
||||||
|
// RX<52><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; // <20><><EFBFBD><EFBFBD>ģʽ
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_4; // RX<52><58><EFBFBD><EFBFBD>
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct); // <20><>ʼ<EFBFBD><CABC>RX<52><58><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE4, GPIO_MUX_10);
|
||||||
|
|
||||||
|
// USART<52><54><EFBFBD><EFBFBD>
|
||||||
|
usart_init(USART5, Lin_Speed, USART_DATA_8BITS, USART_STOP_1_BIT);
|
||||||
|
usart_transmitter_enable(USART5, TRUE); // ʹ<>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
usart_receiver_enable(USART5, TRUE); // ʹ<>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
usart_parity_selection_config(USART5, USART_PARITY_NONE); // <20><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>
|
||||||
|
usart_break_bit_num_set(USART5, USART_BREAK_11BITS); // <20><>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
||||||
|
usart_lin_mode_enable(USART5, TRUE); // <20><><EFBFBD><EFBFBD>LINģʽ
|
||||||
|
|
||||||
|
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
nvic_irq_enable(USART5_IRQn, 0, 0); // <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||||
|
usart_enable(USART5, TRUE); // ʹ<><CAB9>USART1
|
||||||
|
usart_interrupt_enable(USART5, USART_BF_INT, TRUE); // ʹ<><CAB9>֡<EFBFBD>ж<EFBFBD>
|
||||||
|
usart_interrupt_enable(USART5, USART_RDBF_INT,TRUE);// ʹ<>ܴ<EFBFBD><DCB4>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
|
||||||
|
CircBuf_Alloc(&lin_rx_circbuf, sizeof(lin_msg_struct)*2);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t lin_getpid(uint8_t id)
|
||||||
|
{
|
||||||
|
uint8_t pid = 0, p0 = 0, p1 = 0;
|
||||||
|
|
||||||
|
p0 = (((id>>0)^(id>>1)^(id>>2)^(id>>4))&0x01)<<6;//żУ<C5BC><D0A3>λ
|
||||||
|
p1 = ((~((id>>1)^(id>>3)^(id>>4)^(id>>5)))&0x01)<<7;//<2F><>У<EFBFBD><D0A3>λ
|
||||||
|
pid = (id|p0|p1);
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t lin_getchecksum(uint8_t pid, uint8_t* p_data, uint8_t data_len, uint8_t flag)
|
||||||
|
{
|
||||||
|
uint16_t checksum = 0;
|
||||||
|
if((pid != 0x3c)&&(pid != 0x7d))
|
||||||
|
{
|
||||||
|
checksum = pid;
|
||||||
|
}
|
||||||
|
for(uint8_t i = 0; i < data_len; i++)
|
||||||
|
{
|
||||||
|
checksum += p_data[i];
|
||||||
|
if(checksum > 0xff)
|
||||||
|
{
|
||||||
|
checksum -=0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(flag == 0)
|
||||||
|
{
|
||||||
|
return (~checksum) & 0xff; //<2F><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>Ҫȡ<D2AA><C8A1>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return checksum & 0xff; //<2F><><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD>Ҫ
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lin_send_bytes(usart_type * usart_x, uint8_t* p_data, uint8_t data_len)
|
||||||
|
{
|
||||||
|
for(uint8_t i = 0; i < data_len; i++)
|
||||||
|
{
|
||||||
|
usart_data_transmit(usart_x, *p_data++);
|
||||||
|
while(usart_flag_get(USART3, USART_TDBE_FLAG) == RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lin_rx_data(uint8_t pid, uint8_t* p_data, uint8_t data_len)
|
||||||
|
{
|
||||||
|
uint8_t lin_buffer[data_len + 1];
|
||||||
|
uint8_t checksum = lin_getchecksum(pid, p_data, data_len, 0);
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < data_len; i++)
|
||||||
|
{
|
||||||
|
lin_buffer[i] = *(p_data + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
lin_buffer[data_len] = checksum;
|
||||||
|
lin_send_bytes(USART3,lin_buffer, data_len + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void lin_master_rxmsg(uint8_t data)
|
||||||
|
{
|
||||||
|
lin_msg_struct* p_lin_msg = &lin_msg;
|
||||||
|
|
||||||
|
switch((uint8_t)lin_rxstateget)
|
||||||
|
{
|
||||||
|
case BREAK_GET:
|
||||||
|
break;
|
||||||
|
case SYNCH_GET:
|
||||||
|
{
|
||||||
|
if(data != 0x55)
|
||||||
|
{
|
||||||
|
lin_error = SYNC_ERR;
|
||||||
|
lin_rxstateget = BREAK_GET;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p_lin_msg->sync = data;
|
||||||
|
lin_rxstateget = PID_GET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PID_GET:
|
||||||
|
{
|
||||||
|
p_lin_msg->frameid = data&0x3f;
|
||||||
|
p_lin_msg->pid = data;
|
||||||
|
uint8_t pid = lin_getpid(p_lin_msg->frameid);
|
||||||
|
|
||||||
|
if(pid == p_lin_msg->pid)
|
||||||
|
{
|
||||||
|
if(p_lin_msg->frameid == 0x03) //ִ<><D6B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
{
|
||||||
|
lin_rxstateget = MSG_GET;
|
||||||
|
p_lin_msg->datalen = 0;
|
||||||
|
}
|
||||||
|
else if(p_lin_msg->frameid == 0x32) //<2F><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD>lin<69><6E><EFBFBD>߷<EFBFBD><DFB7><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||||
|
{
|
||||||
|
lin_rx_data(p_lin_msg->pid, &data, 1);
|
||||||
|
lin_rxstateget = BREAK_GET;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lin_rxstateget = BREAK_GET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lin_error = PID_ERR;
|
||||||
|
lin_rxstateget = BREAK_GET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_GET:
|
||||||
|
{
|
||||||
|
p_lin_msg->data[p_lin_msg->datalen++] = data;
|
||||||
|
lin_rxstateget = (p_lin_msg->datalen >= 8) ? CHECKSUM_GET:MSG_GET;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHECKSUM_GET:
|
||||||
|
{
|
||||||
|
p_lin_msg->checksum = data;
|
||||||
|
uint8_t checksum = lin_getchecksum(p_lin_msg->pid, p_lin_msg->data, p_lin_msg->datalen, 1);
|
||||||
|
if((checksum + p_lin_msg->checksum) == 0xff)
|
||||||
|
{
|
||||||
|
CircBuf_Push(&lin_rx_circbuf, (uint8_t *)p_lin_msg, sizeof(lin_msg_struct));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lin_error = FORMAT_ERR;
|
||||||
|
}
|
||||||
|
lin_rxstateget = BREAK_GET;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
lin_rxstateget = BREAK_GET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t rx_ring_buffer_get_lin_msg(lin_msg_struct * p_lin_msg)
|
||||||
|
{
|
||||||
|
return CircBuf_Pop(&lin_rx_circbuf,(uint8_t*)p_lin_msg, sizeof(lin_msg_struct));
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART5_IRQHandler(void)
|
||||||
|
{
|
||||||
|
uint8_t receive_data = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if(RESET != usart_interrupt_flag_get(USART5,USART_BFF_FLAG))
|
||||||
|
{
|
||||||
|
usart_data_receive(USART5);
|
||||||
|
|
||||||
|
lin_rxstateget = SYNCH_GET;
|
||||||
|
|
||||||
|
usart_flag_clear(USART5,USART_FERR_FLAG);//<2F><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE>lin<69>Ͽ<EFBFBD><CFBF><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>dz<EFBFBD><C7B3><EFBFBD>10λ<30><CEBB>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4>ڵ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
||||||
|
usart_flag_clear(USART5,USART_BFF_FLAG);
|
||||||
|
usart_flag_clear(USART5,USART_RDBF_FLAG);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(RESET != usart_interrupt_flag_get(USART5,USART_RDBF_FLAG))
|
||||||
|
{
|
||||||
|
receive_data = usart_data_receive(USART5);
|
||||||
|
if(RESET == usart_interrupt_flag_get(USART5,USART_FERR_FLAG))
|
||||||
|
{
|
||||||
|
if((receive_data == 0x55)&&(lin_rxstateget == BREAK_GET))
|
||||||
|
{
|
||||||
|
lin_rxstateget = SYNCH_GET;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
lin_master_rxmsg(receive_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
usart_flag_clear(USART5,USART_RDBF_FLAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
42
Bsp/bsp_lin.h
Normal file
42
Bsp/bsp_lin.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef _BSP_LIN_H
|
||||||
|
#define _BSP_LIN_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
#define Lin_Speed 19200
|
||||||
|
|
||||||
|
//LIN<49><4E><EFBFBD><EFBFBD>״̬
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
BREAK_GET = 0,
|
||||||
|
SYNCH_GET,
|
||||||
|
PID_GET,
|
||||||
|
MSG_GET,
|
||||||
|
CHECKSUM_GET,
|
||||||
|
}lin_rxstate_enum;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LIN_OK = 0,
|
||||||
|
FIFO_VOID, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
SYNC_ERR, //ͬ<><CDAC><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>
|
||||||
|
PID_ERR, //PID<49><44><EFBFBD><EFBFBD>
|
||||||
|
NO_RESPONES, //<2F><><EFBFBD><EFBFBD>Ӧ
|
||||||
|
CYHECK_ERR, //<2F><><EFBFBD>ݳ<EFBFBD><DDB3>ȴ<EFBFBD><C8B4><EFBFBD>
|
||||||
|
FORMAT_ERR, //У<><D0A3><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||||
|
}lin_error_enum;
|
||||||
|
|
||||||
|
#pragma pack (1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t sync; //ͬ<><CDAC><EFBFBD>Σ<EFBFBD><CEA3>̶<EFBFBD>ֵ0x55
|
||||||
|
uint8_t frameid; //֡ID
|
||||||
|
uint8_t pid; //PID
|
||||||
|
uint8_t datalen; //LIN<49><4E><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||||
|
uint8_t data[8]; //<2F><><EFBFBD>ݶΣ<DDB6>lin<69>涨<EFBFBD><E6B6A8><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD>ֽڣ<D6BD>
|
||||||
|
uint8_t checksum; //У<><D0A3><EFBFBD><EFBFBD>
|
||||||
|
}lin_msg_struct;
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
void lin_init(void);
|
||||||
|
uint8_t rx_ring_buffer_get_lin_msg(lin_msg_struct * p_lin_msg);
|
||||||
|
void USART3_IRQHandler(void);
|
||||||
|
#endif
|
||||||
14
Bsp/bsp_mos.c
Normal file
14
Bsp/bsp_mos.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include "bsp_mos.h"
|
||||||
|
#include "74hc595.h"
|
||||||
|
|
||||||
|
void mos_init(void)
|
||||||
|
{
|
||||||
|
ic_74hc595_init();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void mos_set(mos_union mos_data)
|
||||||
|
{
|
||||||
|
ic_74hc595_wirte_32bit(mos_data.mos);
|
||||||
|
}
|
||||||
|
|
||||||
45
Bsp/bsp_mos.h
Normal file
45
Bsp/bsp_mos.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef __BSP_MOS_H
|
||||||
|
#define __BSP_MOS_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
#define MOS(x) ((uint32_t)((uint32_t)0x01U<<(x)))
|
||||||
|
|
||||||
|
#define ALL_PRESSURIZE_MOS MOS(0)|MOS(1)|MOS(2)|MOS(3)|MOS(4)|MOS(5)|MOS(6)|MOS(7)|MOS(8)|MOS(9)
|
||||||
|
#define ALL_INLET_MOS MOS(10)|MOS(11)|MOS(12)|MOS(13)|MOS(14)|MOS(15)|MOS(16)|MOS(17)|MOS(18)|MOS(19)
|
||||||
|
#define ALL_MOS 0XFFFFFFFF
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
__IO uint32_t mos;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
__IO uint32_t mos0 : 1; /* [0] */
|
||||||
|
__IO uint32_t mos1 : 1; /* [1] */
|
||||||
|
__IO uint32_t mos2 : 1; /* [2] */
|
||||||
|
__IO uint32_t mos3 : 1; /* [3] */
|
||||||
|
__IO uint32_t mos4 : 1; /* [4] */
|
||||||
|
__IO uint32_t mos5 : 1; /* [5] */
|
||||||
|
__IO uint32_t mos6 : 1; /* [6] */
|
||||||
|
__IO uint32_t mos7 : 1; /* [7] */
|
||||||
|
__IO uint32_t mos8 : 1; /* [8] */
|
||||||
|
__IO uint32_t mos9 : 1; /* [9] */
|
||||||
|
__IO uint32_t mos10 : 1; /* [10] */
|
||||||
|
__IO uint32_t mos11 : 1; /* [11] */
|
||||||
|
__IO uint32_t mos12 : 1; /* [12] */
|
||||||
|
__IO uint32_t mos13 : 1; /* [13] */
|
||||||
|
__IO uint32_t mos14 : 1; /* [14] */
|
||||||
|
__IO uint32_t mos15 : 1; /* [15] */
|
||||||
|
__IO uint32_t mos16 : 1; /* [16] */
|
||||||
|
__IO uint32_t mos17 : 1; /* [17] */
|
||||||
|
__IO uint32_t mos18 : 1; /* [18] */
|
||||||
|
__IO uint32_t mos19 : 1; /* [19] */
|
||||||
|
__IO uint32_t mos20 : 1; /* [20] */
|
||||||
|
__IO uint32_t reserved1 : 11;/* [31:21] */
|
||||||
|
} mos_bit;
|
||||||
|
}mos_union;
|
||||||
|
|
||||||
|
void mos_init(void);
|
||||||
|
void mos_set(mos_union mos_data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
62
Bsp/bsp_moto.c
Normal file
62
Bsp/bsp_moto.c
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#include "bsp_moto.h"
|
||||||
|
|
||||||
|
|
||||||
|
void bsp_moto_init(uint16_t div, uint16_t period)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
tmr_output_config_type tmr_output_struct;
|
||||||
|
|
||||||
|
/* enable tmr1/gpioa/gpiob clock */
|
||||||
|
crm_periph_clock_enable(CRM_TMR4_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE6, GPIO_MUX_2);
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE7, GPIO_MUX_2);
|
||||||
|
|
||||||
|
|
||||||
|
tmr_reset(TMR4);
|
||||||
|
tmr_base_init(TMR4, period, div);
|
||||||
|
tmr_cnt_dir_set(TMR4, TMR_COUNT_UP);
|
||||||
|
|
||||||
|
tmr_output_default_para_init(&tmr_output_struct);
|
||||||
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
|
|
||||||
|
/* channel 1 */
|
||||||
|
tmr_output_channel_config(TMR4, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
||||||
|
tmr_output_channel_buffer_enable(TMR4, TMR_SELECT_CHANNEL_1, TRUE);
|
||||||
|
|
||||||
|
/* channel 2 */
|
||||||
|
tmr_output_channel_config(TMR4, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
||||||
|
tmr_output_channel_buffer_enable(TMR4, TMR_SELECT_CHANNEL_2, TRUE);
|
||||||
|
|
||||||
|
tmr_period_buffer_enable(TMR4, TRUE);
|
||||||
|
|
||||||
|
|
||||||
|
/* enable tmr1 */
|
||||||
|
tmr_counter_enable(TMR4, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void set_moto_out(uint8_t dir, uint32_t speed)
|
||||||
|
{
|
||||||
|
if( dir == 1 )
|
||||||
|
{
|
||||||
|
tmr_channel_value_set(TMR4, TMR_SELECT_CHANNEL_1, 0);
|
||||||
|
tmr_channel_value_set(TMR4, TMR_SELECT_CHANNEL_2, speed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmr_channel_value_set(TMR4, TMR_SELECT_CHANNEL_1, speed);
|
||||||
|
tmr_channel_value_set(TMR4, TMR_SELECT_CHANNEL_2, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Bsp/bsp_moto.h
Normal file
9
Bsp/bsp_moto.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef __BSP_MOTO_H
|
||||||
|
#define __BSP_MOTO_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
void bsp_moto_init(uint16_t div, uint16_t period);
|
||||||
|
void set_moto_out(uint8_t dir, uint32_t speed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
76
Bsp/bsp_mx_lin.c
Normal file
76
Bsp/bsp_mx_lin.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include "bsp_mx_lin.h"
|
||||||
|
#include "bsp_lin.h"
|
||||||
|
#include "bsp_airsac.h"
|
||||||
|
static lin_msg_struct g_lin_msg = {0};
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t lin_set_airsac_stop(lin_msg_struct * p_lin_msg)
|
||||||
|
{
|
||||||
|
airsac_stop();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t lin_set_airsac_discharge(lin_msg_struct * p_lin_msg)
|
||||||
|
{
|
||||||
|
if(p_lin_msg->datalen >= 2)
|
||||||
|
{
|
||||||
|
airsac_num airsac = (airsac_num)p_lin_msg->data[1];
|
||||||
|
airsac_discharge(airsac);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t lin_set_airsac_charge(lin_msg_struct * p_lin_msg)
|
||||||
|
{
|
||||||
|
if(p_lin_msg->datalen >= 2)
|
||||||
|
{
|
||||||
|
airsac_num airsac = (airsac_num)p_lin_msg->data[1];
|
||||||
|
airsac_charge(airsac);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t lin_set_all_airsac_discharge(lin_msg_struct * p_lin_msg)
|
||||||
|
{
|
||||||
|
all_airsac_discharge();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t lin_set_all_airsac_charge(lin_msg_struct * p_lin_msg)
|
||||||
|
{
|
||||||
|
all_airsac_charge();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mx_lin_handle(void)
|
||||||
|
{
|
||||||
|
lin_msg_struct * p_lin_msg = &g_lin_msg;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(rx_ring_buffer_get_lin_msg(p_lin_msg))
|
||||||
|
{
|
||||||
|
if(p_lin_msg->frameid == 0x03)
|
||||||
|
{
|
||||||
|
switch(p_lin_msg->data[0])
|
||||||
|
{
|
||||||
|
case 0x10: lin_set_airsac_stop(p_lin_msg);
|
||||||
|
break;
|
||||||
|
case 0x11: lin_set_airsac_discharge(p_lin_msg);
|
||||||
|
break;
|
||||||
|
case 0x12: lin_set_airsac_charge(p_lin_msg);
|
||||||
|
break;
|
||||||
|
case 0x13: lin_set_all_airsac_discharge(p_lin_msg);
|
||||||
|
break;
|
||||||
|
case 0x14: lin_set_all_airsac_charge(p_lin_msg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
10
Bsp/bsp_mx_lin.h
Normal file
10
Bsp/bsp_mx_lin.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __BSP_MX_LIN_H
|
||||||
|
#define __BSP_MX_LIN_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
void mx_lin_handle(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
56
Bsp/bsp_rs2251.c
Normal file
56
Bsp/bsp_rs2251.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "bsp_rs2251.h"
|
||||||
|
#include "bsp_adc.h"
|
||||||
|
|
||||||
|
void ref_gpio_init(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
/* enable the led clock */
|
||||||
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* set default parameter */
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the led gpio */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_3;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
gpio_bits_set(GPIOA, GPIO_PINS_3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RS2251_Init(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* set default parameter */
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
/* configure the led gpio */
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_3 | GPIO_PINS_4 | GPIO_PINS_5;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_bits_reset(GPIOB,GPIO_PINS_3);
|
||||||
|
gpio_bits_reset(GPIOB,GPIO_PINS_4);
|
||||||
|
gpio_bits_reset(GPIOB,GPIO_PINS_5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
功能:AY SCAN
|
||||||
|
输入:data 0 -> 7
|
||||||
|
*/
|
||||||
|
void Choose_AX_Channel(uint8_t data)
|
||||||
|
{
|
||||||
|
C_A( data & 0x01);
|
||||||
|
C_B((data & 0x02) >> 1);
|
||||||
|
C_C((data & 0x04) >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
30
Bsp/bsp_rs2251.h
Normal file
30
Bsp/bsp_rs2251.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef __BSP_RS2251_h
|
||||||
|
#define __BSP_RS2251_h
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define REF_OUT(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOA, GPIO_PINS_3);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOA, GPIO_PINS_3)
|
||||||
|
|
||||||
|
|
||||||
|
// Column_Selection
|
||||||
|
#define C_A(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_5);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_5)
|
||||||
|
#define C_B(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_4);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_4)
|
||||||
|
#define C_C(a) if (a) \
|
||||||
|
gpio_bits_set(GPIOB, GPIO_PINS_3);\
|
||||||
|
else \
|
||||||
|
gpio_bits_reset(GPIOB, GPIO_PINS_3)
|
||||||
|
|
||||||
|
|
||||||
|
void RS2251_Init(void);
|
||||||
|
void ref_gpio_init(void);
|
||||||
|
void Choose_AX_Channel(uint8_t data);
|
||||||
|
#endif
|
||||||
112
Bsp/bsp_spi.c
Normal file
112
Bsp/bsp_spi.c
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#include "bsp_spi.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void gpio_config(void)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_initstructure;
|
||||||
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||||
|
gpio_default_para_init(&gpio_initstructure);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* spi3 sck pin */
|
||||||
|
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||||
|
gpio_initstructure.gpio_pins = GPIO_PINS_4;
|
||||||
|
gpio_init(GPIOA, &gpio_initstructure);
|
||||||
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE4, GPIO_MUX_5);
|
||||||
|
|
||||||
|
|
||||||
|
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||||
|
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||||
|
gpio_init(GPIOA, &gpio_initstructure);
|
||||||
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_5);
|
||||||
|
|
||||||
|
/* spi3 miso pin */
|
||||||
|
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||||
|
gpio_initstructure.gpio_pins = GPIO_PINS_6;
|
||||||
|
gpio_init(GPIOA, &gpio_initstructure);
|
||||||
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE6, GPIO_MUX_5);
|
||||||
|
|
||||||
|
/* spi3 mosi pin */
|
||||||
|
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||||
|
gpio_initstructure.gpio_pins = GPIO_PINS_7;
|
||||||
|
gpio_init(GPIOA, &gpio_initstructure);
|
||||||
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE7, GPIO_MUX_5);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spi_config(void)
|
||||||
|
{
|
||||||
|
spi_init_type spi_init_struct;
|
||||||
|
/* master spi initialization */
|
||||||
|
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
|
||||||
|
spi_default_para_init(&spi_init_struct);
|
||||||
|
|
||||||
|
/* dual line unidirectional full-duplex mode */
|
||||||
|
spi_init_struct.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX;
|
||||||
|
spi_init_struct.master_slave_mode = SPI_MODE_SLAVE;
|
||||||
|
spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_64;
|
||||||
|
spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
|
||||||
|
spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
|
||||||
|
spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_LOW;
|
||||||
|
spi_init_struct.clock_phase = SPI_CLOCK_PHASE_1EDGE;
|
||||||
|
spi_init_struct.cs_mode_selection = SPI_CS_HARDWARE_MODE;
|
||||||
|
spi_init(SPI1, &spi_init_struct);
|
||||||
|
spi_i2s_dma_transmitter_enable(SPI1,TRUE);
|
||||||
|
spi_i2s_dma_receiver_enable(SPI1,TRUE);
|
||||||
|
spi_enable(SPI1, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dma_config(uint8_t *buffer, uint16_t buffer_size)
|
||||||
|
{
|
||||||
|
dma_init_type dma_init_struct;
|
||||||
|
crm_periph_clock_enable(CRM_DMA2_PERIPH_CLOCK, TRUE);
|
||||||
|
dmamux_enable(DMA2, TRUE);
|
||||||
|
|
||||||
|
dma_reset(DMA2_CHANNEL1);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = buffer_size;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_HIGH;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)buffer;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&(SPI1->dt);
|
||||||
|
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;
|
||||||
|
dma_init(DMA2_CHANNEL1, &dma_init_struct);
|
||||||
|
dmamux_init(DMA2MUX_CHANNEL1, DMAMUX_DMAREQ_ID_SPI1_TX);
|
||||||
|
dma_channel_enable(DMA2_CHANNEL1, TRUE);
|
||||||
|
|
||||||
|
dma_reset(DMA2_CHANNEL1);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = buffer_size;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_HIGH;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)buffer;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&(SPI1->dt);
|
||||||
|
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;
|
||||||
|
dma_init(DMA2_CHANNEL1, &dma_init_struct);
|
||||||
|
dmamux_init(DMA2MUX_CHANNEL1, DMAMUX_DMAREQ_ID_SPI1_TX);
|
||||||
|
dma_channel_enable(DMA2_CHANNEL1, TRUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void spi1_init(uint8_t *buffer, uint16_t buffer_size)
|
||||||
|
{
|
||||||
|
gpio_config();
|
||||||
|
dma_config(buffer, buffer_size);
|
||||||
|
spi_config();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
11
Bsp/bsp_spi.h
Normal file
11
Bsp/bsp_spi.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef _BSP_SPI_H
|
||||||
|
#define _BSP_SPI_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
#define SPI_SLAVE_CS_READ() gpio_input_data_bit_read(GPIOA, GPIO_PINS_4)
|
||||||
|
|
||||||
|
void spi1_init(uint8_t *buffer, uint16_t buffer_size);
|
||||||
|
uint8_t spi_tx_rx_buffer(uint8_t *tx_buffer, uint8_t *rx_buffer, uint16_t buffer_len);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
648
Bsp/bsp_uart.c
Normal file
648
Bsp/bsp_uart.c
Normal file
@@ -0,0 +1,648 @@
|
|||||||
|
#include "bsp_uart.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
#include "circular_buffer.h"
|
||||||
|
CircBuf_t USART1_RxC = {0};
|
||||||
|
CircBuf_t USART2_RxC = {0};
|
||||||
|
CircBuf_t USART3_RxC = {0};
|
||||||
|
CircBuf_t USART4_RxC = {0};
|
||||||
|
CircBuf_t USART5_RxC = {0};
|
||||||
|
|
||||||
|
CircBuf_t USART1_TxC = {0};
|
||||||
|
CircBuf_t USART2_TxC = {0};
|
||||||
|
CircBuf_t USART3_TxC = {0};
|
||||||
|
CircBuf_t USART4_TxC = {0};
|
||||||
|
CircBuf_t USART5_TxC = {0};
|
||||||
|
|
||||||
|
uint8_t usart1_RX_CBUFF[USART1_RX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart2_RX_CBUFF[USART2_RX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart3_RX_CBUFF[USART3_RX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart4_RX_CBUFF[USART4_RX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart5_RX_CBUFF[USART5_RX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
uint8_t usart1_TX_CBUFF[USART1_TX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart2_TX_CBUFF[USART2_TX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart3_TX_CBUFF[USART3_TX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart4_TX_CBUFF[USART4_TX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart5_TX_CBUFF[USART5_TX_BUF_LEN*2]; // ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t usart1_tx_buf[USART1_TX_BUF_LEN] = {0};//<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart1_rx_buf[USART1_RX_BUF_LEN] = {0};//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart3_tx_buf[USART3_TX_BUF_LEN] = {0};//<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart3_rx_buf[USART3_RX_BUF_LEN] = {0};//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart5_tx_buf[USART5_TX_BUF_LEN] = {0};//<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t usart5_rx_buf[USART5_RX_BUF_LEN] = {0};//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>1
|
||||||
|
void uart1_config(uint32_t band_rate)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
dma_init_type dma_init_struct;
|
||||||
|
|
||||||
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable( CRM_USART1_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = BSP_USART1_TX_PIN;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(USART1_GPIOx, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(USART1_GPIOx, GPIO_PINS_SOURCE9, GPIO_MUX_7);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = BSP_USART1_RX_PIN;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(USART1_GPIOx, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(USART1_GPIOx, GPIO_PINS_SOURCE10, GPIO_MUX_7);
|
||||||
|
|
||||||
|
usart_init(USART1, band_rate, USART_DATA_8BITS, USART_STOP_1_BIT);
|
||||||
|
usart_transmitter_enable(USART1, TRUE);
|
||||||
|
usart_receiver_enable(USART1, TRUE);
|
||||||
|
usart_enable(USART1, TRUE);
|
||||||
|
nvic_irq_enable(USART1_IRQn, 2, 0);
|
||||||
|
usart_interrupt_enable(USART1, USART_IDLE_INT, TRUE);
|
||||||
|
|
||||||
|
//TX_DMA_init
|
||||||
|
dma_reset(DMA1_CHANNEL1);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = ARRAYNUM(usart1_tx_buf);
|
||||||
|
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)&usart1_tx_buf;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&USART1->dt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init(DMA1_CHANNEL1, &dma_init_struct);
|
||||||
|
usart_dma_transmitter_enable(USART1, TRUE);
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL1, DMAMUX_DMAREQ_ID_USART1_TX);
|
||||||
|
|
||||||
|
//RX_DMA_init
|
||||||
|
dma_reset(DMA1_CHANNEL2);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = ARRAYNUM(usart1_rx_buf);
|
||||||
|
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)&usart1_rx_buf;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&USART1->dt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init(DMA1_CHANNEL2, &dma_init_struct);
|
||||||
|
usart_dma_receiver_enable(USART1, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL2,TRUE);
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL2, DMAMUX_DMAREQ_ID_USART1_RX);
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
uint16_t recv_num = 0;
|
||||||
|
uint16_t send_num = 0;
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
if((RESET != usart_interrupt_flag_get(USART1, USART_IDLEF_FLAG)) &&
|
||||||
|
(RESET != usart_flag_get(USART1, USART_IDLEF_FLAG)))
|
||||||
|
{
|
||||||
|
usart_flag_clear(USART1,USART_IDLEF_FLAG);
|
||||||
|
recv_num = sizeof(usart1_rx_buf) - dma_data_number_get(DMA1_CHANNEL2);
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
CircBuf_Push(&USART1_RxC, usart1_rx_buf, recv_num);
|
||||||
|
#endif
|
||||||
|
dma_channel_enable(DMA1_CHANNEL2, FALSE);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL2,sizeof(usart1_rx_buf));
|
||||||
|
dma_channel_enable(DMA1_CHANNEL2, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
if(RESET != usart_interrupt_flag_get(USART1,USART_TDC_FLAG))
|
||||||
|
{
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
send_num = CircBuf_Pop(&USART1_TxC,usart1_tx_buf,sizeof(usart1_tx_buf));
|
||||||
|
#endif
|
||||||
|
if(send_num)
|
||||||
|
{
|
||||||
|
dma_channel_enable(DMA1_CHANNEL1,FALSE);
|
||||||
|
dma_flag_clear(DMA1_FDT1_FLAG);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL1, send_num);
|
||||||
|
usart_dma_transmitter_enable(USART1, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL1,TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
usart_interrupt_enable(USART1, USART_TDC_INT, FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart1_dma_send_data(uint8_t *buffer,uint16_t len)
|
||||||
|
{
|
||||||
|
dma_channel_enable(DMA1_CHANNEL1,FALSE);
|
||||||
|
dma_flag_clear(DMA1_FDT1_FLAG);
|
||||||
|
memcpy(usart1_tx_buf,buffer,len);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL1, len);
|
||||||
|
usart_dma_transmitter_enable(USART1, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL1,TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart1_init(uint32_t band_rate)
|
||||||
|
{
|
||||||
|
uart1_config(band_rate);
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
CircBuf_Init(&USART1_RxC, usart1_RX_CBUFF, 1024);
|
||||||
|
CircBuf_Init(&USART1_TxC, usart1_TX_CBUFF, 1024);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>3
|
||||||
|
void uart3_config(uint32_t band_rate)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
dma_init_type dma_init_struct;
|
||||||
|
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable( CRM_USART3_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = BSP_USART3_TX_PIN;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(USART3_GPIOx, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(USART3_GPIOx, GPIO_PINS_SOURCE10, GPIO_MUX_7);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = BSP_USART3_RX_PIN;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(USART3_GPIOx, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(USART3_GPIOx, GPIO_PINS_SOURCE11, GPIO_MUX_7);
|
||||||
|
|
||||||
|
usart_init(USART3, band_rate, USART_DATA_8BITS, USART_STOP_1_BIT);
|
||||||
|
usart_transmitter_enable(USART3, TRUE);
|
||||||
|
usart_receiver_enable(USART3, TRUE);
|
||||||
|
usart_enable(USART3, TRUE);
|
||||||
|
nvic_irq_enable(USART3_IRQn, 2, 0);
|
||||||
|
usart_interrupt_enable(USART3, USART_IDLE_INT, TRUE);
|
||||||
|
|
||||||
|
//TX_DMA_init
|
||||||
|
dma_reset(DMA1_CHANNEL5);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = ARRAYNUM(usart3_tx_buf);
|
||||||
|
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)&usart3_tx_buf;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&USART3->dt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init(DMA1_CHANNEL5, &dma_init_struct);
|
||||||
|
usart_dma_transmitter_enable(USART3, TRUE);
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL5, DMAMUX_DMAREQ_ID_USART3_TX);
|
||||||
|
|
||||||
|
//RX_DMA_init
|
||||||
|
dma_reset(DMA1_CHANNEL6);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = ARRAYNUM(usart3_rx_buf);
|
||||||
|
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)&usart3_rx_buf;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&USART3->dt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init(DMA1_CHANNEL6, &dma_init_struct);
|
||||||
|
usart_dma_receiver_enable(USART3, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL6,TRUE);
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL6, DMAMUX_DMAREQ_ID_USART3_RX);
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART3_IRQHandler(void)
|
||||||
|
{
|
||||||
|
uint16_t recv_num = 0;
|
||||||
|
uint16_t send_num = 0;
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
if((RESET != usart_interrupt_flag_get(USART3, USART_IDLEF_FLAG)) &&
|
||||||
|
(RESET != usart_flag_get(USART3, USART_IDLEF_FLAG)))
|
||||||
|
{
|
||||||
|
usart_flag_clear(USART3,USART_IDLEF_FLAG);
|
||||||
|
recv_num = sizeof(usart3_rx_buf) - dma_data_number_get(DMA1_CHANNEL6);
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
CircBuf_Push(&USART3_RxC, usart3_rx_buf, recv_num);
|
||||||
|
#endif
|
||||||
|
dma_channel_enable(DMA1_CHANNEL6, FALSE);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL6,sizeof(usart3_rx_buf));
|
||||||
|
dma_channel_enable(DMA1_CHANNEL6, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
if(RESET != usart_interrupt_flag_get(USART3,USART_TDC_FLAG))
|
||||||
|
{
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
send_num = CircBuf_Pop(&USART3_TxC,usart3_tx_buf,sizeof(usart3_tx_buf));
|
||||||
|
#endif
|
||||||
|
if(send_num)
|
||||||
|
{
|
||||||
|
dma_channel_enable(DMA1_CHANNEL5,FALSE);
|
||||||
|
dma_flag_clear(DMA1_FDT5_FLAG);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL5, send_num);
|
||||||
|
usart_dma_transmitter_enable(USART3, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL5,TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
usart_interrupt_enable(USART3, USART_TDC_INT, FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart3_dma_send_data(uint8_t *buffer,uint16_t len)
|
||||||
|
{
|
||||||
|
dma_channel_enable(DMA1_CHANNEL5,FALSE);
|
||||||
|
dma_flag_clear(DMA1_FDT5_FLAG);
|
||||||
|
memcpy(usart3_tx_buf,buffer,len);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL5, len);
|
||||||
|
usart_dma_transmitter_enable(USART3, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL5,TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart3_init(uint32_t band_rate)
|
||||||
|
{
|
||||||
|
uart3_config(band_rate);
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
CircBuf_Init(&USART3_RxC, usart3_RX_CBUFF, 1024);
|
||||||
|
CircBuf_Init(&USART3_TxC, usart3_TX_CBUFF, 1024);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>5
|
||||||
|
void uart5_config(uint32_t band_rate)
|
||||||
|
{
|
||||||
|
gpio_init_type gpio_init_struct;
|
||||||
|
dma_init_type dma_init_struct;
|
||||||
|
|
||||||
|
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable( CRM_USART5_PERIPH_CLOCK, TRUE);
|
||||||
|
crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
gpio_default_para_init(&gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_3;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE3, GPIO_MUX_10);
|
||||||
|
|
||||||
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
gpio_init_struct.gpio_pins = GPIO_PINS_4;
|
||||||
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE4, GPIO_MUX_10);
|
||||||
|
|
||||||
|
usart_init(USART5, band_rate, USART_DATA_8BITS, USART_STOP_1_BIT);
|
||||||
|
usart_transmitter_enable(USART5, TRUE);
|
||||||
|
usart_receiver_enable(USART5, TRUE);
|
||||||
|
usart_enable(USART5, TRUE);
|
||||||
|
nvic_irq_enable(USART5_IRQn, 2, 0);
|
||||||
|
usart_interrupt_enable(USART5, USART_IDLE_INT, TRUE);
|
||||||
|
|
||||||
|
//TX_DMA_init
|
||||||
|
dma_reset(DMA1_CHANNEL1);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = ARRAYNUM(usart5_tx_buf);
|
||||||
|
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)&usart5_tx_buf;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&USART5->dt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init(DMA1_CHANNEL1, &dma_init_struct);
|
||||||
|
usart_dma_transmitter_enable(USART5, TRUE);
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL1, DMAMUX_DMAREQ_ID_USART5_TX);
|
||||||
|
|
||||||
|
//RX_DMA_init
|
||||||
|
dma_reset(DMA1_CHANNEL2);
|
||||||
|
dma_default_para_init(&dma_init_struct);
|
||||||
|
dma_init_struct.buffer_size = ARRAYNUM(usart5_rx_buf);
|
||||||
|
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
|
||||||
|
dma_init_struct.memory_base_addr = (uint32_t)&usart5_rx_buf;
|
||||||
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.memory_inc_enable = TRUE;
|
||||||
|
dma_init_struct.peripheral_base_addr = (uint32_t)&USART5->dt;
|
||||||
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
|
||||||
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||||
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
||||||
|
dma_init_struct.loop_mode_enable = FALSE;
|
||||||
|
dma_init(DMA1_CHANNEL2, &dma_init_struct);
|
||||||
|
usart_dma_receiver_enable(USART5, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL2,TRUE);
|
||||||
|
dmamux_enable(DMA1, TRUE);
|
||||||
|
dmamux_init(DMA1MUX_CHANNEL2, DMAMUX_DMAREQ_ID_USART5_RX);
|
||||||
|
}
|
||||||
|
|
||||||
|
//void USART5_IRQHandler(void)
|
||||||
|
//{
|
||||||
|
// uint16_t recv_num = 0;
|
||||||
|
// uint16_t send_num = 0;
|
||||||
|
//
|
||||||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
// if((RESET != usart_interrupt_flag_get(USART5, USART_IDLEF_FLAG)) &&
|
||||||
|
// (RESET != usart_flag_get(USART5, USART_IDLEF_FLAG)))
|
||||||
|
// {
|
||||||
|
// usart_flag_clear(USART5,USART_IDLEF_FLAG);
|
||||||
|
// recv_num = sizeof(usart5_rx_buf) - dma_data_number_get(DMA1_CHANNEL2);
|
||||||
|
// #if CIRCULAR_BUFFER_ENABLE
|
||||||
|
// CircBuf_Push(&USART5_RxC, usart5_rx_buf, recv_num);
|
||||||
|
// #endif
|
||||||
|
// dma_channel_enable(DMA1_CHANNEL2, FALSE);
|
||||||
|
// dma_data_number_set(DMA1_CHANNEL2,sizeof(usart5_rx_buf));
|
||||||
|
// dma_channel_enable(DMA1_CHANNEL2, TRUE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
// if(RESET != usart_interrupt_flag_get(USART5,USART_TDC_FLAG))
|
||||||
|
// {
|
||||||
|
// #if CIRCULAR_BUFFER_ENABLE
|
||||||
|
// send_num = CircBuf_Pop(&USART5_TxC,usart5_tx_buf,sizeof(usart5_tx_buf));
|
||||||
|
// #endif
|
||||||
|
// if(send_num)
|
||||||
|
// {
|
||||||
|
// dma_channel_enable(DMA1_CHANNEL1,FALSE);
|
||||||
|
// dma_flag_clear(DMA1_FDT1_FLAG);
|
||||||
|
// dma_data_number_set(DMA1_CHANNEL1, send_num);
|
||||||
|
// usart_dma_transmitter_enable(USART5, TRUE);
|
||||||
|
// dma_channel_enable(DMA1_CHANNEL1,TRUE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// usart_interrupt_enable(USART5, USART_TDC_INT, FALSE);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
void usart5_dma_send_data(uint8_t *buffer,uint16_t len)
|
||||||
|
{
|
||||||
|
dma_channel_enable(DMA1_CHANNEL1,FALSE);
|
||||||
|
dma_flag_clear(DMA1_FDT1_FLAG);
|
||||||
|
memcpy(usart5_tx_buf,buffer,len);
|
||||||
|
dma_data_number_set(DMA1_CHANNEL1, len);
|
||||||
|
usart_dma_transmitter_enable(USART5, TRUE);
|
||||||
|
dma_channel_enable(DMA1_CHANNEL1,TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart5_init(uint32_t band_rate)
|
||||||
|
{
|
||||||
|
uart5_config(band_rate);
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
CircBuf_Init(&USART5_RxC, usart5_RX_CBUFF, 1024);
|
||||||
|
CircBuf_Init(&USART5_TxC, usart5_TX_CBUFF, 1024);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
|
||||||
|
uint8_t usart_tx_push(USART_COM_ID_T com_id, uint8_t *data, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ret = 0;
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
ret = CircBuf_Push(&USART1_TxC, data, len);
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
usart_interrupt_enable(USART1,USART_TDC_INT,TRUE);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
case USART_2_TR:
|
||||||
|
ret = CircBuf_Push(&USART2_TxC, data, len);
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
usart_interrupt_enable(USART2,USART_TDC_INT,TRUE);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
case USART_3_TR:
|
||||||
|
ret = CircBuf_Push(&USART3_TxC, data, len);
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
usart_interrupt_enable(USART3,USART_TDC_INT,TRUE);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
case USART_4_TR:
|
||||||
|
ret = CircBuf_Push(&USART4_TxC, data, len);
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
usart_interrupt_enable(USART4,USART_TDC_INT,TRUE);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
case USART_5_TR:
|
||||||
|
ret = CircBuf_Push(&USART5_TxC, data, len);
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
usart_interrupt_enable(USART5,USART_TDC_INT,TRUE);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t usart_rx_recv(USART_COM_ID_T com_id, uint8_t *data, uint16_t len)
|
||||||
|
{
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
return CircBuf_Pop(&USART1_RxC, data, len);
|
||||||
|
case USART_2_TR:
|
||||||
|
return CircBuf_Pop(&USART2_RxC, data, len);
|
||||||
|
case USART_3_TR:
|
||||||
|
return CircBuf_Pop(&USART3_RxC, data, len);
|
||||||
|
case USART_4_TR:
|
||||||
|
return CircBuf_Pop(&USART4_RxC, data, len);
|
||||||
|
case USART_5_TR:
|
||||||
|
return CircBuf_Pop(&USART5_RxC, data, len);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @param[in]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
unsigned int usart_rx_read(USART_COM_ID_T com_id,
|
||||||
|
uint8_t *data,
|
||||||
|
uint16_t len)
|
||||||
|
{
|
||||||
|
if(data != NULL)
|
||||||
|
{
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
return CircBuf_Read(&USART1_RxC, data, len);
|
||||||
|
case USART_2_TR:
|
||||||
|
return CircBuf_Read(&USART2_RxC, data, len);
|
||||||
|
case USART_3_TR:
|
||||||
|
return CircBuf_Read(&USART3_RxC, data, len);
|
||||||
|
case USART_4_TR:
|
||||||
|
return CircBuf_Read(&USART4_RxC, data, len);
|
||||||
|
case USART_5_TR:
|
||||||
|
return CircBuf_Read(&USART5_RxC, data, len);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @param[in]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
unsigned char usart_rx_at(USART_COM_ID_T com_id, uint8_t offset)
|
||||||
|
{
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
return CircBuf_At(&USART1_RxC, offset);
|
||||||
|
case USART_2_TR:
|
||||||
|
return CircBuf_At(&USART2_RxC, offset);
|
||||||
|
case USART_3_TR:
|
||||||
|
return CircBuf_At(&USART3_RxC, offset);
|
||||||
|
case USART_4_TR:
|
||||||
|
return CircBuf_At(&USART4_RxC, offset);
|
||||||
|
case USART_5_TR:
|
||||||
|
return CircBuf_At(&USART5_RxC, offset);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @param[in]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void usart_rx_drop(USART_COM_ID_T com_id, uint8_t drop_lens)
|
||||||
|
{
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
CircBuf_Drop(&USART1_RxC, drop_lens);
|
||||||
|
case USART_2_TR:
|
||||||
|
CircBuf_Drop(&USART2_RxC, drop_lens);
|
||||||
|
case USART_3_TR:
|
||||||
|
CircBuf_Drop(&USART3_RxC, drop_lens);
|
||||||
|
case USART_4_TR:
|
||||||
|
CircBuf_Drop(&USART4_RxC, drop_lens);
|
||||||
|
case USART_5_TR:
|
||||||
|
CircBuf_Drop(&USART5_RxC, drop_lens);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int usart_rx_get_rx_data_count(USART_COM_ID_T com_id)
|
||||||
|
{
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
return CircBuf_GetUsedSize(&USART1_RxC);
|
||||||
|
case USART_2_TR:
|
||||||
|
return CircBuf_GetUsedSize(&USART2_RxC);
|
||||||
|
case USART_3_TR:
|
||||||
|
return CircBuf_GetUsedSize(&USART3_RxC);
|
||||||
|
case USART_4_TR:
|
||||||
|
return CircBuf_GetUsedSize(&USART4_RxC);
|
||||||
|
case USART_5_TR:
|
||||||
|
return CircBuf_GetUsedSize(&USART5_RxC);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int usart_rx_probe(USART_COM_ID_T com_id)
|
||||||
|
{
|
||||||
|
switch (com_id)
|
||||||
|
{
|
||||||
|
case USART_1_TR:
|
||||||
|
return CircBuf_IsEmpty(&USART1_RxC);
|
||||||
|
case USART_2_TR:
|
||||||
|
return CircBuf_IsEmpty(&USART2_RxC);
|
||||||
|
case USART_3_TR:
|
||||||
|
return CircBuf_IsEmpty(&USART3_RxC);
|
||||||
|
case USART_4_TR:
|
||||||
|
return CircBuf_IsEmpty(&USART4_RxC);
|
||||||
|
case USART_5_TR:
|
||||||
|
return CircBuf_IsEmpty(&USART5_RxC);
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int fputc(int ch, FILE *f)
|
||||||
|
{
|
||||||
|
while(usart_flag_get(USART3, USART_TDBE_FLAG) == RESET);
|
||||||
|
usart_data_transmit(USART3, (uint16_t)ch);
|
||||||
|
while(usart_flag_get(USART3, USART_TDC_FLAG) == RESET);
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
71
Bsp/bsp_uart.h
Normal file
71
Bsp/bsp_uart.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#ifndef __BSP_UART_H
|
||||||
|
#define __BSP_UART_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
#include "circular_buffer.h"
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>1
|
||||||
|
#define USART1_TX_BUF_LEN 2 //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART1_RX_BUF_LEN 2 //<2F><><EFBFBD>յĻ<D5B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART1_GPIOx GPIOA
|
||||||
|
#define BSP_USART1_TX_PIN GPIO_PINS_9 // <20><><EFBFBD><EFBFBD>0TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define BSP_USART1_RX_PIN GPIO_PINS_10 // <20><><EFBFBD><EFBFBD>0RX<52><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>2
|
||||||
|
#define USART2_TX_BUF_LEN 2 //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART2_RX_BUF_LEN 2 //<2F><><EFBFBD>յĻ<D5B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART2_GPIOx GPIOB
|
||||||
|
#define BSP_USART2_TX_PIN GPIO_PIN_10 // <20><><EFBFBD><EFBFBD>2TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define BSP_USART2_RX_PIN GPIO_PIN_5 // <20><><EFBFBD><EFBFBD>2RX<52><58><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>GPIOC--5<>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>3
|
||||||
|
#define USART3_TX_BUF_LEN 1024 //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART3_RX_BUF_LEN 1024 //<2F><><EFBFBD>յĻ<D5B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART3_GPIOx GPIOB
|
||||||
|
#define BSP_USART3_TX_PIN GPIO_PINS_10 // <20><><EFBFBD><EFBFBD>0TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define BSP_USART3_RX_PIN GPIO_PINS_11 // <20><><EFBFBD><EFBFBD>0RX<52><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>4
|
||||||
|
#define USART4_TX_BUF_LEN 2 //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART4_RX_BUF_LEN 2 //<2F><><EFBFBD>յĻ<D5B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART4_GPIOx GPIOC
|
||||||
|
#define BSP_UART4_TX_PIN GPIO_PIN_12 // <20><><EFBFBD><EFBFBD>0TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define BSP_UART4_RX_PIN GPIO_PIN_2 // <20><><EFBFBD><EFBFBD>0RX<52><58><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>GPIOD--2
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>5
|
||||||
|
#define USART5_TX_BUF_LEN 2 //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART5_RX_BUF_LEN 2 //<2F><><EFBFBD>յĻ<D5B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||||
|
#define USART5_GPIOx GPIOB
|
||||||
|
#define BSP_USART5_TX_PIN GPIO_PINS_3 // <20><><EFBFBD><EFBFBD>0TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
#define BSP_USART5_RX_PIN GPIO_PINS_4 // <20><><EFBFBD><EFBFBD>0RX<52><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
|
||||||
|
#define CIRCULAR_BUFFER_ENABLE 1 //<2F><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
#if CIRCULAR_BUFFER_ENABLE
|
||||||
|
typedef enum {
|
||||||
|
USART_0_TR,
|
||||||
|
USART_1_TR,
|
||||||
|
USART_2_TR,
|
||||||
|
USART_3_TR,
|
||||||
|
USART_4_TR,
|
||||||
|
USART_5_TR,
|
||||||
|
} USART_COM_ID_T;
|
||||||
|
uint8_t usart_tx_push(USART_COM_ID_T com_id, uint8_t *data, uint16_t len);
|
||||||
|
uint8_t usart_rx_recv(USART_COM_ID_T com_id, uint8_t *data, uint16_t len);
|
||||||
|
unsigned int usart_rx_read(USART_COM_ID_T com_id,uint8_t *data,uint16_t len);
|
||||||
|
unsigned char usart_rx_at(USART_COM_ID_T com_id, uint8_t offset);
|
||||||
|
void usart_rx_drop(USART_COM_ID_T com_id, uint8_t drop_lens);
|
||||||
|
int usart_rx_get_rx_data_count(USART_COM_ID_T com_id);
|
||||||
|
int usart_rx_probe(USART_COM_ID_T com_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define ARRAYNUM(arr_name) (uint32_t)(sizeof(arr_name) / sizeof(*(arr_name)))
|
||||||
|
|
||||||
|
void uart1_init(uint32_t band_rate);
|
||||||
|
void uart3_init(uint32_t band_rate);
|
||||||
|
void uart5_init(uint32_t band_rate);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
148
Bsp/cal_creep/lib_cal_creep_resistance.c
Normal file
148
Bsp/cal_creep/lib_cal_creep_resistance.c
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
#include "lib_cal_creep_resistance.h"
|
||||||
|
|
||||||
|
#define CREEP_VALUE 1
|
||||||
|
#define CREEP_INTERVAL_FRAME 5
|
||||||
|
|
||||||
|
uint8_t g_creep_value = 0;
|
||||||
|
uint8_t g_creep_interval_frame = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static cal_creep_resistance_t creep_strength_value;
|
||||||
|
|
||||||
|
cal_creep_resistance_t * svc_creep_strength_value_get(void)
|
||||||
|
{
|
||||||
|
return &creep_strength_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cal_creep_resistance_init(uint8_t creep_strength, uint8_t creep_level)
|
||||||
|
{
|
||||||
|
g_creep_value = creep_strength;
|
||||||
|
g_creep_interval_frame = creep_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cal_creep_resistance(cal_creep_resistance_t *cfg)
|
||||||
|
{
|
||||||
|
static uint64_t frame_count = 0;
|
||||||
|
uint16_t count = cfg->x_max * cfg->y_max;
|
||||||
|
int16_t matrix_deviation = 0;
|
||||||
|
frame_count ++;
|
||||||
|
|
||||||
|
do{
|
||||||
|
count--;
|
||||||
|
|
||||||
|
if (cfg->matrix_real[count] < 2)
|
||||||
|
{
|
||||||
|
cfg->matrix_display[count] = 0;
|
||||||
|
cfg->matrix_creep[count] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(frame_count % g_creep_interval_frame))
|
||||||
|
{
|
||||||
|
matrix_deviation = (cfg->matrix_real[count] > cfg->matrix_stab[count]) ?
|
||||||
|
(cfg->matrix_real[count] - cfg->matrix_stab[count]) : (cfg->matrix_stab[count] - cfg->matrix_real[count]);
|
||||||
|
|
||||||
|
if (matrix_deviation > g_creep_value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
matrix_deviation = (cfg->matrix_real[count] > cfg->matrix_stab[count]) ? matrix_deviation : -matrix_deviation;
|
||||||
|
cfg->matrix_creep[count] += matrix_deviation;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg->matrix_stab[count] = cfg->matrix_real[count];
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg->matrix_display[count] = (cfg->matrix_real[count] > cfg->matrix_creep[count]) ?
|
||||||
|
(cfg->matrix_real[count] - cfg->matrix_creep[count]) : cfg->matrix_real[count];
|
||||||
|
|
||||||
|
if (cfg->matrix_real[count] < cfg->matrix_creep[count])
|
||||||
|
{
|
||||||
|
cfg->matrix_creep[count] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while(count);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* <20>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ԭ cal_creep_resistance_t <20><><EFBFBD><EFBFBD> */
|
||||||
|
void cal_creep_resistance_4tile(const cal_creep_resistance_t *cfg)
|
||||||
|
{
|
||||||
|
/* ԭ<><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||||
|
uint8_t x_max = cfg->x_max; /* 62 */
|
||||||
|
uint8_t y_max = cfg->y_max; /* 68 */
|
||||||
|
uint8_t *real = cfg->matrix_real;
|
||||||
|
uint8_t *stab = cfg->matrix_stab;
|
||||||
|
uint8_t *creep = cfg->matrix_creep;
|
||||||
|
uint8_t *disp = cfg->matrix_display;
|
||||||
|
|
||||||
|
/* <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ鹲<C4BF><E9B9B2>ͬһ֡<D2BB>ţ<EFBFBD><C5A3>̰߳<DFB3>ȫֻ<C8AB><D6BB><EFBFBD><EFBFBD> */
|
||||||
|
static uint64_t frame_count = 0;
|
||||||
|
#pragma omp atomic update
|
||||||
|
frame_count++; /* ԭ<><D4AD>+1<><31><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9>̬ */
|
||||||
|
|
||||||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD> */
|
||||||
|
uint8_t w2 = x_max / 2; /* 31 */
|
||||||
|
uint8_t h2 = y_max / 2; /* 34 */
|
||||||
|
|
||||||
|
#pragma omp parallel for collapse(2) schedule(static) if(1)
|
||||||
|
for (int by = 0; by < 2; ++by)
|
||||||
|
{
|
||||||
|
for (int bx = 0; bx < 2; ++bx)
|
||||||
|
{
|
||||||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||||
|
uint8_t x0 = bx * w2;
|
||||||
|
uint8_t y0 = by * h2;
|
||||||
|
uint8_t x1 = (bx == 1) ? x_max : x0 + w2;
|
||||||
|
uint8_t y1 = (by == 1) ? y_max : y0 + h2;
|
||||||
|
uint8_t bw = x1 - x0;
|
||||||
|
uint8_t bh = y1 - y0;
|
||||||
|
|
||||||
|
/* <20><>ָ<EFBFBD>루<EFBFBD><EBA3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||||
|
uint8_t *b_real = real + y0 * x_max + x0;
|
||||||
|
uint8_t *b_stab = stab + y0 * x_max + x0;
|
||||||
|
uint8_t *b_creep = creep + y0 * x_max + x0;
|
||||||
|
uint8_t *b_disp = disp + y0 * x_max + x0;
|
||||||
|
|
||||||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>㷨 */
|
||||||
|
for (uint8_t yy = 0; yy < bh; ++yy)
|
||||||
|
{
|
||||||
|
for (uint8_t xx = 0; xx < bw; ++xx)
|
||||||
|
{
|
||||||
|
uint16_t idx = yy * x_max + xx; /* ȫ<>ֿ<EFBFBD><D6BF><EFBFBD> */
|
||||||
|
|
||||||
|
uint8_t r = b_real[idx];
|
||||||
|
if (r < 2)
|
||||||
|
{
|
||||||
|
b_disp[idx] = 0;
|
||||||
|
b_creep[idx] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* UPDATE <20>Σ<D7B6>ֻ<EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>֡<EFBFBD><D6A1> */
|
||||||
|
if ((frame_count % g_creep_interval_frame) == 0)
|
||||||
|
{
|
||||||
|
int16_t s = b_stab[idx];
|
||||||
|
int16_t dev = (r > s) ? (r - s) : (s - r);
|
||||||
|
if (dev <= g_creep_value)
|
||||||
|
{
|
||||||
|
int16_t c = b_creep[idx];
|
||||||
|
c += (r > s) ? dev : -dev;
|
||||||
|
b_creep[idx] = (uint8_t)(c < 0 ? 0 : c);
|
||||||
|
}
|
||||||
|
b_stab[idx] = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DISPLAY <20><EFBFBD> */
|
||||||
|
uint8_t c = b_creep[idx];
|
||||||
|
b_disp[idx] = (r > c) ? r - c : 0;
|
||||||
|
if (r < c) b_creep[idx] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
25
Bsp/cal_creep/lib_cal_creep_resistance.h
Normal file
25
Bsp/cal_creep/lib_cal_creep_resistance.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef __LIB_CAL_CREEP_RESISTANCE_H
|
||||||
|
#define __LIB_CAL_CREEP_RESISTANCE_H
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t x_max; //原始阵列横轴点位数量
|
||||||
|
uint8_t y_max; //原始阵列纵轴点位数量
|
||||||
|
|
||||||
|
uint8_t *matrix_real; //原始输入阵列
|
||||||
|
uint8_t *matrix_stab; //算法缓冲区,需要预留与原始阵列一样大的空间
|
||||||
|
uint8_t *matrix_creep; //算法缓冲区,需要预留与原始阵列一样大的空间
|
||||||
|
|
||||||
|
uint8_t *matrix_display; //输出阵列,输出消除蠕变后的阵列
|
||||||
|
|
||||||
|
} cal_creep_resistance_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cal_creep_resistance_init(uint8_t creep_strength, uint8_t creep_level);
|
||||||
|
cal_creep_resistance_t * svc_creep_strength_value_get(void);
|
||||||
|
void cal_creep_resistance(cal_creep_resistance_t *cfg);
|
||||||
|
|
||||||
|
void cal_creep_resistance_4tile(const cal_creep_resistance_t *cfg);
|
||||||
|
|
||||||
|
#endif
|
||||||
54
Bsp/get_json.c
Normal file
54
Bsp/get_json.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "get_json.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "bsp_uart.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
uint8_t uart_rx_buffer[1024];
|
||||||
|
json_data_struct json_data;
|
||||||
|
|
||||||
|
int get_Json_data(void)
|
||||||
|
{
|
||||||
|
int result = -1;
|
||||||
|
uint16_t uart_get_num = usart_rx_get_rx_data_count(USART_3_TR);
|
||||||
|
uint16_t arry_size = 0;
|
||||||
|
|
||||||
|
if(uart_get_num > 0)
|
||||||
|
{
|
||||||
|
usart_rx_recv(USART_3_TR, uart_rx_buffer, uart_get_num);
|
||||||
|
cJSON *cjson = NULL,*params = NULL,*params_math = NULL;
|
||||||
|
cjson = cJSON_Parse((const char*)uart_rx_buffer);
|
||||||
|
|
||||||
|
memset(uart_rx_buffer,0x00,sizeof(uart_rx_buffer));
|
||||||
|
if(cjson != NULL)
|
||||||
|
{
|
||||||
|
params = cJSON_GetObjectItem(cjson,"params");
|
||||||
|
params_math = cJSON_GetObjectItem(params,"math");
|
||||||
|
arry_size = cJSON_GetArraySize(params_math);
|
||||||
|
if(arry_size >= 2)
|
||||||
|
{
|
||||||
|
json_data.min_trigger_res_value = cJSON_GetArrayItem(params_math, 0)->valueint;
|
||||||
|
json_data.max_trigger_res_value = cJSON_GetArrayItem(params_math, 1)->valueint;
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cJSON_Delete(cjson);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t get_json_min_trigger_res_value(void)
|
||||||
|
{
|
||||||
|
return json_data.min_trigger_res_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t get_json_max_trigger_res_value(void)
|
||||||
|
{
|
||||||
|
return json_data.max_trigger_res_value;
|
||||||
|
}
|
||||||
|
|
||||||
15
Bsp/get_json.h
Normal file
15
Bsp/get_json.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef _GET_JSON_H
|
||||||
|
#define _GET_JSON_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t min_trigger_res_value;
|
||||||
|
uint16_t max_trigger_res_value;
|
||||||
|
}json_data_struct;
|
||||||
|
|
||||||
|
int get_Json_data(void);
|
||||||
|
uint16_t get_json_min_trigger_res_value(void);
|
||||||
|
uint16_t get_json_max_trigger_res_value(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
92
Bsp/scan.c
Normal file
92
Bsp/scan.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#include "scan.h"
|
||||||
|
#include "bsp_rs2251.h"
|
||||||
|
#include "bsp_74hc595.h"
|
||||||
|
#include "bsp_adc.h"
|
||||||
|
#include "resi_math_lib.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#define ADC_DELAY_TIME (10 * 220) //9 ns * 120
|
||||||
|
|
||||||
|
|
||||||
|
void Hc4051Delay(uint32_t num)
|
||||||
|
{
|
||||||
|
while(num --);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
<20><><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
<20><><EFBFBD>룺<EFBFBD><EBA3BA>
|
||||||
|
<20><><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>32*64<36><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
void ReadAdcValue(adc_value_frame_struct *adc_raw_value,RESISTACE_NAME resistace_name)
|
||||||
|
{
|
||||||
|
uint8_t AX_rank[] = {6,4,2,1,0,3,5,7};
|
||||||
|
//uint8_t AX_rank[] = {7,5,3,0,1,2,4,6};
|
||||||
|
|
||||||
|
if(resistace_name == RAW_RESISTACE)
|
||||||
|
{
|
||||||
|
for(uint8_t ax = 0; ax < 8; ++ax)
|
||||||
|
{
|
||||||
|
Choose_AX_Channel(AX_rank[ax]);
|
||||||
|
Hc4051Delay(ADC_DELAY_TIME);
|
||||||
|
|
||||||
|
adc_raw_value->sensorB_raw_value[ax] = GetAdcValue(1);
|
||||||
|
if(ax < 4)
|
||||||
|
{
|
||||||
|
adc_raw_value->sensorB_raw_value[ax + 8] = GetAdcValue(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(uint8_t ax = 0; ax < 8; ++ax)
|
||||||
|
{
|
||||||
|
Choose_AX_Channel(AX_rank[ax]);
|
||||||
|
Hc4051Delay(ADC_DELAY_TIME);
|
||||||
|
|
||||||
|
adc_raw_value->sensorB_ref_value[ax] = GetAdcValue(1);
|
||||||
|
|
||||||
|
if(ax < 4)
|
||||||
|
adc_raw_value->sensorB_ref_value[ax + 8] = GetAdcValue(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void scan_y(adc_value_frame_struct *adc_raw_value,uint8_t count_y)
|
||||||
|
{
|
||||||
|
static uint8_t AY_rank[] = {7,6,5,4,3,2,1,0,15,14,13,12};//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>õ<EFBFBD>
|
||||||
|
static math_resi_cal_t math_resi_cal = {0};
|
||||||
|
|
||||||
|
REF_OUT(1);//<2F><>ɨ
|
||||||
|
ic_74hc595_clean_0(16);
|
||||||
|
ReadAdcValue(adc_raw_value, REFER_RESISTACE);
|
||||||
|
|
||||||
|
REF_OUT(0);
|
||||||
|
ic_74hc595_io_write_1(AY_rank[count_y]);
|
||||||
|
ReadAdcValue(adc_raw_value, RAW_RESISTACE);
|
||||||
|
|
||||||
|
math_resi_cal.sensor_adc_value = adc_raw_value->sensorB_raw_value;
|
||||||
|
math_resi_cal.resi_adc_value = adc_raw_value->sensorB_ref_value;
|
||||||
|
math_resi_cal.math_number = AX_NUM;
|
||||||
|
|
||||||
|
|
||||||
|
math_resi_cali_once(&math_resi_cal,
|
||||||
|
adc_raw_value->sensorB_resi_output,
|
||||||
|
AX_NUM,
|
||||||
|
SCAN_LOW_LEVEL);
|
||||||
|
|
||||||
|
math_display_resi(adc_raw_value->sensorB_resi_output,
|
||||||
|
adc_raw_value->sensorB_display_output,
|
||||||
|
AX_NUM,
|
||||||
|
RESI_BACKWARDS);
|
||||||
|
|
||||||
|
memcpy(adc_raw_value->sensorB_voltage[count_y],adc_raw_value->sensorB_display_output,AX_NUM);
|
||||||
|
}
|
||||||
|
|
||||||
32
Bsp/scan.h
Normal file
32
Bsp/scan.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef __SCAN_H
|
||||||
|
#define __SCAN_H
|
||||||
|
#include "at32a423.h"
|
||||||
|
#include "main.h"
|
||||||
|
/*32x64 Data_Array*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t sensorB_raw_value[AX_NUM];
|
||||||
|
uint16_t sensorB_ref_value[AX_NUM];
|
||||||
|
uint16_t sensorB_resi_output[AX_NUM];
|
||||||
|
uint8_t sensorB_display_output[AX_NUM];
|
||||||
|
uint8_t sensorB_voltage[AX_NUM][AY_NUM];
|
||||||
|
}adc_value_frame_struct;
|
||||||
|
|
||||||
|
typedef enum SENSOR_NAME
|
||||||
|
{
|
||||||
|
SENSOR_A,
|
||||||
|
SENSOR_B
|
||||||
|
} SENSOR_NAME_T;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
REFER_RESISTACE,
|
||||||
|
RAW_RESISTACE
|
||||||
|
}RESISTACE_NAME;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void scan_y(adc_value_frame_struct *adc_raw_value,uint8_t count_y);
|
||||||
|
void align_init(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
126
Common/at32a423_clock.c
Normal file
126
Common/at32a423_clock.c
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************
|
||||||
|
* @file at32a423_clock.c
|
||||||
|
* @brief system clock config program
|
||||||
|
**************************************************************************
|
||||||
|
* Copyright notice & Disclaimer
|
||||||
|
*
|
||||||
|
* The software Board Support Package (BSP) that is made available to
|
||||||
|
* download from Artery official website is the copyrighted work of Artery.
|
||||||
|
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||||
|
* software and its related documentation for the purpose of design and
|
||||||
|
* development in conjunction with Artery microcontrollers. Use of the
|
||||||
|
* software is governed by this copyright notice and the following disclaimer.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||||
|
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||||
|
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||||
|
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||||
|
*
|
||||||
|
**************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* includes ------------------------------------------------------------------*/
|
||||||
|
#include "at32a423_clock.h"
|
||||||
|
|
||||||
|
/** @addtogroup AT32A423_periph_template
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup 423_System_clock_configuration System_clock_configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief system clock config program
|
||||||
|
* @note the system clock is configured as follow:
|
||||||
|
* system clock (sclk) = (hext * pll_ns)/(pll_ms * pll_fr) / 2
|
||||||
|
* system clock source = HEXT_VALUE
|
||||||
|
* - lick = on
|
||||||
|
* - lext = off
|
||||||
|
* - hick = on
|
||||||
|
* - hext = off
|
||||||
|
* - hext = HEXT_VALUE
|
||||||
|
* - sclk = 64000000
|
||||||
|
* - ahbdiv = 1
|
||||||
|
* - ahbclk = 64000000
|
||||||
|
* - apb1div = 2
|
||||||
|
* - apb1clk = 32000000
|
||||||
|
* - apb2div = 1
|
||||||
|
* - apb2clk = 64000000
|
||||||
|
* - pll_ns = 64
|
||||||
|
* - pll_ms = 1
|
||||||
|
* - pll_fr = 4
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
void system_clock_config(void)
|
||||||
|
{
|
||||||
|
/* reset crm */
|
||||||
|
crm_reset();
|
||||||
|
|
||||||
|
/* config flash psr register */
|
||||||
|
flash_psr_set(FLASH_WAIT_CYCLE_3);
|
||||||
|
|
||||||
|
/* enable pwc periph clock */
|
||||||
|
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
|
/* config ldo voltage */
|
||||||
|
pwc_ldo_output_voltage_set(PWC_LDO_OUTPUT_1V2);
|
||||||
|
|
||||||
|
/* enable hext */
|
||||||
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
|
||||||
|
|
||||||
|
/* wait till hext is ready */
|
||||||
|
while(crm_hext_stable_wait() == ERROR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* config pll clock resource
|
||||||
|
common frequency config list: pll source selected hick or hext(8mhz)
|
||||||
|
_____________________________________________________________________________
|
||||||
|
| | | | | | | | |
|
||||||
|
| sysclk | 150 | 144 | 120 | 108 | 96 | 72 | 36 |
|
||||||
|
|________|_________|_________|_________|_________|_________|_________________|
|
||||||
|
| | | | | | | | |
|
||||||
|
|pll_ns | 75 | 72 | 120 | 108 | 96 | 72 | 72 |
|
||||||
|
| | | | | | | | |
|
||||||
|
|pll_ms | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
|
||||||
|
| | | | | | | | |
|
||||||
|
|pll_fr | FR_2 | FR_2 | FR_4 | FR_4 | FR_4 | FR_4 | FR_8 |
|
||||||
|
|________|_________|_________|_________|_________|_________|________|________|
|
||||||
|
|
||||||
|
if pll clock source selects hext with other frequency values, or configure pll to other
|
||||||
|
frequency values, please use the at32 new clock configuration tool for configuration. */
|
||||||
|
crm_pll_config(CRM_PLL_SOURCE_HEXT, 75, 1, CRM_PLL_FR_2);
|
||||||
|
|
||||||
|
/* enable pll */
|
||||||
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
||||||
|
|
||||||
|
/* wait till pll is ready */
|
||||||
|
while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* config ahbclk */
|
||||||
|
crm_ahb_div_set(CRM_AHB_DIV_1);
|
||||||
|
|
||||||
|
/* config apb2clk, the maximum frequency of APB2 clock is 150 MHz */
|
||||||
|
crm_apb2_div_set(CRM_APB2_DIV_1);
|
||||||
|
|
||||||
|
/* config apb1clk, the maximum frequency of APB1 clock is 120 MHz */
|
||||||
|
crm_apb1_div_set(CRM_APB1_DIV_1);
|
||||||
|
|
||||||
|
/* select pll as system clock source */
|
||||||
|
crm_sysclk_switch(CRM_SCLK_PLL);
|
||||||
|
|
||||||
|
/* wait till pll is used as system clock source */
|
||||||
|
while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* update system_core_clock global variable */
|
||||||
|
system_core_clock_update();
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user