renesas / fsp

Flexible Software Package (FSP) for Renesas RA MCU Family
https://renesas.github.io/fsp/
Other
192 stars 82 forks source link

R_GPT_InfoGet only reports count direction TIMER_DIRECTION_UP #364

Open Michael812498 opened 3 months ago

Michael812498 commented 3 months ago

The R_GPT_InfoGet function appears to be hard coded to fill timer_info_t with TIMER_DIRECTION_UP https://github.com/renesas/fsp/blob/bd5dbafc705cd53c83a6c37114fb3f08fd14f25a/ra/fsp/src/r_gpt/r_gpt.c#L683-L684

My interpretation of the intent of the function should be that it should respond with:

p_info->count_direction = p_instance_ctrl->p_reg->GTUDDTC_b_UD; or something to that effect as it is possible to configure the GPT to count down.

renesas-austin-hansen commented 2 months ago

Hi Michael, currently the RA FSP driver for GPT only supports up-counting and so this value is hardcoded. It is possible to configure the hardware to down-count mode but we do not currently expose this functionality.

One further note - GPT does automatically switch direction back and forth in triangle PWM modes. I do not think providing the actual count direction would be useful in this case given polling would be very inexact for motor control (versus events or interrupts), but a case could be made to provide it regardless if there are strong opinions.

Michael812498 commented 2 months ago

In my case I have a cascade timer/counter setup to gauge pulse outputs to absolute counts. As you say I currently manage UD through interruption by register access for timeliness, but encountered this as I was using the Info API as a part of some of the reporting and monitoring functions that have no specific realtime demands.

I have no strong preferences, the API is theoretically more portable but as you point out the argument is kind of contrived considering that you are likely operating outside of the API to some capacity if you are interested in the GPT's UD at this time.