Skip to content

XPD Utilities

IntergatedCircuits edited this page Sep 18, 2018 · 7 revisions

The utilities package is a common tool-set which is used by the individual peripheral drivers internally. These features are available on all targets, and can be called from user code as well.

System timing

Peripheral management requires a time base for polling operations (when further code execution requires a non-instantaneous status change to occur beforehand). The XPD drivers use the XPD_eWaitForDiff() and XPD_eWaitForMatch() functions, which return only when the masked register status satisfies the expected outcome, or when the available time budget expires. These utilities also include fixed execution delay of microsecond and millisecond value: XPD_vDelay_us(), XPD_vDelay_ms().

Use of SysTick

The XPD utilities use the SysTick timer of the Cortex M core to achieve a millisecond-based time-limited polling feature. The timer is configured for 1 ms counter update interval each time HCLK changes. The polling services use the COUNTFLAG bit of the timer's Control and Status Register (CTRL), which is set when the counter is updated and is reset when the CTRL register is read. Therefore a polling function can easily keep track of elapsed milliseconds by simply adding up the consecutive COUNTFLAG bit values continuously.

This method works context-independently (in interrupt handlers as well as in thread mode), leaves the possibility of implementing a user-defined SysTick_Handler(), and itself does not generate interrupts that would wake up a system from low-power mode. However, if these services are used in more than one context concurrently, then the passage of time would be interpreted as slower than real. Therefore in OS environment it is highly recommended to override these function implementations.

Overriding the time service functions

The time service can be replaced during runtime to any implementation of XPD_TimeServiceType by calling the XPD_vSetTimeService() function. From that point onward, all blocking calls from XPD (with ms resolution) will be redirected to the newly set functions. To reset the XPD default solution with the SysTick, call XPD_vResetTimeService().

Stream handling

Many peripherals handle a continuous flow of data, for example between a communication medium and an application. A data stream is an XPD-managed object with a defined data item size, a remaining transfer length and a pointer to the next data element in the application memory. The utility functions provide a generic service to read and write a peripheral register with the current data element, and to update the stream's attributes after the transfer has been complete.

XPD domain initialization and reset

During software startup it is important to put the system in a known state. The XPD initialization functions provide a simple interface to reset the peripherals to an initial state and initialization for the XPD utilities that the peripheral drivers rely on.