# cy_mcwdt_8h¶

Provides an API declaration of the Cypress PDL 3.0 MCWDT driver

Version

1.50.1

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0


Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defines

CY_MCWDT_DRV_VERSION_MAJOR

Driver major version.

CY_MCWDT_DRV_VERSION_MINOR

Driver minor version.

CY_MCWDT_ID

MCWDT PDL ID.

CY_MCWDT_CTR0

This macro is used with functions that handle multiple counters, including Cy_MCWDT_Enable(), Cy_MCWDT_Disable(), Cy_MCWDT_ClearInterrupt() and Cy_MCWDT_ResetCounters().

CY_MCWDT_CTR1

This macro is used with functions that handle multiple counters, including Cy_MCWDT_Enable(), Cy_MCWDT_Disable(), Cy_MCWDT_ClearInterrupt() and Cy_MCWDT_ResetCounters().

CY_MCWDT_CTR2

This macro is used with functions that handle multiple counters, including Cy_MCWDT_Enable(), Cy_MCWDT_Disable(), Cy_MCWDT_ClearInterrupt() and Cy_MCWDT_ResetCounters().

CY_MCWDT_CTR_Msk

This macro is used with functions that handle multiple counters, including Cy_MCWDT_Enable(), Cy_MCWDT_Disable(), Cy_MCWDT_ClearInterrupt() and Cy_MCWDT_ResetCounters().

Enums

enum cy_en_mcwdtctr_t

cy_en_mcwdtctr_t: The mcwdt sub-counter identifiers.

Values:

enumerator CY_MCWDT_COUNTER0

Sub-counter#0 identifier.

enumerator CY_MCWDT_COUNTER1

Sub-counter#1 identifier.

enumerator CY_MCWDT_COUNTER2

Sub-counter#2 identifier.

enum cy_en_mcwdtmode_t

cy_en_mcwdtmode_t: The mcwdt modes.

Values:

enumerator CY_MCWDT_MODE_NONE

The No action mode.

It is used for Set/GetMode functions.

enumerator CY_MCWDT_MODE_INT

The Interrupt mode.

It is used for Set/GetMode functions.

enumerator CY_MCWDT_MODE_RESET

The Reset mode.

It is used for Set/GetMode functions.

enumerator CY_MCWDT_MODE_INT_RESET

The Three interrupts then watchdog reset mode.

It is used for Set/GetMode functions.

enum cy_en_mcwdtcascade_t

Values:

enumerator CY_MCWDT_CASCADE_NONE

It is used for Set/GetCascade functions.

enumerator CY_MCWDT_CASCADE_C0C1

The sub-counter#1 is clocked by LFCLK or from sub-counter#0 cascade.

It is used for Set/GetCascade functions.

enumerator CY_MCWDT_CASCADE_C1C2

The sub-counter#2 is clocked by LFCLK or from sub-counter#1 cascade.

It is used for Set/GetCascade functions.

enumerator CY_MCWDT_CASCADE_BOTH

The sub-counter#1 is clocked by LFCLK or from sub-counter#0 cascade and the sub-counter#2 is clocked by LFCLK or from sub-counter#1 cascade.

It is used for Set/GetCascade functions.

enum cy_en_mcwdt_status_t

cy_en_mcwdt_status_t: The MCWDT error codes.

Values:

enumerator CY_MCWDT_SUCCESS

Successful.

enumerator CY_MCWDT_BAD_PARAM

One or more invalid parameters.

Functions

cy_en_mcwdt_status_t Cy_MCWDT_Init(MCWDT_STRUCT_Type *base, cy_stc_mcwdt_config_t const *config)

Initializes the MCWDT block.

note

This API should not be called when the counters are running. Prior to calling this API the counter should be disabled.

Parameters
• base – The base pointer to a structure that describes the registers.

• config – The pointer to a structure that contains component configuration data.

Returns

cy_en_mcwdt_status_t *base checking result. If the pointer is NULL, returns error.

void Cy_MCWDT_DeInit(MCWDT_STRUCT_Type *base)

De-initializes the MCWDT block, returns register values to their default state.

note

This API should not be called when the counters are running. Prior to calling this API the counter should be disabled.

Parameters

