使用单线程方式运行
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "debug.h"
|
||||
#include "board.h"
|
||||
#include "mymain.h"
|
||||
#include "string.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -66,6 +68,17 @@ static void MX_IPCC_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
void VIRT_UART0_RxCpltCallback(VIRT_UART_HandleTypeDef *huart);
|
||||
void VIRT_UART1_RxCpltCallback(VIRT_UART_HandleTypeDef *huart);
|
||||
|
||||
void send_str_to_a7(const char *str)
|
||||
{
|
||||
static uint8_t send_buff[512];
|
||||
int len=strlen(str);
|
||||
send_buff[0]=0xff;
|
||||
send_buff[1]=len;
|
||||
memcpy(send_buff+2,str,len);
|
||||
VIRT_UART_Transmit(&huart0, send_buff, len+2);
|
||||
}
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@@ -79,12 +92,12 @@ void VIRT_UART1_RxCpltCallback(VIRT_UART_HandleTypeDef *huart);
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
debug_init();
|
||||
//debug_init();
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
DBG_LOG("mcu start.");
|
||||
//DBG_LOG("mcu start.");
|
||||
/* Reset of all peripherals, Initialize the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
@@ -141,10 +154,8 @@ int main(void)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
pwm_def *pwm=dev_get("pwm");
|
||||
pwm->init(pwm);
|
||||
DBG_LOG("pwm start.");
|
||||
pwm->start(pwm,1);
|
||||
void *mymain=mymain_init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@@ -153,11 +164,13 @@ int main(void)
|
||||
{
|
||||
|
||||
OPENAMP_check_for_message();
|
||||
|
||||
mymain_scan(mymain);
|
||||
/* USER CODE END WHILE */
|
||||
if (VirtUart0RxMsg) {
|
||||
VirtUart0RxMsg = RESET;
|
||||
// +2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡ͷ<D6A1>ͳ<EFBFBD><CDB3><EFBFBD>λ
|
||||
VIRT_UART_Transmit(&huart0, VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
|
||||
mymain_loop(mymain,(char *)VirtUart0ChannelBuffRx+2);
|
||||
}
|
||||
|
||||
if (VirtUart1RxMsg) {
|
||||
@@ -307,6 +320,7 @@ void VIRT_UART0_RxCpltCallback(VIRT_UART_HandleTypeDef *huart)
|
||||
/* copy received msg in a variable to sent it back to master processor in main infinite loop*/
|
||||
VirtUart0ChannelRxSize = huart->RxXferSize < MAX_BUFFER_SIZE? huart->RxXferSize : MAX_BUFFER_SIZE-1;
|
||||
memcpy(VirtUart0ChannelBuffRx, huart->pRxBuffPtr, VirtUart0ChannelRxSize);
|
||||
VirtUart0ChannelBuffRx[VirtUart0ChannelRxSize]=0;
|
||||
VirtUart0RxMsg = SET;
|
||||
}
|
||||
|
||||
@@ -318,6 +332,7 @@ void VIRT_UART1_RxCpltCallback(VIRT_UART_HandleTypeDef *huart)
|
||||
/* copy received msg in a variable to sent it back to master processor in main infinite loop*/
|
||||
VirtUart1ChannelRxSize = huart->RxXferSize < MAX_BUFFER_SIZE? huart->RxXferSize : MAX_BUFFER_SIZE-1;
|
||||
memcpy(VirtUart1ChannelBuffRx, huart->pRxBuffPtr, VirtUart1ChannelRxSize);
|
||||
VirtUart1ChannelBuffRx[VirtUart1ChannelRxSize]=0;
|
||||
VirtUart1RxMsg = SET;
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
|
284
source/main/mymain.c
Normal file
284
source/main/mymain.c
Normal file
@@ -0,0 +1,284 @@
|
||||
#include "mymain.h"
|
||||
#include "main.h"
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
#include "core_delay.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
|
||||
|
||||
typedef struct{
|
||||
pwm_def *pwm;
|
||||
int key_old;
|
||||
int key;
|
||||
int sen;
|
||||
char str_buff[200];
|
||||
}mymain_def;
|
||||
|
||||
static mymain_def g_m={0};
|
||||
|
||||
void *mymain_init(void)
|
||||
{
|
||||
|
||||
delay_init();
|
||||
// m.pwm=dev_get("pwm");
|
||||
// m.pwm->init(m.pwm);
|
||||
//DBG_LOG("pwm start.");
|
||||
// m.pwm->start(m.pwm,1);
|
||||
GPIO_InitTypeDef init={0};
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
init.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
init.Pull = GPIO_PULLUP;
|
||||
init.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
|
||||
PERIPH_LOCK(GPIOF);
|
||||
HAL_GPIO_Init(GPIOF, &init);
|
||||
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOF);
|
||||
|
||||
|
||||
// <20><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
init.Pull = GPIO_NOPULL;
|
||||
init.Pin = GPIO_PIN_6;
|
||||
PERIPH_LOCK(GPIOI);
|
||||
HAL_GPIO_Init(GPIOI, &init);
|
||||
PERIPH_UNLOCK(GPIOI);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
init.Pull = GPIO_NOPULL;
|
||||
init.Pin = GPIO_PIN_3;
|
||||
PERIPH_LOCK(GPIOG);
|
||||
HAL_GPIO_Init(GPIOG, &init);
|
||||
PERIPH_UNLOCK(GPIOG);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
init.Pull = GPIO_NOPULL;
|
||||
init.Pin = GPIO_PIN_1|GPIO_PIN_6;
|
||||
PERIPH_LOCK(GPIOE);
|
||||
HAL_GPIO_Init(GPIOE, &init);
|
||||
PERIPH_UNLOCK(GPIOE);
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
init.Pull = GPIO_NOPULL;
|
||||
init.Pin = GPIO_PIN_8|GPIO_PIN_9;
|
||||
PERIPH_LOCK(GPIOH);
|
||||
HAL_GPIO_Init(GPIOH, &init);
|
||||
PERIPH_UNLOCK(GPIOH);
|
||||
|
||||
return &g_m;
|
||||
}
|
||||
|
||||
|
||||
void send_str_to_a7(const char *str);
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1=PF9;2=PF8;3=PF7
|
||||
void out_set(int index,int power)
|
||||
{
|
||||
mymain_def *m=&g_m;
|
||||
PERIPH_LOCK(GPIOF);
|
||||
HAL_GPIO_WritePin(GPIOF,1<<(10-index),power?GPIO_PIN_SET:GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOF);
|
||||
sprintf(m->str_buff,"out_set:%d,%d",index,power);
|
||||
send_str_to_a7(m->str_buff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void moter_plused(int us)
|
||||
{
|
||||
// out3
|
||||
//HAL_GPIO_TogglePin(GPIOF,1<<7);
|
||||
// out1
|
||||
HAL_GPIO_TogglePin(GPIOF,1<<9);
|
||||
delay_us(us);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PF7-PWM PF8-DST PI6_STOP
|
||||
// <20>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
void moter_run(int pwm,int count)
|
||||
{
|
||||
int use_sen=0;
|
||||
if(count>0){
|
||||
HAL_GPIO_WritePin(GPIOF,1<<8,GPIO_PIN_RESET);
|
||||
}else{
|
||||
HAL_GPIO_WritePin(GPIOF,1<<8,GPIO_PIN_SET);
|
||||
count=-count;
|
||||
use_sen=1;
|
||||
}
|
||||
int max_=500;
|
||||
int min_=35;
|
||||
int temp=max_;
|
||||
int add_count=0;
|
||||
int step_sub=0;
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
//<2F>ѵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>˳<EFBFBD>
|
||||
if((HAL_GPIO_ReadPin(GPIOI,1<<6)==RESET)&&(use_sen!=0)) return;
|
||||
moter_plused(temp);
|
||||
if(pwm==0){
|
||||
// pwm==0ʱ <20>Զ<EFBFBD><D4B6>Ӽ<EFBFBD><D3BC><EFBFBD>
|
||||
if(i<count/2){
|
||||
if(temp>min_) {step_sub+=temp; if(step_sub>=1000) {temp--; step_sub=0;}}
|
||||
else add_count++;
|
||||
}else{
|
||||
if(add_count>0) add_count--;
|
||||
else {step_sub+=temp; if(step_sub>=1000) {temp++; step_sub=0;}}
|
||||
}
|
||||
}else{
|
||||
// pwm!=0ʱ <20><><EFBFBD><EFBFBD>
|
||||
temp=1000000/pwm;
|
||||
}
|
||||
}
|
||||
// out3
|
||||
//HAL_GPIO_WritePin(GPIOF,1<<7,GPIO_PIN_SET);
|
||||
// out1
|
||||
HAL_GPIO_WritePin(GPIOF,1<<9,GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int str_ainttoi(const char *s)
|
||||
{
|
||||
int ret=0;
|
||||
int sig=1;
|
||||
if(*s=='-'){
|
||||
s++;
|
||||
sig=-1;
|
||||
}
|
||||
while(*s)
|
||||
{
|
||||
if(*s>='0'&&*s<='9')
|
||||
{
|
||||
ret*=10;
|
||||
ret+=*s-'0';
|
||||
}
|
||||
else return ret*sig;
|
||||
s++;
|
||||
}
|
||||
return ret*sig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void mymain_scan(void *mymain)
|
||||
{
|
||||
mymain_def *m=mymain;
|
||||
m->key=HAL_GPIO_ReadPin(GPIOG,1<<3);
|
||||
m->sen=HAL_GPIO_ReadPin(GPIOI,1<<6);
|
||||
if(m->key_old!=m->key){
|
||||
if(m->key==RESET)
|
||||
{
|
||||
send_str_to_a7("key press");
|
||||
}else
|
||||
{
|
||||
send_str_to_a7("key up");
|
||||
}
|
||||
m->key_old=m->key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int read_sw(void *mymain)
|
||||
{
|
||||
int ret=0;
|
||||
ret|=HAL_GPIO_ReadPin(GPIOE,1<<6);
|
||||
ret|=HAL_GPIO_ReadPin(GPIOH,1<<9)<<1;
|
||||
ret|=HAL_GPIO_ReadPin(GPIOE,1<<1)<<2;
|
||||
ret|=HAL_GPIO_ReadPin(GPIOH,1<<8)<<3;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void mymain_loop(void *mymain,char *cmd_str)
|
||||
{
|
||||
mymain_def *m=mymain;
|
||||
if(strncmp(cmd_str,"moter ",6)==0)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD>
|
||||
int count=str_ainttoi(cmd_str+6);
|
||||
if(count!=0){
|
||||
send_str_to_a7(m->str_buff);
|
||||
moter_run(0,count);
|
||||
if(count>0){
|
||||
send_str_to_a7("moter down");
|
||||
}else{
|
||||
send_str_to_a7("moter up");
|
||||
}
|
||||
}
|
||||
}else if(strncmp(cmd_str,"moterinit",9)==0)
|
||||
{
|
||||
// <20><>ʼ<EFBFBD><CABC>
|
||||
moter_run(2000,-25000);
|
||||
send_str_to_a7("moterinited");
|
||||
}
|
||||
else if(strncmp(cmd_str,"motertest ",10)==0)
|
||||
{
|
||||
// <20><>ʼ<EFBFBD><CABC>
|
||||
int count=str_ainttoi(cmd_str+10);
|
||||
moter_run(2000,count);
|
||||
send_str_to_a7("motertest end");
|
||||
}
|
||||
else if(strncmp(cmd_str,"readsw",6)==0)
|
||||
{
|
||||
int sw=read_sw(mymain);
|
||||
sprintf(m->str_buff,"readsw %d",sw);
|
||||
send_str_to_a7(m->str_buff);
|
||||
}
|
||||
else if(strncmp(cmd_str,"readkey",7)==0){
|
||||
if(m->key)
|
||||
send_str_to_a7("key up");
|
||||
else
|
||||
send_str_to_a7("key press");
|
||||
}
|
||||
else if(strncmp(cmd_str,"readsen",7)==0){
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
if(m->sen)
|
||||
send_str_to_a7("sen high");
|
||||
else
|
||||
send_str_to_a7("sen low");
|
||||
}
|
||||
else if(strncmp(cmd_str,"out",3)==0){
|
||||
if((cmd_str[3]>='1')&&(cmd_str[3]<='3')){
|
||||
if(strncmp(cmd_str+5,"on",2)==0){
|
||||
out_set(cmd_str[3]-'0',1);
|
||||
}else if(strncmp(cmd_str+5,"off",3)==0){
|
||||
out_set(cmd_str[3]-'0',0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mymain_loop__(void *mymain,char *cmd_str)
|
||||
{
|
||||
while(1){
|
||||
HAL_GPIO_TogglePin(GPIOF,1<<7);
|
||||
HAL_GPIO_TogglePin(GPIOF,1<<8);
|
||||
HAL_GPIO_TogglePin(GPIOF,1<<9);
|
||||
HAL_Delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
23
source/main/mymain.h
Normal file
23
source/main/mymain.h
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
#ifndef mymain_h__
|
||||
#define mymain_h__
|
||||
|
||||
|
||||
|
||||
|
||||
void *mymain_init(void);
|
||||
|
||||
|
||||
|
||||
void mymain_loop(void *mymain,char *cmd_str);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -182,16 +182,16 @@ void DebugMon_Handler(void)
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
//void SysTick_Handler(void)
|
||||
//{
|
||||
// /* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
// /* USER CODE END SysTick_IRQn 0 */
|
||||
// HAL_IncTick();
|
||||
// /* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
// /* USER CODE END SysTick_IRQn 1 */
|
||||
//}
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32MP1xx Peripheral Interrupt Handlers */
|
||||
|
Reference in New Issue
Block a user