第一次提交
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user