* AutoChips Inc. (C) 2021. All rights reserved.
*
* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
* RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
* ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
* INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
* SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
* RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
* AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
* CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
*
******************************************************************************
*/
/* --------------------------------- Includes -------------------------------*/
#include "main.h"
#include "ac780x_irq_cb.h"
#include "ac780x_uart.h"
#include "ac780x_uart_reg.h"
#include "ac780x_gpio.h"
/* USER CODE BEGIN Includes */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"
/* USER CODE END Includes */
/* --------------------------------- Typedefs -------------------------------*/
/* USER CODE BEGIN Typedefs */
static TaskHandle_t xHandleTaskLed = NULL;
static TaskHandle_t xTaskTaskKey = NULL;
QueueHandle_t Test_GpioQueue =NULL; //消息队列句柄
/* USER CODE END Typedefs */
/* --------------------------------- Defines --------------------------------*/
/* USER CODE BEGIN Defines */
/* USER CODE END Defines */
/* --------------------------------- Macros ---------------------------------*/
/* USER CODE BEGIN Macros */
/* USER CODE END Macros */
/* --------------------------------- Variables ------------------------------*/
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
/* --------------------------------- Function Prototypes --------------------*/
void SystemClock_Config(void);
static void ATC_GPIO_Init(void);
static void ATC_UART2_Init(void);
static void ATC_UART1_Init(void);
void MSP_Init(void);
void MSP_UART_Init(UART_Type* UARTx);
/* USER CODE BEGIN Function_Prototypes */
static void vTaskTaskLed(void* parameter)
{
BaseType_t xReturn = pdPASS;
uint8_t xRekeydata[2]={0x0};
while (1)
{
printf("Scan msg \r\n");
xReturn = xQueueReceive(Test_GpioQueue, xRekeydata, 500);
if(xReturn == errQUEUE_EMPTY)
{
printf("empty\r\n");
}
if(xReturn == pdTRUE)
{
printf("Get %d,%d\r\n",xRekeydata[0],xRekeydata[1]);
if(xRekeydata[0] == 0x01)
GPIO_SetPinLevel(LED2_GPIO_Port,LED2_Pin,GPIO_LEVEL_LOW);
else
GPIO_SetPinLevel(LED2_GPIO_Port,LED2_Pin,GPIO_LEVEL_HIGH);
}
else
{
}
/*
printf("Task Led 0\r\n");
GPIO_SetPinLevel(LED1_GPIO_Port,LED1_Pin,GPIO_LEVEL_LOW);
vTaskDelay(500);
printf("Task Led 1\r\n");
GPIO_SetPinLevel(LED1_GPIO_Port,LED1_Pin,GPIO_LEVEL_HIGH);
vTaskDelay(500);
*/
}
}
static void vTaskTaskKey(void* parameter)
{
BaseType_t xReturn = pdPASS;
uint8_t xkeydata[2]={0x0};
while (1)
{
//L enable
/* printf("Task Key\r\n");
if(GPIO_GetPinLevel(KEY2_GPIO_Port, KEY2_Pin) == 0)
{
// GPIO_SetPinLevel(LED2_GPIO_Port,LED2_Pin,GPIO_LEVEL_LOW);
xkeydata[0] = 0x00;
xkeydata[1] = 0x00;
xReturn = xQueueSend( Test_GpioQueue, xkeydata,0);
}
else
{
// GPIO_SetPinLevel(LED2_GPIO_Port,LED2_Pin,GPIO_LEVEL_HIGH);
xkeydata[0] = 0x01;
xkeydata[1] = 0x01;
xReturn = xQueueSend( Test_GpioQueue, xkeydata,0);
}
vTaskDelay(5000);
*/
}
}
/* USER CODE END Function_Prototypes */
/* USER CODE BEGIN 0 */
static void AppTaskCreate (void)
{
Test_GpioQueue = xQueueCreate(16, 2);
if(NULL != Test_GpioQueue)
{
printf("消息队列创建成功\r\n");
}
else
{
printf("消息队列创建失败\r\n");
}
xTaskCreate( vTaskTaskLed,
"vTaskLed",
512,
NULL,
1,
&xHandleTaskLed );
xTaskCreate( vTaskTaskKey,
"vTaskUserTRE",
512,
NULL,
1,
&xTaskTaskKey );
}
/*******************************************************************************
* Function Name :void ACC_IRQHandler(void *device, uint32_t wpara, uint32_t lpara)
* Description :ACC 引脚中断处理程序
* Output : None
* Return : None
*******************************************************************************/
void SocGpioACC_IRQHandler(void *device, uint32_t wpara, uint32_t lpara)
{
uint8_t xkeydata[2]={0x0};
//if(GPIO_GetPendingExtInterrupt() & KEY2_Pin)
{
GPIO_ClearPendingExtInterrupt(KEY2_Pin);
xkeydata[0] =GPIO_GetPinLevel(KEY2_GPIO_Port, KEY2_Pin);
xQueueSend( Test_GpioQueue, xkeydata,0);
}
}
/*******************************************************************************
* Function Name :void SocGpioEXITAccDet(void)
* Description :使能 ACC 中断
* Output : None
* Return : None
*******************************************************************************/
void SocGpioEXITKeyDet(void)
{
GPIO_SetPullup(KEY2_GPIO_Port,KEY2_Pin, ENABLE);
GPIO_EnableExtInterrupt(KEY2_GPIO_Port, KEY2_Pin, EXTI_TRIGGER_RISING_FALLING);
GPIO_SetCallback(KEY2_Pin, SocGpioACC_IRQHandler);
}
/* USER CODE END 0 */
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] The application entry point.
*
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration------------------------------------------------------*/
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
ATC_GPIO_Init();
ATC_UART2_Init();
ATC_UART1_Init();
/* USER CODE BEGIN 2 */
SocGpioEXITKeyDet();
InitDebug();
AppTaskCreate();
vTaskStartScheduler();
/* USER CODE END 2 */
/* Infinite loop */
while(1)
{
/* USER CODE BEGIN WHILE */
/* USER CODE END WHILE */
}
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
SPM_EnableXOSC(ENABLE);
SPM_EnablePLL(ENABLE);
CKGEN_SetPLLReference(PLL_REF_INTERAL_OSC);
CKGEN_SetPllPrevDiv(PLL_PREDIV_1);
CKGEN_SetPllFeedbackDiv(96);
CKGEN_SetPllPostDiv(PLL_POSDIV_16);
CKGEN_SetSysclkDiv(SYSCLK_DIVIDER_1);
CKGEN_SetSysclkSrc(SYSCLK_SRC_PLL_OUTPUT);
CKGEN_SetAPBClockDivider(APBCLK_DIVIDER_2);
}
/* UART1 init function */
static void ATC_UART1_Init(void)
{
/* USER CODE BEGIN UART1_Init 0 */
/* USER CODE END UART1_Init 0 */
UART_ConfigType uartConfig;
memset(&uartConfig, 0, sizeof(uartConfig));
/* USER CODE BEGIN UART1_Init 1 */
/* USER CODE END UART1_Init 1 */
MSP_UART_Init(UART1);
uartConfig.baudrate = 115200;
uartConfig.dataBits = UART_WORD_LEN_8BIT;
uartConfig.stopBits = UART_STOP_1BIT;
uartConfig.parity = UART_PARI_NO;
uartConfig.fifoByteEn = DISABLE;
uartConfig.dmaEn = UART_DMA_TXRX_NONE;
uartConfig.sampleCnt = UART_SMP_CNT0;
UART_Init(UART1, &uartConfig);
/* USER CODE BEGIN UART1_Init 2 */
/* USER CODE END UART1_Init 2 */
}
/* UART2 init function */
static void ATC_UART2_Init(void)
{
/* USER CODE BEGIN UART2_Init 0 */
/* USER CODE END UART2_Init 0 */
UART_ConfigType uartConfig;
memset(&uartConfig, 0, sizeof(uartConfig));
/* USER CODE BEGIN UART2_Init 1 */
/* USER CODE END UART2_Init 1 */
MSP_UART_Init(UART2);
uartConfig.baudrate = 115200;
uartConfig.dataBits = UART_WORD_LEN_8BIT;
uartConfig.stopBits = UART_STOP_1BIT;
uartConfig.parity = UART_PARI_NO;
uartConfig.fifoByteEn = DISABLE;
uartConfig.dmaEn = UART_DMA_TXRX_NONE;
uartConfig.sampleCnt = UART_SMP_CNT0;
UART_Init(UART2, &uartConfig);
/* USER CODE BEGIN UART2_Init 2 */
/* USER CODE END UART2_Init 2 */
}
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
static void ATC_GPIO_Init(void)
{
GPIO_SetFunc(KEY2_GPIO_Port, KEY2_Pin, GPIO_FUN0);
GPIO_SetFunc(KEY1_GPIO_Port, KEY1_Pin, GPIO_FUN0);
GPIO_SetFunc(LED2_GPIO_Port, LED2_Pin, GPIO_FUN0);
GPIO_SetFunc(LED1_GPIO_Port, LED1_Pin, GPIO_FUN0);
GPIO_SetDir(KEY2_GPIO_Port, KEY2_Pin, GPIO_IN);
GPIO_SetDir(KEY1_GPIO_Port, KEY1_Pin, GPIO_IN);
GPIO_SetDir(LED2_GPIO_Port, LED2_Pin, GPIO_OUT);
GPIO_SetDir(LED1_GPIO_Port, LED1_Pin, GPIO_OUT);
GPIO_SetPinLevel(LED2_GPIO_Port, LED2_Pin, GPIO_LEVEL_LOW);
GPIO_SetPinLevel(LED1_GPIO_Port, LED1_Pin, GPIO_LEVEL_LOW);
GPIO_SetDrivingAbility(LED2_GPIO_Port, LED2_Pin, GPIO_DRIVING_4MA);
GPIO_SetDrivingAbility(LED1_GPIO_Port, LED1_Pin, GPIO_DRIVING_4MA);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @param file: The file name as string.
* @param line: The line in file as a number.
* @retval None
*/
void Error_Handler(char *file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to handle the driver error */
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}
/************************ (C) COPYRIGHT AutoChips *****END OF FILE****/
———————————————— 版权声明:本文为CSDN博主「大唐不夜城」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/DiQiZiYouDu/article/details/117224782