timer emulation

This commit is contained in:
leo 2023-09-10 10:24:43 +02:00
parent 2b3bb3abc6
commit b32090075e
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
3 changed files with 32 additions and 2 deletions

9
main.c
View File

@ -10,6 +10,7 @@
#include "PSE_unit.h"
#include "home_screen.h"
#include "PSE_unit.h"
#include "pse_stepper_planer.h"
#define BUFF_SIZE (320 * 10)
#define LCD_WIDTH 320
@ -176,3 +177,11 @@ void * tick_thread (void *args){
lv_tick_inc(5); /*Tell LVGL that 5 milliseconds were elapsed*/
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim){
for(int i = 0; i < PSE_UNITS_NUM; i++){
if(htim == pse_units[i].stepper_conf->tim){
pse_stepper_planer_tick(&pse_units[i]);
}
}
}

View File

@ -1,5 +1,7 @@
#include "stm32f1xx_hal.h"
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin){
printf("toggling pin\n");
@ -12,11 +14,26 @@ void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState Pin
printf("writing pin\n");
}
static void* tim_handler(void* arg){
TIM_HandleTypeDef* htim = arg;
while(htim->started){
uint64_t delay_ps = 15625 * htim->presc * htim->period;
printf("delay : %lu\n", delay_ps);
usleep(delay_ps / 1000000);
HAL_TIM_PeriodElapsedCallback(htim);
}
return NULL;
}
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim){
printf("starting timer\n");
htim->started = 1;
pthread_t tim_thread;
pthread_create(&tim_thread, NULL, tim_handler, htim);
return HAL_STATUS_OK;
}
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim){
printf("stopping timer\n");
htim->started = 0;
return HAL_STATUS_OK;
}

View File

@ -7,8 +7,10 @@ typedef struct {
uint8_t index;
} GPIO_TypeDef;
typedef struct
{
typedef struct{
uint16_t presc;
uint16_t period;
uint8_t started;
} TIM_HandleTypeDef;
typedef int HAL_StatusTypeDef;
@ -71,3 +73,5 @@ void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState Pin
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim);