XMC Low Level Driver (LLD) 2015-03 TTA Training Luo Samuel (IFCN ATV IMM) Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 2 Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 3 Overview set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 4 Overview XMC Lib consists of low-level drivers for the XMC product family peripherals Collection of routines and data structures which covers all peripheral functions Built on top of Cortex Microcontroller Software Interface Standard (CMSIS) Tool chain support: GNU GCC Keil MDK IAR Embedded Workbench for ARM set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 5 Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 6 Architecture Application code Middleware DAVETM APPs XMClib DEVICE HEADER FILES CMSIS-CORE CMSIS-DSP Hardware set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 7 LLD coverage XMC4k XMC1k All peripheral covered set date CAN DAC ERU HRPWM RTC UART WDT XMC4k CCU4 CCU8 DMA DSD ETH FCE I2C LEDTS SCU SDMMC USB USIC FLASH CMP CCU8 LEDTS PRNG UART XMC1k VADC BCCU ERU GPIO MATH PAU RTC SCU USIC WDT COMMON EBU GPIO POSIF SPI VADC CCU4 I2C POSIF SPI FLASH Copyright © Infineon Technologies AG 2014. All rights reserved. Page 8 Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 9 Package Description inc folder contains peripheral API header files xmc_common.h: common functionality and definitions xmc_device.h: device selection xmc_<peripheral>.h (one header file per peripheral): Function prototypes, data structures and enumeration xmc<family>_<peripheral>.h (optional): Family extensions src folder contains peripheral API implementation xmc_common.c: common functionality and definitions xmc_<peripheral>.c: Implementation of common peripheral functionality xmc<family>_<peripheral>.c (optional): Family specific implementation doc folder contains API documentation generated from sources examples folder contains extensive set of examples projects for different toolchains set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 10 Package Description User application common API family specific API implementation xmc_usic.c xmc1_usic.c xmc1_usic.h xmc_usic.h Connectivity device specific macros xmc1_usic_map.h family extensions xmc_common.h xmc_device.h stdint.h stdbool.h stddef.h XMC1300.h core_cm0.h set date system_XMC1300.h Copyright © Infineon Technologies AG 2014. All rights reserved. Page 11 LLD Example Macro Enum API set date Struct Copyright © Infineon Technologies AG 2014. All rights reserved. Page 12 Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 13 Coding rules and conventions C99, in addtion unions and bitfields are used for more compact code and data section. Use only standard data types Use enumerations Naming convention: Variables use only lower case,underscore separated words. Functions use CamelCase convention. Non blocking APIs. Runtime error checking can be enabled by user XMC_ASSERT() used to check input parameters of functions, result of calculations, … XMC_DEBUG() used to monitor status of application set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 14 Coding rules and conventions Object = attributes + methods Attributes are the peripheral data struct. Methods are functions that take a pointer to the peripheral data struct as the first argument. XMC Lib uses naming conventions to bind the data struct and the functions that operate on it XMC_PERI_DoSomething(XMC_PERI_t const *peri, …); set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 15 Peripheral namespace Each driver defines its own “namespace”, XMC_PERI Macro Enum Struct API set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 16 Peripheral namespace Macro parameters to define some gloable parameters #define XMC_CCU8_CHECK_MODULE_PTR(PTR) ( ((PTR)== CCU80) ) set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 17 Peripheral namespace Enum to represent different value of single section of a register. enum XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_NONE= 0U XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_FALLING_EDGE XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_DUAL_EDGE 0 1 2 3 0 1 2 3 set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 18 Peripheral namespace Struct to represent register for a function struct XMC_CCU8_SLICE_CAPTURE_CONFIG { union { struct { uint32_t : 4; uint32_t fifo_enable : 1; uint32_t timer_clear_mode : 2; uint32_t : 4; uint32_t same_event : 1; uint32_t ignore_full_flag : 1; uint32_t : 3; uint32_t prescaler_mode: 1; uint32_t : 15; }; uint32_t tc; }; uint32_t prescaler_initval : 4; …… set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 19 Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 20 XMC Lib APIs Common APIs Other APIs Config Control Get/setters Event handling set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 21 Common APIs Each driver has an API to get at runtime the driver version XMC_DRIVER_VERSION_t XMC_PERI_GetDriverVersion(void); Each driver has an initialization function XMC_PERI_STATUS_t XMC_PERI_Init(XMC_PERI_t const *peri, const XMC_PERI_CONFIG_t const *config); Most drivers have enable/disable function void XMC_PERI_Enable(XMC_PERI_t const *peri); void XMC_PERI_Disable(XMC_PERI_t const *peri); set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 22 XMC Lib APIs Config registers or control peripherals void XMC_CCU8_SetModuleClock (XMC_CCU8_MODULE_t *const module, const XMC_CCU8_CLOCK_t clock) set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 23 XMC Lib APIs Control void XMC_PERI_Start(XMC_PERI_t const *peri); Get/setters (run time API to get or modify state of peripheral) void XMC_PERI_SetSomething(XMC_PERI_t const *peri, …) uint32_t XMC_PERI_GetSomething(XMC_PERI_t const *peri, …) set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 24 XMC Lib APIs Event handling XMC_CCU8_SLICE_SetEvent() XMC_CCU8_SLICE_ClearEvent() XMC_CCU8_SLICE_EnableEvent() XMC_CCU8_SLICE_DisableEvent() XMC_CCU8_SLICE_SetInterruptNode() set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 25 Agenda Overview Architecture Package description Coding rules and conventions XMC Lib APIs How to use the library set date Copyright © Infineon Technologies AG 2014. All rights reserved. Page 26 How to use the library Peripheral configuration and initialization Connectivity configuration Event/interrupt configuration Start operation IO configuration #include <xmc_gpio.h> #include <xmc_i2c.h> … int main(void) { XMC_I2C_CH_CONFIG_t i2c_cfg; 1 i2c_cfg.baudrate = 400000U; XMC_I2C_CH_Init(XMC_I2C0_CH0, &i2c_cfg); XMC_I2C_CH_SetInputSource(XMC_I2C0_CH0, XMC_I2C_CH_INPUT_SDA, USIC1_C0_DX0_P2_14); XMC_I2C_CH_SetInputSource(XMC_I2C0_CH0, XMC_I2C_CH_INPUT_SCL, USIC1_C0_DX1_P5_8); XMC_I2C_CH_EnableEvent(XMC_I2C0_CH0, XMC_I2C_CH_EVENT_ARBITRATION_LOST); NVIC_SetPriority(USIC0_0_IRQn, 63U); NVIC_EnableIRQ(USIC0_0_IRQn); XMC_I2C_CH_Start(XMC_I2C0_CH0); 3 4 XMC_GPIO_SetMode(P1_5, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | P1_5_AF_U0C0_DOUT0); XMC_GPIO_SetMode(P1_1, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | P1_1_AF_U0C0_SCLKOUT); set date … 2 Copyright © Infineon Technologies AG 2014. All rights reserved. 5 Page 27