This commit is contained in:
bmy
2024-05-19 16:04:33 +08:00
parent f15fcd4b10
commit f9a87063d8
5 changed files with 440 additions and 287 deletions

142
app/by_servo.c Normal file
View File

@@ -0,0 +1,142 @@
#include "by_servo.h"
#include "at32f415.h"
#include "lwprintf.h"
/**
* @brief 设置云台摇臂
*
* @param angle 角度 (0-180)
*/
void by_servo_set_claw_arm(int16_t angle)
{
#define PULSE_WIDTH_MIN 0.5f
#define PULSE_WIDTH_MAX 2.5f
uint32_t ch_val = 0;
if (angle < 0) {
angle = 0;
} else if (angle > 180) {
angle = 180;
}
ch_val = (uint32_t)(((float)angle / 180.0f * (PULSE_WIDTH_MAX - PULSE_WIDTH_MIN) + PULSE_WIDTH_MIN) / 20.0f * 9999.0f);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, ch_val);
#undef PULSE_WIDTH_MIN
#undef PULSE_WIDTH_MAX
}
/**
* @brief 设置云台摇臂
*
* @param angle 角度 (0-180)
*/
void by_servo_set_claw(int16_t angle)
{
#define PULSE_WIDTH_MIN 1.5f
#define PULSE_WIDTH_MAX 2.5f
uint32_t ch_val = 0;
if (angle < 0) {
angle = 0;
} else if (angle > 180) {
angle = 180;
}
ch_val = (uint32_t)(((float)angle / 180.0f * (PULSE_WIDTH_MAX - PULSE_WIDTH_MIN) + PULSE_WIDTH_MIN) / 20.0f * 9999.0f);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, ch_val);
#undef PULSE_WIDTH_MIN
#undef PULSE_WIDTH_MAX
}
/**
* @brief 设置云台摇臂
*
* @param angle 角度 (0-180)
*/
void by_servo_set_camera(int16_t angle)
{
#define PULSE_WIDTH_MIN 1.5f
#define PULSE_WIDTH_MAX 2.5f
uint32_t ch_val = 0;
if (angle < 0) {
angle = 0;
} else if (angle > 180) {
angle = 180;
}
ch_val = (uint32_t)(((float)angle / 180.0f * (PULSE_WIDTH_MAX - PULSE_WIDTH_MIN) + PULSE_WIDTH_MIN) / 20.0f * 9999.0f);
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_4, ch_val);
#undef PULSE_WIDTH_MIN
#undef PULSE_WIDTH_MAX
}
/**
* @brief 设置云台摇臂
*
* @param angle 角度 (0-180)
*/
void by_servo_set_scoop(int16_t angle)
{
#define PULSE_WIDTH_MIN 1.5f
#define PULSE_WIDTH_MAX 2.5f
uint32_t ch_val = 0;
if (angle < 0) {
angle = 0;
} else if (angle > 180) {
angle = 180;
}
ch_val = (uint32_t)(((float)angle / 180.0f * (PULSE_WIDTH_MAX - PULSE_WIDTH_MIN) + PULSE_WIDTH_MIN) / 20.0f * 9999.0f);
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_3, ch_val);
#undef PULSE_WIDTH_MIN
#undef PULSE_WIDTH_MAX
}
void by_servo_init(void)
{
// 后续要不全初始化为空值,由主控按顺序初始化
by_servo_set_claw_arm(0);
by_servo_set_claw(0);
by_servo_set_camera(0);
by_servo_set_scoop(0);
}
void by_servo_can_handle(uint16_t stdd_id, const uint8_t *data, uint8_t len)
{
int16_t angle = 0;
angle = (int16_t)(data[0] | (data[1] << 8));
switch (stdd_id) {
case 0x009:
by_servo_set_claw_arm(angle);
break;
case 0x00A:
by_servo_set_claw(angle);
break;
case 0x00B:
by_servo_set_camera(angle);
break;
case 0x00C:
by_servo_set_scoop(angle);
break;
default:
break;
}
}

