Drivers

C2000Ware supports multiple ways of accessing peripheral registers - direct register access, driver library (DriverLib), and bitfields. Details of these are mentioned in the sections below. DriverLib is the preferred model of accessing peripherals for the new generation MCUs. Only Bitfield is supported in the older generation of MCUs. But Bitfield is supported in the new generation MCUs also for compatibility and easy migration.

Fig. 3 shows the comparison between DriverLib and Bitfield.

../_images/RegAccess.png

Fig. 3 DriverLib, Bit field and direct regiser access

Differences are summarized below:

  • Direct register access

    • Register address #define individually

    • User must compute bit-field masks

    • Not easy to read

    • eg. *CMPR1 = 0x1234;

  • Bit field header files

    • Header files define all registers as structures

    • Bit fields directly accessible

    • Easy to read

    • eg. EPwm1Regs.CMPA.bit.CMPA = EPwm1Regs.TBPRD * duty;

  • DriverLib

    • DriverLib performs low-level register manipulation

    • Easy to read

    • Highest abstraction level

    • eg. EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, duty);

DriverLib

The C2000 Peripheral Driver Library (Driverlib) is a set of low-level drivers for configuring memory mapped peripheral registers. It provides drivers for all peripherals and provides access to almost all functionality. The driverlib is written in C language and comprises of data structures, macro definitions and functions. Full source code for driverlib is provided within C2000Ware.

At the top-level, driverlib is organized based on devices and there is a device specific driverlib folder under each device. Within this device specific driverlib folder, source code for peripheral drivers applicable to that device is provided.

../_images/C2000WareDriver.png

The source code and header files for the driverlib are located in the driverlib folder. The header (.h files) contain:

  • #defines – usually meant to be used for parameters

  • typedefs – both struct and enum, usually meant to be used for parameters

  • static inline functions – all relatively short functions are inlined for performance

  • extern function prototypes

The implementation (.c files) contains the implementations of the extern functions. Peripheral drivers make use of a hardware header file to obtain information on register definitions for peripherals. These hardware headers are provided in driverlib/inc folder and in most cases there is one header file per peripheral. There is a CCS project provided to build the driverlib library under the driverlib/ccs folder.

Bitfield

Using register files and bitfields is another approach to access hardware or peripheral registers. This approach was used to access peripherals and write applications in controlSUITE. Starting with C2000Ware, the recommended approach to access peripherals is using driverlibs. However, to assist in a smooth transition from bitfield to driverlib, bitfield software continues to be packaged as part of C2000Ware.

../_images/C2000WareBitfield.png

The bitfield source code is organized within the device_support folder within C2000Ware. Under device_support, there are device specific folders which contain the bitfield headers, common code used for initializations and examples for each peripheral. Users can refer to application report SPRAAA85E to get further details on the driverlib and bitfield implementation and how these approaches can be leveraged in building applications.