base – The base pointer to a structure that describes the registers.

__STATIC_INLINE void Cy_MCWDT_Enable (MCWDT_STRUCT_Type *base, uint32_t counters, uint16_t waitUs)

Enables all specified counters.

note

Setting this parameter to a zero means No wait. In this case, it is the user's responsibility to check whether the selected counters were enabled immediately after the function call. This can be done by the Cy_MCWDT_GetEnabledStatus() API.

Parameters
• base – The base pointer to a structure that describes registers.

• counters – OR of all counters to enable. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

• waitUs – The function waits for some delay in microseconds before returning, because the counter begins counting after two lf_clk cycles pass. The recommended value is 93 us.

__STATIC_INLINE void Cy_MCWDT_Disable (MCWDT_STRUCT_Type *base, uint32_t counters, uint16_t waitUs)

Disables all specified counters.

note

Setting this parameter to a zero means No wait. In this case, it is the user's responsibility to check whether the selected counters were disabled immediately after the function call. This can be done by the Cy_MCWDT_GetEnabledStatus() API.

Parameters
• base – The base pointer to a structure describing registers.

• counters – OR of all counters to disable. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

• waitUs – The function waits for some delay in microseconds before returning, because the counter stops counting after two lf_clk cycles pass. The recommended value is 93 us.

__STATIC_INLINE uint32_t Cy_MCWDT_GetEnabledStatus (MCWDT_STRUCT_Type const *base, cy_en_mcwdtctr_t counter)

Reports the enabled status of the specified counter.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the MCWDT counter. The valid range is [0-2].

Returns

The status of the MCWDT counter: 0 = disabled, 1 = enabled.

__STATIC_INLINE void Cy_MCWDT_Lock (MCWDT_STRUCT_Type *base)

Locks out configuration changes to all MCWDT registers.

Parameters

base – The base pointer to a structure that describes registers.

__STATIC_INLINE void Cy_MCWDT_Unlock (MCWDT_STRUCT_Type *base)

Unlocks the MCWDT configuration registers.

Parameters

base – The base pointer to a structure that describes registers.

__STATIC_INLINE uint32_t Cy_MCWDT_GetLockedStatus (MCWDT_STRUCT_Type const *base)

Reports the locked/unlocked state of the MCWDT.

Parameters

base – The base pointer to a structure that describes registers.

Returns

The state of the MCWDT counter: 0 = unlocked, 1 = locked.

__STATIC_INLINE void Cy_MCWDT_SetMode (MCWDT_STRUCT_Type *base, cy_en_mcwdtctr_t counter, cy_en_mcwdtmode_t mode)

Sets the mode of the specified counter.

note

The mode for Counter 2 can be set only to CY_MCWDT_MODE_NONE or CY_MCWDT_MODE_INT.

note

This API must not be called while the counters are running. Prior to calling this API, the counter must be disabled.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-2].

• mode – The mode of operation for the counter. See enum typedef cy_en_mcwdtmode_t.

__STATIC_INLINE cy_en_mcwdtmode_t Cy_MCWDT_GetMode (MCWDT_STRUCT_Type const *base, cy_en_mcwdtctr_t counter)

Reports the mode of the specified counter.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-2].

Returns

The current mode of the counter. See enum typedef cy_en_mcwdtmode_t.

__STATIC_INLINE void Cy_MCWDT_SetClearOnMatch (MCWDT_STRUCT_Type *base, cy_en_mcwdtctr_t counter, uint32_t enable)

Sets the Clear on match option for the specified counter.

note

The match values are not supported by Counter 2.

note

This API must not be called while the counters are running. Prior to calling this API, the counter must be disabled.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-1].

• enable – Set 0 to disable; 1 to enable.

__STATIC_INLINE uint32_t Cy_MCWDT_GetClearOnMatch (MCWDT_STRUCT_Type const *base, cy_en_mcwdtctr_t counter)

Reports the Clear on match setting for the specified counter.

note

The match value is not supported by Counter 2.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-1].

Returns

The Clear on match status: 1 = enabled, 0 = disabled.

__STATIC_INLINE void Cy_MCWDT_SetCascade (MCWDT_STRUCT_Type *base, cy_en_mcwdtcascade_t cascade)