13
app/by_servo.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _BY_SERVO_H__
#define _BY_SERVO_H__
#include "at32f415.h"
extern void by_servo_set_claw_arm(int16_t angle);
extern void by_servo_set_claw(int16_t angle);
extern void by_servo_set_camera(int16_t angle);
extern void by_servo_set_scoop(int16_t angle);
extern void by_servo_init(void);
extern void by_servo_can_handle(uint16_t stdd_id, const uint8_t *data, uint8_t len);
#endif

View File

@@ -1,27 +1,27 @@
/* add user code begin Header */ /* add user code begin Header */
/** /**
************************************************************************** **************************************************************************
* @file at32f415_int.c * @file at32f415_int.c
* @brief main interrupt service routines. * @brief main interrupt service routines.
************************************************************************** **************************************************************************
* Copyright notice & Disclaimer * Copyright notice & Disclaimer
* *
* The software Board Support Package (BSP) that is made available to * The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery. * download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP * Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and * software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the * development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer. * software is governed by this copyright notice and the following disclaimer.
* *
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
* *
************************************************************************** **************************************************************************
*/ */
/* add user code end Header */ /* add user code end Header */
/* includes ------------------------------------------------------------------*/ /* includes ------------------------------------------------------------------*/
@@ -29,7 +29,7 @@
/* private includes ----------------------------------------------------------*/ /* private includes ----------------------------------------------------------*/
/* add user code begin private includes */ /* add user code begin private includes */
#include "by_servo.h"
/* add user code end private includes */ /* add user code end private includes */
/* private typedef -----------------------------------------------------------*/ /* private typedef -----------------------------------------------------------*/
@@ -68,10 +68,10 @@
/* add user code end external variables */ /* add user code end external variables */
/** /**
* @brief this function handles nmi exception. * @brief this function handles nmi exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void NMI_Handler(void) void NMI_Handler(void)
{ {
/* add user code begin NonMaskableInt_IRQ 0 */ /* add user code begin NonMaskableInt_IRQ 0 */
@@ -84,18 +84,17 @@ void NMI_Handler(void)
} }
/** /**
* @brief this function handles hard fault exception. * @brief this function handles hard fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
/* add user code begin HardFault_IRQ 0 */ /* add user code begin HardFault_IRQ 0 */
/* add user code end HardFault_IRQ 0 */ /* add user code end HardFault_IRQ 0 */
/* go to infinite loop when hard fault exception occurs */ /* go to infinite loop when hard fault exception occurs */
while (1) while (1) {
{
/* add user code begin W1_HardFault_IRQ 0 */ /* add user code begin W1_HardFault_IRQ 0 */
/* add user code end W1_HardFault_IRQ 0 */ /* add user code end W1_HardFault_IRQ 0 */
@@ -103,18 +102,17 @@ void HardFault_Handler(void)
} }
/** /**
* @brief this function handles memory manage exception. * @brief this function handles memory manage exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void MemManage_Handler(void) void MemManage_Handler(void)
{ {
/* add user code begin MemoryManagement_IRQ 0 */ /* add user code begin MemoryManagement_IRQ 0 */
/* add user code end MemoryManagement_IRQ 0 */ /* add user code end MemoryManagement_IRQ 0 */
/* go to infinite loop when memory manage exception occurs */ /* go to infinite loop when memory manage exception occurs */
while (1) while (1) {
{
/* add user code begin W1_MemoryManagement_IRQ 0 */ /* add user code begin W1_MemoryManagement_IRQ 0 */
/* add user code end W1_MemoryManagement_IRQ 0 */ /* add user code end W1_MemoryManagement_IRQ 0 */
@@ -122,18 +120,17 @@ void MemManage_Handler(void)
} }
/** /**
* @brief this function handles bus fault exception. * @brief this function handles bus fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void BusFault_Handler(void) void BusFault_Handler(void)
{ {
/* add user code begin BusFault_IRQ 0 */ /* add user code begin BusFault_IRQ 0 */
/* add user code end BusFault_IRQ 0 */ /* add user code end BusFault_IRQ 0 */
/* go to infinite loop when bus fault exception occurs */ /* go to infinite loop when bus fault exception occurs */
while (1) while (1) {
{
/* add user code begin W1_BusFault_IRQ 0 */ /* add user code begin W1_BusFault_IRQ 0 */
/* add user code end W1_BusFault_IRQ 0 */ /* add user code end W1_BusFault_IRQ 0 */
@@ -141,18 +138,17 @@ void BusFault_Handler(void)
} }
/** /**
* @brief this function handles usage fault exception. * @brief this function handles usage fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void UsageFault_Handler(void) void UsageFault_Handler(void)
{ {
/* add user code begin UsageFault_IRQ 0 */ /* add user code begin UsageFault_IRQ 0 */
/* add user code end UsageFault_IRQ 0 */ /* add user code end UsageFault_IRQ 0 */
/* go to infinite loop when usage fault exception occurs */ /* go to infinite loop when usage fault exception occurs */
while (1) while (1) {
{
/* add user code begin W1_UsageFault_IRQ 0 */ /* add user code begin W1_UsageFault_IRQ 0 */
/* add user code end W1_UsageFault_IRQ 0 */ /* add user code end W1_UsageFault_IRQ 0 */
@@ -160,10 +156,10 @@ void UsageFault_Handler(void)
} }
/** /**
* @brief this function handles svcall exception. * @brief this function handles svcall exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void SVC_Handler(void) void SVC_Handler(void)
{ {
/* add user code begin SVCall_IRQ 0 */ /* add user code begin SVCall_IRQ 0 */
@@ -175,10 +171,10 @@ void SVC_Handler(void)
} }
/** /**
* @brief this function handles debug monitor exception. * @brief this function handles debug monitor exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void DebugMon_Handler(void) void DebugMon_Handler(void)
{ {
/* add user code begin DebugMonitor_IRQ 0 */ /* add user code begin DebugMonitor_IRQ 0 */
@@ -190,10 +186,10 @@ void DebugMon_Handler(void)
} }
/** /**
* @brief this function handles pendsv_handler exception. * @brief this function handles pendsv_handler exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void PendSV_Handler(void) void PendSV_Handler(void)
{ {
/* add user code begin PendSV_IRQ 0 */ /* add user code begin PendSV_IRQ 0 */
@@ -205,14 +201,21 @@ void PendSV_Handler(void)
} }
/** /**
* @brief this function handles CAN1 RX0 handler. * @brief this function handles CAN1 RX0 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void CAN1_RX0_IRQHandler(void) void CAN1_RX0_IRQHandler(void)
{ {
/* add user code begin CAN1_RX0_IRQ 0 */ /* add user code begin CAN1_RX0_IRQ 0 */
if (SET == can_flag_get(CAN1, CAN_RF0MN_FLAG)) {
can_rx_message_type can_rx_message;
can_message_receive(CAN1, CAN_RX_FIFO0, &can_rx_message);
by_servo_can_handle((uint16_t)can_rx_message.standard_id, can_rx_message.data, can_rx_message.dlc);
can_flag_clear(CAN1, CAN_RF0MN_FLAG);
}
/* add user code end CAN1_RX0_IRQ 0 */ /* add user code end CAN1_RX0_IRQ 0 */
/* add user code begin CAN1_RX0_IRQ 1 */ /* add user code begin CAN1_RX0_IRQ 1 */

