Skip to content

Commit

Permalink
arch/arm/tiva: Add complementary PWM mode support
Browse files Browse the repository at this point in the history
This commit introduces support for complementary PWM mode on the Tiva
C-Series microcontrollers. The feature allows configuring specific
PWM generators to operate in complementary mode via Kconfig.

Signed-off-by: Sydeney Araujo <[email protected]>
  • Loading branch information
Sydeney-UFCG committed Feb 19, 2025
1 parent 32bc951 commit 7974674
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions arch/arm/src/tiva/common/tiva_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct tiva_pwm_chan_s
uint8_t generator_id;
uintptr_t generator_base;
uint8_t channel_id;
bool complementary_generation;
#ifdef CONFIG_PWM_PULSECOUNT
bool inited;
uint8_t irq;
Expand Down Expand Up @@ -168,6 +169,7 @@ static struct tiva_pwm_chan_s g_pwm_chan0 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 0,
.channel_id = 0,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN0,
Expand All @@ -188,6 +190,7 @@ static struct tiva_pwm_chan_s g_pwm_chan1 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 0,
.channel_id = 1,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN0,
Expand All @@ -208,6 +211,7 @@ static struct tiva_pwm_chan_s g_pwm_chan2 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 1,
.channel_id = 2,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN1,
Expand All @@ -228,6 +232,7 @@ static struct tiva_pwm_chan_s g_pwm_chan3 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 1,
.channel_id = 3,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN1,
Expand All @@ -248,6 +253,7 @@ static struct tiva_pwm_chan_s g_pwm_chan4 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 2,
.channel_id = 4,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN2,
Expand All @@ -268,6 +274,7 @@ static struct tiva_pwm_chan_s g_pwm_chan5 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 2,
.channel_id = 5,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN2,
Expand All @@ -288,6 +295,7 @@ static struct tiva_pwm_chan_s g_pwm_chan6 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 3,
.channel_id = 6,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN3,
Expand All @@ -308,6 +316,7 @@ static struct tiva_pwm_chan_s g_pwm_chan7 =
.generator_base = TIVA_PWM0_BASE + TIVA_PWMN_BASE +
TIVA_PWMN_INTERVAL * 3,
.channel_id = 7,
.complementary_generation = false;
#ifdef CONFIG_PWM_PULSECOUNT
.inited = false,
.irq = TIVA_IRQ_PWM0_GEN3,
Expand Down Expand Up @@ -604,17 +613,31 @@ static inline int tiva_pwm_timer(struct tiva_pwm_chan_s *chan,
/* Configure PWM countdown mode (refer to TM4C1294NCPDT 23.4.6) */

tiva_pwm_putreg(chan, TIVA_PWMN_CTL_OFFSET, 0);
if (chan->channel_id % 2 == 0)
if (chan->complementary_generation)
{
pwminfo("PWM Complementar ativado para Gerador %d\n", chan->generator_id);

Check failure on line 618 in arch/arm/src/tiva/common/tiva_pwm.c

View workflow job for this annotation

GitHub Actions / check

Long line found

tiva_pwm_putreg(chan, TIVA_PWMN_GENA_OFFSET,
GENX_LOW << TIVA_PWMN_GENX_ACTCMPAD |
GENX_HIGH << TIVA_PWMN_GENX_ACTLOAD);
tiva_pwm_putreg(chan, TIVA_PWMN_GENB_OFFSET,
GENX_HIGH << TIVA_PWMN_GENX_ACTCMPBD |
GENX_LOW << TIVA_PWMN_GENX_ACTLOAD);
}
else
{
tiva_pwm_putreg(chan, TIVA_PWMN_GENB_OFFSET,
GENX_LOW << TIVA_PWMN_GENX_ACTCMPBD |
GENX_HIGH << TIVA_PWMN_GENX_ACTLOAD);
if (chan->channel_id % 2 == 0)
{
tiva_pwm_putreg(chan, TIVA_PWMN_GENA_OFFSET,
GENX_LOW << TIVA_PWMN_GENX_ACTCMPAD |
GENX_HIGH << TIVA_PWMN_GENX_ACTLOAD);
}
else
{
tiva_pwm_putreg(chan, TIVA_PWMN_GENB_OFFSET,
GENX_LOW << TIVA_PWMN_GENX_ACTCMPBD |
GENX_HIGH << TIVA_PWMN_GENX_ACTLOAD);
}
}

/* Set the PWM period (refer to TM4C1294NCPDT 23.4.7) */
Expand Down Expand Up @@ -645,13 +668,21 @@ static inline int tiva_pwm_timer(struct tiva_pwm_chan_s *chan,
comp = (duty == 0) ? (comp - 1) : (comp);
pwminfo("> comp = %u (%08x)\n", comp, comp);

if (chan->channel_id % 2 == 0)
if (chan->complementary_generation)
{
tiva_pwm_putreg(chan, TIVA_PWMN_CMPA_OFFSET, comp - 1);
tiva_pwm_putreg(chan, TIVA_PWMN_CMPB_OFFSET, comp - 1);
}
else
{
tiva_pwm_putreg(chan, TIVA_PWMN_CMPB_OFFSET, comp - 1);
if (chan->channel_id % 2 == 0)
{
tiva_pwm_putreg(chan, TIVA_PWMN_CMPA_OFFSET, comp - 1);
}
else
{
tiva_pwm_putreg(chan, TIVA_PWMN_CMPB_OFFSET, comp - 1);
}
}

/* Enable the PWM generator (refer to TM4C1294NCPDT 23.4.10) */
Expand Down Expand Up @@ -878,5 +909,25 @@ struct pwm_lowerhalf_s *tiva_pwm_initialize(int channel)

#endif

#ifdef CONFIG_TIVA_PWM_COMPLEMENTARY_G0
if (chan->generator_id == 0)
chan->complementary_generation = true;
#endif

#ifdef CONFIG_TIVA_PWM_COMPLEMENTARY_G1
if (chan->generator_id == 1)
chan->complementary_generation = true;
#endif

#ifdef CONFIG_TIVA_PWM_COMPLEMENTARY_G2
if (chan->generator_id == 2)
chan->complementary_generation = true;
#endif

#ifdef CONFIG_TIVA_PWM_COMPLEMENTARY_G3
if (chan->generator_id == 3)
chan->complementary_generation = true;
#endif

return (struct pwm_lowerhalf_s *)chan;
}

0 comments on commit 7974674

Please sign in to comment.