Sets all the counter cascade options.

note

This API must not be called when the counters are running. Prior to calling this API, the counter must be disabled.

Parameters
• base – The base pointer to a structure that describes registers.

__STATIC_INLINE cy_en_mcwdtcascade_t Cy_MCWDT_GetCascade (MCWDT_STRUCT_Type const *base)

Reports all the counter cascade option settings.

Parameters

base – The base pointer to a structure that describes registers.

Returns

__STATIC_INLINE void Cy_MCWDT_SetMatch (MCWDT_STRUCT_Type *base, cy_en_mcwdtctr_t counter, uint32_t match, uint16_t waitUs)

Sets the match comparison value for the specified counter (0 or 1).

note

The match value is not supported by Counter 2.

note

Action on match is taken on the next increment after the counter value equal to match value.

note

Setting this parameter to a zero means No wait. This must be taken into account when changing the match values on the running counters.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-1].

• match – The value to match against the counter. The valid range is [0-65535] for c0ClearOnMatch (or c1ClearOnMatch) = 0 and [1-65535] for c0ClearOnMatch (or c1ClearOnMatch) = 1.

• waitUs – The function waits for some delay in microseconds before returning, because the match affects after two lf_clk cycles pass. The recommended value is 93 us.

__STATIC_INLINE uint32_t Cy_MCWDT_GetMatch (MCWDT_STRUCT_Type const *base, cy_en_mcwdtctr_t counter)

Reports the match comparison value for the specified counter (0 or 1).

note

The match values are not supported by Counter 2.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-1].

Returns

A 16-bit match value.

__STATIC_INLINE void Cy_MCWDT_SetToggleBit (MCWDT_STRUCT_Type *base, uint32_t bit)

Sets a bit in Counter 2 to monitor for a toggle.

note

This API must not be called when counters are running. Prior to calling this API, the counter must be disabled.

Parameters
• base – The base pointer to a structure that describes registers.

• bit – The Counter 2 bit is set to monitor for a toggle. The valid range [0-31].

__STATIC_INLINE uint32_t Cy_MCWDT_GetToggleBit (MCWDT_STRUCT_Type const *base)

Reports which bit in Counter 2 is monitored for a toggle.

Parameters

base – The base pointer to a structure that describes registers.

Returns

The bit that is monitored (range 0 to 31).

__STATIC_INLINE uint32_t Cy_MCWDT_GetCount (MCWDT_STRUCT_Type const *base, cy_en_mcwdtctr_t counter)

Reports the current counter value of the specified counter.

Parameters
• base – The base pointer to a structure that describes registers.

• counter – The number of the WDT counter. The valid range is [0-2].

Returns

A live counter value. Counters 0 and 1 are 16-bit counters and Counter 2 is a 32-bit counter.

__STATIC_INLINE void Cy_MCWDT_ResetCounters (MCWDT_STRUCT_Type *base, uint32_t counters, uint16_t waitUs)

Resets all specified counters.

note

This function resets the counters two times to prevent the case when the Counter 1 is not reset when the counters are cascaded. The delay waitUs must be greater than 100 us when the counters are cascaded. The total delay is greater than 2*waitUs because the function has the delay after the first reset.

note

Setting this parameter to a zero means No wait. In this case, it is the user's responsibility to check whether the selected counters were reset immediately after the function call. This can be done by the Cy_MCWDT_GetCount() API.

Parameters
• base – The base pointer to a structure that describes registers.

• counters – OR of all counters to reset. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

• waitUs – The function waits for some delay in microseconds before returning, because a reset occurs after one lf_clk cycle passes. The recommended value is 62 us.

__STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptStatus (MCWDT_STRUCT_Type const *base)

Reports the state of all MCWDT interrupts.

Parameters

base – The base pointer to a structure that describes registers.

Returns

The OR’d state of the interrupts. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

__STATIC_INLINE void Cy_MCWDT_ClearInterrupt (MCWDT_STRUCT_Type *base, uint32_t counters)

Clears all specified MCWDT interrupts.

All the WDT interrupts must be cleared by the firmware; otherwise interrupts are generated continuously.

Parameters
• base – The base pointer to a structure describes registers.

