timer emulation
This commit is contained in:
parent
2b3bb3abc6
commit
b32090075e
9
main.c
9
main.c
@ -10,6 +10,7 @@
|
|||||||
#include "PSE_unit.h"
|
#include "PSE_unit.h"
|
||||||
#include "home_screen.h"
|
#include "home_screen.h"
|
||||||
#include "PSE_unit.h"
|
#include "PSE_unit.h"
|
||||||
|
#include "pse_stepper_planer.h"
|
||||||
|
|
||||||
#define BUFF_SIZE (320 * 10)
|
#define BUFF_SIZE (320 * 10)
|
||||||
#define LCD_WIDTH 320
|
#define LCD_WIDTH 320
|
||||||
@ -176,3 +177,11 @@ void * tick_thread (void *args){
|
|||||||
lv_tick_inc(5); /*Tell LVGL that 5 milliseconds were elapsed*/
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "stm32f1xx_hal.h"
|
#include "stm32f1xx_hal.h"
|
||||||
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin){
|
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin){
|
||||||
printf("toggling pin\n");
|
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");
|
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){
|
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim){
|
||||||
printf("starting timer\n");
|
printf("starting timer\n");
|
||||||
|
htim->started = 1;
|
||||||
|
pthread_t tim_thread;
|
||||||
|
pthread_create(&tim_thread, NULL, tim_handler, htim);
|
||||||
return HAL_STATUS_OK;
|
return HAL_STATUS_OK;
|
||||||
}
|
}
|
||||||
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim){
|
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim){
|
||||||
printf("stopping timer\n");
|
printf("stopping timer\n");
|
||||||
|
htim->started = 0;
|
||||||
return HAL_STATUS_OK;
|
return HAL_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,10 @@ typedef struct {
|
|||||||
uint8_t index;
|
uint8_t index;
|
||||||
} GPIO_TypeDef;
|
} GPIO_TypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct{
|
||||||
{
|
uint16_t presc;
|
||||||
|
uint16_t period;
|
||||||
|
uint8_t started;
|
||||||
} TIM_HandleTypeDef;
|
} TIM_HandleTypeDef;
|
||||||
typedef int HAL_StatusTypeDef;
|
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_Start_IT(TIM_HandleTypeDef *htim);
|
||||||
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
|
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
|
||||||
|
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user