View File

@@ -1,27 +1,27 @@
/* add user code begin Header */ /* add user code begin Header */
/** /**
************************************************************************** **************************************************************************
* @file at32f415_wk_config.c * @file at32f415_wk_config.c
* @brief work bench config program * @brief work bench config program
************************************************************************** **************************************************************************
* Copyright notice & Disclaimer * Copyright notice & Disclaimer
* *
* The software Board Support Package (BSP) that is made available to * The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery. * download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP * Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and * software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the * development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer. * software is governed by this copyright notice and the following disclaimer.
* *
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
* *
************************************************************************** **************************************************************************
*/ */
/* add user code end Header */ /* add user code end Header */
#include "at32f415_wk_config.h" #include "at32f415_wk_config.h"
@@ -62,22 +62,22 @@
/* add user code end 0 */ /* add user code end 0 */
/** /**
* @brief system clock config program * @brief system clock config program
* @note the system clock is configured as follow: * @note the system clock is configured as follow:
* system clock (sclk) = hick / 12 * pll_mult * system clock (sclk) = hick / 12 * pll_mult
* system clock source = HICK_VALUE * system clock source = HICK_VALUE
* - sclk = 144000000 * - sclk = 144000000
* - ahbdiv = 1 * - ahbdiv = 1
* - ahbclk = 144000000 * - ahbclk = 144000000
* - apb1div = 2 * - apb1div = 2
* - apb1clk = 72000000 * - apb1clk = 72000000
* - apb2div = 2 * - apb2div = 2
* - apb2clk = 72000000 * - apb2clk = 72000000
* - pll_mult = 36 * - pll_mult = 36
* - flash_wtcyc = 4 cycle * - flash_wtcyc = 4 cycle
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_system_clock_config(void) void wk_system_clock_config(void)
{ {
/* reset crm */ /* reset crm */
@@ -90,16 +90,14 @@ void wk_system_clock_config(void)
crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE); crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE);
/* wait till lick is ready */ /* wait till lick is ready */
while(crm_flag_get(CRM_LICK_STABLE_FLAG) != SET) while (crm_flag_get(CRM_LICK_STABLE_FLAG) != SET) {
{
} }
/* enable hick */ /* enable hick */
crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE); crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE);
/* wait till hick is ready */ /* wait till hick is ready */
while(crm_flag_get(CRM_HICK_STABLE_FLAG) != SET) while (crm_flag_get(CRM_HICK_STABLE_FLAG) != SET) {
{
} }
/* config pll clock resource */ /* config pll clock resource */
@@ -109,8 +107,7 @@ void wk_system_clock_config(void)
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE); crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
/* wait till pll is ready */ /* wait till pll is ready */
while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) while (crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) {
{
} }
/* config ahbclk */ /* config ahbclk */
@@ -129,8 +126,7 @@ void wk_system_clock_config(void)
crm_sysclk_switch(CRM_SCLK_PLL); crm_sysclk_switch(CRM_SCLK_PLL);
/* wait till pll is used as system clock source */ /* wait till pll is used as system clock source */
while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL) while (crm_sysclk_switch_status_get() != CRM_SCLK_PLL) {
{
} }
/* disable auto step mode */ /* disable auto step mode */
@@ -141,10 +137,10 @@ void wk_system_clock_config(void)
} }
/** /**
* @brief config periph clock * @brief config periph clock
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_periph_clock_config(void) void wk_periph_clock_config(void)
{ {
/* enable iomux periph clock */ /* enable iomux periph clock */
@@ -170,10 +166,10 @@ void wk_periph_clock_config(void)
} }
/** /**
* @brief init debug function. * @brief init debug function.
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_debug_config(void) void wk_debug_config(void)
{ {
/* jtag-dp disabled and sw-dp enabled */ /* jtag-dp disabled and sw-dp enabled */
@@ -181,10 +177,10 @@ void wk_debug_config(void)
} }
/** /**
* @brief nvic config * @brief nvic config
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_nvic_config(void) void wk_nvic_config(void)
{ {
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
@@ -193,10 +189,10 @@ void wk_nvic_config(void)
} }
/** /**
* @brief init gpio_input/gpio_output/gpio_analog/eventout function. * @brief init gpio_input/gpio_output/gpio_analog/eventout function.
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_gpio_config(void) void wk_gpio_config(void)
{ {
/* add user code begin gpio_config 0 */ /* add user code begin gpio_config 0 */
@@ -214,10 +210,10 @@ void wk_gpio_config(void)
gpio_bits_reset(GPIOA, GPIO_PINS_10); gpio_bits_reset(GPIOA, GPIO_PINS_10);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_10; gpio_init_struct.gpio_pins = GPIO_PINS_10;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* add user code begin gpio_config 2 */ /* add user code begin gpio_config 2 */
@@ -226,10 +222,10 @@ void wk_gpio_config(void)
} }
/** /**
* @brief init usart2 function * @brief init usart2 function
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_usart2_init(void) void wk_usart2_init(void)
{ {
/* add user code begin usart2_init 0 */ /* add user code begin usart2_init 0 */
@@ -245,18 +241,18 @@ void wk_usart2_init(void)
/* configure the TX pin */ /* configure the TX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_2; gpio_init_struct.gpio_pins = GPIO_PINS_2;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure the RX pin */ /* configure the RX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_3; gpio_init_struct.gpio_pins = GPIO_PINS_3;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure param */ /* configure param */
@@ -275,10 +271,10 @@ void wk_usart2_init(void)
} }
/** /**
* @brief init tmr1 function. * @brief init tmr1 function.
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_tmr1_init(void) void wk_tmr1_init(void)
{ {
/* add user code begin tmr1_init 0 */ /* add user code begin tmr1_init 0 */
@@ -296,18 +292,18 @@ void wk_tmr1_init(void)
/* add user code end tmr1_init 1 */ /* add user code end tmr1_init 1 */
/* configure the CH1 pin */ /* configure the CH1 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_8; gpio_init_struct.gpio_pins = GPIO_PINS_8;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure the CH2 pin */ /* configure the CH2 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_9; gpio_init_struct.gpio_pins = GPIO_PINS_9;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
@@ -323,13 +319,13 @@ void wk_tmr1_init(void)
tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_RESET); tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_RESET);
/* configure channel 1 output settings */ /* configure channel 1 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE; tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE; tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE; tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_1, &tmr_output_struct); tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 0); tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 0);
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE); tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
@@ -337,13 +333,13 @@ void wk_tmr1_init(void)
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_1, FALSE); tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
/* configure channel 2 output settings */ /* configure channel 2 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE; tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE; tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE; tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_2, &tmr_output_struct); tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 0); tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 0);
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE); tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
@@ -351,16 +347,15 @@ void wk_tmr1_init(void)
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_2, FALSE); tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
/* configure break and dead-time settings */ /* configure break and dead-time settings */
tmr_brkdt_struct.brk_enable = FALSE; tmr_brkdt_struct.brk_enable = FALSE;
tmr_brkdt_struct.auto_output_enable = FALSE; tmr_brkdt_struct.auto_output_enable = FALSE;
tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW; tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW;
tmr_brkdt_struct.fcsoen_state = FALSE; tmr_brkdt_struct.fcsoen_state = FALSE;
tmr_brkdt_struct.fcsodis_state = FALSE; tmr_brkdt_struct.fcsodis_state = FALSE;
tmr_brkdt_struct.wp_level = TMR_WP_OFF; tmr_brkdt_struct.wp_level = TMR_WP_OFF;
tmr_brkdt_struct.deadtime = 0; tmr_brkdt_struct.deadtime = 0;
tmr_brkdt_config(TMR1, &tmr_brkdt_struct); tmr_brkdt_config(TMR1, &tmr_brkdt_struct);
tmr_output_enable(TMR1, TRUE); tmr_output_enable(TMR1, TRUE);
tmr_counter_enable(TMR1, TRUE); tmr_counter_enable(TMR1, TRUE);
@@ -371,10 +366,10 @@ void wk_tmr1_init(void)
} }
/** /**
* @brief init tmr3 function. * @brief init tmr3 function.
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_tmr3_init(void) void wk_tmr3_init(void)
{ {
/* add user code begin tmr3_init 0 */ /* add user code begin tmr3_init 0 */
@@ -391,34 +386,34 @@ void wk_tmr3_init(void)
/* add user code end tmr3_init 1 */ /* add user code end tmr3_init 1 */
/* configure the CH1 pin */ /* configure the CH1 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_6; gpio_init_struct.gpio_pins = GPIO_PINS_6;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure the CH2 pin */ /* configure the CH2 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_7; gpio_init_struct.gpio_pins = GPIO_PINS_7;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure the CH3 pin */ /* configure the CH3 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_0; gpio_init_struct.gpio_pins = GPIO_PINS_0;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOB, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);
/* configure the CH4 pin */ /* configure the CH4 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_1; gpio_init_struct.gpio_pins = GPIO_PINS_1;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOB, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);
@@ -433,13 +428,13 @@ void wk_tmr3_init(void)
tmr_primary_mode_select(TMR3, TMR_PRIMARY_SEL_RESET); tmr_primary_mode_select(TMR3, TMR_PRIMARY_SEL_RESET);
/* configure channel 1 output settings */ /* configure channel 1 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE; tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE; tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE; tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_1, &tmr_output_struct); tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_1, 0); tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_1, 0);
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_1, FALSE); tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_1, FALSE);
@@ -447,13 +442,13 @@ void wk_tmr3_init(void)
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_1, FALSE); tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_1, FALSE);
/* configure channel 2 output settings */ /* configure channel 2 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE; tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE; tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE; tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_2, &tmr_output_struct); tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_2, 0); tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_2, 0);
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_2, FALSE); tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_2, FALSE);
@@ -461,13 +456,13 @@ void wk_tmr3_init(void)
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_2, FALSE); tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_2, FALSE);
/* configure channel 3 output settings */ /* configure channel 3 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE; tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE; tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE; tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_3, &tmr_output_struct); tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_3, 0); tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_3, 0);
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_3, FALSE); tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_3, FALSE);
@@ -475,20 +470,19 @@ void wk_tmr3_init(void)
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_3, FALSE); tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_3, FALSE);
/* configure channel 4 output settings */ /* configure channel 4 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE; tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE; tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE; tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_4, &tmr_output_struct); tmr_output_channel_config(TMR3, TMR_SELECT_CHANNEL_4, &tmr_output_struct);
tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_4, 0); tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_4, 0);
tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_4, FALSE); tmr_output_channel_buffer_enable(TMR3, TMR_SELECT_CHANNEL_4, FALSE);
tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_4, FALSE); tmr_output_channel_immediately_set(TMR3, TMR_SELECT_CHANNEL_4, FALSE);
tmr_counter_enable(TMR3, TRUE); tmr_counter_enable(TMR3, TRUE);
/* add user code begin tmr3_init 2 */ /* add user code begin tmr3_init 2 */
@@ -497,16 +491,16 @@ void wk_tmr3_init(void)
} }
/** /**
* @brief init can1 function. * @brief init can1 function.
* @param none * @param none
* @retval none * @retval none
*/ */
void wk_can1_init(void) void wk_can1_init(void)
{ {
/* add user code begin can1_init 0 */ /* add user code begin can1_init 0 */
/* add user code end can1_init 0 */ /* add user code end can1_init 0 */
gpio_init_type gpio_init_struct; gpio_init_type gpio_init_struct;
can_base_type can_base_struct; can_base_type can_base_struct;
can_baudrate_type can_baudrate_struct; can_baudrate_type can_baudrate_struct;
@@ -515,57 +509,57 @@ void wk_can1_init(void)
/* add user code begin can1_init 1 */ /* add user code begin can1_init 1 */
/* add user code end can1_init 1 */ /* add user code end can1_init 1 */
/*gpio-----------------------------------------------------------------------------*/ /*gpio-----------------------------------------------------------------------------*/
gpio_default_para_init(&gpio_init_struct); gpio_default_para_init(&gpio_init_struct);
/* configure the CAN1 TX pin */ /* configure the CAN1 TX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_12; gpio_init_struct.gpio_pins = GPIO_PINS_12;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure the CAN1 RX pin */ /* configure the CAN1 RX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_11; gpio_init_struct.gpio_pins = GPIO_PINS_11;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/*can_base_init--------------------------------------------------------------------*/ /*can_base_init--------------------------------------------------------------------*/
can_default_para_init(&can_base_struct); can_default_para_init(&can_base_struct);
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE; can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
can_base_struct.ttc_enable = FALSE; can_base_struct.ttc_enable = FALSE;
can_base_struct.aebo_enable = TRUE; can_base_struct.aebo_enable = TRUE;
can_base_struct.aed_enable = TRUE; can_base_struct.aed_enable = TRUE;
can_base_struct.prsf_enable = FALSE; can_base_struct.prsf_enable = FALSE;
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED; can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
can_base_struct.mmssr_selection = CAN_SENDING_BY_ID; can_base_struct.mmssr_selection = CAN_SENDING_BY_ID;
can_base_init(CAN1, &can_base_struct); can_base_init(CAN1, &can_base_struct);
/*can_baudrate_setting-------------------------------------------------------------*/ /*can_baudrate_setting-------------------------------------------------------------*/
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
can_baudrate_struct.baudrate_div = 18; /*value: 1~0xFFF*/ can_baudrate_struct.baudrate_div = 18; /*value: 1~0xFFF*/
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
can_baudrate_struct.bts1_size = CAN_BTS1_6TQ; /*value: 1~16*/ can_baudrate_struct.bts1_size = CAN_BTS1_6TQ; /*value: 1~16*/
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
can_baudrate_set(CAN1, &can_baudrate_struct); can_baudrate_set(CAN1, &can_baudrate_struct);
/*can_filter_0_config--------------------------------------------------------------*/ /*can_filter_0_config--------------------------------------------------------------*/
can_filter_init_struct.filter_activate_enable = TRUE; can_filter_init_struct.filter_activate_enable = TRUE;
can_filter_init_struct.filter_number = 0; can_filter_init_struct.filter_number = 0;
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0; can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT; can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK; can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/ /*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
can_filter_init_struct.filter_id_high = 0x0 << 5; can_filter_init_struct.filter_id_high = 0x0 << 5;
can_filter_init_struct.filter_id_low = 0x0 << 5; can_filter_init_struct.filter_id_low = 0x0 << 5;
can_filter_init_struct.filter_mask_high = 0x0 << 5; can_filter_init_struct.filter_mask_high = 0x0 << 5;
can_filter_init_struct.filter_mask_low = 0x0 << 5; can_filter_init_struct.filter_mask_low = 0x0 << 5;
can_filter_init(CAN1, &can_filter_init_struct); can_filter_init(CAN1, &can_filter_init_struct);
@@ -578,7 +572,7 @@ void wk_can1_init(void)
*/ */
/* add user code begin can1_init 2 */ /* add user code begin can1_init 2 */
can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
/* add user code end can1_init 2 */ /* add user code end can1_init 2 */
} }

View File

@@ -1,27 +1,27 @@
/* add user code begin Header */ /* add user code begin Header */
/** /**
************************************************************************** **************************************************************************
* @file main.c * @file main.c
* @brief main program * @brief main program
************************************************************************** **************************************************************************
* Copyright notice & Disclaimer * Copyright notice & Disclaimer
* *
* The software Board Support Package (BSP) that is made available to * The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery. * download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP * Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and * software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the * development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer. * software is governed by this copyright notice and the following disclaimer.
* *
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
* *
************************************************************************** **************************************************************************
*/ */
/* add user code end Header */ /* add user code end Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
@@ -30,6 +30,7 @@
/* private includes ----------------------------------------------------------*/ /* private includes ----------------------------------------------------------*/
/* add user code begin private includes */ /* add user code begin private includes */
#include "by_debug.h" #include "by_debug.h"
#include "by_servo.h"
/* add user code end private includes */ /* add user code end private includes */
/* private typedef -----------------------------------------------------------*/ /* private typedef -----------------------------------------------------------*/
@@ -63,10 +64,10 @@
/* add user code end 0 */ /* add user code end 0 */
/** /**
* @brief main function. * @brief main function.
* @param none * @param none
* @retval none * @retval none
*/ */
int main(void) int main(void)
{ {
/* add user code begin 1 */ /* add user code begin 1 */
@@ -102,12 +103,12 @@ int main(void)
/* add user code begin 2 */ /* add user code begin 2 */
delay_init(); delay_init();
by_servo_init();
/* add user code end 2 */ /* add user code end 2 */
while(1) while (1) {
{ gpio_bits_write(GPIOA, GPIO_PINS_10, !gpio_output_data_bit_read(GPIOA, GPIO_PINS_10));
/* add user code begin 3 */ delay_ms(1000);
/* add user code end 3 */ /* add user code end 3 */
} }
} }