• counters – OR of all interrupt sources to clear. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

__STATIC_INLINE void Cy_MCWDT_SetInterrupt (MCWDT_STRUCT_Type *base, uint32_t counters)

Sets MCWDT interrupt sources in the interrupt request register.

Parameters
• base – The base pointer to a structure that describes registers.

• counters – OR of all interrupt sources to set. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

__STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptMask (MCWDT_STRUCT_Type const *base)

Returns the CWDT interrupt mask register.

This register specifies which bits from the MCWDT interrupt request register will trigger an interrupt event.

Parameters

base – The base pointer to a structure that describes registers.

Returns

The OR’d state of the interrupt masks. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

__STATIC_INLINE void Cy_MCWDT_SetInterruptMask (MCWDT_STRUCT_Type *base, uint32_t counters)

This register configures which bits from MCWDT interrupt request register will trigger an interrupt event.

Parameters
• base – The base pointer to a structure that describes registers.

• counters – OR of all interrupt masks to set. See CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

__STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptStatusMasked (MCWDT_STRUCT_Type const *base)

Returns the MCWDT interrupt masked request register.

This register contains the logical AND of corresponding bits from the MCWDT interrupt request and mask registers. In the interrupt service routine, this function identifies which of the enabled MCWDT interrupt sources caused an interrupt event.

Parameters

base – The base pointer to a structure that describes registers.

Returns

The current status of enabled MCWDT interrupt sources. See the CY_MCWDT_CTR0, CY_MCWDT_CTR1, and CY_MCWDT_CTR2 macros.

uint32_t Cy_MCWDT_GetCountCascaded(MCWDT_STRUCT_Type const *base)

Reports the current value of combined C1-C0 cascaded counters.

note

The user must enable both counters, and cascade C0 to C1, before calling this function. C2 is not reported. Instead, to get a 64-bit C2-C1-C0 cascaded value, the user must call this function followed by Cy_MCWDT_GetCount(base, CY_MCWDT_COUNTER2), and then combine the results.

note

This function does not return the correct result when it is called after the Cy_MCWDT_Enable() or Cy_MCWDT_ResetCounters() function with a delay less than two lf_clk cycles. The recommended waitUs parameter value is 100 us.

Parameters

base – The base pointer to a structure that describes the registers.

Returns

The value of combined C1-C0 cascaded counters.

struct cy_stc_mcwdt_config_t
#include <>

The MCWDT component configuration structure.

Public Members

uint16_t c0Match

The sub-counter#0 match comparison value, for interrupt or watchdog timeout.

Range: 0 - 65535 for c0ClearOnMatch = 0 and 1 - 65535 for c0ClearOnMatch = 1.

uint16_t c1Match

The sub-counter#1 match comparison value, for interrupt or watchdog timeout.

Range: 0 - 65535 for c1ClearOnMatch = 0 and 1 - 65535 for c1ClearOnMatch = 1.

uint8_t c0Mode

The sub-counter#0 mode.

It can have the following values: CY_MCWDT_MODE_NONE, CY_MCWDT_MODE_INT, CY_MCWDT_MODE_RESET and CY_MCWDT_MODE_INT_RESET.

uint8_t c1Mode

The sub-counter#1 mode.

It can have the following values: CY_MCWDT_MODE_NONE, CY_MCWDT_MODE_INT, CY_MCWDT_MODE_RESET and CY_MCWDT_MODE_INT_RESET.

uint8_t c2ToggleBit

The sub-counter#2 Period / Toggle Bit value.

Range: 0 - 31.

uint8_t c2Mode

The sub-counter#2 mode.

It can have the following values: CY_MCWDT_MODE_NONE and CY_MCWDT_MODE_INT.

bool c0ClearOnMatch

The sub-counter#0 Clear On Match parameter enabled/disabled.

note

This parameter is available for devices having MXS40SSRSS IP.

bool c1ClearOnMatch

The sub-counter#1 Clear On Match parameter enabled/disabled.

bool c0c1Cascade

The sub-counter#1 is clocked by LFCLK or from sub-counter#0 cascade.

bool c1c2Cascade

The sub-counter#2 is clocked by LFCLK or from sub-counter#1 cascade.