diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.c b/targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.c new file mode 100644 index 0000000..488150e --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.c @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "device.h" +#include "PeripheralPins.h" +#include "ioman_regs.h" +#include "ioman.h" +#include "adc.h" + +/* + * To select a peripheral function on Maxim microcontrollers, multiple + * configurations must be made. The mbed PinMap structure only includes one + * data member to hold this information. To extend the configuration storage, + * the "function" data member is used as a pointer to a pin_function_t + * structure. This structure is defined in objects.h. The definitions below + * include the creation of the pin_function_t structures and the assignment of + * the pointers to the "function" data members. + */ + +#ifdef TOOLCHAIN_ARM_STD +#pragma diag_suppress 1296 +#endif + +/************I2C***************/ +const PinMap PinMap_I2C_SDA[] = { + { P1_6, I2C_0, (int)&((pin_function_t){&MXC_IOMAN->i2cm0_req, &MXC_IOMAN->i2cm0_ack, MXC_F_IOMAN_I2CM0_REQ_MAPPING_REQ, MXC_F_IOMAN_I2CM0_ACK_MAPPING_ACK}) }, + { P3_4, I2C_1, (int)&((pin_function_t){&MXC_IOMAN->i2cm1_req, &MXC_IOMAN->i2cm1_ack, MXC_F_IOMAN_I2CM1_REQ_MAPPING_REQ, MXC_F_IOMAN_I2CM1_ACK_MAPPING_ACK}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_I2C_SCL[] = { + { P1_7, I2C_0, (int)&((pin_function_t){&MXC_IOMAN->i2cm0_req, &MXC_IOMAN->i2cm0_ack, MXC_F_IOMAN_I2CM0_REQ_MAPPING_REQ, MXC_F_IOMAN_I2CM0_ACK_MAPPING_ACK}) }, + { P3_5, I2C_1, (int)&((pin_function_t){&MXC_IOMAN->i2cm1_req, &MXC_IOMAN->i2cm1_ack, MXC_F_IOMAN_I2CM1_REQ_MAPPING_REQ, MXC_F_IOMAN_I2CM1_ACK_MAPPING_ACK}) }, + { NC, NC, 0 } +}; + +/************UART***************/ +const PinMap PinMap_UART_TX[] = { + { P0_1, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART0_REQ_IO_REQ), (MXC_F_IOMAN_UART0_ACK_IO_MAP | MXC_F_IOMAN_UART0_ACK_IO_ACK)}) }, + { P2_1, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART1_REQ_IO_REQ), (MXC_F_IOMAN_UART1_ACK_IO_MAP | MXC_F_IOMAN_UART1_ACK_IO_ACK)}) }, + { P3_1, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART2_REQ_IO_REQ), (MXC_F_IOMAN_UART2_ACK_IO_MAP | MXC_F_IOMAN_UART2_ACK_IO_ACK)}) }, + { P0_0, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART0_REQ_IO_REQ), (MXC_F_IOMAN_UART0_ACK_IO_MAP | MXC_F_IOMAN_UART0_ACK_IO_ACK)}) }, + { P2_0, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART1_REQ_IO_REQ), (MXC_F_IOMAN_UART1_ACK_IO_MAP | MXC_F_IOMAN_UART1_ACK_IO_ACK)}) }, + { P3_0, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART2_REQ_IO_REQ), (MXC_F_IOMAN_UART2_ACK_IO_MAP | MXC_F_IOMAN_UART2_ACK_IO_ACK)}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_UART_RX[] = { + { P0_0, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART0_REQ_IO_REQ), (MXC_F_IOMAN_UART0_ACK_IO_MAP | MXC_F_IOMAN_UART0_ACK_IO_ACK)}) }, + { P2_0, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART1_REQ_IO_REQ), (MXC_F_IOMAN_UART1_ACK_IO_MAP | MXC_F_IOMAN_UART1_ACK_IO_ACK)}) }, + { P3_0, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART2_REQ_IO_REQ), (MXC_F_IOMAN_UART2_ACK_IO_MAP | MXC_F_IOMAN_UART2_ACK_IO_ACK)}) }, + { P0_1, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART0_REQ_IO_REQ), (MXC_F_IOMAN_UART0_ACK_IO_MAP | MXC_F_IOMAN_UART0_ACK_IO_ACK)}) }, + { P2_1, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART1_REQ_IO_REQ), (MXC_F_IOMAN_UART1_ACK_IO_MAP | MXC_F_IOMAN_UART1_ACK_IO_ACK)}) }, + { P3_1, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART2_REQ_IO_REQ), (MXC_F_IOMAN_UART2_ACK_IO_MAP | MXC_F_IOMAN_UART2_ACK_IO_ACK)}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_UART_CTS[] = { + { P0_2, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ), (MXC_F_IOMAN_UART0_ACK_CTS_MAP | MXC_F_IOMAN_UART0_ACK_CTS_IO_ACK)}) }, + { P2_2, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART1_REQ_CTS_IO_REQ), (MXC_F_IOMAN_UART1_ACK_CTS_MAP | MXC_F_IOMAN_UART1_ACK_CTS_IO_ACK)}) }, + { P3_2, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART2_REQ_CTS_IO_REQ), (MXC_F_IOMAN_UART2_ACK_CTS_MAP | MXC_F_IOMAN_UART2_ACK_CTS_IO_ACK)}) }, + { P0_3, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ), (MXC_F_IOMAN_UART0_ACK_CTS_MAP | MXC_F_IOMAN_UART0_ACK_CTS_IO_ACK)}) }, + { P2_3, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART1_REQ_CTS_IO_REQ), (MXC_F_IOMAN_UART1_ACK_CTS_MAP | MXC_F_IOMAN_UART1_ACK_CTS_IO_ACK)}) }, + { P3_3, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART2_REQ_CTS_IO_REQ), (MXC_F_IOMAN_UART2_ACK_CTS_MAP | MXC_F_IOMAN_UART2_ACK_CTS_IO_ACK)}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_UART_RTS[] = { + { P0_3, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ), (MXC_F_IOMAN_UART0_ACK_RTS_MAP | MXC_F_IOMAN_UART0_ACK_RTS_IO_ACK)}) }, + { P2_3, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART1_REQ_RTS_IO_REQ), (MXC_F_IOMAN_UART1_ACK_RTS_MAP | MXC_F_IOMAN_UART1_ACK_RTS_IO_ACK)}) }, + { P3_3, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_A | MXC_F_IOMAN_UART2_REQ_RTS_IO_REQ), (MXC_F_IOMAN_UART2_ACK_RTS_MAP | MXC_F_IOMAN_UART2_ACK_RTS_IO_ACK)}) }, + { P0_2, UART_0, (int)&((pin_function_t){&MXC_IOMAN->uart0_req, &MXC_IOMAN->uart0_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ), (MXC_F_IOMAN_UART0_ACK_RTS_MAP | MXC_F_IOMAN_UART0_ACK_RTS_IO_ACK)}) }, + { P2_2, UART_1, (int)&((pin_function_t){&MXC_IOMAN->uart1_req, &MXC_IOMAN->uart1_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART1_REQ_RTS_IO_REQ), (MXC_F_IOMAN_UART1_ACK_RTS_MAP | MXC_F_IOMAN_UART1_ACK_RTS_IO_ACK)}) }, + { P3_2, UART_2, (int)&((pin_function_t){&MXC_IOMAN->uart2_req, &MXC_IOMAN->uart2_ack, ((uint32_t)IOMAN_MAP_B | MXC_F_IOMAN_UART2_REQ_RTS_IO_REQ), (MXC_F_IOMAN_UART2_ACK_RTS_MAP | MXC_F_IOMAN_UART2_ACK_RTS_IO_ACK)}) }, + { NC, NC, 0 } +}; + +/************SPI***************/ +const PinMap PinMap_SPI_SCLK[] = { + { P0_4, SPI_0, (int)&((pin_function_t){&MXC_IOMAN->spim0_req, &MXC_IOMAN->spim0_ack, MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK}) }, + { P1_0, SPI_1, (int)&((pin_function_t){&MXC_IOMAN->spim1_req, &MXC_IOMAN->spim1_ack, MXC_F_IOMAN_SPIM1_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM1_ACK_CORE_IO_ACK}) }, + { P2_4, SPI_2, (int)&((pin_function_t){&MXC_IOMAN->spim2_req, &MXC_IOMAN->spim2_ack, MXC_F_IOMAN_SPIM2_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM2_ACK_CORE_IO_ACK}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_SPI_MOSI[] = { + { P0_5, SPI_0, (int)&((pin_function_t){&MXC_IOMAN->spim0_req, &MXC_IOMAN->spim0_ack, MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK}) }, + { P1_1, SPI_1, (int)&((pin_function_t){&MXC_IOMAN->spim1_req, &MXC_IOMAN->spim1_ack, MXC_F_IOMAN_SPIM1_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM1_ACK_CORE_IO_ACK}) }, + { P2_5, SPI_2, (int)&((pin_function_t){&MXC_IOMAN->spim2_req, &MXC_IOMAN->spim2_ack, MXC_F_IOMAN_SPIM2_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM2_ACK_CORE_IO_ACK}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_SPI_MISO[] = { + { P0_6, SPI_0, (int)&((pin_function_t){&MXC_IOMAN->spim0_req, &MXC_IOMAN->spim0_ack, MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK}) }, + { P1_2, SPI_1, (int)&((pin_function_t){&MXC_IOMAN->spim1_req, &MXC_IOMAN->spim1_ack, MXC_F_IOMAN_SPIM1_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM1_ACK_CORE_IO_ACK}) }, + { P2_6, SPI_2, (int)&((pin_function_t){&MXC_IOMAN->spim2_req, &MXC_IOMAN->spim2_ack, MXC_F_IOMAN_SPIM2_REQ_CORE_IO_REQ, MXC_F_IOMAN_SPIM2_ACK_CORE_IO_ACK}) }, + { NC, NC, 0 } +}; + +const PinMap PinMap_SPI_SSEL[] = { + { P0_7, SPI_0, (int)&((pin_function_t){&MXC_IOMAN->spim0_req, &MXC_IOMAN->spim0_ack, MXC_F_IOMAN_SPIM0_REQ_SS0_IO_REQ, MXC_F_IOMAN_SPIM0_ACK_SS0_IO_ACK}) }, + { P1_3, SPI_1, (int)&((pin_function_t){&MXC_IOMAN->spim1_req, &MXC_IOMAN->spim1_ack, MXC_F_IOMAN_SPIM1_REQ_SS0_IO_REQ, MXC_F_IOMAN_SPIM1_ACK_SS0_IO_ACK}) }, + { P2_7, SPI_2, (int)&((pin_function_t){&MXC_IOMAN->spim2_req, &MXC_IOMAN->spim2_ack, MXC_F_IOMAN_SPIM2_REQ_SS0_IO_REQ, MXC_F_IOMAN_SPIM2_ACK_SS0_IO_ACK}) }, + { NC, NC, 0 } +}; + +/************PWM***************/ +const PinMap PinMap_PWM[] = { + { P0_0, PWM_0, 1 }, { P2_0, PWM_0, 1 }, { P4_0, PWM_0, 1 }, + { P0_1, PWM_1, 1 }, { P2_1, PWM_1, 1 }, { P4_1, PWM_1, 1 }, + { P0_2, PWM_2, 1 }, { P2_2, PWM_2, 1 }, { P4_2, PWM_2, 1 }, + { P0_3, PWM_3, 1 }, { P2_3, PWM_3, 1 }, { P4_3, PWM_3, 1 }, + { P0_4, PWM_4, 1 }, { P2_4, PWM_4, 1 }, { P4_4, PWM_4, 1 }, + { P0_5, PWM_5, 1 }, { P2_5, PWM_5, 1 }, { P4_5, PWM_5, 1 }, + { P0_6, PWM_6, 1 }, { P2_6, PWM_6, 1 }, { P4_6, PWM_6, 1 }, + { P0_7, PWM_7, 1 }, { P2_7, PWM_7, 1 }, { P4_7, PWM_7, 1 }, + { P1_0, PWM_8, 1 }, { P3_0, PWM_8, 1 }, + { P1_1, PWM_9, 1 }, { P3_1, PWM_9, 1 }, + { P1_2, PWM_10, 1 }, { P3_2, PWM_10, 1 }, + { P1_3, PWM_11, 1 }, { P3_3, PWM_11, 1 }, + { P1_4, PWM_12, 1 }, { P3_4, PWM_12, 1 }, + { P1_5, PWM_13, 1 }, { P3_5, PWM_13, 1 }, + { P1_6, PWM_14, 1 }, { P3_6, PWM_14, 1 }, + { P1_7, PWM_15, 1 }, { P3_7, PWM_15, 1 }, + { NC, NC, 0 } +}; + +/************ADC***************/ +const PinMap PinMap_ADC[] = { + { AIN_0, ADC, ADC_CH_0 }, + { AIN_1, ADC, ADC_CH_1 }, + { AIN_2, ADC, ADC_CH_2 }, + { AIN_3, ADC, ADC_CH_3 }, + { AIN_4, ADC, ADC_CH_0_DIV_5 }, + { AIN_5, ADC, ADC_CH_1_DIV_5 }, + { NC, NC, 0 } +}; + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.h b/targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.h new file mode 100644 index 0000000..66b40c1 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_PERIPHERALPINS_H +#define MBED_PERIPHERALPINS_H + +#include "pinmap.h" + +//************I2C*************** +extern const PinMap PinMap_I2C_SDA[]; +extern const PinMap PinMap_I2C_SCL[]; + +//************UART*************** +extern const PinMap PinMap_UART_TX[]; +extern const PinMap PinMap_UART_RX[]; +extern const PinMap PinMap_UART_CTS[]; +extern const PinMap PinMap_UART_RTS[]; + +//************SPI*************** +extern const PinMap PinMap_SPI_SCLK[]; +extern const PinMap PinMap_SPI_MOSI[]; +extern const PinMap PinMap_SPI_MISO[]; +extern const PinMap PinMap_SPI_SSEL[]; + +//************PWM*************** +extern const PinMap PinMap_PWM[]; + +//************ADC*************** +extern const PinMap PinMap_ADC[]; +#endif + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/PortNames.h b/targets/TARGET_Maxim/TARGET_MAX32625/PortNames.h new file mode 100644 index 0000000..ebd8e97 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/PortNames.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_PORTNAMES_H +#define MBED_PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + Port0 = 0, + Port1 = 1, + Port2 = 2, + Port3 = 3, + Port4 = 4, +} PortName; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PeripheralNames.h b/targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PeripheralNames.h new file mode 100644 index 0000000..4686ef9 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PeripheralNames.h @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_PERIPHERALNAMES_H +#define MBED_PERIPHERALNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + UART_0 = MXC_BASE_UART0, + UART_1 = MXC_BASE_UART1, + UART_2 = MXC_BASE_UART2, + STDIO_UART = UART_1 +} UARTName; + +typedef enum { + I2C_0 = MXC_BASE_I2CM0, + I2C_1 = MXC_BASE_I2CM1 +} I2CName; + +typedef enum { + SPI_0 = MXC_BASE_SPIM0, + SPI_1 = MXC_BASE_SPIM1, + SPI_2 = MXC_BASE_SPIM2 +} SPIName; + +typedef enum { + PWM_0 = MXC_BASE_PT0, + PWM_1 = MXC_BASE_PT1, + PWM_2 = MXC_BASE_PT2, + PWM_3 = MXC_BASE_PT3, + PWM_4 = MXC_BASE_PT4, + PWM_5 = MXC_BASE_PT5, + PWM_6 = MXC_BASE_PT6, + PWM_7 = MXC_BASE_PT7, + PWM_8 = MXC_BASE_PT8, + PWM_9 = MXC_BASE_PT9, + PWM_10 = MXC_BASE_PT10, + PWM_11 = MXC_BASE_PT11, + PWM_12 = MXC_BASE_PT12, + PWM_13 = MXC_BASE_PT13, + PWM_14 = MXC_BASE_PT14, + PWM_15 = MXC_BASE_PT15 +} PWMName; + +typedef enum { + ADC = MXC_BASE_ADC +} ADCName; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PinNames.h b/targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PinNames.h new file mode 100644 index 0000000..9574edf --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PinNames.h @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_PINNAMES_H +#define MBED_PINNAMES_H + +#include "cmsis.h" +#include "gpio_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PIN_INPUT = 0, /* MXC_V_GPIO_OUT_MODE_HIGH_Z,*/ + PIN_OUTPUT = 1 /* MXC_V_GPIO_OUT_MODE_NORMAL_DRIVE */ +} PinDirection; + +#define PORT_SHIFT 12 +#define PINNAME_TO_PORT(name) ((unsigned int)(name) >> PORT_SHIFT) +#define PINNAME_TO_PIN(name) ((unsigned int)(name) & ~(0xFFFFFFFF << PORT_SHIFT)) + +#define NOT_CONNECTED (int)0xFFFFFFFF + +typedef enum { + P0_0 = (0 << PORT_SHIFT), P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7, + P1_0 = (1 << PORT_SHIFT), P1_1, P1_2, P1_3, P1_4, P1_5, P1_6, P1_7, + P2_0 = (2 << PORT_SHIFT), P2_1, P2_2, P2_3, P2_4, P2_5, P2_6, P2_7, + P3_0 = (3 << PORT_SHIFT), P3_1, P3_2, P3_3, P3_4, P3_5, P3_6, P3_7, + P4_0 = (4 << PORT_SHIFT), P4_1, P4_2, P4_3, P4_4, P4_5, P4_6, P4_7, + + // Analog input pins + AIN_0 = (0xA << PORT_SHIFT), AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, + + // LEDs + LED1 = P2_4, + LED2 = P2_5, + LED3 = P2_6, + LED4 = P2_7, + LED_RED = LED1, + LED_GREEN = LED2, + LED_BLUE = LED3, + + // Push button + SW1 = P4_2, + SW2 = P4_3, + SW3 = P4_4, + + // USB bridge connected UART pins + USBTX = P2_1, + USBRX = P2_0, + STDIO_UART_TX = USBTX, + STDIO_UART_RX = USBRX, + + // I2C pins + I2C0_SCL = P1_7, + I2C0_SDA = P1_6, + + I2C1_SCL = P3_5, + I2C1_SDA = P3_4, + + // UART pins + UART0_RX = P0_0, + UART0_TX = P0_1, + UART0_CTS = P0_2, + UART0_RTS = P0_3, + + UART1_RX = P2_0, + UART1_TX = P2_1, + UART1_CTS = P2_2, + UART1_RTS = P2_3, + + UART2_RX = P3_0, + UART2_TX = P3_1, + UART2_CTS = P3_2, + UART2_RTS = P3_3, + + // SPI pins + SPI0_SCK = P0_4, + SPI0_MOSI = P0_5, + SPI0_MISO = P0_6, + SPI0_SS = P0_7, + + SPI1_SCK = P1_0, + SPI1_MOSI = P1_1, + SPI1_MISO = P1_2, + SPI1_SS = P1_3, + + SPI2_SCK = P2_4, + SPI2_MOSI = P2_5, + SPI2_MISO = P2_6, + SPI2_SS = P2_7, + + // Not connected + NC = NOT_CONNECTED +} PinName; + +typedef enum { + PullUp, + PullDown, + OpenDrain, + PullNone, + PullDefault = PullUp +} PinMode; + +typedef enum { + LED_ON = 0, + LED_OFF = 1 +} LedStates; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/analogin_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/analogin_api.c new file mode 100644 index 0000000..2f6d348 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/analogin_api.c @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed_assert.h" +#include "analogin_api.h" +#include "adc.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#define ADC_FULL_SCALE 0x3FFU +#define INT_FULL_SCALE 0xFFFFU +#define FLOAT_FULL_SCALE 1.0f + +static int initialized = 0; + +//****************************************************************************** +void analogin_init(analogin_t *obj, PinName pin) +{ + // Make sure pin is an analog pin we can use for ADC + MBED_ASSERT((ADCName)pinmap_peripheral(pin, PinMap_ADC) != (ADCName)NC); + + // Set the object pointer and channel encoding + obj->adc = MXC_ADC; + obj->channel = pinmap_find_function(pin, PinMap_ADC); + + if (!initialized) { + MBED_ASSERT(ADC_Init() == E_NO_ERROR); + initialized = 1; + } +} + +//****************************************************************************** +float analogin_read(analogin_t *obj) +{ + uint16_t tmp; + float result; + + // Start conversion with no input scaling and no input buffer bypass + ADC_StartConvert(obj->channel, 0, 0); + + if (ADC_GetData(&tmp) == E_OVERFLOW) { + result = FLOAT_FULL_SCALE; + } else { + result = (float)tmp * (FLOAT_FULL_SCALE / (float)ADC_FULL_SCALE); + } + + return result; +} + +//****************************************************************************** +uint16_t analogin_read_u16(analogin_t *obj) +{ + uint16_t tmp; + uint16_t result; + + // Start conversion with no input scaling and no input buffer bypass + ADC_StartConvert(obj->channel, 0, 0); + + if (ADC_GetData(&tmp) == E_OVERFLOW) { + result = INT_FULL_SCALE; + } else { + result = ((tmp << 6) & 0xFFC0) | ((tmp >> 4) & 0x003F); + } + + return result; +} + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device.h b/targets/TARGET_Maxim/TARGET_MAX32625/device.h new file mode 100644 index 0000000..3463dfe --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device.h @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_DEVICE_H +#define MBED_DEVICE_H + +#include "objects.h" + +#endif + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/TARGET_MAX32625NEXPAQ/MAX32625.sct b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/TARGET_MAX32625NEXPAQ/MAX32625.sct new file mode 100644 index 0000000..6ea0cb7 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/TARGET_MAX32625NEXPAQ/MAX32625.sct @@ -0,0 +1,16 @@ +; MAX32625 +; 512KB FLASH (0x70000) @ 0x000010000 +; 160KB RAM (0x24F00) @ 0x20003100 + +LR_IROM1 0x000010000 0x70000 { ; load region size_region + ER_IROM1 0x000010000 0x70000 { ; load address = execution address + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + + ; [RAM] Vector table dynamic copy: 68 vectors * 4 bytes = 272 (0x110) + RW_IRAM1 (0x20003100+0x110) (0x24F00-0x110) { ; RW data + .ANY (+RW +ZI) + } +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/startup_MAX32625.S b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/startup_MAX32625.S new file mode 100644 index 0000000..d89f34b --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/startup_MAX32625.S @@ -0,0 +1,297 @@ +;******************************************************************************* +; Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +; +; Permission is hereby granted, free of charge, to any person obtaining a +; copy of this software and associated documentation files (the "Software"), +; to deal in the Software without restriction, including without limitation +; the rights to use, copy, modify, merge, publish, distribute, sublicense, +; and/or sell copies of the Software, and to permit persons to whom the +; Software is furnished to do so, subject to the following conditions: +; +; The above copyright notice and this permission notice shall be included +; in all copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +; IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +; OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +; OTHER DEALINGS IN THE SOFTWARE. +; +; Except as contained in this notice, the name of Maxim Integrated +; Products, Inc. shall not be used except as stated in the Maxim Integrated +; Products, Inc. Branding Policy. +; +; The mere transfer of this software does not imply any licenses +; of trade secrets, proprietary technology, copyrights, patents, +; trademarks, maskwork rights, or any other form of intellectual +; property whatsoever. Maxim Integrated Products, Inc. retains all +; ownership rights. +;******************************************************************************* + +__initial_sp EQU 0x20028000 ; Top of RAM + + PRESERVE8 + THUMB + + +; Vector Table Mapped to Address 0 at Reset + + AREA RESET, DATA, READONLY + EXPORT __Vectors + EXPORT __Vectors_End + EXPORT __Vectors_Size + +__Vectors DCD __initial_sp ; Top of Stack + DCD Reset_Handler ; Reset Handler + DCD NMI_Handler ; NMI Handler + DCD HardFault_Handler ; Hard Fault Handler + DCD MemManage_Handler ; MPU Fault Handler + DCD BusFault_Handler ; Bus Fault Handler + DCD UsageFault_Handler ; Usage Fault Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD SVC_Handler ; SVCall Handler + DCD DebugMon_Handler ; Debug Monitor Handler + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + + ; Maxim 32625 Externals interrupts + DCD CLKMAN_IRQHandler ; 16:01 CLKMAN + DCD PWRMAN_IRQHandler ; 17:02 PWRMAN + DCD FLC_IRQHandler ; 18:03 Flash Controller + DCD RTC0_IRQHandler ; 19:04 RTC INT0 + DCD RTC1_IRQHandler ; 20:05 RTC INT1 + DCD RTC2_IRQHandler ; 21:06 RTC INT2 + DCD RTC3_IRQHandler ; 22:07 RTC INT3 + DCD PMU_IRQHandler ; 23:08 PMU + DCD USB_IRQHandler ; 24:09 USB + DCD AES_IRQHandler ; 25:10 AES + DCD MAA_IRQHandler ; 26:11 MAA + DCD WDT0_IRQHandler ; 27:12 WATCHDOG0 + DCD WDT0_P_IRQHandler ; 28:13 WATCHDOG0 PRE-WINDOW + DCD WDT1_IRQHandler ; 29:14 WATCHDOG1 + DCD WDT1_P_IRQHandler ; 30:15 WATCHDOG1 PRE-WINDOW + DCD GPIO_P0_IRQHandler ; 31:16 GPIO Port 0 + DCD GPIO_P1_IRQHandler ; 32:17 GPIO Port 1 + DCD GPIO_P2_IRQHandler ; 33:18 GPIO Port 2 + DCD GPIO_P3_IRQHandler ; 34:19 GPIO Port 3 + DCD GPIO_P4_IRQHandler ; 35:20 GPIO Port 4 + DCD GPIO_P5_IRQHandler ; 36:21 GPIO Port 5 + DCD GPIO_P6_IRQHandler ; 37:22 GPIO Port 6 + DCD TMR0_IRQHandler ; 38:23 Timer32-0 + DCD TMR16_0_IRQHandler ; 39:24 Timer16-s0 + DCD TMR1_IRQHandler ; 40:25 Timer32-1 + DCD TMR16_1_IRQHandler ; 41:26 Timer16-s1 + DCD TMR2_IRQHandler ; 42:27 Timer32-2 + DCD TMR16_2_IRQHandler ; 43:28 Timer16-s2 + DCD TMR3_IRQHandler ; 44:29 Timer32-3 + DCD TMR16_3_IRQHandler ; 45:30 Timer16-s3 + DCD TMR4_IRQHandler ; 46:31 Timer32-4 + DCD TMR16_4_IRQHandler ; 47:32 Timer16-s4 + DCD TMR5_IRQHandler ; 48:33 Timer32-5 + DCD TMR16_5_IRQHandler ; 49:34 Timer16-s5 + DCD PT_IRQHandler ; 50:35 PT + DCD UART0_IRQHandler ; 51:36 UART0 + DCD UART1_IRQHandler ; 52:37 UART1 + DCD UART2_IRQHandler ; 53:38 UART0 + DCD UART3_IRQHandler ; 54:39 UART1 + DCD I2CM0_IRQHandler ; 55:40 I2C Master 0 + DCD I2CM1_IRQHandler ; 56:41 I2C Master 1 + DCD I2CM2_IRQHandler ; 57:42 I2C Master 2 + DCD I2CS_IRQHandler ; 58:43 I2C Slave + DCD SPIM0_IRQHandler ; 59:44 SPIM0 + DCD SPIM1_IRQHandler ; 60:45 SPIM1 + DCD SPIM2_IRQHandler ; 61:46 SPIM2 + DCD SPIB_IRQHandler ; 62:47 SPI Bridge + DCD OWM_IRQHandler ; 63:48 SPI Bridge + DCD AFE_IRQHandler ; 64:49 AFE + DCD SPIS_IRQHandler ; 65:50 SPI Slave + DCD GPIO_P7_IRQHandler ; 66:51 GPIO Port 7 + DCD GPIO_P8_IRQHandler ; 67:52 GPIO Port 8 +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + + AREA |.text|, CODE, READONLY + +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT __main + IMPORT SystemInit + IMPORT PreInit + LDR R0, =PreInit + BLX R0 + LDR R0, =SystemInit + BLX R0 + LDR R0, =__main + BX R0 +__SPIN + WFI + BL __SPIN + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) + +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B NMI_Handler + ENDP + +HardFault_Handler PROC + EXPORT HardFault_Handler [WEAK] + B HardFault_Handler + ENDP + +MemManage_Handler PROC + EXPORT MemManage_Handler [WEAK] + B MemManage_Handler + ENDP + +BusFault_Handler PROC + EXPORT BusFault_Handler [WEAK] + B BusFault_Handler + ENDP + +UsageFault_Handler PROC + EXPORT UsageFault_Handler [WEAK] + B UsageFault_Handler + ENDP + +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B SVC_Handler + ENDP + +DebugMon_Handler PROC + EXPORT DebugMon_Handler [WEAK] + B DebugMon_Handler + ENDP + +PendSV_Handler PROC + EXPORT PendSV_Handler [WEAK] + B PendSV_Handler + ENDP + +SysTick_Handler PROC + EXPORT SysTick_Handler [WEAK] + B SysTick_Handler + ENDP + +Default_Handler PROC + + ; MAX32625 Interrupts + EXPORT CLKMAN_IRQHandler [WEAK] ; 16:01 CLKMAN + EXPORT PWRMAN_IRQHandler [WEAK] ; 17:02 PWRMAN + EXPORT FLC_IRQHandler [WEAK] ; 18:03 Flash Controller + EXPORT RTC0_IRQHandler [WEAK] ; 19:04 RTC INT0 + EXPORT RTC1_IRQHandler [WEAK] ; 20:05 RTC INT1 + EXPORT RTC2_IRQHandler [WEAK] ; 21:06 RTC INT2 + EXPORT RTC3_IRQHandler [WEAK] ; 22:07 RTC INT3 + EXPORT PMU_IRQHandler [WEAK] ; 23:08 PMU + EXPORT USB_IRQHandler [WEAK] ; 24:09 USB + EXPORT AES_IRQHandler [WEAK] ; 25:10 AES + EXPORT MAA_IRQHandler [WEAK] ; 26:11 MAA + EXPORT WDT0_IRQHandler [WEAK] ; 27:12 WATCHDOG0 + EXPORT WDT0_P_IRQHandler [WEAK] ; 28:13 WATCHDOG0 PRE-WINDOW + EXPORT WDT1_IRQHandler [WEAK] ; 29:14 WATCHDOG1 + EXPORT WDT1_P_IRQHandler [WEAK] ; 30:15 WATCHDOG1 PRE-WINDOW + EXPORT GPIO_P0_IRQHandler [WEAK] ; 31:16 GPIO Port 0 + EXPORT GPIO_P1_IRQHandler [WEAK] ; 32:17 GPIO Port 1 + EXPORT GPIO_P2_IRQHandler [WEAK] ; 33:18 GPIO Port 2 + EXPORT GPIO_P3_IRQHandler [WEAK] ; 34:19 GPIO Port 3 + EXPORT GPIO_P4_IRQHandler [WEAK] ; 35:20 GPIO Port 4 + EXPORT GPIO_P5_IRQHandler [WEAK] ; 36:21 GPIO Port 5 + EXPORT GPIO_P6_IRQHandler [WEAK] ; 37:22 GPIO Port 6 + EXPORT TMR0_IRQHandler [WEAK] ; 38:23 Timer32-0 + EXPORT TMR16_0_IRQHandler [WEAK] ; 39:24 Timer16-s0 + EXPORT TMR1_IRQHandler [WEAK] ; 40:25 Timer32-1 + EXPORT TMR16_1_IRQHandler [WEAK] ; 41:26 Timer16-s1 + EXPORT TMR2_IRQHandler [WEAK] ; 42:27 Timer32-2 + EXPORT TMR16_2_IRQHandler [WEAK] ; 43:28 Timer16-s2 + EXPORT TMR3_IRQHandler [WEAK] ; 44:29 Timer32-3 + EXPORT TMR16_3_IRQHandler [WEAK] ; 45:30 Timer16-s3 + EXPORT TMR4_IRQHandler [WEAK] ; 46:31 Timer32-4 + EXPORT TMR16_4_IRQHandler [WEAK] ; 47:32 Timer16-s4 + EXPORT TMR5_IRQHandler [WEAK] ; 48:33 Timer32-5 + EXPORT TMR16_5_IRQHandler [WEAK] ; 49:34 Timer16-s5 + EXPORT PT_IRQHandler [WEAK] ; 50:35 PT + EXPORT UART0_IRQHandler [WEAK] ; 51:36 UART0 + EXPORT UART1_IRQHandler [WEAK] ; 52:37 UART1 + EXPORT UART2_IRQHandler [WEAK] ; 53:38 UART0 + EXPORT UART3_IRQHandler [WEAK] ; 54:39 UART1 + EXPORT I2CM0_IRQHandler [WEAK] ; 55:40 I2C Master 0 + EXPORT I2CM1_IRQHandler [WEAK] ; 56:41 I2C Master 1 + EXPORT I2CM2_IRQHandler [WEAK] ; 57:42 I2C Master 2 + EXPORT I2CS_IRQHandler [WEAK] ; 58:43 I2C Slave + EXPORT SPIM0_IRQHandler [WEAK] ; 59:44 SPIM0 + EXPORT SPIM1_IRQHandler [WEAK] ; 60:45 SPIM1 + EXPORT SPIM2_IRQHandler [WEAK] ; 61:46 SPIM2 + EXPORT SPIB_IRQHandler [WEAK] ; 62:47 SPI Bridge + EXPORT OWM_IRQHandler [WEAK] ; 63:48 SPI Bridge + EXPORT AFE_IRQHandler [WEAK] ; 64:49 AFE + EXPORT SPIS_IRQHandler [WEAK] ; 65:50 SPI Slave + EXPORT GPIO_P7_IRQHandler [WEAK] ; 66:51 GPIO Port 7 + EXPORT GPIO_P8_IRQHandler [WEAK] ; 67:52 GPIO Port 8 + +CLKMAN_IRQHandler +PWRMAN_IRQHandler +FLC_IRQHandler +RTC0_IRQHandler +RTC1_IRQHandler +RTC2_IRQHandler +RTC3_IRQHandler +PMU_IRQHandler +USB_IRQHandler +AES_IRQHandler +MAA_IRQHandler +WDT0_IRQHandler +WDT0_P_IRQHandler +WDT1_IRQHandler +WDT1_P_IRQHandler +GPIO_P0_IRQHandler +GPIO_P1_IRQHandler +GPIO_P2_IRQHandler +GPIO_P3_IRQHandler +GPIO_P4_IRQHandler +GPIO_P5_IRQHandler +GPIO_P6_IRQHandler +TMR0_IRQHandler +TMR16_0_IRQHandler +TMR1_IRQHandler +TMR16_1_IRQHandler +TMR2_IRQHandler +TMR16_2_IRQHandler +TMR3_IRQHandler +TMR16_3_IRQHandler +TMR4_IRQHandler +TMR16_4_IRQHandler +TMR5_IRQHandler +TMR16_5_IRQHandler +PT_IRQHandler +UART0_IRQHandler +UART1_IRQHandler +UART2_IRQHandler +UART3_IRQHandler +I2CM0_IRQHandler +I2CM1_IRQHandler +I2CM2_IRQHandler +I2CS_IRQHandler +SPIM0_IRQHandler +SPIM1_IRQHandler +SPIM2_IRQHandler +SPIB_IRQHandler +OWM_IRQHandler +AFE_IRQHandler +SPIS_IRQHandler +GPIO_P7_IRQHandler +GPIO_P8_IRQHandler + + B . + ENDP + ALIGN + END diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/sys.cpp b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/sys.cpp new file mode 100644 index 0000000..b6c24b3 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_ARM_STD/sys.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern char Image$$RW_IRAM1$$ZI$$Limit[]; + +extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) { + uint32_t zi_limit = (uint32_t)Image$$RW_IRAM1$$ZI$$Limit; + uint32_t sp_limit = __current_sp(); + + zi_limit = (zi_limit + 7) & ~0x7; // ensure zi_limit is 8-byte aligned + + struct __initial_stackheap r; + r.heap_base = zi_limit; + r.heap_limit = sp_limit; + return r; +} + +#ifdef __cplusplus +} +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_GCC_ARM/TARGET_MAX32625NEXPAQ/max32625.ld b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_GCC_ARM/TARGET_MAX32625NEXPAQ/max32625.ld new file mode 100644 index 0000000..f51f007 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_GCC_ARM/TARGET_MAX32625NEXPAQ/max32625.ld @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x00070000 + RAM (rwx) : ORIGIN = 0x20003100, LENGTH = 0x00024F00 +} + +/* Linker script to place sections and symbol values. Should be used together + * with other linker script that defines memory regions FLASH and RAM. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + */ +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + KEEP(*(.isr_vector)) + *(.text*) + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + KEEP(*(.eh_frame*)) + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + + } > RAM + + .bss : + { + __bss_start__ = .; + *(.bss*) + *(COMMON) + __bss_end__ = .; + } > RAM + + .heap : + { + __end__ = .; + end = __end__; + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy : + { + *(.stack) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_GCC_ARM/startup_max32625.S b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_GCC_ARM/startup_max32625.S new file mode 100644 index 0000000..efe5585 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_GCC_ARM/startup_max32625.S @@ -0,0 +1,298 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + + .syntax unified + .arch armv7-m + + .section .stack + .align 3 +#ifdef __STACK_SIZE + .equ Stack_Size, __STACK_SIZE +#else + .equ Stack_Size, 0x00005000 +#endif + .globl __StackTop + .globl __StackLimit +__StackLimit: + .space Stack_Size + .size __StackLimit, . - __StackLimit +__StackTop: + .size __StackTop, . - __StackTop + + .section .heap + .align 3 +#ifdef __HEAP_SIZE + .equ Heap_Size, __HEAP_SIZE +#else + .equ Heap_Size, 0x0000A000 +#endif + .globl __HeapBase + .globl __HeapLimit +__HeapBase: + .if Heap_Size + .space Heap_Size + .endif + .size __HeapBase, . - __HeapBase +__HeapLimit: + .size __HeapLimit, . - __HeapLimit + + + .section .isr_vector + .align 2 + .globl __isr_vector +__isr_vector: + .long __StackTop /* Top of Stack */ + .long Reset_Handler /* Reset Handler */ + .long NMI_Handler /* NMI Handler */ + .long HardFault_Handler /* Hard Fault Handler */ + .long MemManage_Handler /* MPU Fault Handler */ + .long BusFault_Handler /* Bus Fault Handler */ + .long UsageFault_Handler /* Usage Fault Handler */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long SVC_Handler /* SVCall Handler */ + .long DebugMon_Handler /* Debug Monitor Handler */ + .long 0 /* Reserved */ + .long PendSV_Handler /* PendSV Handler */ + .long SysTick_Handler /* SysTick Handler */ + + /* MAX32625 Interrupts */ + .long CLKMAN_IRQHandler /* 16:01 CLKMAN */ + .long PWRMAN_IRQHandler /* 17:02 PWRMAN */ + .long FLC_IRQHandler /* 18:03 Flash Controller */ + .long RTC0_IRQHandler /* 19:04 RTC INT0 */ + .long RTC1_IRQHandler /* 20:05 RTC INT1 */ + .long RTC2_IRQHandler /* 21:06 RTC INT2 */ + .long RTC3_IRQHandler /* 22:07 RTC INT3 */ + .long PMU_IRQHandler /* 23:08 PMU */ + .long USB_IRQHandler /* 24:09 USB */ + .long AES_IRQHandler /* 25:10 AES */ + .long MAA_IRQHandler /* 26:11 MAA */ + .long WDT0_IRQHandler /* 27:12 WATCHDOG0 */ + .long WDT0_P_IRQHandler /* 28:13 WATCHDOG0 PRE-WINDOW */ + .long WDT1_IRQHandler /* 29:14 WATCHDOG1 */ + .long WDT1_P_IRQHandler /* 30:15 WATCHDOG1 PRE-WINDOW */ + .long GPIO_P0_IRQHandler /* 31:16 GPIO Port 0 */ + .long GPIO_P1_IRQHandler /* 32:17 GPIO Port 1 */ + .long GPIO_P2_IRQHandler /* 33:18 GPIO Port 2 */ + .long GPIO_P3_IRQHandler /* 34:19 GPIO Port 3 */ + .long GPIO_P4_IRQHandler /* 35:20 GPIO Port 4 */ + .long GPIO_P5_IRQHandler /* 36:21 GPIO Port 5 */ + .long GPIO_P6_IRQHandler /* 37:22 GPIO Port 6 */ + .long TMR0_IRQHandler /* 38:23 Timer32-0 */ + .long TMR16_0_IRQHandler /* 39:24 Timer16-s0 */ + .long TMR1_IRQHandler /* 40:25 Timer32-1 */ + .long TMR16_1_IRQHandler /* 41:26 Timer16-s1 */ + .long TMR2_IRQHandler /* 42:27 Timer32-2 */ + .long TMR16_2_IRQHandler /* 43:28 Timer16-s2 */ + .long TMR3_IRQHandler /* 44:29 Timer32-3 */ + .long TMR16_3_IRQHandler /* 45:30 Timer16-s3 */ + .long TMR4_IRQHandler /* 46:31 Timer32-4 */ + .long TMR16_4_IRQHandler /* 47:32 Timer16-s4 */ + .long TMR5_IRQHandler /* 48:33 Timer32-5 */ + .long TMR16_5_IRQHandler /* 49:34 Timer16-s5 */ + .long UART0_IRQHandler /* 50:35 UART0 */ + .long UART1_IRQHandler /* 51:36 UART1 */ + .long UART2_IRQHandler /* 52:37 UART2 */ + .long UART3_IRQHandler /* 53:38 UART3 */ + .long PT_IRQHandler /* 54:39 PT */ + .long I2CM0_IRQHandler /* 55:40 I2C Master 0 */ + .long I2CM1_IRQHandler /* 56:41 I2C Master 1 */ + .long I2CM2_IRQHandler /* 57:42 I2C Master 2 */ + .long I2CS_IRQHandler /* 58:43 I2C Slave */ + .long SPIM0_IRQHandler /* 59:44 SPIM0 */ + .long SPIM1_IRQHandler /* 60:45 SPIM1 */ + .long SPIM2_IRQHandler /* 61:46 SPIM2 */ + .long SPIB_IRQHandler /* 62:47 SPI Bridge */ + .long OWM_IRQHandler /* 63:48 One-wire Master */ + .long AFE_IRQHandler /* 64:49 AFE */ + .long SPIS_IRQHandler /* 65:50 SPI Slave */ + .long GPIO_P7_IRQHandler /* 66:51 GPIO Port 7 */ + .long GPIO_P8_IRQHandler /* 67:52 GPIO Port 8 */ + + + .text + .thumb + .thumb_func + .align 2 + .globl Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + ldr r0, =__StackTop + mov sp, r0 + + ldr r0, =PreInit + blx r0 + cbnz r0, .SKIPRAMINIT + +/* Loop to copy data from read only memory to RAM. The ranges + * of copy from/to are specified by following symbols evaluated in + * linker script. + * _etext: End of code section, i.e., begin of data sections to copy from. + * _data /_edata: RAM address range that data should be + * copied to. Both must be aligned to 4 bytes boundary. */ + + ldr r1, =__etext + ldr r2, =__data_start__ + ldr r3, =__data_end__ + +#if 0 +/* Here are two copies of loop implemenations. First one favors code size + * and the second one favors performance. Default uses the first one. + * Change to "#if 0" to use the second one */ +.LC0: + cmp r2, r3 + ittt lt + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt .LC0 +#else + subs r3, r2 + ble .LC1 +.LC0: + subs r3, #4 + ldr r0, [r1, r3] + str r0, [r2, r3] + bgt .LC0 +.LC1: +#endif + +/* + * Loop to zero out BSS section, which uses following symbols + * in linker script: + * _bss : start of BSS section. Must align to 4 + * _ebss : end of BSS section. Must align to 4 + */ + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + + movs r0, 0 +.LC2: + cmp r1, r2 + itt lt + strlt r0, [r1], #4 + blt .LC2 + +.SKIPRAMINIT: + + ldr r0, =SystemInit + blx r0 + + ldr r0, =_start + blx r0 + +.SPIN: + /* Enter LP2 if main() ever returns. */ + wfi + bl .SPIN + +/* Macro to define default handlers. Default handler + * will be weak symbol and just dead loops. They can be + * overwritten by other handlers */ + .macro def_irq_handler handler_name + .align 1 + .thumb_func + .weak \handler_name + .type \handler_name, %function +\handler_name : + b . + .size \handler_name, . - \handler_name + .endm + + def_irq_handler NMI_Handler + def_irq_handler HardFault_Handler + def_irq_handler MemManage_Handler + def_irq_handler BusFault_Handler + def_irq_handler UsageFault_Handler + def_irq_handler SVC_Handler + def_irq_handler DebugMon_Handler + def_irq_handler PendSV_Handler + def_irq_handler SysTick_Handler + def_irq_handler Default_Handler + + /* MAX32625 Interrupts */ + def_irq_handler CLKMAN_IRQHandler /* 16:01 CLKMAN */ + def_irq_handler PWRMAN_IRQHandler /* 17:02 PWRMAN */ + def_irq_handler FLC_IRQHandler /* 18:03 Flash Controller */ + def_irq_handler RTC0_IRQHandler /* 19:04 RTC INT0 */ + def_irq_handler RTC1_IRQHandler /* 20:05 RTC INT1 */ + def_irq_handler RTC2_IRQHandler /* 21:06 RTC INT2 */ + def_irq_handler RTC3_IRQHandler /* 22:07 RTC INT3 */ + def_irq_handler PMU_IRQHandler /* 23:08 PMU */ + def_irq_handler USB_IRQHandler /* 24:09 USB */ + def_irq_handler AES_IRQHandler /* 25:10 AES */ + def_irq_handler MAA_IRQHandler /* 26:11 MAA */ + def_irq_handler WDT0_IRQHandler /* 27:12 WATCHDOG0 */ + def_irq_handler WDT0_P_IRQHandler /* 28:13 WATCHDOG0 PRE-WINDOW */ + def_irq_handler WDT1_IRQHandler /* 29:14 WATCHDOG1 */ + def_irq_handler WDT1_P_IRQHandler /* 30:15 WATCHDOG1 PRE-WINDOW */ + def_irq_handler GPIO_P0_IRQHandler /* 31:16 GPIO Port 0 */ + def_irq_handler GPIO_P1_IRQHandler /* 32:17 GPIO Port 1 */ + def_irq_handler GPIO_P2_IRQHandler /* 33:18 GPIO Port 2 */ + def_irq_handler GPIO_P3_IRQHandler /* 34:19 GPIO Port 3 */ + def_irq_handler GPIO_P4_IRQHandler /* 35:20 GPIO Port 4 */ + def_irq_handler GPIO_P5_IRQHandler /* 36:21 GPIO Port 5 */ + def_irq_handler GPIO_P6_IRQHandler /* 37:22 GPIO Port 6 */ + def_irq_handler TMR0_IRQHandler /* 38:23 Timer32-0 */ + def_irq_handler TMR16_0_IRQHandler /* 39:24 Timer16-s0 */ + def_irq_handler TMR1_IRQHandler /* 40:25 Timer32-1 */ + def_irq_handler TMR16_1_IRQHandler /* 41:26 Timer16-s1 */ + def_irq_handler TMR2_IRQHandler /* 42:27 Timer32-2 */ + def_irq_handler TMR16_2_IRQHandler /* 43:28 Timer16-s2 */ + def_irq_handler TMR3_IRQHandler /* 44:29 Timer32-3 */ + def_irq_handler TMR16_3_IRQHandler /* 45:30 Timer16-s3 */ + def_irq_handler TMR4_IRQHandler /* 46:31 Timer32-4 */ + def_irq_handler TMR16_4_IRQHandler /* 47:32 Timer16-s4 */ + def_irq_handler TMR5_IRQHandler /* 48:33 Timer32-5 */ + def_irq_handler TMR16_5_IRQHandler /* 49:34 Timer16-s5 */ + def_irq_handler PT_IRQHandler /* 50:35 PT */ + def_irq_handler UART0_IRQHandler /* 51:36 UART0 */ + def_irq_handler UART1_IRQHandler /* 52:37 UART1 */ + def_irq_handler UART2_IRQHandler /* 53:38 UART0 */ + def_irq_handler UART3_IRQHandler /* 54:39 UART1 */ + def_irq_handler I2CM0_IRQHandler /* 55:40 I2C Master 0 */ + def_irq_handler I2CM1_IRQHandler /* 56:41 I2C Master 1 */ + def_irq_handler I2CM2_IRQHandler /* 57:42 I2C Master 2 */ + def_irq_handler I2CS_IRQHandler /* 58:43 I2C Slave */ + def_irq_handler SPIM0_IRQHandler /* 59:44 SPIM0 */ + def_irq_handler SPIM1_IRQHandler /* 60:45 SPIM1 */ + def_irq_handler SPIM2_IRQHandler /* 61:46 SPIM2 */ + def_irq_handler SPIB_IRQHandler /* 62:47 SPI Bridge */ + def_irq_handler OWM_IRQHandler /* 63:48 SPI Bridge */ + def_irq_handler AFE_IRQHandler /* 64:49 AFE */ + def_irq_handler SPIS_IRQHandler /* 65:50 SPI Slave */ + def_irq_handler GPIO_P7_IRQHandler /* 66:51 GPIO Port 7 */ + def_irq_handler GPIO_P8_IRQHandler /* 67:52 GPIO Port 8 */ + .end diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_IAR/TARGET_MAX32625NEXPAQ/MAX32625.icf b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_IAR/TARGET_MAX32625NEXPAQ/MAX32625.icf new file mode 100644 index 0000000..1566573 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_IAR/TARGET_MAX32625NEXPAQ/MAX32625.icf @@ -0,0 +1,29 @@ +/* [ROM] */ +define symbol __intvec_start__ = 0x00010000; +define symbol __region_ROM_start__ = 0x00010000; +define symbol __region_ROM_end__ = 0x0007FFFF; + +/* [RAM] Vector table dynamic copy: 68 vectors * 4 bytes = 272 (0x110) bytes */ +define symbol __NVIC_start__ = 0x00010000; +define symbol __NVIC_end__ = 0x00010110; /* to be aligned on 8 bytes */ +define symbol __region_RAM_start__ = 0x20003100; +define symbol __region_RAM_end__ = 0x20027FFF; + +/* Memory regions */ +define memory mem with size = 4G; +define region ROM_region = mem:[from __region_ROM_start__ to __region_ROM_end__]; +define region RAM_region = mem:[from __region_RAM_start__ to __region_RAM_end__]; + +/* Stack and Heap */ +define symbol __size_cstack__ = 0x5000; +define symbol __size_heap__ = 0xA000; +define block CSTACK with alignment = 8, size = __size_cstack__ { }; +define block HEAP with alignment = 8, size = __size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__intvec_start__ { readonly section .intvec }; +place in ROM_region { readonly }; +place in RAM_region { readwrite, + block CSTACK, block HEAP }; diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_IAR/startup_MAX32625.S b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_IAR/startup_MAX32625.S new file mode 100644 index 0000000..91a154d --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/TOOLCHAIN_IAR/startup_MAX32625.S @@ -0,0 +1,450 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + + MODULE ?cstartup + + ;; Forward declaration of sections. + SECTION CSTACK:DATA:NOROOT(3) + + SECTION .intvec:CODE:NOROOT(2) + + EXTERN __iar_program_start + EXTERN PreInit + EXTERN SystemInit + PUBLIC __vector_table + PUBLIC __vector_table_modify + PUBLIC __Vectors + PUBLIC __Vectors_End + PUBLIC __Vectors_Size + + DATA +__vector_table + DCD sfe(CSTACK) + DCD Reset_Handler ; Reset Handler + + DCD NMI_Handler ; NMI Handler + DCD HardFault_Handler ; Hard Fault Handler + DCD MemManage_Handler ; MPU Fault Handler + DCD BusFault_Handler ; Bus Fault Handler + DCD UsageFault_Handler ; Usage Fault Handler +__vector_table_modify + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD SVC_Handler ; SVCall Handler + DCD DebugMon_Handler ; Debug Monitor Handler + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + ; MAX32625 Specific Interrupts + DCD CLKMAN_IRQHandler ; 16:01 CLKMAN */ + DCD PWRMAN_IRQHandler ; 17:02 PWRMAN */ + DCD FLC_IRQHandler ; 18:03 Flash Controller */ + DCD RTC0_IRQHandler ; 19:04 RTC INT0 */ + DCD RTC1_IRQHandler ; 20:05 RTC INT1 */ + DCD RTC2_IRQHandler ; 21:06 RTC INT2 */ + DCD RTC3_IRQHandler ; 22:07 RTC INT3 */ + DCD PMU_IRQHandler ; 23:08 PMU */ + DCD USB_IRQHandler ; 24:09 USB */ + DCD AES_IRQHandler ; 25:10 AES */ + DCD MAA_IRQHandler ; 26:11 MAA */ + DCD WDT0_IRQHandler ; 27:12 WATCHDOG0 */ + DCD WDT0_P_IRQHandler ; 28:13 WATCHDOG0 PRE-WINDOW */ + DCD WDT1_IRQHandler ; 29:14 WATCHDOG1 */ + DCD WDT1_P_IRQHandler ; 30:15 WATCHDOG1 PRE-WINDOW */ + DCD GPIO_P0_IRQHandler ; 31:16 GPIO Port 0 */ + DCD GPIO_P1_IRQHandler ; 32:17 GPIO Port 1 */ + DCD GPIO_P2_IRQHandler ; 33:18 GPIO Port 2 */ + DCD GPIO_P3_IRQHandler ; 34:19 GPIO Port 3 */ + DCD GPIO_P4_IRQHandler ; 35:20 GPIO Port 4 */ + DCD GPIO_P5_IRQHandler ; 36:21 GPIO Port 5 */ + DCD GPIO_P6_IRQHandler ; 37:22 GPIO Port 6 */ + DCD TMR0_IRQHandler ; 38:23 Timer32-0 */ + DCD TMR16_0_IRQHandler ; 39:24 Timer16-s0 */ + DCD TMR1_IRQHandler ; 40:25 Timer32-1 */ + DCD TMR16_1_IRQHandler ; 41:26 Timer16-s1 */ + DCD TMR2_IRQHandler ; 42:27 Timer32-2 */ + DCD TMR16_2_IRQHandler ; 43:28 Timer16-s2 */ + DCD TMR3_IRQHandler ; 44:29 Timer32-3 */ + DCD TMR16_3_IRQHandler ; 45:30 Timer16-s3 */ + DCD TMR4_IRQHandler ; 46:31 Timer32-4 */ + DCD TMR16_4_IRQHandler ; 47:32 Timer16-s4 */ + DCD TMR5_IRQHandler ; 48:33 Timer32-5 */ + DCD TMR16_5_IRQHandler ; 49:34 Timer16-s5 */ + DCD UART0_IRQHandler ; 50:35 UART0 */ + DCD UART1_IRQHandler ; 51:36 UART1 */ + DCD UART2_IRQHandler ; 52:37 UART2 */ + DCD UART3_IRQHandler ; 53:38 UART3 */ + DCD PT_IRQHandler ; 54:39 PT */ + DCD I2CM0_IRQHandler ; 55:40 I2C Master 0 */ + DCD I2CM1_IRQHandler ; 56:41 I2C Master 1 */ + DCD I2CM2_IRQHandler ; 57:42 I2C Master 2 */ + DCD I2CS_IRQHandler ; 58:43 I2C Slave */ + DCD SPIM0_IRQHandler ; 59:44 SPI Master 0 */ + DCD SPIM1_IRQHandler ; 60:45 SPI Master 1 */ + DCD SPIM2_IRQHandler ; 61:46 SPI Master 2 */ + DCD SPIB_IRQHandler ; 62:47 SPI Bridge */ + DCD OWM_IRQHandler ; 63:48 One-wire Master */ + DCD AFE_IRQHandler ; 64:49 AFE */ + DCD SPIS_IRQHandler ; 65:50 SPI Slave + DCD GPIO_P7_IRQHandler ; 66:51 GPIO Port 7 + DCD GPIO_P8_IRQHandler ; 67:52 GPIO Port 8 + +__Vectors_End +__Vectors EQU __vector_table +__Vectors_Size EQU __Vectors_End - __Vectors + + + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default interrupt handlers. +;; + THUMB + PUBWEAK Reset_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Reset_Handler + + LDR R0, =PreInit + BLX R0 + LDR R0, =SystemInit + BLX R0 + LDR R0, =__iar_program_start + BX R0 + + PUBWEAK NMI_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +NMI_Handler + B NMI_Handler + + PUBWEAK HardFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Handler + B HardFault_Handler + + PUBWEAK MemManage_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +MemManage_Handler + B MemManage_Handler + + PUBWEAK BusFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +BusFault_Handler + B BusFault_Handler + + PUBWEAK UsageFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +UsageFault_Handler + B UsageFault_Handler + + PUBWEAK SVC_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SVC_Handler + B SVC_Handler + + PUBWEAK DebugMon_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +DebugMon_Handler + B DebugMon_Handler + + PUBWEAK PendSV_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +PendSV_Handler + B PendSV_Handler + + PUBWEAK SysTick_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SysTick_Handler + B SysTick_Handler + + PUBWEAK CLKMAN_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +CLKMAN_IRQHandler + B CLKMAN_IRQHandler + + PUBWEAK PWRMAN_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +PWRMAN_IRQHandler + B PWRMAN_IRQHandler + + PUBWEAK FLC_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +FLC_IRQHandler + B FLC_IRQHandler + + PUBWEAK RTC0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +RTC0_IRQHandler + B RTC0_IRQHandler + + PUBWEAK RTC1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +RTC1_IRQHandler + B RTC1_IRQHandler + + PUBWEAK RTC2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +RTC2_IRQHandler + B RTC2_IRQHandler + + PUBWEAK RTC3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +RTC3_IRQHandler + B RTC3_IRQHandler + + PUBWEAK PMU_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +PMU_IRQHandler + B PMU_IRQHandler + + PUBWEAK USB_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +USB_IRQHandler + B USB_IRQHandler + + PUBWEAK AES_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +AES_IRQHandler + B AES_IRQHandler + + PUBWEAK MAA_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +MAA_IRQHandler + B MAA_IRQHandler + + PUBWEAK WDT0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +WDT0_IRQHandler + B WDT0_IRQHandler + + PUBWEAK WDT0_P_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +WDT0_P_IRQHandler + B WDT0_P_IRQHandler + + PUBWEAK WDT1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +WDT1_IRQHandler + B WDT1_IRQHandler + + PUBWEAK WDT1_P_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +WDT1_P_IRQHandler + B WDT1_P_IRQHandler + + PUBWEAK GPIO_P0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P0_IRQHandler + B GPIO_P0_IRQHandler + + PUBWEAK GPIO_P1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P1_IRQHandler + B GPIO_P1_IRQHandler + + PUBWEAK GPIO_P2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P2_IRQHandler + B GPIO_P2_IRQHandler + + PUBWEAK GPIO_P3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P3_IRQHandler + B GPIO_P3_IRQHandler + + PUBWEAK GPIO_P4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P4_IRQHandler + B GPIO_P4_IRQHandler + + PUBWEAK GPIO_P5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P5_IRQHandler + B GPIO_P5_IRQHandler + + PUBWEAK GPIO_P6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P6_IRQHandler + B GPIO_P6_IRQHandler + + PUBWEAK TMR0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR0_IRQHandler + B TMR0_IRQHandler + + PUBWEAK TMR16_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR16_0_IRQHandler + B TMR16_0_IRQHandler + + PUBWEAK TMR1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR1_IRQHandler + B TMR1_IRQHandler + + PUBWEAK TMR16_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR16_1_IRQHandler + B TMR16_1_IRQHandler + + PUBWEAK TMR2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR2_IRQHandler + B TMR2_IRQHandler + + PUBWEAK TMR16_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR16_2_IRQHandler + B TMR16_2_IRQHandler + + PUBWEAK TMR3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR3_IRQHandler + B TMR3_IRQHandler + + PUBWEAK TMR16_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR16_3_IRQHandler + B TMR16_3_IRQHandler + + PUBWEAK TMR4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR4_IRQHandler + B TMR4_IRQHandler + + PUBWEAK TMR16_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR16_4_IRQHandler + B TMR16_4_IRQHandler + + PUBWEAK TMR5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR5_IRQHandler + B TMR5_IRQHandler + + PUBWEAK TMR16_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +TMR16_5_IRQHandler + B TMR16_5_IRQHandler + + PUBWEAK UART0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +UART0_IRQHandler + B UART0_IRQHandler + + PUBWEAK UART1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +UART1_IRQHandler + B UART1_IRQHandler + + PUBWEAK UART2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +UART2_IRQHandler + B UART2_IRQHandler + + PUBWEAK UART3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +UART3_IRQHandler + B UART3_IRQHandler + + PUBWEAK PT_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +PT_IRQHandler + B PT_IRQHandler + + PUBWEAK I2CM0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +I2CM0_IRQHandler + B I2CM0_IRQHandler + + PUBWEAK I2CM1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +I2CM1_IRQHandler + B I2CM1_IRQHandler + + PUBWEAK I2CM2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +I2CM2_IRQHandler + B I2CM2_IRQHandler + + PUBWEAK I2CS_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +I2CS_IRQHandler + B I2CS_IRQHandler + + PUBWEAK SPIM0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +SPIM0_IRQHandler + B SPIM0_IRQHandler + + PUBWEAK SPIM1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +SPIM1_IRQHandler + B SPIM1_IRQHandler + + PUBWEAK SPIM2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +SPIM2_IRQHandler + B SPIM2_IRQHandler + + PUBWEAK SPIB_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +SPIB_IRQHandler + B SPIB_IRQHandler + + PUBWEAK OWM_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +OWM_IRQHandler + B OWM_IRQHandler + + PUBWEAK AFE_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +AFE_IRQHandler + B AFE_IRQHandler + + PUBWEAK SPIS_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +SPIS_IRQHandler + B SPIS_IRQHandler + + PUBWEAK GPIO_P7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P7_IRQHandler + B GPIO_P7_IRQHandler + + PUBWEAK GPIO_P8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +GPIO_P8_IRQHandler + B GPIO_P8_IRQHandler + END diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/adc_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/adc_regs.h new file mode 100644 index 0000000..a249d98 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/adc_regs.h @@ -0,0 +1,271 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_ADC_REGS_H_ +#define _MXC_ADC_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 ADC Control */ + __IO uint32_t status; /* 0x0004 ADC Status */ + __IO uint32_t data; /* 0x0008 ADC Output Data */ + __IO uint32_t intr; /* 0x000C ADC Interrupt Control Register */ + __IO uint32_t limit[4]; /* 0x0010-0x001C ADC Limit 0..3 */ + __IO uint32_t afe_ctrl; /* 0x0020 AFE Control Register */ + __IO uint32_t ro_cal0; /* 0x0024 RO Trim Calibration Register 0 */ + __IO uint32_t ro_cal1; /* 0x0028 RO Trim Calibration Register 1 */ + __IO uint32_t ro_cal2; /* 0x002C RO Trim Calibration Register 2 */ +} mxc_adc_regs_t; + + +/* + Register offsets for module ADC. +*/ + +#define MXC_R_ADC_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_ADC_OFFS_STATUS ((uint32_t)0x00000004UL) +#define MXC_R_ADC_OFFS_DATA ((uint32_t)0x00000008UL) +#define MXC_R_ADC_OFFS_INTR ((uint32_t)0x0000000CUL) +#define MXC_R_ADC_OFFS_LIMIT0 ((uint32_t)0x00000010UL) +#define MXC_R_ADC_OFFS_LIMIT1 ((uint32_t)0x00000014UL) +#define MXC_R_ADC_OFFS_LIMIT2 ((uint32_t)0x00000018UL) +#define MXC_R_ADC_OFFS_LIMIT3 ((uint32_t)0x0000001CUL) +#define MXC_R_ADC_OFFS_AFE_CTRL ((uint32_t)0x00000020UL) +#define MXC_R_ADC_OFFS_RO_CAL0 ((uint32_t)0x00000024UL) +#define MXC_R_ADC_OFFS_RO_CAL1 ((uint32_t)0x00000028UL) +#define MXC_R_ADC_OFFS_RO_CAL2 ((uint32_t)0x0000002CUL) + + +/* + Field positions and masks for module ADC. +*/ + +#define MXC_F_ADC_CTRL_CPU_ADC_START_POS 0 +#define MXC_F_ADC_CTRL_CPU_ADC_START ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_CPU_ADC_START_POS)) +#define MXC_F_ADC_CTRL_ADC_PU_POS 1 +#define MXC_F_ADC_CTRL_ADC_PU ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_PU_POS)) +#define MXC_F_ADC_CTRL_BUF_PU_POS 2 +#define MXC_F_ADC_CTRL_BUF_PU ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_BUF_PU_POS)) +#define MXC_F_ADC_CTRL_ADC_REFBUF_PU_POS 3 +#define MXC_F_ADC_CTRL_ADC_REFBUF_PU ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_REFBUF_PU_POS)) +#define MXC_F_ADC_CTRL_ADC_CHGPUMP_PU_POS 4 +#define MXC_F_ADC_CTRL_ADC_CHGPUMP_PU ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_CHGPUMP_PU_POS)) +#define MXC_F_ADC_CTRL_BUF_CHOP_DIS_POS 5 +#define MXC_F_ADC_CTRL_BUF_CHOP_DIS ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_BUF_CHOP_DIS_POS)) +#define MXC_F_ADC_CTRL_BUF_PUMP_DIS_POS 6 +#define MXC_F_ADC_CTRL_BUF_PUMP_DIS ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_BUF_PUMP_DIS_POS)) +#define MXC_F_ADC_CTRL_BUF_BYPASS_POS 7 +#define MXC_F_ADC_CTRL_BUF_BYPASS ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_BUF_BYPASS_POS)) +#define MXC_F_ADC_CTRL_ADC_REFSCL_POS 8 +#define MXC_F_ADC_CTRL_ADC_REFSCL ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_REFSCL_POS)) +#define MXC_F_ADC_CTRL_ADC_SCALE_POS 9 +#define MXC_F_ADC_CTRL_ADC_SCALE ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_SCALE_POS)) +#define MXC_F_ADC_CTRL_ADC_REFSEL_POS 10 +#define MXC_F_ADC_CTRL_ADC_REFSEL ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_REFSEL_POS)) +#define MXC_F_ADC_CTRL_ADC_CLK_EN_POS 11 +#define MXC_F_ADC_CTRL_ADC_CLK_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_CLK_EN_POS)) +#define MXC_F_ADC_CTRL_ADC_CHSEL_POS 12 +#define MXC_F_ADC_CTRL_ADC_CHSEL ((uint32_t)(0x0000000FUL << MXC_F_ADC_CTRL_ADC_CHSEL_POS)) + +#if (MXC_ADC_REV == 0) +#define MXC_F_ADC_CTRL_ADC_XREF_POS 16 +#define MXC_F_ADC_CTRL_ADC_XREF ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_XREF_POS)) +#endif + +#define MXC_F_ADC_CTRL_ADC_DATAALIGN_POS 17 +#define MXC_F_ADC_CTRL_ADC_DATAALIGN ((uint32_t)(0x00000001UL << MXC_F_ADC_CTRL_ADC_DATAALIGN_POS)) +#define MXC_F_ADC_CTRL_AFE_PWR_UP_DLY_POS 24 +#define MXC_F_ADC_CTRL_AFE_PWR_UP_DLY ((uint32_t)(0x000000FFUL << MXC_F_ADC_CTRL_AFE_PWR_UP_DLY_POS)) + +#define MXC_F_ADC_STATUS_ADC_ACTIVE_POS 0 +#define MXC_F_ADC_STATUS_ADC_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_ADC_STATUS_ADC_ACTIVE_POS)) +#define MXC_F_ADC_STATUS_RO_CAL_ATOMIC_ACTIVE_POS 1 +#define MXC_F_ADC_STATUS_RO_CAL_ATOMIC_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_ADC_STATUS_RO_CAL_ATOMIC_ACTIVE_POS)) +#define MXC_F_ADC_STATUS_AFE_PWR_UP_ACTIVE_POS 2 +#define MXC_F_ADC_STATUS_AFE_PWR_UP_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_ADC_STATUS_AFE_PWR_UP_ACTIVE_POS)) +#define MXC_F_ADC_STATUS_ADC_OVERFLOW_POS 3 +#define MXC_F_ADC_STATUS_ADC_OVERFLOW ((uint32_t)(0x00000001UL << MXC_F_ADC_STATUS_ADC_OVERFLOW_POS)) + +#define MXC_F_ADC_DATA_ADC_DATA_POS 0 +#define MXC_F_ADC_DATA_ADC_DATA ((uint32_t)(0x0000FFFFUL << MXC_F_ADC_DATA_ADC_DATA_POS)) + +#define MXC_F_ADC_INTR_ADC_DONE_IE_POS 0 +#define MXC_F_ADC_INTR_ADC_DONE_IE ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_DONE_IE_POS)) +#define MXC_F_ADC_INTR_ADC_REF_READY_IE_POS 1 +#define MXC_F_ADC_INTR_ADC_REF_READY_IE ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_REF_READY_IE_POS)) +#define MXC_F_ADC_INTR_ADC_HI_LIMIT_IE_POS 2 +#define MXC_F_ADC_INTR_ADC_HI_LIMIT_IE ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_HI_LIMIT_IE_POS)) +#define MXC_F_ADC_INTR_ADC_LO_LIMIT_IE_POS 3 +#define MXC_F_ADC_INTR_ADC_LO_LIMIT_IE ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_LO_LIMIT_IE_POS)) +#define MXC_F_ADC_INTR_ADC_OVERFLOW_IE_POS 4 +#define MXC_F_ADC_INTR_ADC_OVERFLOW_IE ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_OVERFLOW_IE_POS)) +#define MXC_F_ADC_INTR_RO_CAL_DONE_IE_POS 5 +#define MXC_F_ADC_INTR_RO_CAL_DONE_IE ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_RO_CAL_DONE_IE_POS)) +#define MXC_F_ADC_INTR_ADC_DONE_IF_POS 16 +#define MXC_F_ADC_INTR_ADC_DONE_IF ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_DONE_IF_POS)) +#define MXC_F_ADC_INTR_ADC_REF_READY_IF_POS 17 +#define MXC_F_ADC_INTR_ADC_REF_READY_IF ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_REF_READY_IF_POS)) +#define MXC_F_ADC_INTR_ADC_HI_LIMIT_IF_POS 18 +#define MXC_F_ADC_INTR_ADC_HI_LIMIT_IF ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_HI_LIMIT_IF_POS)) +#define MXC_F_ADC_INTR_ADC_LO_LIMIT_IF_POS 19 +#define MXC_F_ADC_INTR_ADC_LO_LIMIT_IF ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_LO_LIMIT_IF_POS)) +#define MXC_F_ADC_INTR_ADC_OVERFLOW_IF_POS 20 +#define MXC_F_ADC_INTR_ADC_OVERFLOW_IF ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_OVERFLOW_IF_POS)) +#define MXC_F_ADC_INTR_RO_CAL_DONE_IF_POS 21 +#define MXC_F_ADC_INTR_RO_CAL_DONE_IF ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_RO_CAL_DONE_IF_POS)) +#define MXC_F_ADC_INTR_ADC_INT_PENDING_POS 22 +#define MXC_F_ADC_INTR_ADC_INT_PENDING ((uint32_t)(0x00000001UL << MXC_F_ADC_INTR_ADC_INT_PENDING_POS)) + +#define MXC_F_ADC_LIMIT0_CH_LO_LIMIT_POS 0 +#define MXC_F_ADC_LIMIT0_CH_LO_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT0_CH_LO_LIMIT_POS)) +#define MXC_F_ADC_LIMIT0_CH_HI_LIMIT_POS 12 +#define MXC_F_ADC_LIMIT0_CH_HI_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT0_CH_HI_LIMIT_POS)) +#define MXC_F_ADC_LIMIT0_CH_SEL_POS 24 +#define MXC_F_ADC_LIMIT0_CH_SEL ((uint32_t)(0x0000000FUL << MXC_F_ADC_LIMIT0_CH_SEL_POS)) +#define MXC_F_ADC_LIMIT0_CH_LO_LIMIT_EN_POS 28 +#define MXC_F_ADC_LIMIT0_CH_LO_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT0_CH_LO_LIMIT_EN_POS)) +#define MXC_F_ADC_LIMIT0_CH_HI_LIMIT_EN_POS 29 +#define MXC_F_ADC_LIMIT0_CH_HI_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT0_CH_HI_LIMIT_EN_POS)) + +#define MXC_F_ADC_LIMIT1_CH_LO_LIMIT_POS 0 +#define MXC_F_ADC_LIMIT1_CH_LO_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT1_CH_LO_LIMIT_POS)) +#define MXC_F_ADC_LIMIT1_CH_HI_LIMIT_POS 12 +#define MXC_F_ADC_LIMIT1_CH_HI_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT1_CH_HI_LIMIT_POS)) +#define MXC_F_ADC_LIMIT1_CH_SEL_POS 24 +#define MXC_F_ADC_LIMIT1_CH_SEL ((uint32_t)(0x0000000FUL << MXC_F_ADC_LIMIT1_CH_SEL_POS)) +#define MXC_F_ADC_LIMIT1_CH_LO_LIMIT_EN_POS 28 +#define MXC_F_ADC_LIMIT1_CH_LO_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT1_CH_LO_LIMIT_EN_POS)) +#define MXC_F_ADC_LIMIT1_CH_HI_LIMIT_EN_POS 29 +#define MXC_F_ADC_LIMIT1_CH_HI_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT1_CH_HI_LIMIT_EN_POS)) + +#define MXC_F_ADC_LIMIT2_CH_LO_LIMIT_POS 0 +#define MXC_F_ADC_LIMIT2_CH_LO_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT2_CH_LO_LIMIT_POS)) +#define MXC_F_ADC_LIMIT2_CH_HI_LIMIT_POS 12 +#define MXC_F_ADC_LIMIT2_CH_HI_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT2_CH_HI_LIMIT_POS)) +#define MXC_F_ADC_LIMIT2_CH_SEL_POS 24 +#define MXC_F_ADC_LIMIT2_CH_SEL ((uint32_t)(0x0000000FUL << MXC_F_ADC_LIMIT2_CH_SEL_POS)) +#define MXC_F_ADC_LIMIT2_CH_LO_LIMIT_EN_POS 28 +#define MXC_F_ADC_LIMIT2_CH_LO_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT2_CH_LO_LIMIT_EN_POS)) +#define MXC_F_ADC_LIMIT2_CH_HI_LIMIT_EN_POS 29 +#define MXC_F_ADC_LIMIT2_CH_HI_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT2_CH_HI_LIMIT_EN_POS)) + +#define MXC_F_ADC_LIMIT3_CH_LO_LIMIT_POS 0 +#define MXC_F_ADC_LIMIT3_CH_LO_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT3_CH_LO_LIMIT_POS)) +#define MXC_F_ADC_LIMIT3_CH_HI_LIMIT_POS 12 +#define MXC_F_ADC_LIMIT3_CH_HI_LIMIT ((uint32_t)(0x000003FFUL << MXC_F_ADC_LIMIT3_CH_HI_LIMIT_POS)) +#define MXC_F_ADC_LIMIT3_CH_SEL_POS 24 +#define MXC_F_ADC_LIMIT3_CH_SEL ((uint32_t)(0x0000000FUL << MXC_F_ADC_LIMIT3_CH_SEL_POS)) +#define MXC_F_ADC_LIMIT3_CH_LO_LIMIT_EN_POS 28 +#define MXC_F_ADC_LIMIT3_CH_LO_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT3_CH_LO_LIMIT_EN_POS)) +#define MXC_F_ADC_LIMIT3_CH_HI_LIMIT_EN_POS 29 +#define MXC_F_ADC_LIMIT3_CH_HI_LIMIT_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_LIMIT3_CH_HI_LIMIT_EN_POS)) + +#define MXC_F_ADC_AFE_CTRL_TMON_INTBIAS_EN_POS 8 +#define MXC_F_ADC_AFE_CTRL_TMON_INTBIAS_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_AFE_CTRL_TMON_INTBIAS_EN_POS)) +#define MXC_F_ADC_AFE_CTRL_TMON_EXTBIAS_EN_POS 9 +#define MXC_F_ADC_AFE_CTRL_TMON_EXTBIAS_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_AFE_CTRL_TMON_EXTBIAS_EN_POS)) + +#define MXC_F_ADC_RO_CAL0_RO_CAL_EN_POS 0 +#define MXC_F_ADC_RO_CAL0_RO_CAL_EN ((uint32_t)(0x00000001UL << MXC_F_ADC_RO_CAL0_RO_CAL_EN_POS)) +#define MXC_F_ADC_RO_CAL0_RO_CAL_RUN_POS 1 +#define MXC_F_ADC_RO_CAL0_RO_CAL_RUN ((uint32_t)(0x00000001UL << MXC_F_ADC_RO_CAL0_RO_CAL_RUN_POS)) +#define MXC_F_ADC_RO_CAL0_RO_CAL_LOAD_POS 2 +#define MXC_F_ADC_RO_CAL0_RO_CAL_LOAD ((uint32_t)(0x00000001UL << MXC_F_ADC_RO_CAL0_RO_CAL_LOAD_POS)) +#define MXC_F_ADC_RO_CAL0_RO_CAL_ATOMIC_POS 4 +#define MXC_F_ADC_RO_CAL0_RO_CAL_ATOMIC ((uint32_t)(0x00000001UL << MXC_F_ADC_RO_CAL0_RO_CAL_ATOMIC_POS)) +#define MXC_F_ADC_RO_CAL0_DUMMY_POS 5 +#define MXC_F_ADC_RO_CAL0_DUMMY ((uint32_t)(0x00000007UL << MXC_F_ADC_RO_CAL0_DUMMY_POS)) +#define MXC_F_ADC_RO_CAL0_TRM_MU_POS 8 +#define MXC_F_ADC_RO_CAL0_TRM_MU ((uint32_t)(0x00000FFFUL << MXC_F_ADC_RO_CAL0_TRM_MU_POS)) +#define MXC_F_ADC_RO_CAL0_RO_TRM_POS 23 +#define MXC_F_ADC_RO_CAL0_RO_TRM ((uint32_t)(0x000001FFUL << MXC_F_ADC_RO_CAL0_RO_TRM_POS)) + +#define MXC_F_ADC_RO_CAL1_TRM_INIT_POS 0 +#define MXC_F_ADC_RO_CAL1_TRM_INIT ((uint32_t)(0x000001FFUL << MXC_F_ADC_RO_CAL1_TRM_INIT_POS)) +#define MXC_F_ADC_RO_CAL1_TRM_MIN_POS 10 +#define MXC_F_ADC_RO_CAL1_TRM_MIN ((uint32_t)(0x000001FFUL << MXC_F_ADC_RO_CAL1_TRM_MIN_POS)) +#define MXC_F_ADC_RO_CAL1_TRM_MAX_POS 20 +#define MXC_F_ADC_RO_CAL1_TRM_MAX ((uint32_t)(0x000001FFUL << MXC_F_ADC_RO_CAL1_TRM_MAX_POS)) + +#define MXC_F_ADC_RO_CAL2_AUTO_CAL_DONE_CNT_POS 0 +#define MXC_F_ADC_RO_CAL2_AUTO_CAL_DONE_CNT ((uint32_t)(0x000000FFUL << MXC_F_ADC_RO_CAL2_AUTO_CAL_DONE_CNT_POS)) + +#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN0 ((uint32_t)(0x00000000UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN1 ((uint32_t)(0x00000001UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN2 ((uint32_t)(0x00000002UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN3 ((uint32_t)(0x00000003UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN0_DIV_5 ((uint32_t)(0x00000004UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN1_DIV_5 ((uint32_t)(0x00000005UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_VDDB_DIV_4 ((uint32_t)(0x00000006UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_VDD18 ((uint32_t)(0x00000007UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_VDD12 ((uint32_t)(0x00000008UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_VRTC_DIV_2 ((uint32_t)(0x00000009UL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_TMON ((uint32_t)(0x0000000AUL)) + +#if(MXC_ADC_REV > 0) +#define MXC_V_ADC_CTRL_ADC_CHSEL_VDDIO_DIV_4 ((uint32_t)(0x0000000BUL)) +#define MXC_V_ADC_CTRL_ADC_CHSEL_VDDIOH_DIV_4 ((uint32_t)(0x0000000CUL)) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_ADC_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/aes_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/aes_regs.h new file mode 100644 index 0000000..4352758 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/aes_regs.h @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_AES_REGS_H_ +#define _MXC_AES_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 AES Control and Status */ + __I uint32_t rsv004; /* 0x0004 */ + __IO uint32_t erase_all; /* 0x0008 Write to Trigger AES Memory Erase */ +} mxc_aes_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t inp[4]; /* 0x0000-0x000C AES Input (128 bits) */ + __IO uint32_t key[8]; /* 0x0010-0x002C AES Symmetric Key (up to 256 bits) */ + __IO uint32_t out[4]; /* 0x0030-0x003C AES Output Data (128 bits) */ + __IO uint32_t expkey[8]; /* 0x0040-0x005C AES Expanded Key Data (256 bits) */ +} mxc_aes_mem_regs_t; + + +/* + Register offsets for module AES. +*/ + +#define MXC_R_AES_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_AES_OFFS_ERASE_ALL ((uint32_t)0x00000008UL) +#define MXC_R_AES_MEM_OFFS_INP0 ((uint32_t)0x00000000UL) +#define MXC_R_AES_MEM_OFFS_INP1 ((uint32_t)0x00000004UL) +#define MXC_R_AES_MEM_OFFS_INP2 ((uint32_t)0x00000008UL) +#define MXC_R_AES_MEM_OFFS_INP3 ((uint32_t)0x0000000CUL) +#define MXC_R_AES_MEM_OFFS_KEY0 ((uint32_t)0x00000010UL) +#define MXC_R_AES_MEM_OFFS_KEY1 ((uint32_t)0x00000014UL) +#define MXC_R_AES_MEM_OFFS_KEY2 ((uint32_t)0x00000018UL) +#define MXC_R_AES_MEM_OFFS_KEY3 ((uint32_t)0x0000001CUL) +#define MXC_R_AES_MEM_OFFS_KEY4 ((uint32_t)0x00000020UL) +#define MXC_R_AES_MEM_OFFS_KEY5 ((uint32_t)0x00000024UL) +#define MXC_R_AES_MEM_OFFS_KEY6 ((uint32_t)0x00000028UL) +#define MXC_R_AES_MEM_OFFS_KEY7 ((uint32_t)0x0000002CUL) +#define MXC_R_AES_MEM_OFFS_OUT0 ((uint32_t)0x00000030UL) +#define MXC_R_AES_MEM_OFFS_OUT1 ((uint32_t)0x00000034UL) +#define MXC_R_AES_MEM_OFFS_OUT2 ((uint32_t)0x00000038UL) +#define MXC_R_AES_MEM_OFFS_OUT3 ((uint32_t)0x0000003CUL) +#define MXC_R_AES_MEM_OFFS_EXPKEY0 ((uint32_t)0x00000040UL) +#define MXC_R_AES_MEM_OFFS_EXPKEY1 ((uint32_t)0x00000044UL) +#define MXC_R_AES_MEM_OFFS_EXPKEY2 ((uint32_t)0x00000048UL) +#define MXC_R_AES_MEM_OFFS_EXPKEY3 ((uint32_t)0x0000004CUL) +#define MXC_R_AES_MEM_OFFS_EXPKEY4 ((uint32_t)0x00000050UL) +#define MXC_R_AES_MEM_OFFS_EXPKEY5 ((uint32_t)0x00000054UL) +#define MXC_R_AES_MEM_OFFS_EXPKEY6 ((uint32_t)0x00000058UL) +#define MXC_R_AES_MEM_OFFS_EXPKEY7 ((uint32_t)0x0000005CUL) + + +/* + Field positions and masks for module AES. +*/ + +#define MXC_F_AES_CTRL_START_POS 0 +#define MXC_F_AES_CTRL_START ((uint32_t)(0x00000001UL << MXC_F_AES_CTRL_START_POS)) +#define MXC_F_AES_CTRL_CRYPT_MODE_POS 1 +#define MXC_F_AES_CTRL_CRYPT_MODE ((uint32_t)(0x00000001UL << MXC_F_AES_CTRL_CRYPT_MODE_POS)) +#define MXC_F_AES_CTRL_EXP_KEY_MODE_POS 2 +#define MXC_F_AES_CTRL_EXP_KEY_MODE ((uint32_t)(0x00000001UL << MXC_F_AES_CTRL_EXP_KEY_MODE_POS)) +#define MXC_F_AES_CTRL_KEY_SIZE_POS 3 +#define MXC_F_AES_CTRL_KEY_SIZE ((uint32_t)(0x00000003UL << MXC_F_AES_CTRL_KEY_SIZE_POS)) +#define MXC_F_AES_CTRL_INTEN_POS 5 +#define MXC_F_AES_CTRL_INTEN ((uint32_t)(0x00000001UL << MXC_F_AES_CTRL_INTEN_POS)) +#define MXC_F_AES_CTRL_INTFL_POS 6 +#define MXC_F_AES_CTRL_INTFL ((uint32_t)(0x00000001UL << MXC_F_AES_CTRL_INTFL_POS)) +#define MXC_F_AES_CTRL_LOAD_HW_KEY_POS 7 +#define MXC_F_AES_CTRL_LOAD_HW_KEY ((uint32_t)(0x00000001UL << MXC_F_AES_CTRL_LOAD_HW_KEY_POS)) + + + +/* + Field values and shifted values for module AES. +*/ + +#define MXC_V_AES_CTRL_ENCRYPT_MODE ((uint32_t)(0x00000000UL)) +#define MXC_V_AES_CTRL_DECRYPT_MODE ((uint32_t)(0x00000001UL)) + +#define MXC_S_AES_CTRL_ENCRYPT_MODE ((uint32_t)(MXC_V_AES_CTRL_ENCRYPT_MODE << MXC_F_AES_CTRL_CRYPT_MODE_POS)) +#define MXC_S_AES_CTRL_DECRYPT_MODE ((uint32_t)(MXC_V_AES_CTRL_DECRYPT_MODE << MXC_F_AES_CTRL_CRYPT_MODE_POS)) + +#define MXC_V_AES_CTRL_CALC_NEW_EXP_KEY ((uint32_t)(0x00000000UL)) +#define MXC_V_AES_CTRL_USE_LAST_EXP_KEY ((uint32_t)(0x00000001UL)) + +#define MXC_S_AES_CTRL_CALC_NEW_EXP_KEY ((uint32_t)(MXC_V_AES_CTRL_CALC_NEW_EXP_KEY << MXC_F_AES_CTRL_EXP_KEY_MODE_POS)) +#define MXC_S_AES_CTRL_USE_LAST_EXP_KEY ((uint32_t)(MXC_V_AES_CTRL_USE_LAST_EXP_KEY << MXC_F_AES_CTRL_EXP_KEY_MODE_POS)) + +#define MXC_V_AES_CTRL_KEY_SIZE_128 ((uint32_t)(0x00000000UL)) +#define MXC_V_AES_CTRL_KEY_SIZE_192 ((uint32_t)(0x00000001UL)) +#define MXC_V_AES_CTRL_KEY_SIZE_256 ((uint32_t)(0x00000002UL)) + +#define MXC_S_AES_CTRL_KEY_SIZE_128 ((uint32_t)(MXC_V_AES_CTRL_KEY_SIZE_128 << MXC_F_AES_CTRL_KEY_SIZE_POS)) +#define MXC_S_AES_CTRL_KEY_SIZE_192 ((uint32_t)(MXC_V_AES_CTRL_KEY_SIZE_192 << MXC_F_AES_CTRL_KEY_SIZE_POS)) +#define MXC_S_AES_CTRL_KEY_SIZE_256 ((uint32_t)(MXC_V_AES_CTRL_KEY_SIZE_256 << MXC_F_AES_CTRL_KEY_SIZE_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_AES_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/clkman_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/clkman_regs.h new file mode 100644 index 0000000..27908fd --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/clkman_regs.h @@ -0,0 +1,436 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_CLKMAN_REGS_H_ +#define _MXC_CLKMAN_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t clk_config; /* 0x0000 System Clock Configuration */ + __IO uint32_t clk_ctrl; /* 0x0004 System Clock Controls */ + __IO uint32_t intfl; /* 0x0008 Interrupt Flags */ + __IO uint32_t inten; /* 0x000C Interrupt Enable/Disable Controls */ + __IO uint32_t trim_calc; /* 0x0010 Trim Calculation Controls */ + __IO uint32_t i2c_timer_ctrl; /* 0x0014 I2C Timer Control */ + __IO uint32_t cm4_start_clk_en0; /* 0x0018 CM4 Start Clock on Interrupt Enable 0 */ + __IO uint32_t cm4_start_clk_en1; /* 0x001C CM4 Start Clock on Interrupt Enable 1 */ + __IO uint32_t cm4_start_clk_en2; /* 0x0020 CM4 Start Clock on Interrupt Enable 2 */ + __I uint32_t rsv024[7]; /* 0x0024-0x003C */ + __IO uint32_t sys_clk_ctrl_0_cm4; /* 0x0040 Control Settings for CLK0 - Cortex M4 Clock */ + __IO uint32_t sys_clk_ctrl_1_sync; /* 0x0044 Control Settings for CLK1 - Synchronizer Clock */ + __IO uint32_t sys_clk_ctrl_2_spix; /* 0x0048 Control Settings for CLK2 - SPI XIP Clock */ + __IO uint32_t sys_clk_ctrl_3_prng; /* 0x004C Control Settings for CLK3 - PRNG Clock */ + __IO uint32_t sys_clk_ctrl_4_wdt0; /* 0x0050 Control Settings for CLK4 - Watchdog Timer 0 */ + __IO uint32_t sys_clk_ctrl_5_wdt1; /* 0x0054 Control Settings for CLK5 - Watchdog Timer 1 */ + __IO uint32_t sys_clk_ctrl_6_gpio; /* 0x0058 Control Settings for CLK6 - Clock for GPIO Ports */ + __IO uint32_t sys_clk_ctrl_7_pt; /* 0x005C Control Settings for CLK7 - Source Clock for All Pulse Trains */ + __IO uint32_t sys_clk_ctrl_8_uart; /* 0x0060 Control Settings for CLK8 - Source Clock for All UARTs */ + __IO uint32_t sys_clk_ctrl_9_i2cm; /* 0x0064 Control Settings for CLK9 - Source Clock for All I2C Masters */ + __IO uint32_t sys_clk_ctrl_10_i2cs; /* 0x0068 Control Settings for CLK10 - Source Clock for I2C Slave */ + __IO uint32_t sys_clk_ctrl_11_spi0; /* 0x006C Control Settings for CLK11 - SPI Master 0 */ + __IO uint32_t sys_clk_ctrl_12_spi1; /* 0x0070 Control Settings for CLK12 - SPI Master 1 */ + __IO uint32_t sys_clk_ctrl_13_spi2; /* 0x0074 Control Settings for CLK13 - SPI Master 2 */ + __I uint32_t rsv078; /* 0x0078 */ + __IO uint32_t sys_clk_ctrl_15_owm; /* 0x007C Control Settings for CLK15 - 1-Wire Master Clock */ + __IO uint32_t sys_clk_ctrl_16_spis; /* 0x0080 Control Settings for CLK16 - SPI Slave Clock */ + __I uint32_t rsv084[31]; /* 0x0084-0x00FC */ + __IO uint32_t crypt_clk_ctrl_0_aes; /* 0x0100 Control Settings for Crypto Clock 0 - AES */ + __IO uint32_t crypt_clk_ctrl_1_maa; /* 0x0104 Control Settings for Crypto Clock 1 - MAA */ + __IO uint32_t crypt_clk_ctrl_2_prng; /* 0x0108 Control Settings for Crypto Clock 2 - PRNG */ + __I uint32_t rsv10C[13]; /* 0x010C-0x013C */ + __IO uint32_t clk_gate_ctrl0; /* 0x0140 Dynamic Clock Gating Control Register 0 */ + __IO uint32_t clk_gate_ctrl1; /* 0x0144 Dynamic Clock Gating Control Register 1 */ + __IO uint32_t clk_gate_ctrl2; /* 0x0148 Dynamic Clock Gating Control Register 2 */ +} mxc_clkman_regs_t; + + +/* + Register offsets for module CLKMAN. +*/ + +#define MXC_R_CLKMAN_OFFS_CLK_CONFIG ((uint32_t)0x00000000UL) +#define MXC_R_CLKMAN_OFFS_CLK_CTRL ((uint32_t)0x00000004UL) +#define MXC_R_CLKMAN_OFFS_INTFL ((uint32_t)0x00000008UL) +#define MXC_R_CLKMAN_OFFS_INTEN ((uint32_t)0x0000000CUL) +#define MXC_R_CLKMAN_OFFS_TRIM_CALC ((uint32_t)0x00000010UL) +#define MXC_R_CLKMAN_OFFS_I2C_TIMER_CTRL ((uint32_t)0x00000014UL) +#define MXC_R_CLKMAN_OFFS_CM4_START_CLK_EN0 ((uint32_t)0x00000018UL) +#define MXC_R_CLKMAN_OFFS_CM4_START_CLK_EN1 ((uint32_t)0x0000001CUL) +#define MXC_R_CLKMAN_OFFS_CM4_START_CLK_EN2 ((uint32_t)0x00000020UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_0_CM4 ((uint32_t)0x00000040UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_1_SYNC ((uint32_t)0x00000044UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_2_SPIX ((uint32_t)0x00000048UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_3_PRNG ((uint32_t)0x0000004CUL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_4_WDT0 ((uint32_t)0x00000050UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_5_WDT1 ((uint32_t)0x00000054UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_6_GPIO ((uint32_t)0x00000058UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_7_PT ((uint32_t)0x0000005CUL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_8_UART ((uint32_t)0x00000060UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_9_I2CM ((uint32_t)0x00000064UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_10_I2CS ((uint32_t)0x00000068UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_11_SPI0 ((uint32_t)0x0000006CUL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_12_SPI1 ((uint32_t)0x00000070UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_13_SPI2 ((uint32_t)0x00000074UL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_15_OWM ((uint32_t)0x0000007CUL) +#define MXC_R_CLKMAN_OFFS_SYS_CLK_CTRL_16_SPIS ((uint32_t)0x00000080UL) +#define MXC_R_CLKMAN_OFFS_CRYPT_CLK_CTRL_0_AES ((uint32_t)0x00000100UL) +#define MXC_R_CLKMAN_OFFS_CRYPT_CLK_CTRL_1_MAA ((uint32_t)0x00000104UL) +#define MXC_R_CLKMAN_OFFS_CRYPT_CLK_CTRL_2_PRNG ((uint32_t)0x00000108UL) +#define MXC_R_CLKMAN_OFFS_CLK_GATE_CTRL0 ((uint32_t)0x00000140UL) +#define MXC_R_CLKMAN_OFFS_CLK_GATE_CTRL1 ((uint32_t)0x00000144UL) +#define MXC_R_CLKMAN_OFFS_CLK_GATE_CTRL2 ((uint32_t)0x00000148UL) + + +/* + Field positions and masks for module CLKMAN. +*/ + +#define MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE_POS 0 +#define MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE_POS)) +#define MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS 4 +#define MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) + +#define MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_POS 0 +#define MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_ENABLE_POS 4 +#define MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_ENABLE_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_SELECT_POS 5 +#define MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_SELECT ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_SELECT_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE_POS 8 +#define MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_RTOS_MODE_POS 12 +#define MXC_F_CLKMAN_CLK_CTRL_RTOS_MODE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_RTOS_MODE_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_CPU_DYNAMIC_CLOCK_POS 13 +#define MXC_F_CLKMAN_CLK_CTRL_CPU_DYNAMIC_CLOCK ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_CPU_DYNAMIC_CLOCK_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE_POS 16 +#define MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS 17 +#define MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE_POS 20 +#define MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS 21 +#define MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS)) +#define MXC_F_CLKMAN_CLK_CTRL_ADC_CLOCK_ENABLE_POS 24 +#define MXC_F_CLKMAN_CLK_CTRL_ADC_CLOCK_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_CLK_CTRL_ADC_CLOCK_ENABLE_POS)) + +#define MXC_F_CLKMAN_INTFL_CRYPTO_STABLE_POS 0 +#define MXC_F_CLKMAN_INTFL_CRYPTO_STABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_INTFL_CRYPTO_STABLE_POS)) +#define MXC_F_CLKMAN_INTFL_SYS_RO_STABLE_POS 1 +#define MXC_F_CLKMAN_INTFL_SYS_RO_STABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_INTFL_SYS_RO_STABLE_POS)) + +#define MXC_F_CLKMAN_INTEN_CRYPTO_STABLE_POS 0 +#define MXC_F_CLKMAN_INTEN_CRYPTO_STABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_INTEN_CRYPTO_STABLE_POS)) +#define MXC_F_CLKMAN_INTEN_SYS_RO_STABLE_POS 1 +#define MXC_F_CLKMAN_INTEN_SYS_RO_STABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_INTEN_SYS_RO_STABLE_POS)) + +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CLK_SEL_POS 0 +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CLK_SEL ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_TRIM_CALC_TRIM_CLK_SEL_POS)) +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_START_POS 1 +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_START ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_START_POS)) +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_COMPLETED_POS 2 +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_COMPLETED ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_COMPLETED_POS)) +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_ENABLE_POS 3 +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_ENABLE ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_TRIM_CALC_TRIM_ENABLE_POS)) +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_LENGTH_POS 4 +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_LENGTH ((uint32_t)(0x00000FFFUL << MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_LENGTH_POS)) +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_RESULTS_POS 16 +#define MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_RESULTS ((uint32_t)(0x00003FFFUL << MXC_F_CLKMAN_TRIM_CALC_TRIM_CALC_RESULTS_POS)) + +#define MXC_F_CLKMAN_I2C_TIMER_CTRL_I2C_1MS_TIMER_EN_POS 0 +#define MXC_F_CLKMAN_I2C_TIMER_CTRL_I2C_1MS_TIMER_EN ((uint32_t)(0x00000001UL << MXC_F_CLKMAN_I2C_TIMER_CTRL_I2C_1MS_TIMER_EN_POS)) + +#define MXC_F_CLKMAN_CM4_START_CLK_EN0_INTS_POS 0 +#define MXC_F_CLKMAN_CM4_START_CLK_EN0_INTS ((uint32_t)(0xFFFFFFFFUL << MXC_F_CLKMAN_CM4_START_CLK_EN0_INTS_POS)) + +#define MXC_F_CLKMAN_CM4_START_CLK_EN1_INTS_POS 0 +#define MXC_F_CLKMAN_CM4_START_CLK_EN1_INTS ((uint32_t)(0xFFFFFFFFUL << MXC_F_CLKMAN_CM4_START_CLK_EN1_INTS_POS)) + +#define MXC_F_CLKMAN_CM4_START_CLK_EN2_INTS_POS 0 +#define MXC_F_CLKMAN_CM4_START_CLK_EN2_INTS ((uint32_t)(0xFFFFFFFFUL << MXC_F_CLKMAN_CM4_START_CLK_EN2_INTS_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_1_SYNC_SYNC_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_1_SYNC_SYNC_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_1_SYNC_SYNC_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_2_SPIX_SPIX_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_2_SPIX_SPIX_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_2_SPIX_SPIX_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_3_PRNG_PRNG_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_3_PRNG_PRNG_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_3_PRNG_PRNG_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_4_WDT0_WATCHDOG0_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_4_WDT0_WATCHDOG0_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_4_WDT0_WATCHDOG0_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_5_WDT1_WATCHDOG1_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_5_WDT1_WATCHDOG1_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_5_WDT1_WATCHDOG1_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_6_GPIO_GPIO_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_6_GPIO_GPIO_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_6_GPIO_GPIO_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_7_PT_PULSE_TRAIN_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_7_PT_PULSE_TRAIN_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_7_PT_PULSE_TRAIN_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_8_UART_UART_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_8_UART_UART_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_8_UART_UART_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_9_I2CM_I2CM_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_9_I2CM_I2CM_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_9_I2CM_I2CM_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_10_I2CS_I2CS_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_10_I2CS_I2CS_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_10_I2CS_I2CS_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_11_SPI0_SPI0_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_11_SPI0_SPI0_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_11_SPI0_SPI0_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_12_SPI1_SPI1_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_12_SPI1_SPI1_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_12_SPI1_SPI1_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_13_SPI2_SPI2_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_13_SPI2_SPI2_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_13_SPI2_SPI2_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_15_OWM_OWM_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_15_OWM_OWM_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_15_OWM_OWM_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_SYS_CLK_CTRL_16_SPIS_SPIS_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_SYS_CLK_CTRL_16_SPIS_SPIS_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_SYS_CLK_CTRL_16_SPIS_SPIS_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_CRYPT_CLK_CTRL_0_AES_AES_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_CRYPT_CLK_CTRL_0_AES_AES_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_CRYPT_CLK_CTRL_0_AES_AES_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_CRYPT_CLK_CTRL_1_MAA_MAA_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_CRYPT_CLK_CTRL_1_MAA_MAA_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_CRYPT_CLK_CTRL_1_MAA_MAA_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_CRYPT_CLK_CTRL_2_PRNG_PRNG_CLK_SCALE_POS 0 +#define MXC_F_CLKMAN_CRYPT_CLK_CTRL_2_PRNG_PRNG_CLK_SCALE ((uint32_t)(0x0000000FUL << MXC_F_CLKMAN_CRYPT_CLK_CTRL_2_PRNG_PRNG_CLK_SCALE_POS)) + +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_CM4_CLK_GATER_POS 0 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_CM4_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_CM4_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_AHB32_CLK_GATER_POS 2 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_AHB32_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_AHB32_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER_POS 4 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_FLASH_CLK_GATER_POS 6 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_FLASH_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_FLASH_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SRAM_CLK_GATER_POS 8 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SRAM_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_SRAM_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_APB_BRIDGE_CLK_GATER_POS 10 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_APB_BRIDGE_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_APB_BRIDGE_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SYSMAN_CLK_GATER_POS 12 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SYSMAN_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_SYSMAN_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_PTP_CLK_GATER_POS 14 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_PTP_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_PTP_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SSB_MUX_CLK_GATER_POS 16 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SSB_MUX_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_SSB_MUX_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_PAD_CLK_GATER_POS 18 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_PAD_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_PAD_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SPIX_CLK_GATER_POS 20 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_SPIX_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_SPIX_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_PMU_CLK_GATER_POS 22 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_PMU_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_PMU_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_USB_CLK_GATER_POS 24 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_USB_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_USB_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_CRC_CLK_GATER_POS 26 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_CRC_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_CRC_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_TPU_CLK_GATER_POS 28 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_TPU_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_TPU_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_WATCHDOG0_CLK_GATER_POS 30 +#define MXC_F_CLKMAN_CLK_GATE_CTRL0_WATCHDOG0_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL0_WATCHDOG0_CLK_GATER_POS)) + +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_WATCHDOG1_CLK_GATER_POS 0 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_WATCHDOG1_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_WATCHDOG1_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_GPIO_CLK_GATER_POS 2 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_GPIO_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_GPIO_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER0_CLK_GATER_POS 4 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER0_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER0_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER1_CLK_GATER_POS 6 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER1_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER1_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER2_CLK_GATER_POS 8 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER2_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER2_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER3_CLK_GATER_POS 10 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER3_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER3_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER4_CLK_GATER_POS 12 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER4_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER4_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER5_CLK_GATER_POS 14 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER5_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_TIMER5_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_PULSETRAIN_CLK_GATER_POS 16 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_PULSETRAIN_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_PULSETRAIN_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_UART0_CLK_GATER_POS 18 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_UART0_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_UART0_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_UART1_CLK_GATER_POS 20 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_UART1_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_UART1_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_UART2_CLK_GATER_POS 22 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_UART2_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_UART2_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_I2CM0_CLK_GATER_POS 26 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_I2CM0_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_I2CM0_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_I2CM1_CLK_GATER_POS 28 +#define MXC_F_CLKMAN_CLK_GATE_CTRL1_I2CM1_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL1_I2CM1_CLK_GATER_POS)) + +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_I2CS_CLK_GATER_POS 0 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_I2CS_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_I2CS_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI0_CLK_GATER_POS 2 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI0_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI0_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI1_CLK_GATER_POS 4 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI1_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI1_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI2_CLK_GATER_POS 6 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI2_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_SPI2_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_OWM_CLK_GATER_POS 10 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_OWM_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_OWM_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_ADC_CLK_GATER_POS 12 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_ADC_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_ADC_CLK_GATER_POS)) +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPIS_CLK_GATER_POS 14 +#define MXC_F_CLKMAN_CLK_GATE_CTRL2_SPIS_CLK_GATER ((uint32_t)(0x00000003UL << MXC_F_CLKMAN_CLK_GATE_CTRL2_SPIS_CLK_GATER_POS)) + + + +/* + Field values and shifted values for module CLKMAN. +*/ + +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_8_CLOCKS ((uint32_t)(0x00000000UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_9_CLOCKS ((uint32_t)(0x00000001UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_10_CLOCKS ((uint32_t)(0x00000002UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_11_CLOCKS ((uint32_t)(0x00000003UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_12_CLOCKS ((uint32_t)(0x00000004UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_13_CLOCKS ((uint32_t)(0x00000005UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_14_CLOCKS ((uint32_t)(0x00000006UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_15_CLOCKS ((uint32_t)(0x00000007UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_16_CLOCKS ((uint32_t)(0x00000008UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_17_CLOCKS ((uint32_t)(0x00000009UL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_18_CLOCKS ((uint32_t)(0x0000000AUL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_19_CLOCKS ((uint32_t)(0x0000000BUL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_20_CLOCKS ((uint32_t)(0x0000000CUL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_21_CLOCKS ((uint32_t)(0x0000000DUL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_22_CLOCKS ((uint32_t)(0x0000000EUL)) +#define MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_23_CLOCKS ((uint32_t)(0x0000000FUL)) + +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_8_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_8_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_9_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_9_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_10_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_10_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_11_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_11_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_12_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_12_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_13_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_13_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_14_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_14_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_15_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_15_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_16_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_16_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_17_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_17_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_18_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_18_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_19_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_19_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_20_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_20_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_21_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_21_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_22_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_22_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) +#define MXC_S_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_23_CLOCKS ((uint32_t)(MXC_V_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_2_EXP_23_CLOCKS << MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_STABILITY_COUNT_POS)) + +#define MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO_DIV_2 ((uint32_t)(0x00000000UL)) +#define MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO ((uint32_t)(0x00000001UL)) + +#define MXC_S_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO_DIV_2 ((uint32_t)(MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO_DIV_2 << MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_POS)) +#define MXC_S_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO ((uint32_t)(MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO << MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_POS)) + +#define MXC_V_CLKMAN_WDT0_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT0 ((uint32_t)(0x00000000UL)) +#define MXC_V_CLKMAN_WDT0_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR ((uint32_t)(0x00000001UL)) +#define MXC_V_CLKMAN_WDT0_CLOCK_SELECT_96MHZ_OSCILLATOR ((uint32_t)(0x00000002UL)) +#define MXC_V_CLKMAN_WDT0_CLOCK_SELECT_NANO_RING_OSCILLATOR ((uint32_t)(0x00000003UL)) + +#define MXC_S_CLKMAN_WDT0_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT0 ((uint32_t)(MXC_V_CLKMAN_WDT0_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT0 << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS)) +#define MXC_S_CLKMAN_WDT0_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR ((uint32_t)(MXC_V_CLKMAN_WDT0_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS)) +#define MXC_S_CLKMAN_WDT0_CLOCK_SELECT_96MHZ_OSCILLATOR ((uint32_t)(MXC_V_CLKMAN_WDT0_CLOCK_SELECT_96MHZ_OSCILLATOR << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS)) +#define MXC_S_CLKMAN_WDT0_CLOCK_SELECT_NANO_RING_OSCILLATOR ((uint32_t)(MXC_V_CLKMAN_WDT0_CLOCK_SELECT_NANO_RING_OSCILLATOR << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS)) + +#define MXC_V_CLKMAN_WDT1_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT1 ((uint32_t)(0x00000000UL)) +#define MXC_V_CLKMAN_WDT1_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR ((uint32_t)(0x00000001UL)) +#define MXC_V_CLKMAN_WDT1_CLOCK_SELECT_96MHZ_OSCILLATOR ((uint32_t)(0x00000002UL)) +#define MXC_V_CLKMAN_WDT1_CLOCK_SELECT_NANO_RING_OSCILLATOR ((uint32_t)(0x00000003UL)) + +#define MXC_S_CLKMAN_WDT1_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT1 ((uint32_t)(MXC_V_CLKMAN_WDT1_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT1 << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS)) +#define MXC_S_CLKMAN_WDT1_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR ((uint32_t)(MXC_V_CLKMAN_WDT1_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS)) +#define MXC_S_CLKMAN_WDT1_CLOCK_SELECT_96MHZ_OSCILLATOR ((uint32_t)(MXC_V_CLKMAN_WDT1_CLOCK_SELECT_96MHZ_OSCILLATOR << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS)) +#define MXC_S_CLKMAN_WDT1_CLOCK_SELECT_NANO_RING_OSCILLATOR ((uint32_t)(MXC_V_CLKMAN_WDT1_CLOCK_SELECT_NANO_RING_OSCILLATOR << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS)) + +#define MXC_V_CLKMAN_CLK_SCALE_DISABLED ((uint32_t)(0x00000000UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_1 ((uint32_t)(0x00000001UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_2 ((uint32_t)(0x00000002UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_4 ((uint32_t)(0x00000003UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_8 ((uint32_t)(0x00000004UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_16 ((uint32_t)(0x00000005UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_32 ((uint32_t)(0x00000006UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_64 ((uint32_t)(0x00000007UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_128 ((uint32_t)(0x00000008UL)) +#define MXC_V_CLKMAN_CLK_SCALE_DIV_256 ((uint32_t)(0x00000009UL)) + +#define MXC_S_CLKMAN_CLK_SCALE_DISABLED ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DISABLED << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_1 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_1 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_2 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_2 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_4 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_4 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_8 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_8 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_16 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_16 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_32 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_32 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_64 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_64 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_128 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_128 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) +#define MXC_S_CLKMAN_CLK_SCALE_DIV_256 ((uint32_t)(MXC_V_CLKMAN_CLK_SCALE_DIV_256 << MXC_F_CLKMAN_SYS_CLK_CTRL_0_CM4_CM4_CLK_SCALE_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_CLKMAN_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis.h new file mode 100644 index 0000000..68bee5b --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis.h @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_CMSIS_H +#define MBED_CMSIS_H + +#include "max32625.h" +#include "cmsis_nvic.h" + +#endif + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis_nvic.c b/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis_nvic.c new file mode 100644 index 0000000..b3dbada --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis_nvic.c @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "cmsis_nvic.h" + +#if defined(TOOLCHAIN_GCC_ARM) || defined(TOOLCHAIN_ARM_STD) +__attribute__((aligned(256))) +#endif +#if defined(TOOLCHAIN_IAR) +#pragma data_alignment=256 +#endif +static void (*ramVectorTable[MXC_IRQ_COUNT])(void); + +void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ + uint32_t *vectors = (uint32_t*)SCB->VTOR; + uint32_t i; + + // Copy and switch to dynamic vectors if the first time called + if (SCB->VTOR != (uint32_t)ramVectorTable) { + uint32_t *old_vectors = (uint32_t*)SCB->VTOR; + vectors = (uint32_t*)ramVectorTable; + for (i = 0; i < NVIC_NUM_VECTORS; i++) { + vectors[i] = old_vectors[i]; + } + SCB->VTOR = (uint32_t)ramVectorTable; + } + vectors[IRQn + NVIC_USER_IRQ_OFFSET] = vector; +} + +uint32_t NVIC_GetVector(IRQn_Type IRQn) +{ + uint32_t *vectors = (uint32_t*)SCB->VTOR; + return vectors[IRQn + NVIC_USER_IRQ_OFFSET]; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis_nvic.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis_nvic.h new file mode 100644 index 0000000..5f44cc5 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/cmsis_nvic.h @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_CMSIS_NVIC_H +#define MBED_CMSIS_NVIC_H + +#include "cmsis.h" + +#define NVIC_NUM_VECTORS MXC_IRQ_COUNT +#define NVIC_USER_IRQ_OFFSET 16 + +#ifdef __cplusplus +extern "C" { +#endif + +void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); +uint32_t NVIC_GetVector(IRQn_Type IRQn); + +#ifdef __cplusplus +} +#endif + +#endif /* MBED_CMSIS_NVIC_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/crc_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/crc_regs.h new file mode 100644 index 0000000..0538800 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/crc_regs.h @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_CRC_REGS_H_ +#define _MXC_CRC_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t reseed; /* 0x0000 CRC-16/CRC-32 Reseed Controls */ + __IO uint32_t seed16; /* 0x0004 Reseed Value for CRC-16 Calculations */ + __IO uint32_t seed32; /* 0x0008 Reseed Value for CRC-32 Calculations */ +} mxc_crc_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t value16[512]; /* 0x0000-0x07FC Write Next CRC-16 Data Value / Read CRC-16 Result Value */ + __IO uint32_t value32[512]; /* 0x0800-0x0FFC Write Next CRC-32 Data Value / Read CRC-32 Result Value */ +} mxc_crc_data_regs_t; + + +/* + Register offsets for module CRC. +*/ + +#define MXC_R_CRC_OFFS_RESEED ((uint32_t)0x00000000UL) +#define MXC_R_CRC_OFFS_SEED16 ((uint32_t)0x00000004UL) +#define MXC_R_CRC_OFFS_SEED32 ((uint32_t)0x00000008UL) +#define MXC_R_CRC_DATA_OFFS_VALUE16 ((uint32_t)0x00000000UL) +#define MXC_R_CRC_DATA_OFFS_VALUE32 ((uint32_t)0x00000800UL) + + +/* + Field positions and masks for module CRC. +*/ + +#define MXC_F_CRC_RESEED_CRC16_POS 0 +#define MXC_F_CRC_RESEED_CRC16 ((uint32_t)(0x00000001UL << MXC_F_CRC_RESEED_CRC16_POS)) +#define MXC_F_CRC_RESEED_CRC32_POS 1 +#define MXC_F_CRC_RESEED_CRC32 ((uint32_t)(0x00000001UL << MXC_F_CRC_RESEED_CRC32_POS)) +#define MXC_F_CRC_RESEED_REV_ENDIAN16_POS 4 +#define MXC_F_CRC_RESEED_REV_ENDIAN16 ((uint32_t)(0x00000001UL << MXC_F_CRC_RESEED_REV_ENDIAN16_POS)) +#define MXC_F_CRC_RESEED_REV_ENDIAN32_POS 5 +#define MXC_F_CRC_RESEED_REV_ENDIAN32 ((uint32_t)(0x00000001UL << MXC_F_CRC_RESEED_REV_ENDIAN32_POS)) +#define MXC_F_CRC_RESEED_CCITT_MODE_POS 8 +#define MXC_F_CRC_RESEED_CCITT_MODE ((uint32_t)(0x00000001UL << MXC_F_CRC_RESEED_CCITT_MODE_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_CRC_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/flc_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/flc_regs.h new file mode 100644 index 0000000..da1b949 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/flc_regs.h @@ -0,0 +1,298 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_FLC_REGS_H_ +#define _MXC_FLC_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +#define MXC_V_FLC_ERASE_CODE_PAGE_ERASE ((uint8_t)0x55) +#define MXC_V_FLC_ERASE_CODE_MASS_ERASE ((uint8_t)0xAA) +#define MXC_V_FLC_FLSH_UNLOCK_KEY ((uint8_t)0x2) + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t faddr; /* 0x0000 Flash Operation Address */ + __IO uint32_t fckdiv; /* 0x0004 Flash Clock Pulse Divisor */ + __IO uint32_t ctrl; /* 0x0008 Flash Control Register */ + __I uint32_t rsv00C[6]; /* 0x000C-0x0020 */ + __IO uint32_t intr; /* 0x0024 Flash Controller Interrupt Flags and Enable/Disable 0 */ + __I uint32_t rsv028[2]; /* 0x0028-0x002C */ + __IO uint32_t fdata; /* 0x0030 Flash Operation Data Register */ + __I uint32_t rsv034[7]; /* 0x0034-0x004C */ + __IO uint32_t perform; /* 0x0050 Flash Performance Settings */ + __IO uint32_t tacc; /* 0x0054 Flash Read Cycle Config */ + __IO uint32_t tprog; /* 0x0058 Flash Write Cycle Config */ + __I uint32_t rsv05C[9]; /* 0x005C-0x007C */ + __IO uint32_t status; /* 0x0080 Security Status Flags */ + __I uint32_t rsv084; /* 0x0084 */ + __IO uint32_t security; /* 0x0088 Flash Controller Security Settings */ + __I uint32_t rsv08C[4]; /* 0x008C-0x0098 */ + __IO uint32_t bypass; /* 0x009C Status Flags for DSB Operations */ + __I uint32_t rsv0A0[24]; /* 0x00A0-0x00FC */ + __IO uint32_t user_option; /* 0x0100 Used to set DSB Access code and Auto-Lock in info block */ + __I uint32_t rsv104[15]; /* 0x0104-0x013C */ + __IO uint32_t ctrl2; /* 0x0140 Flash Control Register 2 */ + __IO uint32_t intfl1; /* 0x0144 Interrupt Flags Register 1 */ + __IO uint32_t inten1; /* 0x0148 Interrupt Enable/Disable Register 1 */ + __I uint32_t rsv14C[9]; /* 0x014C-0x016C */ + __IO uint32_t bl_ctrl; /* 0x0170 Bootloader Control Register */ + __IO uint32_t twk; /* 0x0174 PDM33 Register */ + __I uint32_t rsv178; /* 0x0178 */ + __IO uint32_t slm; /* 0x017C Sleep Mode Register */ + __I uint32_t rsv180[32]; /* 0x0180-0x01FC */ + __IO uint32_t disable_xr0; /* 0x0200 Disable Flash Page Exec/Read Register 0 */ + __IO uint32_t disable_xr1; /* 0x0204 Disable Flash Page Exec/Read Register 1 */ + __IO uint32_t disable_xr2; /* 0x0208 Disable Flash Page Exec/Read Register 2 */ + __IO uint32_t disable_xr3; /* 0x020C Disable Flash Page Exec/Read Register 3 */ + __IO uint32_t disable_xr4; /* 0x0210 Disable Flash Page Exec/Read Register 4 */ + __IO uint32_t disable_xr5; /* 0x0214 Disable Flash Page Exec/Read Register 5 */ + __IO uint32_t disable_xr6; /* 0x0218 Disable Flash Page Exec/Read Register 6 */ + __IO uint32_t disable_xr7; /* 0x021C Disable Flash Page Exec/Read Register 7 */ + __I uint32_t rsv220[56]; /* 0x0220-0x02FC */ + __IO uint32_t disable_we0; /* 0x0300 Disable Flash Page Write/Erase Register 0 */ + __IO uint32_t disable_we1; /* 0x0304 Disable Flash Page Write/Erase Register 1 */ + __IO uint32_t disable_we2; /* 0x0308 Disable Flash Page Write/Erase Register 2 */ + __IO uint32_t disable_we3; /* 0x030C Disable Flash Page Write/Erase Register 3 */ + __IO uint32_t disable_we4; /* 0x0310 Disable Flash Page Write/Erase Register 4 */ + __IO uint32_t disable_we5; /* 0x0314 Disable Flash Page Write/Erase Register 5 */ + __IO uint32_t disable_we6; /* 0x0318 Disable Flash Page Write/Erase Register 6 */ + __IO uint32_t disable_we7; /* 0x031C Disable Flash Page Write/Erase Register 7 */ +} mxc_flc_regs_t; + + +/* + Register offsets for module FLC. +*/ + +#define MXC_R_FLC_OFFS_FADDR ((uint32_t)0x00000000UL) +#define MXC_R_FLC_OFFS_FCKDIV ((uint32_t)0x00000004UL) +#define MXC_R_FLC_OFFS_CTRL ((uint32_t)0x00000008UL) +#define MXC_R_FLC_OFFS_INTR ((uint32_t)0x00000024UL) +#define MXC_R_FLC_OFFS_FDATA ((uint32_t)0x00000030UL) +#define MXC_R_FLC_OFFS_PERFORM ((uint32_t)0x00000050UL) +#define MXC_R_FLC_OFFS_TACC ((uint32_t)0x00000054UL) +#define MXC_R_FLC_OFFS_TPROG ((uint32_t)0x00000058UL) +#define MXC_R_FLC_OFFS_STATUS ((uint32_t)0x00000080UL) +#define MXC_R_FLC_OFFS_SECURITY ((uint32_t)0x00000088UL) +#define MXC_R_FLC_OFFS_BYPASS ((uint32_t)0x0000009CUL) +#define MXC_R_FLC_OFFS_USER_OPTION ((uint32_t)0x00000100UL) +#define MXC_R_FLC_OFFS_CTRL2 ((uint32_t)0x00000140UL) +#define MXC_R_FLC_OFFS_INTFL1 ((uint32_t)0x00000144UL) +#define MXC_R_FLC_OFFS_INTEN1 ((uint32_t)0x00000148UL) +#define MXC_R_FLC_OFFS_BL_CTRL ((uint32_t)0x00000170UL) +#define MXC_R_FLC_OFFS_TWK ((uint32_t)0x00000174UL) +#define MXC_R_FLC_OFFS_SLM ((uint32_t)0x0000017CUL) +#define MXC_R_FLC_OFFS_DISABLE_XR0 ((uint32_t)0x00000200UL) +#define MXC_R_FLC_OFFS_DISABLE_XR1 ((uint32_t)0x00000204UL) +#define MXC_R_FLC_OFFS_DISABLE_XR2 ((uint32_t)0x00000208UL) +#define MXC_R_FLC_OFFS_DISABLE_XR3 ((uint32_t)0x0000020CUL) +#define MXC_R_FLC_OFFS_DISABLE_XR4 ((uint32_t)0x00000210UL) +#define MXC_R_FLC_OFFS_DISABLE_XR5 ((uint32_t)0x00000214UL) +#define MXC_R_FLC_OFFS_DISABLE_XR6 ((uint32_t)0x00000218UL) +#define MXC_R_FLC_OFFS_DISABLE_XR7 ((uint32_t)0x0000021CUL) +#define MXC_R_FLC_OFFS_DISABLE_WE0 ((uint32_t)0x00000300UL) +#define MXC_R_FLC_OFFS_DISABLE_WE1 ((uint32_t)0x00000304UL) +#define MXC_R_FLC_OFFS_DISABLE_WE2 ((uint32_t)0x00000308UL) +#define MXC_R_FLC_OFFS_DISABLE_WE3 ((uint32_t)0x0000030CUL) +#define MXC_R_FLC_OFFS_DISABLE_WE4 ((uint32_t)0x00000310UL) +#define MXC_R_FLC_OFFS_DISABLE_WE5 ((uint32_t)0x00000314UL) +#define MXC_R_FLC_OFFS_DISABLE_WE6 ((uint32_t)0x00000318UL) +#define MXC_R_FLC_OFFS_DISABLE_WE7 ((uint32_t)0x0000031CUL) + + +/* + Field positions and masks for module FLC. +*/ + +#define MXC_F_FLC_FADDR_FADDR_POS 0 +#define MXC_F_FLC_FADDR_FADDR ((uint32_t)(0x003FFFFFUL << MXC_F_FLC_FADDR_FADDR_POS)) + +#define MXC_F_FLC_FCKDIV_FCKDIV_POS 0 +#define MXC_F_FLC_FCKDIV_FCKDIV ((uint32_t)(0x0000007FUL << MXC_F_FLC_FCKDIV_FCKDIV_POS)) +#define MXC_F_FLC_FCKDIV_AUTO_FCKDIV_RESULT_POS 16 +#define MXC_F_FLC_FCKDIV_AUTO_FCKDIV_RESULT ((uint32_t)(0x0000FFFFUL << MXC_F_FLC_FCKDIV_AUTO_FCKDIV_RESULT_POS)) + +#define MXC_F_FLC_CTRL_WRITE_POS 0 +#define MXC_F_FLC_CTRL_WRITE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_WRITE_POS)) +#define MXC_F_FLC_CTRL_MASS_ERASE_POS 1 +#define MXC_F_FLC_CTRL_MASS_ERASE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_MASS_ERASE_POS)) +#define MXC_F_FLC_CTRL_PAGE_ERASE_POS 2 +#define MXC_F_FLC_CTRL_PAGE_ERASE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_PAGE_ERASE_POS)) +#define MXC_F_FLC_CTRL_ERASE_CODE_POS 8 +#define MXC_F_FLC_CTRL_ERASE_CODE ((uint32_t)(0x000000FFUL << MXC_F_FLC_CTRL_ERASE_CODE_POS)) +#define MXC_F_FLC_CTRL_INFO_BLOCK_UNLOCK_POS 16 +#define MXC_F_FLC_CTRL_INFO_BLOCK_UNLOCK ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_INFO_BLOCK_UNLOCK_POS)) +#define MXC_F_FLC_CTRL_WRITE_ENABLE_POS 17 +#define MXC_F_FLC_CTRL_WRITE_ENABLE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_WRITE_ENABLE_POS)) +#define MXC_F_FLC_CTRL_PENDING_POS 24 +#define MXC_F_FLC_CTRL_PENDING ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_PENDING_POS)) +#define MXC_F_FLC_CTRL_INFO_BLOCK_VALID_POS 25 +#define MXC_F_FLC_CTRL_INFO_BLOCK_VALID ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_INFO_BLOCK_VALID_POS)) +#define MXC_F_FLC_CTRL_AUTO_INCRE_MODE_POS 27 +#define MXC_F_FLC_CTRL_AUTO_INCRE_MODE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL_AUTO_INCRE_MODE_POS)) +#define MXC_F_FLC_CTRL_FLSH_UNLOCK_POS 28 +#define MXC_F_FLC_CTRL_FLSH_UNLOCK ((uint32_t)(0x0000000FUL << MXC_F_FLC_CTRL_FLSH_UNLOCK_POS)) + +#define MXC_F_FLC_INTR_FINISHED_IF_POS 0 +#define MXC_F_FLC_INTR_FINISHED_IF ((uint32_t)(0x00000001UL << MXC_F_FLC_INTR_FINISHED_IF_POS)) +#define MXC_F_FLC_INTR_FAILED_IF_POS 1 +#define MXC_F_FLC_INTR_FAILED_IF ((uint32_t)(0x00000001UL << MXC_F_FLC_INTR_FAILED_IF_POS)) +#define MXC_F_FLC_INTR_FINISHED_IE_POS 8 +#define MXC_F_FLC_INTR_FINISHED_IE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTR_FINISHED_IE_POS)) +#define MXC_F_FLC_INTR_FAILED_IE_POS 9 +#define MXC_F_FLC_INTR_FAILED_IE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTR_FAILED_IE_POS)) +#define MXC_F_FLC_INTR_FAIL_FLAGS_POS 16 +#define MXC_F_FLC_INTR_FAIL_FLAGS ((uint32_t)(0x0000FFFFUL << MXC_F_FLC_INTR_FAIL_FLAGS_POS)) + +#define MXC_F_FLC_PERFORM_DELAY_SE_EN_POS 0 +#define MXC_F_FLC_PERFORM_DELAY_SE_EN ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_DELAY_SE_EN_POS)) +#define MXC_F_FLC_PERFORM_FAST_READ_MODE_EN_POS 8 +#define MXC_F_FLC_PERFORM_FAST_READ_MODE_EN ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_FAST_READ_MODE_EN_POS)) +#define MXC_F_FLC_PERFORM_EN_PREVENT_FAIL_POS 12 +#define MXC_F_FLC_PERFORM_EN_PREVENT_FAIL ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_EN_PREVENT_FAIL_POS)) +#define MXC_F_FLC_PERFORM_EN_BACK2BACK_RDS_POS 16 +#define MXC_F_FLC_PERFORM_EN_BACK2BACK_RDS ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_EN_BACK2BACK_RDS_POS)) +#define MXC_F_FLC_PERFORM_EN_BACK2BACK_WRS_POS 20 +#define MXC_F_FLC_PERFORM_EN_BACK2BACK_WRS ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_EN_BACK2BACK_WRS_POS)) +#define MXC_F_FLC_PERFORM_EN_MERGE_GRAB_GNT_POS 24 +#define MXC_F_FLC_PERFORM_EN_MERGE_GRAB_GNT ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_EN_MERGE_GRAB_GNT_POS)) +#define MXC_F_FLC_PERFORM_AUTO_TACC_POS 28 +#define MXC_F_FLC_PERFORM_AUTO_TACC ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_AUTO_TACC_POS)) +#define MXC_F_FLC_PERFORM_AUTO_CLKDIV_POS 29 +#define MXC_F_FLC_PERFORM_AUTO_CLKDIV ((uint32_t)(0x00000001UL << MXC_F_FLC_PERFORM_AUTO_CLKDIV_POS)) + +#define MXC_F_FLC_STATUS_JTAG_LOCK_WINDOW_POS 0 +#define MXC_F_FLC_STATUS_JTAG_LOCK_WINDOW ((uint32_t)(0x00000001UL << MXC_F_FLC_STATUS_JTAG_LOCK_WINDOW_POS)) +#define MXC_F_FLC_STATUS_JTAG_LOCK_STATIC_POS 1 +#define MXC_F_FLC_STATUS_JTAG_LOCK_STATIC ((uint32_t)(0x00000001UL << MXC_F_FLC_STATUS_JTAG_LOCK_STATIC_POS)) +#define MXC_F_FLC_STATUS_AUTO_LOCK_POS 3 +#define MXC_F_FLC_STATUS_AUTO_LOCK ((uint32_t)(0x00000001UL << MXC_F_FLC_STATUS_AUTO_LOCK_POS)) +#define MXC_F_FLC_STATUS_TRIM_UPDATE_DONE_POS 29 +#define MXC_F_FLC_STATUS_TRIM_UPDATE_DONE ((uint32_t)(0x00000001UL << MXC_F_FLC_STATUS_TRIM_UPDATE_DONE_POS)) +#define MXC_F_FLC_STATUS_INFO_BLOCK_VALID_POS 30 +#define MXC_F_FLC_STATUS_INFO_BLOCK_VALID ((uint32_t)(0x00000001UL << MXC_F_FLC_STATUS_INFO_BLOCK_VALID_POS)) + +#define MXC_F_FLC_SECURITY_DEBUG_DISABLE_POS 0 +#define MXC_F_FLC_SECURITY_DEBUG_DISABLE ((uint32_t)(0x000000FFUL << MXC_F_FLC_SECURITY_DEBUG_DISABLE_POS)) +#define MXC_F_FLC_SECURITY_MASS_ERASE_LOCK_POS 8 +#define MXC_F_FLC_SECURITY_MASS_ERASE_LOCK ((uint32_t)(0x0000000FUL << MXC_F_FLC_SECURITY_MASS_ERASE_LOCK_POS)) +#define MXC_F_FLC_SECURITY_DISABLE_AHB_WR_POS 16 +#define MXC_F_FLC_SECURITY_DISABLE_AHB_WR ((uint32_t)(0x0000000FUL << MXC_F_FLC_SECURITY_DISABLE_AHB_WR_POS)) +#define MXC_F_FLC_SECURITY_FLC_SETTINGS_LOCK_POS 24 +#define MXC_F_FLC_SECURITY_FLC_SETTINGS_LOCK ((uint32_t)(0x0000000FUL << MXC_F_FLC_SECURITY_FLC_SETTINGS_LOCK_POS)) +#define MXC_F_FLC_SECURITY_SECURITY_LOCK_POS 28 +#define MXC_F_FLC_SECURITY_SECURITY_LOCK ((uint32_t)(0x0000000FUL << MXC_F_FLC_SECURITY_SECURITY_LOCK_POS)) + +#define MXC_F_FLC_BYPASS_DESTRUCT_BYPASS_ERASE_POS 0 +#define MXC_F_FLC_BYPASS_DESTRUCT_BYPASS_ERASE ((uint32_t)(0x00000001UL << MXC_F_FLC_BYPASS_DESTRUCT_BYPASS_ERASE_POS)) +#define MXC_F_FLC_BYPASS_SUPERWIPE_ERASE_POS 1 +#define MXC_F_FLC_BYPASS_SUPERWIPE_ERASE ((uint32_t)(0x00000001UL << MXC_F_FLC_BYPASS_SUPERWIPE_ERASE_POS)) +#define MXC_F_FLC_BYPASS_DESTRUCT_BYPASS_COMPLETE_POS 2 +#define MXC_F_FLC_BYPASS_DESTRUCT_BYPASS_COMPLETE ((uint32_t)(0x00000001UL << MXC_F_FLC_BYPASS_DESTRUCT_BYPASS_COMPLETE_POS)) +#define MXC_F_FLC_BYPASS_SUPERWIPE_COMPLETE_POS 3 +#define MXC_F_FLC_BYPASS_SUPERWIPE_COMPLETE ((uint32_t)(0x00000001UL << MXC_F_FLC_BYPASS_SUPERWIPE_COMPLETE_POS)) + +#define MXC_F_FLC_CTRL2_FLASH_LVE_POS 0 +#define MXC_F_FLC_CTRL2_FLASH_LVE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL2_FLASH_LVE_POS)) +#define MXC_F_FLC_CTRL2_FRC_FCLK1_ON_POS 1 +#define MXC_F_FLC_CTRL2_FRC_FCLK1_ON ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL2_FRC_FCLK1_ON_POS)) +#define MXC_F_FLC_CTRL2_EN_WRITE_ALL_ZEROES_POS 3 +#define MXC_F_FLC_CTRL2_EN_WRITE_ALL_ZEROES ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL2_EN_WRITE_ALL_ZEROES_POS)) +#define MXC_F_FLC_CTRL2_EN_CHANGE_POS 4 +#define MXC_F_FLC_CTRL2_EN_CHANGE ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL2_EN_CHANGE_POS)) +#define MXC_F_FLC_CTRL2_SLOW_CLK_POS 5 +#define MXC_F_FLC_CTRL2_SLOW_CLK ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL2_SLOW_CLK_POS)) +#define MXC_F_FLC_CTRL2_ENABLE_RAM_HRESP_POS 6 +#define MXC_F_FLC_CTRL2_ENABLE_RAM_HRESP ((uint32_t)(0x00000001UL << MXC_F_FLC_CTRL2_ENABLE_RAM_HRESP_POS)) +#define MXC_F_FLC_CTRL2_BYPASS_AHB_FAIL_POS 8 +#define MXC_F_FLC_CTRL2_BYPASS_AHB_FAIL ((uint32_t)(0x000000FFUL << MXC_F_FLC_CTRL2_BYPASS_AHB_FAIL_POS)) + +#define MXC_F_FLC_INTFL1_SRAM_ADDR_WRAPPED_POS 0 +#define MXC_F_FLC_INTFL1_SRAM_ADDR_WRAPPED ((uint32_t)(0x00000001UL << MXC_F_FLC_INTFL1_SRAM_ADDR_WRAPPED_POS)) +#define MXC_F_FLC_INTFL1_INVALID_FLASH_ADDR_POS 1 +#define MXC_F_FLC_INTFL1_INVALID_FLASH_ADDR ((uint32_t)(0x00000001UL << MXC_F_FLC_INTFL1_INVALID_FLASH_ADDR_POS)) +#define MXC_F_FLC_INTFL1_FLASH_READ_LOCKED_POS 2 +#define MXC_F_FLC_INTFL1_FLASH_READ_LOCKED ((uint32_t)(0x00000001UL << MXC_F_FLC_INTFL1_FLASH_READ_LOCKED_POS)) +#define MXC_F_FLC_INTFL1_TRIM_UPDATE_DONE_POS 3 +#define MXC_F_FLC_INTFL1_TRIM_UPDATE_DONE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTFL1_TRIM_UPDATE_DONE_POS)) +#define MXC_F_FLC_INTFL1_FLC_STATE_DONE_POS 4 +#define MXC_F_FLC_INTFL1_FLC_STATE_DONE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTFL1_FLC_STATE_DONE_POS)) +#define MXC_F_FLC_INTFL1_FLC_PROG_COMPLETE_POS 5 +#define MXC_F_FLC_INTFL1_FLC_PROG_COMPLETE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTFL1_FLC_PROG_COMPLETE_POS)) + +#define MXC_F_FLC_INTEN1_SRAM_ADDR_WRAPPED_POS 0 +#define MXC_F_FLC_INTEN1_SRAM_ADDR_WRAPPED ((uint32_t)(0x00000001UL << MXC_F_FLC_INTEN1_SRAM_ADDR_WRAPPED_POS)) +#define MXC_F_FLC_INTEN1_INVALID_FLASH_ADDR_POS 1 +#define MXC_F_FLC_INTEN1_INVALID_FLASH_ADDR ((uint32_t)(0x00000001UL << MXC_F_FLC_INTEN1_INVALID_FLASH_ADDR_POS)) +#define MXC_F_FLC_INTEN1_FLASH_READ_LOCKED_POS 2 +#define MXC_F_FLC_INTEN1_FLASH_READ_LOCKED ((uint32_t)(0x00000001UL << MXC_F_FLC_INTEN1_FLASH_READ_LOCKED_POS)) +#define MXC_F_FLC_INTEN1_TRIM_UPDATE_DONE_POS 3 +#define MXC_F_FLC_INTEN1_TRIM_UPDATE_DONE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTEN1_TRIM_UPDATE_DONE_POS)) +#define MXC_F_FLC_INTEN1_FLC_STATE_DONE_POS 4 +#define MXC_F_FLC_INTEN1_FLC_STATE_DONE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTEN1_FLC_STATE_DONE_POS)) +#define MXC_F_FLC_INTEN1_FLC_PROG_COMPLETE_POS 5 +#define MXC_F_FLC_INTEN1_FLC_PROG_COMPLETE ((uint32_t)(0x00000001UL << MXC_F_FLC_INTEN1_FLC_PROG_COMPLETE_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_FLC_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/gpio_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/gpio_regs.h new file mode 100644 index 0000000..24c11b3 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/gpio_regs.h @@ -0,0 +1,470 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_GPIO_REGS_H_ +#define _MXC_GPIO_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t rst_mode[16]; /* 0x0000-0x003C Port P[0..15] Default (Power-On Reset) Output Drive Mode */ + __IO uint32_t free[16]; /* 0x0040-0x007C Port P[0..15] Free for GPIO Operation Flags */ + __IO uint32_t out_mode[16]; /* 0x0080-0x00BC Port P[0..15] Output Drive Mode */ + __IO uint32_t out_val[16]; /* 0x00C0-0x00FC Port P[0..15] GPIO Output Value */ + __IO uint32_t func_sel[16]; /* 0x0100-0x013C Port P[0..15] GPIO Function Select */ + __IO uint32_t in_mode[16]; /* 0x0140-0x017C Port P[0..15] GPIO Input Monitoring Mode */ + __IO uint32_t in_val[16]; /* 0x0180-0x01BC Port P[0..15] GPIO Input Value */ + __IO uint32_t int_mode[16]; /* 0x01C0-0x01FC Port P[0..15] Interrupt Detection Mode */ + __IO uint32_t intfl[16]; /* 0x0200-0x023C Port P[0..15] Interrupt Flags */ + __IO uint32_t inten[16]; /* 0x0240-0x027C Port P[0..15] Interrupt Enables */ +} mxc_gpio_regs_t; + + +/* + Register offsets for module GPIO. +*/ + +#define MXC_R_GPIO_OFFS_RST_MODE_P0 ((uint32_t)0x00000000UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P1 ((uint32_t)0x00000004UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P2 ((uint32_t)0x00000008UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P3 ((uint32_t)0x0000000CUL) +#define MXC_R_GPIO_OFFS_RST_MODE_P4 ((uint32_t)0x00000010UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P5 ((uint32_t)0x00000014UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P6 ((uint32_t)0x00000018UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P7 ((uint32_t)0x0000001CUL) +#define MXC_R_GPIO_OFFS_RST_MODE_P8 ((uint32_t)0x00000020UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P9 ((uint32_t)0x00000024UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P10 ((uint32_t)0x00000028UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P11 ((uint32_t)0x0000002CUL) +#define MXC_R_GPIO_OFFS_RST_MODE_P12 ((uint32_t)0x00000030UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P13 ((uint32_t)0x00000034UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P14 ((uint32_t)0x00000038UL) +#define MXC_R_GPIO_OFFS_RST_MODE_P15 ((uint32_t)0x0000003CUL) +#define MXC_R_GPIO_OFFS_FREE_P0 ((uint32_t)0x00000040UL) +#define MXC_R_GPIO_OFFS_FREE_P1 ((uint32_t)0x00000044UL) +#define MXC_R_GPIO_OFFS_FREE_P2 ((uint32_t)0x00000048UL) +#define MXC_R_GPIO_OFFS_FREE_P3 ((uint32_t)0x0000004CUL) +#define MXC_R_GPIO_OFFS_FREE_P4 ((uint32_t)0x00000050UL) +#define MXC_R_GPIO_OFFS_FREE_P5 ((uint32_t)0x00000054UL) +#define MXC_R_GPIO_OFFS_FREE_P6 ((uint32_t)0x00000058UL) +#define MXC_R_GPIO_OFFS_FREE_P7 ((uint32_t)0x0000005CUL) +#define MXC_R_GPIO_OFFS_FREE_P8 ((uint32_t)0x00000060UL) +#define MXC_R_GPIO_OFFS_FREE_P9 ((uint32_t)0x00000064UL) +#define MXC_R_GPIO_OFFS_FREE_P10 ((uint32_t)0x00000068UL) +#define MXC_R_GPIO_OFFS_FREE_P11 ((uint32_t)0x0000006CUL) +#define MXC_R_GPIO_OFFS_FREE_P12 ((uint32_t)0x00000070UL) +#define MXC_R_GPIO_OFFS_FREE_P13 ((uint32_t)0x00000074UL) +#define MXC_R_GPIO_OFFS_FREE_P14 ((uint32_t)0x00000078UL) +#define MXC_R_GPIO_OFFS_FREE_P15 ((uint32_t)0x0000007CUL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P0 ((uint32_t)0x00000080UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P1 ((uint32_t)0x00000084UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P2 ((uint32_t)0x00000088UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P3 ((uint32_t)0x0000008CUL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P4 ((uint32_t)0x00000090UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P5 ((uint32_t)0x00000094UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P6 ((uint32_t)0x00000098UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P7 ((uint32_t)0x0000009CUL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P8 ((uint32_t)0x000000A0UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P9 ((uint32_t)0x000000A4UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P10 ((uint32_t)0x000000A8UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P11 ((uint32_t)0x000000ACUL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P12 ((uint32_t)0x000000B0UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P13 ((uint32_t)0x000000B4UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P14 ((uint32_t)0x000000B8UL) +#define MXC_R_GPIO_OFFS_OUT_MODE_P15 ((uint32_t)0x000000BCUL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P0 ((uint32_t)0x000000C0UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P1 ((uint32_t)0x000000C4UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P2 ((uint32_t)0x000000C8UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P3 ((uint32_t)0x000000CCUL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P4 ((uint32_t)0x000000D0UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P5 ((uint32_t)0x000000D4UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P6 ((uint32_t)0x000000D8UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P7 ((uint32_t)0x000000DCUL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P8 ((uint32_t)0x000000E0UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P9 ((uint32_t)0x000000E4UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P10 ((uint32_t)0x000000E8UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P11 ((uint32_t)0x000000ECUL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P12 ((uint32_t)0x000000F0UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P13 ((uint32_t)0x000000F4UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P14 ((uint32_t)0x000000F8UL) +#define MXC_R_GPIO_OFFS_OUT_VAL_P15 ((uint32_t)0x000000FCUL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P0 ((uint32_t)0x00000100UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P1 ((uint32_t)0x00000104UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P2 ((uint32_t)0x00000108UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P3 ((uint32_t)0x0000010CUL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P4 ((uint32_t)0x00000110UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P5 ((uint32_t)0x00000114UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P6 ((uint32_t)0x00000118UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P7 ((uint32_t)0x0000011CUL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P8 ((uint32_t)0x00000120UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P9 ((uint32_t)0x00000124UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P10 ((uint32_t)0x00000128UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P11 ((uint32_t)0x0000012CUL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P12 ((uint32_t)0x00000130UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P13 ((uint32_t)0x00000134UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P14 ((uint32_t)0x00000138UL) +#define MXC_R_GPIO_OFFS_FUNC_SEL_P15 ((uint32_t)0x0000013CUL) +#define MXC_R_GPIO_OFFS_IN_MODE_P0 ((uint32_t)0x00000140UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P1 ((uint32_t)0x00000144UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P2 ((uint32_t)0x00000148UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P3 ((uint32_t)0x0000014CUL) +#define MXC_R_GPIO_OFFS_IN_MODE_P4 ((uint32_t)0x00000150UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P5 ((uint32_t)0x00000154UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P6 ((uint32_t)0x00000158UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P7 ((uint32_t)0x0000015CUL) +#define MXC_R_GPIO_OFFS_IN_MODE_P8 ((uint32_t)0x00000160UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P9 ((uint32_t)0x00000164UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P10 ((uint32_t)0x00000168UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P11 ((uint32_t)0x0000016CUL) +#define MXC_R_GPIO_OFFS_IN_MODE_P12 ((uint32_t)0x00000170UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P13 ((uint32_t)0x00000174UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P14 ((uint32_t)0x00000178UL) +#define MXC_R_GPIO_OFFS_IN_MODE_P15 ((uint32_t)0x0000017CUL) +#define MXC_R_GPIO_OFFS_IN_VAL_P0 ((uint32_t)0x00000180UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P1 ((uint32_t)0x00000184UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P2 ((uint32_t)0x00000188UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P3 ((uint32_t)0x0000018CUL) +#define MXC_R_GPIO_OFFS_IN_VAL_P4 ((uint32_t)0x00000190UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P5 ((uint32_t)0x00000194UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P6 ((uint32_t)0x00000198UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P7 ((uint32_t)0x0000019CUL) +#define MXC_R_GPIO_OFFS_IN_VAL_P8 ((uint32_t)0x000001A0UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P9 ((uint32_t)0x000001A4UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P10 ((uint32_t)0x000001A8UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P11 ((uint32_t)0x000001ACUL) +#define MXC_R_GPIO_OFFS_IN_VAL_P12 ((uint32_t)0x000001B0UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P13 ((uint32_t)0x000001B4UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P14 ((uint32_t)0x000001B8UL) +#define MXC_R_GPIO_OFFS_IN_VAL_P15 ((uint32_t)0x000001BCUL) +#define MXC_R_GPIO_OFFS_INT_MODE_P0 ((uint32_t)0x000001C0UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P1 ((uint32_t)0x000001C4UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P2 ((uint32_t)0x000001C8UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P3 ((uint32_t)0x000001CCUL) +#define MXC_R_GPIO_OFFS_INT_MODE_P4 ((uint32_t)0x000001D0UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P5 ((uint32_t)0x000001D4UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P6 ((uint32_t)0x000001D8UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P7 ((uint32_t)0x000001DCUL) +#define MXC_R_GPIO_OFFS_INT_MODE_P8 ((uint32_t)0x000001E0UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P9 ((uint32_t)0x000001E4UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P10 ((uint32_t)0x000001E8UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P11 ((uint32_t)0x000001ECUL) +#define MXC_R_GPIO_OFFS_INT_MODE_P12 ((uint32_t)0x000001F0UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P13 ((uint32_t)0x000001F4UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P14 ((uint32_t)0x000001F8UL) +#define MXC_R_GPIO_OFFS_INT_MODE_P15 ((uint32_t)0x000001FCUL) +#define MXC_R_GPIO_OFFS_INTFL_P0 ((uint32_t)0x00000200UL) +#define MXC_R_GPIO_OFFS_INTFL_P1 ((uint32_t)0x00000204UL) +#define MXC_R_GPIO_OFFS_INTFL_P2 ((uint32_t)0x00000208UL) +#define MXC_R_GPIO_OFFS_INTFL_P3 ((uint32_t)0x0000020CUL) +#define MXC_R_GPIO_OFFS_INTFL_P4 ((uint32_t)0x00000210UL) +#define MXC_R_GPIO_OFFS_INTFL_P5 ((uint32_t)0x00000214UL) +#define MXC_R_GPIO_OFFS_INTFL_P6 ((uint32_t)0x00000218UL) +#define MXC_R_GPIO_OFFS_INTFL_P7 ((uint32_t)0x0000021CUL) +#define MXC_R_GPIO_OFFS_INTFL_P8 ((uint32_t)0x00000220UL) +#define MXC_R_GPIO_OFFS_INTFL_P9 ((uint32_t)0x00000224UL) +#define MXC_R_GPIO_OFFS_INTFL_P10 ((uint32_t)0x00000228UL) +#define MXC_R_GPIO_OFFS_INTFL_P11 ((uint32_t)0x0000022CUL) +#define MXC_R_GPIO_OFFS_INTFL_P12 ((uint32_t)0x00000230UL) +#define MXC_R_GPIO_OFFS_INTFL_P13 ((uint32_t)0x00000234UL) +#define MXC_R_GPIO_OFFS_INTFL_P14 ((uint32_t)0x00000238UL) +#define MXC_R_GPIO_OFFS_INTFL_P15 ((uint32_t)0x0000023CUL) +#define MXC_R_GPIO_OFFS_INTEN_P0 ((uint32_t)0x00000240UL) +#define MXC_R_GPIO_OFFS_INTEN_P1 ((uint32_t)0x00000244UL) +#define MXC_R_GPIO_OFFS_INTEN_P2 ((uint32_t)0x00000248UL) +#define MXC_R_GPIO_OFFS_INTEN_P3 ((uint32_t)0x0000024CUL) +#define MXC_R_GPIO_OFFS_INTEN_P4 ((uint32_t)0x00000250UL) +#define MXC_R_GPIO_OFFS_INTEN_P5 ((uint32_t)0x00000254UL) +#define MXC_R_GPIO_OFFS_INTEN_P6 ((uint32_t)0x00000258UL) +#define MXC_R_GPIO_OFFS_INTEN_P7 ((uint32_t)0x0000025CUL) +#define MXC_R_GPIO_OFFS_INTEN_P8 ((uint32_t)0x00000260UL) +#define MXC_R_GPIO_OFFS_INTEN_P9 ((uint32_t)0x00000264UL) +#define MXC_R_GPIO_OFFS_INTEN_P10 ((uint32_t)0x00000268UL) +#define MXC_R_GPIO_OFFS_INTEN_P11 ((uint32_t)0x0000026CUL) +#define MXC_R_GPIO_OFFS_INTEN_P12 ((uint32_t)0x00000270UL) +#define MXC_R_GPIO_OFFS_INTEN_P13 ((uint32_t)0x00000274UL) +#define MXC_R_GPIO_OFFS_INTEN_P14 ((uint32_t)0x00000278UL) +#define MXC_R_GPIO_OFFS_INTEN_P15 ((uint32_t)0x0000027CUL) + + +/* + Field positions and masks for module GPIO. +*/ + +#define MXC_F_GPIO_RST_MODE_PIN0_POS 0 +#define MXC_F_GPIO_RST_MODE_PIN0 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN0_POS)) +#define MXC_F_GPIO_RST_MODE_PIN1_POS 4 +#define MXC_F_GPIO_RST_MODE_PIN1 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN1_POS)) +#define MXC_F_GPIO_RST_MODE_PIN2_POS 8 +#define MXC_F_GPIO_RST_MODE_PIN2 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN2_POS)) +#define MXC_F_GPIO_RST_MODE_PIN3_POS 12 +#define MXC_F_GPIO_RST_MODE_PIN3 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN3_POS)) +#define MXC_F_GPIO_RST_MODE_PIN4_POS 16 +#define MXC_F_GPIO_RST_MODE_PIN4 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN4_POS)) +#define MXC_F_GPIO_RST_MODE_PIN5_POS 20 +#define MXC_F_GPIO_RST_MODE_PIN5 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN5_POS)) +#define MXC_F_GPIO_RST_MODE_PIN6_POS 24 +#define MXC_F_GPIO_RST_MODE_PIN6 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN6_POS)) +#define MXC_F_GPIO_RST_MODE_PIN7_POS 28 +#define MXC_F_GPIO_RST_MODE_PIN7 ((uint32_t)(0x00000007UL << MXC_F_GPIO_RST_MODE_PIN7_POS)) + +#define MXC_F_GPIO_FREE_PIN0_POS 0 +#define MXC_F_GPIO_FREE_PIN0 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN0_POS)) +#define MXC_F_GPIO_FREE_PIN1_POS 1 +#define MXC_F_GPIO_FREE_PIN1 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN1_POS)) +#define MXC_F_GPIO_FREE_PIN2_POS 2 +#define MXC_F_GPIO_FREE_PIN2 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN2_POS)) +#define MXC_F_GPIO_FREE_PIN3_POS 3 +#define MXC_F_GPIO_FREE_PIN3 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN3_POS)) +#define MXC_F_GPIO_FREE_PIN4_POS 4 +#define MXC_F_GPIO_FREE_PIN4 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN4_POS)) +#define MXC_F_GPIO_FREE_PIN5_POS 5 +#define MXC_F_GPIO_FREE_PIN5 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN5_POS)) +#define MXC_F_GPIO_FREE_PIN6_POS 6 +#define MXC_F_GPIO_FREE_PIN6 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN6_POS)) +#define MXC_F_GPIO_FREE_PIN7_POS 7 +#define MXC_F_GPIO_FREE_PIN7 ((uint32_t)(0x00000001UL << MXC_F_GPIO_FREE_PIN7_POS)) + +#define MXC_F_GPIO_OUT_MODE_PIN0_POS 0 +#define MXC_F_GPIO_OUT_MODE_PIN0 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN0_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN1_POS 4 +#define MXC_F_GPIO_OUT_MODE_PIN1 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN1_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN2_POS 8 +#define MXC_F_GPIO_OUT_MODE_PIN2 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN2_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN3_POS 12 +#define MXC_F_GPIO_OUT_MODE_PIN3 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN3_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN4_POS 16 +#define MXC_F_GPIO_OUT_MODE_PIN4 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN4_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN5_POS 20 +#define MXC_F_GPIO_OUT_MODE_PIN5 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN5_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN6_POS 24 +#define MXC_F_GPIO_OUT_MODE_PIN6 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN6_POS)) +#define MXC_F_GPIO_OUT_MODE_PIN7_POS 28 +#define MXC_F_GPIO_OUT_MODE_PIN7 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_OUT_MODE_PIN7_POS)) + +#define MXC_F_GPIO_OUT_VAL_PIN0_POS 0 +#define MXC_F_GPIO_OUT_VAL_PIN0 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN0_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN1_POS 1 +#define MXC_F_GPIO_OUT_VAL_PIN1 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN1_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN2_POS 2 +#define MXC_F_GPIO_OUT_VAL_PIN2 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN2_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN3_POS 3 +#define MXC_F_GPIO_OUT_VAL_PIN3 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN3_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN4_POS 4 +#define MXC_F_GPIO_OUT_VAL_PIN4 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN4_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN5_POS 5 +#define MXC_F_GPIO_OUT_VAL_PIN5 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN5_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN6_POS 6 +#define MXC_F_GPIO_OUT_VAL_PIN6 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN6_POS)) +#define MXC_F_GPIO_OUT_VAL_PIN7_POS 7 +#define MXC_F_GPIO_OUT_VAL_PIN7 ((uint32_t)(0x00000001UL << MXC_F_GPIO_OUT_VAL_PIN7_POS)) + +#define MXC_F_GPIO_FUNC_SEL_PIN0_POS 0 +#define MXC_F_GPIO_FUNC_SEL_PIN0 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN0_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN1_POS 4 +#define MXC_F_GPIO_FUNC_SEL_PIN1 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN1_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN2_POS 8 +#define MXC_F_GPIO_FUNC_SEL_PIN2 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN2_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN3_POS 12 +#define MXC_F_GPIO_FUNC_SEL_PIN3 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN3_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN4_POS 16 +#define MXC_F_GPIO_FUNC_SEL_PIN4 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN4_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN5_POS 20 +#define MXC_F_GPIO_FUNC_SEL_PIN5 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN5_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN6_POS 24 +#define MXC_F_GPIO_FUNC_SEL_PIN6 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN6_POS)) +#define MXC_F_GPIO_FUNC_SEL_PIN7_POS 28 +#define MXC_F_GPIO_FUNC_SEL_PIN7 ((uint32_t)(0x0000000FUL << MXC_F_GPIO_FUNC_SEL_PIN7_POS)) + +#define MXC_F_GPIO_IN_MODE_PIN0_POS 0 +#define MXC_F_GPIO_IN_MODE_PIN0 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN0_POS)) +#define MXC_F_GPIO_IN_MODE_PIN1_POS 4 +#define MXC_F_GPIO_IN_MODE_PIN1 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN1_POS)) +#define MXC_F_GPIO_IN_MODE_PIN2_POS 8 +#define MXC_F_GPIO_IN_MODE_PIN2 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN2_POS)) +#define MXC_F_GPIO_IN_MODE_PIN3_POS 12 +#define MXC_F_GPIO_IN_MODE_PIN3 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN3_POS)) +#define MXC_F_GPIO_IN_MODE_PIN4_POS 16 +#define MXC_F_GPIO_IN_MODE_PIN4 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN4_POS)) +#define MXC_F_GPIO_IN_MODE_PIN5_POS 20 +#define MXC_F_GPIO_IN_MODE_PIN5 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN5_POS)) +#define MXC_F_GPIO_IN_MODE_PIN6_POS 24 +#define MXC_F_GPIO_IN_MODE_PIN6 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN6_POS)) +#define MXC_F_GPIO_IN_MODE_PIN7_POS 28 +#define MXC_F_GPIO_IN_MODE_PIN7 ((uint32_t)(0x00000003UL << MXC_F_GPIO_IN_MODE_PIN7_POS)) + +#define MXC_F_GPIO_IN_VAL_PIN0_POS 0 +#define MXC_F_GPIO_IN_VAL_PIN0 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN0_POS)) +#define MXC_F_GPIO_IN_VAL_PIN1_POS 1 +#define MXC_F_GPIO_IN_VAL_PIN1 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN1_POS)) +#define MXC_F_GPIO_IN_VAL_PIN2_POS 2 +#define MXC_F_GPIO_IN_VAL_PIN2 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN2_POS)) +#define MXC_F_GPIO_IN_VAL_PIN3_POS 3 +#define MXC_F_GPIO_IN_VAL_PIN3 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN3_POS)) +#define MXC_F_GPIO_IN_VAL_PIN4_POS 4 +#define MXC_F_GPIO_IN_VAL_PIN4 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN4_POS)) +#define MXC_F_GPIO_IN_VAL_PIN5_POS 5 +#define MXC_F_GPIO_IN_VAL_PIN5 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN5_POS)) +#define MXC_F_GPIO_IN_VAL_PIN6_POS 6 +#define MXC_F_GPIO_IN_VAL_PIN6 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN6_POS)) +#define MXC_F_GPIO_IN_VAL_PIN7_POS 7 +#define MXC_F_GPIO_IN_VAL_PIN7 ((uint32_t)(0x00000001UL << MXC_F_GPIO_IN_VAL_PIN7_POS)) + +#define MXC_F_GPIO_INT_MODE_PIN0_POS 0 +#define MXC_F_GPIO_INT_MODE_PIN0 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN0_POS)) +#define MXC_F_GPIO_INT_MODE_PIN1_POS 4 +#define MXC_F_GPIO_INT_MODE_PIN1 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN1_POS)) +#define MXC_F_GPIO_INT_MODE_PIN2_POS 8 +#define MXC_F_GPIO_INT_MODE_PIN2 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN2_POS)) +#define MXC_F_GPIO_INT_MODE_PIN3_POS 12 +#define MXC_F_GPIO_INT_MODE_PIN3 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN3_POS)) +#define MXC_F_GPIO_INT_MODE_PIN4_POS 16 +#define MXC_F_GPIO_INT_MODE_PIN4 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN4_POS)) +#define MXC_F_GPIO_INT_MODE_PIN5_POS 20 +#define MXC_F_GPIO_INT_MODE_PIN5 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN5_POS)) +#define MXC_F_GPIO_INT_MODE_PIN6_POS 24 +#define MXC_F_GPIO_INT_MODE_PIN6 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN6_POS)) +#define MXC_F_GPIO_INT_MODE_PIN7_POS 28 +#define MXC_F_GPIO_INT_MODE_PIN7 ((uint32_t)(0x00000007UL << MXC_F_GPIO_INT_MODE_PIN7_POS)) + +#define MXC_F_GPIO_INTFL_PIN0_POS 0 +#define MXC_F_GPIO_INTFL_PIN0 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN0_POS)) +#define MXC_F_GPIO_INTFL_PIN1_POS 1 +#define MXC_F_GPIO_INTFL_PIN1 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN1_POS)) +#define MXC_F_GPIO_INTFL_PIN2_POS 2 +#define MXC_F_GPIO_INTFL_PIN2 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN2_POS)) +#define MXC_F_GPIO_INTFL_PIN3_POS 3 +#define MXC_F_GPIO_INTFL_PIN3 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN3_POS)) +#define MXC_F_GPIO_INTFL_PIN4_POS 4 +#define MXC_F_GPIO_INTFL_PIN4 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN4_POS)) +#define MXC_F_GPIO_INTFL_PIN5_POS 5 +#define MXC_F_GPIO_INTFL_PIN5 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN5_POS)) +#define MXC_F_GPIO_INTFL_PIN6_POS 6 +#define MXC_F_GPIO_INTFL_PIN6 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN6_POS)) +#define MXC_F_GPIO_INTFL_PIN7_POS 7 +#define MXC_F_GPIO_INTFL_PIN7 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTFL_PIN7_POS)) + +#define MXC_F_GPIO_INTEN_PIN0_POS 0 +#define MXC_F_GPIO_INTEN_PIN0 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN0_POS)) +#define MXC_F_GPIO_INTEN_PIN1_POS 1 +#define MXC_F_GPIO_INTEN_PIN1 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN1_POS)) +#define MXC_F_GPIO_INTEN_PIN2_POS 2 +#define MXC_F_GPIO_INTEN_PIN2 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN2_POS)) +#define MXC_F_GPIO_INTEN_PIN3_POS 3 +#define MXC_F_GPIO_INTEN_PIN3 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN3_POS)) +#define MXC_F_GPIO_INTEN_PIN4_POS 4 +#define MXC_F_GPIO_INTEN_PIN4 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN4_POS)) +#define MXC_F_GPIO_INTEN_PIN5_POS 5 +#define MXC_F_GPIO_INTEN_PIN5 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN5_POS)) +#define MXC_F_GPIO_INTEN_PIN6_POS 6 +#define MXC_F_GPIO_INTEN_PIN6 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN6_POS)) +#define MXC_F_GPIO_INTEN_PIN7_POS 7 +#define MXC_F_GPIO_INTEN_PIN7 ((uint32_t)(0x00000001UL << MXC_F_GPIO_INTEN_PIN7_POS)) + + + +/* + Field values and shifted values for module GPIO. +*/ + +#define MXC_V_GPIO_RST_MODE_DRIVE_0 ((uint32_t)(0x00000000UL)) +#define MXC_V_GPIO_RST_MODE_WEAK_PULLDOWN ((uint32_t)(0x00000001UL)) +#define MXC_V_GPIO_RST_MODE_WEAK_PULLUP ((uint32_t)(0x00000002UL)) +#define MXC_V_GPIO_RST_MODE_DRIVE_1 ((uint32_t)(0x00000003UL)) +#define MXC_V_GPIO_RST_MODE_HIGH_Z ((uint32_t)(0x00000004UL)) + +#define MXC_V_GPIO_FREE_NOT_AVAILABLE ((uint32_t)(0x00000000UL)) +#define MXC_V_GPIO_FREE_AVAILABLE ((uint32_t)(0x00000001UL)) + +#define MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP ((uint32_t)(0x00000000UL)) +#define MXC_V_GPIO_OUT_MODE_OPEN_DRAIN ((uint32_t)(0x00000001UL)) +#define MXC_V_GPIO_OUT_MODE_OPEN_DRAIN_WEAK_PULLUP ((uint32_t)(0x00000002UL)) +#define MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z ((uint32_t)(0x00000004UL)) +#define MXC_V_GPIO_OUT_MODE_NORMAL ((uint32_t)(0x00000005UL)) +#define MXC_V_GPIO_OUT_MODE_SLOW_HIGH_Z ((uint32_t)(0x00000006UL)) +#define MXC_V_GPIO_OUT_MODE_SLOW_DRIVE ((uint32_t)(0x00000007UL)) +#define MXC_V_GPIO_OUT_MODE_FAST_HIGH_Z ((uint32_t)(0x00000008UL)) +#define MXC_V_GPIO_OUT_MODE_FAST_DRIVE ((uint32_t)(0x00000009UL)) +#define MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN ((uint32_t)(0x0000000AUL)) +#define MXC_V_GPIO_OUT_MODE_OPEN_SOURCE ((uint32_t)(0x0000000BUL)) +#define MXC_V_GPIO_OUT_MODE_OPEN_SOURCE_WEAK_PULLDOWN ((uint32_t)(0x0000000CUL)) +#define MXC_V_GPIO_OUT_MODE_HIGH_Z_INPUT_DISABLED ((uint32_t)(0x0000000FUL)) + +#define MXC_V_GPIO_FUNC_SEL_MODE_GPIO ((uint32_t)(0x00000000UL)) +#define MXC_V_GPIO_FUNC_SEL_MODE_PT ((uint32_t)(0x00000001UL)) +#define MXC_V_GPIO_FUNC_SEL_MODE_TMR ((uint32_t)(0x00000002UL)) + +#define MXC_V_GPIO_IN_MODE_NORMAL ((uint32_t)(0x00000000UL)) +#define MXC_V_GPIO_IN_MODE_INVERTED ((uint32_t)(0x00000001UL)) +#define MXC_V_GPIO_IN_MODE_ALWAYS_ZERO ((uint32_t)(0x00000002UL)) +#define MXC_V_GPIO_IN_MODE_ALWAYS_ONE ((uint32_t)(0x00000003UL)) + +#define MXC_V_GPIO_INT_MODE_DISABLE ((uint32_t)(0x00000000UL)) +#define MXC_V_GPIO_INT_MODE_FALLING_EDGE ((uint32_t)(0x00000001UL)) +#define MXC_V_GPIO_INT_MODE_RISING_EDGE ((uint32_t)(0x00000002UL)) +#define MXC_V_GPIO_INT_MODE_ANY_EDGE ((uint32_t)(0x00000003UL)) +#define MXC_V_GPIO_INT_MODE_LOW_LVL ((uint32_t)(0x00000004UL)) +#define MXC_V_GPIO_INT_MODE_HIGH_LVL ((uint32_t)(0x00000005UL)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_GPIO_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/i2cm_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/i2cm_regs.h new file mode 100644 index 0000000..63d94cf --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/i2cm_regs.h @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_I2CM_REGS_H_ +#define _MXC_I2CM_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +#define MXC_S_I2CM_TRANS_TAG_START 0x000 +#define MXC_S_I2CM_TRANS_TAG_TXDATA_ACK 0x100 +#define MXC_S_I2CM_TRANS_TAG_TXDATA_NACK 0x200 +#define MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT 0x400 +#define MXC_S_I2CM_TRANS_TAG_RXDATA_NACK 0x500 +#define MXC_S_I2CM_TRANS_TAG_STOP 0x700 +#define MXC_S_I2CM_RSTLS_TAG_DATA 0x100 +#define MXC_S_I2CM_RSTLS_TAG_EMPTY 0x200 + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t fs_clk_div; /* 0x0000 I2C Master Full Speed SCL Clock Settings */ + __I uint32_t rsv004[2]; /* 0x0004-0x0008 */ + __IO uint32_t timeout; /* 0x000C I2C Master Timeout and Auto-Stop Settings */ + __IO uint32_t ctrl; /* 0x0010 I2C Master Control Register */ + __IO uint32_t trans; /* 0x0014 I2C Master Transaction Start and Status Flags */ + __IO uint32_t intfl; /* 0x0018 I2C Master Interrupt Flags */ + __IO uint32_t inten; /* 0x001C I2C Master Interrupt Enable/Disable Controls */ + __I uint32_t rsv020[2]; /* 0x0020-0x0024 */ + __IO uint32_t bb; /* 0x0028 I2C Master Bit-Bang Control Register */ +} mxc_i2cm_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + union { /* 0x0000-0x07FC FIFO Write Point for Data to Transmit */ + __IO uint16_t tx; + __IO uint8_t tx_8[2048]; + __IO uint16_t tx_16[1024]; + __IO uint32_t tx_32[512]; + }; + union { /* 0x0800-0x0FFC FIFO Read Point for Received Data */ + __IO uint16_t rx; + __IO uint8_t rx_8[2048]; + __IO uint16_t rx_16[1024]; + __IO uint32_t rx_32[512]; + }; +} mxc_i2cm_fifo_regs_t; + + +/* + Register offsets for module I2CM. +*/ + +#define MXC_R_I2CM_OFFS_FS_CLK_DIV ((uint32_t)0x00000000UL) +#define MXC_R_I2CM_OFFS_TIMEOUT ((uint32_t)0x0000000CUL) +#define MXC_R_I2CM_OFFS_CTRL ((uint32_t)0x00000010UL) +#define MXC_R_I2CM_OFFS_TRANS ((uint32_t)0x00000014UL) +#define MXC_R_I2CM_OFFS_INTFL ((uint32_t)0x00000018UL) +#define MXC_R_I2CM_OFFS_INTEN ((uint32_t)0x0000001CUL) +#define MXC_R_I2CM_OFFS_BB ((uint32_t)0x00000028UL) +#define MXC_R_I2CM_FIFO_OFFS_TRANS ((uint32_t)0x00000000UL) +#define MXC_R_I2CM_FIFO_OFFS_RSLTS ((uint32_t)0x00000800UL) + + +/* + Field positions and masks for module I2CM. +*/ + +#define MXC_F_I2CM_FS_CLK_DIV_FS_FILTER_CLK_DIV_POS 0 +#define MXC_F_I2CM_FS_CLK_DIV_FS_FILTER_CLK_DIV ((uint32_t)(0x000000FFUL << MXC_F_I2CM_FS_CLK_DIV_FS_FILTER_CLK_DIV_POS)) +#define MXC_F_I2CM_FS_CLK_DIV_FS_SCL_LO_CNT_POS 8 +#define MXC_F_I2CM_FS_CLK_DIV_FS_SCL_LO_CNT ((uint32_t)(0x00000FFFUL << MXC_F_I2CM_FS_CLK_DIV_FS_SCL_LO_CNT_POS)) +#define MXC_F_I2CM_FS_CLK_DIV_FS_SCL_HI_CNT_POS 20 +#define MXC_F_I2CM_FS_CLK_DIV_FS_SCL_HI_CNT ((uint32_t)(0x00000FFFUL << MXC_F_I2CM_FS_CLK_DIV_FS_SCL_HI_CNT_POS)) + +#define MXC_F_I2CM_TIMEOUT_TX_TIMEOUT_POS 16 +#define MXC_F_I2CM_TIMEOUT_TX_TIMEOUT ((uint32_t)(0x000000FFUL << MXC_F_I2CM_TIMEOUT_TX_TIMEOUT_POS)) +#define MXC_F_I2CM_TIMEOUT_AUTO_STOP_EN_POS 24 +#define MXC_F_I2CM_TIMEOUT_AUTO_STOP_EN ((uint32_t)(0x00000001UL << MXC_F_I2CM_TIMEOUT_AUTO_STOP_EN_POS)) + +#define MXC_F_I2CM_CTRL_TX_FIFO_EN_POS 2 +#define MXC_F_I2CM_CTRL_TX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_I2CM_CTRL_TX_FIFO_EN_POS)) +#define MXC_F_I2CM_CTRL_RX_FIFO_EN_POS 3 +#define MXC_F_I2CM_CTRL_RX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_I2CM_CTRL_RX_FIFO_EN_POS)) +#define MXC_F_I2CM_CTRL_MSTR_RESET_EN_POS 7 +#define MXC_F_I2CM_CTRL_MSTR_RESET_EN ((uint32_t)(0x00000001UL << MXC_F_I2CM_CTRL_MSTR_RESET_EN_POS)) + +#define MXC_F_I2CM_TRANS_TX_START_POS 0 +#define MXC_F_I2CM_TRANS_TX_START ((uint32_t)(0x00000001UL << MXC_F_I2CM_TRANS_TX_START_POS)) +#define MXC_F_I2CM_TRANS_TX_IN_PROGRESS_POS 1 +#define MXC_F_I2CM_TRANS_TX_IN_PROGRESS ((uint32_t)(0x00000001UL << MXC_F_I2CM_TRANS_TX_IN_PROGRESS_POS)) +#define MXC_F_I2CM_TRANS_TX_DONE_POS 2 +#define MXC_F_I2CM_TRANS_TX_DONE ((uint32_t)(0x00000001UL << MXC_F_I2CM_TRANS_TX_DONE_POS)) +#define MXC_F_I2CM_TRANS_TX_NACKED_POS 3 +#define MXC_F_I2CM_TRANS_TX_NACKED ((uint32_t)(0x00000001UL << MXC_F_I2CM_TRANS_TX_NACKED_POS)) +#define MXC_F_I2CM_TRANS_TX_LOST_ARBITR_POS 4 +#define MXC_F_I2CM_TRANS_TX_LOST_ARBITR ((uint32_t)(0x00000001UL << MXC_F_I2CM_TRANS_TX_LOST_ARBITR_POS)) +#define MXC_F_I2CM_TRANS_TX_TIMEOUT_POS 5 +#define MXC_F_I2CM_TRANS_TX_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_I2CM_TRANS_TX_TIMEOUT_POS)) + +#define MXC_F_I2CM_INTFL_TX_DONE_POS 0 +#define MXC_F_I2CM_INTFL_TX_DONE ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_TX_DONE_POS)) +#define MXC_F_I2CM_INTFL_TX_NACKED_POS 1 +#define MXC_F_I2CM_INTFL_TX_NACKED ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_TX_NACKED_POS)) +#define MXC_F_I2CM_INTFL_TX_LOST_ARBITR_POS 2 +#define MXC_F_I2CM_INTFL_TX_LOST_ARBITR ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_TX_LOST_ARBITR_POS)) +#define MXC_F_I2CM_INTFL_TX_TIMEOUT_POS 3 +#define MXC_F_I2CM_INTFL_TX_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_TX_TIMEOUT_POS)) +#define MXC_F_I2CM_INTFL_TX_FIFO_EMPTY_POS 4 +#define MXC_F_I2CM_INTFL_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_TX_FIFO_EMPTY_POS)) +#define MXC_F_I2CM_INTFL_TX_FIFO_3Q_EMPTY_POS 5 +#define MXC_F_I2CM_INTFL_TX_FIFO_3Q_EMPTY ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_TX_FIFO_3Q_EMPTY_POS)) +#define MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY_POS 6 +#define MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY_POS)) +#define MXC_F_I2CM_INTFL_RX_FIFO_2Q_FULL_POS 7 +#define MXC_F_I2CM_INTFL_RX_FIFO_2Q_FULL ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_RX_FIFO_2Q_FULL_POS)) +#define MXC_F_I2CM_INTFL_RX_FIFO_3Q_FULL_POS 8 +#define MXC_F_I2CM_INTFL_RX_FIFO_3Q_FULL ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_RX_FIFO_3Q_FULL_POS)) +#define MXC_F_I2CM_INTFL_RX_FIFO_FULL_POS 9 +#define MXC_F_I2CM_INTFL_RX_FIFO_FULL ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTFL_RX_FIFO_FULL_POS)) + +#define MXC_F_I2CM_INTEN_TX_DONE_POS 0 +#define MXC_F_I2CM_INTEN_TX_DONE ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_TX_DONE_POS)) +#define MXC_F_I2CM_INTEN_TX_NACKED_POS 1 +#define MXC_F_I2CM_INTEN_TX_NACKED ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_TX_NACKED_POS)) +#define MXC_F_I2CM_INTEN_TX_LOST_ARBITR_POS 2 +#define MXC_F_I2CM_INTEN_TX_LOST_ARBITR ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_TX_LOST_ARBITR_POS)) +#define MXC_F_I2CM_INTEN_TX_TIMEOUT_POS 3 +#define MXC_F_I2CM_INTEN_TX_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_TX_TIMEOUT_POS)) +#define MXC_F_I2CM_INTEN_TX_FIFO_EMPTY_POS 4 +#define MXC_F_I2CM_INTEN_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_TX_FIFO_EMPTY_POS)) +#define MXC_F_I2CM_INTEN_TX_FIFO_3Q_EMPTY_POS 5 +#define MXC_F_I2CM_INTEN_TX_FIFO_3Q_EMPTY ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_TX_FIFO_3Q_EMPTY_POS)) +#define MXC_F_I2CM_INTEN_RX_FIFO_NOT_EMPTY_POS 6 +#define MXC_F_I2CM_INTEN_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_RX_FIFO_NOT_EMPTY_POS)) +#define MXC_F_I2CM_INTEN_RX_FIFO_2Q_FULL_POS 7 +#define MXC_F_I2CM_INTEN_RX_FIFO_2Q_FULL ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_RX_FIFO_2Q_FULL_POS)) +#define MXC_F_I2CM_INTEN_RX_FIFO_3Q_FULL_POS 8 +#define MXC_F_I2CM_INTEN_RX_FIFO_3Q_FULL ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_RX_FIFO_3Q_FULL_POS)) +#define MXC_F_I2CM_INTEN_RX_FIFO_FULL_POS 9 +#define MXC_F_I2CM_INTEN_RX_FIFO_FULL ((uint32_t)(0x00000001UL << MXC_F_I2CM_INTEN_RX_FIFO_FULL_POS)) + +#define MXC_F_I2CM_BB_BB_SCL_OUT_POS 0 +#define MXC_F_I2CM_BB_BB_SCL_OUT ((uint32_t)(0x00000001UL << MXC_F_I2CM_BB_BB_SCL_OUT_POS)) +#define MXC_F_I2CM_BB_BB_SDA_OUT_POS 1 +#define MXC_F_I2CM_BB_BB_SDA_OUT ((uint32_t)(0x00000001UL << MXC_F_I2CM_BB_BB_SDA_OUT_POS)) +#define MXC_F_I2CM_BB_BB_SCL_IN_VAL_POS 2 +#define MXC_F_I2CM_BB_BB_SCL_IN_VAL ((uint32_t)(0x00000001UL << MXC_F_I2CM_BB_BB_SCL_IN_VAL_POS)) +#define MXC_F_I2CM_BB_BB_SDA_IN_VAL_POS 3 +#define MXC_F_I2CM_BB_BB_SDA_IN_VAL ((uint32_t)(0x00000001UL << MXC_F_I2CM_BB_BB_SDA_IN_VAL_POS)) +#define MXC_F_I2CM_BB_RX_FIFO_CNT_POS 16 +#define MXC_F_I2CM_BB_RX_FIFO_CNT ((uint32_t)(0x0000001FUL << MXC_F_I2CM_BB_RX_FIFO_CNT_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_I2CM_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/i2cs_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/i2cs_regs.h new file mode 100644 index 0000000..89d8970 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/i2cs_regs.h @@ -0,0 +1,242 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_I2CS_REGS_H_ +#define _MXC_I2CS_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t clk_div; /* 0x0000 I2C Slave Clock Divisor Control */ + __IO uint32_t dev_id; /* 0x0004 I2C Slave Device ID Register */ + __IO uint32_t intfl; /* 0x0008 I2CS Interrupt Flags */ + __IO uint32_t inten; /* 0x000C I2CS Interrupt Enable/Disable Controls */ + __IO uint32_t data_byte[32]; /* 0x0010-0x008C I2CS Data Byte */ +} mxc_i2cs_regs_t; + + +/* + Register offsets for module I2CS. +*/ + +#define MXC_R_I2CS_OFFS_CLK_DIV ((uint32_t)0x00000000UL) +#define MXC_R_I2CS_OFFS_DEV_ID ((uint32_t)0x00000004UL) +#define MXC_R_I2CS_OFFS_INTFL ((uint32_t)0x00000008UL) +#define MXC_R_I2CS_OFFS_INTEN ((uint32_t)0x0000000CUL) +#define MXC_R_I2CS_OFFS_DATA_BYTE ((uint32_t)0x00000010UL) + + +/* + Field positions and masks for module I2CS. +*/ + +#define MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS 0 +#define MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV ((uint32_t)(0x000000FFUL << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS)) + +#define MXC_F_I2CS_DEV_ID_SLAVE_DEV_ID_POS 0 +#define MXC_F_I2CS_DEV_ID_SLAVE_DEV_ID ((uint32_t)(0x000003FFUL << MXC_F_I2CS_DEV_ID_SLAVE_DEV_ID_POS)) +#define MXC_F_I2CS_DEV_ID_TEN_BIT_ID_MODE_POS 12 +#define MXC_F_I2CS_DEV_ID_TEN_BIT_ID_MODE ((uint32_t)(0x00000001UL << MXC_F_I2CS_DEV_ID_TEN_BIT_ID_MODE_POS)) +#define MXC_F_I2CS_DEV_ID_SLAVE_RESET_POS 14 +#define MXC_F_I2CS_DEV_ID_SLAVE_RESET ((uint32_t)(0x00000001UL << MXC_F_I2CS_DEV_ID_SLAVE_RESET_POS)) + +#define MXC_F_I2CS_INTFL_BYTE0_POS 0 +#define MXC_F_I2CS_INTFL_BYTE0 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE0_POS)) +#define MXC_F_I2CS_INTFL_BYTE1_POS 1 +#define MXC_F_I2CS_INTFL_BYTE1 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE1_POS)) +#define MXC_F_I2CS_INTFL_BYTE2_POS 2 +#define MXC_F_I2CS_INTFL_BYTE2 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE2_POS)) +#define MXC_F_I2CS_INTFL_BYTE3_POS 3 +#define MXC_F_I2CS_INTFL_BYTE3 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE3_POS)) +#define MXC_F_I2CS_INTFL_BYTE4_POS 4 +#define MXC_F_I2CS_INTFL_BYTE4 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE4_POS)) +#define MXC_F_I2CS_INTFL_BYTE5_POS 5 +#define MXC_F_I2CS_INTFL_BYTE5 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE5_POS)) +#define MXC_F_I2CS_INTFL_BYTE6_POS 6 +#define MXC_F_I2CS_INTFL_BYTE6 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE6_POS)) +#define MXC_F_I2CS_INTFL_BYTE7_POS 7 +#define MXC_F_I2CS_INTFL_BYTE7 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE7_POS)) +#define MXC_F_I2CS_INTFL_BYTE8_POS 8 +#define MXC_F_I2CS_INTFL_BYTE8 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE8_POS)) +#define MXC_F_I2CS_INTFL_BYTE9_POS 9 +#define MXC_F_I2CS_INTFL_BYTE9 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE9_POS)) +#define MXC_F_I2CS_INTFL_BYTE10_POS 10 +#define MXC_F_I2CS_INTFL_BYTE10 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE10_POS)) +#define MXC_F_I2CS_INTFL_BYTE11_POS 11 +#define MXC_F_I2CS_INTFL_BYTE11 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE11_POS)) +#define MXC_F_I2CS_INTFL_BYTE12_POS 12 +#define MXC_F_I2CS_INTFL_BYTE12 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE12_POS)) +#define MXC_F_I2CS_INTFL_BYTE13_POS 13 +#define MXC_F_I2CS_INTFL_BYTE13 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE13_POS)) +#define MXC_F_I2CS_INTFL_BYTE14_POS 14 +#define MXC_F_I2CS_INTFL_BYTE14 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE14_POS)) +#define MXC_F_I2CS_INTFL_BYTE15_POS 15 +#define MXC_F_I2CS_INTFL_BYTE15 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE15_POS)) +#define MXC_F_I2CS_INTFL_BYTE16_POS 16 +#define MXC_F_I2CS_INTFL_BYTE16 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE16_POS)) +#define MXC_F_I2CS_INTFL_BYTE17_POS 17 +#define MXC_F_I2CS_INTFL_BYTE17 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE17_POS)) +#define MXC_F_I2CS_INTFL_BYTE18_POS 18 +#define MXC_F_I2CS_INTFL_BYTE18 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE18_POS)) +#define MXC_F_I2CS_INTFL_BYTE19_POS 19 +#define MXC_F_I2CS_INTFL_BYTE19 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE19_POS)) +#define MXC_F_I2CS_INTFL_BYTE20_POS 20 +#define MXC_F_I2CS_INTFL_BYTE20 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE20_POS)) +#define MXC_F_I2CS_INTFL_BYTE21_POS 21 +#define MXC_F_I2CS_INTFL_BYTE21 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE21_POS)) +#define MXC_F_I2CS_INTFL_BYTE22_POS 22 +#define MXC_F_I2CS_INTFL_BYTE22 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE22_POS)) +#define MXC_F_I2CS_INTFL_BYTE23_POS 23 +#define MXC_F_I2CS_INTFL_BYTE23 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE23_POS)) +#define MXC_F_I2CS_INTFL_BYTE24_POS 24 +#define MXC_F_I2CS_INTFL_BYTE24 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE24_POS)) +#define MXC_F_I2CS_INTFL_BYTE25_POS 25 +#define MXC_F_I2CS_INTFL_BYTE25 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE25_POS)) +#define MXC_F_I2CS_INTFL_BYTE26_POS 26 +#define MXC_F_I2CS_INTFL_BYTE26 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE26_POS)) +#define MXC_F_I2CS_INTFL_BYTE27_POS 27 +#define MXC_F_I2CS_INTFL_BYTE27 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE27_POS)) +#define MXC_F_I2CS_INTFL_BYTE28_POS 28 +#define MXC_F_I2CS_INTFL_BYTE28 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE28_POS)) +#define MXC_F_I2CS_INTFL_BYTE29_POS 29 +#define MXC_F_I2CS_INTFL_BYTE29 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE29_POS)) +#define MXC_F_I2CS_INTFL_BYTE30_POS 30 +#define MXC_F_I2CS_INTFL_BYTE30 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE30_POS)) +#define MXC_F_I2CS_INTFL_BYTE31_POS 31 +#define MXC_F_I2CS_INTFL_BYTE31 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTFL_BYTE31_POS)) + +#define MXC_F_I2CS_INTEN_BYTE0_POS 0 +#define MXC_F_I2CS_INTEN_BYTE0 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE0_POS)) +#define MXC_F_I2CS_INTEN_BYTE1_POS 1 +#define MXC_F_I2CS_INTEN_BYTE1 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE1_POS)) +#define MXC_F_I2CS_INTEN_BYTE2_POS 2 +#define MXC_F_I2CS_INTEN_BYTE2 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE2_POS)) +#define MXC_F_I2CS_INTEN_BYTE3_POS 3 +#define MXC_F_I2CS_INTEN_BYTE3 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE3_POS)) +#define MXC_F_I2CS_INTEN_BYTE4_POS 4 +#define MXC_F_I2CS_INTEN_BYTE4 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE4_POS)) +#define MXC_F_I2CS_INTEN_BYTE5_POS 5 +#define MXC_F_I2CS_INTEN_BYTE5 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE5_POS)) +#define MXC_F_I2CS_INTEN_BYTE6_POS 6 +#define MXC_F_I2CS_INTEN_BYTE6 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE6_POS)) +#define MXC_F_I2CS_INTEN_BYTE7_POS 7 +#define MXC_F_I2CS_INTEN_BYTE7 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE7_POS)) +#define MXC_F_I2CS_INTEN_BYTE8_POS 8 +#define MXC_F_I2CS_INTEN_BYTE8 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE8_POS)) +#define MXC_F_I2CS_INTEN_BYTE9_POS 9 +#define MXC_F_I2CS_INTEN_BYTE9 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE9_POS)) +#define MXC_F_I2CS_INTEN_BYTE10_POS 10 +#define MXC_F_I2CS_INTEN_BYTE10 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE10_POS)) +#define MXC_F_I2CS_INTEN_BYTE11_POS 11 +#define MXC_F_I2CS_INTEN_BYTE11 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE11_POS)) +#define MXC_F_I2CS_INTEN_BYTE12_POS 12 +#define MXC_F_I2CS_INTEN_BYTE12 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE12_POS)) +#define MXC_F_I2CS_INTEN_BYTE13_POS 13 +#define MXC_F_I2CS_INTEN_BYTE13 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE13_POS)) +#define MXC_F_I2CS_INTEN_BYTE14_POS 14 +#define MXC_F_I2CS_INTEN_BYTE14 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE14_POS)) +#define MXC_F_I2CS_INTEN_BYTE15_POS 15 +#define MXC_F_I2CS_INTEN_BYTE15 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE15_POS)) +#define MXC_F_I2CS_INTEN_BYTE16_POS 16 +#define MXC_F_I2CS_INTEN_BYTE16 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE16_POS)) +#define MXC_F_I2CS_INTEN_BYTE17_POS 17 +#define MXC_F_I2CS_INTEN_BYTE17 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE17_POS)) +#define MXC_F_I2CS_INTEN_BYTE18_POS 18 +#define MXC_F_I2CS_INTEN_BYTE18 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE18_POS)) +#define MXC_F_I2CS_INTEN_BYTE19_POS 19 +#define MXC_F_I2CS_INTEN_BYTE19 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE19_POS)) +#define MXC_F_I2CS_INTEN_BYTE20_POS 20 +#define MXC_F_I2CS_INTEN_BYTE20 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE20_POS)) +#define MXC_F_I2CS_INTEN_BYTE21_POS 21 +#define MXC_F_I2CS_INTEN_BYTE21 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE21_POS)) +#define MXC_F_I2CS_INTEN_BYTE22_POS 22 +#define MXC_F_I2CS_INTEN_BYTE22 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE22_POS)) +#define MXC_F_I2CS_INTEN_BYTE23_POS 23 +#define MXC_F_I2CS_INTEN_BYTE23 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE23_POS)) +#define MXC_F_I2CS_INTEN_BYTE24_POS 24 +#define MXC_F_I2CS_INTEN_BYTE24 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE24_POS)) +#define MXC_F_I2CS_INTEN_BYTE25_POS 25 +#define MXC_F_I2CS_INTEN_BYTE25 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE25_POS)) +#define MXC_F_I2CS_INTEN_BYTE26_POS 26 +#define MXC_F_I2CS_INTEN_BYTE26 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE26_POS)) +#define MXC_F_I2CS_INTEN_BYTE27_POS 27 +#define MXC_F_I2CS_INTEN_BYTE27 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE27_POS)) +#define MXC_F_I2CS_INTEN_BYTE28_POS 28 +#define MXC_F_I2CS_INTEN_BYTE28 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE28_POS)) +#define MXC_F_I2CS_INTEN_BYTE29_POS 29 +#define MXC_F_I2CS_INTEN_BYTE29 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE29_POS)) +#define MXC_F_I2CS_INTEN_BYTE30_POS 30 +#define MXC_F_I2CS_INTEN_BYTE30 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE30_POS)) +#define MXC_F_I2CS_INTEN_BYTE31_POS 31 +#define MXC_F_I2CS_INTEN_BYTE31 ((uint32_t)(0x00000001UL << MXC_F_I2CS_INTEN_BYTE31_POS)) + +#define MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS 0 +#define MXC_F_I2CS_DATA_BYTE_DATA_FIELD ((uint32_t)(0x000000FFUL << MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS)) +#define MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL_POS 8 +#define MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL ((uint32_t)(0x00000001UL << MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL_POS)) +#define MXC_F_I2CS_DATA_BYTE_DATA_UPDATED_FL_POS 9 +#define MXC_F_I2CS_DATA_BYTE_DATA_UPDATED_FL ((uint32_t)(0x00000001UL << MXC_F_I2CS_DATA_BYTE_DATA_UPDATED_FL_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_I2CS_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/icc_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/icc_regs.h new file mode 100644 index 0000000..1d27ed5 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/icc_regs.h @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_ICC_REGS_H_ +#define _MXC_ICC_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t id; /* 0x0000 Cache ID Register (INTERNAL USE ONLY) */ + __IO uint32_t mem_cfg; /* 0x0004 Memory Configuration Register */ + __I uint32_t rsv008[62]; /* 0x0008-0x00FC */ + __IO uint32_t ctrl_stat; /* 0x0100 Control and Status */ + __I uint32_t rsv104[383]; /* 0x0104-0x06FC */ + __IO uint32_t invdt_all; /* 0x0700 Invalidate (Clear) Cache Control */ +} mxc_icc_regs_t; + + +/* + Register offsets for module ICC. +*/ + +#define MXC_R_ICC_OFFS_ID ((uint32_t)0x00000000UL) +#define MXC_R_ICC_OFFS_MEM_CFG ((uint32_t)0x00000004UL) +#define MXC_R_ICC_OFFS_CTRL_STAT ((uint32_t)0x00000100UL) +#define MXC_R_ICC_OFFS_INVDT_ALL ((uint32_t)0x00000700UL) + + +/* + Field positions and masks for module ICC. +*/ + +#define MXC_F_ICC_ID_RTL_VERSION_POS 0 +#define MXC_F_ICC_ID_RTL_VERSION ((uint32_t)(0x0000003FUL << MXC_F_ICC_ID_RTL_VERSION_POS)) +#define MXC_F_ICC_ID_PART_NUM_POS 6 +#define MXC_F_ICC_ID_PART_NUM ((uint32_t)(0x0000000FUL << MXC_F_ICC_ID_PART_NUM_POS)) +#define MXC_F_ICC_ID_CACHE_ID_POS 10 +#define MXC_F_ICC_ID_CACHE_ID ((uint32_t)(0x0000003FUL << MXC_F_ICC_ID_CACHE_ID_POS)) + +#define MXC_F_ICC_MEM_CFG_CACHE_SIZE_POS 0 +#define MXC_F_ICC_MEM_CFG_CACHE_SIZE ((uint32_t)(0x0000FFFFUL << MXC_F_ICC_MEM_CFG_CACHE_SIZE_POS)) +#define MXC_F_ICC_MEM_CFG_MAIN_MEMORY_SIZE_POS 16 +#define MXC_F_ICC_MEM_CFG_MAIN_MEMORY_SIZE ((uint32_t)(0x0000FFFFUL << MXC_F_ICC_MEM_CFG_MAIN_MEMORY_SIZE_POS)) + +#define MXC_F_ICC_CTRL_STAT_ENABLE_POS 0 +#define MXC_F_ICC_CTRL_STAT_ENABLE ((uint32_t)(0x00000001UL << MXC_F_ICC_CTRL_STAT_ENABLE_POS)) +#define MXC_F_ICC_CTRL_STAT_READY_POS 16 +#define MXC_F_ICC_CTRL_STAT_READY ((uint32_t)(0x00000001UL << MXC_F_ICC_CTRL_STAT_READY_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_ICC_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/ioman_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/ioman_regs.h new file mode 100644 index 0000000..0124889 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/ioman_regs.h @@ -0,0 +1,816 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_IOMAN_REGS_H_ +#define _MXC_IOMAN_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Bitfield structs for registers in this module +*/ + +typedef struct { + uint32_t wud_req_p0 : 8; + uint32_t wud_req_p1 : 8; + uint32_t wud_req_p2 : 8; + uint32_t wud_req_p3 : 8; +} mxc_ioman_wud_req0_t; + +typedef struct { + uint32_t wud_req_p4 : 8; + uint32_t : 24; +} mxc_ioman_wud_req1_t; + +typedef struct { + uint32_t wud_ack_p0 : 8; + uint32_t wud_ack_p1 : 8; + uint32_t wud_ack_p2 : 8; + uint32_t wud_ack_p3 : 8; +} mxc_ioman_wud_ack0_t; + +typedef struct { + uint32_t wud_ack_p4 : 8; + uint32_t : 24; +} mxc_ioman_wud_ack1_t; + +typedef struct { + uint32_t ali_req_p0 : 8; + uint32_t ali_req_p1 : 8; + uint32_t ali_req_p2 : 8; + uint32_t ali_req_p3 : 8; +} mxc_ioman_ali_req0_t; + +typedef struct { + uint32_t ali_req_p4 : 8; + uint32_t : 24; +} mxc_ioman_ali_req1_t; + +typedef struct { + uint32_t ali_ack_p0 : 8; + uint32_t ali_ack_p1 : 8; + uint32_t ali_ack_p2 : 8; + uint32_t ali_ack_p3 : 8; +} mxc_ioman_ali_ack0_t; + +typedef struct { + uint32_t ali_ack_p4 : 8; + uint32_t : 24; +} mxc_ioman_ali_ack1_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_req : 1; + uint32_t : 3; + uint32_t ss0_io_req : 1; + uint32_t ss1_io_req : 1; + uint32_t ss2_io_req : 1; + uint32_t : 1; + uint32_t quad_io_req : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 15; +} mxc_ioman_spix_req_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_ack : 1; + uint32_t : 3; + uint32_t ss0_io_ack : 1; + uint32_t ss1_io_ack : 1; + uint32_t ss2_io_ack : 1; + uint32_t : 1; + uint32_t quad_io_ack : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 15; +} mxc_ioman_spix_ack_t; + +typedef struct { + uint32_t io_map : 1; + uint32_t cts_map : 1; + uint32_t rts_map : 1; + uint32_t : 1; + uint32_t io_req : 1; + uint32_t cts_io_req : 1; + uint32_t rts_io_req : 1; + uint32_t : 25; +} mxc_ioman_uart0_req_t; + +typedef struct { + uint32_t io_map : 1; + uint32_t cts_map : 1; + uint32_t rts_map : 1; + uint32_t : 1; + uint32_t io_ack : 1; + uint32_t cts_io_ack : 1; + uint32_t rts_io_ack : 1; + uint32_t : 25; +} mxc_ioman_uart0_ack_t; + +typedef struct { + uint32_t io_map : 1; + uint32_t cts_map : 1; + uint32_t rts_map : 1; + uint32_t : 1; + uint32_t io_req : 1; + uint32_t cts_io_req : 1; + uint32_t rts_io_req : 1; + uint32_t : 25; +} mxc_ioman_uart1_req_t; + +typedef struct { + uint32_t io_map : 1; + uint32_t cts_map : 1; + uint32_t rts_map : 1; + uint32_t : 1; + uint32_t io_ack : 1; + uint32_t cts_io_ack : 1; + uint32_t rts_io_ack : 1; + uint32_t : 25; +} mxc_ioman_uart1_ack_t; + +typedef struct { + uint32_t io_map : 1; + uint32_t cts_map : 1; + uint32_t rts_map : 1; + uint32_t : 1; + uint32_t io_req : 1; + uint32_t cts_io_req : 1; + uint32_t rts_io_req : 1; + uint32_t : 25; +} mxc_ioman_uart2_req_t; + +typedef struct { + uint32_t io_map : 1; + uint32_t cts_map : 1; + uint32_t rts_map : 1; + uint32_t : 1; + uint32_t io_ack : 1; + uint32_t cts_io_ack : 1; + uint32_t rts_io_ack : 1; + uint32_t : 25; +} mxc_ioman_uart2_ack_t; + +typedef struct { + uint32_t : 4; + uint32_t mapping_req : 1; + uint32_t scl_push_pull : 1; + uint32_t : 26; +} mxc_ioman_i2cm0_req_t; + +typedef struct { + uint32_t : 4; + uint32_t mapping_ack : 1; + uint32_t : 27; +} mxc_ioman_i2cm0_ack_t; + +typedef struct { + uint32_t : 4; + uint32_t mapping_req : 1; + uint32_t scl_push_pull : 1; + uint32_t : 26; +} mxc_ioman_i2cm1_req_t; + +typedef struct { + uint32_t : 4; + uint32_t mapping_ack : 1; + uint32_t : 27; +} mxc_ioman_i2cm1_ack_t; + +typedef struct { + uint32_t io_sel : 2; + uint32_t : 2; + uint32_t mapping_req : 1; + uint32_t : 27; +} mxc_ioman_i2cs_req_t; + +typedef struct { + uint32_t io_sel : 2; + uint32_t : 2; + uint32_t mapping_ack : 1; + uint32_t : 27; +} mxc_ioman_i2cs_ack_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_req : 1; + uint32_t : 3; + uint32_t ss0_io_req : 1; + uint32_t ss1_io_req : 1; + uint32_t ss2_io_req : 1; + uint32_t ss3_io_req : 1; + uint32_t ss4_io_req : 1; + uint32_t : 7; + uint32_t quad_io_req : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 7; +} mxc_ioman_spim0_req_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_ack : 1; + uint32_t : 3; + uint32_t ss0_io_ack : 1; + uint32_t ss1_io_ack : 1; + uint32_t ss2_io_ack : 1; + uint32_t ss3_io_ack : 1; + uint32_t ss4_io_ack : 1; + uint32_t : 7; + uint32_t quad_io_ack : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 7; +} mxc_ioman_spim0_ack_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_req : 1; + uint32_t : 3; + uint32_t ss0_io_req : 1; + uint32_t ss1_io_req : 1; + uint32_t ss2_io_req : 1; + uint32_t : 9; + uint32_t quad_io_req : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 7; +} mxc_ioman_spim1_req_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_ack : 1; + uint32_t : 3; + uint32_t ss0_io_ack : 1; + uint32_t ss1_io_ack : 1; + uint32_t ss2_io_ack : 1; + uint32_t : 9; + uint32_t quad_io_ack : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 7; +} mxc_ioman_spim1_ack_t; + +typedef struct { + uint32_t mapping_req : 2; // 1:0 + uint32_t : 1; // 2:3 + uint32_t core_io_req : 1; // 4 + uint32_t : 3; // 5:7 + uint32_t ss0_io_req : 1; // 8 + uint32_t ss1_io_req : 1; // 9 + uint32_t ss2_io_req : 1; // 10 + uint32_t : 5; // 11:15 + uint32_t sr0_io_req : 1; // 16 + uint32_t sr1_io_req : 1; // 17 + uint32_t : 2; // 18:19 + uint32_t quad_io_req : 1; // 20 + uint32_t : 3; // 21:23 + uint32_t fast_mode : 1; // 24 + uint32_t : 7; // 25:31 +} mxc_ioman_spim2_req_t; + +typedef struct { + uint32_t mapping_ack : 1; + uint32_t : 3; + uint32_t core_io_ack : 1; + uint32_t : 3; + uint32_t ss0_io_ack : 1; + uint32_t ss1_io_ack : 1; + uint32_t ss2_io_ack : 1; + uint32_t : 5; + uint32_t sr0_io_ack : 1; + uint32_t sr1_io_ack : 1; + uint32_t : 2; + uint32_t quad_io_ack : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 7; +} mxc_ioman_spim2_ack_t; + +typedef struct { + uint32_t : 4; + uint32_t mapping_req : 1; + uint32_t epu_io_req : 1; + uint32_t : 26; +} mxc_ioman_owm_req_t; + +typedef struct { + uint32_t : 4; + uint32_t mapping_ack : 1; + uint32_t epu_io_ack : 1; + uint32_t : 26; +} mxc_ioman_owm_ack_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_req : 1; + uint32_t : 3; + uint32_t quad_io_req : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 19; +} mxc_ioman_spis_req_t; + +typedef struct { + uint32_t : 4; + uint32_t core_io_ack : 1; + uint32_t : 3; + uint32_t quad_io_ack : 1; + uint32_t : 3; + uint32_t fast_mode : 1; + uint32_t : 19; +} mxc_ioman_spis_ack_t; + +typedef struct { + uint32_t slow_mode : 1; + uint32_t alt_rcvr_mode : 1; + uint32_t : 30; +} mxc_ioman_pad_mode_t; + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t wud_req0; /* 0x0000 Wakeup Detect Mode Request Register 0 (P0/P1/P2/P3) */ + __IO uint32_t wud_req1; /* 0x0004 Wakeup Detect Mode Request Register 1 (P4) */ + __IO uint32_t wud_ack0; /* 0x0008 Wakeup Detect Mode Acknowledge Register 0 (P0/P1/P2/P3) */ + __IO uint32_t wud_ack1; /* 0x000C Wakeup Detect Mode Acknowledge Register 1 (P4) */ + __IO uint32_t ali_req0; /* 0x0010 Analog Input Request Register 0 (P0/P1/P2/P3) */ + __IO uint32_t ali_req1; /* 0x0014 Analog Input Request Register 1 (P4) */ + __IO uint32_t ali_ack0; /* 0x0018 Analog Input Acknowledge Register 0 (P0/P1/P2/P3) */ + __IO uint32_t ali_ack1; /* 0x001C Analog Input Acknowledge Register 1 (P4) */ + __IO uint32_t ali_connect0; /* 0x0020 Analog I/O Connection Control Register 0 */ + __IO uint32_t ali_connect1; /* 0x0024 Analog I/O Connection Control Register 1 */ + __IO uint32_t spix_req; /* 0x0028 SPIX I/O Mode Request */ + __IO uint32_t spix_ack; /* 0x002C SPIX I/O Mode Acknowledge */ + __IO uint32_t uart0_req; /* 0x0030 UART0 I/O Mode Request */ + __IO uint32_t uart0_ack; /* 0x0034 UART0 I/O Mode Acknowledge */ + __IO uint32_t uart1_req; /* 0x0038 UART1 I/O Mode Request */ + __IO uint32_t uart1_ack; /* 0x003C UART1 I/O Mode Acknowledge */ + __IO uint32_t uart2_req; /* 0x0040 UART2 I/O Mode Request */ + __IO uint32_t uart2_ack; /* 0x0044 UART2 I/O Mode Acknowledge */ + __I uint32_t rsv048[2]; /* 0x0048-0x004C */ + __IO uint32_t i2cm0_req; /* 0x0050 I2C Master 0 I/O Request */ + __IO uint32_t i2cm0_ack; /* 0x0054 I2C Master 0 I/O Acknowledge */ + __IO uint32_t i2cm1_req; /* 0x0058 I2C Master 1 I/O Request */ + __IO uint32_t i2cm1_ack; /* 0x005C I2C Master 1 I/O Acknowledge */ + __I uint32_t rsv060[2]; /* 0x0060-0x0064 */ + __IO uint32_t i2cs_req; /* 0x0068 I2C Slave I/O Request */ + __IO uint32_t i2cs_ack; /* 0x006C I2C Slave I/O Acknowledge */ + __IO uint32_t spim0_req; /* 0x0070 SPI Master 0 I/O Mode Request */ + __IO uint32_t spim0_ack; /* 0x0074 SPI Master 0 I/O Mode Acknowledge */ + __IO uint32_t spim1_req; /* 0x0078 SPI Master 1 I/O Mode Request */ + __IO uint32_t spim1_ack; /* 0x007C SPI Master 1 I/O Mode Acknowledge */ + __IO uint32_t spim2_req; /* 0x0080 SPI Master 2 I/O Mode Request */ + __IO uint32_t spim2_ack; /* 0x0084 SPI Master 2 I/O Mode Acknowledge */ + __I uint32_t rsv088[2]; /* 0x0088-0x008C */ + __IO uint32_t owm_req; /* 0x0090 1-Wire Master I/O Mode Request */ + __IO uint32_t owm_ack; /* 0x0094 1-Wire Master I/O Mode Acknowledge */ + __IO uint32_t spis_req; /* 0x0098 SPI Slave I/O Mode Request */ + __IO uint32_t spis_ack; /* 0x009C SPI Slave I/O Mode Acknowledge */ + __I uint32_t rsv0A0[24]; /* 0x00A0-0x00FC */ + __IO uint32_t use_vddioh_0; /* 0x0100 Enable VDDIOH Register 0 */ + __IO uint32_t use_vddioh_1; /* 0x0104 Enable VDDIOH Register 1 */ + __I uint32_t rsv108[2]; /* 0x0108-0x010C */ + __IO uint32_t pad_mode; /* 0x0110 Pad Mode Control Register */ +} mxc_ioman_regs_t; + + +/* + Register offsets for module IOMAN. +*/ + +#define MXC_R_IOMAN_OFFS_WUD_REQ0 ((uint32_t)0x00000000UL) +#define MXC_R_IOMAN_OFFS_WUD_REQ1 ((uint32_t)0x00000004UL) +#define MXC_R_IOMAN_OFFS_WUD_ACK0 ((uint32_t)0x00000008UL) +#define MXC_R_IOMAN_OFFS_WUD_ACK1 ((uint32_t)0x0000000CUL) +#define MXC_R_IOMAN_OFFS_ALI_REQ0 ((uint32_t)0x00000010UL) +#define MXC_R_IOMAN_OFFS_ALI_REQ1 ((uint32_t)0x00000014UL) +#define MXC_R_IOMAN_OFFS_ALI_ACK0 ((uint32_t)0x00000018UL) +#define MXC_R_IOMAN_OFFS_ALI_ACK1 ((uint32_t)0x0000001CUL) +#define MXC_R_IOMAN_OFFS_ALI_CONNECT0 ((uint32_t)0x00000020UL) +#define MXC_R_IOMAN_OFFS_ALI_CONNECT1 ((uint32_t)0x00000024UL) +#define MXC_R_IOMAN_OFFS_SPIX_REQ ((uint32_t)0x00000028UL) +#define MXC_R_IOMAN_OFFS_SPIX_ACK ((uint32_t)0x0000002CUL) +#define MXC_R_IOMAN_OFFS_UART0_REQ ((uint32_t)0x00000030UL) +#define MXC_R_IOMAN_OFFS_UART0_ACK ((uint32_t)0x00000034UL) +#define MXC_R_IOMAN_OFFS_UART1_REQ ((uint32_t)0x00000038UL) +#define MXC_R_IOMAN_OFFS_UART1_ACK ((uint32_t)0x0000003CUL) +#define MXC_R_IOMAN_OFFS_UART2_REQ ((uint32_t)0x00000040UL) +#define MXC_R_IOMAN_OFFS_UART2_ACK ((uint32_t)0x00000044UL) +#define MXC_R_IOMAN_OFFS_I2CM0_REQ ((uint32_t)0x00000050UL) +#define MXC_R_IOMAN_OFFS_I2CM0_ACK ((uint32_t)0x00000054UL) +#define MXC_R_IOMAN_OFFS_I2CM1_REQ ((uint32_t)0x00000058UL) +#define MXC_R_IOMAN_OFFS_I2CM1_ACK ((uint32_t)0x0000005CUL) +#define MXC_R_IOMAN_OFFS_I2CS_REQ ((uint32_t)0x00000068UL) +#define MXC_R_IOMAN_OFFS_I2CS_ACK ((uint32_t)0x0000006CUL) +#define MXC_R_IOMAN_OFFS_SPIM0_REQ ((uint32_t)0x00000070UL) +#define MXC_R_IOMAN_OFFS_SPIM0_ACK ((uint32_t)0x00000074UL) +#define MXC_R_IOMAN_OFFS_SPIM1_REQ ((uint32_t)0x00000078UL) +#define MXC_R_IOMAN_OFFS_SPIM1_ACK ((uint32_t)0x0000007CUL) +#define MXC_R_IOMAN_OFFS_SPIM2_REQ ((uint32_t)0x00000080UL) +#define MXC_R_IOMAN_OFFS_SPIM2_ACK ((uint32_t)0x00000084UL) +#define MXC_R_IOMAN_OFFS_OWM_REQ ((uint32_t)0x00000090UL) +#define MXC_R_IOMAN_OFFS_OWM_ACK ((uint32_t)0x00000094UL) +#define MXC_R_IOMAN_OFFS_SPIS_REQ ((uint32_t)0x00000098UL) +#define MXC_R_IOMAN_OFFS_SPIS_ACK ((uint32_t)0x0000009CUL) +#define MXC_R_IOMAN_OFFS_USE_VDDIOH_0 ((uint32_t)0x00000100UL) +#define MXC_R_IOMAN_OFFS_USE_VDDIOH_1 ((uint32_t)0x00000104UL) +#define MXC_R_IOMAN_OFFS_PAD_MODE ((uint32_t)0x00000110UL) + + +/* + Field positions and masks for module IOMAN. +*/ + +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P0_POS 0 +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P0 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P0_POS)) +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P1_POS 8 +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P1 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P1_POS)) +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P2_POS 16 +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P2 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P2_POS)) +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P3_POS 24 +#define MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P3 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_REQ0_WUD_REQ_P3_POS)) + +#define MXC_F_IOMAN_WUD_REQ1_WUD_REQ_P4_POS 0 +#define MXC_F_IOMAN_WUD_REQ1_WUD_REQ_P4 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_REQ1_WUD_REQ_P4_POS)) + +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P0_POS 0 +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P0 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P0_POS)) +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P1_POS 8 +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P1 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P1_POS)) +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P2_POS 16 +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P2 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P2_POS)) +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P3_POS 24 +#define MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P3 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_ACK0_WUD_ACK_P3_POS)) + +#define MXC_F_IOMAN_WUD_ACK1_WUD_ACK_P4_POS 0 +#define MXC_F_IOMAN_WUD_ACK1_WUD_ACK_P4 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_WUD_ACK1_WUD_ACK_P4_POS)) + +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P0_POS 0 +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P0 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P0_POS)) +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P1_POS 8 +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P1 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P1_POS)) +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P2_POS 16 +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P2 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P2_POS)) +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P3_POS 24 +#define MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P3 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_REQ0_ALI_REQ_P3_POS)) + +#define MXC_F_IOMAN_ALI_REQ1_ALI_REQ_P4_POS 0 +#define MXC_F_IOMAN_ALI_REQ1_ALI_REQ_P4 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_REQ1_ALI_REQ_P4_POS)) + +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P0_POS 0 +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P0 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P0_POS)) +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P1_POS 8 +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P1 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P1_POS)) +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P2_POS 16 +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P2 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P2_POS)) +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P3_POS 24 +#define MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P3 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_ACK0_ALI_ACK_P3_POS)) + +#define MXC_F_IOMAN_ALI_ACK1_ALI_ACK_P4_POS 0 +#define MXC_F_IOMAN_ALI_ACK1_ALI_ACK_P4 ((uint32_t)(0x000000FFUL << MXC_F_IOMAN_ALI_ACK1_ALI_ACK_P4_POS)) + +#define MXC_F_IOMAN_SPIX_REQ_CORE_IO_REQ_POS 4 +#define MXC_F_IOMAN_SPIX_REQ_CORE_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_REQ_CORE_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIX_REQ_SS0_IO_REQ_POS 8 +#define MXC_F_IOMAN_SPIX_REQ_SS0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_REQ_SS0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIX_REQ_SS1_IO_REQ_POS 9 +#define MXC_F_IOMAN_SPIX_REQ_SS1_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_REQ_SS1_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIX_REQ_SS2_IO_REQ_POS 10 +#define MXC_F_IOMAN_SPIX_REQ_SS2_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_REQ_SS2_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIX_REQ_QUAD_IO_REQ_POS 12 +#define MXC_F_IOMAN_SPIX_REQ_QUAD_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_REQ_QUAD_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIX_REQ_FAST_MODE_POS 16 +#define MXC_F_IOMAN_SPIX_REQ_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_REQ_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIX_ACK_CORE_IO_ACK_POS 4 +#define MXC_F_IOMAN_SPIX_ACK_CORE_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_ACK_CORE_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIX_ACK_SS0_IO_ACK_POS 8 +#define MXC_F_IOMAN_SPIX_ACK_SS0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_ACK_SS0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIX_ACK_SS1_IO_ACK_POS 9 +#define MXC_F_IOMAN_SPIX_ACK_SS1_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_ACK_SS1_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIX_ACK_SS2_IO_ACK_POS 10 +#define MXC_F_IOMAN_SPIX_ACK_SS2_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_ACK_SS2_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIX_ACK_QUAD_IO_ACK_POS 12 +#define MXC_F_IOMAN_SPIX_ACK_QUAD_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_ACK_QUAD_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIX_ACK_FAST_MODE_POS 16 +#define MXC_F_IOMAN_SPIX_ACK_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIX_ACK_FAST_MODE_POS)) + +#define MXC_F_IOMAN_UART0_REQ_IO_MAP_POS 0 +#define MXC_F_IOMAN_UART0_REQ_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_IO_MAP_POS)) +#define MXC_F_IOMAN_UART0_REQ_CTS_MAP_POS 1 +#define MXC_F_IOMAN_UART0_REQ_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART0_REQ_RTS_MAP_POS 2 +#define MXC_F_IOMAN_UART0_REQ_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART0_REQ_IO_REQ_POS 4 +#define MXC_F_IOMAN_UART0_REQ_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_IO_REQ_POS)) +#define MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ_POS 5 +#define MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ_POS)) +#define MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ_POS 6 +#define MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ_POS)) + +#define MXC_F_IOMAN_UART0_ACK_IO_MAP_POS 0 +#define MXC_F_IOMAN_UART0_ACK_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_IO_MAP_POS)) +#define MXC_F_IOMAN_UART0_ACK_CTS_MAP_POS 1 +#define MXC_F_IOMAN_UART0_ACK_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART0_ACK_RTS_MAP_POS 2 +#define MXC_F_IOMAN_UART0_ACK_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART0_ACK_IO_ACK_POS 4 +#define MXC_F_IOMAN_UART0_ACK_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_IO_ACK_POS)) +#define MXC_F_IOMAN_UART0_ACK_CTS_IO_ACK_POS 5 +#define MXC_F_IOMAN_UART0_ACK_CTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_CTS_IO_ACK_POS)) +#define MXC_F_IOMAN_UART0_ACK_RTS_IO_ACK_POS 6 +#define MXC_F_IOMAN_UART0_ACK_RTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_RTS_IO_ACK_POS)) + +#define MXC_F_IOMAN_UART1_REQ_IO_MAP_POS 0 +#define MXC_F_IOMAN_UART1_REQ_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_REQ_IO_MAP_POS)) +#define MXC_F_IOMAN_UART1_REQ_CTS_MAP_POS 1 +#define MXC_F_IOMAN_UART1_REQ_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_REQ_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART1_REQ_RTS_MAP_POS 2 +#define MXC_F_IOMAN_UART1_REQ_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_REQ_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART1_REQ_IO_REQ_POS 4 +#define MXC_F_IOMAN_UART1_REQ_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_REQ_IO_REQ_POS)) +#define MXC_F_IOMAN_UART1_REQ_CTS_IO_REQ_POS 5 +#define MXC_F_IOMAN_UART1_REQ_CTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_REQ_CTS_IO_REQ_POS)) +#define MXC_F_IOMAN_UART1_REQ_RTS_IO_REQ_POS 6 +#define MXC_F_IOMAN_UART1_REQ_RTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_REQ_RTS_IO_REQ_POS)) + +#define MXC_F_IOMAN_UART1_ACK_IO_MAP_POS 0 +#define MXC_F_IOMAN_UART1_ACK_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_ACK_IO_MAP_POS)) +#define MXC_F_IOMAN_UART1_ACK_CTS_MAP_POS 1 +#define MXC_F_IOMAN_UART1_ACK_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_ACK_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART1_ACK_RTS_MAP_POS 2 +#define MXC_F_IOMAN_UART1_ACK_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_ACK_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART1_ACK_IO_ACK_POS 4 +#define MXC_F_IOMAN_UART1_ACK_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_ACK_IO_ACK_POS)) +#define MXC_F_IOMAN_UART1_ACK_CTS_IO_ACK_POS 5 +#define MXC_F_IOMAN_UART1_ACK_CTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_ACK_CTS_IO_ACK_POS)) +#define MXC_F_IOMAN_UART1_ACK_RTS_IO_ACK_POS 6 +#define MXC_F_IOMAN_UART1_ACK_RTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART1_ACK_RTS_IO_ACK_POS)) + +#define MXC_F_IOMAN_UART2_REQ_IO_MAP_POS 0 +#define MXC_F_IOMAN_UART2_REQ_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_REQ_IO_MAP_POS)) +#define MXC_F_IOMAN_UART2_REQ_CTS_MAP_POS 1 +#define MXC_F_IOMAN_UART2_REQ_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_REQ_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART2_REQ_RTS_MAP_POS 2 +#define MXC_F_IOMAN_UART2_REQ_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_REQ_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART2_REQ_IO_REQ_POS 4 +#define MXC_F_IOMAN_UART2_REQ_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_REQ_IO_REQ_POS)) +#define MXC_F_IOMAN_UART2_REQ_CTS_IO_REQ_POS 5 +#define MXC_F_IOMAN_UART2_REQ_CTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_REQ_CTS_IO_REQ_POS)) +#define MXC_F_IOMAN_UART2_REQ_RTS_IO_REQ_POS 6 +#define MXC_F_IOMAN_UART2_REQ_RTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_REQ_RTS_IO_REQ_POS)) + +#define MXC_F_IOMAN_UART2_ACK_IO_MAP_POS 0 +#define MXC_F_IOMAN_UART2_ACK_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_ACK_IO_MAP_POS)) +#define MXC_F_IOMAN_UART2_ACK_CTS_MAP_POS 1 +#define MXC_F_IOMAN_UART2_ACK_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_ACK_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART2_ACK_RTS_MAP_POS 2 +#define MXC_F_IOMAN_UART2_ACK_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_ACK_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART2_ACK_IO_ACK_POS 4 +#define MXC_F_IOMAN_UART2_ACK_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_ACK_IO_ACK_POS)) +#define MXC_F_IOMAN_UART2_ACK_CTS_IO_ACK_POS 5 +#define MXC_F_IOMAN_UART2_ACK_CTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_ACK_CTS_IO_ACK_POS)) +#define MXC_F_IOMAN_UART2_ACK_RTS_IO_ACK_POS 6 +#define MXC_F_IOMAN_UART2_ACK_RTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART2_ACK_RTS_IO_ACK_POS)) + +#define MXC_F_IOMAN_I2CM0_REQ_MAPPING_REQ_POS 4 +#define MXC_F_IOMAN_I2CM0_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM0_REQ_MAPPING_REQ_POS)) +#define MXC_F_IOMAN_I2CM0_REQ_SCL_PUSH_PULL_POS 5 +#define MXC_F_IOMAN_I2CM0_REQ_SCL_PUSH_PULL ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM0_REQ_SCL_PUSH_PULL_POS)) + +#define MXC_F_IOMAN_I2CM0_ACK_MAPPING_ACK_POS 4 +#define MXC_F_IOMAN_I2CM0_ACK_MAPPING_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM0_ACK_MAPPING_ACK_POS)) + +#define MXC_F_IOMAN_I2CM1_REQ_MAPPING_REQ_POS 4 +#define MXC_F_IOMAN_I2CM1_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM1_REQ_MAPPING_REQ_POS)) +#define MXC_F_IOMAN_I2CM1_REQ_SCL_PUSH_PULL_POS 5 +#define MXC_F_IOMAN_I2CM1_REQ_SCL_PUSH_PULL ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM1_REQ_SCL_PUSH_PULL_POS)) + +#define MXC_F_IOMAN_I2CM1_ACK_MAPPING_ACK_POS 4 +#define MXC_F_IOMAN_I2CM1_ACK_MAPPING_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM1_ACK_MAPPING_ACK_POS)) + +#define MXC_F_IOMAN_I2CS_REQ_IO_SEL_POS 0 +#define MXC_F_IOMAN_I2CS_REQ_IO_SEL ((uint32_t)(0x00000003UL << MXC_F_IOMAN_I2CS_REQ_IO_SEL_POS)) +#define MXC_F_IOMAN_I2CS_REQ_MAPPING_REQ_POS 4 +#define MXC_F_IOMAN_I2CS_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CS_REQ_MAPPING_REQ_POS)) + +#define MXC_F_IOMAN_I2CS_ACK_IO_SEL_POS 0 +#define MXC_F_IOMAN_I2CS_ACK_IO_SEL ((uint32_t)(0x00000003UL << MXC_F_IOMAN_I2CS_ACK_IO_SEL_POS)) +#define MXC_F_IOMAN_I2CS_ACK_MAPPING_ACK_POS 4 +#define MXC_F_IOMAN_I2CS_ACK_MAPPING_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CS_ACK_MAPPING_ACK_POS)) + +#define MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ_POS 4 +#define MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_SS0_IO_REQ_POS 8 +#define MXC_F_IOMAN_SPIM0_REQ_SS0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_SS0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_SS1_IO_REQ_POS 9 +#define MXC_F_IOMAN_SPIM0_REQ_SS1_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_SS1_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_SS2_IO_REQ_POS 10 +#define MXC_F_IOMAN_SPIM0_REQ_SS2_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_SS2_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_SS3_IO_REQ_POS 11 +#define MXC_F_IOMAN_SPIM0_REQ_SS3_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_SS3_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_SS4_IO_REQ_POS 12 +#define MXC_F_IOMAN_SPIM0_REQ_SS4_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_SS4_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_QUAD_IO_REQ_POS 20 +#define MXC_F_IOMAN_SPIM0_REQ_QUAD_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_QUAD_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM0_REQ_FAST_MODE_POS 24 +#define MXC_F_IOMAN_SPIM0_REQ_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK_POS 4 +#define MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_SS0_IO_ACK_POS 8 +#define MXC_F_IOMAN_SPIM0_ACK_SS0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_SS0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_SS1_IO_ACK_POS 9 +#define MXC_F_IOMAN_SPIM0_ACK_SS1_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_SS1_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_SS2_IO_ACK_POS 10 +#define MXC_F_IOMAN_SPIM0_ACK_SS2_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_SS2_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_SS3_IO_ACK_POS 11 +#define MXC_F_IOMAN_SPIM0_ACK_SS3_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_SS3_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_SS4_IO_ACK_POS 12 +#define MXC_F_IOMAN_SPIM0_ACK_SS4_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_SS4_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_QUAD_IO_ACK_POS 20 +#define MXC_F_IOMAN_SPIM0_ACK_QUAD_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_QUAD_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM0_ACK_FAST_MODE_POS 24 +#define MXC_F_IOMAN_SPIM0_ACK_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIM1_REQ_CORE_IO_REQ_POS 4 +#define MXC_F_IOMAN_SPIM1_REQ_CORE_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_REQ_CORE_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM1_REQ_SS0_IO_REQ_POS 8 +#define MXC_F_IOMAN_SPIM1_REQ_SS0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_REQ_SS0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM1_REQ_SS1_IO_REQ_POS 9 +#define MXC_F_IOMAN_SPIM1_REQ_SS1_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_REQ_SS1_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM1_REQ_SS2_IO_REQ_POS 10 +#define MXC_F_IOMAN_SPIM1_REQ_SS2_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_REQ_SS2_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM1_REQ_QUAD_IO_REQ_POS 20 +#define MXC_F_IOMAN_SPIM1_REQ_QUAD_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_REQ_QUAD_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM1_REQ_FAST_MODE_POS 24 +#define MXC_F_IOMAN_SPIM1_REQ_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_REQ_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIM1_ACK_CORE_IO_ACK_POS 4 +#define MXC_F_IOMAN_SPIM1_ACK_CORE_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_ACK_CORE_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM1_ACK_SS0_IO_ACK_POS 8 +#define MXC_F_IOMAN_SPIM1_ACK_SS0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_ACK_SS0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM1_ACK_SS1_IO_ACK_POS 9 +#define MXC_F_IOMAN_SPIM1_ACK_SS1_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_ACK_SS1_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM1_ACK_SS2_IO_ACK_POS 10 +#define MXC_F_IOMAN_SPIM1_ACK_SS2_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_ACK_SS2_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM1_ACK_QUAD_IO_ACK_POS 20 +#define MXC_F_IOMAN_SPIM1_ACK_QUAD_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_ACK_QUAD_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM1_ACK_FAST_MODE_POS 24 +#define MXC_F_IOMAN_SPIM1_ACK_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM1_ACK_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIM2_REQ_MAPPING_REQ_POS 0 +#define MXC_F_IOMAN_SPIM2_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_MAPPING_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_CORE_IO_REQ_POS 4 +#define MXC_F_IOMAN_SPIM2_REQ_CORE_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_CORE_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_SS0_IO_REQ_POS 8 +#define MXC_F_IOMAN_SPIM2_REQ_SS0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_SS0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_SS1_IO_REQ_POS 9 +#define MXC_F_IOMAN_SPIM2_REQ_SS1_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_SS1_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_SS2_IO_REQ_POS 10 +#define MXC_F_IOMAN_SPIM2_REQ_SS2_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_SS2_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_SR0_IO_REQ_POS 16 +#define MXC_F_IOMAN_SPIM2_REQ_SR0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_SR0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_SR1_IO_REQ_POS 17 +#define MXC_F_IOMAN_SPIM2_REQ_SR1_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_SR1_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM2_REQ_FAST_MODE_POS 24 +#define MXC_F_IOMAN_SPIM2_REQ_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIM2_ACK_MAPPING_ACK_POS 0 +#define MXC_F_IOMAN_SPIM2_ACK_MAPPING_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_MAPPING_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_CORE_IO_ACK_POS 4 +#define MXC_F_IOMAN_SPIM2_ACK_CORE_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_CORE_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_SS0_IO_ACK_POS 8 +#define MXC_F_IOMAN_SPIM2_ACK_SS0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_SS0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_SS1_IO_ACK_POS 9 +#define MXC_F_IOMAN_SPIM2_ACK_SS1_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_SS1_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_SS2_IO_ACK_POS 10 +#define MXC_F_IOMAN_SPIM2_ACK_SS2_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_SS2_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_SR0_IO_ACK_POS 16 +#define MXC_F_IOMAN_SPIM2_ACK_SR0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_SR0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_SR1_IO_ACK_POS 17 +#define MXC_F_IOMAN_SPIM2_ACK_SR1_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_SR1_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM2_ACK_FAST_MODE_POS 24 +#define MXC_F_IOMAN_SPIM2_ACK_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_FAST_MODE_POS)) + +#define MXC_F_IOMAN_OWM_REQ_MAPPING_REQ_POS 4 +#define MXC_F_IOMAN_OWM_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_OWM_REQ_MAPPING_REQ_POS)) +#define MXC_F_IOMAN_OWM_REQ_EPU_IO_REQ_POS 5 +#define MXC_F_IOMAN_OWM_REQ_EPU_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_OWM_REQ_EPU_IO_REQ_POS)) + +#define MXC_F_IOMAN_OWM_ACK_MAPPING_ACK_POS 4 +#define MXC_F_IOMAN_OWM_ACK_MAPPING_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_OWM_ACK_MAPPING_ACK_POS)) +#define MXC_F_IOMAN_OWM_ACK_EPU_IO_ACK_POS 5 +#define MXC_F_IOMAN_OWM_ACK_EPU_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_OWM_ACK_EPU_IO_ACK_POS)) + +#define MXC_F_IOMAN_SPIS_REQ_CORE_IO_REQ_POS 4 +#define MXC_F_IOMAN_SPIS_REQ_CORE_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIS_REQ_CORE_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIS_REQ_QUAD_IO_REQ_POS 8 +#define MXC_F_IOMAN_SPIS_REQ_QUAD_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIS_REQ_QUAD_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIS_REQ_FAST_MODE_POS 12 +#define MXC_F_IOMAN_SPIS_REQ_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIS_REQ_FAST_MODE_POS)) + +#define MXC_F_IOMAN_SPIS_ACK_CORE_IO_ACK_POS 4 +#define MXC_F_IOMAN_SPIS_ACK_CORE_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIS_ACK_CORE_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIS_ACK_QUAD_IO_ACK_POS 8 +#define MXC_F_IOMAN_SPIS_ACK_QUAD_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIS_ACK_QUAD_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIS_ACK_FAST_MODE_POS 12 +#define MXC_F_IOMAN_SPIS_ACK_FAST_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIS_ACK_FAST_MODE_POS)) + +#define MXC_F_IOMAN_PAD_MODE_SLOW_MODE_POS 0 +#define MXC_F_IOMAN_PAD_MODE_SLOW_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_PAD_MODE_SLOW_MODE_POS)) +#define MXC_F_IOMAN_PAD_MODE_ALT_RCVR_MODE_POS 1 +#define MXC_F_IOMAN_PAD_MODE_ALT_RCVR_MODE ((uint32_t)(0x00000001UL << MXC_F_IOMAN_PAD_MODE_ALT_RCVR_MODE_POS)) + +/* + Generic field positions and masks for module IOMAN. +*/ +#define MXC_F_IOMAN_UART_REQ_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_IO_MAP_POS)) +#define MXC_F_IOMAN_UART_REQ_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART_REQ_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART_REQ_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_IO_REQ_POS)) +#define MXC_F_IOMAN_UART_REQ_CTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ_POS)) +#define MXC_F_IOMAN_UART_REQ_RTS_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ_POS)) + +#define MXC_F_IOMAN_UART_ACK_IO_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_IO_MAP_POS)) +#define MXC_F_IOMAN_UART_ACK_CTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_CTS_MAP_POS)) +#define MXC_F_IOMAN_UART_ACK_RTS_MAP ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_RTS_MAP_POS)) +#define MXC_F_IOMAN_UART_ACK_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_IO_ACK_POS)) +#define MXC_F_IOMAN_UART_ACK_CTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_CTS_IO_ACK_POS)) +#define MXC_F_IOMAN_UART_ACK_RTS_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_UART0_ACK_RTS_IO_ACK_POS)) + +#define MXC_F_IOMAN_I2CM_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM0_REQ_MAPPING_REQ_POS)) +#define MXC_F_IOMAN_I2CM_ACK_MAPPING_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_I2CM0_ACK_MAPPING_ACK_POS)) + +#define MXC_F_IOMAN_SPIM_REQ_CORE_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_CORE_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM_REQ_SS0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_SS0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM_REQ_SR0_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_SR0_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM_REQ_QUAD_IO_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_REQ_QUAD_IO_REQ_POS)) +#define MXC_F_IOMAN_SPIM_ACK_CORE_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_CORE_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM_ACK_SS0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_SS0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM_ACK_SR0_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_ACK_SR0_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM_ACK_QUAD_IO_ACK ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM0_ACK_QUAD_IO_ACK_POS)) +#define MXC_F_IOMAN_SPIM_REQ_MAPPING_REQ ((uint32_t)(0x00000001UL << MXC_F_IOMAN_SPIM2_REQ_MAPPING_REQ_POS)) + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_IOMAN_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/maa_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/maa_regs.h new file mode 100644 index 0000000..58c33f1 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/maa_regs.h @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_MAA_REGS_H_ +#define _MXC_MAA_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 MAA Control, Configuration and Status */ + __IO uint32_t maws; /* 0x0004 MAA Word (Operand) Size, Big/Little Endian Mode Select */ +} mxc_maa_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t seg0[32]; /* 0x0000-0x007C [128 bytes] MAA Memory Segment 0 */ + __IO uint32_t seg1[32]; /* 0x0080-0x00FC [128 bytes] MAA Memory Segment 1 */ + __IO uint32_t seg2[32]; /* 0x0100-0x017C [128 bytes] MAA Memory Segment 2 */ + __IO uint32_t seg3[32]; /* 0x0180-0x01FC [128 bytes] MAA Memory Segment 3 */ + __IO uint32_t seg4[32]; /* 0x0200-0x027C [128 bytes] MAA Memory Segment 4 */ + __IO uint32_t seg5[32]; /* 0x0280-0x02FC [128 bytes] MAA Memory Segment 5 */ +} mxc_maa_mem_regs_t; + + +/* + Register offsets for module MAA. +*/ + +#define MXC_R_MAA_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_MAA_OFFS_MAWS ((uint32_t)0x00000004UL) +#define MXC_R_MAA_MEM_OFFS_SEG0 ((uint32_t)0x00000000UL) +#define MXC_R_MAA_MEM_OFFS_SEG1 ((uint32_t)0x00000080UL) +#define MXC_R_MAA_MEM_OFFS_SEG2 ((uint32_t)0x00000100UL) +#define MXC_R_MAA_MEM_OFFS_SEG3 ((uint32_t)0x00000180UL) +#define MXC_R_MAA_MEM_OFFS_SEG4 ((uint32_t)0x00000200UL) +#define MXC_R_MAA_MEM_OFFS_SEG5 ((uint32_t)0x00000280UL) + + +/* + Field positions and masks for module MAA. +*/ + +#define MXC_F_MAA_CTRL_START_POS 0 +#define MXC_F_MAA_CTRL_START ((uint32_t)(0x00000001UL << MXC_F_MAA_CTRL_START_POS)) +#define MXC_F_MAA_CTRL_OPSEL_POS 1 +#define MXC_F_MAA_CTRL_OPSEL ((uint32_t)(0x00000007UL << MXC_F_MAA_CTRL_OPSEL_POS)) +#define MXC_F_MAA_CTRL_OCALC_POS 4 +#define MXC_F_MAA_CTRL_OCALC ((uint32_t)(0x00000001UL << MXC_F_MAA_CTRL_OCALC_POS)) +#define MXC_F_MAA_CTRL_IF_DONE_POS 5 +#define MXC_F_MAA_CTRL_IF_DONE ((uint32_t)(0x00000001UL << MXC_F_MAA_CTRL_IF_DONE_POS)) +#define MXC_F_MAA_CTRL_INTEN_POS 6 +#define MXC_F_MAA_CTRL_INTEN ((uint32_t)(0x00000001UL << MXC_F_MAA_CTRL_INTEN_POS)) +#define MXC_F_MAA_CTRL_IF_ERROR_POS 7 +#define MXC_F_MAA_CTRL_IF_ERROR ((uint32_t)(0x00000001UL << MXC_F_MAA_CTRL_IF_ERROR_POS)) +#define MXC_F_MAA_CTRL_OFS_A_POS 8 +#define MXC_F_MAA_CTRL_OFS_A ((uint32_t)(0x00000003UL << MXC_F_MAA_CTRL_OFS_A_POS)) +#define MXC_F_MAA_CTRL_OFS_B_POS 10 +#define MXC_F_MAA_CTRL_OFS_B ((uint32_t)(0x00000003UL << MXC_F_MAA_CTRL_OFS_B_POS)) +#define MXC_F_MAA_CTRL_OFS_EXP_POS 12 +#define MXC_F_MAA_CTRL_OFS_EXP ((uint32_t)(0x00000003UL << MXC_F_MAA_CTRL_OFS_EXP_POS)) +#define MXC_F_MAA_CTRL_OFS_MOD_POS 14 +#define MXC_F_MAA_CTRL_OFS_MOD ((uint32_t)(0x00000003UL << MXC_F_MAA_CTRL_OFS_MOD_POS)) +#define MXC_F_MAA_CTRL_SEG_A_POS 16 +#define MXC_F_MAA_CTRL_SEG_A ((uint32_t)(0x0000000FUL << MXC_F_MAA_CTRL_SEG_A_POS)) +#define MXC_F_MAA_CTRL_SEG_B_POS 20 +#define MXC_F_MAA_CTRL_SEG_B ((uint32_t)(0x0000000FUL << MXC_F_MAA_CTRL_SEG_B_POS)) +#define MXC_F_MAA_CTRL_SEG_RES_POS 24 +#define MXC_F_MAA_CTRL_SEG_RES ((uint32_t)(0x0000000FUL << MXC_F_MAA_CTRL_SEG_RES_POS)) +#define MXC_F_MAA_CTRL_SEG_TMP_POS 28 +#define MXC_F_MAA_CTRL_SEG_TMP ((uint32_t)(0x0000000FUL << MXC_F_MAA_CTRL_SEG_TMP_POS)) + +#define MXC_F_MAA_MAWS_MODLEN_POS 0 +#define MXC_F_MAA_MAWS_MODLEN ((uint32_t)(0x000007FFUL << MXC_F_MAA_MAWS_MODLEN_POS)) +#define MXC_F_MAA_MAWS_BYTESWAP_POS 15 +#define MXC_F_MAA_MAWS_BYTESWAP ((uint32_t)(0x00000001UL << MXC_F_MAA_MAWS_BYTESWAP_POS)) + + + +/* + Field values and shifted values for module MAA. +*/ + +#define MXC_V_MAA_OPSEL_EXP ((uint32_t)(0x00000000UL)) +#define MXC_V_MAA_OPSEL_SQR ((uint32_t)(0x00000001UL)) +#define MXC_V_MAA_OPSEL_MUL ((uint32_t)(0x00000002UL)) +#define MXC_V_MAA_OPSEL_SQRMUL ((uint32_t)(0x00000003UL)) +#define MXC_V_MAA_OPSEL_ADD ((uint32_t)(0x00000004UL)) +#define MXC_V_MAA_OPSEL_SUB ((uint32_t)(0x00000005UL)) + +#define MXC_S_MAA_OPSEL_EXP ((uint32_t)(MXC_V_MAA_OPSEL_EXP << MXC_F_MAA_CTRL_OPSEL_POS)) +#define MXC_S_MAA_OPSEL_SQR ((uint32_t)(MXC_V_MAA_OPSEL_SQR << MXC_F_MAA_CTRL_OPSEL_POS)) +#define MXC_S_MAA_OPSEL_MUL ((uint32_t)(MXC_V_MAA_OPSEL_MUL << MXC_F_MAA_CTRL_OPSEL_POS)) +#define MXC_S_MAA_OPSEL_SQRMUL ((uint32_t)(MXC_V_MAA_OPSEL_SQRMUL << MXC_F_MAA_CTRL_OPSEL_POS)) +#define MXC_S_MAA_OPSEL_ADD ((uint32_t)(MXC_V_MAA_OPSEL_ADD << MXC_F_MAA_CTRL_OPSEL_POS)) +#define MXC_S_MAA_OPSEL_SUB ((uint32_t)(MXC_V_MAA_OPSEL_SUB << MXC_F_MAA_CTRL_OPSEL_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_MAA_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/max32625.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/max32625.h new file mode 100644 index 0000000..32beddc --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/max32625.h @@ -0,0 +1,802 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MAX32625_H_ +#define _MAX32625_H_ + +#include + +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef TRUE +#define TRUE (1) +#endif + +/* COMPILER SPECIFIC DEFINES (IAR, ARMCC and GNUC) */ +#if defined ( __GNUC__ ) +#define __weak __attribute__((weak)) + +#elif defined ( __CC_ARM) + +#define inline __inline +#pragma anon_unions + +#endif + +typedef enum { + NonMaskableInt_IRQn = -14, + HardFault_IRQn = -13, + MemoryManagement_IRQn = -12, + BusFault_IRQn = -11, + UsageFault_IRQn = -10, + SVCall_IRQn = -5, + DebugMonitor_IRQn = -4, + PendSV_IRQn = -2, + SysTick_IRQn = -1, + + /* Device-specific interrupt sources (external to ARM core) */ + /* table entry number */ + /* |||| */ + /* |||| table offset address */ + /* vvvv vvvvvv */ + + CLKMAN_IRQn = 0, /* 0x10 0x0040,CLKMAN */ + PWRMAN_IRQn = 1, /* 0x11 0x0044 PWRMAN */ + FLC_IRQn = 2, /* 0x12 0x0048 Flash Controller */ + RTC0_IRQn = 3, /* 0x13 0x004C RTC Counter match with Compare 0 */ + RTC1_IRQn = 4, /* 0x14 0x0050 RTC Counter match with Compare 1 */ + RTC2_IRQn = 5, /* 0x15 0x0054 RTC Prescaler interval compare match */ + RTC3_IRQn = 6, /* 0x16 0x0058 RTC Overflow */ + PMU_IRQn = 7, /* 0x17 0x005C Peripheral Management Unit (PMU/DMA) */ + USB_IRQn = 8, /* 0x18 0x0060 USB */ + AES_IRQn = 9, /* 0x19 0x0064 AES */ + MAA_IRQn = 10, /* 0x1A 0x0068 MAA */ + WDT0_IRQn = 11, /* 0x1B 0x006C Watchdog 0 timeout */ + WDT0_P_IRQn = 12, /* 0x1C 0x0070 Watchdog 0 pre-window (fed too early) */ + WDT1_IRQn = 13, /* 0x1D 0x0074 Watchdog 1 timeout */ + WDT1_P_IRQn = 14, /* 0x1E 0x0078 Watchdog 1 pre-window (fed too early) */ + GPIO_P0_IRQn = 15, /* 0x1F 0x007C GPIO Port 0 */ + GPIO_P1_IRQn = 16, /* 0x20 0x0080 GPIO Port 1 */ + GPIO_P2_IRQn = 17, /* 0x21 0x0084 GPIO Port 2 */ + GPIO_P3_IRQn = 18, /* 0x22 0x0088 GPIO Port 3 */ + GPIO_P4_IRQn = 19, /* 0x23 0x008C GPIO Port 4 */ + GPIO_P5_IRQn = 20, /* 0x24 0x0090 GPIO Port 5 (Unused) */ + GPIO_P6_IRQn = 21, /* 0x25 0x0094 GPIO Port 6 (Unused) */ + TMR0_0_IRQn = 22, /* 0x26 0x0098 Timer 0 (32-bit, 16-bit #0) */ + TMR0_1_IRQn = 23, /* 0x27 0x009C Timer 0 (16-bit #1) */ + TMR1_0_IRQn = 24, /* 0x28 0x00A0 Timer 1 (32-bit, 16-bit #0) */ + TMR1_1_IRQn = 25, /* 0x29 0x00A4 Timer 1 (16-bit #1) */ + TMR2_0_IRQn = 26, /* 0x2A 0x00A8 Timer 2 (32-bit, 16-bit #0) */ + TMR2_1_IRQn = 27, /* 0x2B 0x00AC Timer 2 (16-bit #1) */ + TMR3_0_IRQn = 28, /* 0x2C 0x00B0 Timer 3 (32-bit, 16-bit #0) */ + TMR3_1_IRQn = 29, /* 0x2D 0x00B4 Timer 3 (16-bit #1) */ + TMR4_0_IRQn = 30, /* 0x2E 0x00B8 Timer 4 (32-bit, 16-bit #0) */ + TMR4_1_IRQn = 31, /* 0x2F 0x00BC Timer 4 (16-bit #1) */ + TMR5_0_IRQn = 32, /* 0x30 0x00C0 Timer 5 (32-bit, 16-bit #0) */ + TMR5_1_IRQn = 33, /* 0x31 0x00C4 Timer 5 (16-bit #1) */ + UART0_IRQn = 34, /* 0x32 0x00C8 UART 0 */ + UART1_IRQn = 35, /* 0x33 0x00CC UART 1 */ + UART2_IRQn = 36, /* 0x34 0x00D0 UART 2 */ + UART3_IRQn = 37, /* 0x35 0x00D4 UART 3 (Unused) */ + PT_IRQn = 38, /* 0x36 0x00D8 Pulse Trains */ + I2CM0_IRQn = 39, /* 0x37 0x00DC I2C Master 0 */ + I2CM1_IRQn = 40, /* 0x38 0x00E0 I2C Master 1 */ + I2CM2_IRQn = 41, /* 0x39 0x00E4 I2C Master 2 (Unused) */ + I2CS_IRQn = 42, /* 0x3A 0x00E8 I2C Slave */ + SPIM0_IRQn = 43, /* 0x3B 0x00EC SPI Master 0 */ + SPIM1_IRQn = 44, /* 0x3C 0x00F0 SPI Master 1 */ + SPIM2_IRQn = 45, /* 0x3D 0x00F4 SPI Master 2 */ + SPIB_IRQn = 46, /* 0x3E 0x00F8 SPI Bridge (Unused) */ + OWM_IRQn = 47, /* 0x3F 0x00FC 1-Wire Master */ + AFE_IRQn = 48, /* 0x40 0x0100 Analog Front End, ADC */ + SPIS_IRQn = 49, /* 0x41 0x0104 SPI Slave */ + MXC_IRQ_EXT_COUNT, +} IRQn_Type; + +#define MXC_IRQ_COUNT (MXC_IRQ_EXT_COUNT + 16) + + +/* ================================================================================ */ +/* ================ Processor and Core Peripheral Section ================ */ +/* ================================================================================ */ + +/* ---------------------- Configuration of the Cortex-M Processor and Core Peripherals ---------------------- */ +#define __CM4_REV 0x0100 /*!< Cortex-M4 Core Revision */ +#define __MPU_PRESENT 0 /*!< MPU present or not */ +#define __NVIC_PRIO_BITS 3 /*!< Number of Bits used for Priority Levels */ +#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ +#define __FPU_PRESENT 1 /*!< FPU present or not */ + +#include /*!< Cortex-M4 processor and core peripherals */ +#include "system_max32625.h" /*!< System Header */ + + +/* ================================================================================ */ +/* ================== Device Specific Memory Section ================== */ +/* ================================================================================ */ + +#define MXC_FLASH_MEM_BASE 0x00000000UL +#define MXC_FLASH_PAGE_SIZE 0x00002000UL +#define MXC_FLASH_FULL_MEM_SIZE 0x00080000UL +#define MXC_SYS_MEM_BASE 0x20000000UL +#define MXC_SRAM_FULL_MEM_SIZE 0x00028000UL +#define MXC_EXT_FLASH_MEM_BASE 0x10000000UL + +/* ================================================================================ */ +/* ================ Device Specific Peripheral Section ================ */ +/* ================================================================================ */ + + +/* + Base addresses and configuration settings for all MAX32625 peripheral modules. +*/ + + +/*******************************************************************************/ +/* System Manager Settings */ + +#define MXC_BASE_SYSMAN ((uint32_t)0x40000000UL) +#define MXC_SYSMAN ((mxc_sysman_regs_t *)MXC_BASE_SYSMAN) + + + +/*******************************************************************************/ +/* System Clock Manager */ + +#define MXC_BASE_CLKMAN ((uint32_t)0x40000400UL) +#define MXC_CLKMAN ((mxc_clkman_regs_t *)MXC_BASE_CLKMAN) + + + +/*******************************************************************************/ +/* System Power Manager */ + +#define MXC_BASE_PWRMAN ((uint32_t)0x40000800UL) +#define MXC_PWRMAN ((mxc_pwrman_regs_t *)MXC_BASE_PWRMAN) + + + +/*******************************************************************************/ +/* Real Time Clock */ + +#define MXC_BASE_RTCTMR ((uint32_t)0x40000A00UL) +#define MXC_RTCTMR ((mxc_rtctmr_regs_t *)MXC_BASE_RTCTMR) +#define MXC_BASE_RTCCFG ((uint32_t)0x40000A70UL) +#define MXC_RTCCFG ((mxc_rtccfg_regs_t *)MXC_BASE_RTCCFG) + +#define MXC_RTCTMR_GET_IRQ(i) (IRQn_Type)((i) == 0 ? RTC0_IRQn : \ + (i) == 1 ? RTC1_IRQn : \ + (i) == 2 ? RTC2_IRQn : \ + (i) == 3 ? RTC3_IRQn : 0) + + + +/*******************************************************************************/ +/* Power Sequencer */ + +#define MXC_BASE_PWRSEQ ((uint32_t)0x40000A30UL) +#define MXC_PWRSEQ ((mxc_pwrseq_regs_t *)MXC_BASE_PWRSEQ) + + + +/*******************************************************************************/ +/* System I/O Manager */ + +#define MXC_BASE_IOMAN ((uint32_t)0x40000C00UL) +#define MXC_IOMAN ((mxc_ioman_regs_t *)MXC_BASE_IOMAN) + + + +/*******************************************************************************/ +/* Shadow Trim Registers */ + +#define MXC_BASE_TRIM ((uint32_t)0x40001000UL) +#define MXC_TRIM ((mxc_trim_regs_t *)MXC_BASE_TRIM) + + + +/*******************************************************************************/ +/* Flash Controller */ + +#define MXC_BASE_FLC ((uint32_t)0x40002000UL) +#define MXC_FLC ((mxc_flc_regs_t *)MXC_BASE_FLC) + +#define MXC_FLC_PAGE_SIZE_SHIFT (13) +#define MXC_FLC_PAGE_SIZE (1 << MXC_FLC_PAGE_SIZE_SHIFT) +#define MXC_FLC_PAGE_ERASE_MSK ((~(1 << (MXC_FLC_PAGE_SIZE_SHIFT - 1))) >> MXC_FLC_PAGE_SIZE_SHIFT) << MXC_FLC_PAGE_SIZE_SHIFT + + + +/*******************************************************************************/ +/* Instruction Cache */ + +#define MXC_BASE_ICC ((uint32_t)0x40003000UL) +#define MXC_ICC ((mxc_icc_regs_t *)MXC_BASE_ICC) + + + +/*******************************************************************************/ +/* SPI XIP Interface */ + +#define MXC_BASE_SPIX ((uint32_t)0x40004000UL) +#define MXC_SPIX ((mxc_spix_regs_t *)MXC_BASE_SPIX) + + + +/*******************************************************************************/ +/* Peripheral Management Unit */ + +#define MXC_CFG_PMU_CHANNELS (6) + +#define MXC_BASE_PMU0 ((uint32_t)0x40005000UL) +#define MXC_PMU0 ((mxc_pmu_regs_t *)MXC_BASE_PMU0) +#define MXC_BASE_PMU1 ((uint32_t)0x40005020UL) +#define MXC_PMU1 ((mxc_pmu_regs_t *)MXC_BASE_PMU1) +#define MXC_BASE_PMU2 ((uint32_t)0x40005040UL) +#define MXC_PMU2 ((mxc_pmu_regs_t *)MXC_BASE_PMU2) +#define MXC_BASE_PMU3 ((uint32_t)0x40005060UL) +#define MXC_PMU3 ((mxc_pmu_regs_t *)MXC_BASE_PMU3) +#define MXC_BASE_PMU4 ((uint32_t)0x40005080UL) +#define MXC_PMU4 ((mxc_pmu_regs_t *)MXC_BASE_PMU4) +#define MXC_BASE_PMU5 ((uint32_t)0x400050A0UL) +#define MXC_PMU5 ((mxc_pmu_regs_t *)MXC_BASE_PMU5) + +#define MXC_PMU_GET_BASE(i) ((i) == 0 ? MXC_BASE_PMU0 : \ + (i) == 1 ? MXC_BASE_PMU1 : \ + (i) == 2 ? MXC_BASE_PMU2 : \ + (i) == 3 ? MXC_BASE_PMU3 : \ + (i) == 4 ? MXC_BASE_PMU4 : \ + (i) == 5 ? MXC_BASE_PMU5 : 0) + +#define MXC_PMU_GET_PMU(i) ((i) == 0 ? MXC_PMU0 : \ + (i) == 1 ? MXC_PMU1 : \ + (i) == 2 ? MXC_PMU2 : \ + (i) == 3 ? MXC_PMU3 : \ + (i) == 4 ? MXC_PMU4 : \ + (i) == 5 ? MXC_PMU5 : 0) + +#define MXC_PMU_GET_IDX(p) ((p) == MXC_PMU0 ? 0 : \ + (p) == MXC_PMU1 ? 1 : \ + (p) == MXC_PMU2 ? 2 : \ + (p) == MXC_PMU3 ? 3 : \ + (p) == MXC_PMU4 ? 4 : \ + (p) == MXC_PMU5 ? 5 : -1) + + +/*******************************************************************************/ +/* USB Device Controller */ + +#define MXC_BASE_USB ((uint32_t)0x40100000UL) +#define MXC_USB ((mxc_usb_regs_t *)MXC_BASE_USB) + +#define MXC_USB_MAX_PACKET (64) +#define MXC_USB_NUM_EP (8) + + + +/*******************************************************************************/ +/* CRC-16/CRC-32 Engine */ + +#define MXC_BASE_CRC ((uint32_t)0x40006000UL) +#define MXC_CRC ((mxc_crc_regs_t *)MXC_BASE_CRC) +#define MXC_BASE_CRC_DATA ((uint32_t)0x40101000UL) +#define MXC_CRC_DATA ((mxc_crc_data_regs_t *)MXC_BASE_CRC_DATA) + + + +/*******************************************************************************/ +/* Pseudo-random number generator (PRNG) */ + +#define MXC_BASE_PRNG ((uint32_t)0x40007000UL) +#define MXC_PRNG ((mxc_prng_regs_t *)MXC_BASE_PRNG) + +/*******************************************************************************/ +/* AES Cryptographic Engine */ + +#define MXC_BASE_AES ((uint32_t)0x40007400UL) +#define MXC_AES ((mxc_aes_regs_t *)MXC_BASE_AES) +#define MXC_BASE_AES_MEM ((uint32_t)0x40102000UL) +#define MXC_AES_MEM ((mxc_aes_mem_regs_t *)MXC_BASE_AES_MEM) + + + +/*******************************************************************************/ +/* MAA Cryptographic Engine */ + +#define MXC_BASE_MAA ((uint32_t)0x40007800UL) +#define MXC_MAA ((mxc_maa_regs_t *)MXC_BASE_MAA) +#define MXC_BASE_MAA_MEM ((uint32_t)0x40102800UL) +#define MXC_MAA_MEM ((mxc_maa_mem_regs_t *)MXC_BASE_MAA_MEM) + +/*******************************************************************************/ +/* Trust Protection Unit (TPU) */ + +#define MXC_BASE_TPU ((uint32_t)0x40007000UL) +#define MXC_TPU ((mxc_tpu_regs_t *)MXC_BASE_TPU) +#define MXC_BASE_TPU_TSR ((uint32_t)0x40007C00UL) +#define MXC_TPU_TSR ((mxc_tpu_tsr_regs_t *)MXC_BASE_TPU_TSR) + +/*******************************************************************************/ +/* Watchdog Timers */ + +#define MXC_CFG_WDT_INSTANCES (2) + +#define MXC_BASE_WDT0 ((uint32_t)0x40008000UL) +#define MXC_WDT0 ((mxc_wdt_regs_t *)MXC_BASE_WDT0) +#define MXC_BASE_WDT1 ((uint32_t)0x40009000UL) +#define MXC_WDT1 ((mxc_wdt_regs_t *)MXC_BASE_WDT1) + +#define MXC_WDT_GET_IRQ(i) (IRQn_Type)((i) == 0 ? WDT0_IRQn : \ + (i) == 1 ? WDT1_IRQn : 0) + +#define MXC_WDT_GET_IRQ_P(i) (IRQn_Type)((i) == 0 ? WDT0_P_IRQn : \ + (i) == 1 ? WDT1_P_IRQn : 0) + +#define MXC_WDT_GET_BASE(i) ((i) == 0 ? MXC_BASE_WDT0 : \ + (i) == 1 ? MXC_BASE_WDT1 : 0) + +#define MXC_WDT_GET_WDT(i) ((i) == 0 ? MXC_WDT0 : \ + (i) == 1 ? MXC_WDT1 : 0) + +#define MXC_WDT_GET_IDX(i) ((i) == MXC_WDT0 ? 0: \ + (i) == MXC_WDT1 ? 1: -1) + + +/*******************************************************************************/ +/* Low-Level Watchdog Timer */ + +#define MXC_BASE_WDT2 ((uint32_t)0x40007C60UL) +#define MXC_WDT2 ((mxc_wdt2_regs_t *)MXC_BASE_WDT2) + + + +/*******************************************************************************/ +/* General Purpose I/O Ports (GPIO) */ + +#define MXC_GPIO_NUM_PORTS (5) +#define MXC_GPIO_MAX_PINS_PER_PORT (8) + +#define MXC_BASE_GPIO ((uint32_t)0x4000A000UL) +#define MXC_GPIO ((mxc_gpio_regs_t *)MXC_BASE_GPIO) + +#define MXC_GPIO_GET_IRQ(i) (IRQn_Type)((i) == 0 ? GPIO_P0_IRQn : \ + (i) == 1 ? GPIO_P1_IRQn : \ + (i) == 2 ? GPIO_P2_IRQn : \ + (i) == 3 ? GPIO_P3_IRQn : \ + (i) == 4 ? GPIO_P4_IRQn : 0) + + + +/*******************************************************************************/ +/* 16/32 bit Timer/Counters */ + +#define MXC_CFG_TMR_INSTANCES (6) + +#define MXC_BASE_TMR0 ((uint32_t)0x4000B000UL) +#define MXC_TMR0 ((mxc_tmr_regs_t *)MXC_BASE_TMR0) +#define MXC_BASE_TMR1 ((uint32_t)0x4000C000UL) +#define MXC_TMR1 ((mxc_tmr_regs_t *)MXC_BASE_TMR1) +#define MXC_BASE_TMR2 ((uint32_t)0x4000D000UL) +#define MXC_TMR2 ((mxc_tmr_regs_t *)MXC_BASE_TMR2) +#define MXC_BASE_TMR3 ((uint32_t)0x4000E000UL) +#define MXC_TMR3 ((mxc_tmr_regs_t *)MXC_BASE_TMR3) +#define MXC_BASE_TMR4 ((uint32_t)0x4000F000UL) +#define MXC_TMR4 ((mxc_tmr_regs_t *)MXC_BASE_TMR4) +#define MXC_BASE_TMR5 ((uint32_t)0x40010000UL) +#define MXC_TMR5 ((mxc_tmr_regs_t *)MXC_BASE_TMR5) + +#define MXC_TMR_GET_IRQ_32(i) (IRQn_Type)((i) == 0 ? TMR0_0_IRQn : \ + (i) == 1 ? TMR1_0_IRQn : \ + (i) == 2 ? TMR2_0_IRQn : \ + (i) == 3 ? TMR3_0_IRQn : \ + (i) == 4 ? TMR4_0_IRQn : \ + (i) == 5 ? TMR5_0_IRQn : 0) + +#define MXC_TMR_GET_IRQ_16(i) (IRQn_Type)((i) == 0 ? TMR0_0_IRQn : \ + (i) == 1 ? TMR1_0_IRQn : \ + (i) == 2 ? TMR2_0_IRQn : \ + (i) == 3 ? TMR3_0_IRQn : \ + (i) == 4 ? TMR4_0_IRQn : \ + (i) == 5 ? TMR5_0_IRQn : \ + (i) == 6 ? TMR0_1_IRQn : \ + (i) == 7 ? TMR1_1_IRQn : \ + (i) == 8 ? TMR2_1_IRQn : \ + (i) == 9 ? TMR3_1_IRQn : \ + (i) == 10 ? TMR4_1_IRQn : \ + (i) == 11 ? TMR5_1_IRQn : 0) + +#define MXC_TMR_GET_BASE(i) ((i) == 0 ? MXC_BASE_TMR0 : \ + (i) == 1 ? MXC_BASE_TMR1 : \ + (i) == 2 ? MXC_BASE_TMR2 : \ + (i) == 3 ? MXC_BASE_TMR3 : \ + (i) == 4 ? MXC_BASE_TMR4 : \ + (i) == 5 ? MXC_BASE_TMR5 : 0) + +#define MXC_TMR_GET_TMR(i) ((i) == 0 ? MXC_TMR0 : \ + (i) == 1 ? MXC_TMR1 : \ + (i) == 2 ? MXC_TMR2 : \ + (i) == 3 ? MXC_TMR3 : \ + (i) == 4 ? MXC_TMR4 : \ + (i) == 5 ? MXC_TMR5 : 0) + +#define MXC_TMR_GET_IDX(p) ((p) == MXC_TMR0 ? 0 : \ + (p) == MXC_TMR1 ? 1 : \ + (p) == MXC_TMR2 ? 2 : \ + (p) == MXC_TMR3 ? 3 : \ + (p) == MXC_TMR4 ? 4 : \ + (p) == MXC_TMR5 ? 5 : -1) + + + + +/*******************************************************************************/ +/* Pulse Train Generation */ + +#define MXC_CFG_PT_INSTANCES (16) + +#define MXC_BASE_PTG ((uint32_t)0x40011000UL) +#define MXC_PTG ((mxc_ptg_regs_t *)MXC_BASE_PTG) +#define MXC_BASE_PT0 ((uint32_t)0x40011020UL) +#define MXC_PT0 ((mxc_pt_regs_t *)MXC_BASE_PT0) +#define MXC_BASE_PT1 ((uint32_t)0x40011040UL) +#define MXC_PT1 ((mxc_pt_regs_t *)MXC_BASE_PT1) +#define MXC_BASE_PT2 ((uint32_t)0x40011060UL) +#define MXC_PT2 ((mxc_pt_regs_t *)MXC_BASE_PT2) +#define MXC_BASE_PT3 ((uint32_t)0x40011080UL) +#define MXC_PT3 ((mxc_pt_regs_t *)MXC_BASE_PT3) +#define MXC_BASE_PT4 ((uint32_t)0x400110A0UL) +#define MXC_PT4 ((mxc_pt_regs_t *)MXC_BASE_PT4) +#define MXC_BASE_PT5 ((uint32_t)0x400110C0UL) +#define MXC_PT5 ((mxc_pt_regs_t *)MXC_BASE_PT5) +#define MXC_BASE_PT6 ((uint32_t)0x400110E0UL) +#define MXC_PT6 ((mxc_pt_regs_t *)MXC_BASE_PT6) +#define MXC_BASE_PT7 ((uint32_t)0x40011100UL) +#define MXC_PT7 ((mxc_pt_regs_t *)MXC_BASE_PT7) +#define MXC_BASE_PT8 ((uint32_t)0x40011120UL) +#define MXC_PT8 ((mxc_pt_regs_t *)MXC_BASE_PT8) +#define MXC_BASE_PT9 ((uint32_t)0x40011140UL) +#define MXC_PT9 ((mxc_pt_regs_t *)MXC_BASE_PT9) +#define MXC_BASE_PT10 ((uint32_t)0x40011160UL) +#define MXC_PT10 ((mxc_pt_regs_t *)MXC_BASE_PT10) +#define MXC_BASE_PT11 ((uint32_t)0x40011180UL) +#define MXC_PT11 ((mxc_pt_regs_t *)MXC_BASE_PT11) +#define MXC_BASE_PT12 ((uint32_t)0x400111A0UL) +#define MXC_PT12 ((mxc_pt_regs_t *)MXC_BASE_PT12) +#define MXC_BASE_PT13 ((uint32_t)0x400111C0UL) +#define MXC_PT13 ((mxc_pt_regs_t *)MXC_BASE_PT13) +#define MXC_BASE_PT14 ((uint32_t)0x400111E0UL) +#define MXC_PT14 ((mxc_pt_regs_t *)MXC_BASE_PT14) +#define MXC_BASE_PT15 ((uint32_t)0x40011200UL) +#define MXC_PT15 ((mxc_pt_regs_t *)MXC_BASE_PT15) + +#define MXC_PT_GET_BASE(i) ((i) == 0 ? MXC_BASE_PT0 : \ + (i) == 1 ? MXC_BASE_PT1 : \ + (i) == 2 ? MXC_BASE_PT2 : \ + (i) == 3 ? MXC_BASE_PT3 : \ + (i) == 4 ? MXC_BASE_PT4 : \ + (i) == 5 ? MXC_BASE_PT5 : \ + (i) == 6 ? MXC_BASE_PT6 : \ + (i) == 7 ? MXC_BASE_PT7 : \ + (i) == 8 ? MXC_BASE_PT8 : \ + (i) == 9 ? MXC_BASE_PT9 : \ + (i) == 10 ? MXC_BASE_PT10 : \ + (i) == 11 ? MXC_BASE_PT11 : \ + (i) == 12 ? MXC_BASE_PT12 : \ + (i) == 13 ? MXC_BASE_PT13 : \ + (i) == 14 ? MXC_BASE_PT14 : \ + (i) == 15 ? MXC_BASE_PT15 : 0) + +#define MXC_PT_GET_PT(i) ((i) == 0 ? MXC_PT0 : \ + (i) == 1 ? MXC_PT1 : \ + (i) == 2 ? MXC_PT2 : \ + (i) == 3 ? MXC_PT3 : \ + (i) == 4 ? MXC_PT4 : \ + (i) == 5 ? MXC_PT5 : \ + (i) == 6 ? MXC_PT6 : \ + (i) == 7 ? MXC_PT7 : \ + (i) == 8 ? MXC_PT8 : \ + (i) == 9 ? MXC_PT9 : \ + (i) == 10 ? MXC_PT10 : \ + (i) == 11 ? MXC_PT11 : \ + (i) == 12 ? MXC_PT12 : \ + (i) == 13 ? MXC_PT13 : \ + (i) == 14 ? MXC_PT14 : \ + (i) == 15 ? MXC_PT15 : 0) + +#define MXC_PT_GET_IDX(p) ((p) == MXC_PT0 ? 0 : \ + (p) == MXC_PT1 ? 1 : \ + (p) == MXC_PT2 ? 2 : \ + (p) == MXC_PT3 ? 3 : \ + (p) == MXC_PT4 ? 4 : \ + (p) == MXC_PT5 ? 5 : \ + (p) == MXC_PT6 ? 6 : \ + (p) == MXC_PT7 ? 7 : \ + (p) == MXC_PT8 ? 8 : \ + (p) == MXC_PT9 ? 9 : \ + (p) == MXC_PT10 ? 10 : \ + (p) == MXC_PT11 ? 11 : \ + (p) == MXC_PT12 ? 12 : \ + (p) == MXC_PT13 ? 13 : \ + (p) == MXC_PT14 ? 14 : \ + (p) == MXC_PT15 ? 15 : -1) + + + +/*******************************************************************************/ +/* UART / Serial Port Interface */ + +#define MXC_CFG_UART_INSTANCES (3) +#define MXC_UART_FIFO_DEPTH (32) + +#define MXC_BASE_UART0 ((uint32_t)0x40012000UL) +#define MXC_UART0 ((mxc_uart_regs_t *)MXC_BASE_UART0) +#define MXC_BASE_UART1 ((uint32_t)0x40013000UL) +#define MXC_UART1 ((mxc_uart_regs_t *)MXC_BASE_UART1) +#define MXC_BASE_UART2 ((uint32_t)0x40014000UL) +#define MXC_UART2 ((mxc_uart_regs_t *)MXC_BASE_UART2) +#define MXC_BASE_UART0_FIFO ((uint32_t)0x40103000UL) +#define MXC_UART0_FIFO ((mxc_uart_fifo_regs_t *)MXC_BASE_UART0_FIFO) +#define MXC_BASE_UART1_FIFO ((uint32_t)0x40104000UL) +#define MXC_UART1_FIFO ((mxc_uart_fifo_regs_t *)MXC_BASE_UART1_FIFO) +#define MXC_BASE_UART2_FIFO ((uint32_t)0x40105000UL) +#define MXC_UART2_FIFO ((mxc_uart_fifo_regs_t *)MXC_BASE_UART2_FIFO) + +#define MXC_UART_GET_IRQ(i) (IRQn_Type)((i) == 0 ? UART0_IRQn : \ + (i) == 1 ? UART1_IRQn : \ + (i) == 2 ? UART2_IRQn : 0) + +#define MXC_UART_GET_BASE(i) ((i) == 0 ? MXC_BASE_UART0 : \ + (i) == 1 ? MXC_BASE_UART1 : \ + (i) == 2 ? MXC_BASE_UART2 : 0) + +#define MXC_UART_GET_UART(i) ((i) == 0 ? MXC_UART0 : \ + (i) == 1 ? MXC_UART1 : \ + (i) == 2 ? MXC_UART2 : 0) + +#define MXC_UART_GET_IDX(p) ((p) == MXC_UART0 ? 0 : \ + (p) == MXC_UART1 ? 1 : \ + (p) == MXC_UART2 ? 2 : -1) + +#define MXC_UART_GET_BASE_FIFO(i) ((i) == 0 ? MXC_BASE_UART0_FIFO : \ + (i) == 1 ? MXC_BASE_UART1_FIFO : \ + (i) == 2 ? MXC_BASE_UART2_FIFO : 0) + +#define MXC_UART_GET_FIFO(i) ((i) == 0 ? MXC_UART0_FIFO : \ + (i) == 1 ? MXC_UART1_FIFO : \ + (i) == 2 ? MXC_UART2_FIFO : 0) + + + +/*******************************************************************************/ +/* I2C Master Interface */ + +#define MXC_CFG_I2CM_INSTANCES (2) +#define MXC_I2CM_FIFO_DEPTH (8) + +#define MXC_BASE_I2CM0 ((uint32_t)0x40016000UL) +#define MXC_I2CM0 ((mxc_i2cm_regs_t *)MXC_BASE_I2CM0) +#define MXC_BASE_I2CM1 ((uint32_t)0x40017000UL) +#define MXC_I2CM1 ((mxc_i2cm_regs_t *)MXC_BASE_I2CM1) +#define MXC_BASE_I2CM0_FIFO ((uint32_t)0x40107000UL) +#define MXC_I2CM0_FIFO ((mxc_i2cm_fifo_regs_t *)MXC_BASE_I2CM0_FIFO) +#define MXC_BASE_I2CM1_FIFO ((uint32_t)0x40108000UL) +#define MXC_I2CM1_FIFO ((mxc_i2cm_fifo_regs_t *)MXC_BASE_I2CM1_FIFO) + +#define MXC_I2CM_GET_IRQ(i) (IRQn_Type)((i) == 0 ? I2CM0_IRQn : \ + (i) == 1 ? I2CM1_IRQn : 0) + +#define MXC_I2CM_GET_BASE(i) ((i) == 0 ? MXC_BASE_I2CM0 : \ + (i) == 1 ? MXC_BASE_I2CM1 : 0) + +#define MXC_I2CM_GET_I2CM(i) ((i) == 0 ? MXC_I2CM0 : \ + (i) == 1 ? MXC_I2CM1 : 0) + +#define MXC_I2CM_GET_IDX(p) ((p) == MXC_I2CM0 ? 0 : \ + (p) == MXC_I2CM1 ? 1 : -1) + +#define MXC_I2CM_GET_BASE_FIFO(i) ((i) == 0 ? MXC_BASE_I2CM0_FIFO : \ + (i) == 1 ? MXC_BASE_I2CM1_FIFO : 0) + +#define MXC_I2CM_GET_FIFO(i) ((i) == 0 ? MXC_I2CM0_FIFO : \ + (i) == 1 ? MXC_I2CM1_FIFO : 0) + + + +/*******************************************************************************/ +/* I2C Slave Interface (Mailbox type) */ + +#define MXC_CFG_I2CS_INSTANCES (1) +#define MXC_CFG_I2CS_BUFFER_SIZE (32) + +#define MXC_BASE_I2CS ((uint32_t)0x40019000UL) +#define MXC_I2CS ((mxc_i2cs_regs_t *)MXC_BASE_I2CS) + +#define MXC_I2CS_GET_IRQ(i) (IRQn_Type)((i) == 0 ? I2CS_IRQn : 0) + +#define MXC_I2CS_GET_BASE(i) ((i) == 0 ? MXC_BASE_I2CS : 0) + +#define MXC_I2CS_GET_I2CS(i) ((i) == 0 ? MXC_I2CS : 0) + +#define MXC_I2CS_GET_IDX(p) ((p) == MXC_I2CS ? 0 : -1) + +/*******************************************************************************/ +/* SPI Master Interface */ + +#define MXC_CFG_SPIM_INSTANCES (3) +#define MXC_CFG_SPIM_FIFO_DEPTH (16) + +#define MXC_BASE_SPIM0 ((uint32_t)0x4001A000UL) +#define MXC_SPIM0 ((mxc_spim_regs_t *)MXC_BASE_SPIM0) +#define MXC_BASE_SPIM1 ((uint32_t)0x4001B000UL) +#define MXC_SPIM1 ((mxc_spim_regs_t *)MXC_BASE_SPIM1) +#define MXC_BASE_SPIM2 ((uint32_t)0x4001C000UL) +#define MXC_SPIM2 ((mxc_spim_regs_t *)MXC_BASE_SPIM2) +#define MXC_BASE_SPIM0_FIFO ((uint32_t)0x4010A000UL) +#define MXC_SPIM0_FIFO ((mxc_spim_fifo_regs_t *)MXC_BASE_SPIM0_FIFO) +#define MXC_BASE_SPIM1_FIFO ((uint32_t)0x4010B000UL) +#define MXC_SPIM1_FIFO ((mxc_spim_fifo_regs_t *)MXC_BASE_SPIM1_FIFO) +#define MXC_BASE_SPIM2_FIFO ((uint32_t)0x4010C000UL) +#define MXC_SPIM2_FIFO ((mxc_spim_fifo_regs_t *)MXC_BASE_SPIM2_FIFO) + +#define MXC_SPIM_GET_IRQ(i) (IRQn_Type)((i) == 0 ? SPIM0_IRQn : \ + (i) == 1 ? SPIM1_IRQn : \ + (i) == 2 ? SPIM2_IRQn : 0) + +#define MXC_SPIM_GET_BASE(i) ((i) == 0 ? MXC_BASE_SPIM0 : \ + (i) == 1 ? MXC_BASE_SPIM1 : \ + (i) == 2 ? MXC_BASE_SPIM2 : 0) + +#define MXC_SPIM_GET_SPIM(i) ((i) == 0 ? MXC_SPIM0 : \ + (i) == 1 ? MXC_SPIM1 : \ + (i) == 2 ? MXC_SPIM2 : 0) + +#define MXC_SPIM_GET_IDX(p) ((p) == MXC_SPIM0 ? 0 : \ + (p) == MXC_SPIM1 ? 1 : \ + (p) == MXC_SPIM2 ? 2 : -1) + +#define MXC_SPIM_GET_BASE_FIFO(i) ((i) == 0 ? MXC_BASE_SPIM0_FIFO : \ + (i) == 1 ? MXC_BASE_SPIM1_FIFO : \ + (i) == 2 ? MXC_BASE_SPIM2_FIFO : 0) + +#define MXC_SPIM_GET_SPIM_FIFO(i) ((i) == 0 ? MXC_SPIM0_FIFO : \ + (i) == 1 ? MXC_SPIM1_FIFO : \ + (i) == 2 ? MXC_SPIM2_FIFO : 0) + + + +/*******************************************************************************/ +/* 1-Wire Master Interface */ + +#define MXC_CFG_OWM_INSTANCES (1) + +#define MXC_BASE_OWM ((uint32_t)0x4001E000UL) +#define MXC_OWM ((mxc_owm_regs_t *)MXC_BASE_OWM) + +#define MXC_OWM_GET_IRQ(i) (IRQn_Type)((i) == 0 ? OWM_IRQn : 0) + +#define MXC_OWM_GET_BASE(i) ((i) == 0 ? MXC_BASE_OWM : 0) + +#define MXC_OWM_GET_OWM(i) ((i) == 0 ? MXC_OWM : 0) + +#define MXC_OWM_GET_IDX(p) ((p) == MXC_OWM ? 0 : -1) + +/*******************************************************************************/ +/* ADC / AFE */ + +#define MXC_CFG_ADC_FIFO_DEPTH (32) + +#define MXC_BASE_ADC ((uint32_t)0x4001F000UL) +#define MXC_ADC ((mxc_adc_regs_t *)MXC_BASE_ADC) + + + +/*******************************************************************************/ +/* SPI Slave Interface */ +#define MXC_CFG_SPIS_INSTANCES (1) +#define MXC_CFG_SPIS_FIFO_DEPTH (32) + +#define MXC_BASE_SPIS ((uint32_t)0x40020000UL) +#define MXC_SPIS ((mxc_spis_regs_t *)MXC_BASE_SPIS) +#define MXC_BASE_SPIS_FIFO ((uint32_t)0x4010E000UL) +#define MXC_SPIS_FIFO ((mxc_spis_fifo_regs_t *)MXC_BASE_SPIS_FIFO) + +#define MXC_SPIS_GET_IRQ(i) (IRQn_Type)((i) == 0 ? SPIS_IRQn : 0) + +#define MXC_SPIS_GET_BASE(i) ((i) == 0 ? MXC_BASE_SPIS : 0) + +#define MXC_SPIS_GET_SPIS(i) ((i) == 0 ? MXC_SPIS : 0) + +#define MXC_SPIS_GET_IDX(p) ((p) == MXC_SPIS ? 0 : -1) + +#define MXC_SPIS_GET_BASE_FIFO(i) ((i) == 0 ? MXC_BASE_SPIS_FIFO : 0) + +#define MXC_SPIS_GET_SPIS_FIFO(i) ((i) == 0 ? MXC_SPIS_FIFO :0) + +/*******************************************************************************/ +/* Bit Shifting */ + +#define MXC_F_BIT_0 (1 << 0) +#define MXC_F_BIT_1 (1 << 1) +#define MXC_F_BIT_2 (1 << 2) +#define MXC_F_BIT_3 (1 << 3) +#define MXC_F_BIT_4 (1 << 4) +#define MXC_F_BIT_5 (1 << 5) +#define MXC_F_BIT_6 (1 << 6) +#define MXC_F_BIT_7 (1 << 7) +#define MXC_F_BIT_8 (1 << 8) +#define MXC_F_BIT_9 (1 << 9) +#define MXC_F_BIT_10 (1 << 10) +#define MXC_F_BIT_11 (1 << 11) +#define MXC_F_BIT_12 (1 << 12) +#define MXC_F_BIT_13 (1 << 13) +#define MXC_F_BIT_14 (1 << 14) +#define MXC_F_BIT_15 (1 << 15) +#define MXC_F_BIT_16 (1 << 16) +#define MXC_F_BIT_17 (1 << 17) +#define MXC_F_BIT_18 (1 << 18) +#define MXC_F_BIT_19 (1 << 19) +#define MXC_F_BIT_20 (1 << 20) +#define MXC_F_BIT_21 (1 << 21) +#define MXC_F_BIT_22 (1 << 22) +#define MXC_F_BIT_23 (1 << 23) +#define MXC_F_BIT_24 (1 << 24) +#define MXC_F_BIT_25 (1 << 25) +#define MXC_F_BIT_26 (1 << 26) +#define MXC_F_BIT_27 (1 << 27) +#define MXC_F_BIT_28 (1 << 28) +#define MXC_F_BIT_29 (1 << 29) +#define MXC_F_BIT_30 (1 << 30) +#define MXC_F_BIT_31 (1 << 31) + + +/*******************************************************************************/ + +#define BITBAND(reg, bit) ((0xf0000000 & (uint32_t)(reg)) + 0x2000000 + (((uint32_t)(reg) & 0x0fffffff) << 5) + ((bit) << 2)) +#define MXC_CLRBIT(reg, bit) (*(volatile uint32_t *)BITBAND(reg, bit) = 0) +#define MXC_SETBIT(reg, bit) (*(volatile uint32_t *)BITBAND(reg, bit) = 1) +#define MXC_GETBIT(reg, bit) (*(volatile uint32_t *)BITBAND(reg, bit)) +#define MXC_SET_FIELD(reg, clr, set) (*(volatile uint32_t *)reg = ((*(volatile uint32_t *)reg & ~clr) | set)) + + +/*******************************************************************************/ + +/* SCB CPACR Register Definitions */ +/* Note: Added by Maxim Integrated, as these are missing from CMSIS/Core/Include/core_cm4.h */ +#define SCB_CPACR_CP10_Pos 20 /*!< SCB CPACR: Coprocessor 10 Position */ +#define SCB_CPACR_CP10_Msk (0x3UL << SCB_CPACR_CP10_Pos) /*!< SCB CPACR: Coprocessor 10 Mask */ +#define SCB_CPACR_CP11_Pos 22 /*!< SCB CPACR: Coprocessor 11 Position */ +#define SCB_CPACR_CP11_Msk (0x3UL << SCB_CPACR_CP11_Pos) /*!< SCB CPACR: Coprocessor 11 Mask */ + +#endif /* _MAX32625_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/mxc_device.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/mxc_device.h new file mode 100644 index 0000000..534f6a1 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/mxc_device.h @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_DEVICE_H_ +#define _MXC_DEVICE_H_ + +#include "max32625.h" + + +#ifndef TARGET +#error TARGET NOT DEFINED +#endif + +// Create a string definition for the TARGET +#define STRING_ARG(arg) #arg +#define STRING_NAME(name) STRING_ARG(name) +#define TARGET_NAME STRING_NAME(TARGET) + +// Define which revisions of the IP we are using +#ifndef TARGET_REV +#error TARGET_REV NOT DEFINED +#endif + +#if(TARGET_REV == 0x4132) +#define MXC_ADC_REV 1 +#define MXC_AES_REV 0 +#define MXC_CRC_REV 0 +#define MXC_FLC_REV 0 +#define MXC_GPIO_REV 0 +#define MXC_I2CM_REV 0 +#define MXC_I2CS_REV 0 +#define MXC_ICC_REV 0 +#define MXC_MAA_REV 0 +#define MXC_OWM_REV 0 +#define MXC_PMU_REV 1 +#define MXC_PRNG_REV 0 +#define MXC_PT_REV 0 +#define MXC_RTC_REV 0 +#define MXC_SPIM_REV 1 +#define MXC_SPIS_REV 0 +#define MXC_SPIX_REV 1 +#define MXC_TMR_REV 0 +#define MXC_UART_REV 1 +#define MXC_USB_REV 0 +#define MXC_WDT2_REV 0 +#define MXC_WDT_REV 0 + +#else + +#error TARGET_REV NOT SUPPORTED + +#endif /* if(TARGET_REV == 0x4132) */ + +#endif /* _MXC_DEVICE_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/owm_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/owm_regs.h new file mode 100644 index 0000000..e5dc288 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/owm_regs.h @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_OWM_REGS_H_ +#define _MXC_OWM_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t cfg; /* 0x0000 1-Wire Master Configuration */ + __IO uint32_t clk_div_1us; /* 0x0004 1-Wire Master Clock Divisor */ + __IO uint32_t ctrl_stat; /* 0x0008 1-Wire Master Control/Status */ + __IO uint32_t data; /* 0x000C 1-Wire Master Data Buffer */ + __IO uint32_t intfl; /* 0x0010 1-Wire Master Interrupt Flags */ + __IO uint32_t inten; /* 0x0014 1-Wire Master Interrupt Enables */ +} mxc_owm_regs_t; + + +/* + Register offsets for module OWM. +*/ + +#define MXC_R_OWM_OFFS_CFG ((uint32_t)0x00000000UL) +#define MXC_R_OWM_OFFS_CLK_DIV_1US ((uint32_t)0x00000004UL) +#define MXC_R_OWM_OFFS_CTRL_STAT ((uint32_t)0x00000008UL) +#define MXC_R_OWM_OFFS_DATA ((uint32_t)0x0000000CUL) +#define MXC_R_OWM_OFFS_INTFL ((uint32_t)0x00000010UL) +#define MXC_R_OWM_OFFS_INTEN ((uint32_t)0x00000014UL) + + +/* + Field positions and masks for module OWM. +*/ + +#define MXC_F_OWM_CFG_LONG_LINE_MODE_POS 0 +#define MXC_F_OWM_CFG_LONG_LINE_MODE ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_LONG_LINE_MODE_POS)) +#define MXC_F_OWM_CFG_FORCE_PRES_DET_POS 1 +#define MXC_F_OWM_CFG_FORCE_PRES_DET ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_FORCE_PRES_DET_POS)) +#define MXC_F_OWM_CFG_BIT_BANG_EN_POS 2 +#define MXC_F_OWM_CFG_BIT_BANG_EN ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_BIT_BANG_EN_POS)) +#define MXC_F_OWM_CFG_EXT_PULLUP_MODE_POS 3 +#define MXC_F_OWM_CFG_EXT_PULLUP_MODE ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_EXT_PULLUP_MODE_POS)) +#define MXC_F_OWM_CFG_EXT_PULLUP_ENABLE_POS 4 +#define MXC_F_OWM_CFG_EXT_PULLUP_ENABLE ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_EXT_PULLUP_ENABLE_POS)) +#define MXC_F_OWM_CFG_SINGLE_BIT_MODE_POS 5 +#define MXC_F_OWM_CFG_SINGLE_BIT_MODE ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_SINGLE_BIT_MODE_POS)) +#define MXC_F_OWM_CFG_OVERDRIVE_POS 6 +#define MXC_F_OWM_CFG_OVERDRIVE ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_OVERDRIVE_POS)) +#define MXC_F_OWM_CFG_INT_PULLUP_ENABLE_POS 7 +#define MXC_F_OWM_CFG_INT_PULLUP_ENABLE ((uint32_t)(0x00000001UL << MXC_F_OWM_CFG_INT_PULLUP_ENABLE_POS)) + +#define MXC_F_OWM_CLK_DIV_1US_DIVISOR_POS 0 +#define MXC_F_OWM_CLK_DIV_1US_DIVISOR ((uint32_t)(0x000000FFUL << MXC_F_OWM_CLK_DIV_1US_DIVISOR_POS)) + +#define MXC_F_OWM_CTRL_STAT_START_OW_RESET_POS 0 +#define MXC_F_OWM_CTRL_STAT_START_OW_RESET ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_START_OW_RESET_POS)) +#define MXC_F_OWM_CTRL_STAT_SRA_MODE_POS 1 +#define MXC_F_OWM_CTRL_STAT_SRA_MODE ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_SRA_MODE_POS)) +#define MXC_F_OWM_CTRL_STAT_BIT_BANG_OE_POS 2 +#define MXC_F_OWM_CTRL_STAT_BIT_BANG_OE ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_BIT_BANG_OE_POS)) +#define MXC_F_OWM_CTRL_STAT_OW_INPUT_POS 3 +#define MXC_F_OWM_CTRL_STAT_OW_INPUT ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_OW_INPUT_POS)) +#define MXC_F_OWM_CTRL_STAT_OD_SPEC_MODE_POS 4 +#define MXC_F_OWM_CTRL_STAT_OD_SPEC_MODE ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_OD_SPEC_MODE_POS)) +#define MXC_F_OWM_CTRL_STAT_EXT_PULLUP_POL_POS 5 +#define MXC_F_OWM_CTRL_STAT_EXT_PULLUP_POL ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_EXT_PULLUP_POL_POS)) +#define MXC_F_OWM_CTRL_STAT_PRESENCE_DETECT_POS 7 +#define MXC_F_OWM_CTRL_STAT_PRESENCE_DETECT ((uint32_t)(0x00000001UL << MXC_F_OWM_CTRL_STAT_PRESENCE_DETECT_POS)) + +#define MXC_F_OWM_DATA_TX_RX_POS 0 +#define MXC_F_OWM_DATA_TX_RX ((uint32_t)(0x000000FFUL << MXC_F_OWM_DATA_TX_RX_POS)) + +#define MXC_F_OWM_INTFL_OW_RESET_DONE_POS 0 +#define MXC_F_OWM_INTFL_OW_RESET_DONE ((uint32_t)(0x00000001UL << MXC_F_OWM_INTFL_OW_RESET_DONE_POS)) +#define MXC_F_OWM_INTFL_TX_DATA_EMPTY_POS 1 +#define MXC_F_OWM_INTFL_TX_DATA_EMPTY ((uint32_t)(0x00000001UL << MXC_F_OWM_INTFL_TX_DATA_EMPTY_POS)) +#define MXC_F_OWM_INTFL_RX_DATA_READY_POS 2 +#define MXC_F_OWM_INTFL_RX_DATA_READY ((uint32_t)(0x00000001UL << MXC_F_OWM_INTFL_RX_DATA_READY_POS)) +#define MXC_F_OWM_INTFL_LINE_SHORT_POS 3 +#define MXC_F_OWM_INTFL_LINE_SHORT ((uint32_t)(0x00000001UL << MXC_F_OWM_INTFL_LINE_SHORT_POS)) +#define MXC_F_OWM_INTFL_LINE_LOW_POS 4 +#define MXC_F_OWM_INTFL_LINE_LOW ((uint32_t)(0x00000001UL << MXC_F_OWM_INTFL_LINE_LOW_POS)) + +#define MXC_F_OWM_INTEN_OW_RESET_DONE_POS 0 +#define MXC_F_OWM_INTEN_OW_RESET_DONE ((uint32_t)(0x00000001UL << MXC_F_OWM_INTEN_OW_RESET_DONE_POS)) +#define MXC_F_OWM_INTEN_TX_DATA_EMPTY_POS 1 +#define MXC_F_OWM_INTEN_TX_DATA_EMPTY ((uint32_t)(0x00000001UL << MXC_F_OWM_INTEN_TX_DATA_EMPTY_POS)) +#define MXC_F_OWM_INTEN_RX_DATA_READY_POS 2 +#define MXC_F_OWM_INTEN_RX_DATA_READY ((uint32_t)(0x00000001UL << MXC_F_OWM_INTEN_RX_DATA_READY_POS)) +#define MXC_F_OWM_INTEN_LINE_SHORT_POS 3 +#define MXC_F_OWM_INTEN_LINE_SHORT ((uint32_t)(0x00000001UL << MXC_F_OWM_INTEN_LINE_SHORT_POS)) +#define MXC_F_OWM_INTEN_LINE_LOW_POS 4 +#define MXC_F_OWM_INTEN_LINE_LOW ((uint32_t)(0x00000001UL << MXC_F_OWM_INTEN_LINE_LOW_POS)) + +#define MXC_V_OWM_CFG_EXT_PULLUP_MODE_UNUSED ((uint32_t)(0x00000000UL)) +#define MXC_V_OWM_CFG_EXT_PULLUP_MODE_USED ((uint32_t)(0x00000001UL)) + +#define MXC_V_OWM_CTRL_STAT_OD_SPEC_MODE_12US ((uint32_t)(0x00000000UL)) +#define MXC_V_OWM_CTRL_STAT_OD_SPEC_MODE_10US ((uint32_t)(0x00000001UL)) + +#define MXC_V_OWM_CTRL_STAT_EXT_PULLUP_POL_ACT_HIGH ((uint32_t)(0x00000000UL)) +#define MXC_V_OWM_CTRL_STAT_EXT_PULLUP_POL_ACT_LOW ((uint32_t)(0x00000001UL)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_OWM_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/pmu_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/pmu_regs.h new file mode 100644 index 0000000..931e8dc --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/pmu_regs.h @@ -0,0 +1,388 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_PMU_REGS_H_ +#define _MXC_PMU_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t dscadr; /* 0x0000 PMU Channel Next Descriptor Address */ + __IO uint32_t cfg; /* 0x0004 PMU Channel Configuration */ + __IO uint32_t loop; /* 0x0008 PMU Channel Loop Counters */ + __I uint32_t rsv00C[5]; /* 0x000C-0x001C */ +} mxc_pmu_regs_t; + + +/* + Register offsets for module PMU. +*/ + +#define MXC_R_PMU_OFFS_DSCADR ((uint32_t)0x00000000UL) +#define MXC_R_PMU_OFFS_CFG ((uint32_t)0x00000004UL) +#define MXC_R_PMU_OFFS_LOOP ((uint32_t)0x00000008UL) + + +/* + Field positions and masks for module PMU. +*/ + +#define MXC_F_PMU_CFG_ENABLE_POS 0 +#define MXC_F_PMU_CFG_ENABLE ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_ENABLE_POS)) +#define MXC_F_PMU_CFG_LL_STOPPED_POS 2 +#define MXC_F_PMU_CFG_LL_STOPPED ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_LL_STOPPED_POS)) +#define MXC_F_PMU_CFG_MANUAL_POS 3 +#define MXC_F_PMU_CFG_MANUAL ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_MANUAL_POS)) +#define MXC_F_PMU_CFG_BUS_ERROR_POS 4 +#define MXC_F_PMU_CFG_BUS_ERROR ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_BUS_ERROR_POS)) +#define MXC_F_PMU_CFG_TO_STAT_POS 6 +#define MXC_F_PMU_CFG_TO_STAT ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_TO_STAT_POS)) +#define MXC_F_PMU_CFG_TO_SEL_POS 11 +#define MXC_F_PMU_CFG_TO_SEL ((uint32_t)(0x00000007UL << MXC_F_PMU_CFG_TO_SEL_POS)) +#define MXC_F_PMU_CFG_PS_SEL_POS 14 +#define MXC_F_PMU_CFG_PS_SEL ((uint32_t)(0x00000003UL << MXC_F_PMU_CFG_PS_SEL_POS)) +#define MXC_F_PMU_CFG_INTERRUPT_POS 16 +#define MXC_F_PMU_CFG_INTERRUPT ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_INTERRUPT_POS)) +#define MXC_F_PMU_CFG_INT_EN_POS 17 +#define MXC_F_PMU_CFG_INT_EN ((uint32_t)(0x00000001UL << MXC_F_PMU_CFG_INT_EN_POS)) +#define MXC_F_PMU_CFG_BURST_SIZE_POS 24 +#define MXC_F_PMU_CFG_BURST_SIZE ((uint32_t)(0x0000001FUL << MXC_F_PMU_CFG_BURST_SIZE_POS)) + +#define MXC_F_PMU_LOOP_COUNTER_0_POS 0 +#define MXC_F_PMU_LOOP_COUNTER_0 ((uint32_t)(0x0000FFFFUL << MXC_F_PMU_LOOP_COUNTER_0_POS)) +#define MXC_F_PMU_LOOP_COUNTER_1_POS 16 +#define MXC_F_PMU_LOOP_COUNTER_1 ((uint32_t)(0x0000FFFFUL << MXC_F_PMU_LOOP_COUNTER_1_POS)) + +/* + Field values +*/ + +#define MXC_V_PMU_CFG_TO_SEL_TICKS_4 ((uint32_t)(0x00000000UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_8 ((uint32_t)(0x00000001UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_16 ((uint32_t)(0x00000002UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_32 ((uint32_t)(0x00000003UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_64 ((uint32_t)(0x00000004UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_128 ((uint32_t)(0x00000005UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_256 ((uint32_t)(0x00000006UL)) +#define MXC_V_PMU_CFG_TO_SEL_TICKS_512 ((uint32_t)(0x00000007UL)) + +#define MXC_V_PMU_CFG_PS_SEL_DISABLE ((uint32_t)(0x00000000UL)) +#define MXC_V_PMU_CFG_PS_SEL_DIV_2_8 ((uint32_t)(0x00000001UL)) +#define MXC_V_PMU_CFG_PS_SEL_DIV_2_16 ((uint32_t)(0x00000002UL)) +#define MXC_V_PMU_CFG_PS_SEL_DIV_2_24 ((uint32_t)(0x00000003UL)) + +/* Op codes */ +#define PMU_MOVE_OP 0 +#define PMU_WRITE_OP 1 +#define PMU_WAIT_OP 2 +#define PMU_JUMP_OP 3 +#define PMU_LOOP_OP 4 +#define PMU_POLL_OP 5 +#define PMU_BRANCH_OP 6 +#define PMU_TRANSFER_OP 7 + +/* Bit values used in all decroptiors */ +#define PMU_NO_INTERRUPT 0 /* Interrupt flag is NOT set at end of channel execution */ +#define PMU_INTERRUPT 1 /* Interrupt flag is set at end of channel execution */ + +#define PMU_NO_STOP 0 /* Do not stop channel after this descriptor ends */ +#define PMU_STOP 1 /* Halt PMU channel after this descriptor ends */ + +/* Interrupt and Stop bit positions */ +#define PMU_INT_POS 3 +#define PMU_STOP_POS 4 + +/* MOVE descriptor bit values */ +#define PMU_MOVE_READ_8_BIT 0 /* Read size = 8 */ +#define PMU_MOVE_READ_16_BIT 1 /* Read size = 16 */ +#define PMU_MOVE_READ_32_BIT 2 /* Read size = 32 */ + +#define PMU_MOVE_READ_NO_INC 0 /* read address not incremented */ +#define PMU_MOVE_READ_INC 1 /* Auto-Increment read address */ + +#define PMU_MOVE_WRITE_8_BIT 0 /* Write Size = 8 */ +#define PMU_MOVE_WRITE_16_BIT 1 /* Write Size = 16 */ +#define PMU_MOVE_WRITE_32_BIT 2 /* Write Size = 32 */ + +#define PMU_MOVE_WRITE_NO_INC 0 /* Write address not incremented */ +#define PMU_MOVE_WRITE_INC 1 /* Auto_Increment write address */ + +#define PMU_MOVE_NO_CONT 0 /* MOVE does not rely on previous MOVE */ +#define PMU_MOVE_CONT 1 /* MOVE continues from read/write address */ + /* and INC values defined in previous MOVE */ + +/* MOVE bit positions */ +#define PMU_MOVE_READS_POS 5 +#define PMU_MOVE_READI_POS 7 +#define PMU_MOVE_WRITES_POS 8 +#define PMU_MOVE_WRITEI_POS 10 +#define PMU_MOVE_CONT_POS 11 +#define PMU_MOVE_LEN_POS 12 + +/* WRITE descriptor bit values */ +#define PMU_WRITE_MASKED_WRITE_VALUE 0 /* Value = READ_VALUE & (~WRITE_MASK) | WRITE_VALUE */ +#define PMU_WRITE_PLUS_1 1 /* Value = READ_VALUE + 1 */ +#define PMU_WRITE_MINUS_1 2 /* Value = READ_VALUE - 1 */ +#define PMU_WRITE_SHIFT_RT_1 3 /* Value = READ_VALUE >> 1 */ +#define PMU_WRITE_SHIFT_LT_1 4 /* Value = READ_VALUE << 1 */ +#define PMU_WRITE_ROTATE_RT_1 5 /* Value = READ_VALUE rotated right by 1 (bit 0 becomes bit 31) */ +#define PMU_WRITE_ROTATE_LT_1 6 /* Value = READ_VALUE rotated left by 1 (bit 31 becomes bit 0) */ +#define PMU_WRITE_NOT_READ_VAL 7 /* Value = ~READ_VALUE */ +#define PMU_WRITE_XOR_MASK 8 /* Value = READ_VALUE XOR WRITE_MASK */ +#define PMU_WRITE_OR_MASK 9 /* Value = READ_VALUE | WRITE_MASK */ +#define PMU_WRITE_AND_MASK 10 /* Value = READ_VALUE & WRITE_MASK */ + +/* WRITE bit positions */ +#define PMU_WRITE_METHOD_POS 8 + +/* WAIT descriptor bit values */ +#define PMU_WAIT_SEL_0 0 /* Select the interrupt source */ +#define PMU_WAIT_SEL_1 1 + +/* WAIT bit positions */ +#define PMU_WAIT_WAIT_POS 5 +#define PMU_WAIT_SEL_POS 6 + +/* LOOP descriptor bit values */ +#define PMU_LOOP_SEL_COUNTER0 0 /* select Counter0 to count down from */ +#define PMU_LOOP_SEL_COUNTER1 1 /* select Counter1 to count down from */ + +/* LOOP bit positions */ +#define PMU_LOOP_SEL_COUNTER_POS 5 + +/* POLL descriptor bit values */ +#define PMU_POLL_OR 0 /* polling ends when at least one mask bit matches expected data */ +#define PMU_POLL_AND 1 /* polling ends when all mask bits matches expected data */ + +/* POLL bit positions */ +#define PMU_POLL_AND_POS 7 + +/* BRANCH descriptor bit values */ +#define PMU_BRANCH_OR 0 /* branch when any mask bit = or != expected data (based on = or != branch type) */ +#define PMU_BRANCH_AND 1 /* branch when all mask bit = or != expected data (based on = or != branch type) */ + +#define PMU_BRANCH_TYPE_NOT_EQUAL 0 /* Branch when polled data != expected data */ +#define PMU_BRANCH_TYPE_EQUAL 1 /* Branch when polled data = expected data */ +#define PMU_BRANCH_TYPE_LESS_OR_EQUAL 2 /* Branch when polled data <= expected data */ +#define PMU_BRANCH_TYPE_GREAT_OR_EQUAL 3 /* Branch when polled data >= expected data */ +#define PMU_BRANCH_TYPE_LESSER 4 /* Branch when polled data < expected data */ +#define PMU_BRANCH_TYPE_GREATER 5 /* Branch when polled data > expected data */ + +/* BRANCH bit positions */ +#define PMU_BRANCH_AND_POS 7 +#define PMU_BRANCH_TYPE_POS 8 + +/* TRANSFER descriptor bit values */ +#define PMU_TX_READ_8_BIT 0 /* Read size = 8 */ +#define PMU_TX_READ_16_BIT 1 /* Read size = 16 */ +#define PMU_TX_READ_32_BIT 2 /* Read size = 32 */ + +#define PMU_TX_READ_NO_INC 0 /* read address not incremented */ +#define PMU_TX_READ_INC 1 /* Auto-Increment read address */ + +#define PMU_TX_WRITE_8_BIT 0 /* Write Size = 8 */ +#define PMU_TX_WRITE_16_BIT 1 /* Write Size = 16 */ +#define PMU_TX_WRITE_32_BIT 2 /* Write Size = 32 */ + +#define PMU_TX_WRITE_NO_INC 0 /* Write address not incremented */ +#define PMU_TX_WRITE_INC 1 /* Auto_Increment write address */ + +/* TRANSFER bit positions */ +#define PMU_TX_READS_POS 5 +#define PMU_TX_READI_POS 7 +#define PMU_TX_WRITES_POS 8 +#define PMU_TX_WRITEI_POS 10 +#define PMU_TX_LEN_POS 12 +#define PMU_TX_BS_POS 26 + +/* PMU interrupt sources for the WAIT opcode */ +#define PMU_WAIT_IRQ_MASK1_SEL0_UART0_TX_FIFO_AE ((uint32_t)(0x00000001UL << 0)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART0_RX_FIFO_AF ((uint32_t)(0x00000001UL << 1)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART1_TX_FIFO_AE ((uint32_t)(0x00000001UL << 2)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART1_RX_FIFO_AF ((uint32_t)(0x00000001UL << 3)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART2_TX_FIFO_AE ((uint32_t)(0x00000001UL << 4)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART2_RX_FIFO_AF ((uint32_t)(0x00000001UL << 5)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART3_TX_FIFO_AE ((uint32_t)(0x00000001UL << 6)) +#define PMU_WAIT_IRQ_MASK1_SEL0_UART3_RX_FIFO_AF ((uint32_t)(0x00000001UL << 7)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI0_TX_FIFO_AE ((uint32_t)(0x00000001UL << 8)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI0_RX_FIFO_AF ((uint32_t)(0x00000001UL << 9)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI1_TX_FIFO_AE ((uint32_t)(0x00000001UL << 10)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI1_RX_FIFO_AF ((uint32_t)(0x00000001UL << 11)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI2_TX_FIFO_AE ((uint32_t)(0x00000001UL << 12)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI2_RX_FIFO_AF ((uint32_t)(0x00000001UL << 13)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM0_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << 14)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM0_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << 15)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM1_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << 16)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM1_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << 17)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM2_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << 18)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM2_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << 19)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI0_TX_RX_STALLED ((uint32_t)(0x00000001UL << 20)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI1_TX_RX_STALLED ((uint32_t)(0x00000001UL << 21)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPI2_TX_RX_STALLED ((uint32_t)(0x00000001UL << 22)) +#define PMU_WAIT_IRQ_MASK1_SEL0_SPIB ((uint32_t)(0x00000001UL << 23)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM0_DONE ((uint32_t)(0x00000001UL << 24)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM1_DONE ((uint32_t)(0x00000001UL << 25)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CM2_DONE ((uint32_t)(0x00000001UL << 26)) +#define PMU_WAIT_IRQ_MASK1_SEL0_I2CS ((uint32_t)(0x00000001UL << 27)) +#define PMU_WAIT_IRQ_MASK1_SEL0_ADC_DONE ((uint32_t)(0x00000001UL << 28)) +#define PMU_WAIT_IRQ_MASK1_SEL0_ADC_READY ((uint32_t)(0x00000001UL << 29)) +#define PMU_WAIT_IRQ_MASK1_SEL0_ADC_HI ((uint32_t)(0x00000001UL << 30)) +#define PMU_WAIT_IRQ_MASK1_SEL0_ADC_LOW ((uint32_t)(0x00000001UL << 31)) +#define PMU_WAIT_IRQ_MASK2_SEL0_RTC_COMP0 ((uint32_t)(0x00000001UL << 0)) +#define PMU_WAIT_IRQ_MASK2_SEL0_RTC_COMP1 ((uint32_t)(0x00000001UL << 1)) +#define PMU_WAIT_IRQ_MASK2_SEL0_RTC_PRESCALE ((uint32_t)(0x00000001UL << 2)) +#define PMU_WAIT_IRQ_MASK2_SEL0_RTC_OVERFLOW ((uint32_t)(0x00000001UL << 3)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT0_DISABLED ((uint32_t)(0x00000001UL << 4)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT1_DISABLED ((uint32_t)(0x00000001UL << 5)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT2_DISABLED ((uint32_t)(0x00000001UL << 6)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT3_DISABLED ((uint32_t)(0x00000001UL << 7)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT4_DISABLED ((uint32_t)(0x00000001UL << 8)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT5_DISABLED ((uint32_t)(0x00000001UL << 9)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT6_DISABLED ((uint32_t)(0x00000001UL << 10)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT7_DISABLED ((uint32_t)(0x00000001UL << 11)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT8_DISABLED ((uint32_t)(0x00000001UL << 12)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT9_DISABLED ((uint32_t)(0x00000001UL << 13)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT10_DISABLED ((uint32_t)(0x00000001UL << 14)) +#define PMU_WAIT_IRQ_MASK2_SEL0_PT11_DISABLED ((uint32_t)(0x00000001UL << 15)) +#define PMU_WAIT_IRQ_MASK2_SEL0_TMR0 ((uint32_t)(0x00000001UL << 16)) +#define PMU_WAIT_IRQ_MASK2_SEL0_TMR1 ((uint32_t)(0x00000001UL << 17)) +#define PMU_WAIT_IRQ_MASK2_SEL0_TMR2 ((uint32_t)(0x00000001UL << 18)) +#define PMU_WAIT_IRQ_MASK2_SEL0_TMR3 ((uint32_t)(0x00000001UL << 19)) +#define PMU_WAIT_IRQ_MASK2_SEL0_TMR4 ((uint32_t)(0x00000001UL << 20)) +#define PMU_WAIT_IRQ_MASK2_SEL0_TMR5 ((uint32_t)(0x00000001UL << 21)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO0 ((uint32_t)(0x00000001UL << 22)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO1 ((uint32_t)(0x00000001UL << 23)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO2 ((uint32_t)(0x00000001UL << 24)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO3 ((uint32_t)(0x00000001UL << 25)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO4 ((uint32_t)(0x00000001UL << 26)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO5 ((uint32_t)(0x00000001UL << 27)) +#define PMU_WAIT_IRQ_MASK2_SEL0_GPIO6 ((uint32_t)(0x00000001UL << 28)) +#define PMU_WAIT_IRQ_MASK2_SEL0_AES ((uint32_t)(0x00000001UL << 29)) +#define PMU_WAIT_IRQ_MASK2_SEL0_MAA_DONE ((uint32_t)(0x00000001UL << 30)) +#define PMU_WAIT_IRQ_MASK2_SEL0_OWM ((uint32_t)(0x00000001UL << 31)) +#define PMU_WAIT_IRQ_MASK1_SEL1_GPIO7 ((uint32_t)(0x00000001UL << 0)) +#define PMU_WAIT_IRQ_MASK1_SEL1_GPIO8 ((uint32_t)(0x00000001UL << 1)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT12_DISABLED ((uint32_t)(0x00000001UL << 2)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT13_DISABLED ((uint32_t)(0x00000001UL << 3)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT14_DISABLED ((uint32_t)(0x00000001UL << 4)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT15_DISABLED ((uint32_t)(0x00000001UL << 5)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT0_INT ((uint32_t)(0x00000001UL << 6)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT1_INT ((uint32_t)(0x00000001UL << 7)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT2_INT ((uint32_t)(0x00000001UL << 8)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT3_INT ((uint32_t)(0x00000001UL << 9)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT4_INT ((uint32_t)(0x00000001UL << 10)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT5_INT ((uint32_t)(0x00000001UL << 11)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT6_INT ((uint32_t)(0x00000001UL << 12)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT7_INT ((uint32_t)(0x00000001UL << 13)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT8_INT ((uint32_t)(0x00000001UL << 14)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT9_INT ((uint32_t)(0x00000001UL << 15)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT10_INT ((uint32_t)(0x00000001UL << 16)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT11_INT ((uint32_t)(0x00000001UL << 17)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT12_INT ((uint32_t)(0x00000001UL << 18)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT13_INT ((uint32_t)(0x00000001UL << 19)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT14_INT ((uint32_t)(0x00000001UL << 20)) +#define PMU_WAIT_IRQ_MASK1_SEL1_PT15_INT ((uint32_t)(0x00000001UL << 21)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPIS_TX_FIFO_AE ((uint32_t)(0x00000001UL << 22)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPIS_RX_FIFO_AF ((uint32_t)(0x00000001UL << 23)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPIS_TX_NO_DATA ((uint32_t)(0x00000001UL << 24)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPIS_RX_DATA_LOST ((uint32_t)(0x00000001UL << 25)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPI0_TX_READY ((uint32_t)(0x00000001UL << 26)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPI1_TX_READY ((uint32_t)(0x00000001UL << 27)) +#define PMU_WAIT_IRQ_MASK1_SEL1_SPI2_TX_READY ((uint32_t)(0x00000001UL << 28)) +#define PMU_WAIT_IRQ_MASK1_SEL1_UART0_TX_DONE ((uint32_t)(0x00000001UL << 29)) +#define PMU_WAIT_IRQ_MASK1_SEL1_UART1_TX_DONE ((uint32_t)(0x00000001UL << 30)) +#define PMU_WAIT_IRQ_MASK1_SEL1_UART2_TX_DONE ((uint32_t)(0x00000001UL << 31)) +#define PMU_WAIT_IRQ_MASK2_SEL1_UART3_TX_DONE ((uint32_t)(0x00000001UL << 0)) +#define PMU_WAIT_IRQ_MASK2_SEL1_UART0_RX_DATA_READY ((uint32_t)(0x00000001UL << 1)) +#define PMU_WAIT_IRQ_MASK2_SEL1_UART1_RX_DATA_READY ((uint32_t)(0x00000001UL << 2)) +#define PMU_WAIT_IRQ_MASK2_SEL1_UART2_RX_DATA_READY ((uint32_t)(0x00000001UL << 3)) +#define PMU_WAIT_IRQ_MASK2_SEL1_UART3_RX_DATA_READY ((uint32_t)(0x00000001UL << 4)) + +/* PMU interrupt sources for the TRANSFER opcode */ +#define PMU_TRANSFER_IRQ_UART0_TX_FIFO_AE ((uint32_t)(0x00000001UL << 0)) +#define PMU_TRANSFER_IRQ_UART0_RX_FIFO_AF ((uint32_t)(0x00000001UL << 1)) +#define PMU_TRANSFER_IRQ_UART1_TX_FIFO_AE ((uint32_t)(0x00000001UL << 2)) +#define PMU_TRANSFER_IRQ_UART1_RX_FIFO_AF ((uint32_t)(0x00000001UL << 3)) +#define PMU_TRANSFER_IRQ_UART2_TX_FIFO_AE ((uint32_t)(0x00000001UL << 4)) +#define PMU_TRANSFER_IRQ_UART2_RX_FIFO_AF ((uint32_t)(0x00000001UL << 5)) +#define PMU_TRANSFER_IRQ_UART3_TX_FIFO_AE ((uint32_t)(0x00000001UL << 6)) +#define PMU_TRANSFER_IRQ_UART3_RX_FIFO_AF ((uint32_t)(0x00000001UL << 7)) +#define PMU_TRANSFER_IRQ_SPI0_TX_FIFO_AE ((uint32_t)(0x00000001UL << 8)) +#define PMU_TRANSFER_IRQ_SPI0_RX_FIFO_AF ((uint32_t)(0x00000001UL << 9)) +#define PMU_TRANSFER_IRQ_SPI1_TX_FIFO_AE ((uint32_t)(0x00000001UL << 10)) +#define PMU_TRANSFER_IRQ_SPI1_RX_FIFO_AF ((uint32_t)(0x00000001UL << 11)) +#define PMU_TRANSFER_IRQ_SPI2_TX_FIFO_AE ((uint32_t)(0x00000001UL << 12)) +#define PMU_TRANSFER_IRQ_SPI2_RX_FIFO_AF ((uint32_t)(0x00000001UL << 13)) +#define PMU_TRANSFER_IRQ_I2CM0_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << 14)) +#define PMU_TRANSFER_IRQ_I2CM0_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << 15)) +#define PMU_TRANSFER_IRQ_I2CM0_RX_FIFO_FULL ((uint32_t)(0x00000001UL << 16)) +#define PMU_TRANSFER_IRQ_I2CM1_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << 17)) +#define PMU_TRANSFER_IRQ_I2CM1_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << 18)) +#define PMU_TRANSFER_IRQ_I2CM1_RX_FIFO_FULL ((uint32_t)(0x00000001UL << 19)) +#define PMU_TRANSFER_IRQ_I2CM2_TX_FIFO_EMPTY ((uint32_t)(0x00000001UL << 20)) +#define PMU_TRANSFER_IRQ_I2CM2_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << 21)) +#define PMU_TRANSFER_IRQ_I2CM2_RX_FIFO_FULL ((uint32_t)(0x00000001UL << 22)) +#define PMU_TRANSFER_IRQ_SPIS_TX_FIFO_AE ((uint32_t)(0x00000001UL << 23)) +#define PMU_TRANSFER_IRQ_SPIS_RX_FIFO_AF ((uint32_t)(0x00000001UL << 24)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_PMU_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/prng_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/prng_regs.h new file mode 100644 index 0000000..eedec6e --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/prng_regs.h @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_PRNG_REGS_H_ +#define _MXC_PRNG_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t user_entropy; /* 0x0000 PRNG User Entropy and Status */ + __IO uint32_t rnd_num; /* 0x0004 PRNG Seed Output */ +} mxc_prng_regs_t; + +/* + Register offsets for module PRNG. +*/ + +#define MXC_R_PRNG_OFFS_USER_ENTROPY ((uint32_t)0x00000000UL) +#define MXC_R_PRNG_OFFS_RND_NUM ((uint32_t)0x00000004UL) + +/* + Field positions and masks for module PRNG. +*/ + +#define MXC_F_PRNG_USER_ENTROPY_VALUE_POS 0 +#define MXC_F_PRNG_USER_ENTROPY_VALUE ((uint32_t)(0x000000FFUL << MXC_F_PRNG_USER_ENTROPY_VALUE_POS)) +#define MXC_F_PRNG_USER_ENTROPY_RND_NUM_READY_POS 8 +#define MXC_F_PRNG_USER_ENTROPY_RND_NUM_READY ((uint32_t)(0x00000001UL << MXC_F_PRNG_USER_ENTROPY_RND_NUM_READY_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_PRNG_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/pt_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/pt_regs.h new file mode 100644 index 0000000..12692ca --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/pt_regs.h @@ -0,0 +1,330 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_PT_REGS_H_ +#define _MXC_PT_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t enable; /* 0x0000 Global Enable/Disable Controls for All Pulse Trains */ + __IO uint32_t resync; /* 0x0004 Global Resync (All Pulse Trains) Control */ + __IO uint32_t intfl; /* 0x0008 Pulse Train Interrupt Flags */ + __IO uint32_t inten; /* 0x000C Pulse Train Interrupt Enable/Disable */ +} mxc_ptg_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t rate_length; /* 0x0000 Pulse Train Configuration */ + __IO uint32_t train; /* 0x0004 Pulse Train Output Pattern */ + __IO uint32_t loop; /* 0x0008 Pulse Train Loop Configuration */ + __IO uint32_t restart; /* 0x000C Pulse Train Auto-Restart Configuration */ +} mxc_pt_regs_t; + + +/* + Register offsets for module PT. +*/ + +#define MXC_R_PTG_OFFS_ENABLE ((uint32_t)0x00000000UL) +#define MXC_R_PTG_OFFS_RESYNC ((uint32_t)0x00000004UL) +#define MXC_R_PTG_OFFS_INTFL ((uint32_t)0x00000008UL) +#define MXC_R_PTG_OFFS_INTEN ((uint32_t)0x0000000CUL) +#define MXC_R_PT_OFFS_RATE_LENGTH ((uint32_t)0x00000000UL) +#define MXC_R_PT_OFFS_TRAIN ((uint32_t)0x00000004UL) +#define MXC_R_PT_OFFS_LOOP ((uint32_t)0x00000008UL) +#define MXC_R_PT_OFFS_RESTART ((uint32_t)0x0000000CUL) + + +/* + Field positions and masks for module PT. +*/ + +#define MXC_F_PT_ENABLE_PT0_POS 0 +#define MXC_F_PT_ENABLE_PT0 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT0_POS)) +#define MXC_F_PT_ENABLE_PT1_POS 1 +#define MXC_F_PT_ENABLE_PT1 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT1_POS)) +#define MXC_F_PT_ENABLE_PT2_POS 2 +#define MXC_F_PT_ENABLE_PT2 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT2_POS)) +#define MXC_F_PT_ENABLE_PT3_POS 3 +#define MXC_F_PT_ENABLE_PT3 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT3_POS)) +#define MXC_F_PT_ENABLE_PT4_POS 4 +#define MXC_F_PT_ENABLE_PT4 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT4_POS)) +#define MXC_F_PT_ENABLE_PT5_POS 5 +#define MXC_F_PT_ENABLE_PT5 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT5_POS)) +#define MXC_F_PT_ENABLE_PT6_POS 6 +#define MXC_F_PT_ENABLE_PT6 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT6_POS)) +#define MXC_F_PT_ENABLE_PT7_POS 7 +#define MXC_F_PT_ENABLE_PT7 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT7_POS)) +#define MXC_F_PT_ENABLE_PT8_POS 8 +#define MXC_F_PT_ENABLE_PT8 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT8_POS)) +#define MXC_F_PT_ENABLE_PT9_POS 9 +#define MXC_F_PT_ENABLE_PT9 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT9_POS)) +#define MXC_F_PT_ENABLE_PT10_POS 10 +#define MXC_F_PT_ENABLE_PT10 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT10_POS)) +#define MXC_F_PT_ENABLE_PT11_POS 11 +#define MXC_F_PT_ENABLE_PT11 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT11_POS)) +#define MXC_F_PT_ENABLE_PT12_POS 12 +#define MXC_F_PT_ENABLE_PT12 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT12_POS)) +#define MXC_F_PT_ENABLE_PT13_POS 13 +#define MXC_F_PT_ENABLE_PT13 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT13_POS)) +#define MXC_F_PT_ENABLE_PT14_POS 14 +#define MXC_F_PT_ENABLE_PT14 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT14_POS)) +#define MXC_F_PT_ENABLE_PT15_POS 15 +#define MXC_F_PT_ENABLE_PT15 ((uint32_t)(0x00000001UL << MXC_F_PT_ENABLE_PT15_POS)) + +#define MXC_F_PT_RESYNC_PT0_POS 0 +#define MXC_F_PT_RESYNC_PT0 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT0_POS)) +#define MXC_F_PT_RESYNC_PT1_POS 1 +#define MXC_F_PT_RESYNC_PT1 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT1_POS)) +#define MXC_F_PT_RESYNC_PT2_POS 2 +#define MXC_F_PT_RESYNC_PT2 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT2_POS)) +#define MXC_F_PT_RESYNC_PT3_POS 3 +#define MXC_F_PT_RESYNC_PT3 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT3_POS)) +#define MXC_F_PT_RESYNC_PT4_POS 4 +#define MXC_F_PT_RESYNC_PT4 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT4_POS)) +#define MXC_F_PT_RESYNC_PT5_POS 5 +#define MXC_F_PT_RESYNC_PT5 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT5_POS)) +#define MXC_F_PT_RESYNC_PT6_POS 6 +#define MXC_F_PT_RESYNC_PT6 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT6_POS)) +#define MXC_F_PT_RESYNC_PT7_POS 7 +#define MXC_F_PT_RESYNC_PT7 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT7_POS)) +#define MXC_F_PT_RESYNC_PT8_POS 8 +#define MXC_F_PT_RESYNC_PT8 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT8_POS)) +#define MXC_F_PT_RESYNC_PT9_POS 9 +#define MXC_F_PT_RESYNC_PT9 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT9_POS)) +#define MXC_F_PT_RESYNC_PT10_POS 10 +#define MXC_F_PT_RESYNC_PT10 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT10_POS)) +#define MXC_F_PT_RESYNC_PT11_POS 11 +#define MXC_F_PT_RESYNC_PT11 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT11_POS)) +#define MXC_F_PT_RESYNC_PT12_POS 12 +#define MXC_F_PT_RESYNC_PT12 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT12_POS)) +#define MXC_F_PT_RESYNC_PT13_POS 13 +#define MXC_F_PT_RESYNC_PT13 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT13_POS)) +#define MXC_F_PT_RESYNC_PT14_POS 14 +#define MXC_F_PT_RESYNC_PT14 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT14_POS)) +#define MXC_F_PT_RESYNC_PT15_POS 15 +#define MXC_F_PT_RESYNC_PT15 ((uint32_t)(0x00000001UL << MXC_F_PT_RESYNC_PT15_POS)) + +#define MXC_F_PT_INTFL_PT0_POS 0 +#define MXC_F_PT_INTFL_PT0 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT0_POS)) +#define MXC_F_PT_INTFL_PT1_POS 1 +#define MXC_F_PT_INTFL_PT1 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT1_POS)) +#define MXC_F_PT_INTFL_PT2_POS 2 +#define MXC_F_PT_INTFL_PT2 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT2_POS)) +#define MXC_F_PT_INTFL_PT3_POS 3 +#define MXC_F_PT_INTFL_PT3 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT3_POS)) +#define MXC_F_PT_INTFL_PT4_POS 4 +#define MXC_F_PT_INTFL_PT4 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT4_POS)) +#define MXC_F_PT_INTFL_PT5_POS 5 +#define MXC_F_PT_INTFL_PT5 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT5_POS)) +#define MXC_F_PT_INTFL_PT6_POS 6 +#define MXC_F_PT_INTFL_PT6 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT6_POS)) +#define MXC_F_PT_INTFL_PT7_POS 7 +#define MXC_F_PT_INTFL_PT7 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT7_POS)) +#define MXC_F_PT_INTFL_PT8_POS 8 +#define MXC_F_PT_INTFL_PT8 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT8_POS)) +#define MXC_F_PT_INTFL_PT9_POS 9 +#define MXC_F_PT_INTFL_PT9 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT9_POS)) +#define MXC_F_PT_INTFL_PT10_POS 10 +#define MXC_F_PT_INTFL_PT10 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT10_POS)) +#define MXC_F_PT_INTFL_PT11_POS 11 +#define MXC_F_PT_INTFL_PT11 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT11_POS)) +#define MXC_F_PT_INTFL_PT12_POS 12 +#define MXC_F_PT_INTFL_PT12 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT12_POS)) +#define MXC_F_PT_INTFL_PT13_POS 13 +#define MXC_F_PT_INTFL_PT13 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT13_POS)) +#define MXC_F_PT_INTFL_PT14_POS 14 +#define MXC_F_PT_INTFL_PT14 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT14_POS)) +#define MXC_F_PT_INTFL_PT15_POS 15 +#define MXC_F_PT_INTFL_PT15 ((uint32_t)(0x00000001UL << MXC_F_PT_INTFL_PT15_POS)) + +#define MXC_F_PT_INTEN_PT0_POS 0 +#define MXC_F_PT_INTEN_PT0 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT0_POS)) +#define MXC_F_PT_INTEN_PT1_POS 1 +#define MXC_F_PT_INTEN_PT1 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT1_POS)) +#define MXC_F_PT_INTEN_PT2_POS 2 +#define MXC_F_PT_INTEN_PT2 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT2_POS)) +#define MXC_F_PT_INTEN_PT3_POS 3 +#define MXC_F_PT_INTEN_PT3 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT3_POS)) +#define MXC_F_PT_INTEN_PT4_POS 4 +#define MXC_F_PT_INTEN_PT4 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT4_POS)) +#define MXC_F_PT_INTEN_PT5_POS 5 +#define MXC_F_PT_INTEN_PT5 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT5_POS)) +#define MXC_F_PT_INTEN_PT6_POS 6 +#define MXC_F_PT_INTEN_PT6 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT6_POS)) +#define MXC_F_PT_INTEN_PT7_POS 7 +#define MXC_F_PT_INTEN_PT7 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT7_POS)) +#define MXC_F_PT_INTEN_PT8_POS 8 +#define MXC_F_PT_INTEN_PT8 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT8_POS)) +#define MXC_F_PT_INTEN_PT9_POS 9 +#define MXC_F_PT_INTEN_PT9 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT9_POS)) +#define MXC_F_PT_INTEN_PT10_POS 10 +#define MXC_F_PT_INTEN_PT10 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT10_POS)) +#define MXC_F_PT_INTEN_PT11_POS 11 +#define MXC_F_PT_INTEN_PT11 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT11_POS)) +#define MXC_F_PT_INTEN_PT12_POS 12 +#define MXC_F_PT_INTEN_PT12 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT12_POS)) +#define MXC_F_PT_INTEN_PT13_POS 13 +#define MXC_F_PT_INTEN_PT13 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT13_POS)) +#define MXC_F_PT_INTEN_PT14_POS 14 +#define MXC_F_PT_INTEN_PT14 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT14_POS)) +#define MXC_F_PT_INTEN_PT15_POS 15 +#define MXC_F_PT_INTEN_PT15 ((uint32_t)(0x00000001UL << MXC_F_PT_INTEN_PT15_POS)) + +#define MXC_F_PT_RATE_LENGTH_RATE_CONTROL_POS 0 +#define MXC_F_PT_RATE_LENGTH_RATE_CONTROL ((uint32_t)(0x07FFFFFFUL << MXC_F_PT_RATE_LENGTH_RATE_CONTROL_POS)) +#define MXC_F_PT_RATE_LENGTH_MODE_POS 27 +#define MXC_F_PT_RATE_LENGTH_MODE ((uint32_t)(0x0000001FUL << MXC_F_PT_RATE_LENGTH_MODE_POS)) + +#define MXC_F_PT_LOOP_COUNT_POS 0 +#define MXC_F_PT_LOOP_COUNT ((uint32_t)(0x0000FFFFUL << MXC_F_PT_LOOP_COUNT_POS)) +#define MXC_F_PT_LOOP_DELAY_POS 16 +#define MXC_F_PT_LOOP_DELAY ((uint32_t)(0x00000FFFUL << MXC_F_PT_LOOP_DELAY_POS)) + +#define MXC_F_PT_RESTART_PT_X_SELECT_POS 0 +#define MXC_F_PT_RESTART_PT_X_SELECT ((uint32_t)(0x0000001FUL << MXC_F_PT_RESTART_PT_X_SELECT_POS)) +#define MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT_POS 7 +#define MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT ((uint32_t)(0x00000001UL << MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT_POS)) +#define MXC_F_PT_RESTART_PT_Y_SELECT_POS 8 +#define MXC_F_PT_RESTART_PT_Y_SELECT ((uint32_t)(0x0000001FUL << MXC_F_PT_RESTART_PT_Y_SELECT_POS)) +#define MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT_POS 15 +#define MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT ((uint32_t)(0x00000001UL << MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT_POS)) + + + +/* + Field values and shifted values for module PT. +*/ + +#define MXC_V_PT_RATE_LENGTH_MODE_32_BIT ((uint32_t)(0x00000000UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_SQUARE_WAVE ((uint32_t)(0x00000001UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_2_BIT ((uint32_t)(0x00000002UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_3_BIT ((uint32_t)(0x00000003UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_4_BIT ((uint32_t)(0x00000004UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_5_BIT ((uint32_t)(0x00000005UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_6_BIT ((uint32_t)(0x00000006UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_7_BIT ((uint32_t)(0x00000007UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_8_BIT ((uint32_t)(0x00000008UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_9_BIT ((uint32_t)(0x00000009UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_10_BIT ((uint32_t)(0x0000000AUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_11_BIT ((uint32_t)(0x0000000BUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_12_BIT ((uint32_t)(0x0000000CUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_13_BIT ((uint32_t)(0x0000000DUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_14_BIT ((uint32_t)(0x0000000EUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_15_BIT ((uint32_t)(0x0000000FUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_16_BIT ((uint32_t)(0x00000010UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_17_BIT ((uint32_t)(0x00000011UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_18_BIT ((uint32_t)(0x00000012UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_19_BIT ((uint32_t)(0x00000013UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_20_BIT ((uint32_t)(0x00000014UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_21_BIT ((uint32_t)(0x00000015UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_22_BIT ((uint32_t)(0x00000016UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_23_BIT ((uint32_t)(0x00000017UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_24_BIT ((uint32_t)(0x00000018UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_25_BIT ((uint32_t)(0x00000019UL)) +#define MXC_V_PT_RATE_LENGTH_MODE_26_BIT ((uint32_t)(0x0000001AUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_27_BIT ((uint32_t)(0x0000001BUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_28_BIT ((uint32_t)(0x0000001CUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_29_BIT ((uint32_t)(0x0000001DUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_30_BIT ((uint32_t)(0x0000001EUL)) +#define MXC_V_PT_RATE_LENGTH_MODE_31_BIT ((uint32_t)(0x0000001FUL)) + +#define MXC_S_PT_RATE_LENGTH_MODE_32_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_32_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_SQUARE_WAVE ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_SQUARE_WAVE << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_2_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_2_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_3_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_3_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_4_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_4_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_5_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_5_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_6_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_6_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_7_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_7_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_8_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_8_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_9_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_9_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_10_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_10_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_11_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_11_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_12_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_12_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_13_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_13_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_14_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_14_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_15_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_15_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_16_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_16_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_17_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_17_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_18_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_18_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_19_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_19_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_20_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_20_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_21_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_21_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_22_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_22_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_23_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_23_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_24_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_24_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_25_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_25_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_26_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_26_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_27_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_27_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_28_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_28_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_29_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_29_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_30_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_30_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) +#define MXC_S_PT_RATE_LENGTH_MODE_31_BIT ((uint32_t)(MXC_V_PT_RATE_LENGTH_MODE_31_BIT << MXC_F_PT_RATE_LENGTH_MODE_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_PT_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/pwrman_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/pwrman_regs.h new file mode 100644 index 0000000..ab4abec --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/pwrman_regs.h @@ -0,0 +1,367 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_PWRMAN_REGS_H_ +#define _MXC_PWRMAN_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/** + * @brief Defines PAD Modes for Wake Up Detection. + */ +typedef enum { + /** WUD Mode for Selected PAD = Clear/Activate */ + MXC_E_PWRMAN_PAD_MODE_CLEAR_SET, + /** WUD Mode for Selected PAD = Set WUD Act Hi/Set WUD Act Lo */ + MXC_E_PWRMAN_PAD_MODE_ACT_HI_LO, + /** WUD Mode for Selected PAD = Set Weak Hi/ Set Weak Lo */ + MXC_E_PWRMAN_PAD_MODE_WEAK_HI_LO, + /** WUD Mode for Selected PAD = No pad state change */ + MXC_E_PWRMAN_PAD_MODE_NONE +} mxc_pwrman_pad_mode_t; + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t pwr_rst_ctrl; /* 0x0000 Power Reset Control and Status */ + __IO uint32_t intfl; /* 0x0004 Interrupt Flags */ + __IO uint32_t inten; /* 0x0008 Interrupt Enable/Disable Controls */ + __IO uint32_t svm_events; /* 0x000C SVM Event Status Flags (read-only) */ + __IO uint32_t wud_ctrl; /* 0x0010 Wake-Up Detect Control */ + __IO uint32_t wud_pulse0; /* 0x0014 WUD Pulse To Mode Bit 0 */ + __IO uint32_t wud_pulse1; /* 0x0018 WUD Pulse To Mode Bit 1 */ + __IO uint32_t wud_seen0; /* 0x001C Wake-up Detect Status for P0/P1/P2/P3 */ + __IO uint32_t wud_seen1; /* 0x0020 Wake-up Detect Status for P4/P5/P6/P7 */ + __I uint32_t rsv024[3]; /* 0x0024-0x002C */ + __IO uint32_t pt_regmap_ctrl; /* 0x0030 PT Register Mapping Control */ + __I uint32_t rsv034; /* 0x0034 */ + __IO uint32_t die_type; /* 0x0038 Die Type ID Register */ + __IO uint32_t base_part_num; /* 0x003C Base Part Number */ + __IO uint32_t mask_id0; /* 0x0040 Mask ID Register 0 */ + __IO uint32_t mask_id1; /* 0x0044 Mask ID Register 1 */ + __IO uint32_t peripheral_reset; /* 0x0048 Peripheral Reset Control Register */ +} mxc_pwrman_regs_t; + + +/* + Register offsets for module PWRMAN. +*/ + +#define MXC_R_PWRMAN_OFFS_PWR_RST_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_PWRMAN_OFFS_INTFL ((uint32_t)0x00000004UL) +#define MXC_R_PWRMAN_OFFS_INTEN ((uint32_t)0x00000008UL) +#define MXC_R_PWRMAN_OFFS_SVM_EVENTS ((uint32_t)0x0000000CUL) +#define MXC_R_PWRMAN_OFFS_WUD_CTRL ((uint32_t)0x00000010UL) +#define MXC_R_PWRMAN_OFFS_WUD_PULSE0 ((uint32_t)0x00000014UL) +#define MXC_R_PWRMAN_OFFS_WUD_PULSE1 ((uint32_t)0x00000018UL) +#define MXC_R_PWRMAN_OFFS_WUD_SEEN0 ((uint32_t)0x0000001CUL) +#define MXC_R_PWRMAN_OFFS_WUD_SEEN1 ((uint32_t)0x00000020UL) +#define MXC_R_PWRMAN_OFFS_PT_REGMAP_CTRL ((uint32_t)0x00000030UL) +#define MXC_R_PWRMAN_OFFS_DIE_TYPE ((uint32_t)0x00000038UL) +#define MXC_R_PWRMAN_OFFS_BASE_PART_NUM ((uint32_t)0x0000003CUL) +#define MXC_R_PWRMAN_OFFS_MASK_ID0 ((uint32_t)0x00000040UL) +#define MXC_R_PWRMAN_OFFS_MASK_ID1 ((uint32_t)0x00000044UL) +#define MXC_R_PWRMAN_OFFS_PERIPHERAL_RESET ((uint32_t)0x00000048UL) + + +/* + Field positions and masks for module PWRMAN. +*/ + +#define MXC_F_PWRMAN_PWR_RST_CTRL_AFE_POWERED_POS 2 +#define MXC_F_PWRMAN_PWR_RST_CTRL_AFE_POWERED ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_AFE_POWERED_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_IO_ACTIVE_POS 3 +#define MXC_F_PWRMAN_PWR_RST_CTRL_IO_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_IO_ACTIVE_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_USB_POWERED_POS 4 +#define MXC_F_PWRMAN_PWR_RST_CTRL_USB_POWERED ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_USB_POWERED_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_PULLUPS_ENABLED_POS 5 +#define MXC_F_PWRMAN_PWR_RST_CTRL_PULLUPS_ENABLED ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_PULLUPS_ENABLED_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_FIRMWARE_RESET_POS 8 +#define MXC_F_PWRMAN_PWR_RST_CTRL_FIRMWARE_RESET ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_FIRMWARE_RESET_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_ARM_LOCKUP_RESET_POS 9 +#define MXC_F_PWRMAN_PWR_RST_CTRL_ARM_LOCKUP_RESET ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_ARM_LOCKUP_RESET_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_TAMPER_DETECT_POS 16 +#define MXC_F_PWRMAN_PWR_RST_CTRL_TAMPER_DETECT ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_TAMPER_DETECT_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_ARM_LOCKUP_POS 17 +#define MXC_F_PWRMAN_PWR_RST_CTRL_ARM_LOCKUP ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_ARM_LOCKUP_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_FW_COMMAND_ARM_POS 18 +#define MXC_F_PWRMAN_PWR_RST_CTRL_FW_COMMAND_ARM ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_FW_COMMAND_ARM_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_WATCHDOG_TIMEOUT_POS 19 +#define MXC_F_PWRMAN_PWR_RST_CTRL_WATCHDOG_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_WATCHDOG_TIMEOUT_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_FW_COMMAND_SYSMAN_POS 20 +#define MXC_F_PWRMAN_PWR_RST_CTRL_FW_COMMAND_SYSMAN ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_FW_COMMAND_SYSMAN_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_SRSTN_ASSERTION_POS 21 +#define MXC_F_PWRMAN_PWR_RST_CTRL_SRSTN_ASSERTION ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_SRSTN_ASSERTION_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_POR_POS 22 +#define MXC_F_PWRMAN_PWR_RST_CTRL_POR ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_POR_POS)) +#define MXC_F_PWRMAN_PWR_RST_CTRL_LOW_POWER_MODE_POS 31 +#define MXC_F_PWRMAN_PWR_RST_CTRL_LOW_POWER_MODE ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PWR_RST_CTRL_LOW_POWER_MODE_POS)) + +#define MXC_F_PWRMAN_INTFL_V1_2_WARNING_POS 0 +#define MXC_F_PWRMAN_INTFL_V1_2_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_V1_2_WARNING_POS)) +#define MXC_F_PWRMAN_INTFL_V1_8_WARNING_POS 1 +#define MXC_F_PWRMAN_INTFL_V1_8_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_V1_8_WARNING_POS)) +#define MXC_F_PWRMAN_INTFL_RTC_WARNING_POS 2 +#define MXC_F_PWRMAN_INTFL_RTC_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_RTC_WARNING_POS)) +#define MXC_F_PWRMAN_INTFL_VDDA_WARNING_POS 3 +#define MXC_F_PWRMAN_INTFL_VDDA_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_VDDA_WARNING_POS)) +#define MXC_F_PWRMAN_INTFL_VDDB_WARNING_POS 4 +#define MXC_F_PWRMAN_INTFL_VDDB_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_VDDB_WARNING_POS)) +#define MXC_F_PWRMAN_INTFL_VDDIO_WARNING_POS 5 +#define MXC_F_PWRMAN_INTFL_VDDIO_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_VDDIO_WARNING_POS)) +#define MXC_F_PWRMAN_INTFL_VDDIOH_WARNING_POS 6 +#define MXC_F_PWRMAN_INTFL_VDDIOH_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTFL_VDDIOH_WARNING_POS)) + +#define MXC_F_PWRMAN_INTEN_V1_2_WARNING_POS 0 +#define MXC_F_PWRMAN_INTEN_V1_2_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_V1_2_WARNING_POS)) +#define MXC_F_PWRMAN_INTEN_V1_8_WARNING_POS 1 +#define MXC_F_PWRMAN_INTEN_V1_8_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_V1_8_WARNING_POS)) +#define MXC_F_PWRMAN_INTEN_RTC_WARNING_POS 2 +#define MXC_F_PWRMAN_INTEN_RTC_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_RTC_WARNING_POS)) +#define MXC_F_PWRMAN_INTEN_VDDA_WARNING_POS 3 +#define MXC_F_PWRMAN_INTEN_VDDA_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_VDDA_WARNING_POS)) +#define MXC_F_PWRMAN_INTEN_VDDB_WARNING_POS 4 +#define MXC_F_PWRMAN_INTEN_VDDB_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_VDDB_WARNING_POS)) +#define MXC_F_PWRMAN_INTEN_VDDIO_WARNING_POS 5 +#define MXC_F_PWRMAN_INTEN_VDDIO_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_VDDIO_WARNING_POS)) +#define MXC_F_PWRMAN_INTEN_VDDIOH_WARNING_POS 6 +#define MXC_F_PWRMAN_INTEN_VDDIOH_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_INTEN_VDDIOH_WARNING_POS)) + +#define MXC_F_PWRMAN_SVM_EVENTS_V1_2_WARNING_POS 0 +#define MXC_F_PWRMAN_SVM_EVENTS_V1_2_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_V1_2_WARNING_POS)) +#define MXC_F_PWRMAN_SVM_EVENTS_V1_8_WARNING_POS 1 +#define MXC_F_PWRMAN_SVM_EVENTS_V1_8_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_V1_8_WARNING_POS)) +#define MXC_F_PWRMAN_SVM_EVENTS_RTC_WARNING_POS 2 +#define MXC_F_PWRMAN_SVM_EVENTS_RTC_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_RTC_WARNING_POS)) +#define MXC_F_PWRMAN_SVM_EVENTS_VDDA_WARNING_POS 3 +#define MXC_F_PWRMAN_SVM_EVENTS_VDDA_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_VDDA_WARNING_POS)) +#define MXC_F_PWRMAN_SVM_EVENTS_VDDB_WARNING_POS 4 +#define MXC_F_PWRMAN_SVM_EVENTS_VDDB_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_VDDB_WARNING_POS)) +#define MXC_F_PWRMAN_SVM_EVENTS_VDDIO_WARNING_POS 5 +#define MXC_F_PWRMAN_SVM_EVENTS_VDDIO_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_VDDIO_WARNING_POS)) +#define MXC_F_PWRMAN_SVM_EVENTS_VDDIOH_WARNING_POS 6 +#define MXC_F_PWRMAN_SVM_EVENTS_VDDIOH_WARNING ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_SVM_EVENTS_VDDIOH_WARNING_POS)) + +#define MXC_F_PWRMAN_WUD_CTRL_PAD_SELECT_POS 0 +#define MXC_F_PWRMAN_WUD_CTRL_PAD_SELECT ((uint32_t)(0x0000003FUL << MXC_F_PWRMAN_WUD_CTRL_PAD_SELECT_POS)) +#define MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS 8 +#define MXC_F_PWRMAN_WUD_CTRL_PAD_MODE ((uint32_t)(0x00000003UL << MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS)) +#define MXC_F_PWRMAN_WUD_CTRL_CLEAR_ALL_POS 12 +#define MXC_F_PWRMAN_WUD_CTRL_CLEAR_ALL ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_CTRL_CLEAR_ALL_POS)) +#define MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE_POS 16 +#define MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE_POS)) + +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO0_POS 0 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO0 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO0_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO1_POS 1 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO1 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO1_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO2_POS 2 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO2 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO2_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO3_POS 3 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO3 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO3_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO4_POS 4 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO4 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO4_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO5_POS 5 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO5 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO5_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO6_POS 6 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO6 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO6_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO7_POS 7 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO7 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO7_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO8_POS 8 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO8 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO8_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO9_POS 9 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO9 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO9_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO10_POS 10 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO10 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO10_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO11_POS 11 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO11 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO11_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO12_POS 12 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO12 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO12_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO13_POS 13 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO13 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO13_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO14_POS 14 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO14 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO14_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO15_POS 15 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO15 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO15_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO16_POS 16 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO16 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO16_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO17_POS 17 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO17 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO17_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO18_POS 18 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO18 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO18_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO19_POS 19 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO19 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO19_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO20_POS 20 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO20 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO20_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO21_POS 21 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO21 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO21_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO22_POS 22 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO22 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO22_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO23_POS 23 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO23 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO23_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO24_POS 24 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO24 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO24_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO25_POS 25 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO25 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO25_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO26_POS 26 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO26 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO26_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO27_POS 27 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO27 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO27_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO28_POS 28 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO28 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO28_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO29_POS 29 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO29 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO29_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO30_POS 30 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO30 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO30_POS)) +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO31_POS 31 +#define MXC_F_PWRMAN_WUD_SEEN0_GPIO31 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN0_GPIO31_POS)) + +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO32_POS 0 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO32 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO32_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO33_POS 1 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO33 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO33_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO34_POS 2 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO34 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO34_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO35_POS 3 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO35 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO35_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO36_POS 4 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO36 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO36_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO37_POS 5 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO37 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO37_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO38_POS 6 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO38 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO38_POS)) +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO39_POS 7 +#define MXC_F_PWRMAN_WUD_SEEN1_GPIO39 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_WUD_SEEN1_GPIO39_POS)) + +#define MXC_F_PWRMAN_PT_REGMAP_CTRL_ME02A_MODE_POS 0 +#define MXC_F_PWRMAN_PT_REGMAP_CTRL_ME02A_MODE ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PT_REGMAP_CTRL_ME02A_MODE_POS)) + +#define MXC_F_PWRMAN_BASE_PART_NUM_BASE_PART_NUMBER_POS 0 +#define MXC_F_PWRMAN_BASE_PART_NUM_BASE_PART_NUMBER ((uint32_t)(0x0000FFFFUL << MXC_F_PWRMAN_BASE_PART_NUM_BASE_PART_NUMBER_POS)) + +#define MXC_F_PWRMAN_MASK_ID0_REVISION_ID_POS 0 +#define MXC_F_PWRMAN_MASK_ID0_REVISION_ID ((uint32_t)(0x0000000FUL << MXC_F_PWRMAN_MASK_ID0_REVISION_ID_POS)) +#define MXC_F_PWRMAN_MASK_ID0_MASK_ID_POS 4 +#define MXC_F_PWRMAN_MASK_ID0_MASK_ID ((uint32_t)(0x0FFFFFFFUL << MXC_F_PWRMAN_MASK_ID0_MASK_ID_POS)) + +#define MXC_F_PWRMAN_MASK_ID1_MASK_ID_POS 0 +#define MXC_F_PWRMAN_MASK_ID1_MASK_ID ((uint32_t)(0x7FFFFFFFUL << MXC_F_PWRMAN_MASK_ID1_MASK_ID_POS)) +#define MXC_F_PWRMAN_MASK_ID1_MASK_ID_ENABLE_POS 31 +#define MXC_F_PWRMAN_MASK_ID1_MASK_ID_ENABLE ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_MASK_ID1_MASK_ID_ENABLE_POS)) + +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SSB_POS 0 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SSB ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_SSB_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIX_POS 1 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIX ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_SPIX_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_PMU_POS 2 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_PMU ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_PMU_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_USB_POS 3 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_USB ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_USB_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_CRC_POS 4 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_CRC ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_CRC_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TPU_POS 5 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TPU ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TPU_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_WATCHDOG0_POS 6 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_WATCHDOG0 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_WATCHDOG0_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_GPIO_POS 7 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_GPIO ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_GPIO_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER0_POS 8 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER0 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER0_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER1_POS 9 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER1 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER1_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER2_POS 10 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER2 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER2_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER3_POS 11 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER3 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER3_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER4_POS 12 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER4 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER4_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER5_POS 13 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER5 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_TIMER5_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_PULSE_TRAIN_POS 14 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_PULSE_TRAIN ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_PULSE_TRAIN_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_UART0_POS 15 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_UART0 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_UART0_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_UART1_POS 16 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_UART1 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_UART1_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_UART2_POS 17 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_UART2 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_UART2_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_I2CM0_POS 19 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_I2CM0 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_I2CM0_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_I2CM1_POS 20 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_I2CM1 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_I2CM1_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_I2CS_POS 22 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_I2CS ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_I2CS_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM0_POS 23 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM0 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM0_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM1_POS 24 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM1 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM1_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM2_POS 25 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM2 ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_SPIM2_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_OWM_POS 27 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_OWM ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_OWM_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_ADC_POS 28 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_ADC ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_ADC_POS)) +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIS_POS 29 +#define MXC_F_PWRMAN_PERIPHERAL_RESET_SPIS ((uint32_t)(0x00000001UL << MXC_F_PWRMAN_PERIPHERAL_RESET_SPIS_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_PWRMAN_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/pwrseq_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/pwrseq_regs.h new file mode 100644 index 0000000..cacbe13 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/pwrseq_regs.h @@ -0,0 +1,425 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_PWRSEQ_REGS_H_ +#define _MXC_PWRSEQ_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t reg0; /* 0x0000 Power Sequencer Control Register 0 */ + __IO uint32_t reg1; /* 0x0004 Power Sequencer Control Register 1 */ + __IO uint32_t reg2; /* 0x0008 Power Sequencer Control Register 2 */ + __IO uint32_t reg3; /* 0x000C Power Sequencer Control Register 3 */ + __IO uint32_t reg4; /* 0x0010 Power Sequencer Control Register 4 (Internal Test Only) */ + __IO uint32_t reg5; /* 0x0014 Power Sequencer Control Register 5 (Trim 0) */ + __IO uint32_t reg6; /* 0x0018 Power Sequencer Control Register 6 (Trim 1) */ + __IO uint32_t reg7; /* 0x001C Power Sequencer Control Register 7 (Trim 2) */ + __IO uint32_t flags; /* 0x0020 Power Sequencer Flags */ + __IO uint32_t msk_flags; /* 0x0024 Power Sequencer Flags Mask Register */ + __I uint32_t rsv028; /* 0x0028 */ + __IO uint32_t wr_protect; /* 0x002C Critical Setting Write Protect Register */ + __IO uint32_t retn_ctrl0; /* 0x0030 Retention Control Register 0 */ + __IO uint32_t retn_ctrl1; /* 0x0034 Retention Control Register 1 */ + __IO uint32_t pwr_misc; /* 0x0038 Power Misc Controls */ + __IO uint32_t rtc_ctrl2; /* 0x003C RTC Misc Controls */ +} mxc_pwrseq_regs_t; + + +/* + Register offsets for module PWRSEQ. +*/ + +#define MXC_R_PWRSEQ_OFFS_REG0 ((uint32_t)0x00000000UL) +#define MXC_R_PWRSEQ_OFFS_REG1 ((uint32_t)0x00000004UL) +#define MXC_R_PWRSEQ_OFFS_REG2 ((uint32_t)0x00000008UL) +#define MXC_R_PWRSEQ_OFFS_REG3 ((uint32_t)0x0000000CUL) +#define MXC_R_PWRSEQ_OFFS_REG4 ((uint32_t)0x00000010UL) +#define MXC_R_PWRSEQ_OFFS_REG5 ((uint32_t)0x00000014UL) +#define MXC_R_PWRSEQ_OFFS_REG6 ((uint32_t)0x00000018UL) +#define MXC_R_PWRSEQ_OFFS_REG7 ((uint32_t)0x0000001CUL) +#define MXC_R_PWRSEQ_OFFS_FLAGS ((uint32_t)0x00000020UL) +#define MXC_R_PWRSEQ_OFFS_MSK_FLAGS ((uint32_t)0x00000024UL) +#define MXC_R_PWRSEQ_OFFS_WR_PROTECT ((uint32_t)0x0000002CUL) +#define MXC_R_PWRSEQ_OFFS_RETN_CTRL0 ((uint32_t)0x00000030UL) +#define MXC_R_PWRSEQ_OFFS_RETN_CTRL1 ((uint32_t)0x00000034UL) +#define MXC_R_PWRSEQ_OFFS_PWR_MISC ((uint32_t)0x00000038UL) +#define MXC_R_PWRSEQ_OFFS_RTC_CTRL2 ((uint32_t)0x0000003CUL) + + +/* + Field positions and masks for module PWRSEQ. +*/ + +#define MXC_F_PWRSEQ_REG0_PWR_LP1_POS 0 +#define MXC_F_PWRSEQ_REG0_PWR_LP1 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_LP1_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT_POS 1 +#define MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_SYS_REBOOT_POS 2 +#define MXC_F_PWRSEQ_REG0_PWR_SYS_REBOOT ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_SYS_REBOOT_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_FLASHEN_RUN_POS 3 +#define MXC_F_PWRSEQ_REG0_PWR_FLASHEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_FLASHEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_FLASHEN_SLP_POS 4 +#define MXC_F_PWRSEQ_REG0_PWR_FLASHEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_FLASHEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_RETREGEN_RUN_POS 5 +#define MXC_F_PWRSEQ_REG0_PWR_RETREGEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_RETREGEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_RETREGEN_SLP_POS 6 +#define MXC_F_PWRSEQ_REG0_PWR_RETREGEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_RETREGEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN_POS 7 +#define MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_ROEN_SLP_POS 8 +#define MXC_F_PWRSEQ_REG0_PWR_ROEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_ROEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_NREN_RUN_POS 9 +#define MXC_F_PWRSEQ_REG0_PWR_NREN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_NREN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_NREN_SLP_POS 10 +#define MXC_F_PWRSEQ_REG0_PWR_NREN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_NREN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN_POS 11 +#define MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP_POS 12 +#define MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_SVM12EN_RUN_POS 13 +#define MXC_F_PWRSEQ_REG0_PWR_SVM12EN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_SVM12EN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_SVM18EN_RUN_POS 15 +#define MXC_F_PWRSEQ_REG0_PWR_SVM18EN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_SVM18EN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_SVMRTCEN_RUN_POS 17 +#define MXC_F_PWRSEQ_REG0_PWR_SVMRTCEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_SVMRTCEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_SVM_VDDB_RUN_POS 19 +#define MXC_F_PWRSEQ_REG0_PWR_SVM_VDDB_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_SVM_VDDB_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_SVMTVDD12EN_RUN_POS 21 +#define MXC_F_PWRSEQ_REG0_PWR_SVMTVDD12EN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_SVMTVDD12EN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_VDD12_SWEN_RUN_POS 23 +#define MXC_F_PWRSEQ_REG0_PWR_VDD12_SWEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_VDD12_SWEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_VDD12_SWEN_SLP_POS 24 +#define MXC_F_PWRSEQ_REG0_PWR_VDD12_SWEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_VDD12_SWEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_VDD18_SWEN_RUN_POS 25 +#define MXC_F_PWRSEQ_REG0_PWR_VDD18_SWEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_VDD18_SWEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_VDD18_SWEN_SLP_POS 26 +#define MXC_F_PWRSEQ_REG0_PWR_VDD18_SWEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_VDD18_SWEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_TVDD12_SWEN_RUN_POS 27 +#define MXC_F_PWRSEQ_REG0_PWR_TVDD12_SWEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_TVDD12_SWEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_TVDD12_SWEN_SLP_POS 28 +#define MXC_F_PWRSEQ_REG0_PWR_TVDD12_SWEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_TVDD12_SWEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN_POS 29 +#define MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_RCEN_SLP_POS 30 +#define MXC_F_PWRSEQ_REG0_PWR_RCEN_SLP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_RCEN_SLP_POS)) +#define MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT_POS 31 +#define MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT_POS)) + +#define MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH_POS 0 +#define MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH_POS 1 +#define MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_MBUS_GATE_POS 2 +#define MXC_F_PWRSEQ_REG1_PWR_MBUS_GATE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_MBUS_GATE_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_DISCHARGE_EN_POS 3 +#define MXC_F_PWRSEQ_REG1_PWR_DISCHARGE_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_DISCHARGE_EN_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_TVDD12_WELL_POS 4 +#define MXC_F_PWRSEQ_REG1_PWR_TVDD12_WELL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_TVDD12_WELL_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_SRAM_NWELL_SW_POS 5 +#define MXC_F_PWRSEQ_REG1_PWR_SRAM_NWELL_SW ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_SRAM_NWELL_SW_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_AUTO_MBUS_GATE_POS 6 +#define MXC_F_PWRSEQ_REG1_PWR_AUTO_MBUS_GATE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_AUTO_MBUS_GATE_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_SVM_VDDIO_EN_RUN_POS 8 +#define MXC_F_PWRSEQ_REG1_PWR_SVM_VDDIO_EN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_SVM_VDDIO_EN_RUN_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_SVM_VDDIOH_EN_RUN_POS 10 +#define MXC_F_PWRSEQ_REG1_PWR_SVM_VDDIOH_EN_RUN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_SVM_VDDIOH_EN_RUN_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_V12_POS 12 +#define MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_V12 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_V12_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_VRTC_POS 13 +#define MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_VRTC ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_VRTC_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_V18_POS 14 +#define MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_V18 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_RETREG_SRC_V18_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_VDDIO_EN_ISO_POR_POS 16 +#define MXC_F_PWRSEQ_REG1_PWR_VDDIO_EN_ISO_POR ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_VDDIO_EN_ISO_POR_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_VDDIOH_EN_ISO_POR_POS 17 +#define MXC_F_PWRSEQ_REG1_PWR_VDDIOH_EN_ISO_POR ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_VDDIOH_EN_ISO_POR_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_LP0_CORE_RESUME_EN_POS 18 +#define MXC_F_PWRSEQ_REG1_PWR_LP0_CORE_RESUME_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_LP0_CORE_RESUME_EN_POS)) +#define MXC_F_PWRSEQ_REG1_PWR_LP1_CORE_RSTN_EN_POS 19 +#define MXC_F_PWRSEQ_REG1_PWR_LP1_CORE_RSTN_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG1_PWR_LP1_CORE_RSTN_EN_POS)) + +#define MXC_F_PWRSEQ_REG2_PWR_VDD12_HYST_POS 0 +#define MXC_F_PWRSEQ_REG2_PWR_VDD12_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_VDD12_HYST_POS)) +#define MXC_F_PWRSEQ_REG2_PWR_VDD18_HYST_POS 2 +#define MXC_F_PWRSEQ_REG2_PWR_VDD18_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_VDD18_HYST_POS)) +#define MXC_F_PWRSEQ_REG2_PWR_VRTC_HYST_POS 4 +#define MXC_F_PWRSEQ_REG2_PWR_VRTC_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_VRTC_HYST_POS)) +#define MXC_F_PWRSEQ_REG2_PWR_VDDB_HYST_POS 6 +#define MXC_F_PWRSEQ_REG2_PWR_VDDB_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_VDDB_HYST_POS)) +#define MXC_F_PWRSEQ_REG2_PWR_TVDD12_HYST_POS 8 +#define MXC_F_PWRSEQ_REG2_PWR_TVDD12_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_TVDD12_HYST_POS)) +#define MXC_F_PWRSEQ_REG2_PWR_VDDIO_HYST_POS 10 +#define MXC_F_PWRSEQ_REG2_PWR_VDDIO_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_VDDIO_HYST_POS)) +#define MXC_F_PWRSEQ_REG2_PWR_VDDIOH_HYST_POS 12 +#define MXC_F_PWRSEQ_REG2_PWR_VDDIOH_HYST ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG2_PWR_VDDIOH_HYST_POS)) + +#define MXC_F_PWRSEQ_REG3_PWR_ROSEL_POS 0 +#define MXC_F_PWRSEQ_REG3_PWR_ROSEL ((uint32_t)(0x00000007UL << MXC_F_PWRSEQ_REG3_PWR_ROSEL_POS)) +#define MXC_F_PWRSEQ_REG3_PWR_FLTRROSEL_POS 3 +#define MXC_F_PWRSEQ_REG3_PWR_FLTRROSEL ((uint32_t)(0x00000007UL << MXC_F_PWRSEQ_REG3_PWR_FLTRROSEL_POS)) +#define MXC_F_PWRSEQ_REG3_PWR_SVM_CLK_MUX_POS 6 +#define MXC_F_PWRSEQ_REG3_PWR_SVM_CLK_MUX ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG3_PWR_SVM_CLK_MUX_POS)) +#define MXC_F_PWRSEQ_REG3_PWR_RO_CLK_MUX_POS 8 +#define MXC_F_PWRSEQ_REG3_PWR_RO_CLK_MUX ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG3_PWR_RO_CLK_MUX_POS)) +#define MXC_F_PWRSEQ_REG3_PWR_FAILSEL_POS 10 +#define MXC_F_PWRSEQ_REG3_PWR_FAILSEL ((uint32_t)(0x00000007UL << MXC_F_PWRSEQ_REG3_PWR_FAILSEL_POS)) +#define MXC_F_PWRSEQ_REG3_PWR_RO_DIV_POS 16 +#define MXC_F_PWRSEQ_REG3_PWR_RO_DIV ((uint32_t)(0x00000007UL << MXC_F_PWRSEQ_REG3_PWR_RO_DIV_POS)) +#define MXC_F_PWRSEQ_REG3_PWR_RC_DIV_POS 20 +#define MXC_F_PWRSEQ_REG3_PWR_RC_DIV ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG3_PWR_RC_DIV_POS)) + +#define MXC_F_PWRSEQ_REG4_PWR_TM_PS_2_GPIO_POS 0 +#define MXC_F_PWRSEQ_REG4_PWR_TM_PS_2_GPIO ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_TM_PS_2_GPIO_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_TM_FAST_TIMERS_POS 1 +#define MXC_F_PWRSEQ_REG4_PWR_TM_FAST_TIMERS ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_TM_FAST_TIMERS_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_USB_DIS_COMP_POS 3 +#define MXC_F_PWRSEQ_REG4_PWR_USB_DIS_COMP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_USB_DIS_COMP_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_RO_TSTCLK_EN_POS 4 +#define MXC_F_PWRSEQ_REG4_PWR_RO_TSTCLK_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_RO_TSTCLK_EN_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_NR_CLK_GATE_EN_POS 5 +#define MXC_F_PWRSEQ_REG4_PWR_NR_CLK_GATE_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_NR_CLK_GATE_EN_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_EXT_CLK_IN_EN_POS 6 +#define MXC_F_PWRSEQ_REG4_PWR_EXT_CLK_IN_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_EXT_CLK_IN_EN_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_PSEQ_32K_EN_POS 7 +#define MXC_F_PWRSEQ_REG4_PWR_PSEQ_32K_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_PSEQ_32K_EN_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_RTC_MUX_POS 8 +#define MXC_F_PWRSEQ_REG4_PWR_RTC_MUX ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_RTC_MUX_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_RETREG_TRIM_LP1_EN_POS 9 +#define MXC_F_PWRSEQ_REG4_PWR_RETREG_TRIM_LP1_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_RETREG_TRIM_LP1_EN_POS)) +#define MXC_F_PWRSEQ_REG4_PWR_USB_XVR_TST_EN_POS 10 +#define MXC_F_PWRSEQ_REG4_PWR_USB_XVR_TST_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG4_PWR_USB_XVR_TST_EN_POS)) + +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_SVM_BG_POS 0 +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_SVM_BG ((uint32_t)(0x000001FFUL << MXC_F_PWRSEQ_REG5_PWR_TRIM_SVM_BG_POS)) +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_BIAS_POS 9 +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_BIAS ((uint32_t)(0x0000003FUL << MXC_F_PWRSEQ_REG5_PWR_TRIM_BIAS_POS)) +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_RETREG_5_0_POS 15 +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_RETREG_5_0 ((uint32_t)(0x0000003FUL << MXC_F_PWRSEQ_REG5_PWR_TRIM_RETREG_5_0_POS)) +#define MXC_F_PWRSEQ_REG5_PWR_RTC_TRIM_POS 21 +#define MXC_F_PWRSEQ_REG5_PWR_RTC_TRIM ((uint32_t)(0x0000000FUL << MXC_F_PWRSEQ_REG5_PWR_RTC_TRIM_POS)) +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_RETREG_7_6_POS 25 +#define MXC_F_PWRSEQ_REG5_PWR_TRIM_RETREG_7_6 ((uint32_t)(0x00000003UL << MXC_F_PWRSEQ_REG5_PWR_TRIM_RETREG_7_6_POS)) + +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_BIAS_POS 0 +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_BIAS ((uint32_t)(0x00000007UL << MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_BIAS_POS)) +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_PM_RES_POS 3 +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_PM_RES ((uint32_t)(0x0000000FUL << MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_PM_RES_POS)) +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_DM_RES_POS 7 +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_DM_RES ((uint32_t)(0x0000000FUL << MXC_F_PWRSEQ_REG6_PWR_TRIM_USB_DM_RES_POS)) +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF_POS 11 +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF ((uint32_t)(0x000001FFUL << MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF_POS)) +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_CRYPTO_OSC_POS 20 +#define MXC_F_PWRSEQ_REG6_PWR_TRIM_CRYPTO_OSC ((uint32_t)(0x000001FFUL << MXC_F_PWRSEQ_REG6_PWR_TRIM_CRYPTO_OSC_POS)) + +#define MXC_F_PWRSEQ_REG7_PWR_FLASH_PD_LOOKAHEAD_POS 0 +#define MXC_F_PWRSEQ_REG7_PWR_FLASH_PD_LOOKAHEAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_REG7_PWR_FLASH_PD_LOOKAHEAD_POS)) +#define MXC_F_PWRSEQ_REG7_PWR_TRIM_RC_POS 16 +#define MXC_F_PWRSEQ_REG7_PWR_TRIM_RC ((uint32_t)(0x0000FFFFUL << MXC_F_PWRSEQ_REG7_PWR_TRIM_RC_POS)) + +#define MXC_F_PWRSEQ_FLAGS_PWR_FIRST_BOOT_POS 0 +#define MXC_F_PWRSEQ_FLAGS_PWR_FIRST_BOOT ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_FIRST_BOOT_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_SYS_REBOOT_POS 1 +#define MXC_F_PWRSEQ_FLAGS_PWR_SYS_REBOOT ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_SYS_REBOOT_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_POWER_FAIL_POS 2 +#define MXC_F_PWRSEQ_FLAGS_PWR_POWER_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_POWER_FAIL_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_BOOT_FAIL_POS 3 +#define MXC_F_PWRSEQ_FLAGS_PWR_BOOT_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_BOOT_FAIL_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_FLASH_DISCHARGE_POS 4 +#define MXC_F_PWRSEQ_FLAGS_PWR_FLASH_DISCHARGE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_FLASH_DISCHARGE_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_IOWAKEUP_POS 5 +#define MXC_F_PWRSEQ_FLAGS_PWR_IOWAKEUP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_IOWAKEUP_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_VDD12_RST_BAD_POS 6 +#define MXC_F_PWRSEQ_FLAGS_PWR_VDD12_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_VDD12_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_VDD18_RST_BAD_POS 7 +#define MXC_F_PWRSEQ_FLAGS_PWR_VDD18_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_VDD18_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_VRTC_RST_BAD_POS 8 +#define MXC_F_PWRSEQ_FLAGS_PWR_VRTC_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_VRTC_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_VDDB_RST_BAD_POS 9 +#define MXC_F_PWRSEQ_FLAGS_PWR_VDDB_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_VDDB_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_TVDD12_RST_BAD_POS 10 +#define MXC_F_PWRSEQ_FLAGS_PWR_TVDD12_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_TVDD12_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_POR18Z_FAIL_LATCH_POS 11 +#define MXC_F_PWRSEQ_FLAGS_PWR_POR18Z_FAIL_LATCH ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_POR18Z_FAIL_LATCH_POS)) +#define MXC_F_PWRSEQ_FLAGS_RTC_CMPR0_POS 12 +#define MXC_F_PWRSEQ_FLAGS_RTC_CMPR0 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_RTC_CMPR0_POS)) +#define MXC_F_PWRSEQ_FLAGS_RTC_CMPR1_POS 13 +#define MXC_F_PWRSEQ_FLAGS_RTC_CMPR1 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_RTC_CMPR1_POS)) +#define MXC_F_PWRSEQ_FLAGS_RTC_PRESCALE_CMP_POS 14 +#define MXC_F_PWRSEQ_FLAGS_RTC_PRESCALE_CMP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_RTC_PRESCALE_CMP_POS)) +#define MXC_F_PWRSEQ_FLAGS_RTC_ROLLOVER_POS 15 +#define MXC_F_PWRSEQ_FLAGS_RTC_ROLLOVER ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_RTC_ROLLOVER_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_USB_PLUG_WAKEUP_POS 16 +#define MXC_F_PWRSEQ_FLAGS_PWR_USB_PLUG_WAKEUP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_USB_PLUG_WAKEUP_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_USB_REMOVE_WAKEUP_POS 17 +#define MXC_F_PWRSEQ_FLAGS_PWR_USB_REMOVE_WAKEUP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_USB_REMOVE_WAKEUP_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_TVDD12_BAD_POS 18 +#define MXC_F_PWRSEQ_FLAGS_PWR_TVDD12_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_TVDD12_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_VDDIO_RST_BAD_POS 19 +#define MXC_F_PWRSEQ_FLAGS_PWR_VDDIO_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_VDDIO_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_VDDIOH_RST_BAD_POS 20 +#define MXC_F_PWRSEQ_FLAGS_PWR_VDDIOH_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_VDDIOH_RST_BAD_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_ISOZ_VDDIO_FAIL_POS 21 +#define MXC_F_PWRSEQ_FLAGS_PWR_ISOZ_VDDIO_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_ISOZ_VDDIO_FAIL_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_ISOZ_VDDIOH_FAIL_POS 22 +#define MXC_F_PWRSEQ_FLAGS_PWR_ISOZ_VDDIOH_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_ISOZ_VDDIOH_FAIL_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_NANORING_WAKEUP_FLAG_POS 23 +#define MXC_F_PWRSEQ_FLAGS_PWR_NANORING_WAKEUP_FLAG ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_NANORING_WAKEUP_FLAG_POS)) +#define MXC_F_PWRSEQ_FLAGS_PWR_WATCHDOG_RSTN_FLAG_POS 24 +#define MXC_F_PWRSEQ_FLAGS_PWR_WATCHDOG_RSTN_FLAG ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_FLAGS_PWR_WATCHDOG_RSTN_FLAG_POS)) + +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_SYS_REBOOT_POS 1 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_SYS_REBOOT ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_SYS_REBOOT_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_POWER_FAIL_POS 2 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_POWER_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_POWER_FAIL_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_BOOT_FAIL_POS 3 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_BOOT_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_BOOT_FAIL_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_FLASH_DISCHARGE_POS 4 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_FLASH_DISCHARGE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_FLASH_DISCHARGE_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_IOWAKEUP_POS 5 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_IOWAKEUP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_IOWAKEUP_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDD12_RST_BAD_POS 6 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDD12_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDD12_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDD18_RST_BAD_POS 7 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDD18_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDD18_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VRTC_RST_BAD_POS 8 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VRTC_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_VRTC_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDB_RST_BAD_POS 9 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDB_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDB_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_TVDD12_RST_BAD_POS 10 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_TVDD12_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_TVDD12_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_POR18Z_FAIL_LATCH_POS 11 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_POR18Z_FAIL_LATCH ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_POR18Z_FAIL_LATCH_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR0_POS 12 +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR0 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR0_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR1_POS 13 +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR1 ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR1_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_PRESCALE_CMP_POS 14 +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_PRESCALE_CMP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_RTC_PRESCALE_CMP_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_ROLLOVER_POS 15 +#define MXC_F_PWRSEQ_MSK_FLAGS_RTC_ROLLOVER ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_RTC_ROLLOVER_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_PLUG_WAKEUP_POS 16 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_PLUG_WAKEUP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_PLUG_WAKEUP_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_REMOVE_WAKEUP_POS 17 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_REMOVE_WAKEUP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_REMOVE_WAKEUP_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_TVDD12_BAD_POS 18 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_TVDD12_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_TVDD12_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDIO_RST_BAD_POS 19 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDIO_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDIO_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDIOH_RST_BAD_POS 20 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDIOH_RST_BAD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_VDDIOH_RST_BAD_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_ISOZ_VDDIO_FAIL_POS 21 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_ISOZ_VDDIO_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_ISOZ_VDDIO_FAIL_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_ISOZ_VDDIOH_FAIL_POS 22 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_ISOZ_VDDIOH_FAIL ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_ISOZ_VDDIOH_FAIL_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_NANORING_WAKEUP_FLAG_POS 23 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_NANORING_WAKEUP_FLAG ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_NANORING_WAKEUP_FLAG_POS)) +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_WATCHDOG_RSTN_FLAG_POS 24 +#define MXC_F_PWRSEQ_MSK_FLAGS_PWR_WATCHDOG_RSTN_FLAG ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_MSK_FLAGS_PWR_WATCHDOG_RSTN_FLAG_POS)) + +#define MXC_F_PWRSEQ_WR_PROTECT_BYPASS_SEQ_POS 0 +#define MXC_F_PWRSEQ_WR_PROTECT_BYPASS_SEQ ((uint32_t)(0x000000FFUL << MXC_F_PWRSEQ_WR_PROTECT_BYPASS_SEQ_POS)) +#define MXC_F_PWRSEQ_WR_PROTECT_RTC_SEQ_POS 8 +#define MXC_F_PWRSEQ_WR_PROTECT_RTC_SEQ ((uint32_t)(0x000000FFUL << MXC_F_PWRSEQ_WR_PROTECT_RTC_SEQ_POS)) +#define MXC_F_PWRSEQ_WR_PROTECT_RTC_POS 28 +#define MXC_F_PWRSEQ_WR_PROTECT_RTC ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_WR_PROTECT_RTC_POS)) +#define MXC_F_PWRSEQ_WR_PROTECT_INFO_POS 29 +#define MXC_F_PWRSEQ_WR_PROTECT_INFO ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_WR_PROTECT_INFO_POS)) +#define MXC_F_PWRSEQ_WR_PROTECT_BYPASS_POS 30 +#define MXC_F_PWRSEQ_WR_PROTECT_BYPASS ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_WR_PROTECT_BYPASS_POS)) +#define MXC_F_PWRSEQ_WR_PROTECT_WP_POS 31 +#define MXC_F_PWRSEQ_WR_PROTECT_WP ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_WR_PROTECT_WP_POS)) + +#define MXC_F_PWRSEQ_RETN_CTRL0_RETN_CTRL_EN_POS 0 +#define MXC_F_PWRSEQ_RETN_CTRL0_RETN_CTRL_EN ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RETN_CTRL0_RETN_CTRL_EN_POS)) +#define MXC_F_PWRSEQ_RETN_CTRL0_RC_REL_CCG_EARLY_POS 1 +#define MXC_F_PWRSEQ_RETN_CTRL0_RC_REL_CCG_EARLY ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RETN_CTRL0_RC_REL_CCG_EARLY_POS)) +#define MXC_F_PWRSEQ_RETN_CTRL0_RC_USE_FLC_TWK_POS 2 +#define MXC_F_PWRSEQ_RETN_CTRL0_RC_USE_FLC_TWK ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RETN_CTRL0_RC_USE_FLC_TWK_POS)) +#define MXC_F_PWRSEQ_RETN_CTRL0_RC_POLL_FLASH_POS 3 +#define MXC_F_PWRSEQ_RETN_CTRL0_RC_POLL_FLASH ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RETN_CTRL0_RC_POLL_FLASH_POS)) +#define MXC_F_PWRSEQ_RETN_CTRL0_RESTORE_OVERRIDE_POS 4 +#define MXC_F_PWRSEQ_RETN_CTRL0_RESTORE_OVERRIDE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RETN_CTRL0_RESTORE_OVERRIDE_POS)) + +#define MXC_F_PWRSEQ_RETN_CTRL1_RC_TWK_POS 0 +#define MXC_F_PWRSEQ_RETN_CTRL1_RC_TWK ((uint32_t)(0x0000000FUL << MXC_F_PWRSEQ_RETN_CTRL1_RC_TWK_POS)) +#define MXC_F_PWRSEQ_RETN_CTRL1_SRAM_FMS_POS 4 +#define MXC_F_PWRSEQ_RETN_CTRL1_SRAM_FMS ((uint32_t)(0x0000000FUL << MXC_F_PWRSEQ_RETN_CTRL1_SRAM_FMS_POS)) + +#define MXC_F_PWRSEQ_PWR_MISC_INVERT_4_MASK_BITS_POS 0 +#define MXC_F_PWRSEQ_PWR_MISC_INVERT_4_MASK_BITS ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_PWR_MISC_INVERT_4_MASK_BITS_POS)) + +#define MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_RD_POS 0 +#define MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_RD ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_RD_POS)) +#define MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_WR_POS 1 +#define MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_WR ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_WR_POS)) +#define MXC_F_PWRSEQ_RTC_CTRL2_TIMER_AUTO_UPDATE_POS 2 +#define MXC_F_PWRSEQ_RTC_CTRL2_TIMER_AUTO_UPDATE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RTC_CTRL2_TIMER_AUTO_UPDATE_POS)) +#define MXC_F_PWRSEQ_RTC_CTRL2_SSB_PERFORMANCE_POS 3 +#define MXC_F_PWRSEQ_RTC_CTRL2_SSB_PERFORMANCE ((uint32_t)(0x00000001UL << MXC_F_PWRSEQ_RTC_CTRL2_SSB_PERFORMANCE_POS)) +#define MXC_F_PWRSEQ_RTC_CTRL2_CFG_LOCK_POS 24 +#define MXC_F_PWRSEQ_RTC_CTRL2_CFG_LOCK ((uint32_t)(0x000000FFUL << MXC_F_PWRSEQ_RTC_CTRL2_CFG_LOCK_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_PWRSEQ_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/rtc_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/rtc_regs.h new file mode 100644 index 0000000..323e77d --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/rtc_regs.h @@ -0,0 +1,268 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_RTC_REGS_H_ +#define _MXC_RTC_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 RTC Timer Control */ + __IO uint32_t timer; /* 0x0004 RTC Timer Count Value */ + __IO uint32_t comp[2]; /* 0x0008-0x000C RTC Time of Day Alarm [0..1] Compare Register */ + __IO uint32_t flags; /* 0x0010 CPU Interrupt and RTC Domain Flags */ + __IO uint32_t snz_val; /* 0x0014 RTC Timer Alarm Snooze Value */ + __IO uint32_t inten; /* 0x0018 Interrupt Enable Controls */ + __IO uint32_t prescale; /* 0x001C RTC Timer Prescale Setting */ + __I uint32_t rsv020; /* 0x0020 */ + __IO uint32_t prescale_mask; /* 0x0024 RTC Timer Prescale Compare Mask */ + __IO uint32_t trim_ctrl; /* 0x0028 RTC Timer Trim Controls */ + __IO uint32_t trim_value; /* 0x002C RTC Timer Trim Adjustment Interval */ +} mxc_rtctmr_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t nano_cntr; /* 0x0000 Nano Oscillator Counter Read Register */ + __IO uint32_t clk_ctrl; /* 0x0004 RTC Clock Control Settings */ + __I uint32_t rsv008; /* 0x0008 */ + __IO uint32_t osc_ctrl; /* 0x000C RTC Oscillator Control */ +} mxc_rtccfg_regs_t; + + +/* + Register offsets for module RTC. +*/ + +#define MXC_R_RTCTMR_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_RTCTMR_OFFS_TIMER ((uint32_t)0x00000004UL) +#define MXC_R_RTCTMR_OFFS_COMP0 ((uint32_t)0x00000008UL) +#define MXC_R_RTCTMR_OFFS_COMP1 ((uint32_t)0x0000000CUL) +#define MXC_R_RTCTMR_OFFS_FLAGS ((uint32_t)0x00000010UL) +#define MXC_R_RTCTMR_OFFS_SNZ_VAL ((uint32_t)0x00000014UL) +#define MXC_R_RTCTMR_OFFS_INTEN ((uint32_t)0x00000018UL) +#define MXC_R_RTCTMR_OFFS_PRESCALE ((uint32_t)0x0000001CUL) +#define MXC_R_RTCTMR_OFFS_PRESCALE_MASK ((uint32_t)0x00000024UL) +#define MXC_R_RTCTMR_OFFS_TRIM_CTRL ((uint32_t)0x00000028UL) +#define MXC_R_RTCTMR_OFFS_TRIM_VALUE ((uint32_t)0x0000002CUL) +#define MXC_R_RTCCFG_OFFS_NANO_CNTR ((uint32_t)0x00000000UL) +#define MXC_R_RTCCFG_OFFS_CLK_CTRL ((uint32_t)0x00000004UL) +#define MXC_R_RTCCFG_OFFS_OSC_CTRL ((uint32_t)0x0000000CUL) + + +/* + Field positions and masks for module RTC. +*/ + +#define MXC_F_RTC_CTRL_ENABLE_POS 0 +#define MXC_F_RTC_CTRL_ENABLE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_ENABLE_POS)) +#define MXC_F_RTC_CTRL_CLEAR_POS 1 +#define MXC_F_RTC_CTRL_CLEAR ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_CLEAR_POS)) +#define MXC_F_RTC_CTRL_PENDING_POS 2 +#define MXC_F_RTC_CTRL_PENDING ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_PENDING_POS)) +#define MXC_F_RTC_CTRL_USE_ASYNC_FLAGS_POS 3 +#define MXC_F_RTC_CTRL_USE_ASYNC_FLAGS ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_USE_ASYNC_FLAGS_POS)) +#define MXC_F_RTC_CTRL_AGGRESSIVE_RST_POS 4 +#define MXC_F_RTC_CTRL_AGGRESSIVE_RST ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_AGGRESSIVE_RST_POS)) +#define MXC_F_RTC_CTRL_AUTO_UPDATE_DISABLE_POS 5 +#define MXC_F_RTC_CTRL_AUTO_UPDATE_DISABLE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_AUTO_UPDATE_DISABLE_POS)) +#define MXC_F_RTC_CTRL_SNOOZE_ENABLE_POS 6 +#define MXC_F_RTC_CTRL_SNOOZE_ENABLE ((uint32_t)(0x00000003UL << MXC_F_RTC_CTRL_SNOOZE_ENABLE_POS)) +#define MXC_F_RTC_CTRL_RTC_ENABLE_ACTIVE_POS 16 +#define MXC_F_RTC_CTRL_RTC_ENABLE_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_RTC_ENABLE_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_OSC_GOTO_LOW_ACTIVE_POS 17 +#define MXC_F_RTC_CTRL_OSC_GOTO_LOW_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_OSC_GOTO_LOW_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_OSC_FRCE_SM_EN_ACTIVE_POS 18 +#define MXC_F_RTC_CTRL_OSC_FRCE_SM_EN_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_OSC_FRCE_SM_EN_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_OSC_FRCE_ST_ACTIVE_POS 19 +#define MXC_F_RTC_CTRL_OSC_FRCE_ST_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_OSC_FRCE_ST_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_RTC_SET_ACTIVE_POS 20 +#define MXC_F_RTC_CTRL_RTC_SET_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_RTC_SET_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_RTC_CLR_ACTIVE_POS 21 +#define MXC_F_RTC_CTRL_RTC_CLR_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_RTC_CLR_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_ROLLOVER_CLR_ACTIVE_POS 22 +#define MXC_F_RTC_CTRL_ROLLOVER_CLR_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_ROLLOVER_CLR_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_PRESCALE_CMPR0_ACTIVE_POS 23 +#define MXC_F_RTC_CTRL_PRESCALE_CMPR0_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_PRESCALE_CMPR0_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_PRESCALE_UPDATE_ACTIVE_POS 24 +#define MXC_F_RTC_CTRL_PRESCALE_UPDATE_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_PRESCALE_UPDATE_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_CMPR1_CLR_ACTIVE_POS 25 +#define MXC_F_RTC_CTRL_CMPR1_CLR_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_CMPR1_CLR_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_CMPR0_CLR_ACTIVE_POS 26 +#define MXC_F_RTC_CTRL_CMPR0_CLR_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_CMPR0_CLR_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_TRIM_ENABLE_ACTIVE_POS 27 +#define MXC_F_RTC_CTRL_TRIM_ENABLE_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_TRIM_ENABLE_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_TRIM_SLOWER_ACTIVE_POS 28 +#define MXC_F_RTC_CTRL_TRIM_SLOWER_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_TRIM_SLOWER_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_TRIM_CLR_ACTIVE_POS 29 +#define MXC_F_RTC_CTRL_TRIM_CLR_ACTIVE ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_TRIM_CLR_ACTIVE_POS)) +#define MXC_F_RTC_CTRL_ACTIVE_TRANS_0_POS 30 +#define MXC_F_RTC_CTRL_ACTIVE_TRANS_0 ((uint32_t)(0x00000001UL << MXC_F_RTC_CTRL_ACTIVE_TRANS_0_POS)) + +#define MXC_F_RTC_FLAGS_COMP0_POS 0 +#define MXC_F_RTC_FLAGS_COMP0 ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_COMP0_POS)) +#define MXC_F_RTC_FLAGS_COMP1_POS 1 +#define MXC_F_RTC_FLAGS_COMP1 ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_COMP1_POS)) +#define MXC_F_RTC_FLAGS_PRESCALE_COMP_POS 2 +#define MXC_F_RTC_FLAGS_PRESCALE_COMP ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_PRESCALE_COMP_POS)) +#define MXC_F_RTC_FLAGS_OVERFLOW_POS 3 +#define MXC_F_RTC_FLAGS_OVERFLOW ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_OVERFLOW_POS)) +#define MXC_F_RTC_FLAGS_TRIM_POS 4 +#define MXC_F_RTC_FLAGS_TRIM ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_TRIM_POS)) +#define MXC_F_RTC_FLAGS_SNOOZE_POS 5 +#define MXC_F_RTC_FLAGS_SNOOZE ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_SNOOZE_POS)) +#define MXC_F_RTC_FLAGS_COMP0_FLAG_A_POS 8 +#define MXC_F_RTC_FLAGS_COMP0_FLAG_A ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_COMP0_FLAG_A_POS)) +#define MXC_F_RTC_FLAGS_COMP1_FLAG_A_POS 9 +#define MXC_F_RTC_FLAGS_COMP1_FLAG_A ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_COMP1_FLAG_A_POS)) +#define MXC_F_RTC_FLAGS_PRESCL_FLAG_A_POS 10 +#define MXC_F_RTC_FLAGS_PRESCL_FLAG_A ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_PRESCL_FLAG_A_POS)) +#define MXC_F_RTC_FLAGS_OVERFLOW_FLAG_A_POS 11 +#define MXC_F_RTC_FLAGS_OVERFLOW_FLAG_A ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_OVERFLOW_FLAG_A_POS)) +#define MXC_F_RTC_FLAGS_TRIM_FLAG_A_POS 12 +#define MXC_F_RTC_FLAGS_TRIM_FLAG_A ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_TRIM_FLAG_A_POS)) +#define MXC_F_RTC_FLAGS_SNOOZE_A_POS 28 +#define MXC_F_RTC_FLAGS_SNOOZE_A ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_SNOOZE_A_POS)) +#define MXC_F_RTC_FLAGS_SNOOZE_B_POS 29 +#define MXC_F_RTC_FLAGS_SNOOZE_B ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_SNOOZE_B_POS)) +#define MXC_F_RTC_FLAGS_ASYNC_CLR_FLAGS_POS 31 +#define MXC_F_RTC_FLAGS_ASYNC_CLR_FLAGS ((uint32_t)(0x00000001UL << MXC_F_RTC_FLAGS_ASYNC_CLR_FLAGS_POS)) + +#define MXC_F_RTC_SNZ_VAL_VALUE_POS 0 +#define MXC_F_RTC_SNZ_VAL_VALUE ((uint32_t)(0x000003FFUL << MXC_F_RTC_SNZ_VAL_VALUE_POS)) + +#define MXC_F_RTC_INTEN_COMP0_POS 0 +#define MXC_F_RTC_INTEN_COMP0 ((uint32_t)(0x00000001UL << MXC_F_RTC_INTEN_COMP0_POS)) +#define MXC_F_RTC_INTEN_COMP1_POS 1 +#define MXC_F_RTC_INTEN_COMP1 ((uint32_t)(0x00000001UL << MXC_F_RTC_INTEN_COMP1_POS)) +#define MXC_F_RTC_INTEN_PRESCALE_COMP_POS 2 +#define MXC_F_RTC_INTEN_PRESCALE_COMP ((uint32_t)(0x00000001UL << MXC_F_RTC_INTEN_PRESCALE_COMP_POS)) +#define MXC_F_RTC_INTEN_OVERFLOW_POS 3 +#define MXC_F_RTC_INTEN_OVERFLOW ((uint32_t)(0x00000001UL << MXC_F_RTC_INTEN_OVERFLOW_POS)) +#define MXC_F_RTC_INTEN_TRIM_POS 4 +#define MXC_F_RTC_INTEN_TRIM ((uint32_t)(0x00000001UL << MXC_F_RTC_INTEN_TRIM_POS)) + +#define MXC_F_RTC_PRESCALE_PRESCALE_POS 0 +#define MXC_F_RTC_PRESCALE_PRESCALE ((uint32_t)(0x0000000FUL << MXC_F_RTC_PRESCALE_PRESCALE_POS)) + +#define MXC_F_RTC_PRESCALE_MASK_PRESCALE_MASK_POS 0 +#define MXC_F_RTC_PRESCALE_MASK_PRESCALE_MASK ((uint32_t)(0x0000000FUL << MXC_F_RTC_PRESCALE_MASK_PRESCALE_MASK_POS)) + +#define MXC_F_RTC_TRIM_CTRL_TRIM_ENABLE_R_POS 0 +#define MXC_F_RTC_TRIM_CTRL_TRIM_ENABLE_R ((uint32_t)(0x00000001UL << MXC_F_RTC_TRIM_CTRL_TRIM_ENABLE_R_POS)) +#define MXC_F_RTC_TRIM_CTRL_TRIM_FASTER_OVR_R_POS 1 +#define MXC_F_RTC_TRIM_CTRL_TRIM_FASTER_OVR_R ((uint32_t)(0x00000001UL << MXC_F_RTC_TRIM_CTRL_TRIM_FASTER_OVR_R_POS)) +#define MXC_F_RTC_TRIM_CTRL_TRIM_SLOWER_R_POS 2 +#define MXC_F_RTC_TRIM_CTRL_TRIM_SLOWER_R ((uint32_t)(0x00000001UL << MXC_F_RTC_TRIM_CTRL_TRIM_SLOWER_R_POS)) + +#define MXC_F_RTC_TRIM_VALUE_TRIM_VALUE_POS 0 +#define MXC_F_RTC_TRIM_VALUE_TRIM_VALUE ((uint32_t)(0x0003FFFFUL << MXC_F_RTC_TRIM_VALUE_TRIM_VALUE_POS)) +#define MXC_F_RTC_TRIM_VALUE_TRIM_SLOWER_CONTROL_POS 18 +#define MXC_F_RTC_TRIM_VALUE_TRIM_SLOWER_CONTROL ((uint32_t)(0x00000001UL << MXC_F_RTC_TRIM_VALUE_TRIM_SLOWER_CONTROL_POS)) + +#define MXC_F_RTC_NANO_CNTR_NANORING_COUNTER_POS 0 +#define MXC_F_RTC_NANO_CNTR_NANORING_COUNTER ((uint32_t)(0x0000FFFFUL << MXC_F_RTC_NANO_CNTR_NANORING_COUNTER_POS)) + +#define MXC_F_RTC_CLK_CTRL_OSC1_EN_POS 0 +#define MXC_F_RTC_CLK_CTRL_OSC1_EN ((uint32_t)(0x00000001UL << MXC_F_RTC_CLK_CTRL_OSC1_EN_POS)) +#define MXC_F_RTC_CLK_CTRL_OSC2_EN_POS 1 +#define MXC_F_RTC_CLK_CTRL_OSC2_EN ((uint32_t)(0x00000001UL << MXC_F_RTC_CLK_CTRL_OSC2_EN_POS)) +#define MXC_F_RTC_CLK_CTRL_NANO_EN_POS 2 +#define MXC_F_RTC_CLK_CTRL_NANO_EN ((uint32_t)(0x00000001UL << MXC_F_RTC_CLK_CTRL_NANO_EN_POS)) + +#define MXC_F_RTC_OSC_CTRL_OSC_BYPASS_POS 0 +#define MXC_F_RTC_OSC_CTRL_OSC_BYPASS ((uint32_t)(0x00000001UL << MXC_F_RTC_OSC_CTRL_OSC_BYPASS_POS)) +#define MXC_F_RTC_OSC_CTRL_OSC_DISABLE_R_POS 1 +#define MXC_F_RTC_OSC_CTRL_OSC_DISABLE_R ((uint32_t)(0x00000001UL << MXC_F_RTC_OSC_CTRL_OSC_DISABLE_R_POS)) +#define MXC_F_RTC_OSC_CTRL_OSC_DISABLE_SEL_POS 2 +#define MXC_F_RTC_OSC_CTRL_OSC_DISABLE_SEL ((uint32_t)(0x00000001UL << MXC_F_RTC_OSC_CTRL_OSC_DISABLE_SEL_POS)) +#define MXC_F_RTC_OSC_CTRL_OSC_DISABLE_O_POS 3 +#define MXC_F_RTC_OSC_CTRL_OSC_DISABLE_O ((uint32_t)(0x00000001UL << MXC_F_RTC_OSC_CTRL_OSC_DISABLE_O_POS)) +#define MXC_F_RTC_OSC_CTRL_OSC_WARMUP_ENABLE_POS 14 +#define MXC_F_RTC_OSC_CTRL_OSC_WARMUP_ENABLE ((uint32_t)(0x00000001UL << MXC_F_RTC_OSC_CTRL_OSC_WARMUP_ENABLE_POS)) + +/* + Field values +*/ + +#define MXC_V_RTC_CTRL_SNOOZE_DISABLE ((uint32_t)(0x00000000UL)) +#define MXC_V_RTC_CTRL_SNOOZE_MODE_A ((uint32_t)(0x00000001UL)) +#define MXC_V_RTC_CTRL_SNOOZE_MODE_B ((uint32_t)(0x00000002UL)) + +#define MXC_V_RTC_PRESCALE_DIV_2_0 ((uint32_t)(0x00000000UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_1 ((uint32_t)(0x00000001UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_2 ((uint32_t)(0x00000002UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_3 ((uint32_t)(0x00000003UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_4 ((uint32_t)(0x00000004UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_5 ((uint32_t)(0x00000005UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_6 ((uint32_t)(0x00000006UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_7 ((uint32_t)(0x00000007UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_8 ((uint32_t)(0x00000008UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_9 ((uint32_t)(0x00000009UL)) +#define MXC_V_RTC_PRESCALE_DIV_2_10 ((uint32_t)(0x0000000AUL)) +#define MXC_V_RTC_PRESCALE_DIV_2_11 ((uint32_t)(0x0000000BUL)) +#define MXC_V_RTC_PRESCALE_DIV_2_12 ((uint32_t)(0x0000000CUL)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_RTC_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/spim_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/spim_regs.h new file mode 100644 index 0000000..b86e354 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/spim_regs.h @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_SPIM_REGS_H_ +#define _MXC_SPIM_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t mstr_cfg; /* 0x0000 SPI Master Configuration Register */ + __IO uint32_t ss_sr_polarity; /* 0x0004 SPI Master Polarity Control for SS and SR Signals */ + __IO uint32_t gen_ctrl; /* 0x0008 SPI Master General Control Register */ + __IO uint32_t fifo_ctrl; /* 0x000C SPI Master FIFO Control Register */ + __IO uint32_t spcl_ctrl; /* 0x0010 SPI Master Special Mode Controls */ + __IO uint32_t intfl; /* 0x0014 SPI Master Interrupt Flags */ + __IO uint32_t inten; /* 0x0018 SPI Master Interrupt Enable/Disable Settings */ + __IO uint32_t simple_headers; /* 0x001C SPI Master Simple Mode Transaction Headers */ +} mxc_spim_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + union { /* 0x0000-0x07FC SPI Master FIFO Write Space for Transaction Setup */ + __IO uint8_t trans_8[2048]; + __IO uint16_t trans_16[1024]; + __IO uint32_t trans_32[512]; + }; + union { /* 0x0800-0x0FFC SPI Master FIFO Read Space for Results Data */ + __IO uint8_t rslts_8[2048]; + __IO uint16_t rslts_16[1024]; + __IO uint32_t rslts_32[512]; + }; +} mxc_spim_fifo_regs_t; + + +/* + Register offsets for module SPIM. +*/ + +#define MXC_R_SPIM_OFFS_MSTR_CFG ((uint32_t)0x00000000UL) +#define MXC_R_SPIM_OFFS_SS_SR_POLARITY ((uint32_t)0x00000004UL) +#define MXC_R_SPIM_OFFS_GEN_CTRL ((uint32_t)0x00000008UL) +#define MXC_R_SPIM_OFFS_FIFO_CTRL ((uint32_t)0x0000000CUL) +#define MXC_R_SPIM_OFFS_SPCL_CTRL ((uint32_t)0x00000010UL) +#define MXC_R_SPIM_OFFS_INTFL ((uint32_t)0x00000014UL) +#define MXC_R_SPIM_OFFS_INTEN ((uint32_t)0x00000018UL) +#define MXC_R_SPIM_OFFS_SIMPLE_HEADERS ((uint32_t)0x0000001CUL) +#define MXC_R_SPIM_FIFO_OFFS_TRANS ((uint32_t)0x00000000UL) +#define MXC_R_SPIM_FIFO_OFFS_RSLTS ((uint32_t)0x00000800UL) + + +/* + Field positions and masks for module SPIM. +*/ + +#define MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS 0 +#define MXC_F_SPIM_MSTR_CFG_SLAVE_SEL ((uint32_t)(0x00000007UL << MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS)) +#define MXC_F_SPIM_MSTR_CFG_THREE_WIRE_MODE_POS 3 +#define MXC_F_SPIM_MSTR_CFG_THREE_WIRE_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIM_MSTR_CFG_THREE_WIRE_MODE_POS)) +#define MXC_F_SPIM_MSTR_CFG_SPI_MODE_POS 4 +#define MXC_F_SPIM_MSTR_CFG_SPI_MODE ((uint32_t)(0x00000003UL << MXC_F_SPIM_MSTR_CFG_SPI_MODE_POS)) +#define MXC_F_SPIM_MSTR_CFG_PAGE_SIZE_POS 6 +#define MXC_F_SPIM_MSTR_CFG_PAGE_SIZE ((uint32_t)(0x00000003UL << MXC_F_SPIM_MSTR_CFG_PAGE_SIZE_POS)) +#define MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK_POS 8 +#define MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK ((uint32_t)(0x0000000FUL << MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK_POS)) +#define MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK_POS 12 +#define MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK ((uint32_t)(0x0000000FUL << MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK_POS)) +#define MXC_F_SPIM_MSTR_CFG_ACT_DELAY_POS 16 +#define MXC_F_SPIM_MSTR_CFG_ACT_DELAY ((uint32_t)(0x00000003UL << MXC_F_SPIM_MSTR_CFG_ACT_DELAY_POS)) +#define MXC_F_SPIM_MSTR_CFG_INACT_DELAY_POS 18 +#define MXC_F_SPIM_MSTR_CFG_INACT_DELAY ((uint32_t)(0x00000003UL << MXC_F_SPIM_MSTR_CFG_INACT_DELAY_POS)) +#define MXC_F_SPIM_MSTR_CFG_SDIO_SAMPLE_POINT_POS 20 +#define MXC_F_SPIM_MSTR_CFG_SDIO_SAMPLE_POINT ((uint32_t)(0x0000000FUL << MXC_F_SPIM_MSTR_CFG_SDIO_SAMPLE_POINT_POS)) + +#define MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_4B ((uint32_t)0x00000000UL) +#define MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_8B ((uint32_t)0x00000001UL) +#define MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_16B ((uint32_t)0x00000002UL) +#define MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_32B ((uint32_t)0x00000003UL) + +#define MXC_S_SPIM_MSTR_CFG_PAGE_4B (MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_4B << MXC_F_SPIM_MSTR_CFG_PAGE_SIZE_POS) +#define MXC_S_SPIM_MSTR_CFG_PAGE_8B (MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_8B << MXC_F_SPIM_MSTR_CFG_PAGE_SIZE_POS) +#define MXC_S_SPIM_MSTR_CFG_PAGE_16B (MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_16B << MXC_F_SPIM_MSTR_CFG_PAGE_SIZE_POS) +#define MXC_S_SPIM_MSTR_CFG_PAGE_32B (MXC_V_SPIM_MSTR_CFG_PAGE_SIZE_32B << MXC_F_SPIM_MSTR_CFG_PAGE_SIZE_POS) + +#define MXC_F_SPIM_SS_SR_POLARITY_SS_POLARITY_POS 0 +#define MXC_F_SPIM_SS_SR_POLARITY_SS_POLARITY ((uint32_t)(0x000000FFUL << MXC_F_SPIM_SS_SR_POLARITY_SS_POLARITY_POS)) +#define MXC_F_SPIM_SS_SR_POLARITY_FC_POLARITY_POS 8 +#define MXC_F_SPIM_SS_SR_POLARITY_FC_POLARITY ((uint32_t)(0x000000FFUL << MXC_F_SPIM_SS_SR_POLARITY_FC_POLARITY_POS)) + +#define MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN_POS 0 +#define MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN_POS)) +#define MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN_POS 1 +#define MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN_POS)) +#define MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN_POS 2 +#define MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN_POS)) +#define MXC_F_SPIM_GEN_CTRL_BIT_BANG_MODE_POS 3 +#define MXC_F_SPIM_GEN_CTRL_BIT_BANG_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_BIT_BANG_MODE_POS)) +#define MXC_F_SPIM_GEN_CTRL_BB_SS_IN_OUT_POS 4 +#define MXC_F_SPIM_GEN_CTRL_BB_SS_IN_OUT ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_BB_SS_IN_OUT_POS)) +#define MXC_F_SPIM_GEN_CTRL_BB_SR_IN_POS 5 +#define MXC_F_SPIM_GEN_CTRL_BB_SR_IN ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_BB_SR_IN_POS)) +#define MXC_F_SPIM_GEN_CTRL_BB_SCK_IN_OUT_POS 6 +#define MXC_F_SPIM_GEN_CTRL_BB_SCK_IN_OUT ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_BB_SCK_IN_OUT_POS)) +#define MXC_F_SPIM_GEN_CTRL_BB_SDIO_IN_POS 8 +#define MXC_F_SPIM_GEN_CTRL_BB_SDIO_IN ((uint32_t)(0x0000000FUL << MXC_F_SPIM_GEN_CTRL_BB_SDIO_IN_POS)) +#define MXC_F_SPIM_GEN_CTRL_BB_SDIO_OUT_POS 12 +#define MXC_F_SPIM_GEN_CTRL_BB_SDIO_OUT ((uint32_t)(0x0000000FUL << MXC_F_SPIM_GEN_CTRL_BB_SDIO_OUT_POS)) +#define MXC_F_SPIM_GEN_CTRL_BB_SDIO_DR_EN_POS 16 +#define MXC_F_SPIM_GEN_CTRL_BB_SDIO_DR_EN ((uint32_t)(0x0000000FUL << MXC_F_SPIM_GEN_CTRL_BB_SDIO_DR_EN_POS)) +#define MXC_F_SPIM_GEN_CTRL_SIMPLE_MODE_POS 20 +#define MXC_F_SPIM_GEN_CTRL_SIMPLE_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_SIMPLE_MODE_POS)) +#define MXC_F_SPIM_GEN_CTRL_START_RX_ONLY_POS 21 +#define MXC_F_SPIM_GEN_CTRL_START_RX_ONLY ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_START_RX_ONLY_POS)) +#define MXC_F_SPIM_GEN_CTRL_DEASSERT_ACT_SS_POS 22 +#define MXC_F_SPIM_GEN_CTRL_DEASSERT_ACT_SS ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_DEASSERT_ACT_SS_POS)) +#define MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE_POS 24 +#define MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE_POS)) +#define MXC_F_SPIM_GEN_CTRL_INVERT_SCK_FB_CLK_POS 25 +#define MXC_F_SPIM_GEN_CTRL_INVERT_SCK_FB_CLK ((uint32_t)(0x00000001UL << MXC_F_SPIM_GEN_CTRL_INVERT_SCK_FB_CLK_POS)) + +#define MXC_F_SPIM_FIFO_CTRL_TX_FIFO_AE_LVL_POS 0 +#define MXC_F_SPIM_FIFO_CTRL_TX_FIFO_AE_LVL ((uint32_t)(0x0000000FUL << MXC_F_SPIM_FIFO_CTRL_TX_FIFO_AE_LVL_POS)) +#define MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS 8 +#define MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED ((uint32_t)(0x0000001FUL << MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS)) +#define MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL_POS 16 +#define MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL ((uint32_t)(0x0000001FUL << MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL_POS)) +#define MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS 24 +#define MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED ((uint32_t)(0x0000003FUL << MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS)) + +#define MXC_F_SPIM_SPCL_CTRL_SS_SAMPLE_MODE_POS 0 +#define MXC_F_SPIM_SPCL_CTRL_SS_SAMPLE_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIM_SPCL_CTRL_SS_SAMPLE_MODE_POS)) +#define MXC_F_SPIM_SPCL_CTRL_MISO_FC_EN_POS 1 +#define MXC_F_SPIM_SPCL_CTRL_MISO_FC_EN ((uint32_t)(0x00000001UL << MXC_F_SPIM_SPCL_CTRL_MISO_FC_EN_POS)) +#define MXC_F_SPIM_SPCL_CTRL_SS_SA_SDIO_OUT_POS 4 +#define MXC_F_SPIM_SPCL_CTRL_SS_SA_SDIO_OUT ((uint32_t)(0x0000000FUL << MXC_F_SPIM_SPCL_CTRL_SS_SA_SDIO_OUT_POS)) +#define MXC_F_SPIM_SPCL_CTRL_SS_SA_SDIO_DR_EN_POS 8 +#define MXC_F_SPIM_SPCL_CTRL_SS_SA_SDIO_DR_EN ((uint32_t)(0x0000000FUL << MXC_F_SPIM_SPCL_CTRL_SS_SA_SDIO_DR_EN_POS)) + +#if (MXC_SPIM_REV == 0) +#define MXC_F_SPIM_SPCL_CTRL_SPECIAL_MODE_3_EN_POS 16 +#define MXC_F_SPIM_SPCL_CTRL_SPECIAL_MODE_3_EN ((uint32_t)(0x00000001UL << MXC_F_SPIM_SPCL_CTRL_SPECIAL_MODE_3_EN_POS)) +#else +#define MXC_F_SPIM_SPCL_CTRL_RX_FIFO_MARGIN_POS 12 +#define MXC_F_SPIM_SPCL_CTRL_RX_FIFO_MARGIN ((uint32_t)(0x00000007UL << MXC_F_SPIM_SPCL_CTRL_RX_FIFO_MARGIN_POS)) +#define MXC_F_SPIM_SPCL_CTRL_SCK_FB_DELAY_POS 16 +#define MXC_F_SPIM_SPCL_CTRL_SCK_FB_DELAY ((uint32_t)(0x0000000FUL << MXC_F_SPIM_SPCL_CTRL_SCK_FB_DELAY_POS)) +#define MXC_F_SPIM_SPCL_CTRL_SPARE_RESERVED_POS 20 +#define MXC_F_SPIM_SPCL_CTRL_SPARE_RESERVED ((uint32_t)(0x00000FFFUL << MXC_F_SPIM_SPCL_CTRL_SPARE_RESERVED_POS)) +#endif + +#define MXC_F_SPIM_INTFL_TX_STALLED_POS 0 +#define MXC_F_SPIM_INTFL_TX_STALLED ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTFL_TX_STALLED_POS)) +#define MXC_F_SPIM_INTFL_RX_STALLED_POS 1 +#define MXC_F_SPIM_INTFL_RX_STALLED ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTFL_RX_STALLED_POS)) +#define MXC_F_SPIM_INTFL_TX_READY_POS 2 +#define MXC_F_SPIM_INTFL_TX_READY ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTFL_TX_READY_POS)) +#define MXC_F_SPIM_INTFL_RX_DONE_POS 3 +#define MXC_F_SPIM_INTFL_RX_DONE ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTFL_RX_DONE_POS)) +#define MXC_F_SPIM_INTFL_TX_FIFO_AE_POS 4 +#define MXC_F_SPIM_INTFL_TX_FIFO_AE ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTFL_TX_FIFO_AE_POS)) +#define MXC_F_SPIM_INTFL_RX_FIFO_AF_POS 5 +#define MXC_F_SPIM_INTFL_RX_FIFO_AF ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTFL_RX_FIFO_AF_POS)) + +#define MXC_F_SPIM_INTEN_TX_STALLED_POS 0 +#define MXC_F_SPIM_INTEN_TX_STALLED ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTEN_TX_STALLED_POS)) +#define MXC_F_SPIM_INTEN_RX_STALLED_POS 1 +#define MXC_F_SPIM_INTEN_RX_STALLED ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTEN_RX_STALLED_POS)) +#define MXC_F_SPIM_INTEN_TX_READY_POS 2 +#define MXC_F_SPIM_INTEN_TX_READY ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTEN_TX_READY_POS)) +#define MXC_F_SPIM_INTEN_RX_DONE_POS 3 +#define MXC_F_SPIM_INTEN_RX_DONE ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTEN_RX_DONE_POS)) +#define MXC_F_SPIM_INTEN_TX_FIFO_AE_POS 4 +#define MXC_F_SPIM_INTEN_TX_FIFO_AE ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTEN_TX_FIFO_AE_POS)) +#define MXC_F_SPIM_INTEN_RX_FIFO_AF_POS 5 +#define MXC_F_SPIM_INTEN_RX_FIFO_AF ((uint32_t)(0x00000001UL << MXC_F_SPIM_INTEN_RX_FIFO_AF_POS)) + +#define MXC_F_SPIM_SIMPLE_HEADERS_TX_BIDIR_HEADER_POS 0 +#define MXC_F_SPIM_SIMPLE_HEADERS_TX_BIDIR_HEADER ((uint32_t)(0x00003FFFUL << MXC_F_SPIM_SIMPLE_HEADERS_TX_BIDIR_HEADER_POS)) +#define MXC_F_SPIM_SIMPLE_HEADERS_RX_ONLY_HEADER_POS 16 +#define MXC_F_SPIM_SIMPLE_HEADERS_RX_ONLY_HEADER ((uint32_t)(0x00003FFFUL << MXC_F_SPIM_SIMPLE_HEADERS_RX_ONLY_HEADER_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_SPIM_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/spis_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/spis_regs.h new file mode 100644 index 0000000..e5e6de8 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/spis_regs.h @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_SPIS_REGS_H_ +#define _MXC_SPIS_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t gen_ctrl; /* 0x0000 SPI Slave General Control Register */ + __IO uint32_t fifo_ctrl; /* 0x0004 SPI Slave FIFO Control Register */ + __IO uint32_t fifo_stat; /* 0x0008 SPI Slave FIFO Status Register */ + __IO uint32_t intfl; /* 0x000C SPI Slave Interrupt Flags */ + __IO uint32_t inten; /* 0x0010 SPI Slave Interrupt Enable/Disable Settings */ +} mxc_spis_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + union { /* 0x0000-0x07FC SPI Slave FIFO TX Write Space */ + __IO uint8_t tx_8[2048]; + __IO uint16_t tx_16[1024]; + __IO uint32_t tx_32[512]; + }; + union { /* 0x0800-0x0FFC FIFO Read Space for Results Data */ + __IO uint8_t rx_8[2048]; + __IO uint16_t rx_16[1024]; + __IO uint32_t rx_32[512]; + }; +} mxc_spis_fifo_regs_t; + + +/* + Register offsets for module SPIS. +*/ + +#define MXC_R_SPIS_OFFS_GEN_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_SPIS_OFFS_FIFO_CTRL ((uint32_t)0x00000004UL) +#define MXC_R_SPIS_OFFS_FIFO_STAT ((uint32_t)0x00000008UL) +#define MXC_R_SPIS_OFFS_INTFL ((uint32_t)0x0000000CUL) +#define MXC_R_SPIS_OFFS_INTEN ((uint32_t)0x00000010UL) +#define MXC_R_SPIS_FIFO_OFFS_TX ((uint32_t)0x00000000UL) +#define MXC_R_SPIS_FIFO_OFFS_RX ((uint32_t)0x00000800UL) + + +/* + Field positions and masks for module SPIS. +*/ + +#define MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN_POS 0 +#define MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN ((uint32_t)(0x00000001UL << MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN_POS)) +#define MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN_POS 1 +#define MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN_POS)) +#define MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN_POS 2 +#define MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN_POS)) +#define MXC_F_SPIS_GEN_CTRL_DATA_WIDTH_POS 4 +#define MXC_F_SPIS_GEN_CTRL_DATA_WIDTH ((uint32_t)(0x00000003UL << MXC_F_SPIS_GEN_CTRL_DATA_WIDTH_POS)) +#define MXC_F_SPIS_GEN_CTRL_SPI_MODE_POS 16 +#define MXC_F_SPIS_GEN_CTRL_SPI_MODE ((uint32_t)(0x00000003UL << MXC_F_SPIS_GEN_CTRL_SPI_MODE_POS)) +#define MXC_F_SPIS_GEN_CTRL_TX_CLK_INVERT_POS 20 +#define MXC_F_SPIS_GEN_CTRL_TX_CLK_INVERT ((uint32_t)(0x00000001UL << MXC_F_SPIS_GEN_CTRL_TX_CLK_INVERT_POS)) + +#define MXC_F_SPIS_FIFO_CTRL_TX_FIFO_AE_LVL_POS 0 +#define MXC_F_SPIS_FIFO_CTRL_TX_FIFO_AE_LVL ((uint32_t)(0x0000001FUL << MXC_F_SPIS_FIFO_CTRL_TX_FIFO_AE_LVL_POS)) +#define MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL_POS 8 +#define MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL ((uint32_t)(0x0000001FUL << MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL_POS)) + +#define MXC_F_SPIS_FIFO_STAT_TX_FIFO_USED_POS 0 +#define MXC_F_SPIS_FIFO_STAT_TX_FIFO_USED ((uint32_t)(0x0000003FUL << MXC_F_SPIS_FIFO_STAT_TX_FIFO_USED_POS)) +#define MXC_F_SPIS_FIFO_STAT_RX_FIFO_USED_POS 8 +#define MXC_F_SPIS_FIFO_STAT_RX_FIFO_USED ((uint32_t)(0x0000003FUL << MXC_F_SPIS_FIFO_STAT_RX_FIFO_USED_POS)) + +#define MXC_F_SPIS_INTFL_TX_FIFO_AE_POS 0 +#define MXC_F_SPIS_INTFL_TX_FIFO_AE ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_TX_FIFO_AE_POS)) +#define MXC_F_SPIS_INTFL_RX_FIFO_AF_POS 1 +#define MXC_F_SPIS_INTFL_RX_FIFO_AF ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_RX_FIFO_AF_POS)) +#define MXC_F_SPIS_INTFL_TX_NO_DATA_POS 2 +#define MXC_F_SPIS_INTFL_TX_NO_DATA ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_TX_NO_DATA_POS)) +#define MXC_F_SPIS_INTFL_RX_LOST_DATA_POS 3 +#define MXC_F_SPIS_INTFL_RX_LOST_DATA ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_RX_LOST_DATA_POS)) +#define MXC_F_SPIS_INTFL_TX_UNDERFLOW_POS 4 +#define MXC_F_SPIS_INTFL_TX_UNDERFLOW ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_TX_UNDERFLOW_POS)) +#define MXC_F_SPIS_INTFL_SS_ASSERTED_POS 5 +#define MXC_F_SPIS_INTFL_SS_ASSERTED ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_SS_ASSERTED_POS)) +#define MXC_F_SPIS_INTFL_SS_DEASSERTED_POS 6 +#define MXC_F_SPIS_INTFL_SS_DEASSERTED ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTFL_SS_DEASSERTED_POS)) + +#define MXC_F_SPIS_INTEN_TX_FIFO_AE_POS 0 +#define MXC_F_SPIS_INTEN_TX_FIFO_AE ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_TX_FIFO_AE_POS)) +#define MXC_F_SPIS_INTEN_RX_FIFO_AF_POS 1 +#define MXC_F_SPIS_INTEN_RX_FIFO_AF ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_RX_FIFO_AF_POS)) +#define MXC_F_SPIS_INTEN_TX_NO_DATA_POS 2 +#define MXC_F_SPIS_INTEN_TX_NO_DATA ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_TX_NO_DATA_POS)) +#define MXC_F_SPIS_INTEN_RX_LOST_DATA_POS 3 +#define MXC_F_SPIS_INTEN_RX_LOST_DATA ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_RX_LOST_DATA_POS)) +#define MXC_F_SPIS_INTEN_TX_UNDERFLOW_POS 4 +#define MXC_F_SPIS_INTEN_TX_UNDERFLOW ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_TX_UNDERFLOW_POS)) +#define MXC_F_SPIS_INTEN_SS_ASSERTED_POS 5 +#define MXC_F_SPIS_INTEN_SS_ASSERTED ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_SS_ASSERTED_POS)) +#define MXC_F_SPIS_INTEN_SS_DEASSERTED_POS 6 +#define MXC_F_SPIS_INTEN_SS_DEASSERTED ((uint32_t)(0x00000001UL << MXC_F_SPIS_INTEN_SS_DEASSERTED_POS)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_SPIS_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/spix_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/spix_regs.h new file mode 100644 index 0000000..8fa9ab8 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/spix_regs.h @@ -0,0 +1,218 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_SPIX_REGS_H_ +#define _MXC_SPIX_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t master_cfg; /* 0x0000 SPIX Master Configuration */ + __IO uint32_t fetch_ctrl; /* 0x0004 SPIX Fetch Control */ + __IO uint32_t mode_ctrl; /* 0x0008 SPIX Mode Control */ + __IO uint32_t mode_data; /* 0x000C SPIX Mode Data */ + __IO uint32_t sck_fb_ctrl; /* 0x0010 SPIX SCK_FB Control Register */ +} mxc_spix_regs_t; + + +/* + Register offsets for module SPIX. +*/ + +#define MXC_R_SPIX_OFFS_MASTER_CFG ((uint32_t)0x00000000UL) +#define MXC_R_SPIX_OFFS_FETCH_CTRL ((uint32_t)0x00000004UL) +#define MXC_R_SPIX_OFFS_MODE_CTRL ((uint32_t)0x00000008UL) +#define MXC_R_SPIX_OFFS_MODE_DATA ((uint32_t)0x0000000CUL) +#define MXC_R_SPIX_OFFS_SCK_FB_CTRL ((uint32_t)0x00000010UL) + + +/* + Field positions and masks for module SPIX. +*/ + +#define MXC_F_SPIX_MASTER_CFG_SPI_MODE_POS 0 +#define MXC_F_SPIX_MASTER_CFG_SPI_MODE ((uint32_t)(0x00000003UL << MXC_F_SPIX_MASTER_CFG_SPI_MODE_POS)) +#define MXC_F_SPIX_MASTER_CFG_SS_ACT_LO_POS 2 +#define MXC_F_SPIX_MASTER_CFG_SS_ACT_LO ((uint32_t)(0x00000001UL << MXC_F_SPIX_MASTER_CFG_SS_ACT_LO_POS)) +#define MXC_F_SPIX_MASTER_CFG_ALT_TIMING_EN_POS 3 +#define MXC_F_SPIX_MASTER_CFG_ALT_TIMING_EN ((uint32_t)(0x00000001UL << MXC_F_SPIX_MASTER_CFG_ALT_TIMING_EN_POS)) +#define MXC_F_SPIX_MASTER_CFG_SLAVE_SEL_POS 4 +#define MXC_F_SPIX_MASTER_CFG_SLAVE_SEL ((uint32_t)(0x00000007UL << MXC_F_SPIX_MASTER_CFG_SLAVE_SEL_POS)) +#define MXC_F_SPIX_MASTER_CFG_SCK_LO_CLK_POS 8 +#define MXC_F_SPIX_MASTER_CFG_SCK_LO_CLK ((uint32_t)(0x0000000FUL << MXC_F_SPIX_MASTER_CFG_SCK_LO_CLK_POS)) +#define MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK_POS 12 +#define MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK ((uint32_t)(0x0000000FUL << MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK_POS)) +#define MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS 16 +#define MXC_F_SPIX_MASTER_CFG_ACT_DELAY ((uint32_t)(0x00000003UL << MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS)) +#define MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS 18 +#define MXC_F_SPIX_MASTER_CFG_INACT_DELAY ((uint32_t)(0x00000003UL << MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS)) +#define MXC_F_SPIX_MASTER_CFG_ALT_SCK_LO_CLK_POS 20 +#define MXC_F_SPIX_MASTER_CFG_ALT_SCK_LO_CLK ((uint32_t)(0x0000000FUL << MXC_F_SPIX_MASTER_CFG_ALT_SCK_LO_CLK_POS)) +#define MXC_F_SPIX_MASTER_CFG_ALT_SCK_HI_CLK_POS 24 +#define MXC_F_SPIX_MASTER_CFG_ALT_SCK_HI_CLK ((uint32_t)(0x0000000FUL << MXC_F_SPIX_MASTER_CFG_ALT_SCK_HI_CLK_POS)) +#define MXC_F_SPIX_MASTER_CFG_SDIO_SAMPLE_POINT_POS 28 +#define MXC_F_SPIX_MASTER_CFG_SDIO_SAMPLE_POINT ((uint32_t)(0x0000000FUL << MXC_F_SPIX_MASTER_CFG_SDIO_SAMPLE_POINT_POS)) + +#define MXC_F_SPIX_FETCH_CTRL_CMD_VALUE_POS 0 +#define MXC_F_SPIX_FETCH_CTRL_CMD_VALUE ((uint32_t)(0x000000FFUL << MXC_F_SPIX_FETCH_CTRL_CMD_VALUE_POS)) +#define MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH_POS 8 +#define MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH ((uint32_t)(0x00000003UL << MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH_POS)) +#define MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS 10 +#define MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH ((uint32_t)(0x00000003UL << MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS)) +#define MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS 12 +#define MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH ((uint32_t)(0x00000003UL << MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS)) +#define MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR_POS 16 +#define MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR ((uint32_t)(0x00000001UL << MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR_POS)) + +#define MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS_POS 0 +#define MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS ((uint32_t)(0x0000000FUL << MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS_POS)) +#define MXC_F_SPIX_MODE_CTRL_NO_CMD_MODE_POS 8 +#define MXC_F_SPIX_MODE_CTRL_NO_CMD_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIX_MODE_CTRL_NO_CMD_MODE_POS)) + +#define MXC_F_SPIX_MODE_DATA_MODE_DATA_BITS_POS 0 +#define MXC_F_SPIX_MODE_DATA_MODE_DATA_BITS ((uint32_t)(0x0000FFFFUL << MXC_F_SPIX_MODE_DATA_MODE_DATA_BITS_POS)) +#define MXC_F_SPIX_MODE_DATA_MODE_DATA_OE_POS 16 +#define MXC_F_SPIX_MODE_DATA_MODE_DATA_OE ((uint32_t)(0x0000FFFFUL << MXC_F_SPIX_MODE_DATA_MODE_DATA_OE_POS)) + +#define MXC_F_SPIX_SCK_FB_CTRL_ENABLE_SCK_FB_MODE_POS 0 +#define MXC_F_SPIX_SCK_FB_CTRL_ENABLE_SCK_FB_MODE ((uint32_t)(0x00000001UL << MXC_F_SPIX_SCK_FB_CTRL_ENABLE_SCK_FB_MODE_POS)) +#define MXC_F_SPIX_SCK_FB_CTRL_INVERT_SCK_FB_CLK_POS 1 +#define MXC_F_SPIX_SCK_FB_CTRL_INVERT_SCK_FB_CLK ((uint32_t)(0x00000001UL << MXC_F_SPIX_SCK_FB_CTRL_INVERT_SCK_FB_CLK_POS)) + +#if(MXC_SPIX_REV == 0) +#define MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_POS 4 +#define MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS ((uint32_t)(0x0000003FUL << MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_POS)) +#define MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_NO_CMD_POS 12 +#define MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_NO_CMD ((uint32_t)(0x0000003FUL << MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_NO_CMD_POS)) +#endif + + +/* + Field values and shifted values for module SPIX. +*/ + +#define MXC_V_SPIX_MASTER_CFG_SPI_MODE_SCK_HI_SAMPLE_RISING ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_MASTER_CFG_SPI_MODE_SCK_LO_SAMPLE_FALLING ((uint32_t)(0x00000003UL)) + +#define MXC_S_SPIX_MASTER_CFG_SPI_MODE_SCK_HI_SAMPLE_RISING ((uint32_t)(MXC_V_SPIX_MASTER_CFG_SPI_MODE_SCK_HI_SAMPLE_RISING << MXC_F_SPIX_MASTER_CFG_SPI_MODE_POS)) +#define MXC_S_SPIX_MASTER_CFG_SPI_MODE_SCK_LO_SAMPLE_FALLING ((uint32_t)(MXC_V_SPIX_MASTER_CFG_SPI_MODE_SCK_LO_SAMPLE_FALLING << MXC_F_SPIX_MASTER_CFG_SPI_MODE_POS)) + +#define MXC_V_SPIX_MASTER_CFG_SS_ACT_LO_ACTIVE_HIGH ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_MASTER_CFG_SS_ACT_LO_ACTIVE_LOW ((uint32_t)(0x00000001UL)) + +#define MXC_S_SPIX_MASTER_CFG_SS_ACT_LO_ACTIVE_HIGH ((uint32_t)(MXC_V_SPIX_MASTER_CFG_SS_ACT_LO_ACTIVE_HIGH << MXC_F_SPIX_MASTER_CFG_SS_ACT_LO_POS)) +#define MXC_S_SPIX_MASTER_CFG_SS_ACT_LO_ACTIVE_LOW ((uint32_t)(MXC_V_SPIX_MASTER_CFG_SS_ACT_LO_ACTIVE_LOW << MXC_F_SPIX_MASTER_CFG_SS_ACT_LO_POS)) + +#define MXC_V_SPIX_MASTER_CFG_ALT_TIMING_EN_DISABLED ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_MASTER_CFG_ALT_TIMING_EN_ENABLED_AS_NEEDED ((uint32_t)(0x00000001UL)) + +#define MXC_S_SPIX_MASTER_CFG_ALT_TIMING_EN_DISABLED ((uint32_t)(MXC_V_SPIX_MASTER_CFG_ALT_TIMING_EN_DISABLED << MXC_F_SPIX_MASTER_CFG_ALT_TIMING_EN_POS)) +#define MXC_S_SPIX_MASTER_CFG_ALT_TIMING_EN_ENABLED_AS_NEEDED ((uint32_t)(MXC_V_SPIX_MASTER_CFG_ALT_TIMING_EN_ENABLED_AS_NEEDED << MXC_F_SPIX_MASTER_CFG_ALT_TIMING_EN_POS)) + +#define MXC_V_SPIX_MASTER_CFG_ACT_DELAY_OFF ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_MASTER_CFG_ACT_DELAY_FOR_2_MOD_CLK ((uint32_t)(0x00000001UL)) +#define MXC_V_SPIX_MASTER_CFG_ACT_DELAY_FOR_4_MOD_CLK ((uint32_t)(0x00000002UL)) +#define MXC_V_SPIX_MASTER_CFG_ACT_DELAY_FOR_8_MOD_CLK ((uint32_t)(0x00000003UL)) + +#define MXC_S_SPIX_MASTER_CFG_ACT_DELAY_OFF ((uint32_t)(MXC_V_SPIX_MASTER_CFG_ACT_DELAY_OFF << MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS)) +#define MXC_S_SPIX_MASTER_CFG_ACT_DELAY_FOR_2_MOD_CLK ((uint32_t)(MXC_V_SPIX_MASTER_CFG_ACT_DELAY_FOR_2_MOD_CLK << MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS)) +#define MXC_S_SPIX_MASTER_CFG_ACT_DELAY_FOR_4_MOD_CLK ((uint32_t)(MXC_V_SPIX_MASTER_CFG_ACT_DELAY_FOR_4_MOD_CLK << MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS)) +#define MXC_S_SPIX_MASTER_CFG_ACT_DELAY_FOR_8_MOD_CLK ((uint32_t)(MXC_V_SPIX_MASTER_CFG_ACT_DELAY_FOR_8_MOD_CLK << MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS)) + +#define MXC_V_SPIX_MASTER_CFG_INACT_DELAY_OFF ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_MASTER_CFG_INACT_DELAY_FOR_2_MOD_CLK ((uint32_t)(0x00000001UL)) +#define MXC_V_SPIX_MASTER_CFG_INACT_DELAY_FOR_4_MOD_CLK ((uint32_t)(0x00000002UL)) +#define MXC_V_SPIX_MASTER_CFG_INACT_DELAY_FOR_8_MOD_CLK ((uint32_t)(0x00000003UL)) + +#define MXC_S_SPIX_MASTER_CFG_INACT_DELAY_OFF ((uint32_t)(MXC_V_SPIX_MASTER_CFG_INACT_DELAY_OFF << MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS)) +#define MXC_S_SPIX_MASTER_CFG_INACT_DELAY_FOR_2_MOD_CLK ((uint32_t)(MXC_V_SPIX_MASTER_CFG_INACT_DELAY_FOR_2_MOD_CLK << MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS)) +#define MXC_S_SPIX_MASTER_CFG_INACT_DELAY_FOR_4_MOD_CLK ((uint32_t)(MXC_V_SPIX_MASTER_CFG_INACT_DELAY_FOR_4_MOD_CLK << MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS)) +#define MXC_S_SPIX_MASTER_CFG_INACT_DELAY_FOR_8_MOD_CLK ((uint32_t)(MXC_V_SPIX_MASTER_CFG_INACT_DELAY_FOR_8_MOD_CLK << MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS)) + +#define MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_SINGLE ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_DUAL_IO ((uint32_t)(0x00000001UL)) +#define MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_QUAD_IO ((uint32_t)(0x00000002UL)) + +#define MXC_S_SPIX_FETCH_CTRL_CMD_WIDTH_SINGLE ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_SINGLE << MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH_POS)) +#define MXC_S_SPIX_FETCH_CTRL_CMD_WIDTH_DUAL_IO ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_DUAL_IO << MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH_POS)) +#define MXC_S_SPIX_FETCH_CTRL_CMD_WIDTH_QUAD_IO ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_QUAD_IO << MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH_POS)) + +#define MXC_V_SPIX_FETCH_CTRL_ADDR_WIDTH_SINGLE ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_FETCH_CTRL_ADDR_WIDTH_DUAL_IO ((uint32_t)(0x00000001UL)) +#define MXC_V_SPIX_FETCH_CTRL_ADDR_WIDTH_QUAD_IO ((uint32_t)(0x00000002UL)) + +#define MXC_S_SPIX_FETCH_CTRL_ADDR_WIDTH_SINGLE ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_ADDR_WIDTH_SINGLE << MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS)) +#define MXC_S_SPIX_FETCH_CTRL_ADDR_WIDTH_DUAL_IO ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_ADDR_WIDTH_DUAL_IO << MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS)) +#define MXC_S_SPIX_FETCH_CTRL_ADDR_WIDTH_QUAD_IO ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_ADDR_WIDTH_QUAD_IO << MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS)) + +#define MXC_V_SPIX_FETCH_CTRL_DATA_WIDTH_SINGLE ((uint32_t)(0x00000000UL)) +#define MXC_V_SPIX_FETCH_CTRL_DATA_WIDTH_DUAL_IO ((uint32_t)(0x00000001UL)) +#define MXC_V_SPIX_FETCH_CTRL_DATA_WIDTH_QUAD_IO ((uint32_t)(0x00000002UL)) + +#define MXC_S_SPIX_FETCH_CTRL_DATA_WIDTH_SINGLE ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_DATA_WIDTH_SINGLE << MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS)) +#define MXC_S_SPIX_FETCH_CTRL_DATA_WIDTH_DUAL_IO ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_DATA_WIDTH_DUAL_IO << MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS)) +#define MXC_S_SPIX_FETCH_CTRL_DATA_WIDTH_QUAD_IO ((uint32_t)(MXC_V_SPIX_FETCH_CTRL_DATA_WIDTH_QUAD_IO << MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_SPIX_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/sysman_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/sysman_regs.h new file mode 100644 index 0000000..4af5a85 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/sysman_regs.h @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_SYSMAN_REGS_H_ +#define _MXC_SYSMAN_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t pvt_monitor; /* 0x0000 System Clock Configuration */ +} mxc_sysman_regs_t; + + +/* + Register offsets for module SYSMAN. +*/ + +#define MXC_R_SYSMAN_OFFS_PVT_MONITOR ((uint32_t)0x00000000UL) + + +/* + Field positions and masks for module SYSMAN. +*/ + +#define MXC_F_SYSMAN_PVT_MONITOR_CODE_POS 0 +#define MXC_F_SYSMAN_PVT_MONITOR_CODE ((uint32_t)(0xFFFFFFFFUL << MXC_F_SYSMAN_PVT_MONITOR_CODE_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_SYSMAN_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/system_max32625.c b/targets/TARGET_Maxim/TARGET_MAX32625/device/system_max32625.c new file mode 100644 index 0000000..4f77b21 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/system_max32625.c @@ -0,0 +1,263 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#include +#include +#include +#include "max32625.h" +#include "clkman_regs.h" +#include "adc_regs.h" +#include "pwrseq_regs.h" +#include "pwrman_regs.h" +#include "icc_regs.h" +#include "flc_regs.h" +#include "rtc_regs.h" +#include "trim_regs.h" + +#ifndef RO_FREQ +#define RO_FREQ 96000000 +#endif + +#ifndef LP0_POST_HOOK +#define LP0_POST_HOOK +#endif + +// NOTE: Setting the CMSIS SystemCoreClock value to the actual value it will +// be AFTER SystemInit() runs. This is required so the hal drivers will have +// the correct value when the DATA sections are initialized. +uint32_t SystemCoreClock = RO_FREQ; + +void SystemCoreClockUpdate(void) +{ + if (MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN) { + /* 4 MHz source */ + if (MXC_PWRSEQ->reg3 & MXC_F_PWRSEQ_REG3_PWR_RC_DIV) { + SystemCoreClock = (4000000 / (0x1 << ((MXC_PWRSEQ->reg3 & MXC_F_PWRSEQ_REG3_PWR_RC_DIV) >> + MXC_F_PWRSEQ_REG3_PWR_RC_DIV_POS))); + } else { + SystemCoreClock = 4000000; + } + } else { + /* 96 MHz source */ + if (MXC_PWRSEQ->reg3 & MXC_F_PWRSEQ_REG3_PWR_RO_DIV) { + SystemCoreClock = (RO_FREQ / (0x1 << ((MXC_PWRSEQ->reg3 & MXC_F_PWRSEQ_REG3_PWR_RO_DIV) >> + MXC_F_PWRSEQ_REG3_PWR_RO_DIV_POS))); + } else { + SystemCoreClock = RO_FREQ; + } + } +} + +void CLKMAN_TrimRO(void) +{ + uint32_t running; + uint32_t trim; + + /* Step 1: enable 32KHz RTC */ + running = MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN; + MXC_PWRSEQ->reg0 |= MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN; + + /* Wait for RTC warm-up */ + while(MXC_RTCCFG->osc_ctrl & MXC_F_RTC_OSC_CTRL_OSC_WARMUP_ENABLE) {} + + /* Step 2: enable RO calibration complete interrupt */ + MXC_ADC->intr |= MXC_F_ADC_INTR_RO_CAL_DONE_IE; + + /* Step 3: clear RO calibration complete interrupt */ + MXC_ADC->intr |= MXC_F_ADC_INTR_RO_CAL_DONE_IF; + + /* Step 4: -- NO LONGER NEEDED / HANDLED BY STARTUP CODE -- */ + + /* Step 5: write initial trim to frequency calibration initial condition register */ + trim = (MXC_PWRSEQ->reg6 & MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF) >> MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF_POS; + MXC_ADC->ro_cal1 = (MXC_ADC->ro_cal1 & ~MXC_F_ADC_RO_CAL1_TRM_INIT) | + ((trim << MXC_F_ADC_RO_CAL1_TRM_INIT_POS) & MXC_F_ADC_RO_CAL1_TRM_INIT); + + /* Step 6: load initial trim to active frequency trim register */ + MXC_ADC->ro_cal0 |= MXC_F_ADC_RO_CAL0_RO_CAL_LOAD; + + /* Step 7: enable frequency loop to control RO trim */ + MXC_ADC->ro_cal0 |= MXC_F_ADC_RO_CAL0_RO_CAL_EN; + + /* Step 8: run frequency calibration in atomic mode */ + MXC_ADC->ro_cal0 |= MXC_F_ADC_RO_CAL0_RO_CAL_ATOMIC; + + /* Step 9: waiting for ro_cal_done flag */ + while(!(MXC_ADC->intr & MXC_F_ADC_INTR_RO_CAL_DONE_IF)); + + /* Step 10: stop frequency calibration */ + MXC_ADC->ro_cal0 &= ~MXC_F_ADC_RO_CAL0_RO_CAL_RUN; + + /* Step 11: disable RO calibration complete interrupt */ + MXC_ADC->intr &= ~MXC_F_ADC_INTR_RO_CAL_DONE_IE; + + /* Step 12: read final frequency trim value */ + trim = (MXC_ADC->ro_cal0 & MXC_F_ADC_RO_CAL0_RO_TRM) >> MXC_F_ADC_RO_CAL0_RO_TRM_POS; + + /* Step 13: write final trim to RO flash trim shadow register */ + MXC_PWRSEQ->reg6 = (MXC_PWRSEQ->reg6 & ~MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF) | + ((trim << MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF_POS) & MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF); + + /* Step 14: restore RTC status */ + if (!running) { + MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN; + } + + /* Step 15: disable frequency loop to control RO trim */ + MXC_ADC->ro_cal0 &= ~MXC_F_ADC_RO_CAL0_RO_CAL_EN; +} + +static void ICC_Enable(void) +{ + /* Invalidate cache and wait until ready */ + MXC_ICC->invdt_all = 1; + while (!(MXC_ICC->ctrl_stat & MXC_F_ICC_CTRL_STAT_READY)); + + /* Enable cache */ + MXC_ICC->ctrl_stat |= MXC_F_ICC_CTRL_STAT_ENABLE; + + /* Must invalidate a second time for proper use */ + MXC_ICC->invdt_all = 1; +} + +/* This function is called before C runtime initialization and can be + * implemented by the application for early initializations. If a value other + * than '0' is returned, the C runtime initialization will be skipped. + * + * You may over-ride this function in your program by defining a custom + * PreInit(), but care should be taken to reproduce the initialization steps + * or a non-functional system may result. + */ +__weak int PreInit(void) +{ + /* Increase system clock to 96 MHz */ + MXC_CLKMAN->clk_ctrl = MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO; + + /* Performance-measurement hook, may be defined as nothing */ + LP0_POST_HOOK; + + /* Enable cache here to reduce boot time */ + ICC_Enable(); + + return 0; +} + +/* This function is called just before control is transferred to main(). + */ +void SystemInit(void) +{ + /* Copy trim information from shadow registers into power manager registers */ + /* NOTE: Checks have been added to prevent bad/missing trim values from being loaded */ + if ((MXC_FLC->ctrl & MXC_F_FLC_CTRL_INFO_BLOCK_VALID) && + (MXC_TRIM->for_pwr_reg5 != 0xffffffff) && + (MXC_TRIM->for_pwr_reg6 != 0xffffffff)) { + MXC_PWRSEQ->reg5 = MXC_TRIM->for_pwr_reg5; + MXC_PWRSEQ->reg6 = MXC_TRIM->for_pwr_reg6; + } else { + /* No valid info block, use some reasonable defaults */ + MXC_PWRSEQ->reg6 &= ~MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF; + MXC_PWRSEQ->reg6 |= (0x1e0 << MXC_F_PWRSEQ_REG6_PWR_TRIM_OSC_VREF_POS); + } + + /* Improve flash access timing */ + MXC_FLC->perform |= (MXC_F_FLC_PERFORM_EN_BACK2BACK_RDS | + MXC_F_FLC_PERFORM_EN_MERGE_GRAB_GNT | + MXC_F_FLC_PERFORM_AUTO_TACC | + MXC_F_FLC_PERFORM_AUTO_CLKDIV); + + /* First, eliminate the unnecessary RTC handshake between clock domains. Must be set as a pair. */ + MXC_RTCTMR->ctrl |= (MXC_F_RTC_CTRL_USE_ASYNC_FLAGS | + MXC_F_RTC_CTRL_AGGRESSIVE_RST); + + /* Enable fast read of the RTC timer value, and fast write of all other RTC registers */ + MXC_PWRSEQ->rtc_ctrl2 |= (MXC_F_PWRSEQ_RTC_CTRL2_TIMER_AUTO_UPDATE | + MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_WR); + MXC_PWRSEQ->rtc_ctrl2 &= ~MXC_F_PWRSEQ_RTC_CTRL2_TIMER_ASYNC_RD; + + /* Clear the GPIO WUD event if not waking up from LP0 */ + /* this is necessary because WUD flops come up in undetermined state out of POR or SRST*/ + if ((MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT) || + !(MXC_PWRMAN->pwr_rst_ctrl & MXC_F_PWRMAN_PWR_RST_CTRL_POR)) { + /* Clear GPIO WUD event and configuration registers, globally */ + MXC_PWRSEQ->reg1 |= (MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH | + MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH); + MXC_PWRSEQ->reg1 &= ~(MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH | + MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH); + } else { + /* Unfreeze the GPIO by clearing MBUS_GATE, when returning from LP0 */ + MXC_PWRSEQ->reg1 &= ~MXC_F_PWRSEQ_REG1_PWR_MBUS_GATE; + /* LP0 wake-up: Turn off special switch to eliminate ~50nA of leakage on VDD12 */ + MXC_PWRSEQ->reg1 &= ~MXC_F_PWRSEQ_REG1_PWR_SRAM_NWELL_SW; + } + + /* Turn on retention regulator */ + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RETREGEN_RUN | + MXC_F_PWRSEQ_REG0_PWR_RETREGEN_SLP); + + /* Turn on Auto GPIO Freeze/UnFreeze in sleep modes */ + MXC_PWRSEQ->reg1 |= MXC_F_PWRSEQ_REG1_PWR_AUTO_MBUS_GATE; + + /* Adjust settings in the retention controller for fastest wake-up time */ + MXC_PWRSEQ->retn_ctrl0 |= (MXC_F_PWRSEQ_RETN_CTRL0_RC_REL_CCG_EARLY | + MXC_F_PWRSEQ_RETN_CTRL0_RC_POLL_FLASH); + MXC_PWRSEQ->retn_ctrl0 &= ~MXC_F_PWRSEQ_RETN_CTRL0_RC_USE_FLC_TWK; + + + /* Set retention controller TWake cycle count to 1us to minimize the wake-up time */ + /* NOTE: flash polling (...PWRSEQ_RETN_CTRL0_RC_POLL_FLASH) must be enabled before changing POR default! */ + MXC_PWRSEQ->retn_ctrl1 = (MXC_PWRSEQ->retn_ctrl1 & ~MXC_F_PWRSEQ_RETN_CTRL1_RC_TWK) | + (1 << MXC_F_PWRSEQ_RETN_CTRL1_RC_TWK_POS); + + /* Improve wake-up time by changing ROSEL to 140ns */ + MXC_PWRSEQ->reg3 = (1 << MXC_F_PWRSEQ_REG3_PWR_ROSEL_POS) | + (1 << MXC_F_PWRSEQ_REG3_PWR_FAILSEL_POS) | + (MXC_PWRSEQ->reg3 & ~(MXC_F_PWRSEQ_REG3_PWR_ROSEL | + MXC_F_PWRSEQ_REG3_PWR_FLTRROSEL)); + + /* Enable RTOS Mode: Enable 32kHz clock synchronizer to SysTick external clock input */ + MXC_CLKMAN->clk_ctrl |= MXC_F_CLKMAN_CLK_CTRL_RTOS_MODE; + + /* Set this so all bits of PWR_MSK_FLAGS are active low to mask the corresponding flags */ + MXC_PWRSEQ->pwr_misc |= MXC_F_PWRSEQ_PWR_MISC_INVERT_4_MASK_BITS; + +#if (__FPU_PRESENT == 1) + /* Enable FPU on Cortex-M4, which occupies coprocessor slots 10 & 11 */ + /* Grant full access, per "Table B3-24 CPACR bit assignments". */ + /* DDI0403D "ARMv7-M Architecture Reference Manual" */ + SCB->CPACR |= SCB_CPACR_CP10_Msk | SCB_CPACR_CP11_Msk; + __DSB(); + __ISB(); +#endif + + /* Perform an initial trim of the internal ring oscillator */ + CLKMAN_TrimRO(); +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/system_max32625.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/system_max32625.h new file mode 100644 index 0000000..cfb45ad --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/system_max32625.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _SYSTEM_MAX32625_H_ +#define _SYSTEM_MAX32625_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/*---------------------------------------------------------------------------- + Define clocks + *----------------------------------------------------------------------------*/ +#ifndef HFXIN_FREQ +#define HFXIN_FREQ 8000000 +#endif + +#ifndef RO_FREQ +#define RO_FREQ 96000000 +#endif + +extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ + +/* + * Initialize the system + * + * @brief Setup the microcontroller system. + * Initialize the System and update the SystemCoreClock variable. + */ +extern void SystemInit(void); + +/* + * Update SystemCoreClock variable + * + * @brief Updates the SystemCoreClock with current core Clock + * retrieved from cpu registers. + */ +extern void SystemCoreClockUpdate(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _SYSTEM_MAX32625_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/tmr_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/tmr_regs.h new file mode 100644 index 0000000..ea37cac --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/tmr_regs.h @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_TMR_REGS_H_ +#define _MXC_TMR_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 Timer Control Register */ + __IO uint32_t count32; /* 0x0004 Timer [32 bit] Current Count Value */ + __IO uint32_t term_cnt32; /* 0x0008 Timer [32 bit] Terminal Count Setting */ + __IO uint32_t pwm_cap32; /* 0x000C Timer [32 bit] PWM Compare Setting or Capture/Measure Value */ + __IO uint32_t count16_0; /* 0x0010 Timer [16 bit] Current Count Value, 16-bit Timer 0 */ + __IO uint32_t term_cnt16_0; /* 0x0014 Timer [16 bit] Terminal Count Setting, 16-bit Timer 0 */ + __IO uint32_t count16_1; /* 0x0018 Timer [16 bit] Current Count Value, 16-bit Timer 1 */ + __IO uint32_t term_cnt16_1; /* 0x001C Timer [16 bit] Terminal Count Setting, 16-bit Timer 1 */ + __IO uint32_t intfl; /* 0x0020 Timer Interrupt Flags */ + __IO uint32_t inten; /* 0x0024 Timer Interrupt Enable/Disable Settings */ +} mxc_tmr_regs_t; + + +/* + Register offsets for module TMR. +*/ + +#define MXC_R_TMR_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_TMR_OFFS_COUNT32 ((uint32_t)0x00000004UL) +#define MXC_R_TMR_OFFS_TERM_CNT32 ((uint32_t)0x00000008UL) +#define MXC_R_TMR_OFFS_PWM_CAP32 ((uint32_t)0x0000000CUL) +#define MXC_R_TMR_OFFS_COUNT16_0 ((uint32_t)0x00000010UL) +#define MXC_R_TMR_OFFS_TERM_CNT16_0 ((uint32_t)0x00000014UL) +#define MXC_R_TMR_OFFS_COUNT16_1 ((uint32_t)0x00000018UL) +#define MXC_R_TMR_OFFS_TERM_CNT16_1 ((uint32_t)0x0000001CUL) +#define MXC_R_TMR_OFFS_INTFL ((uint32_t)0x00000020UL) +#define MXC_R_TMR_OFFS_INTEN ((uint32_t)0x00000024UL) + + +/* + Field positions and masks for module TMR. +*/ + +#define MXC_F_TMR_CTRL_MODE_POS 0 +#define MXC_F_TMR_CTRL_MODE ((uint32_t)(0x00000007UL << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_F_TMR_CTRL_TMR2X16_POS 3 +#define MXC_F_TMR_CTRL_TMR2X16 ((uint32_t)(0x00000001UL << MXC_F_TMR_CTRL_TMR2X16_POS)) +#define MXC_F_TMR_CTRL_PRESCALE_POS 4 +#define MXC_F_TMR_CTRL_PRESCALE ((uint32_t)(0x0000000FUL << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_F_TMR_CTRL_POLARITY_POS 8 +#define MXC_F_TMR_CTRL_POLARITY ((uint32_t)(0x00000001UL << MXC_F_TMR_CTRL_POLARITY_POS)) +#define MXC_F_TMR_CTRL_ENABLE0_POS 12 +#define MXC_F_TMR_CTRL_ENABLE0 ((uint32_t)(0x00000001UL << MXC_F_TMR_CTRL_ENABLE0_POS)) +#define MXC_F_TMR_CTRL_ENABLE1_POS 13 +#define MXC_F_TMR_CTRL_ENABLE1 ((uint32_t)(0x00000001UL << MXC_F_TMR_CTRL_ENABLE1_POS)) + +#define MXC_F_TMR_COUNT16_0_VALUE_POS 0 +#define MXC_F_TMR_COUNT16_0_VALUE ((uint32_t)(0x0000FFFFUL << MXC_F_TMR_COUNT16_0_VALUE_POS)) + +#define MXC_F_TMR_TERM_CNT16_0_TERM_COUNT_POS 0 +#define MXC_F_TMR_TERM_CNT16_0_TERM_COUNT ((uint32_t)(0x0000FFFFUL << MXC_F_TMR_TERM_CNT16_0_TERM_COUNT_POS)) + +#define MXC_F_TMR_COUNT16_1_VALUE_POS 0 +#define MXC_F_TMR_COUNT16_1_VALUE ((uint32_t)(0x0000FFFFUL << MXC_F_TMR_COUNT16_1_VALUE_POS)) + +#define MXC_F_TMR_TERM_CNT16_1_TERM_COUNT_POS 0 +#define MXC_F_TMR_TERM_CNT16_1_TERM_COUNT ((uint32_t)(0x0000FFFFUL << MXC_F_TMR_TERM_CNT16_1_TERM_COUNT_POS)) + +#define MXC_F_TMR_INTFL_TIMER0_POS 0 +#define MXC_F_TMR_INTFL_TIMER0 ((uint32_t)(0x00000001UL << MXC_F_TMR_INTFL_TIMER0_POS)) +#define MXC_F_TMR_INTFL_TIMER1_POS 1 +#define MXC_F_TMR_INTFL_TIMER1 ((uint32_t)(0x00000001UL << MXC_F_TMR_INTFL_TIMER1_POS)) + +#define MXC_F_TMR_INTEN_TIMER0_POS 0 +#define MXC_F_TMR_INTEN_TIMER0 ((uint32_t)(0x00000001UL << MXC_F_TMR_INTEN_TIMER0_POS)) +#define MXC_F_TMR_INTEN_TIMER1_POS 1 +#define MXC_F_TMR_INTEN_TIMER1 ((uint32_t)(0x00000001UL << MXC_F_TMR_INTEN_TIMER1_POS)) + + + +/* + Field values and shifted values for module TMR. +*/ + +#define MXC_V_TMR_CTRL_MODE_ONE_SHOT ((uint32_t)(0x00000000UL)) +#define MXC_V_TMR_CTRL_MODE_CONTINUOUS ((uint32_t)(0x00000001UL)) +#define MXC_V_TMR_CTRL_MODE_COUNTER ((uint32_t)(0x00000002UL)) +#define MXC_V_TMR_CTRL_MODE_PWM ((uint32_t)(0x00000003UL)) +#define MXC_V_TMR_CTRL_MODE_CAPTURE ((uint32_t)(0x00000004UL)) +#define MXC_V_TMR_CTRL_MODE_COMPARE ((uint32_t)(0x00000005UL)) +#define MXC_V_TMR_CTRL_MODE_GATED ((uint32_t)(0x00000006UL)) +#define MXC_V_TMR_CTRL_MODE_MEASURE ((uint32_t)(0x00000007UL)) + +#define MXC_S_TMR_CTRL_MODE_ONE_SHOT ((uint32_t)(MXC_V_TMR_CTRL_MODE_ONE_SHOT << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_CONTINUOUS ((uint32_t)(MXC_V_TMR_CTRL_MODE_CONTINUOUS << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_COUNTER ((uint32_t)(MXC_V_TMR_CTRL_MODE_COUNTER << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_PWM ((uint32_t)(MXC_V_TMR_CTRL_MODE_PWM << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_CAPTURE ((uint32_t)(MXC_V_TMR_CTRL_MODE_CAPTURE << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_COMPARE ((uint32_t)(MXC_V_TMR_CTRL_MODE_COMPARE << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_GATED ((uint32_t)(MXC_V_TMR_CTRL_MODE_GATED << MXC_F_TMR_CTRL_MODE_POS)) +#define MXC_S_TMR_CTRL_MODE_MEASURE ((uint32_t)(MXC_V_TMR_CTRL_MODE_MEASURE << MXC_F_TMR_CTRL_MODE_POS)) + +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1 ((uint32_t)(0x00000000UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2 ((uint32_t)(0x00000001UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4 ((uint32_t)(0x00000002UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_8 ((uint32_t)(0x00000003UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_16 ((uint32_t)(0x00000004UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_32 ((uint32_t)(0x00000005UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_64 ((uint32_t)(0x00000006UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_128 ((uint32_t)(0x00000007UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_256 ((uint32_t)(0x00000008UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_512 ((uint32_t)(0x00000009UL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1024 ((uint32_t)(0x0000000AUL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2048 ((uint32_t)(0x0000000BUL)) +#define MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4096 ((uint32_t)(0x0000000CUL)) + +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_1 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_2 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_4 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_8 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_8 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_16 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_16 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_32 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_32 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_64 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_64 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_128 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_128 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_256 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_256 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_512 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_512 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_1024 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1024 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_2048 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2048 << MXC_F_TMR_CTRL_PRESCALE_POS)) +#define MXC_S_TMR_CTRL_PRESCALE_DIVIDE_BY_4096 ((uint32_t)(MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4096 << MXC_F_TMR_CTRL_PRESCALE_POS)) + + +/* + * These two 1-bit fields replace the standard 3-bit mode field when the associated TMR module + * is in dual 16-bit timer mode. + */ + +#define MXC_F_TMR_CTRL_MODE_16_0_POS 0 +#define MXC_F_TMR_CTRL_MODE_16_0 ((uint32_t)(0x00000001UL << MXC_F_TMR_CTRL_MODE_16_0_POS)) + +#define MXC_F_TMR_CTRL_MODE_16_1_POS 1 +#define MXC_F_TMR_CTRL_MODE_16_1 ((uint32_t)(0x00000001UL << MXC_F_TMR_CTRL_MODE_16_1_POS)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_TMR_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/tpu_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/tpu_regs.h new file mode 100644 index 0000000..f115124 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/tpu_regs.h @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_TPU_REGS_H_ +#define _MXC_TPU_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __I uint32_t rsv000[4]; /* 0x0000-0x000C */ + __IO uint32_t sks0; /* 0x0010 TPU Secure Key Storage Register 0 (Cleared on Tamper Detect) */ + __IO uint32_t sks1; /* 0x0014 TPU Secure Key Storage Register 1 (Cleared on Tamper Detect) */ + __IO uint32_t sks2; /* 0x0018 TPU Secure Key Storage Register 2 (Cleared on Tamper Detect) */ + __IO uint32_t sks3; /* 0x001C TPU Secure Key Storage Register 3 (Cleared on Tamper Detect) */ +} mxc_tpu_tsr_regs_t; + + +/* + Register offsets for module TPU. +*/ + +#define MXC_R_TPU_TSR_OFFS_SKS0 ((uint32_t)0x00000010UL) +#define MXC_R_TPU_TSR_OFFS_SKS1 ((uint32_t)0x00000014UL) +#define MXC_R_TPU_TSR_OFFS_SKS2 ((uint32_t)0x00000018UL) +#define MXC_R_TPU_TSR_OFFS_SKS3 ((uint32_t)0x0000001CUL) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_TPU_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/trim_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/trim_regs.h new file mode 100644 index 0000000..fa11fa8 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/trim_regs.h @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_TRIM_REGS_H_ +#define _MXC_TRIM_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __I uint32_t rsv000[10]; /* 0x0000-0x0024 */ + __IO uint32_t reg10_mem_size; /* 0x0028 Shadow Trim for Flash and SRAM Memory Size */ + __IO uint32_t reg11_adc_trim0; /* 0x002C Shadow Trim for ADC R0 */ + __IO uint32_t reg12_adc_trim1; /* 0x0030 Shadow Trim for ADC R1 */ + __IO uint32_t for_pwr_reg5; /* 0x0034 Shadow Trim for PWRSEQ Register REG5 */ + __IO uint32_t for_pwr_reg6; /* 0x0038 Shadow Trim for PWRSEQ Register REG6 */ + __IO uint32_t for_pwr_reg7; /* 0x003C Shadow Trim for PWRSEQ Register REG7 */ +} mxc_trim_regs_t; + + +/* + Register offsets for module TRIM. +*/ + +#define MXC_R_TRIM_OFFS_REG10_MEM_SIZE ((uint32_t)0x00000028UL) +#define MXC_R_TRIM_OFFS_REG11_ADC_TRIM0 ((uint32_t)0x0000002CUL) +#define MXC_R_TRIM_OFFS_REG12_ADC_TRIM1 ((uint32_t)0x00000030UL) +#define MXC_R_TRIM_OFFS_FOR_PWR_REG5 ((uint32_t)0x00000034UL) +#define MXC_R_TRIM_OFFS_FOR_PWR_REG6 ((uint32_t)0x00000038UL) +#define MXC_R_TRIM_OFFS_FOR_PWR_REG7 ((uint32_t)0x0000003CUL) + + +/* + Field positions and masks for module TRIM. +*/ + +#define MXC_F_TRIM_REG10_MEM_SIZE_SRAM_POS 0 +#define MXC_F_TRIM_REG10_MEM_SIZE_SRAM ((uint32_t)(0x00000003UL << MXC_F_TRIM_REG10_MEM_SIZE_SRAM_POS)) +#define MXC_F_TRIM_REG10_MEM_SIZE_FLASH_POS 2 +#define MXC_F_TRIM_REG10_MEM_SIZE_FLASH ((uint32_t)(0x00000007UL << MXC_F_TRIM_REG10_MEM_SIZE_FLASH_POS)) + +#define MXC_V_TRIM_REG10_MEM_SRAM_FULL_SIZE ((uint32_t)(0x00000000UL)) +#define MXC_V_TRIM_REG10_MEM_SRAM_THREE_FOURTHS_SIZE ((uint32_t)(0x00000001UL)) +#define MXC_V_TRIM_REG10_MEM_SRAM_HALF_SIZE ((uint32_t)(0x00000002UL)) + +#define MXC_V_TRIM_REG10_MEM_FLASH_FULL_SIZE ((uint32_t)(0x00000000UL)) +#define MXC_V_TRIM_REG10_MEM_FLASH_THREE_FOURTHS_SIZE ((uint32_t)(0x00000001UL)) +#define MXC_V_TRIM_REG10_MEM_FLASH_HALF_SIZE ((uint32_t)(0x00000002UL)) +#define MXC_V_TRIM_REG10_MEM_FLASH_THREE_EIGHTHS_SIZE ((uint32_t)(0x00000003UL)) +#define MXC_V_TRIM_REG10_MEM_FLASH_FOURTH_SIZE ((uint32_t)(0x00000004UL)) + +#define MXC_F_TRIM_REG11_ADC_TRIM0_ADCTRIM_X0R0_POS 0 +#define MXC_F_TRIM_REG11_ADC_TRIM0_ADCTRIM_X0R0 ((uint32_t)(0x000003FFUL << MXC_F_TRIM_REG11_ADC_TRIM0_ADCTRIM_X0R0_POS)) +#define MXC_F_TRIM_REG11_ADC_TRIM0_ADCTRIM_X1R0_POS 16 +#define MXC_F_TRIM_REG11_ADC_TRIM0_ADCTRIM_X1R0 ((uint32_t)(0x000003FFUL << MXC_F_TRIM_REG11_ADC_TRIM0_ADCTRIM_X1R0_POS)) + +#define MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_X0R1_POS 0 +#define MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_X0R1 ((uint32_t)(0x000003FFUL << MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_X0R1_POS)) +#define MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_X1R1_POS 16 +#define MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_X1R1 ((uint32_t)(0x000003FFUL << MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_X1R1_POS)) +#define MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_DC_POS 28 +#define MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_DC ((uint32_t)(0x0000000FUL << MXC_F_TRIM_REG12_ADC_TRIM1_ADCTRIM_DC_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_TRIM_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/uart_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/uart_regs.h new file mode 100644 index 0000000..df320ea --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/uart_regs.h @@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_UART_REGS_H_ +#define _MXC_UART_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 UART Control Register */ + __IO uint32_t baud; /* 0x0004 UART Baud Control Register */ + __IO uint32_t tx_fifo_ctrl; /* 0x0008 UART TX FIFO Control Register */ + __IO uint32_t rx_fifo_ctrl; /* 0x000C UART RX FIFO Control Register */ + __IO uint32_t md_ctrl; /* 0x0010 UART Multidrop Control Register */ + __IO uint32_t intfl; /* 0x0014 UART Interrupt Flags */ + __IO uint32_t inten; /* 0x0018 UART Interrupt Enable/Disable Controls */ +#if (MXC_UART_REV > 0) + __I uint32_t idle; /* 0x001C UART Idle Status */ +#endif +} mxc_uart_regs_t; + + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + union { /* 0x0000-0x07FC FIFO Write Point for Data to Transmit */ + __IO uint8_t tx; + __IO uint8_t tx_8[2048]; + __IO uint16_t tx_16[1024]; + __IO uint32_t tx_32[512]; + }; + union { /* 0x0800-0x0FFC FIFO Read Point for Received Data */ + __IO uint8_t rx; + __IO uint8_t rx_8[2048]; + __IO uint16_t rx_16[1024]; + __IO uint32_t rx_32[512]; + }; +} mxc_uart_fifo_regs_t; + + +/* + Register offsets for module UART. +*/ + +#define MXC_R_UART_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_UART_OFFS_BAUD ((uint32_t)0x00000004UL) +#define MXC_R_UART_OFFS_TX_FIFO_CTRL ((uint32_t)0x00000008UL) +#define MXC_R_UART_OFFS_RX_FIFO_CTRL ((uint32_t)0x0000000CUL) +#define MXC_R_UART_OFFS_MD_CTRL ((uint32_t)0x00000010UL) +#define MXC_R_UART_OFFS_INTFL ((uint32_t)0x00000014UL) +#define MXC_R_UART_OFFS_INTEN ((uint32_t)0x00000018UL) +#define MXC_R_UART_FIFO_OFFS_TX ((uint32_t)0x00000000UL) +#define MXC_R_UART_FIFO_OFFS_RX ((uint32_t)0x00000800UL) + + +/* + Field positions and masks for module UART. +*/ + +#define MXC_F_UART_CTRL_UART_EN_POS 0 +#define MXC_F_UART_CTRL_UART_EN ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_UART_EN_POS)) +#define MXC_F_UART_CTRL_RX_FIFO_EN_POS 1 +#define MXC_F_UART_CTRL_RX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_RX_FIFO_EN_POS)) +#define MXC_F_UART_CTRL_TX_FIFO_EN_POS 2 +#define MXC_F_UART_CTRL_TX_FIFO_EN ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_TX_FIFO_EN_POS)) +#define MXC_F_UART_CTRL_DATA_SIZE_POS 4 +#define MXC_F_UART_CTRL_DATA_SIZE ((uint32_t)(0x00000003UL << MXC_F_UART_CTRL_DATA_SIZE_POS)) +#define MXC_F_UART_CTRL_EXTRA_STOP_POS 8 +#define MXC_F_UART_CTRL_EXTRA_STOP ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_EXTRA_STOP_POS)) +#define MXC_F_UART_CTRL_PARITY_POS 12 +#define MXC_F_UART_CTRL_PARITY ((uint32_t)(0x00000003UL << MXC_F_UART_CTRL_PARITY_POS)) +#define MXC_F_UART_CTRL_CTS_EN_POS 16 +#define MXC_F_UART_CTRL_CTS_EN ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_CTS_EN_POS)) +#define MXC_F_UART_CTRL_CTS_POLARITY_POS 17 +#define MXC_F_UART_CTRL_CTS_POLARITY ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_CTS_POLARITY_POS)) +#define MXC_F_UART_CTRL_RTS_EN_POS 18 +#define MXC_F_UART_CTRL_RTS_EN ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_RTS_EN_POS)) +#define MXC_F_UART_CTRL_RTS_POLARITY_POS 19 +#define MXC_F_UART_CTRL_RTS_POLARITY ((uint32_t)(0x00000001UL << MXC_F_UART_CTRL_RTS_POLARITY_POS)) +#define MXC_F_UART_CTRL_RTS_LEVEL_POS 20 +#define MXC_F_UART_CTRL_RTS_LEVEL ((uint32_t)(0x0000003FUL << MXC_F_UART_CTRL_RTS_LEVEL_POS)) + +#define MXC_F_UART_BAUD_BAUD_DIVISOR_POS 0 +#define MXC_F_UART_BAUD_BAUD_DIVISOR ((uint32_t)(0x000000FFUL << MXC_F_UART_BAUD_BAUD_DIVISOR_POS)) +#define MXC_F_UART_BAUD_BAUD_MODE_POS 8 +#define MXC_F_UART_BAUD_BAUD_MODE ((uint32_t)(0x00000003UL << MXC_F_UART_BAUD_BAUD_MODE_POS)) + +#define MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY_POS 0 +#define MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY ((uint32_t)(0x0000003FUL << MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY_POS)) +#define MXC_F_UART_TX_FIFO_CTRL_FIFO_AE_LVL_POS 16 +#define MXC_F_UART_TX_FIFO_CTRL_FIFO_AE_LVL ((uint32_t)(0x0000001FUL << MXC_F_UART_TX_FIFO_CTRL_FIFO_AE_LVL_POS)) + +#define MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY_POS 0 +#define MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY ((uint32_t)(0x0000003FUL << MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY_POS)) +#define MXC_F_UART_RX_FIFO_CTRL_FIFO_AF_LVL_POS 16 +#define MXC_F_UART_RX_FIFO_CTRL_FIFO_AF_LVL ((uint32_t)(0x0000001FUL << MXC_F_UART_RX_FIFO_CTRL_FIFO_AF_LVL_POS)) + +#define MXC_F_UART_MD_CTRL_SLAVE_ADDR_POS 0 +#define MXC_F_UART_MD_CTRL_SLAVE_ADDR ((uint32_t)(0x000000FFUL << MXC_F_UART_MD_CTRL_SLAVE_ADDR_POS)) +#define MXC_F_UART_MD_CTRL_SLAVE_ADDR_MSK_POS 8 +#define MXC_F_UART_MD_CTRL_SLAVE_ADDR_MSK ((uint32_t)(0x000000FFUL << MXC_F_UART_MD_CTRL_SLAVE_ADDR_MSK_POS)) +#define MXC_F_UART_MD_CTRL_MD_MSTR_POS 16 +#define MXC_F_UART_MD_CTRL_MD_MSTR ((uint32_t)(0x00000001UL << MXC_F_UART_MD_CTRL_MD_MSTR_POS)) +#define MXC_F_UART_MD_CTRL_TX_ADDR_MARK_POS 17 +#define MXC_F_UART_MD_CTRL_TX_ADDR_MARK ((uint32_t)(0x00000001UL << MXC_F_UART_MD_CTRL_TX_ADDR_MARK_POS)) + +#define MXC_F_UART_INTFL_TX_DONE_POS 0 +#define MXC_F_UART_INTFL_TX_DONE ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_TX_DONE_POS)) +#define MXC_F_UART_INTFL_TX_UNSTALLED_POS 1 +#define MXC_F_UART_INTFL_TX_UNSTALLED ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_TX_UNSTALLED_POS)) +#define MXC_F_UART_INTFL_TX_FIFO_AE_POS 2 +#define MXC_F_UART_INTFL_TX_FIFO_AE ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_TX_FIFO_AE_POS)) +#define MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY_POS 3 +#define MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY_POS)) +#define MXC_F_UART_INTFL_RX_STALLED_POS 4 +#define MXC_F_UART_INTFL_RX_STALLED ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_RX_STALLED_POS)) +#define MXC_F_UART_INTFL_RX_FIFO_AF_POS 5 +#define MXC_F_UART_INTFL_RX_FIFO_AF ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_RX_FIFO_AF_POS)) +#define MXC_F_UART_INTFL_RX_FIFO_OVERFLOW_POS 6 +#define MXC_F_UART_INTFL_RX_FIFO_OVERFLOW ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_RX_FIFO_OVERFLOW_POS)) +#define MXC_F_UART_INTFL_RX_FRAMING_ERR_POS 7 +#define MXC_F_UART_INTFL_RX_FRAMING_ERR ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_RX_FRAMING_ERR_POS)) +#define MXC_F_UART_INTFL_RX_PARITY_ERR_POS 8 +#define MXC_F_UART_INTFL_RX_PARITY_ERR ((uint32_t)(0x00000001UL << MXC_F_UART_INTFL_RX_PARITY_ERR_POS)) + +#define MXC_F_UART_INTEN_TX_DONE_POS 0 +#define MXC_F_UART_INTEN_TX_DONE ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_TX_DONE_POS)) +#define MXC_F_UART_INTEN_TX_UNSTALLED_POS 1 +#define MXC_F_UART_INTEN_TX_UNSTALLED ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_TX_UNSTALLED_POS)) +#define MXC_F_UART_INTEN_TX_FIFO_AE_POS 2 +#define MXC_F_UART_INTEN_TX_FIFO_AE ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_TX_FIFO_AE_POS)) +#define MXC_F_UART_INTEN_RX_FIFO_NOT_EMPTY_POS 3 +#define MXC_F_UART_INTEN_RX_FIFO_NOT_EMPTY ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_RX_FIFO_NOT_EMPTY_POS)) +#define MXC_F_UART_INTEN_RX_STALLED_POS 4 +#define MXC_F_UART_INTEN_RX_STALLED ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_RX_STALLED_POS)) +#define MXC_F_UART_INTEN_RX_FIFO_AF_POS 5 +#define MXC_F_UART_INTEN_RX_FIFO_AF ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_RX_FIFO_AF_POS)) +#define MXC_F_UART_INTEN_RX_FIFO_OVERFLOW_POS 6 +#define MXC_F_UART_INTEN_RX_FIFO_OVERFLOW ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_RX_FIFO_OVERFLOW_POS)) +#define MXC_F_UART_INTEN_RX_FRAMING_ERR_POS 7 +#define MXC_F_UART_INTEN_RX_FRAMING_ERR ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_RX_FRAMING_ERR_POS)) +#define MXC_F_UART_INTEN_RX_PARITY_ERR_POS 8 +#define MXC_F_UART_INTEN_RX_PARITY_ERR ((uint32_t)(0x00000001UL << MXC_F_UART_INTEN_RX_PARITY_ERR_POS)) + +#if (MXC_UART_REV > 0) +#define MXC_F_UART_IDLE_TX_RX_IDLE_POS 0 +#define MXC_F_UART_IDLE_TX_RX_IDLE ((uint32_t)(0x00000001UL << MXC_F_UART_IDLE_TX_RX_IDLE_POS)) +#define MXC_F_UART_IDLE_TX_IDLE_POS 1 +#define MXC_F_UART_IDLE_TX_IDLE ((uint32_t)(0x00000001UL << MXC_F_UART_IDLE_TX_IDLE_POS)) +#define MXC_F_UART_IDLE_RX_IDLE_POS 2 +#define MXC_F_UART_IDLE_RX_IDLE ((uint32_t)(0x00000001UL << MXC_F_UART_IDLE_RX_IDLE_POS)) +#endif + +/* + Field values and shifted values for module UART. +*/ + +#define MXC_V_UART_CTRL_DATA_SIZE_5_BITS ((uint32_t)(0x00000000UL)) +#define MXC_V_UART_CTRL_DATA_SIZE_6_BITS ((uint32_t)(0x00000001UL)) +#define MXC_V_UART_CTRL_DATA_SIZE_7_BITS ((uint32_t)(0x00000002UL)) +#define MXC_V_UART_CTRL_DATA_SIZE_8_BITS ((uint32_t)(0x00000003UL)) + +#define MXC_S_UART_CTRL_DATA_SIZE_5_BITS ((uint32_t)(MXC_V_UART_CTRL_DATA_SIZE_5_BITS << MXC_F_UART_CTRL_DATA_SIZE_POS)) +#define MXC_S_UART_CTRL_DATA_SIZE_6_BITS ((uint32_t)(MXC_V_UART_CTRL_DATA_SIZE_6_BITS << MXC_F_UART_CTRL_DATA_SIZE_POS)) +#define MXC_S_UART_CTRL_DATA_SIZE_7_BITS ((uint32_t)(MXC_V_UART_CTRL_DATA_SIZE_7_BITS << MXC_F_UART_CTRL_DATA_SIZE_POS)) +#define MXC_S_UART_CTRL_DATA_SIZE_8_BITS ((uint32_t)(MXC_V_UART_CTRL_DATA_SIZE_8_BITS << MXC_F_UART_CTRL_DATA_SIZE_POS)) + +#define MXC_V_UART_CTRL_PARITY_DISABLE ((uint32_t)(0x00000000UL)) +#define MXC_V_UART_CTRL_PARITY_ODD ((uint32_t)(0x00000001UL)) +#define MXC_V_UART_CTRL_PARITY_EVEN ((uint32_t)(0x00000002UL)) +#define MXC_V_UART_CTRL_PARITY_MARK ((uint32_t)(0x00000003UL)) + +#define MXC_S_UART_CTRL_PARITY_DISABLE ((uint32_t)(MXC_V_UART_CTRL_PARITY_DISABLE << MXC_F_UART_CTRL_PARITY_POS)) +#define MXC_S_UART_CTRL_PARITY_ODD ((uint32_t)(MXC_V_UART_CTRL_PARITY_ODD << MXC_F_UART_CTRL_PARITY_POS)) +#define MXC_S_UART_CTRL_PARITY_EVEN ((uint32_t)(MXC_V_UART_CTRL_PARITY_EVEN << MXC_F_UART_CTRL_PARITY_POS)) +#define MXC_S_UART_CTRL_PARITY_MARK ((uint32_t)(MXC_V_UART_CTRL_PARITY_MARK << MXC_F_UART_CTRL_PARITY_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_UART_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/usb_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/usb_regs.h new file mode 100644 index 0000000..c764445 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/usb_regs.h @@ -0,0 +1,293 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_USB_REGS_H_ +#define _MXC_USB_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +#define MXC_V_USB_EP_DIR_DISABLE ((uint32_t)0x00000000UL) +#define MXC_V_USB_EP_DIR_OUT ((uint32_t)0x00000001UL) +#define MXC_V_USB_EP_DIR_IN ((uint32_t)0x00000002UL) +#define MXC_V_USB_EP_DIR_CONTROL ((uint32_t)0x00000003UL) + +#define MXC_S_USB_EP_DIR_DISABLE (MXC_V_USB_EP_DIR_DISABLE << MXC_F_USB_EP_DIR_POS) +#define MXC_S_USB_EP_DIR_OUT (MXC_V_USB_EP_DIR_OUT << MXC_F_USB_EP_DIR_POS) +#define MXC_S_USB_EP_DIR_IN (MXC_V_USB_EP_DIR_IN << MXC_F_USB_EP_DIR_POS) +#define MXC_S_USB_EP_DIR_CONTROL (MXC_V_USB_EP_DIR_CONTROL << MXC_F_USB_EP_DIR_POS) + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t cn; /* 0x0000 USB Control Register */ + __I uint32_t rsv004[127]; /* 0x0004-0x01FC */ + __IO uint32_t dev_addr; /* 0x0200 USB Device Address Register */ + __IO uint32_t dev_cn; /* 0x0204 USB Device Control Register */ + __IO uint32_t dev_intfl; /* 0x0208 USB Device Interrupt */ + __IO uint32_t dev_inten; /* 0x020C USB Device Interrupt Enable */ + __I uint32_t rsv210[4]; /* 0x0210-0x021C */ + __IO uint32_t ep_base; /* 0x0220 USB Endpoint Descriptor Table Base Address */ + __IO uint32_t cur_buf; /* 0x0224 USB Current Endpoint Buffer Register */ + __IO uint32_t in_owner; /* 0x0228 USB IN Endpoint Buffer Owner Register */ + __IO uint32_t out_owner; /* 0x022C USB OUT Endpoint Buffer Owner Register */ + __IO uint32_t in_int; /* 0x0230 USB IN Endpoint Buffer Available Interrupt */ + __IO uint32_t out_int; /* 0x0234 USB OUT Endpoint Data Available Interrupt */ + __IO uint32_t nak_int; /* 0x0238 USB IN Endpoint NAK Interrupt */ + __IO uint32_t dma_err_int; /* 0x023C USB DMA Error Interrupt */ + __IO uint32_t buf_ovr_int; /* 0x0240 USB Buffer Overflow Interrupt */ + __I uint32_t rsv244[7]; /* 0x0244-0x025C */ + __IO uint32_t setup0; /* 0x0260 USB SETUP Packet Bytes 0 to 3 */ + __IO uint32_t setup1; /* 0x0264 USB SETUP Packet Bytes 4 to 7 */ + __I uint32_t rsv268[6]; /* 0x0268-0x027C */ + __IO uint32_t ep[8]; /* 0x0280-0x029C USB Endpoint[n] Control Register */ +} mxc_usb_regs_t; + + +/* + Register offsets for module USB. +*/ + +#define MXC_R_USB_OFFS_CN ((uint32_t)0x00000000UL) +#define MXC_R_USB_OFFS_DEV_ADDR ((uint32_t)0x00000200UL) +#define MXC_R_USB_OFFS_DEV_CN ((uint32_t)0x00000204UL) +#define MXC_R_USB_OFFS_DEV_INTFL ((uint32_t)0x00000208UL) +#define MXC_R_USB_OFFS_DEV_INTEN ((uint32_t)0x0000020CUL) +#define MXC_R_USB_OFFS_EP_BASE ((uint32_t)0x00000220UL) +#define MXC_R_USB_OFFS_CUR_BUF ((uint32_t)0x00000224UL) +#define MXC_R_USB_OFFS_IN_OWNER ((uint32_t)0x00000228UL) +#define MXC_R_USB_OFFS_OUT_OWNER ((uint32_t)0x0000022CUL) +#define MXC_R_USB_OFFS_IN_INT ((uint32_t)0x00000230UL) +#define MXC_R_USB_OFFS_OUT_INT ((uint32_t)0x00000234UL) +#define MXC_R_USB_OFFS_NAK_INT ((uint32_t)0x00000238UL) +#define MXC_R_USB_OFFS_DMA_ERR_INT ((uint32_t)0x0000023CUL) +#define MXC_R_USB_OFFS_BUF_OVR_INT ((uint32_t)0x00000240UL) +#define MXC_R_USB_OFFS_SETUP0 ((uint32_t)0x00000260UL) +#define MXC_R_USB_OFFS_SETUP1 ((uint32_t)0x00000264UL) +#define MXC_R_USB_OFFS_EP0 ((uint32_t)0x00000280UL) +#define MXC_R_USB_OFFS_EP1 ((uint32_t)0x00000284UL) +#define MXC_R_USB_OFFS_EP2 ((uint32_t)0x00000288UL) +#define MXC_R_USB_OFFS_EP3 ((uint32_t)0x0000028CUL) +#define MXC_R_USB_OFFS_EP4 ((uint32_t)0x00000290UL) +#define MXC_R_USB_OFFS_EP5 ((uint32_t)0x00000294UL) +#define MXC_R_USB_OFFS_EP6 ((uint32_t)0x00000298UL) +#define MXC_R_USB_OFFS_EP7 ((uint32_t)0x0000029CUL) + + +/* + Field positions and masks for module USB. +*/ + +#define MXC_F_USB_CN_USB_EN_POS 0 +#define MXC_F_USB_CN_USB_EN ((uint32_t)(0x00000001UL << MXC_F_USB_CN_USB_EN_POS)) +#define MXC_F_USB_CN_HOST_POS 1 +#define MXC_F_USB_CN_HOST ((uint32_t)(0x00000001UL << MXC_F_USB_CN_HOST_POS)) + +#define MXC_F_USB_DEV_ADDR_DEV_ADDR_POS 0 +#define MXC_F_USB_DEV_ADDR_DEV_ADDR ((uint32_t)(0x0000007FUL << MXC_F_USB_DEV_ADDR_DEV_ADDR_POS)) + +#define MXC_F_USB_DEV_CN_SIGRWU_POS 2 +#define MXC_F_USB_DEV_CN_SIGRWU ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_SIGRWU_POS)) +#define MXC_F_USB_DEV_CN_CONNECT_POS 3 +#define MXC_F_USB_DEV_CN_CONNECT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_CONNECT_POS)) +#define MXC_F_USB_DEV_CN_ULPM_POS 4 +#define MXC_F_USB_DEV_CN_ULPM ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_ULPM_POS)) +#define MXC_F_USB_DEV_CN_URST_POS 5 +#define MXC_F_USB_DEV_CN_URST ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_URST_POS)) +#define MXC_F_USB_DEV_CN_VBGATE_POS 6 +#define MXC_F_USB_DEV_CN_VBGATE ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_VBGATE_POS)) +#define MXC_F_USB_DEV_CN_OSCEN_POS 7 +#define MXC_F_USB_DEV_CN_OSCEN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_OSCEN_POS)) +#define MXC_F_USB_DEV_CN_BACT_OE_POS 8 +#define MXC_F_USB_DEV_CN_BACT_OE ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_BACT_OE_POS)) +#define MXC_F_USB_DEV_CN_FIFO_MODE_POS 9 +#define MXC_F_USB_DEV_CN_FIFO_MODE ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_CN_FIFO_MODE_POS)) + +#define MXC_F_USB_DEV_INTFL_DPACT_POS 0 +#define MXC_F_USB_DEV_INTFL_DPACT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_DPACT_POS)) +#define MXC_F_USB_DEV_INTFL_RWU_DN_POS 1 +#define MXC_F_USB_DEV_INTFL_RWU_DN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_RWU_DN_POS)) +#define MXC_F_USB_DEV_INTFL_BACT_POS 2 +#define MXC_F_USB_DEV_INTFL_BACT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_BACT_POS)) +#define MXC_F_USB_DEV_INTFL_BRST_POS 3 +#define MXC_F_USB_DEV_INTFL_BRST ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_BRST_POS)) +#define MXC_F_USB_DEV_INTFL_SUSP_POS 4 +#define MXC_F_USB_DEV_INTFL_SUSP ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_SUSP_POS)) +#define MXC_F_USB_DEV_INTFL_NO_VBUS_POS 5 +#define MXC_F_USB_DEV_INTFL_NO_VBUS ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_NO_VBUS_POS)) +#define MXC_F_USB_DEV_INTFL_VBUS_POS 6 +#define MXC_F_USB_DEV_INTFL_VBUS ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_VBUS_POS)) +#define MXC_F_USB_DEV_INTFL_BRST_DN_POS 7 +#define MXC_F_USB_DEV_INTFL_BRST_DN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_BRST_DN_POS)) +#define MXC_F_USB_DEV_INTFL_SETUP_POS 8 +#define MXC_F_USB_DEV_INTFL_SETUP ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_SETUP_POS)) +#define MXC_F_USB_DEV_INTFL_EP_IN_POS 9 +#define MXC_F_USB_DEV_INTFL_EP_IN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_EP_IN_POS)) +#define MXC_F_USB_DEV_INTFL_EP_OUT_POS 10 +#define MXC_F_USB_DEV_INTFL_EP_OUT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_EP_OUT_POS)) +#define MXC_F_USB_DEV_INTFL_EP_NAK_POS 11 +#define MXC_F_USB_DEV_INTFL_EP_NAK ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_EP_NAK_POS)) +#define MXC_F_USB_DEV_INTFL_DMA_ERR_POS 12 +#define MXC_F_USB_DEV_INTFL_DMA_ERR ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_DMA_ERR_POS)) +#define MXC_F_USB_DEV_INTFL_BUF_OVR_POS 13 +#define MXC_F_USB_DEV_INTFL_BUF_OVR ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_BUF_OVR_POS)) +#define MXC_F_USB_DEV_INTFL_VBUS_ST_POS 16 +#define MXC_F_USB_DEV_INTFL_VBUS_ST ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTFL_VBUS_ST_POS)) + +#define MXC_F_USB_DEV_INTEN_DPACT_POS 0 +#define MXC_F_USB_DEV_INTEN_DPACT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_DPACT_POS)) +#define MXC_F_USB_DEV_INTEN_RWU_DN_POS 1 +#define MXC_F_USB_DEV_INTEN_RWU_DN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_RWU_DN_POS)) +#define MXC_F_USB_DEV_INTEN_BACT_POS 2 +#define MXC_F_USB_DEV_INTEN_BACT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_BACT_POS)) +#define MXC_F_USB_DEV_INTEN_BRST_POS 3 +#define MXC_F_USB_DEV_INTEN_BRST ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_BRST_POS)) +#define MXC_F_USB_DEV_INTEN_SUSP_POS 4 +#define MXC_F_USB_DEV_INTEN_SUSP ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_SUSP_POS)) +#define MXC_F_USB_DEV_INTEN_NO_VBUS_POS 5 +#define MXC_F_USB_DEV_INTEN_NO_VBUS ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_NO_VBUS_POS)) +#define MXC_F_USB_DEV_INTEN_VBUS_POS 6 +#define MXC_F_USB_DEV_INTEN_VBUS ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_VBUS_POS)) +#define MXC_F_USB_DEV_INTEN_BRST_DN_POS 7 +#define MXC_F_USB_DEV_INTEN_BRST_DN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_BRST_DN_POS)) +#define MXC_F_USB_DEV_INTEN_SETUP_POS 8 +#define MXC_F_USB_DEV_INTEN_SETUP ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_SETUP_POS)) +#define MXC_F_USB_DEV_INTEN_EP_IN_POS 9 +#define MXC_F_USB_DEV_INTEN_EP_IN ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_EP_IN_POS)) +#define MXC_F_USB_DEV_INTEN_EP_OUT_POS 10 +#define MXC_F_USB_DEV_INTEN_EP_OUT ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_EP_OUT_POS)) +#define MXC_F_USB_DEV_INTEN_EP_NAK_POS 11 +#define MXC_F_USB_DEV_INTEN_EP_NAK ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_EP_NAK_POS)) +#define MXC_F_USB_DEV_INTEN_DMA_ERR_POS 12 +#define MXC_F_USB_DEV_INTEN_DMA_ERR ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_DMA_ERR_POS)) +#define MXC_F_USB_DEV_INTEN_BUF_OVR_POS 13 +#define MXC_F_USB_DEV_INTEN_BUF_OVR ((uint32_t)(0x00000001UL << MXC_F_USB_DEV_INTEN_BUF_OVR_POS)) + +#define MXC_F_USB_EP_BASE_EP_BASE_POS 9 +#define MXC_F_USB_EP_BASE_EP_BASE ((uint32_t)(0x007FFFFFUL << MXC_F_USB_EP_BASE_EP_BASE_POS)) + +#define MXC_F_USB_CUR_BUF_OUT_BUF_POS 0 +#define MXC_F_USB_CUR_BUF_OUT_BUF ((uint32_t)(0x0000FFFFUL << MXC_F_USB_CUR_BUF_OUT_BUF_POS)) +#define MXC_F_USB_CUR_BUF_IN_BUF_POS 16 +#define MXC_F_USB_CUR_BUF_IN_BUF ((uint32_t)(0x0000FFFFUL << MXC_F_USB_CUR_BUF_IN_BUF_POS)) + +#define MXC_F_USB_IN_OWNER_BUF0_OWNER_POS 0 +#define MXC_F_USB_IN_OWNER_BUF0_OWNER ((uint32_t)(0x0000FFFFUL << MXC_F_USB_IN_OWNER_BUF0_OWNER_POS)) +#define MXC_F_USB_IN_OWNER_BUF1_OWNER_POS 16 +#define MXC_F_USB_IN_OWNER_BUF1_OWNER ((uint32_t)(0x0000FFFFUL << MXC_F_USB_IN_OWNER_BUF1_OWNER_POS)) + +#define MXC_F_USB_OUT_OWNER_BUF0_OWNER_POS 0 +#define MXC_F_USB_OUT_OWNER_BUF0_OWNER ((uint32_t)(0x0000FFFFUL << MXC_F_USB_OUT_OWNER_BUF0_OWNER_POS)) +#define MXC_F_USB_OUT_OWNER_BUF1_OWNER_POS 16 +#define MXC_F_USB_OUT_OWNER_BUF1_OWNER ((uint32_t)(0x0000FFFFUL << MXC_F_USB_OUT_OWNER_BUF1_OWNER_POS)) + +#define MXC_F_USB_IN_INT_INBAV_POS 0 +#define MXC_F_USB_IN_INT_INBAV ((uint32_t)(0x000000FFUL << MXC_F_USB_IN_INT_INBAV_POS)) + +#define MXC_F_USB_OUT_INT_OUTDAV_POS 0 +#define MXC_F_USB_OUT_INT_OUTDAV ((uint32_t)(0x000000FFUL << MXC_F_USB_OUT_INT_OUTDAV_POS)) + +#define MXC_F_USB_NAK_INT_NAK_POS 0 +#define MXC_F_USB_NAK_INT_NAK ((uint32_t)(0x000000FFUL << MXC_F_USB_NAK_INT_NAK_POS)) + +#define MXC_F_USB_DMA_ERR_INT_DMA_ERR_POS 0 +#define MXC_F_USB_DMA_ERR_INT_DMA_ERR ((uint32_t)(0x000000FFUL << MXC_F_USB_DMA_ERR_INT_DMA_ERR_POS)) + +#define MXC_F_USB_BUF_OVR_INT_BUF_OVR_POS 0 +#define MXC_F_USB_BUF_OVR_INT_BUF_OVR ((uint32_t)(0x000000FFUL << MXC_F_USB_BUF_OVR_INT_BUF_OVR_POS)) + +#define MXC_F_USB_SETUP0_BYTE0_POS 0 +#define MXC_F_USB_SETUP0_BYTE0 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP0_BYTE0_POS)) +#define MXC_F_USB_SETUP0_BYTE1_POS 8 +#define MXC_F_USB_SETUP0_BYTE1 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP0_BYTE1_POS)) +#define MXC_F_USB_SETUP0_BYTE2_POS 16 +#define MXC_F_USB_SETUP0_BYTE2 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP0_BYTE2_POS)) +#define MXC_F_USB_SETUP0_BYTE3_POS 24 +#define MXC_F_USB_SETUP0_BYTE3 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP0_BYTE3_POS)) + +#define MXC_F_USB_SETUP1_BYTE0_POS 0 +#define MXC_F_USB_SETUP1_BYTE0 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP1_BYTE0_POS)) +#define MXC_F_USB_SETUP1_BYTE1_POS 8 +#define MXC_F_USB_SETUP1_BYTE1 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP1_BYTE1_POS)) +#define MXC_F_USB_SETUP1_BYTE2_POS 16 +#define MXC_F_USB_SETUP1_BYTE2 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP1_BYTE2_POS)) +#define MXC_F_USB_SETUP1_BYTE3_POS 24 +#define MXC_F_USB_SETUP1_BYTE3 ((uint32_t)(0x000000FFUL << MXC_F_USB_SETUP1_BYTE3_POS)) + +#define MXC_F_USB_EP_DIR_POS 0 +#define MXC_F_USB_EP_DIR ((uint32_t)(0x00000003UL << MXC_F_USB_EP_DIR_POS)) +#define MXC_F_USB_EP_BUF2_POS 3 +#define MXC_F_USB_EP_BUF2 ((uint32_t)(0x00000001UL << MXC_F_USB_EP_BUF2_POS)) +#define MXC_F_USB_EP_INT_EN_POS 4 +#define MXC_F_USB_EP_INT_EN ((uint32_t)(0x00000001UL << MXC_F_USB_EP_INT_EN_POS)) +#define MXC_F_USB_EP_NAK_EN_POS 5 +#define MXC_F_USB_EP_NAK_EN ((uint32_t)(0x00000001UL << MXC_F_USB_EP_NAK_EN_POS)) +#define MXC_F_USB_EP_DT_POS 6 +#define MXC_F_USB_EP_DT ((uint32_t)(0x00000001UL << MXC_F_USB_EP_DT_POS)) +#define MXC_F_USB_EP_STALL_POS 8 +#define MXC_F_USB_EP_STALL ((uint32_t)(0x00000001UL << MXC_F_USB_EP_STALL_POS)) +#define MXC_F_USB_EP_ST_STALL_POS 9 +#define MXC_F_USB_EP_ST_STALL ((uint32_t)(0x00000001UL << MXC_F_USB_EP_ST_STALL_POS)) +#define MXC_F_USB_EP_ST_ACK_POS 10 +#define MXC_F_USB_EP_ST_ACK ((uint32_t)(0x00000001UL << MXC_F_USB_EP_ST_ACK_POS)) + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_USB_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/wdt2_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/wdt2_regs.h new file mode 100644 index 0000000..6bfd4de --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/wdt2_regs.h @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_WDT2_REGS_H_ +#define _MXC_WDT2_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 Watchdog Timer 2 Control Register */ + __IO uint32_t clear; /* 0x0004 Watchdog Timer 2 Clear Register (Feed Dog) */ + __IO uint32_t flags; /* 0x0008 Watchdog Timer 2 Interrupt and Reset Flags */ + __IO uint32_t enable; /* 0x000C Watchdog Timer 2 Interrupt/Reset Enable/Disable Controls */ + __I uint32_t rsv010; /* 0x0010 */ + __IO uint32_t lock_ctrl; /* 0x0014 Watchdog Timer 2 Register Setting Lock for Control Register */ +} mxc_wdt2_regs_t; + + +/* + Register offsets for module WDT2. +*/ + +#define MXC_R_WDT2_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_WDT2_OFFS_CLEAR ((uint32_t)0x00000004UL) +#define MXC_R_WDT2_OFFS_FLAGS ((uint32_t)0x00000008UL) +#define MXC_R_WDT2_OFFS_ENABLE ((uint32_t)0x0000000CUL) +#define MXC_R_WDT2_OFFS_LOCK_CTRL ((uint32_t)0x00000014UL) + + +/* + Field positions and masks for module WDT2. +*/ + +#define MXC_F_WDT2_CTRL_INT_PERIOD_POS 0 +#define MXC_F_WDT2_CTRL_INT_PERIOD ((uint32_t)(0x0000000FUL << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_F_WDT2_CTRL_RST_PERIOD_POS 4 +#define MXC_F_WDT2_CTRL_RST_PERIOD ((uint32_t)(0x0000000FUL << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_F_WDT2_CTRL_EN_TIMER_POS 8 +#define MXC_F_WDT2_CTRL_EN_TIMER ((uint32_t)(0x00000001UL << MXC_F_WDT2_CTRL_EN_TIMER_POS)) +#define MXC_F_WDT2_CTRL_EN_CLOCK_POS 9 +#define MXC_F_WDT2_CTRL_EN_CLOCK ((uint32_t)(0x00000001UL << MXC_F_WDT2_CTRL_EN_CLOCK_POS)) +#define MXC_F_WDT2_CTRL_EN_TIMER_SLP_POS 10 +#define MXC_F_WDT2_CTRL_EN_TIMER_SLP ((uint32_t)(0x00000001UL << MXC_F_WDT2_CTRL_EN_TIMER_SLP_POS)) + +#define MXC_F_WDT2_FLAGS_TIMEOUT_POS 0 +#define MXC_F_WDT2_FLAGS_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_WDT2_FLAGS_TIMEOUT_POS)) +#define MXC_F_WDT2_FLAGS_RESET_OUT_POS 2 +#define MXC_F_WDT2_FLAGS_RESET_OUT ((uint32_t)(0x00000001UL << MXC_F_WDT2_FLAGS_RESET_OUT_POS)) + +#define MXC_F_WDT2_ENABLE_TIMEOUT_POS 0 +#define MXC_F_WDT2_ENABLE_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_WDT2_ENABLE_TIMEOUT_POS)) +#define MXC_F_WDT2_ENABLE_RESET_OUT_POS 2 +#define MXC_F_WDT2_ENABLE_RESET_OUT ((uint32_t)(0x00000001UL << MXC_F_WDT2_ENABLE_RESET_OUT_POS)) + +#define MXC_F_WDT2_LOCK_CTRL_WDLOCK_POS 0 +#define MXC_F_WDT2_LOCK_CTRL_WDLOCK ((uint32_t)(0x000000FFUL << MXC_F_WDT2_LOCK_CTRL_WDLOCK_POS)) + + + +/* + Field values and shifted values for module WDT2. +*/ + +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_25_NANO_CLKS ((uint32_t)(0x00000000UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_24_NANO_CLKS ((uint32_t)(0x00000001UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_23_NANO_CLKS ((uint32_t)(0x00000002UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_22_NANO_CLKS ((uint32_t)(0x00000003UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_21_NANO_CLKS ((uint32_t)(0x00000004UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_20_NANO_CLKS ((uint32_t)(0x00000005UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_19_NANO_CLKS ((uint32_t)(0x00000006UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_18_NANO_CLKS ((uint32_t)(0x00000007UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_17_NANO_CLKS ((uint32_t)(0x00000008UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_16_NANO_CLKS ((uint32_t)(0x00000009UL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_15_NANO_CLKS ((uint32_t)(0x0000000AUL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_14_NANO_CLKS ((uint32_t)(0x0000000BUL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_13_NANO_CLKS ((uint32_t)(0x0000000CUL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_12_NANO_CLKS ((uint32_t)(0x0000000DUL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_11_NANO_CLKS ((uint32_t)(0x0000000EUL)) +#define MXC_V_WDT2_CTRL_INT_PERIOD_2_10_NANO_CLKS ((uint32_t)(0x0000000FUL)) + +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_25_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_25_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_24_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_24_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_23_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_23_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_22_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_22_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_21_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_21_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_20_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_20_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_19_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_19_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_18_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_18_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_17_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_17_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_16_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_16_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_15_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_15_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_14_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_14_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_13_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_13_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_12_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_12_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_11_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_11_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_INT_PERIOD_2_10_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_INT_PERIOD_2_10_NANO_CLKS << MXC_F_WDT2_CTRL_INT_PERIOD_POS)) + +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_25_NANO_CLKS ((uint32_t)(0x00000000UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_24_NANO_CLKS ((uint32_t)(0x00000001UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_23_NANO_CLKS ((uint32_t)(0x00000002UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_22_NANO_CLKS ((uint32_t)(0x00000003UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_21_NANO_CLKS ((uint32_t)(0x00000004UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_20_NANO_CLKS ((uint32_t)(0x00000005UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_19_NANO_CLKS ((uint32_t)(0x00000006UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_18_NANO_CLKS ((uint32_t)(0x00000007UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_17_NANO_CLKS ((uint32_t)(0x00000008UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_16_NANO_CLKS ((uint32_t)(0x00000009UL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_15_NANO_CLKS ((uint32_t)(0x0000000AUL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_14_NANO_CLKS ((uint32_t)(0x0000000BUL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_13_NANO_CLKS ((uint32_t)(0x0000000CUL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_12_NANO_CLKS ((uint32_t)(0x0000000DUL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_11_NANO_CLKS ((uint32_t)(0x0000000EUL)) +#define MXC_V_WDT2_CTRL_RST_PERIOD_2_10_NANO_CLKS ((uint32_t)(0x0000000FUL)) + +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_25_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_25_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_24_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_24_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_23_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_23_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_22_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_22_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_21_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_21_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_20_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_20_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_19_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_19_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_18_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_18_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_17_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_17_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_16_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_16_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_15_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_15_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_14_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_14_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_13_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_13_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_12_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_12_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_11_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_11_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT2_CTRL_RST_PERIOD_2_10_NANO_CLKS ((uint32_t)(MXC_V_WDT2_CTRL_RST_PERIOD_2_10_NANO_CLKS << MXC_F_WDT2_CTRL_RST_PERIOD_POS)) + + +#define MXC_V_WDT2_LOCK_KEY 0x24 +#define MXC_V_WDT2_UNLOCK_KEY 0x42 + +#define MXC_V_WDT2_RESET_KEY_0 0xA5 +#define MXC_V_WDT2_RESET_KEY_1 0x5A + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_WDT2_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/device/wdt_regs.h b/targets/TARGET_Maxim/TARGET_MAX32625/device/wdt_regs.h new file mode 100644 index 0000000..b793bb0 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/device/wdt_regs.h @@ -0,0 +1,238 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************/ + +#ifndef _MXC_WDT_REGS_H_ +#define _MXC_WDT_REGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "mxc_device.h" + +/* + If types are not defined elsewhere (CMSIS) define them here +*/ +#ifndef __IO +#define __IO volatile +#endif +#ifndef __I +#define __I volatile const +#endif +#ifndef __O +#define __O volatile +#endif + + +/* + Typedefed structure(s) for module registers (per instance or section) with direct 32-bit + access to each register in module. +*/ + +/* Offset Register Description + ============= ============================================================================ */ +typedef struct { + __IO uint32_t ctrl; /* 0x0000 Watchdog Timer Control Register */ + __IO uint32_t clear; /* 0x0004 Watchdog Timer Clear Register (Feed Dog) */ + __IO uint32_t flags; /* 0x0008 Watchdog Timer Interrupt and Reset Flags */ + __IO uint32_t enable; /* 0x000C Watchdog Timer Interrupt/Reset Enable/Disable Controls */ + __I uint32_t rsv010; /* 0x0010 */ + __IO uint32_t lock_ctrl; /* 0x0014 Watchdog Timer Register Setting Lock for Control Register */ +} mxc_wdt_regs_t; + + +/* + Register offsets for module WDT. +*/ + +#define MXC_R_WDT_OFFS_CTRL ((uint32_t)0x00000000UL) +#define MXC_R_WDT_OFFS_CLEAR ((uint32_t)0x00000004UL) +#define MXC_R_WDT_OFFS_FLAGS ((uint32_t)0x00000008UL) +#define MXC_R_WDT_OFFS_ENABLE ((uint32_t)0x0000000CUL) +#define MXC_R_WDT_OFFS_LOCK_CTRL ((uint32_t)0x00000014UL) + + +/* + Field positions and masks for module WDT. +*/ + +#define MXC_F_WDT_CTRL_INT_PERIOD_POS 0 +#define MXC_F_WDT_CTRL_INT_PERIOD ((uint32_t)(0x0000000FUL << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_F_WDT_CTRL_RST_PERIOD_POS 4 +#define MXC_F_WDT_CTRL_RST_PERIOD ((uint32_t)(0x0000000FUL << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_F_WDT_CTRL_EN_TIMER_POS 8 +#define MXC_F_WDT_CTRL_EN_TIMER ((uint32_t)(0x00000001UL << MXC_F_WDT_CTRL_EN_TIMER_POS)) +#define MXC_F_WDT_CTRL_EN_CLOCK_POS 9 +#define MXC_F_WDT_CTRL_EN_CLOCK ((uint32_t)(0x00000001UL << MXC_F_WDT_CTRL_EN_CLOCK_POS)) +#define MXC_F_WDT_CTRL_WAIT_PERIOD_POS 12 +#define MXC_F_WDT_CTRL_WAIT_PERIOD ((uint32_t)(0x0000000FUL << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) + +#define MXC_F_WDT_FLAGS_TIMEOUT_POS 0 +#define MXC_F_WDT_FLAGS_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_WDT_FLAGS_TIMEOUT_POS)) +#define MXC_F_WDT_FLAGS_PRE_WIN_POS 1 +#define MXC_F_WDT_FLAGS_PRE_WIN ((uint32_t)(0x00000001UL << MXC_F_WDT_FLAGS_PRE_WIN_POS)) +#define MXC_F_WDT_FLAGS_RESET_OUT_POS 2 +#define MXC_F_WDT_FLAGS_RESET_OUT ((uint32_t)(0x00000001UL << MXC_F_WDT_FLAGS_RESET_OUT_POS)) + +#define MXC_F_WDT_ENABLE_TIMEOUT_POS 0 +#define MXC_F_WDT_ENABLE_TIMEOUT ((uint32_t)(0x00000001UL << MXC_F_WDT_ENABLE_TIMEOUT_POS)) +#define MXC_F_WDT_ENABLE_PRE_WIN_POS 1 +#define MXC_F_WDT_ENABLE_PRE_WIN ((uint32_t)(0x00000001UL << MXC_F_WDT_ENABLE_PRE_WIN_POS)) +#define MXC_F_WDT_ENABLE_RESET_OUT_POS 2 +#define MXC_F_WDT_ENABLE_RESET_OUT ((uint32_t)(0x00000001UL << MXC_F_WDT_ENABLE_RESET_OUT_POS)) + +#define MXC_F_WDT_LOCK_CTRL_WDLOCK_POS 0 +#define MXC_F_WDT_LOCK_CTRL_WDLOCK ((uint32_t)(0x000000FFUL << MXC_F_WDT_LOCK_CTRL_WDLOCK_POS)) + + + +/* + Field values and shifted values for module WDT. +*/ + +#define MXC_V_WDT_CTRL_INT_PERIOD_2_31_CLKS ((uint32_t)(0x00000000UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_30_CLKS ((uint32_t)(0x00000001UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_29_CLKS ((uint32_t)(0x00000002UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_28_CLKS ((uint32_t)(0x00000003UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_27_CLKS ((uint32_t)(0x00000004UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_26_CLKS ((uint32_t)(0x00000005UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_25_CLKS ((uint32_t)(0x00000006UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_24_CLKS ((uint32_t)(0x00000007UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_23_CLKS ((uint32_t)(0x00000008UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_22_CLKS ((uint32_t)(0x00000009UL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_21_CLKS ((uint32_t)(0x0000000AUL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_20_CLKS ((uint32_t)(0x0000000BUL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_19_CLKS ((uint32_t)(0x0000000CUL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_18_CLKS ((uint32_t)(0x0000000DUL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_17_CLKS ((uint32_t)(0x0000000EUL)) +#define MXC_V_WDT_CTRL_INT_PERIOD_2_16_CLKS ((uint32_t)(0x0000000FUL)) + +#define MXC_S_WDT_CTRL_INT_PERIOD_2_31_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_31_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_30_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_30_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_29_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_29_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_28_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_28_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_27_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_27_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_26_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_26_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_25_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_25_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_24_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_24_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_23_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_23_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_22_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_22_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_21_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_21_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_20_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_20_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_19_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_19_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_18_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_18_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_17_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_17_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_INT_PERIOD_2_16_CLKS ((uint32_t)(MXC_V_WDT_CTRL_INT_PERIOD_2_16_CLKS << MXC_F_WDT_CTRL_INT_PERIOD_POS)) + +#define MXC_V_WDT_CTRL_RST_PERIOD_2_31_CLKS ((uint32_t)(0x00000000UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_30_CLKS ((uint32_t)(0x00000001UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_29_CLKS ((uint32_t)(0x00000002UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_28_CLKS ((uint32_t)(0x00000003UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_27_CLKS ((uint32_t)(0x00000004UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_26_CLKS ((uint32_t)(0x00000005UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_25_CLKS ((uint32_t)(0x00000006UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_24_CLKS ((uint32_t)(0x00000007UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_23_CLKS ((uint32_t)(0x00000008UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_22_CLKS ((uint32_t)(0x00000009UL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_21_CLKS ((uint32_t)(0x0000000AUL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_20_CLKS ((uint32_t)(0x0000000BUL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_19_CLKS ((uint32_t)(0x0000000CUL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_18_CLKS ((uint32_t)(0x0000000DUL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_17_CLKS ((uint32_t)(0x0000000EUL)) +#define MXC_V_WDT_CTRL_RST_PERIOD_2_16_CLKS ((uint32_t)(0x0000000FUL)) + +#define MXC_S_WDT_CTRL_RST_PERIOD_2_31_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_31_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_30_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_30_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_29_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_29_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_28_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_28_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_27_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_27_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_26_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_26_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_25_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_25_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_24_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_24_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_23_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_23_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_22_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_22_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_21_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_21_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_20_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_20_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_19_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_19_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_18_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_18_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_17_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_17_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) +#define MXC_S_WDT_CTRL_RST_PERIOD_2_16_CLKS ((uint32_t)(MXC_V_WDT_CTRL_RST_PERIOD_2_16_CLKS << MXC_F_WDT_CTRL_RST_PERIOD_POS)) + +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_31_CLKS ((uint32_t)(0x00000000UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_30_CLKS ((uint32_t)(0x00000001UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_29_CLKS ((uint32_t)(0x00000002UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_28_CLKS ((uint32_t)(0x00000003UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_27_CLKS ((uint32_t)(0x00000004UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_26_CLKS ((uint32_t)(0x00000005UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_25_CLKS ((uint32_t)(0x00000006UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_24_CLKS ((uint32_t)(0x00000007UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_23_CLKS ((uint32_t)(0x00000008UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_22_CLKS ((uint32_t)(0x00000009UL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_21_CLKS ((uint32_t)(0x0000000AUL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_20_CLKS ((uint32_t)(0x0000000BUL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_19_CLKS ((uint32_t)(0x0000000CUL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_18_CLKS ((uint32_t)(0x0000000DUL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_17_CLKS ((uint32_t)(0x0000000EUL)) +#define MXC_V_WDT_CTRL_WAIT_PERIOD_2_16_CLKS ((uint32_t)(0x0000000FUL)) + +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_31_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_31_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_30_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_30_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_29_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_29_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_28_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_28_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_27_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_27_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_26_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_26_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_25_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_25_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_24_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_24_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_23_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_23_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_22_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_22_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_21_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_21_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_20_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_20_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_19_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_19_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_18_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_18_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_17_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_17_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) +#define MXC_S_WDT_CTRL_WAIT_PERIOD_2_16_CLKS ((uint32_t)(MXC_V_WDT_CTRL_WAIT_PERIOD_2_16_CLKS << MXC_F_WDT_CTRL_WAIT_PERIOD_POS)) + + +#define MXC_V_WDT_LOCK_KEY 0x24 +#define MXC_V_WDT_UNLOCK_KEY 0x42 + +#define MXC_V_WDT_RESET_KEY_0 0xA5 +#define MXC_V_WDT_RESET_KEY_1 0x5A + + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_WDT_REGS_H_ */ + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/gpio_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/gpio_api.c new file mode 100644 index 0000000..2b5bb5e --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/gpio_api.c @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed_assert.h" +#include "gpio_api.h" +#include "pinmap.h" +#include "gpio_regs.h" +#include "clkman_regs.h" + +uint32_t gpio_set(PinName name) +{ + MBED_ASSERT(name != (PinName)NC); + pin_function(name, 0); + return 1 << PINNAME_TO_PIN(name); +} + +void gpio_init(gpio_t *obj, PinName name) +{ + obj->name = name; + if (name == (PinName)NC) { + return; + } + + unsigned int port = PINNAME_TO_PORT(name); + unsigned int pin = PINNAME_TO_PIN(name); + + obj->reg_out = (uint32_t*)BITBAND(&MXC_GPIO->out_val[port], pin); + obj->reg_in = (uint32_t*)BITBAND(&MXC_GPIO->in_val[port], pin); + obj->mode = PullDefault; + + /* Ensure that the GPIO clock is enabled */ + MXC_CLKMAN->clk_gate_ctrl1 |= MXC_F_CLKMAN_CLK_GATE_CTRL1_GPIO_CLK_GATER; + + /* Ensure that the GPIO clock is enabled */ + MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1; +} + +void gpio_mode(gpio_t *obj, PinMode mode) +{ + obj->mode = mode; + pin_mode(obj->name, mode); +} + +void pin_dir_mode(PinName name, PinDirection direction, PinMode mode) +{ + MBED_ASSERT(name != (PinName)NC); + + unsigned int port = PINNAME_TO_PORT(name); + unsigned int pin = PINNAME_TO_PIN(name); + + /* Set function; Firmware Control (GPIO mode) */ + MXC_GPIO->func_sel[port] &= ~(0xF << (4 * pin)); + + /* Normal input is always enabled */ + MXC_GPIO->in_mode[port] &= ~(0xF << (4 * pin)); + + uint32_t new_mode; + if (direction == PIN_OUTPUT) { + // PullUp = not valid, + // PullDown = not valid, + // OpenDrain = MXC_V_GPIO_OUT_MODE_OD, + // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL, + if (mode == OpenDrain) { + new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN; + } else { + new_mode = MXC_V_GPIO_OUT_MODE_NORMAL; + } + } else { + // PullUp = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP + // PullDown = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN + // OpenDrain = MXC_V_GPIO_OUT_MODE_OD + // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z + if (mode == PullUp) { + new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP; + MXC_GPIO->out_val[port] |= 1 << pin; + } else if (mode == PullDown) { + new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN; + MXC_GPIO->out_val[port] &= ~(1 << pin); + } else if (mode == OpenDrain) { + new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN; + MXC_GPIO->out_val[port] |= 1 << pin; + } else { + new_mode = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z; + MXC_GPIO->out_val[port] &= ~(1 << pin); + } + } + + /* Set new mode */ + uint32_t out_mode = MXC_GPIO->out_mode[port]; + out_mode &= ~(0xF << (pin * 4)); + out_mode |= (new_mode << (pin * 4)); + MXC_GPIO->out_mode[port] = out_mode; +} + +void gpio_dir(gpio_t *obj, PinDirection direction) +{ + pin_dir_mode(obj->name, direction, obj->mode); +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/gpio_irq_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/gpio_irq_api.c new file mode 100644 index 0000000..ead582a --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/gpio_irq_api.c @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include +#include "cmsis.h" +#include "gpio_irq_api.h" +#include "mbed_error.h" + +static gpio_irq_t *objs[MXC_GPIO_NUM_PORTS][MXC_GPIO_MAX_PINS_PER_PORT] = {{0}}; +static gpio_irq_handler irq_handler; + +static void handle_irq(unsigned int port) +{ + uint32_t intfl, in_val; + uint32_t mask; + unsigned int pin; + + /* Read pin state */ + in_val = MXC_GPIO->in_val[port]; + + /* Read interrupts */ + intfl = MXC_GPIO->intfl[port] & MXC_GPIO->inten[port]; + + mask = 1; + + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if (intfl & mask) { + MXC_GPIO->intfl[port] = mask; /* clear interrupt */ + gpio_irq_event event = (in_val & mask) ? IRQ_RISE : IRQ_FALL; + gpio_irq_t *obj = objs[port][pin]; + if (obj && obj->id) { + if ((event == IRQ_RISE) && obj->rise_en) { + irq_handler(obj->id, IRQ_RISE); + } else if ((event == IRQ_FALL) && obj->fall_en) { + irq_handler(obj->id, IRQ_FALL); + } + } + } + mask <<= 1; + } +} + +void gpio_irq_0(void) { handle_irq(0); } +void gpio_irq_1(void) { handle_irq(1); } +void gpio_irq_2(void) { handle_irq(2); } +void gpio_irq_3(void) { handle_irq(3); } +void gpio_irq_4(void) { handle_irq(4); } + +int gpio_irq_init(gpio_irq_t *obj, PinName name, gpio_irq_handler handler, uint32_t id) +{ + if (name == NC) { + return -1; + } + + uint8_t port = PINNAME_TO_PORT(name); + uint8_t pin = PINNAME_TO_PIN(name); + + if ((port > MXC_GPIO_NUM_PORTS) || (pin > MXC_GPIO_MAX_PINS_PER_PORT)) { + return 1; + } + + obj->port = port; + obj->pin = pin; + obj->id = id; + objs[port][pin] = obj; + + /* register handlers */ + irq_handler = handler; + NVIC_SetVector(GPIO_P0_IRQn, (uint32_t)gpio_irq_0); + NVIC_SetVector(GPIO_P1_IRQn, (uint32_t)gpio_irq_1); + NVIC_SetVector(GPIO_P2_IRQn, (uint32_t)gpio_irq_2); + NVIC_SetVector(GPIO_P3_IRQn, (uint32_t)gpio_irq_3); + NVIC_SetVector(GPIO_P4_IRQn, (uint32_t)gpio_irq_4); + + /* disable the interrupt locally */ + MXC_GPIO->int_mode[port] &= ~(0xF << (pin*4)); + + /* clear a pending request */ + MXC_GPIO->intfl[port] = 1 << pin; + + /* enable the requested interrupt */ + MXC_GPIO->inten[port] |= (1 << pin); + NVIC_EnableIRQ((IRQn_Type)((uint32_t)GPIO_P0_IRQn + port)); + + return 0; +} + +void gpio_irq_free(gpio_irq_t *obj) +{ + /* disable interrupt */ + MXC_GPIO->inten[obj->port] &= ~(1 << obj->pin); + MXC_GPIO->int_mode[obj->port] &= ~(MXC_V_GPIO_INT_MODE_ANY_EDGE << (obj->pin*4)); + objs[obj->port][obj->pin] = NULL; +} + +void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) +{ + if (event == IRQ_FALL) { + obj->fall_en = enable; + } else if (event == IRQ_RISE) { + obj->rise_en = enable; + } + + if (obj->fall_en && obj->rise_en) { + MXC_GPIO->int_mode[obj->port] |= (MXC_V_GPIO_INT_MODE_ANY_EDGE << (obj->pin*4)); + } else if (obj->fall_en) { + uint32_t int_mode = MXC_GPIO->int_mode[obj->port]; + int_mode &= ~(MXC_V_GPIO_INT_MODE_ANY_EDGE << (obj->pin*4)); + int_mode |= (MXC_V_GPIO_INT_MODE_FALLING_EDGE << (obj->pin*4)); + MXC_GPIO->int_mode[obj->port] = int_mode; + } else if (obj->rise_en) { + uint32_t int_mode = MXC_GPIO->int_mode[obj->port]; + int_mode &= ~(MXC_V_GPIO_INT_MODE_ANY_EDGE << (obj->pin*4)); + int_mode |= (MXC_V_GPIO_INT_MODE_RISING_EDGE << (obj->pin*4)); + MXC_GPIO->int_mode[obj->port] = int_mode; + } else { + MXC_GPIO->int_mode[obj->port] &= ~(MXC_V_GPIO_INT_MODE_ANY_EDGE << (obj->pin*4)); + } +} + +void gpio_irq_enable(gpio_irq_t *obj) +{ + MXC_GPIO->inten[obj->port] |= (1 << obj->pin); +} + +void gpio_irq_disable(gpio_irq_t *obj) +{ + MXC_GPIO->inten[obj->port] &= ~(1 << obj->pin); +} + +gpio_irq_t *gpio_irq_get_obj(PinName name) +{ + if (name == NC) { + return NULL; + } + + unsigned int port = PINNAME_TO_PORT(name); + unsigned int pin = PINNAME_TO_PIN(name); + + if ((port > MXC_GPIO_NUM_PORTS) || (pin > MXC_GPIO_MAX_PINS_PER_PORT)) { + return NULL; + } + + return objs[port][pin]; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/gpio_object.h b/targets/TARGET_Maxim/TARGET_MAX32625/gpio_object.h new file mode 100644 index 0000000..63c5be2 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/gpio_object.h @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_GPIO_OBJECT_H +#define MBED_GPIO_OBJECT_H + +#include "mbed_assert.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName name; + __IO uint32_t *reg_out; + __I uint32_t *reg_in; + PinMode mode; +} gpio_t; + +static inline void gpio_write(gpio_t *obj, int value) +{ + MBED_ASSERT(obj->name != (PinName)NC); + *obj->reg_out = !!value; +} + +static inline int gpio_read(gpio_t *obj) +{ + MBED_ASSERT(obj->name != (PinName)NC); + return *obj->reg_in; +} + +void pin_dir_mode(PinName name, PinDirection direction, PinMode mode); + +static inline int gpio_is_connected(const gpio_t *obj) +{ + return obj->name != (PinName)NC; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/i2c_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/i2c_api.c new file mode 100644 index 0000000..6886bee --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/i2c_api.c @@ -0,0 +1,214 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed_assert.h" +#include "i2c_api.h" +#include "i2cm_regs.h" +#include "i2cm.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#ifndef MXC_I2CM_RX_TIMEOUT +#define MXC_I2CM_RX_TIMEOUT 0x5000 +#endif + +#define MBED_NAK 0 +#define MBED_ACK 1 +#define MBED_TIMEOUT 2 + +//****************************************************************************** +void i2c_init(i2c_t *obj, PinName sda, PinName scl) +{ + // SDA and SCL must map to same peripheral instance + I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); + I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); + mxc_i2cm_regs_t *i2c = (mxc_i2cm_regs_t*)pinmap_merge(i2c_sda, i2c_scl); + MBED_ASSERT((int)i2c != NC); + + obj->i2c = i2c; + obj->fifo = MXC_I2CM_GET_FIFO(MXC_I2CM_GET_IDX(i2c)); + obj->start_pending = 0; + + // Merge pin function requests for use with CMSIS init func + ioman_req_t io_req; + pin_function_t *pin_func; + pin_func = (pin_function_t *)pinmap_find_function(sda, PinMap_I2C_SDA); + io_req.value = pin_func->req_val; + pin_func = (pin_function_t *)pinmap_find_function(scl, PinMap_I2C_SCL); + io_req.value |= pin_func->req_val; + + sys_cfg_i2cm_t sys_cfg; + sys_cfg.io_cfg.req_reg = pin_func->reg_req; + sys_cfg.io_cfg.ack_reg = pin_func->reg_ack; + sys_cfg.io_cfg.req_val = io_req; + sys_cfg.clk_scale = CLKMAN_SCALE_DIV_1; + + I2CM_Init(obj->i2c, &sys_cfg, I2CM_SPEED_400KHZ); +} + +//****************************************************************************** +void i2c_frequency(i2c_t *obj, int hz) +{ + I2CM_SetFrequency(obj->i2c, hz); +} + +//****************************************************************************** +int i2c_start(i2c_t *obj) +{ + obj->start_pending = 1; + return 0; +} + +//****************************************************************************** +int i2c_stop(i2c_t *obj) +{ + obj->start_pending = 0; + I2CM_WriteTxFifo(obj->i2c, obj->fifo, MXC_S_I2CM_TRANS_TAG_STOP); + I2CM_TxInProgress(obj->i2c); + return 0; +} + +//****************************************************************************** +int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) +{ + MBED_ASSERT(stop != 0); + return I2CM_Read(obj->i2c, address >> 1, NULL, 0, (uint8_t *)data, length); +} + +//****************************************************************************** +int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) +{ + mxc_i2cm_regs_t *i2cm = obj->i2c; + mxc_i2cm_fifo_regs_t *fifo = obj->fifo; + + if (stop) { + return I2CM_Write(i2cm, address >> 1, NULL, 0, (uint8_t *)data, length); + } + + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + if (I2CM_Tx(i2cm, fifo, address >> 1, (uint8_t *)data, length, 0) == E_NO_ERROR) { + return length; + } else { + return -1; + } +} + +//****************************************************************************** +void i2c_reset(i2c_t *obj) +{ + I2CM_Recover(obj->i2c); +} + +//****************************************************************************** +int i2c_byte_read(i2c_t *obj, int last) +{ + mxc_i2cm_regs_t *i2cm = obj->i2c; + mxc_i2cm_fifo_regs_t *fifo = obj->fifo; + int tmp; + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + + if (last) { + // NACK the last read byte + if (I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_RXDATA_NACK) != E_NO_ERROR) { + goto byte_write_err; + } + + // Send the stop condition + if (I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_STOP) != E_NO_ERROR) { + goto byte_write_err; + } + } else { + if (I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT) != E_NO_ERROR) { + goto byte_write_err; + } + } + + do { + // Wait for data in RX FIFO + int timeout = MXC_I2CM_RX_TIMEOUT; + while (!(i2cm->intfl & MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY) && + ((i2cm->bb & MXC_F_I2CM_BB_RX_FIFO_CNT) == 0)) { + + if((timeout-- < 0) || (i2cm->trans & MXC_F_I2CM_TRANS_TX_TIMEOUT)) { + goto byte_write_err; + } + + if (i2cm->trans & (MXC_F_I2CM_TRANS_TX_LOST_ARBITR | MXC_F_I2CM_TRANS_TX_NACKED)) { + goto byte_write_err; + } + } + i2cm->intfl = MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY; + + } while ((tmp = fifo->rx) & MXC_S_I2CM_RSTLS_TAG_EMPTY); + + return (uint8_t)tmp; + +byte_write_err: + i2c_reset(obj); + return -1; +} + +//****************************************************************************** +int i2c_byte_write(i2c_t *obj, int data) +{ + mxc_i2cm_regs_t *i2cm = obj->i2c; + mxc_i2cm_fifo_regs_t *fifo = obj->fifo; + int result; + + if (obj->start_pending) { + obj->start_pending = 0; + data |= MXC_S_I2CM_TRANS_TAG_START; + } else { + data |= MXC_S_I2CM_TRANS_TAG_TXDATA_ACK; + } + + if ((result = I2CM_WriteTxFifo(i2cm, fifo, data)) != E_NO_ERROR) { + i2c_reset(obj); + if (result == E_COMM_ERR) { + return MBED_NAK; + } + return MBED_TIMEOUT; + } + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + + return MBED_ACK; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/adc.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/adc.c new file mode 100644 index 0000000..33ac291 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/adc.c @@ -0,0 +1,178 @@ +/** + * @file adc.c + * @brief This file contains the function implementations for the Analog to + * Digital Converter (ADC) peripheral module. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:32:46 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23893 $ + * + *************************************************************************** */ + +/** + * @ingroup adc + * @{ + */ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "mxc_assert.h" +#include "mxc_sys.h" +#include "adc.h" + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Functions **** */ + +/* ************************************************************************* */ +int ADC_Init(void) +{ + int err; + + if ((err = SYS_ADC_Init()) != E_NO_ERROR) { + return err; + } + + /* Wipe previous configuration */ + MXC_ADC->intr = 0; + + /* Clear all ADC interrupt flags (W1C) */ + MXC_ADC->intr = MXC_ADC->intr; + + /* Enable done interrupt */ + MXC_ADC->intr = MXC_F_ADC_INTR_ADC_DONE_IE; + + /* Power up the ADC */ + MXC_ADC->ctrl = (MXC_F_ADC_CTRL_ADC_PU | + MXC_F_ADC_CTRL_ADC_CLK_EN | + MXC_F_ADC_CTRL_BUF_PU | + MXC_F_ADC_CTRL_ADC_REFBUF_PU | + MXC_F_ADC_CTRL_ADC_CHGPUMP_PU); + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +void ADC_StartConvert(mxc_adc_chsel_t channel, unsigned int adc_scale, unsigned int bypass) +{ + uint32_t ctrl_tmp; + + /* Clear the ADC done flag */ + ADC_ClearFlags(MXC_F_ADC_INTR_ADC_DONE_IF); + + /* Insert channel selection */ + ctrl_tmp = MXC_ADC->ctrl; + ctrl_tmp &= ~(MXC_F_ADC_CTRL_ADC_CHSEL); + ctrl_tmp |= ((channel << MXC_F_ADC_CTRL_ADC_CHSEL_POS) & MXC_F_ADC_CTRL_ADC_CHSEL); + + /* Clear channel configuration */ + ctrl_tmp &= ~(MXC_F_ADC_CTRL_ADC_REFSCL | MXC_F_ADC_CTRL_ADC_SCALE | MXC_F_ADC_CTRL_BUF_BYPASS); + + /* ADC reference scaling must be set for all channels but two*/ + if ((channel != ADC_CH_VDD18) && (channel != ADC_CH_VDD12)) { + ctrl_tmp |= MXC_F_ADC_CTRL_ADC_REFSCL; + } + + /* Finalize user-requested channel configuration */ + if (adc_scale || channel > ADC_CH_3) { + ctrl_tmp |= MXC_F_ADC_CTRL_ADC_SCALE; + } + if (bypass) { + ctrl_tmp |= MXC_F_ADC_CTRL_BUF_BYPASS; + } + + /* Write this configuration */ + MXC_ADC->ctrl = ctrl_tmp; + + /* Start conversion */ + MXC_ADC->ctrl |= MXC_F_ADC_CTRL_CPU_ADC_START; + +} + +/* ************************************************************************* */ +int ADC_GetData(uint16_t *outdata) +{ + /* See if a conversion is in process */ + if (MXC_ADC->status & MXC_F_ADC_STATUS_ADC_ACTIVE) { + /* Wait for conversion to complete */ + while ((MXC_ADC->intr & MXC_F_ADC_INTR_ADC_DONE_IF) == 0); + } + + /* Read 32-bit value and truncate to 16-bit for output depending on data align bit*/ + if((MXC_ADC->ctrl & MXC_F_ADC_CTRL_ADC_DATAALIGN) == 0) + *outdata = (uint16_t)(MXC_ADC->data); /* LSB justified */ + else + *outdata = (uint16_t)(MXC_ADC->data >> 6); /* MSB justified */ + + /* Check for overflow */ + if (MXC_ADC->status & MXC_F_ADC_STATUS_ADC_OVERFLOW) { + return E_OVERFLOW; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int ADC_SetLimit(mxc_adc_limitsel_t unit, mxc_adc_chsel_t channel, + unsigned int low_enable, unsigned int low_limit, + unsigned int high_enable, unsigned int high_limit) +{ + /* Check args */ + if ((unit >= ADC_LIMIT_MAX) || (channel >= ADC_CH_MAX)) + return E_BAD_PARAM; + + /* set channel using the limit */ + MXC_ADC->limit[unit] = ((channel << MXC_F_ADC_LIMIT0_CH_SEL_POS) & MXC_F_ADC_LIMIT0_CH_SEL); + + /* enable/disable the limit*/ + if (low_enable) { + MXC_ADC->limit[unit] |= MXC_F_ADC_LIMIT0_CH_LO_LIMIT_EN | + ((low_limit << MXC_F_ADC_LIMIT0_CH_LO_LIMIT_POS) & MXC_F_ADC_LIMIT0_CH_LO_LIMIT); + } else { + MXC_ADC->limit[unit] &= ~MXC_F_ADC_LIMIT0_CH_LO_LIMIT_EN; + } + + if (high_enable) { + MXC_ADC->limit[unit] |= MXC_F_ADC_LIMIT0_CH_HI_LIMIT_EN | + ((high_limit << MXC_F_ADC_LIMIT0_CH_HI_LIMIT_POS) & MXC_F_ADC_LIMIT0_CH_HI_LIMIT); + } else { + MXC_ADC->limit[unit] &= ~MXC_F_ADC_LIMIT0_CH_HI_LIMIT_EN; + } + + return E_NO_ERROR; +} + +/**@} end of group adc */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/adc.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/adc.h new file mode 100644 index 0000000..26146f3 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/adc.h @@ -0,0 +1,216 @@ +/** + * @file adc.h + * @brief Analog to Digital Converter function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-04 16:21:09 -0500 (Thu, 04 Aug 2016) $ + * $Revision: 23947 $ + * + *************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _ADC_H +#define _ADC_H + +/* **** Includes **** */ +#include +#include "adc_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Doxy group definition for this peripheral module */ + +/** + * @defgroup adc Analog to Digital Converter (ADC) + * @ingroup periphlibs + * @{ + */ + +/* **** Definitions **** */ + +/** + * Enumeration type for ADC Channel Selection. See \ref ADC_CHSEL_values "ADC Channel Select Values" for additional information. + */ +typedef enum { + ADC_CH_0 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN0, /**< Channel 0 Select */ + ADC_CH_1 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN1, /**< Channel 1 Select */ + ADC_CH_2 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN2, /**< Channel 2 Select */ + ADC_CH_3 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN3, /**< Channel 3 Select */ + ADC_CH_0_DIV_5 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN0_DIV_5, /**< Channel 0 divided by 5 */ + ADC_CH_1_DIV_5 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN1_DIV_5, /**< Channel 1 divided by 5 */ + ADC_CH_VDDB_DIV_4 = MXC_V_ADC_CTRL_ADC_CHSEL_VDDB_DIV_4, /**< VDDB divided by 4 */ + ADC_CH_VDD18 = MXC_V_ADC_CTRL_ADC_CHSEL_VDD18, /**< VDD18 input select */ + ADC_CH_VDD12 = MXC_V_ADC_CTRL_ADC_CHSEL_VDD12, /**< VDD12 input select */ + ADC_CH_VRTC_DIV_2 = MXC_V_ADC_CTRL_ADC_CHSEL_VRTC_DIV_2, /**< VRTC divided by 2 */ + ADC_CH_TMON = MXC_V_ADC_CTRL_ADC_CHSEL_TMON, /**< TMON input select */ +#if (MXC_ADC_REV > 0) + ADC_CH_VDDIO_DIV_4 = MXC_V_ADC_CTRL_ADC_CHSEL_VDDIO_DIV_4, /**< VDDIO divided by 4 select */ + ADC_CH_VDDIOH_DIV_4 = MXC_V_ADC_CTRL_ADC_CHSEL_VDDIOH_DIV_4, /**< VDDIOH divided by 4 select */ +#endif + ADC_CH_MAX /**< Max enum value for channel selection */ +} mxc_adc_chsel_t; + +/** + * Enumeration type for the ADC limit register to set + */ +typedef enum { + ADC_LIMIT_0 = 0, /**< ADC Limit Register 0 */ + ADC_LIMIT_1 = 1, /**< ADC Limit Register 1 */ + ADC_LIMIT_2 = 2, /**< ADC Limit Register 2 */ + ADC_LIMIT_3 = 3, /**< ADC Limit Register 3 */ + ADC_LIMIT_MAX /**< Number of Limit registers */ +} mxc_adc_limitsel_t; + +///@cond +/** + * Mask for all Interrupt Flag Fields + */ +#define ADC_IF_MASK (0xffffffffUL << MXC_F_ADC_INTR_ADC_DONE_IF_POS) + +/** + * Mask for all Interrupt Enable Fields + */ +#define ADC_IE_MASK (0xffffffffUL >> MXC_F_ADC_INTR_ADC_DONE_IF_POS) +///@endcond + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize the ADC hardware + * + * @return #E_NO_ERROR if successful + */ +int ADC_Init(void); + +/** + * @brief Start ADC conversion on the selected channel + * + * @param channel Channel select from #mxc_adc_chsel_t + * @param adc_scale Enable the ADC input scaling mode if non-zero + * @param bypass Bypass input buffer stage if non-zero + */ +void ADC_StartConvert(mxc_adc_chsel_t channel, unsigned int adc_scale, unsigned int bypass); + +/** + * @brief Gets the result from the previous ADC conversion + * + * @param outdata Pointer to store the ADC data conversion + * result. + * @return #E_OVERFLOW ADC overflow error + * @return #E_NO_ERROR Data returned in outdata parameter + */ +int ADC_GetData(uint16_t *outdata); + +/** + * @brief Set the data limits for an ADC channel monitor + * + * @param unit Which data limit unit to configure + * @param channel Channel select from mxc_adc_chsel_t + * @param low_enable Enable the lower limit on this monitor + * @param low_limit Value for lower limit monitor + * @param high_enable Enable the upper limit on this monitor + * @param high_limit Value for upper limit monitor + * + * @return #E_BAD_PARAM ADC limit or channel greater than supported + * @return #E_NO_ERROR ADC limit set successfully + */ +int ADC_SetLimit(mxc_adc_limitsel_t unit, mxc_adc_chsel_t channel, + unsigned int low_enable, unsigned int low_limit, + unsigned int high_enable, unsigned int high_limit); + +/** + * @brief Get interrupt flags + * + * @return ADC Interrupt flags bit mask. See the @ref ADC_INTR_IF_Register + * "ADC_INTR Register" for the interrupt flag masks. + */ +__STATIC_INLINE uint32_t ADC_GetFlags() +{ + return (MXC_ADC->intr & ADC_IF_MASK); +} + +/** + * @brief Clear interrupt flag(s) using the mask parameter. All bits set in + * the parameter will be cleared. + * + * @param mask Interrupt flags to clear. See the @ref ADC_INTR_IF_Register + * "ADC_INTR Register" for the interrupt flag masks. + */ +__STATIC_INLINE void ADC_ClearFlags(uint32_t mask) +{ + MXC_ADC->intr = ((MXC_ADC->intr & ADC_IF_MASK) | mask); +} + +/** + * @brief Get the Status of the ADC + * + * @return ADC status register. See @ref ADC_STATUS_Register "ADC_STATUS + * Register" for details. + */ +__STATIC_INLINE uint32_t ADC_GetStatus() +{ + return (MXC_ADC->status); +} + +/** + * @brief Enables the ADC interrupts specified by the mask parameter + * + * @param mask ADC interrupts to enable. See @ref ADC_INTR_IE_Register + * "ADC_INTR Register" for the interrupt enable bit masks. + */ +__STATIC_INLINE void ADC_EnableINT(uint32_t mask) +{ + MXC_ADC->intr = ((MXC_ADC->intr & ADC_IE_MASK) | mask); +} + +/** + * @brief Disable ADC interrupts based on mask + * + * @param mask ADC interrupts to disable. See @ref ADC_INTR_IE_Register + * "ADC_INTR Register" for the interrupt enable bit masks. + */ +__STATIC_INLINE void ADC_DisableINT(uint32_t mask) +{ + MXC_ADC->intr = ((MXC_ADC->intr & ADC_IE_MASK) & ~mask); +} + +/**@} end of group adc */ + +#ifdef __cplusplus +} +#endif + +#endif /* _ADC_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/aes.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/aes.c new file mode 100644 index 0000000..02ee506 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/aes.c @@ -0,0 +1,213 @@ +/** + * @file aes.c + * @brief This file contains the function implementations for the Advanced + * Encryption Standard (AES) peripheral module. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:39:05 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23894 $ + * + *************************************************************************** */ + +/* **** Includes **** */ +#include /* Included for memcpy() & #includes stddef for NULL */ + +#include "mxc_config.h" +#include "aes.h" + +/** + * @ingroup aes + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Local Function Prototypes **** */ +static int aes_memcpy32(uint32_t *out, uint32_t *in, unsigned int count); + +/* **** Functions **** */ + +/* ************************************************************************* */ +int AES_SetKey(const uint8_t *key, mxc_aes_mode_t mode) +{ + unsigned int len; + + /* Erase any existing key */ + MXC_AES_MEM->key[7] = MXC_AES_MEM->key[6] = MXC_AES_MEM->key[5] = MXC_AES_MEM->key[4] \ + = MXC_AES_MEM->key[3] = MXC_AES_MEM->key[2] = MXC_AES_MEM->key[1] = MXC_AES_MEM->key[0] \ + = 0x00000000; + + /* Determine length of key */ + if (mode == MXC_E_AES_MODE_256) { + len = MXC_AES_KEY_256_LEN; + } else if (mode == MXC_E_AES_MODE_192) { + len = MXC_AES_KEY_192_LEN; + } else if (mode == MXC_E_AES_MODE_128) { + len = MXC_AES_KEY_128_LEN; + } else { + return E_BAD_PARAM; + } + + /* Load new key, based on key mode */ + if (aes_memcpy32((uint32_t *)MXC_AES_MEM->key, (uint32_t *)key, len / sizeof(uint32_t)) < 0) { + return E_NULL_PTR; + } + + return E_SUCCESS; +} + +/* ************************************************************************* */ +int AES_ECBOp(const uint8_t *in, uint8_t *out, mxc_aes_mode_t mode, mxc_aes_dir_t dir) +{ + /* Output array can't be a NULL, unless we are in _ASYNC mode */ + if ((out == NULL) + && ((dir != MXC_E_AES_ENCRYPT_ASYNC) && (dir != MXC_E_AES_DECRYPT_ASYNC))) { + return E_NULL_PTR; + } + + /* Another encryption is already in progress */ + if (MXC_AES->ctrl & MXC_F_AES_CTRL_START) { + return E_BUSY; + } + + /* Clear interrupt flag and any existing configuration*/ + MXC_AES->ctrl = MXC_F_AES_CTRL_INTFL; + + /* Select key size & direction + * + * Note: This is done first to detect argument errors, before sensitive data + * is loaded into AES_MEM block + * + */ + switch (mode) { + case MXC_E_AES_MODE_128: + MXC_AES->ctrl |= MXC_S_AES_CTRL_KEY_SIZE_128; + break; + + case MXC_E_AES_MODE_192: + MXC_AES->ctrl |= MXC_S_AES_CTRL_KEY_SIZE_192; + break; + + case MXC_E_AES_MODE_256: + MXC_AES->ctrl |= MXC_S_AES_CTRL_KEY_SIZE_256; + break; + + default: + return E_BAD_PARAM; + } + + switch (dir) { + case MXC_E_AES_ENCRYPT: + case MXC_E_AES_ENCRYPT_ASYNC: + MXC_AES->ctrl |= MXC_S_AES_CTRL_ENCRYPT_MODE; + break; + + case MXC_E_AES_DECRYPT: + case MXC_E_AES_DECRYPT_ASYNC: + MXC_AES->ctrl |= MXC_S_AES_CTRL_DECRYPT_MODE; + break; + + default: + return E_BAD_PARAM; + } + + /* If non-blocking mode has been selected, interrupts are automatically enabled */ + if ((dir == MXC_E_AES_ENCRYPT_ASYNC) || + (dir == MXC_E_AES_DECRYPT_ASYNC)) { + MXC_AES->ctrl |= MXC_F_AES_CTRL_INTEN; + } + + /* Load input into engine */ + if (aes_memcpy32((uint32_t *)MXC_AES_MEM->inp, (uint32_t *)in, MXC_AES_DATA_LEN / sizeof(uint32_t)) < 0) { + return E_NULL_PTR; + } + + /* Start operation */ + MXC_AES->ctrl |= MXC_F_AES_CTRL_START; + + /* Block, waiting on engine to complete, or fall through if non-blocking */ + if ((dir != MXC_E_AES_ENCRYPT_ASYNC) && + (dir != MXC_E_AES_DECRYPT_ASYNC)) { + while (MXC_AES->ctrl & MXC_F_AES_CTRL_START) { + /* Ensure that this wait loop is not optimized out */ + __NOP(); + } + + /* Get output from engine */ + return AES_GetOutput(out); + } + + return E_SUCCESS; +} + +/* ************************************************************************* */ +int AES_GetOutput(uint8_t *out) +{ + /* Don't read it out of the AES memory unless engine is idle */ + if (MXC_AES->ctrl & MXC_F_AES_CTRL_START) { + return E_BUSY; + } + + /* Pull out result */ + if (aes_memcpy32((uint32_t *)out, (uint32_t *)MXC_AES_MEM->out, MXC_AES_DATA_LEN / sizeof(uint32_t)) < 0) { + return E_NULL_PTR; + } + + /* Clear interrupt flag, write 1 to clear */ + MXC_AES->ctrl |= MXC_F_AES_CTRL_INTFL; + + return E_SUCCESS; +} + +/** + * @internal This memory copy is used only by the AES module to avoid data leakage by the standard C library. + * Copy count number of 32-bit locations from in to out + */ +static int aes_memcpy32(uint32_t *out, uint32_t *in, unsigned int count) +{ + if ((out == NULL) || (in == NULL)) { + /* Invalid arguments, but is internal-only so don't use error codes */ + return -1; + } + + while (count--) { + *out++ = *in++; + } + + return 0; +} + +/**@} end of group aes */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/aes.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/aes.h new file mode 100644 index 0000000..8dc7f6a --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/aes.h @@ -0,0 +1,199 @@ +/** + * @file aes.h + * @brief Advanced Encryption Standard (AES) function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:39:05 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23894 $ + * + *************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _AES_H +#define _AES_H + +#include +#include "aes_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup aes Advanced Encryption Standard (AES) + * @ingroup periphlibs + * @brief High-level API for AES encryption engine + * @{ + */ + +/** + * @page aes_overview Overview and Usage + * @parblock + * #### Key/data format in memory + * + * The API functions require that key and plain/ciphertext will be stored as a + * byte array in LSB .. MSB format. + * + * As an example, given the key @a 0x139a35422f1d61de3c91787fe0507afd, the proper storage order is: + * ~~~~~ + * uint8_t key[16] = { 0xfd, 0x7a, 0x50, 0xe0, + * 0x7f, 0x78, 0x91, 0x3c, + * 0xde, 0x61, 0x1d, 0x2f, + * 0x42, 0x35, 0x9a, 0x13 }; + * ~~~~~ + * This is the same order expected by the underlying hardware. + * @endparblock + */ + +/* **** Definitions **** */ + +#define MXC_AES_DATA_LEN (128 / 8) /**< Number of bytes in an AES plaintext or cyphertext block (always 128-bits) */ + +#define MXC_AES_KEY_128_LEN (128 / 8) /**< Number of bytes in a AES-128 key */ +#define MXC_AES_KEY_192_LEN (192 / 8) /**< Number of bytes in a AES-192 key */ +#define MXC_AES_KEY_256_LEN (256 / 8) /**< Number of bytes in a AES-256 key */ + +/** + * Enumeration type for AES key size selection (bits). + */ +typedef enum { + MXC_E_AES_MODE_128 = MXC_V_AES_CTRL_KEY_SIZE_128, /**< 128-bit key */ + MXC_E_AES_MODE_192 = MXC_V_AES_CTRL_KEY_SIZE_192, /**< 192-bit key */ + MXC_E_AES_MODE_256 = MXC_V_AES_CTRL_KEY_SIZE_256 /**< 256-bit key */ +} mxc_aes_mode_t; + +/** + * Enumeration type for specifying encryption/decrytion and asynchronous or blocking behavior. + */ +typedef enum { + MXC_E_AES_ENCRYPT = 0, /**< Encrypt (blocking) */ + MXC_E_AES_ENCRYPT_ASYNC = 1, /**< Encrypt (interrupt-driven) */ + MXC_E_AES_DECRYPT = 2, /**< Decrypt (blocking) */ + MXC_E_AES_DECRYPT_ASYNC = 3 /**< Decrypt (interrupt-driven) */ +} mxc_aes_dir_t; + +/* **** Function Prototypes **** */ + +/** + * @brief Configure AES block with keying material + * + * @param key 128, 192, or 256 bit keying material + * @param mode Selects key length, valid modes defined in #mxc_aes_mode_t + * + * @return #E_BAD_PARAM Specified @a mode is invalid, see #mxc_aes_mode_t. + * @return #E_NULL_PTR Invalid/Null pointer for parameter @a key. + * @return #E_SUCCESS Key and mode set up correctly. + */ +int AES_SetKey(const uint8_t *key, mxc_aes_mode_t mode); + + +/** + * @brief Encrypt/decrypt an input block with the loaded AES key. + * @note The parameters @a in and @a out should always be 16 bytes + * + * @param in Pointer to input array of 16 bytes. + * @param out Pointer to output array of 16 bytes. + * @param mode AES key size to use for the transaction, see #mxc_aes_mode_t + * @param dir Encrypt/Decrypt and Blocking or Asynchronous operation, see #mxc_aes_dir_t. + * + * @return #E_SUCCESS Operation completed successfully, output data is stored in @a *out. + * @return ErrorCode An @link MXC_Error_Codes Error Code@endlink. + */ +int AES_ECBOp(const uint8_t *in, uint8_t *out, mxc_aes_mode_t mode, mxc_aes_dir_t dir); + +/** + * @brief Read the AES output memory, used for asynchronous encryption, and clears interrupt flag. + * @note The parameter @a out is always 16 bytes + * + * @param out Pointer to output array of 16 bytes + * + * @return #E_SUCCESS Output data was written to the location pointed to by @a *out + * @return Error Code indicating the type of error encountered. See @ref MXC_Error_Codes + * for possible return code values. + */ +int AES_GetOutput(uint8_t *out); + +/** + * @def AES_ECBEncrypt(ptxt, ctxt, mode)s + * @brief Encrypt a block of plaintext with the loaded AES key, blocks until complete + * @hideinitializer + * + * @param ptxt Pointer to plaintext input array (always 16 bytes) + * @param ctxt Pointer to ciphertext output array (always 16 bytes) + * @param mode Selects key length, valid modes found in mxc_aes_mode_t + */ +#define AES_ECBEncrypt(ptxt, ctxt, mode) AES_ECBOp(ptxt, ctxt, mode, MXC_E_AES_ENCRYPT) + + +/** + * @def AES_ECBDecrypt(ctxt, ptxt, mode) + * @hideinitializer + * @brief Decrypt a block of ciphertext with the loaded AES key, blocks until complete + * + * @param ctxt Pointer to ciphertext output array (always 16 bytes) + * @param ptxt Pointer to plaintext input array (always 16 bytes) + * @param mode Selects key length, valid modes found in mxc_aes_mode_t + */ +#define AES_ECBDecrypt(ctxt, ptxt, mode) AES_ECBOp(ctxt, ptxt, mode, MXC_E_AES_DECRYPT) + +/** + * @def AES_ECBEncryptAsync(ptxt, mode) + * @hideinitializer + * @brief Starts encryption of a block, enables interrupt, and returns immediately. + * Use AES_GetOuput() to retrieve result after interrupt fires + * + * + * @param ptxt Pointer to plaintext input array (always 16 bytes) + * @param mode Selects key length, valid modes found in mxc_aes_mode_t + */ +#define AES_ECBEncryptAsync(ptxt, mode) AES_ECBOp(ptxt, NULL, mode, MXC_E_AES_ENCRYPT_ASYNC) + +/** + * @def AES_ECBDecryptAsync(ctxt, mode) + * @hideinitializer + * @brief Starts encryption of a block, enables interrupt, and returns immediately. + * Use AES_GetOuput() to retrieve result after interrupt fires + * + * @param ctxt Pointer to ciphertext output array (always 16 bytes) + * @param mode Selects key length, valid modes found in mxc_aes_mode_t + */ +#define AES_ECBDecryptAsync(ctxt, mode) AES_ECBOp(ctxt, NULL, mode, MXC_E_AES_DECRYPT_ASYNC) + +/**@} end of group aes*/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/clkman.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/clkman.c new file mode 100644 index 0000000..f26bc56 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/clkman.c @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-04-27 09:12:45 -0500 (Wed, 27 Apr 2016) $ + * $Revision: 22531 $ + * + ******************************************************************************/ +#include "mxc_config.h" +#include "mxc_assert.h" +#include "clkman.h" +#include "pwrseq_regs.h" + +/******************************************************************************/ +void CLKMAN_SetSystemClock(clkman_system_source_select_t select, clkman_system_scale_t scale) +{ + MXC_CLKMAN->clk_ctrl = ((MXC_CLKMAN->clk_ctrl & ~MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT) | + (MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO)); + + switch(select) { + case CLKMAN_SYSTEM_SOURCE_96MHZ: + default: + // Enable and select the 96MHz oscillator + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN); + MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT); + + // Disable the 4MHz oscillator + MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN; + + // Divide the system clock by the scale + MXC_PWRSEQ->reg3 = ((MXC_PWRSEQ->reg3 & ~MXC_F_PWRSEQ_REG3_PWR_RO_DIV) | + (scale << MXC_F_PWRSEQ_REG3_PWR_RO_DIV_POS)); + + break; + case CLKMAN_SYSTEM_SOURCE_4MHZ: + // Enable and select the 4MHz oscillator + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN); + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT); + + // Disable the 96MHz oscillator + MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN; + + // 4MHz System source can only be divided down by a maximum factor of 8 + MXC_ASSERT(scale <= CLKMAN_SYSTEM_SCALE_DIV_8); + + // Divide the system clock by the scale + MXC_PWRSEQ->reg3 = ((MXC_PWRSEQ->reg3 & ~MXC_F_PWRSEQ_REG3_PWR_RC_DIV) | + (scale << MXC_F_PWRSEQ_REG3_PWR_RC_DIV_POS)); + break; + } + + SystemCoreClockUpdate(); +} + +/******************************************************************************/ +void CLKMAN_CryptoClockEnable(int enable) +{ + if (enable) { + /* Enable oscillator */ + MXC_CLKMAN->clk_config |= MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE; + /* Un-gate clock to TPU modules */ + MXC_CLKMAN->clk_ctrl |= MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE; + } else { + /* Gate clock off */ + MXC_CLKMAN->clk_ctrl &= ~MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE; + /* Disable oscillator */ + MXC_CLKMAN->clk_config &= ~MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE; + } +} + +/******************************************************************************/ +void CLKMAN_SetClkScale(clkman_clk_t clk, clkman_scale_t scale) +{ + volatile uint32_t *clk_ctrl_reg; + + MXC_ASSERT(clk <= CLKMAN_CLK_MAX); + MXC_ASSERT(scale != CLKMAN_SCALE_AUTO); + + if (clk < CLKMAN_CRYPTO_CLK_AES) { + clk_ctrl_reg = &MXC_CLKMAN->sys_clk_ctrl_0_cm4 + clk; + } else { + clk_ctrl_reg = &MXC_CLKMAN->crypt_clk_ctrl_0_aes + (clk - CLKMAN_CRYPTO_CLK_AES); + } + + *clk_ctrl_reg = scale; +} + +/******************************************************************************/ +clkman_scale_t CLKMAN_GetClkScale(clkman_clk_t clk) +{ + volatile uint32_t *clk_ctrl_reg; + MXC_ASSERT(clk <= CLKMAN_CLK_MAX); + + if (clk < CLKMAN_CRYPTO_CLK_AES) { + clk_ctrl_reg = &MXC_CLKMAN->sys_clk_ctrl_0_cm4 + clk; + } else { + clk_ctrl_reg = &MXC_CLKMAN->crypt_clk_ctrl_0_aes + (clk - CLKMAN_CRYPTO_CLK_AES); + } + + return (clkman_scale_t)*clk_ctrl_reg; +} + +/******************************************************************************/ +void CLKMAN_ClockGate(clkman_enable_clk_t clk, int enable) +{ + if (enable) { + MXC_CLKMAN->clk_ctrl |= clk; + } else { + MXC_CLKMAN->clk_ctrl &= ~clk; + } +} + +/******************************************************************************/ +int CLKMAN_WdtClkSelect(unsigned int idx, clkman_wdt_clk_select_t select) +{ + MXC_ASSERT(idx < MXC_CFG_WDT_INSTANCES); + + if (select == CLKMAN_WDT_SELECT_DISABLED) { + if (idx == 0) { + MXC_CLKMAN->clk_ctrl &= ~MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE; + } else if (idx == 1) { + MXC_CLKMAN->clk_ctrl &= ~MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE; + } else { + return E_BAD_PARAM; + } + } else { + if (idx == 0) { + MXC_CLKMAN->clk_ctrl = (MXC_CLKMAN->clk_ctrl & ~MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT) | + MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE | + ((select << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS) & MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT); + } else if (idx == 1) { + MXC_CLKMAN->clk_ctrl = (MXC_CLKMAN->clk_ctrl & ~MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT) | + MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE | + ((select << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS) & MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT); + } else { + return E_BAD_PARAM; + } + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +/* NOTE: CLKMAN_TrimRO() is implemented in system_max32XXX.c */ +/******************************************************************************/ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/clkman.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/clkman.h new file mode 100644 index 0000000..03f7347 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/clkman.h @@ -0,0 +1,234 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-04-27 09:12:45 -0500 (Wed, 27 Apr 2016) $ + * $Revision: 22531 $ + * + ******************************************************************************/ + +/** + * @file clkman.h + * @brief Clock management driver header file. + */ + +#ifndef _CLKMAN_H_ +#define _CLKMAN_H_ + +/***** Includes *****/ +#include "mxc_config.h" +#include "clkman_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/** + * @brief Defines clock source selections for the system clock. + */ +typedef enum { + /** Clock select for 96MHz oscillator */ + CLKMAN_SYSTEM_SOURCE_96MHZ, + /** Clock select for 4MHz oscillator */ + CLKMAN_SYSTEM_SOURCE_4MHZ +} +clkman_system_source_select_t; + +/** + * @brief Defines clock scales for the system clock. + * @note 4MHz System source can only be divided down by a maximum factor of 8. + */ +typedef enum { + CLKMAN_SYSTEM_SCALE_DIV_1, /** Clock scale for dividing system by 1 */ + CLKMAN_SYSTEM_SCALE_DIV_2, /** Clock scale for dividing system by 2 */ + CLKMAN_SYSTEM_SCALE_DIV_4, /** Clock scale for dividing system by 4 */ + CLKMAN_SYSTEM_SCALE_DIV_8, /** Clock scale for dividing system by 8 */ + CLKMAN_SYSTEM_SCALE_DIV_16 /** Clock scale for dividing system by 16 */ +} clkman_system_scale_t; + +/** + * @brief Selects an internal module clock for clock scaling configuration. + */ +typedef enum { + CLKMAN_CLK_CPU = 0, /** CPU clock */ + CLKMAN_CLK_SYNC = 1, /** Synchronizer clock */ + CLKMAN_CLK_SPIX = 2, /** SPI XIP module clock */ + CLKMAN_CLK_PRNG = 3, /** PRNG module clock */ + CLKMAN_CLK_WDT0 = 4, /** Watchdog Timer 0 clock */ + CLKMAN_CLK_WDT1 = 5, /** Watchdog Timer 1 clock */ + CLKMAN_CLK_GPIO = 6, /** GPIO module clock */ + CLKMAN_CLK_PT = 7, /** Pulse Train engine clock */ + CLKMAN_CLK_UART = 8, /** UART clock */ + CLKMAN_CLK_I2CM = 9, /** I2C Master module clock (for all instances) */ + CLKMAN_CLK_I2CS = 10, /** I2C Slave module clock */ + CLKMAN_CLK_SPIM0 = 11, /** SPI Master instance 0 module clock */ + CLKMAN_CLK_SPIM1 = 12, /** SPI Master instance 1 module clock */ + CLKMAN_CLK_SPIM2 = 13, /** SPI Master instance 2 module clock */ + CLKMAN_CLK_OWM = 15, /** OWM module clock*/ + CLKMAN_CLK_SPIS = 16, /** SPI Slave module clock*/ + CLKMAN_CRYPTO_CLK_AES = 17, /** AES engine clock */ + CLKMAN_CRYPTO_CLK_MAA = 18, /** Modular Arithmetic Accelerator (MAA) clock */ + CLKMAN_CRYPTO_CLK_PRNG = 19, /** Pseudo-random number Generator (PRNG) clock */ + CLKMAN_CLK_MAX = 19 +} clkman_clk_t; + +/** + * @brief Selects a clock to enable/disable + */ +typedef enum { + CLKMAN_USB_CLOCK = MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_ENABLE, + CLKMAN_CRYPTO_CLOCK = MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE, + CLKMAN_ADC_CLOCK = MXC_F_CLKMAN_CLK_CTRL_ADC_CLOCK_ENABLE, + CLKMAN_WDT0_CLOCK = MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE, + CLKMAN_WDT1_CLOCK = MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE, + CLKMAN_RTOS_MODE = MXC_F_CLKMAN_CLK_CTRL_RTOS_MODE, +} clkman_enable_clk_t; + +/** + * @brief Defines clock scales for various clocks. + */ +typedef enum { + CLKMAN_SCALE_DISABLED = MXC_V_CLKMAN_CLK_SCALE_DISABLED, /** Clock disabled */ + CLKMAN_SCALE_DIV_1 = MXC_V_CLKMAN_CLK_SCALE_DIV_1, /** Clock scale for dividing by 1 */ + CLKMAN_SCALE_DIV_2 = MXC_V_CLKMAN_CLK_SCALE_DIV_2, /** Clock scale for dividing by 2 */ + CLKMAN_SCALE_DIV_4 = MXC_V_CLKMAN_CLK_SCALE_DIV_4, /** Clock scale for dividing by 4 */ + CLKMAN_SCALE_DIV_8 = MXC_V_CLKMAN_CLK_SCALE_DIV_8, /** Clock scale for dividing by 8 */ + CLKMAN_SCALE_DIV_16 = MXC_V_CLKMAN_CLK_SCALE_DIV_16, /** Clock scale for dividing by 16 */ + CLKMAN_SCALE_DIV_32 = MXC_V_CLKMAN_CLK_SCALE_DIV_32, /** Clock scale for dividing by 32 */ + CLKMAN_SCALE_DIV_64 = MXC_V_CLKMAN_CLK_SCALE_DIV_64, /** Clock scale for dividing by 64 */ + CLKMAN_SCALE_DIV_128 = MXC_V_CLKMAN_CLK_SCALE_DIV_128, /** Clock scale for dividing by 128 */ + CLKMAN_SCALE_DIV_256 = MXC_V_CLKMAN_CLK_SCALE_DIV_256, /** Clock scale for dividing by 256 */ + CLKMAN_SCALE_AUTO /** Clock scale to auto select divider */ +} clkman_scale_t; + +/** + * @brief Defines clock selections for the watchdog timers. + */ +typedef enum { + CLKMAN_WDT_SELECT_SCALED_SYS_CLK_CTRL = MXC_V_CLKMAN_WDT0_CLOCK_SELECT_SCALED_SYS_CLK_CTRL_4_WDT0, + CLKMAN_WDT_SELECT_32KHZ_RTC_OSCILLATOR = MXC_V_CLKMAN_WDT0_CLOCK_SELECT_32KHZ_RTC_OSCILLATOR, + CLKMAN_WDT_SELECT_96MHZ_OSCILLATOR = MXC_V_CLKMAN_WDT0_CLOCK_SELECT_96MHZ_OSCILLATOR, + CLKMAN_WDT_SELECT_NANO_RING_OSCILLATOR = MXC_V_CLKMAN_WDT0_CLOCK_SELECT_NANO_RING_OSCILLATOR, + CLKMAN_WDT_SELECT_DISABLED +} clkman_wdt_clk_select_t; + + +/***** Function Prototypes *****/ + +/** + * @brief Selects the system clock source. + * @note 4MHz System source can only be divided down by a maximum factor of 8. + * @param select System clock source. + * @param scale System clock scaler. + */ +void CLKMAN_SetSystemClock(clkman_system_source_select_t select, clkman_system_scale_t scale); + +/** + * @brief Enables/disables the Crypto/TPU relaxation oscillator + * @param enable enable (1) or disable (0) + */ +void CLKMAN_CryptoClockEnable(int enable); + +/** + * @brief Enables/Disables the specified clock. + * @param clk clock to enable/disable + * @param enable enable (1) or disable (0) + */ +void CLKMAN_ClockGate(clkman_enable_clk_t clk, int enable); + +/** + * @brief Sets the specified clock scaler value. + * @param clk clock to set scaler value for + * @param scale clock scaler value + */ +void CLKMAN_SetClkScale(clkman_clk_t clk, clkman_scale_t scale); + +/** + * @brief Get the specified clock scaler value + * @param clk clock to get the scaler value for + */ +clkman_scale_t CLKMAN_GetClkScale(clkman_clk_t clk); + +/** + * @brief Selects the clock source for the watchdog timer + * @param idx index of the watchdog timer + * @param select clock to select + * @returns E_NO_ERROR if successful + */ +int CLKMAN_WdtClkSelect(unsigned int idx, clkman_wdt_clk_select_t select); + +/** + * @brief Get the interrupt flags + * @returns mask mask of flags set + */ +__STATIC_INLINE uint32_t CLKMAN_GetFlags(void) +{ + return MXC_CLKMAN->intfl; +} + +/** + * @brief Clear the specified interrupt flags + * @param mask mask of flags to clear + */ +__STATIC_INLINE void CLKMAN_ClrFlags(uint32_t mask) +{ + MXC_CLKMAN->intfl = mask; +} + +/** + * @brief Enable the specified interrupt flags + * @param mask mask of flags to enable + */ +__STATIC_INLINE void CLKMAN_EnableInt(uint32_t mask) +{ + MXC_CLKMAN->inten |= mask; +} + +/** + * @brief Disable the specified interrupt flags + * @param mask mask of flags to disable + */ +__STATIC_INLINE void CLKMAN_DisableInt(uint32_t mask) +{ + MXC_CLKMAN->inten &= ~mask; +} + +/** + * @brief Trim the ring oscillator. + */ +void CLKMAN_TrimRO(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _CLKMAN_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/crc.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/crc.c new file mode 100644 index 0000000..735cac4 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/crc.c @@ -0,0 +1,108 @@ +/** + * @file crc.c + * @brief This file contains the function implementations for the Cyclic + * Redundency Check (CRC) peripheral module. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:45:09 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23897 $ + * + *************************************************************************** */ + +/* **** Includes **** */ +#include "crc.h" + +/** + * @ingroup crc + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Functions **** */ + +/* ************************************************************************* */ +void CRC16_Init(uint8_t CCITT_TRUE, uint8_t lilEndian) +{ + if(CCITT_TRUE) + MXC_CRC->reseed |= MXC_F_CRC_RESEED_CCITT_MODE; + else + MXC_CRC->reseed &= ~MXC_F_CRC_RESEED_CCITT_MODE; + + if(lilEndian) + MXC_CRC->reseed |= MXC_F_CRC_RESEED_REV_ENDIAN16; + else + MXC_CRC->reseed &= ~MXC_F_CRC_RESEED_REV_ENDIAN16; +} + +/* ************************************************************************* */ +void CRC32_Init(uint8_t lilEndian) +{ + if(lilEndian) + MXC_CRC->reseed |= MXC_F_CRC_RESEED_REV_ENDIAN32; + else + MXC_CRC->reseed &= ~MXC_F_CRC_RESEED_REV_ENDIAN32; +} + +/* ************************************************************************* */ + +void CRC16_Reseed(uint16_t initData) +{ + //set initial value + MXC_CRC->seed16 = initData; + + //reseed the CRC16 generator + MXC_CRC->reseed |= MXC_F_CRC_RESEED_CRC16; + + //wait for reseed to clear itself + while(MXC_CRC->reseed & MXC_F_CRC_RESEED_CRC16); + +} + +/* ************************************************************************* */ +void CRC32_Reseed(uint32_t initData) +{ + //set initial value + MXC_CRC->seed32 = initData; + + //reseed the CRC16 generator + MXC_CRC->reseed |= MXC_F_CRC_RESEED_CRC32; + + //wait for reseed to clear itself + while(MXC_CRC->reseed & MXC_F_CRC_RESEED_CRC32); +} + +/**@} end of group crc */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/crc.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/crc.h new file mode 100644 index 0000000..646c716 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/crc.h @@ -0,0 +1,191 @@ +/** + * @file crc.h + * @brief CRC peripheral module function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:45:09 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23897 $ + * + **************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _CRC_H_ +#define _CRC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup crc Cyclic Redundancy Check (CRC) + * @ingroup periphlibs + * @brief High-level API for CRC Peripheral Module + * @{ + */ + +/** + * @page crc_overview Overview and Usage + * @parblock + * - Initialize the CRC for usage by calling either the CRC16_Init() function or the CRC32_Init() funciton + * + For CRC16, CCITT mode is enabled if the parameter is set + * + Select the Endian of the data for calculation + * - passing a 1 sets the module to little endian + * - passing a 0 sets the module to big endian + * - Set the intial CRC seed by calling CRC16_Reseed() or CRC32_Reseed() + * + This is the initial value of the CRC remainder to be used when the data is passed to the module + * - Pass data to the CRC engine using the methods: + * + CRC16_AddData() + * + CRC16_AddDataArray() + * + CRC32_AddData() + * + CRC32_AddDataArray() + * @note any data passed to the add methods of the peripheral is padded with zeros if it is less than + * 32-bits. + * @endparblock +*/ + + +/* **** Includes **** */ +#include "mxc_config.h" +#include +#include "crc_regs.h" + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize CRC clock and select CRC16 mode and byte order. + * + * @param CCITT_TRUE CRC16-CCITT-TRUE = 1, CRC16-CCITT-FALSE = 0 + * @param lilEndian byte order, little endian = 1, big endian = 0 + */ +void CRC16_Init(uint8_t CCITT_TRUE, uint8_t lilEndian); + +/** + * @brief Initialize CRC clock and select byte order for CRC32. + * + * @param lilEndian byte order, little endian = 1, big endian = 0 + */ +void CRC32_Init(uint8_t lilEndian); + +/** + * @brief Initialize CRC16 calculation. + * + * @param initData intial remainder to start the CRC16 calculation with + */ +void CRC16_Reseed(uint16_t initData); + +/** + * @brief Initialize CRC32 calculation. + * + * @param initData intial remainder to start the CRC32 calculation with + */ +void CRC32_Reseed(uint32_t initData); + +/** + * @brief Add data to the CRC16 calculation. + * + * @param data data to add to the CRC16 calculation + * @note data is padded with zeros if less than 32bits. + */ +__STATIC_INLINE void CRC16_AddData(uint32_t data) +{ + MXC_CRC_DATA->value16[0] = data; +} + +/** + * @brief Add data to the CRC32 calculation + * + * @param data data to add to the CRC32 calculation + * @note data is padded with zeros if less than 32bits + */ +__STATIC_INLINE void CRC32_AddData(uint32_t data) +{ + MXC_CRC_DATA->value32[0] = data; +} + +/** + * @brief Add an array of data to the CRC16 calculation + * + * @param data pointer to array of data + * @note data is padded with zeros if less than 32bits + * + * @param arrayLength number of elements in array + */ +__STATIC_INLINE void CRC16_AddDataArray(uint32_t *data, uint32_t arrayLength) +{ + memcpy((void *)(&(MXC_CRC_DATA->value16)), (void *)data, arrayLength * sizeof(data[0])); +} + +/** + * @brief Add an array of data to the CRC32 calculation + * + * @param data pointer to array of data + * @note data is padded with zeros if less than 32bits + * @param arrayLength number of elements in array + */ +__STATIC_INLINE void CRC32_AddDataArray(uint32_t *data, uint32_t arrayLength) +{ + memcpy((void *)(&(MXC_CRC_DATA->value32)), (void *)data, arrayLength * sizeof(data[0])); +} + +/** + * @brief Get the calculated CRC16 value + * + * @return CRC16 value + */ +__STATIC_INLINE uint32_t CRC16_GetCRC() +{ + return MXC_CRC_DATA->value16[0]; +} + +/** + * @brief Get the calculated CRC32 value + * + * @return CRC32 value + */ +__STATIC_INLINE uint32_t CRC32_GetCRC() +{ + return MXC_CRC_DATA->value32[0]; +} + +/**@} end of crc group */ + +#ifdef __cplusplus +} +#endif + +#endif /* _CRC_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/flc.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/flc.c new file mode 100644 index 0000000..9a02ce6 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/flc.c @@ -0,0 +1,260 @@ +/** + * @file flc.c + * @brief This file contains the function implementations for the Flash + * Controller peripheral module. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:46:43 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23898 $ + * + *************************************************************************** */ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "flc.h" + + +/** + * @ingroup flc + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Functions **** */ + +/* ************************************************************************* */ +#if defined ( __GNUC__ ) +#undef IAR_PRAGMAS //Make sure this is not defined for GCC +#endif + +#if IAR_PRAGMAS +// IAR memory section declaration for the in-system flash programming functions to be loaded in RAM. +#pragma section=".flashprog" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".flashprog"))) +#endif +/** + * @brief Return the status of the busy state of the flash controller. + * + * @return 0 Flash Controller is idle. + * @return Non-zero indicates the flash controller is performing an + * erase or write request. + */ +__STATIC_INLINE int FLC_Busy(void) +{ + return (MXC_FLC->ctrl & (MXC_F_FLC_CTRL_WRITE | MXC_F_FLC_CTRL_MASS_ERASE | MXC_F_FLC_CTRL_PAGE_ERASE)); +} + +/* ************************************************************************* */ +#if IAR_PRAGMAS +// IAR memory section declaration for the in-system flash programming functions to be loaded in RAM. +#pragma section=".flashprog" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".flashprog"))) +#endif +int FLC_Init(void) +{ + /* Check if the flash controller is busy */ + if (FLC_Busy()) { + return E_BUSY; + } + + /* Enable automatic calculation of the clock divider to generate a 1MHz clock from the APB clock */ + MXC_FLC->perform |= MXC_F_FLC_PERFORM_AUTO_CLKDIV; + + /* The flash controller will stall any reads while flash operations are in + * progress. Disable the legacy failure detection logic that would flag reads + * during flash operations as errors. + */ + MXC_FLC->perform |= MXC_F_FLC_PERFORM_EN_PREVENT_FAIL; + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +#if IAR_PRAGMAS +// IAR memory section declaration for the in-system flash programming functions to be loaded in RAM. +#pragma section=".flashprog" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".flashprog"))) +#endif +int FLC_PageErase(uint32_t address, uint8_t erase_code, uint8_t unlock_key) +{ + /* Check if the flash controller is busy */ + if (FLC_Busy()) { + return E_BUSY; + } + + /* Clear stale errors. Interrupt flags can only be written to zero, so this is safe */ + MXC_FLC->intr &= ~MXC_F_FLC_INTR_FAILED_IF; + + /* Unlock flash */ + MXC_FLC->ctrl = (MXC_FLC->ctrl & ~MXC_F_FLC_CTRL_FLSH_UNLOCK) | + ((unlock_key << MXC_F_FLC_CTRL_FLSH_UNLOCK_POS) & MXC_F_FLC_CTRL_FLSH_UNLOCK); + + /* Write the Erase Code */ + MXC_FLC->ctrl = (MXC_FLC->ctrl & ~MXC_F_FLC_CTRL_ERASE_CODE) | + ((erase_code << MXC_F_FLC_CTRL_ERASE_CODE_POS) & MXC_F_FLC_CTRL_ERASE_CODE); + + /* Erase the request page */ + MXC_FLC->faddr = address; + MXC_FLC->ctrl |= MXC_F_FLC_CTRL_PAGE_ERASE; + + /* Wait until flash operation is complete */ + while (FLC_Busy()); + + /* Lock flash */ + MXC_FLC->ctrl &= ~(MXC_F_FLC_CTRL_FLSH_UNLOCK | MXC_F_FLC_CTRL_ERASE_CODE); + + /* Check for failures */ + if (MXC_FLC->intr & MXC_F_FLC_INTR_FAILED_IF) { + /* Interrupt flags can only be written to zero, so this is safe */ + MXC_FLC->intr &= ~MXC_F_FLC_INTR_FAILED_IF; + return E_UNKNOWN; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +#if IAR_PRAGMAS +// IAR memory section declaration for the in-system flash programming functions to be loaded in RAM. +#pragma section=".flashprog" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".flashprog"))) +#endif +int FLC_Write(uint32_t address, const void *data, uint32_t length, uint8_t unlock_key) +{ + uint32_t *ptr = (uint32_t*)data; + + /* Can only write in full word units */ + if ((address & 3) || (length & 3)) { + return E_BAD_PARAM; + } + + if (length == 0) { + /* Nothing to do */ + return E_NO_ERROR; + } + + /* Check if the flash controller is busy */ + if (FLC_Busy()) { + return E_BUSY; + } + + /* Clear stale errors. Interrupt flags can only be written to zero, so this is safe */ + MXC_FLC->intr &= ~MXC_F_FLC_INTR_FAILED_IF; + + /* Unlock flash */ + MXC_FLC->ctrl = (MXC_FLC->ctrl & ~MXC_F_FLC_CTRL_FLSH_UNLOCK) | + ((unlock_key << MXC_F_FLC_CTRL_FLSH_UNLOCK_POS) & MXC_F_FLC_CTRL_FLSH_UNLOCK); + + /* Set the address to write and enable auto increment */ + MXC_FLC->faddr = address; + MXC_FLC->ctrl |= MXC_F_FLC_CTRL_AUTO_INCRE_MODE; + uint32_t write_cmd = MXC_FLC->ctrl | MXC_F_FLC_CTRL_WRITE; + + for (; length > 0; length -= 4) { + /* Perform the write */ + MXC_FLC->fdata = *ptr++; + MXC_FLC->ctrl = write_cmd; + while (FLC_Busy()); + } + + /* Lock flash */ + MXC_FLC->ctrl &= ~MXC_F_FLC_CTRL_FLSH_UNLOCK; + + /* Check for failures */ + if (MXC_FLC->intr & MXC_F_FLC_INTR_FAILED_IF) { + /* Interrupt flags can only be written to zero, so this is safe */ + MXC_FLC->intr &= ~MXC_F_FLC_INTR_FAILED_IF; + return E_UNKNOWN; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +#if IAR_PRAGMAS +// IAR memory section declaration for the in-system flash programming functions to be loaded in RAM. +#pragma section=".flashprog" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".flashprog"))) +#endif +int FLC_MassErase(uint8_t erase_code, uint8_t unlock_key) +{ + /* Check if the flash controller is busy */ + if (FLC_Busy()) { + return E_BUSY; + } + + /* Clear stale errors. Interrupt flags can only be written to zero, so this is safe */ + MXC_FLC->intr &= ~MXC_F_FLC_INTR_FAILED_IF; + + /* Unlock flash */ + MXC_FLC->ctrl = (MXC_FLC->ctrl & ~MXC_F_FLC_CTRL_FLSH_UNLOCK) | + ((unlock_key << MXC_F_FLC_CTRL_FLSH_UNLOCK_POS) & MXC_F_FLC_CTRL_FLSH_UNLOCK); + + /* Write the Erase Code */ + MXC_FLC->ctrl = (MXC_FLC->ctrl & ~MXC_F_FLC_CTRL_ERASE_CODE) | + ((erase_code << MXC_F_FLC_CTRL_ERASE_CODE_POS) & MXC_F_FLC_CTRL_ERASE_CODE); + + /* Start the mass erase */ + MXC_FLC->ctrl |= MXC_F_FLC_CTRL_MASS_ERASE; + + /* Wait until flash operation is complete */ + while (FLC_Busy()); + + /* Lock flash */ + MXC_FLC->ctrl &= ~(MXC_F_FLC_CTRL_FLSH_UNLOCK | MXC_F_FLC_CTRL_ERASE_CODE); + + /* Check for failures */ + if (MXC_FLC->intr & MXC_F_FLC_INTR_FAILED_IF) { + /* Interrupt flags can only be written to zero, so this is safe */ + MXC_FLC->intr &= ~MXC_F_FLC_INTR_FAILED_IF; + return E_UNKNOWN; + } + + return E_NO_ERROR; +} + +/**@} end of group flc */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/flc.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/flc.h new file mode 100644 index 0000000..c4716a4 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/flc.h @@ -0,0 +1,117 @@ +/** + * @file flc.h + * @brief Flash Controller function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-02 13:46:43 -0500 (Tue, 02 Aug 2016) $ + * $Revision: 23898 $ + * + *************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _FLC_H_ +#define _FLC_H_ + +/* **** Includes **** */ +#include "flc_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup flc Flash Controller + * @ingroup sysconfig + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Function Prototypes **** */ + +/** + * @brief Prepares the Flash Controller for in-application flash operations. This function + * only needs to be called one time after a reset event. + * + * @return #E_NO_ERROR if flash controller initialized correctly, error if + * unsuccessful. + */ +int FLC_Init(void); + +/** + * @brief This function will erase a single page of flash. + * + * @param address Address of the page to be erased. + * @param erase_code Flash erase code; defined as + * #MXC_V_FLC_ERASE_CODE_PAGE_ERASE for page erase + * @param unlock_key Unlock key, #MXC_V_FLC_FLSH_UNLOCK_KEY. + * + * @returns #E_NO_ERROR if page erase successful, error if unsuccessful. + */ +int FLC_PageErase(uint32_t address, uint8_t erase_code, uint8_t unlock_key); + +/** + * @brief This function writes data to the flash device through the flash + * controller interface + * + * @param address Start address for desired write. @note This address + * must be 32-bit word aligned + * @param data A pointer to the buffer containing the data to write. + * @param length Size of the data to write in bytes. @note The length + * must be in 32-bit multiples. + * @param unlock_key Unlock key, #MXC_V_FLC_FLSH_UNLOCK_KEY. + * + * @returns #E_NO_ERROR if data written successfully, error if unsuccessful. + */ +int FLC_Write(uint32_t address, const void *data, uint32_t length, uint8_t unlock_key); + +/** + * @brief This function will mass erase the flash. + * + * @param erase_code Flash erase code, #MXC_V_FLC_ERASE_CODE_MASS_ERASE. + * @param unlock_key Unlock key, #MXC_V_FLC_FLSH_UNLOCK_KEY. + * + * @returns #E_NO_ERROR if device mass erase successful, error if unsuccessful. + */ +int FLC_MassErase(uint8_t erase_code, uint8_t unlock_key); + +/**@} end of group flc */ + +#ifdef __cplusplus +} +#endif + +#endif /* _FLC_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.c new file mode 100644 index 0000000..2e0f10c --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.c @@ -0,0 +1,186 @@ +/** + * @file gpio.c + * @brief This file contains the function implementations for the + * General-Purpose Input/Output (GPIO) peripheral module. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 20:04:11 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24085 $ + * + *************************************************************************** */ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "mxc_assert.h" +#include "mxc_sys.h" +#include "gpio.h" +#include "clkman_regs.h" + +/** + * @ingroup gpio + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* ************************************************************************* */ +static void (*callbacks[MXC_GPIO_NUM_PORTS][MXC_GPIO_MAX_PINS_PER_PORT])(void *); +static void *cbparam[MXC_GPIO_NUM_PORTS][MXC_GPIO_MAX_PINS_PER_PORT]; + +/* **** Functions **** */ + +/* ************************************************************************* */ +static int PinConfig(unsigned int port, unsigned int pin, gpio_func_t func, gpio_pad_t pad) +{ + /* Check if available */ + if (!(MXC_GPIO->free[port] & (1 << pin))) { + return E_BUSY; + } + + /* Set function */ + uint32_t func_sel = MXC_GPIO->func_sel[port]; + func_sel &= ~(0xF << (4 * pin)); + func_sel |= (func << (4 * pin)); + MXC_GPIO->func_sel[port] = func_sel; + + /* Normal input is always enabled */ + MXC_GPIO->in_mode[port] &= ~(0xF << (4 * pin)); + + /* Set requested output mode */ + uint32_t out_mode = MXC_GPIO->out_mode[port]; + out_mode &= ~(0xF << (4 * pin)); + out_mode |= (pad << (4 * pin)); + MXC_GPIO->out_mode[port] = out_mode; + + /* Enable the pull up/down if necessary */ + if (pad == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP) { + MXC_GPIO->out_val[port] |= (1 << pin); + } else if (pad == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN) { + MXC_GPIO->out_val[port] &= ~(1 << pin); + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int GPIO_Config(const gpio_cfg_t *cfg) +{ + unsigned int pin; + int err = E_NO_ERROR; + + MXC_ASSERT(cfg); + MXC_ASSERT(cfg->port < MXC_GPIO_NUM_PORTS); + + // Set system level configurations + if ((err = SYS_GPIO_Init()) != E_NO_ERROR) { + return err; + } + + // Configure each pin in the mask + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if (cfg->mask & (1 << pin)) { + if (PinConfig(cfg->port, pin, cfg->func, cfg->pad) != E_NO_ERROR) { + err = E_BUSY; + } + } + } + + return err; +} + +/* ************************************************************************* */ +static void IntConfig(unsigned int port, unsigned int pin, gpio_int_mode_t mode) +{ + uint32_t int_mode = MXC_GPIO->int_mode[port]; + int_mode &= ~(0xF << (pin*4)); + int_mode |= (mode << (pin*4)); + MXC_GPIO->int_mode[port] = int_mode; +} + +/* ************************************************************************* */ +void GPIO_IntConfig(const gpio_cfg_t *cfg, gpio_int_mode_t mode) +{ + unsigned int pin; + + MXC_ASSERT(cfg); + MXC_ASSERT(cfg->port < MXC_GPIO_NUM_PORTS); + + // Configure each pin in the mask + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if (cfg->mask & (1 << pin)) { + IntConfig(cfg->port, pin, mode); + } + } +} + +/* ************************************************************************* */ +void GPIO_RegisterCallback(const gpio_cfg_t *cfg, gpio_callback_fn func, void *cbdata) +{ + unsigned int pin; + + MXC_ASSERT(cfg); + MXC_ASSERT(cfg->port < MXC_GPIO_NUM_PORTS); + + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if (cfg->mask & (1 << pin)) { + callbacks[cfg->port][pin] = func; + cbparam[cfg->port][pin] = cbdata; + } + } +} + +/* ************************************************************************* */ +void GPIO_Handler(unsigned int port) +{ + uint8_t intfl; + unsigned int pin; + + MXC_ASSERT(port < MXC_GPIO_NUM_PORTS); + + // Read and clear enabled interrupts. + intfl = MXC_GPIO->intfl[port]; + intfl &= MXC_GPIO->inten[port]; + MXC_GPIO->intfl[port] = intfl; + + // Process each pins' interrupt + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if ((intfl & (1 << pin)) && callbacks[port][pin]) { + callbacks[port][pin](cbparam[port][pin]); + } + } +} + +/**@} end of group gpio */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.h new file mode 100644 index 0000000..e9fcfd6 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.h @@ -0,0 +1,315 @@ +/** + * @file gpio.h + * @brief General-Purpose Input/Output (GPIO) function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 20:04:11 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24085 $ + * + *************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _GPIO_H_ +#define _GPIO_H_ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "gpio_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Doxy group definition for this peripheral module +/** + * @defgroup gpio General-Purpose Input/Output (GPIO) + * @ingroup periphlibs + * @{ + */ + +/* **** Definitions **** */ +/** + * @defgroup gpio_port_pin Port and Pin Definitions + * @ingroup gpio + * @{ + * @defgroup gpio_port Port Definitions + * @ingroup gpio_port_pin + * @{ + */ +#define PORT_0 (0) /**< Port 0 Define*/ +#define PORT_1 (1) /**< Port 1 Define*/ +#define PORT_2 (2) /**< Port 2 Define*/ +#define PORT_3 (3) /**< Port 3 Define*/ +#define PORT_4 (4) /**< Port 4 Define*/ +#define PORT_5 (5) /**< Port 5 Define*/ +#define PORT_6 (6) /**< Port 6 Define*/ +#define PORT_7 (7) /**< Port 7 Define*/ +#define PORT_8 (8) /**< Port 8 Define*/ +#define PORT_9 (9) /**< Port 9 Define*/ +#define PORT_10 (10) /**< Port 10 Define*/ +#define PORT_11 (11) /**< Port 11 Define*/ +#define PORT_12 (12) /**< Port 12 Define*/ +#define PORT_13 (13) /**< Port 13 Define*/ +#define PORT_14 (14) /**< Port 14 Define*/ +#define PORT_15 (15) /**< Port 15 Define*/ +/**@} end of gpio_port group*/ +/** + * @defgroup gpio_pin Pin Definitions + * @ingroup gpio_port_pin + * @{ + */ +#define PIN_0 (1 << 0) /**< Pin 0 Define */ +#define PIN_1 (1 << 1) /**< Pin 1 Define */ +#define PIN_2 (1 << 2) /**< Pin 2 Define */ +#define PIN_3 (1 << 3) /**< Pin 3 Define */ +#define PIN_4 (1 << 4) /**< Pin 4 Define */ +#define PIN_5 (1 << 5) /**< Pin 5 Define */ +#define PIN_6 (1 << 6) /**< Pin 6 Define */ +#define PIN_7 (1 << 7) /**< Pin 7 Define */ +/**@} end of gpio_pin group */ +/**@} end of gpio_port_pin group */ + +/** + * Enumeration type for the GPIO Function Type + */ +typedef enum { + GPIO_FUNC_GPIO = MXC_V_GPIO_FUNC_SEL_MODE_GPIO, /**< GPIO Function Selection */ + GPIO_FUNC_PT = MXC_V_GPIO_FUNC_SEL_MODE_PT, /**< Pulse Train Function Selection */ + GPIO_FUNC_TMR = MXC_V_GPIO_FUNC_SEL_MODE_TMR /**< Timer Function Selection */ +} +gpio_func_t; + +/** + * Enumeration type for the type of GPIO pad on a given pin. + */ +typedef enum { + GPIO_PAD_INPUT_PULLUP = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP, /**< Set pad to high impedance, weak pull-up */ + GPIO_PAD_OPEN_DRAIN = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN, /**< Set pad to open-drain with high impedance with input buffer */ + GPIO_PAD_OPEN_DRAIN_PULLUP = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN_WEAK_PULLUP, /**< Set pad to open-drain with weak pull-up */ + GPIO_PAD_INPUT = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z, /**< Set pad to high impednace, input buffer enabled */ + GPIO_PAD_NORMAL = MXC_V_GPIO_OUT_MODE_NORMAL, /**< Set pad to normal drive mode for high an low output */ + GPIO_PAD_SLOW = MXC_V_GPIO_OUT_MODE_SLOW_DRIVE, /**< Set pad to slow drive mode, which is normal mode with negative feedback to slow edge transitions */ + GPIO_PAD_FAST = MXC_V_GPIO_OUT_MODE_FAST_DRIVE, /**< Set pad to fash drive mode, which is normal mode with a transistor drive to drive fast high and low */ + GPIO_PAD_INPUT_PULLDOWN = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN, /**< Set pad to weak pulldown mode */ + GPIO_PAD_OPEN_SOURCE = MXC_V_GPIO_OUT_MODE_OPEN_SOURCE, /**< Set pad to open source mode, transistor drive to high */ + GPIO_PAD_OPEN_SOURCE_PULLDOWN = MXC_V_GPIO_OUT_MODE_OPEN_SOURCE_WEAK_PULLDOWN /**< Set pad to open source with weak pulldown mode, transistor drive to high, weak pulldown to GND for low */ +} gpio_pad_t; + +/** + * Structure type for configuring a GPIO port. + */ +typedef struct { + uint32_t port; /// Index of GPIO port + uint32_t mask; /// Pin mask. Multiple bits can be set. + gpio_func_t func; /// Function type + gpio_pad_t pad; /// Pad type +} gpio_cfg_t; + +/** + * Enumeration type for the interrupt type on a GPIO port. + */ +typedef enum { + GPIO_INT_DISABLE = MXC_V_GPIO_INT_MODE_DISABLE, /**< Disable interrupts */ + GPIO_INT_FALLING_EDGE = MXC_V_GPIO_INT_MODE_FALLING_EDGE, /**< Interrupt on Falling Edge */ + GPIO_INT_RISING_EDGE = MXC_V_GPIO_INT_MODE_RISING_EDGE, /**< Interrupt on Rising Edge */ + GPIO_INT_ANY_EDGE = MXC_V_GPIO_INT_MODE_ANY_EDGE, /**< Interrupt on Falling or Rising Edge */ + GPIO_INT_LOW_LEVEL = MXC_V_GPIO_INT_MODE_LOW_LVL, /**< Interrupt on a low level input detection */ + GPIO_INT_HIGH_LEVEL = MXC_V_GPIO_INT_MODE_HIGH_LVL /**< Interrupt on a high level input detection */ +} gpio_int_mode_t; + +/* **** Function Prototypes **** */ + +/** + * @brief Configure GPIO pin(s). + * @param cfg Pointer to configuration structure describing the pin. + * + * @return #E_NO_ERROR if everything is successful. + * + */ +int GPIO_Config(const gpio_cfg_t *cfg); + +/** + * @brief Gets the pin(s) input state. + * @param cfg Pointer to configuration structure describing the pin. + * + * @return The requested pin state. + * + */ +__STATIC_INLINE uint32_t GPIO_InGet(const gpio_cfg_t *cfg) +{ + return (MXC_GPIO->in_val[cfg->port] & cfg->mask); +} + +/** + * @brief Sets the pin(s) to a high level output. + * @param cfg Pointer to configuration structure describing the pin. + * + */ +__STATIC_INLINE void GPIO_OutSet(const gpio_cfg_t *cfg) +{ + MXC_GPIO->out_val[cfg->port] |= cfg->mask; +} + +/** + * @brief Clears the pin(s) to a low level output. + * @param cfg Pointer to configuration structure describing the pin. + * + */ +__STATIC_INLINE void GPIO_OutClr(const gpio_cfg_t *cfg) +{ + MXC_GPIO->out_val[cfg->port] &= ~(cfg->mask); +} + +/** + * @brief Gets the pin(s) output state. + * @param cfg Pointer to configuration structure describing the pin. + * + * @return The state of the requested pin. + * + */ +__STATIC_INLINE uint32_t GPIO_OutGet(const gpio_cfg_t *cfg) +{ + return (MXC_GPIO->out_val[cfg->port] & cfg->mask); +} + +/** + * @brief Write the pin(s) to a desired output level. + * @param cfg Pointer to configuration structure describing the pin. + * @param val Desired output level of the pin(s). This will be masked + * with the configuration mask. + * + */ +__STATIC_INLINE void GPIO_OutPut(const gpio_cfg_t *cfg, uint32_t val) +{ + MXC_GPIO->out_val[cfg->port] = (MXC_GPIO->out_val[cfg->port] & ~cfg->mask) | (val & cfg->mask); +} + +/** + * @brief Toggles the the pin(s) output level. + * @param cfg Pointer to configuration structure describing the pin. + * + */ +__STATIC_INLINE void GPIO_OutToggle(const gpio_cfg_t *cfg) +{ + MXC_GPIO->out_val[cfg->port] ^= cfg->mask; +} + +/** + * @brief Configure GPIO interrupt(s) + * @param cfg Pointer to configuration structure describing the pin. + * @param mode Requested interrupt mode. + * + */ +void GPIO_IntConfig(const gpio_cfg_t *cfg, gpio_int_mode_t mode); + +/** + * @brief Enables the specified GPIO interrupt + * @param cfg Pointer to configuration structure describing the pin. + * + */ +__STATIC_INLINE void GPIO_IntEnable(const gpio_cfg_t *cfg) +{ + MXC_GPIO->inten[cfg->port] |= cfg->mask; +} + +/** + * @brief Disables the specified GPIO interrupt. + * @param cfg Pointer to configuration structure describing the pin. + * + */ +__STATIC_INLINE void GPIO_IntDisable(const gpio_cfg_t *cfg) +{ + MXC_GPIO->inten[cfg->port] &= ~cfg->mask; +} + +/** + * @brief Gets the interrupt(s) status on a GPIO pin. + * @param cfg Pointer to configuration structure describing the pin + * for which the status is being requested. + * + * @return The requested interrupt status. + * + */ +__STATIC_INLINE uint32_t GPIO_IntStatus(const gpio_cfg_t *cfg) +{ + return (MXC_GPIO->intfl[cfg->port] & cfg->mask); +} + +/** + * @brief Clears the interrupt(s) status on a GPIO pin. + * @param cfg Pointer to configuration structure describing the pin + * to clear the interrupt state of. + * + */ +__STATIC_INLINE void GPIO_IntClr(const gpio_cfg_t *cfg) +{ + MXC_GPIO->intfl[cfg->port] = cfg->mask; +} + +/** + * @brief Type alias for a GPIO callback function with prototype: + * @code + * void callback_fn(void *cbdata); + * @endcode + * @param cbdata A void pointer to the data type as registered when + * @c GPIO_RegisterCallback() was called. + * + */ +typedef void (*gpio_callback_fn)(void *cbdata); + +/** + * @brief Registers a callback for the interrupt on a given port and pin. + * @param cfg Pointer to configuration structure describing the pin + * @param callback A pointer to a function of type #callback_fn. + * @param cbdata The parameter to be passed to the callback function, #callback_fn, when an interrupt occurs. + * + */ +void GPIO_RegisterCallback(const gpio_cfg_t *cfg, gpio_callback_fn callback, void *cbdata); + +/** + * @brief GPIO IRQ Handler. @note If a callback is registered for a given + * interrupt, the callback function will be called. + * + * @param port number of the port that generated the interrupt service routine. + * + */ +void GPIO_Handler(unsigned int port); + +/**@} end of group gpio */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GPIO_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cm.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cm.c new file mode 100644 index 0000000..5c1471e --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cm.c @@ -0,0 +1,880 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-01 08:51:23 -0500 (Wed, 01 Jun 2016) $ + * $Revision: 23131 $ + * + ******************************************************************************/ + +/** + * @file i2cm.c + * @brief I2C Master driver source. + */ + +/***** Includes *****/ +#include +#include +#include "mxc_assert.h" +#include "mxc_lock.h" +#include "mxc_errors.h" +#include "mxc_sys.h" +#include "i2cm.h" + +/***** Definitions *****/ + +#ifndef MXC_I2CM_TX_TIMEOUT +#define MXC_I2CM_TX_TIMEOUT 0x5000 +#endif + +#ifndef MXC_I2CM_RX_TIMEOUT +#define MXC_I2CM_RX_TIMEOUT 0x5000 +#endif + +#define I2CM_READ_BIT 0x0001 +#define I2CM_FIFO_DEPTH_3Q ((3 * MXC_I2CM_FIFO_DEPTH) / 4) +#define I2CM_FIFO_DEPTH_2Q (MXC_I2CM_FIFO_DEPTH / 2) + +/***** Globals *****/ + +// Saves the state of the non-blocking requests +typedef enum { + I2CM_STATE_READING = 0, + I2CM_STATE_WRITING = 1 +} i2cm_state_t; + +typedef struct { + i2cm_req_t *req; + i2cm_state_t state; +} i2cm_req_state_t; +static i2cm_req_state_t states[MXC_CFG_I2CM_INSTANCES]; + +/***** Functions *****/ + +//static void I2CM_Recover(mxc_i2cm_regs_t *i2cm); +//static int I2CM_WriteTxFifo(mxc_i2cm_regs_t *regs, mxc_i2cm_fifo_regs_t *fifo, const uint16_t data); +//static int I2CM_TxInProgress(mxc_i2cm_regs_t *i2cm); +static void I2CM_FreeCallback(int i2cm_num, int error); +//static int I2CM_Tx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, +// const uint8_t *data, uint32_t len, uint8_t stop); + +//static int I2CM_Rx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, +// uint8_t *data, uint32_t len); + +static int I2CM_CmdHandler(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, i2cm_req_t *req); +static int I2CM_ReadHandler(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req, int i2cm_num); +static int I2CM_WriteHandler(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req, int i2cm_num); + +/******************************************************************************/ +int I2CM_Init(mxc_i2cm_regs_t *i2cm, const sys_cfg_i2cm_t *sys_cfg, i2cm_speed_t speed) +{ + int err; + + // Check the base pointer + MXC_ASSERT(MXC_I2CM_GET_IDX(i2cm) >= 0); + + // Set system level configurations + if ((err = SYS_I2CM_Init(i2cm, sys_cfg)) != E_NO_ERROR) { + return err; + } + + I2CM_SetFrequency(i2cm,speed); + + // Reset module + i2cm->ctrl = MXC_F_I2CM_CTRL_MSTR_RESET_EN; + i2cm->ctrl = 0; + + // Set timeout to 255 ms and turn on the auto-stop option + i2cm->timeout = (MXC_F_I2CM_TIMEOUT_TX_TIMEOUT | MXC_F_I2CM_TIMEOUT_AUTO_STOP_EN); + + // Enable tx_fifo and rx_fifo + i2cm->ctrl |= (MXC_F_I2CM_CTRL_TX_FIFO_EN | MXC_F_I2CM_CTRL_RX_FIFO_EN); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_Shutdown(mxc_i2cm_regs_t *i2cm) +{ + int i2cm_num, err; + + // Check the base pointer + i2cm_num = MXC_I2CM_GET_IDX(i2cm); + MXC_ASSERT(i2cm_num >= 0); + + // Disable and clear interrupts + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + + // Call all of the pending callbacks for this I2CM + if(states[i2cm_num].req != NULL) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, E_SHUTDOWN); + } + + // Clears system level configurations + if ((err = SYS_I2CM_Shutdown(i2cm)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + + +/******************************************************************************/ +int I2CM_Read(mxc_i2cm_regs_t *i2cm, uint8_t addr, const uint8_t *cmd_data, + uint32_t cmd_len, uint8_t* data, uint32_t len) +{ + int i2cm_num; + int error = E_NO_ERROR; + int retval = E_NO_ERROR; + mxc_i2cm_fifo_regs_t *fifo; + + if(data == NULL) { + return E_NULL_PTR; + } + + // Make sure the I2CM has been initialized + if(i2cm->ctrl == 0) { + return E_UNINITIALIZED; + } + + if(!(len > 0)) { + return E_NO_ERROR; + } + + // Lock this I2CM + i2cm_num = MXC_I2CM_GET_IDX(i2cm); + while(mxc_get_lock((uint32_t*)&states[i2cm_num].req,1) != E_NO_ERROR) {} + + // Get the FIFO pointer for this I2CM + fifo = MXC_I2CM_GET_FIFO(i2cm_num); + + // Disable and clear the interrupts + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + + // Transmit the command if there is command data and length + if((cmd_data != NULL) && (cmd_len > 0)) { + retval = I2CM_Tx(i2cm, fifo, addr, cmd_data, cmd_len, 0); + } + + // Read data from the slave if we don't have any errors + if(retval == E_NO_ERROR) { + retval = I2CM_Rx(i2cm, fifo, addr, data, len); + } + + // Wait for the transaction to complete + if((error = I2CM_TxInProgress(i2cm)) != E_NO_ERROR) { + retval = error; + } + + // Unlock this I2CM + mxc_free_lock((uint32_t*)&states[i2cm_num].req); + + if(retval != E_NO_ERROR) { + return retval; + } + + return len; +} + +/******************************************************************************/ +int I2CM_Write(mxc_i2cm_regs_t *i2cm, uint8_t addr, const uint8_t *cmd_data, + uint32_t cmd_len, uint8_t* data, uint32_t len) +{ + int i2cm_num; + int error = E_NO_ERROR; + int retval = E_NO_ERROR; + mxc_i2cm_fifo_regs_t *fifo; + + if(data == NULL) { + return E_NULL_PTR; + } + + // Make sure the I2CM has been initialized + if(i2cm->ctrl == 0) { + return E_UNINITIALIZED; + } + + if(!(len > 0)) { + return E_NO_ERROR; + } + + // Lock this I2CM + i2cm_num = MXC_I2CM_GET_IDX(i2cm); + while(mxc_get_lock((uint32_t*)&states[i2cm_num].req,1) != E_NO_ERROR) {} + + // Get the FIFO pointer for this I2CM + fifo = MXC_I2CM_GET_FIFO(i2cm_num); + + // Disable and clear the interrupts + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + + // Transmit the command if there is command data and length, don't send stop bit + if((cmd_data != NULL) && (cmd_len > 0)) { + retval = I2CM_Tx(i2cm, fifo, addr, cmd_data, cmd_len, 0); + } + + // Write data to the slave, send the stop bit + if(retval == E_NO_ERROR) { + retval = I2CM_Tx(i2cm, fifo, addr, data, len, 1); + } + + // Wait for the transaction to complete + if((error = I2CM_TxInProgress(i2cm)) != E_NO_ERROR) { + retval = error; + } + + // Unlock this I2CM + mxc_free_lock((uint32_t*)&states[i2cm_num].req); + + if(retval != E_NO_ERROR) { + return retval; + } + + return len; +} + +/******************************************************************************/ +int I2CM_ReadAsync(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req) +{ + int i2cm_num, error; + + if(req->data == NULL) { + return E_NULL_PTR; + } + + // Make sure the I2CM has been initialized + if(i2cm->ctrl == 0) { + return E_UNINITIALIZED; + } + + if(!(req->data_len > 0)) { + return E_NO_ERROR; + } + + i2cm_num = MXC_I2CM_GET_IDX(i2cm); + + // Attempt to register this request + if(mxc_get_lock((uint32_t*)&states[i2cm_num].req, (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + states[i2cm_num].state = I2CM_STATE_READING; + + // Clear the number of bytes counter + req->cmd_num = 0; + req->data_num = 0; + + // Disable and clear the interrupts + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + + // Start the read + if((error = I2CM_ReadHandler(i2cm, req, i2cm_num)) != E_NO_ERROR) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, error); + return error; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_WriteAsync(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req) +{ + int i2cm_num, error; + + if(req->data == NULL) { + return E_NULL_PTR; + } + + // Make sure the I2CM has been initialized + if(i2cm->ctrl == 0) { + return E_UNINITIALIZED; + } + + if(!(req->data_len > 0)) { + return E_NO_ERROR; + } + + i2cm_num = MXC_I2CM_GET_IDX(i2cm); + + // Attempt to register this request + if(mxc_get_lock((uint32_t*)&states[i2cm_num].req, (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + states[i2cm_num].state = I2CM_STATE_WRITING; + + // Clear the number of bytes counter + req->cmd_num = 0; + req->data_num = 0; + + // Disable and clear the interrupts + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + + // Start the Write + if((error = I2CM_WriteHandler(i2cm, req, i2cm_num)) != E_NO_ERROR) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, error); + return error; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_AbortAsync(i2cm_req_t *req) +{ + int i2cm_num; + mxc_i2cm_regs_t *i2cm; + + // Find the request, set to NULL + for(i2cm_num = 0; i2cm_num < MXC_CFG_I2CM_INSTANCES; i2cm_num++) { + if(req == states[i2cm_num].req) { + + i2cm = MXC_I2CM_GET_I2CM(i2cm_num); + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, E_ABORT); + + return E_NO_ERROR; + } + } + + return E_BAD_PARAM; +} + +/******************************************************************************/ +void I2CM_Handler(mxc_i2cm_regs_t *i2cm) +{ + uint32_t intfl; + int i2cm_num, error; + + // Save and clear the interrupts + intfl = i2cm->intfl; + i2cm->intfl = intfl; + + // Mask the disabled interrupts + intfl &= i2cm->inten; + + i2cm_num = MXC_I2CM_GET_IDX(i2cm); + + // Check for errors + if ((intfl & MXC_F_I2CM_INTFL_TX_NACKED) || (intfl & MXC_F_I2CM_INTFL_TX_LOST_ARBITR)) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, E_COMM_ERR); + return; + } + + if(intfl & MXC_F_I2CM_INTFL_TX_TIMEOUT) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, E_TIME_OUT); + return; + } + + // Read or write + if(states[i2cm_num].state == I2CM_STATE_READING) { + if((error = I2CM_ReadHandler(i2cm, states[i2cm_num].req, i2cm_num)) != E_NO_ERROR) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, error); + return; + } + + } else if(states[i2cm_num].state == I2CM_STATE_WRITING) { + if((error = I2CM_WriteHandler(i2cm, states[i2cm_num].req, i2cm_num)) != E_NO_ERROR) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, error); + return; + } + } + + // Done with the transaction + if(intfl & MXC_F_I2CM_INTFL_TX_DONE) { + I2CM_Recover(i2cm); + I2CM_FreeCallback(i2cm_num, E_NO_ERROR); + } + +} + +/******************************************************************************/ +int I2CM_Busy(mxc_i2cm_regs_t *i2cm) +{ + // Check to see if there are any ongoing transactions + if((states[MXC_I2CM_GET_IDX(i2cm)].req == NULL) && + !(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + + return E_NO_ERROR; + } + + return E_BUSY; +} + +/******************************************************************************/ +int I2CM_PrepForSleep(mxc_i2cm_regs_t *i2cm) +{ + if(I2CM_Busy(i2cm) != E_NO_ERROR) { + return E_BUSY; + } + + // Disable interrupts + i2cm->inten = 0; + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_BusCheck(mxc_i2cm_regs_t *i2cm) +{ + // If SCL is low, we don't have the bus + if(!(i2cm->bb & MXC_F_I2CM_BB_BB_SCL_IN_VAL)) { + return E_BUSY; + } + + // If SDA is low, we don't have the bus + if(!(i2cm->bb & MXC_F_I2CM_BB_BB_SDA_IN_VAL)) { + return E_BUSY; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +static void I2CM_FreeCallback(int i2cm_num, int error) +{ + // Save the request + i2cm_req_t *temp_req = states[i2cm_num].req; + + // Unlock this UART to write + mxc_free_lock((uint32_t*)&states[i2cm_num].req); + + // Callback if not NULL + if(temp_req->callback != NULL) { + temp_req->callback(temp_req, error); + } +} + +/******************************************************************************/ +void I2CM_Recover(mxc_i2cm_regs_t *i2cm) +{ + // Disable and clear interrupts + i2cm->inten = 0; + i2cm->intfl = i2cm->intfl; + i2cm->ctrl = MXC_F_I2CM_CTRL_MSTR_RESET_EN; + i2cm->ctrl = MXC_F_I2CM_CTRL_TX_FIFO_EN | MXC_F_I2CM_CTRL_RX_FIFO_EN; +} + +/******************************************************************************/ +int I2CM_WriteTxFifo(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, const uint16_t data) +{ + int32_t timeout = MXC_I2CM_TX_TIMEOUT; + + // Read the TX FIFO to determine if it's full + do { + + // Wait for the TX FIFO to have room and check for errors + if (i2cm->intfl & (MXC_F_I2CM_INTFL_TX_NACKED | + MXC_F_I2CM_INTFL_TX_LOST_ARBITR)) { + + return E_COMM_ERR; + } + + if((i2cm->intfl & MXC_F_I2CM_INTFL_TX_TIMEOUT) || !timeout--) { + return E_TIME_OUT; + } + + } while (fifo->tx); + + fifo->tx = data; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_TxInProgress(mxc_i2cm_regs_t *i2cm) +{ + int32_t timeout = MXC_I2CM_TX_TIMEOUT; + + while ((i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS) && --timeout); + + if (i2cm->intfl & (MXC_F_I2CM_INTFL_TX_NACKED | + MXC_F_I2CM_INTFL_TX_LOST_ARBITR)) { + + I2CM_Recover(i2cm); + return E_COMM_ERR; + } + + if((i2cm->intfl & MXC_F_I2CM_INTFL_TX_TIMEOUT) && !timeout--) { + I2CM_Recover(i2cm); + return E_TIME_OUT; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_Tx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, + const uint8_t *data, uint32_t len, uint8_t stop) +{ + uint32_t i; + int error; + + // Write the address to the TXFIFO + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_START | (addr << 1)))) != E_NO_ERROR) { + return error; + } + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + + // Fill the FIFO + for (i = 0; i < len; i++) { + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_TXDATA_ACK | data[i]))) != E_NO_ERROR) { + return error; + } + } + + // Send the stop condition + if(stop) { + if ((error = I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_STOP)) != E_NO_ERROR) { + return error; + } + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int I2CM_Rx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, + uint8_t *data, uint32_t len) +{ + uint32_t i = len; + int32_t timeout; + uint16_t temp; + int error; + + // Write the address to the TXFIFO + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_START | + (addr << 1) | I2CM_READ_BIT))) != E_NO_ERROR) { + + return error; + } + + // Write to the TXFIFO the number of bytes we want to read + while(i > 256) { + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT | 255))) != E_NO_ERROR) { + return error; + } + + i -= 256; + } + + if(i > 1) { + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT | (i-2)))) != E_NO_ERROR) { + return error; + } + } + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + + + // NACK the last read byte + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_RXDATA_NACK))) != E_NO_ERROR) { + return error; + } + + // Send the stop condition + if ((error = I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_STOP)) != E_NO_ERROR) { + return error; + } + + // Get the data from the RX FIFO + i = 0; + while (i < len) { + + // Wait for there to be data in the RX FIFO + timeout = MXC_I2CM_RX_TIMEOUT; + while (!(i2cm->intfl & MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY) && + ((i2cm->bb & MXC_F_I2CM_BB_RX_FIFO_CNT) == 0)) { + + if((timeout-- < 0) || (i2cm->trans & MXC_F_I2CM_TRANS_TX_TIMEOUT)) { + return E_TIME_OUT; + } + + if (i2cm->trans & (MXC_F_I2CM_TRANS_TX_LOST_ARBITR | MXC_F_I2CM_TRANS_TX_NACKED)) { + return E_COMM_ERR; + } + } + i2cm->intfl = MXC_F_I2CM_INTFL_RX_FIFO_NOT_EMPTY; + + // Save the data from the RX FIFO + temp = fifo->rx; + if (temp & MXC_S_I2CM_RSTLS_TAG_EMPTY) { + continue; + } + data[i++] = (uint8_t)temp; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +static int I2CM_CmdHandler(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, i2cm_req_t *req) +{ + int error; + + // Start of the command + if(req->cmd_num == 0) { + + // Write the address to the TXFIFO + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_START | (req->addr << 1)))) != E_NO_ERROR) { + return error; + } + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + } + + // Write to the FIFO until it is full or we run out of command bytes + while((req->cmd_num < req->cmd_len) && (!fifo->tx)) { + fifo->tx = MXC_S_I2CM_TRANS_TAG_TXDATA_ACK | req->cmd_data[req->cmd_num++]; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +static int I2CM_ReadHandler(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req, int i2cm_num) +{ + int error, cmd_remain, data_remain; + uint16_t data; + uint32_t temp_len, inten; + mxc_i2cm_fifo_regs_t *fifo; + + // Get the FIFO pointer for this I2CM + fifo = MXC_I2CM_GET_FIFO(i2cm_num); + + cmd_remain = req->cmd_len - req->cmd_num; + data_remain = req->data_len - req->data_num; + + // Process the command portion + if((cmd_remain) && (req->cmd_data != NULL)) { + if((error = I2CM_CmdHandler(i2cm, fifo, req)) != E_NO_ERROR) { + return error; + } + + cmd_remain = req->cmd_len - req->cmd_num; + } + + // Process the data portion + if((cmd_remain == 0) && (data_remain)) { + + // Save the data from the RXFIFO + data = fifo->rx; + while((req->data_num < req->data_len) && !(data & MXC_S_I2CM_RSTLS_TAG_EMPTY)) { + req->data[req->data_num++] = data; + data = fifo->rx; + } + + // Start of the data portion + if(req->data_num == 0) { + + temp_len = req->data_len; + + // Write the address to the TXFIFO + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_START | + (req->addr << 1) | I2CM_READ_BIT))) != E_NO_ERROR) { + + return error; + } + + // Write to the TXFIFO the number of bytes we want to read + while(temp_len > 256) { + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT | 255))) != E_NO_ERROR) { + return error; + } + + temp_len -= 256; + } + + if(temp_len > 1) { + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT | (temp_len-2)))) != E_NO_ERROR) { + return error; + } + } + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + + // NACK the last read byte + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_RXDATA_NACK))) != E_NO_ERROR) { + return error; + } + + // Send the stop condition + if ((error = I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_STOP)) != E_NO_ERROR) { + return error; + } + } + } + + // Enable the required interrupts + inten = MXC_F_I2CM_INTEN_TX_DONE | MXC_F_I2CM_INTEN_TX_NACKED | + MXC_F_I2CM_INTEN_TX_LOST_ARBITR | MXC_F_I2CM_INTEN_TX_TIMEOUT; + + if (cmd_remain) { + inten |= (MXC_F_I2CM_INTEN_TX_FIFO_EMPTY | MXC_F_I2CM_INTEN_TX_FIFO_3Q_EMPTY); + } + + data_remain = req->data_len - req->data_num; + if (data_remain > I2CM_FIFO_DEPTH_3Q) { + inten |= MXC_F_I2CM_INTEN_RX_FIFO_3Q_FULL; + + } else if (data_remain > I2CM_FIFO_DEPTH_2Q) { + inten |= MXC_F_I2CM_INTEN_RX_FIFO_2Q_FULL; + + } else if (data_remain > 0) { + inten |= MXC_F_I2CM_INTEN_RX_FIFO_NOT_EMPTY; + } + + i2cm->inten = inten; + + return E_NO_ERROR; +} + +/******************************************************************************/ +static int I2CM_WriteHandler(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req, int i2cm_num) +{ + int error, cmd_remain, data_remain; + uint32_t inten; + mxc_i2cm_fifo_regs_t *fifo; + + // Get the FIFO pointer for this I2CM + fifo = MXC_I2CM_GET_FIFO(i2cm_num); + + cmd_remain = req->cmd_len - req->cmd_num; + data_remain = req->data_len - req->data_num; + + // Process the command portion + if((cmd_remain) && (req->cmd_data != NULL)) { + if((error = I2CM_CmdHandler(i2cm, fifo, req)) != E_NO_ERROR) { + return error; + } + + cmd_remain = req->cmd_len - req->cmd_num; + } + + // Process the data portion + if((cmd_remain == 0) && (data_remain)) { + + // Start of the data portion + if(req->data_num == 0) { + + // Write the address to the TXFIFO + if((error = I2CM_WriteTxFifo(i2cm, fifo, (MXC_S_I2CM_TRANS_TAG_START | + (req->addr << 1)))) != E_NO_ERROR) { + + return error; + } + + // Start the transaction if it is not currently ongoing + if (!(i2cm->trans & MXC_F_I2CM_TRANS_TX_IN_PROGRESS)) { + i2cm->trans |= MXC_F_I2CM_TRANS_TX_START; + } + } + + // Write bytes to the FIFO until it's full or we run out of bytes + while(req->data_num < req->data_len) { + fifo->tx = MXC_S_I2CM_TRANS_TAG_TXDATA_ACK | req->data[req->data_num++]; + } + + // Send the stop condition + if ((error = I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_STOP)) != E_NO_ERROR) { + return error; + } + } + + // Enable the required interrupts + data_remain = req->data_len - req->data_num; + inten = MXC_F_I2CM_INTEN_TX_DONE | MXC_F_I2CM_INTEN_TX_NACKED | + MXC_F_I2CM_INTEN_TX_LOST_ARBITR | MXC_F_I2CM_INTEN_TX_TIMEOUT; + + if(data_remain || cmd_remain) { + inten |= (MXC_F_I2CM_INTEN_TX_FIFO_EMPTY | MXC_F_I2CM_INTEN_TX_FIFO_3Q_EMPTY); + } + i2cm->inten = inten; + + return E_NO_ERROR; +} + +int I2CM_SetFrequency(mxc_i2cm_regs_t *i2cm, int speed) +{ + // Speed converted into Khz + float i2cSpeed = speed / 1000.0f; + //get clk speed into MHz + int sClk = SYS_I2CM_GetFreq(i2cm) / 1000000; + // duty cycle of .67 + float dc = 2.0f / 3.0f; + //Hold Time + float hold = (100.0f / i2cSpeed); + int riseTime; + //max rise time based on speed according to the I2C specs + if (i2cSpeed <= 100) { + riseTime = 1000; + } else if (i2cSpeed <= 400) { + riseTime = 300; + } else if (i2cSpeed <= 1000) { + riseTime = 120; + } else { + return E_NOT_SUPPORTED; + } + // Clock cycles to delay + int latency = 4; + int filtDev, sclHi, sclLow; + filtDev = (hold * sClk) / 2; + sclHi = (((dc * sClk * 1000.0f / i2cSpeed) - (((2.5f * filtDev) + (riseTime / 1000.0f * sClk) + latency) * (1.0f + dc))) / (1.0f + dc)); + sclLow = ((sClk * 1000.0f / i2cSpeed) - (2.5f * filtDev) - (riseTime / 1000.0f * sClk) - latency - sclHi); + + i2cm->fs_clk_div = ((filtDev << MXC_F_I2CM_FS_CLK_DIV_FS_FILTER_CLK_DIV_POS) | + (sclHi << MXC_F_I2CM_FS_CLK_DIV_FS_SCL_HI_CNT_POS) | + (sclLow << MXC_F_I2CM_FS_CLK_DIV_FS_SCL_LO_CNT_POS)); + return E_NO_ERROR; +} \ No newline at end of file diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cm.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cm.h new file mode 100644 index 0000000..b938ad3 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cm.h @@ -0,0 +1,257 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-04-27 11:55:43 -0500 (Wed, 27 Apr 2016) $ + * $Revision: 22541 $ + * + ******************************************************************************/ + +/** + * @file i2cm.h + * @brief I2C Master driver header file. + */ + +#ifndef _I2CM_H_ +#define _I2CM_H_ + +/***** Includes *****/ +#include "mxc_config.h" +#include "mxc_sys.h" +#include "i2cm_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/// @brief I2CM frequencies. +typedef enum { + I2CM_SPEED_100KHZ = 100000, + I2CM_SPEED_400KHZ = 400000 +} i2cm_speed_t; + +/// @brief I2CM Transaction request. +typedef struct i2cm_req i2cm_req_t; +struct i2cm_req { + + /** + * @details Only supports 7-bit addressing. Driver will shift the address and + * add the read bit when necessary. + */ + uint8_t addr; + const uint8_t *cmd_data; ///< Optional command data to write before reading. + uint32_t cmd_len; ///< Number of bytes in command. + uint8_t *data; ///< Data to write or read. + uint32_t data_len; ///< Length of data. + uint32_t cmd_num; ///< Number of command bytes sent + uint32_t data_num; ///< Number of data bytes sent + + /** + * @brief Callback for asynchronous request. + * @param i2cm_req_t* Pointer to the transaction request. + * @param int Error code. + */ + void (*callback)(i2cm_req_t*, int); +}; + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Initialize I2CM module. + * @param i2cm Pointer to I2CM regs. + * @param cfg Pointer to I2CM configuration. + * @param speed I2CM frequency. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int I2CM_Init(mxc_i2cm_regs_t *i2cm, const sys_cfg_i2cm_t *sys_cfg, i2cm_speed_t speed); + +/** + * @brief Shutdown I2CM module. + * @param i2cm Pointer to I2CM regs. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int I2CM_Shutdown(mxc_i2cm_regs_t *i2cm); + +/** + * @brief Read I2CM data. Will block until transaction is complete. + * @param i2cm Pointer to I2CM regs. + * @param addr I2C address of the slave. + * @param cmd_data Data to write before reading. + * @param cmd_len Number of bytes to write before reading. + * @param data Where to store read data. + * @param len Number of bytes to read. + * @details Command is an optional feature where the master will write the cmd_data + * before reading from the slave. If command is undesired, leave the pointer + * NULL and cmd_len 0. If there is a command, the master will send a + repeated start before reading. Will block until transaction has completed. + * @returns Bytes transacted if everything is successful, error if unsuccessful. + */ +int I2CM_Read(mxc_i2cm_regs_t *i2cm, uint8_t addr, const uint8_t *cmd_data, + uint32_t cmd_len, uint8_t* data, uint32_t len); + +/** + * @brief Write I2CM data. Will block until transaction is complete. + * @param i2cm Pointer to I2CM regs. + * @param addr I2C address of the slave. + * @param cmd_data Data to write before writing data. + * @param cmd_len Number of bytes to write before writing data. + * @param data Data to be written. + * @param len Number of bytes to Write. + * @details Command is an optional feature where the master will write the cmd_data + * before writing to the slave. If command is undesired, leave the pointer + * NULL and cmd_len 0. If there is a command, the master will send a + repeated start before writing again. Will block until transaction has completed. + * @returns Bytes transacted if everything is successful, error if unsuccessful. + */ +int I2CM_Write(mxc_i2cm_regs_t *i2cm, uint8_t addr, const uint8_t *cmd_data, + uint32_t cmd_len, uint8_t* data, uint32_t len); + +/** + * @brief Asynchronously read I2CM data. + * @param i2cm Pointer to I2CM regs. + * @param req Request for an I2CM transaction. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int I2CM_ReadAsync(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req); + +/** + * @brief Asynchronously write I2CM data. + * @param i2cm Pointer to I2CM regs. + * @param req Request for an I2CM transaction. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int I2CM_WriteAsync(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req); + +/** + * @brief Abort asynchronous request. + * @param req Pointer to request for a I2CM transaction. + * @note Will call the callback for the request. + * @returns #E_NO_ERROR if request aborted, error if unsuccessful. + */ +int I2CM_AbortAsync(i2cm_req_t *req); + +/** + * @brief I2CM interrupt handler. + * @details This function should be called by the application from the interrupt + * handler if I2CM interrupts are enabled. Alternately, this function + * can be periodically called by the application if I2CM interrupts are + * disabled. + * @param i2cm Base address of the I2CM module. + */ +void I2CM_Handler(mxc_i2cm_regs_t *i2cm); + +/** + * @brief Checks to see if the I2CM is busy. + * @param i2cm Pointer to I2CM regs. + * @returns #E_NO_ERROR if idle, #E_BUSY if in use. + */ +int I2CM_Busy(mxc_i2cm_regs_t *i2cm); + +/** + * @brief Attempt to prepare the I2CM for sleep. + * @param i2cm Pointer to I2CM regs. + * @details Checks for any ongoing transactions. Disables interrupts if the I2CM + is idle. + * @returns #E_NO_ERROR if ready to sleep, #E_BUSY if not ready for sleep. + */ +int I2CM_PrepForSleep(mxc_i2cm_regs_t *i2cm); + +/** + * @brief Check the I2C bus. + * @param i2cm Pointer to I2CM regs. + * @details Checks the I2CM bus to determine if there is any other master using + * the bus. + * @returns #E_NO_ERROR if SCL and SDA are high, #E_BUSY otherwise. + */ +int I2CM_BusCheck(mxc_i2cm_regs_t *i2cm); + +/** + * @brief Drain all of the data in the RXFIFO. + * @param i2cm Pointer to UART regs. + */ +__STATIC_INLINE void I2CM_DrainRX(mxc_i2cm_regs_t *i2cm) +{ + i2cm->ctrl &= ~(MXC_F_I2CM_CTRL_RX_FIFO_EN); + i2cm->ctrl |= MXC_F_I2CM_CTRL_RX_FIFO_EN; +} + +/** + * @brief Drain all of the data in the TXFIFO. + * @param i2cm Pointer to UART regs. + */ +__STATIC_INLINE void I2CM_DrainTX(mxc_i2cm_regs_t *i2cm) +{ + i2cm->ctrl &= ~(MXC_F_I2CM_CTRL_TX_FIFO_EN); + i2cm->ctrl |= MXC_F_I2CM_CTRL_TX_FIFO_EN; +} + +/** + * @brief Clear interrupt flags. + * @param i2cm Pointer to I2CM regs. + * @param mask Mask of interrupts to clear. + */ +__STATIC_INLINE void I2CM_ClearFlags(mxc_i2cm_regs_t *i2cm, uint32_t mask) +{ + i2cm->intfl = mask; +} + +/** + * @brief Get interrupt flags. + * @param i2cm Pointer to I2CM regs. + * @returns Mask of active flags. + */ +__STATIC_INLINE unsigned I2CM_GetFlags(mxc_i2cm_regs_t *i2cm) +{ + return(i2cm->intfl); +} +/** + * @brief Set the I2C Frequency + * @param i2cm Pointer to I2CM regs. + * @param speed speed in Hz + * @details sets the registers for the proper frequency + * @returns #E_NO_ERROR if Frequency is supported, #E_NOT_Supported otherwise. + */ +int I2CM_SetFrequency(mxc_i2cm_regs_t *i2cm, int speed); + +void I2CM_Recover(mxc_i2cm_regs_t *i2cm); +int I2CM_WriteTxFifo(mxc_i2cm_regs_t *regs, mxc_i2cm_fifo_regs_t *fifo, const uint16_t data); +int I2CM_TxInProgress(mxc_i2cm_regs_t *i2cm); +int I2CM_Tx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, const uint8_t *data, uint32_t len, uint8_t stop); +int I2CM_Rx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, uint8_t *data, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* _I2CM_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.c new file mode 100644 index 0000000..06ee8bf --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.c @@ -0,0 +1,209 @@ +/** + * @file i2cs.c + * @brief This file contains the function implementations for the I2CS + * (Inter-Integrated Circuit Slave) peripheral module. + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 20:05:48 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24086 $ + * + *************************************************************************** */ + +/* **** Includes **** */ +#include +#include "mxc_assert.h" +#include "mxc_errors.h" +#include "mxc_sys.h" +#include "i2cs.h" + +/** + * @ingroup i2cs + * @{ + */ +/* **** Definitions **** */ + +/* **** Globals ***** */ + + +// No Doxygen documentation for the items between here and endcond. +/* Clock divider lookup table */ +static const uint32_t clk_div_table[2][8] = { + /* I2CS_SPEED_100KHZ */ + { + // 12000000 + (6 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS), + // 24000000 + (12 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS), + // 36000000 NOT SUPPORTED + 0, + // 48000000 + (24 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS), + // 60000000 NOT SUPPORTED + 0, + // 72000000 NOT SUPPORTED + 0, + // 84000000 NOT SUPPORTED + 0, + // 96000000 + (48 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS) + }, + /* I2CS_SPEED_400KHZ */ + { + // 12000000 + (2 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS), + // 24000000 + (3 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS), + // 36000000 NOT SUPPORTED + 0, + // 48000000 + (6 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS), + // 60000000 NOT SUPPORTED + 0, + // 72000000 NOT SUPPORTED + 0, + // 84000000 NOT SUPPORTED + 0, + // 96000000 + (12 << MXC_F_I2CS_CLK_DIV_FS_FILTER_CLOCK_DIV_POS) + }, +}; + + +static void (*callbacks[MXC_CFG_I2CS_INSTANCES][MXC_CFG_I2CS_BUFFER_SIZE])(uint8_t); + +/* **** Functions **** */ + +/* ************************************************************************* */ +int I2CS_Init(mxc_i2cs_regs_t *i2cs, const sys_cfg_i2cs_t *sys_cfg, i2cs_speed_t speed, + uint16_t address, i2cs_addr_t addr_len) +{ + int err, i, i2cs_index; + + i2cs_index = MXC_I2CS_GET_IDX(i2cs); + MXC_ASSERT(i2cs_index >= 0); + + // Set system level configurations + if ((err = SYS_I2CS_Init(i2cs, sys_cfg)) != E_NO_ERROR) { + return err; + } + + // Compute clock array index + int clki = ((SYS_I2CS_GetFreq(i2cs) / 12000000) - 1); + + // Get clock divider settings from lookup table + if ((speed == I2CS_SPEED_100KHZ) && (clk_div_table[I2CS_SPEED_100KHZ][clki] > 0)) { + i2cs->clk_div = clk_div_table[I2CS_SPEED_100KHZ][clki]; + } else if ((speed == I2CS_SPEED_400KHZ) && (clk_div_table[I2CS_SPEED_400KHZ][clki] > 0)) { + i2cs->clk_div = clk_div_table[I2CS_SPEED_400KHZ][clki]; + } else { + MXC_ASSERT_FAIL(); + } + + // Clear the interrupt callbacks + for(i = 0; i < MXC_CFG_I2CS_BUFFER_SIZE; i++) { + callbacks[i2cs_index][i] = NULL; + } + + // Reset module + i2cs->dev_id = MXC_F_I2CS_DEV_ID_SLAVE_RESET; + i2cs->dev_id = ((((address >> 0) << MXC_F_I2CS_DEV_ID_SLAVE_DEV_ID_POS) + & MXC_F_I2CS_DEV_ID_SLAVE_DEV_ID) | addr_len); + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int I2CS_Shutdown(mxc_i2cs_regs_t *i2cs) +{ + int err; + + // Disable and clear interrupts + i2cs->inten = 0; + i2cs->intfl = i2cs->intfl; + + // clears system level configurations + if ((err = SYS_I2CS_Shutdown(i2cs)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +void I2CS_Handler(mxc_i2cs_regs_t *i2cs) +{ + uint32_t intfl; + uint8_t i; + int i2cs_index = MXC_I2CS_GET_IDX(i2cs); + + // Save and clear the interrupt flags + intfl = i2cs->intfl; + i2cs->intfl = intfl; + + // Process each interrupt + for(i = 0; i < 32; i++) { + if(intfl & (0x1 << i)) { + if(callbacks[i2cs_index][i] != NULL) { + callbacks[i2cs_index][i](i); + } + } + } + +} + +/* ************************************************************************* */ +void I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback) +{ + int i2cs_index = MXC_I2CS_GET_IDX(i2cs); + + // Make sure we don't overflow + MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); + + if(callback != NULL) { + // Save the callback address + callbacks[i2cs_index][addr] = callback; + + // Clear and Enable the interrupt for the given byte + i2cs->intfl = (0x1 << addr); + i2cs->inten |= (0x1 << addr); + } else { + // Disable and clear the interrupt + i2cs->inten &= ~(0x1 << addr); + i2cs->intfl = (0x1 << addr); + + // Clear the callback address + callbacks[i2cs_index][addr] = NULL; + } +} + +/**@} end of group i2cs*/ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.h new file mode 100644 index 0000000..5cc6bc3 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.h @@ -0,0 +1,215 @@ +/** + * @file i2cs.h + * @brief I2CS (Inter-Integrated Circuit Slave) function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 20:05:48 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24086 $ + * + *************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _I2CS_H_ +#define _I2CS_H_ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "mxc_sys.h" +#include "mxc_assert.h" +#include "i2cs_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup i2cs I2C Slave + * @ingroup i2c_master_slave + * @brief I2C Slave (I2CS) API + * @{ + */ + +/* **** Definitions **** */ +/** + * Internal buffer size for storing I2C Slave Messages + */ +#define I2CS_BUFFER_SIZE 32 + +/** + * Enumeration type to select supported I2CS frequencies. + */ +typedef enum { + I2CS_SPEED_100KHZ = 0, /**< Use to select a bus communication speed of 100 kHz. */ + I2CS_SPEED_400KHZ = 1 /**< Use to select a bus communication speed of 400 kHz. */ +} i2cs_speed_t; + +/** + * Enumeration type to select the I2CS addressing mode. + */ +typedef enum { + I2CS_ADDR_8 = 0, /**< Sets the slave address mode to 8-bits (7-bits address plus read/write bit). */ + I2CS_ADDR_10 = MXC_F_I2CS_DEV_ID_TEN_BIT_ID_MODE /**< Sets the slave address mode to 10-bits. */ +} i2cs_addr_t; + +/** + * Type alias for an I2CS callback function that will be called when a given byte is updated by the Master, see I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback). + * @details The function prototype for implementing callback_fn is: + * @code + * void func(uint8_t addr); + * @endcode + */ +typedef void (*i2cs_callback_fn)(uint8_t error_code); +/* **** Globals **** */ + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize I2CS module. + * @param i2cs Pointer to I2CS regs. + * @param sys_cfg Pointer to I2CS system configuration, see + * #sys_cfg_i2cs_t. + * @param speed I2CS frequency. + * @param address I2CS address. + * @param addr_len I2CS address length. + * @return #E_NO_ERROR if everything is successful or an + * @ref MXC_Error_Codes "error code" if unsuccessful. + * + */ +int I2CS_Init(mxc_i2cs_regs_t *i2cs, const sys_cfg_i2cs_t *sys_cfg, i2cs_speed_t speed, uint16_t address, i2cs_addr_t addr_len); + +/** + * @brief Shutdown I2CS module. + * @param i2cs Pointer to I2CS regs. + * @return #E_NO_ERROR if everything is successful or an + * @ref MXC_Error_Codes "error code" if unsuccessful. + */ +int I2CS_Shutdown(mxc_i2cs_regs_t *i2cs); + +/** + * @brief I2CS interrupt handler. + * @details This function should be called by the application from the + * interrupt handler if I2CS interrupts are enabled. Alternately, + * this function can be periodically called by the application if + * I2CS interrupts are disabled. + * + * @param i2cs Pointer to I2CS regs. + */ +void I2CS_Handler(mxc_i2cs_regs_t *i2cs); + +/** + * @brief Register a callback that is triggered by an update of a specified + * byte. + * @details Registering a callback causes the slave to interrupt when the + * master has updated a specified byte. + * + * @param i2cs Pointer to the I2CS register structure, see + * #mxc_i2cs_regs_t. + * @param addr Index to trigger a call to the #i2cs_callback_fn. + * @param callback callback function of type #i2cs_callback_fn to be called + * when the addr being written by the master matches \c addr. + */ +void I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback); + +/** + * @brief Write I2CS data to a given byte. + * @details The slave has a buffer of registers that the external master can + * read. Use this function to write data into a specified + * address/index. + * + * @param i2cs Pointer to I2CS regs. + * @param addr Address/Index to write. + * @param data Data to be written. + */ +__STATIC_INLINE void I2CS_Write(mxc_i2cs_regs_t *i2cs, uint8_t addr, uint8_t data) +{ + // Make sure we don't overflow + MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); + i2cs->data_byte[addr] = ((i2cs->data_byte[addr] & ~MXC_F_I2CS_DATA_BYTE_DATA_FIELD) | + (data << MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS)); +} + +/** + * @brief Read I2CS data from a given address . + * @details The slave has a buffer of registers that the external master can + * read. Use this function to read the data from the registers. + * + * @param i2cs Pointer to I2CS regs. + * @param addr Address/Index to read from. + * + * @return Data contained in requested @c addr register. + */ +__STATIC_INLINE uint8_t I2CS_Read(mxc_i2cs_regs_t *i2cs, uint8_t addr) +{ + // Make sure we don't overflow + MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); + return ((i2cs->data_byte[addr] & MXC_F_I2CS_DATA_BYTE_DATA_FIELD) >> + MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS); +} + +/** + * @brief Set the given index to read only (RO). + * @details This index will be flagged as read only. The slave will NACK the + * master if it attempts to write this location. Multiple calls with + * different index/address values will yield multiple read-only + * locations within the slave register set. + * + * @param i2cs Pointer to I2CS regs. + * @param addr Address/Index of the byte to set to RO. + */ +__STATIC_INLINE void I2CS_SetRO(mxc_i2cs_regs_t *i2cs, uint8_t addr) +{ + // Make sure we don't overflow + MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); + i2cs->data_byte[addr] |= MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL; +} + +/** + * @brief Sets the given address to R/W. + * @param i2cs Pointer to I2CS regs. + * @param addr Index to start clearing RO flag. + */ +__STATIC_INLINE void I2CS_ClearRO(mxc_i2cs_regs_t *i2cs, uint8_t addr) +{ + // Make sure we don't overflow + MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); + i2cs->data_byte[addr] &= ~MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL; +} + +/**@} end of group i2cs */ + +#ifdef __cplusplus +} +#endif + +#endif /* _I2CS_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/icc.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/icc.c new file mode 100644 index 0000000..1e048ba --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/icc.c @@ -0,0 +1,77 @@ +/** + * @file icc.c + * @brief This file contains the function implementations for the + * Instruction Cache Controller. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 11:26:49 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24063 $ + * + *************************************************************************** */ + + +/* **** Includes **** */ +#include "mxc_config.h" +#include "icc.h" +/** + * @ingroup icc + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ + +/* **** Functions **** */ + +/* ************************************************************************* */ +void ICC_Enable(void) +{ + /* Invalidate cache and wait until ready */ + MXC_ICC->invdt_all = 1; + while (!(MXC_ICC->ctrl_stat & MXC_F_ICC_CTRL_STAT_READY)); + + /* Enable cache */ + MXC_ICC->ctrl_stat |= MXC_F_ICC_CTRL_STAT_ENABLE; + + /* Must invalidate a second time for proper use */ + MXC_ICC->invdt_all = 1; +} + +/* ************************************************************************* */ +void ICC_Disable(void) +{ + MXC_ICC->ctrl_stat &= ~MXC_F_ICC_CTRL_STAT_ENABLE; +} +/**@} end of group icc */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/icc.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/icc.h new file mode 100644 index 0000000..7510eb2 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/icc.h @@ -0,0 +1,83 @@ +/** + * @file icc.h + * @brief Instruction Cache Controller function prototypes and data types. + */ + +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 11:26:49 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24063 $ + * + *************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _ICC_H_ +#define _ICC_H_ + +/* **** Includes **** */ +#include "icc_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Doxy group definition for this peripheral module */ + +/** + * @defgroup icc Instruction Cache Controller (ICC) + * @ingroup sysconfig + * @{ + */ +/** + * @brief Enable and flush the instruction cache controller. + */ +void ICC_Enable(void); + +/** + * @brief Disable the instruction cache controller. + */ +void ICC_Disable(void); + +/** + * @brief Flush the instruction cache controller. + */ +__STATIC_INLINE void ICC_Flush() +{ + ICC_Disable(); + ICC_Enable(); +} +/**@} end of group icc */ +#ifdef __cplusplus +} +#endif + +#endif /* _ICC_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/ioman.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/ioman.c new file mode 100644 index 0000000..16c4b32 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/ioman.c @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-04-27 09:05:41 -0500 (Wed, 27 Apr 2016) $ + * $Revision: 22529 $ + * + ******************************************************************************/ + +#include +#include "mxc_config.h" +#include "ioman.h" + +/******************************************************************************/ +int IOMAN_Config(const ioman_cfg_t *cfg) +{ + + if(cfg == NULL) { + return E_NULL_PTR; + } + + if ((cfg->req_reg == &MXC_IOMAN->i2cm0_req) || (cfg->req_reg == &MXC_IOMAN->i2cm1_req)) { + /* Request pin mapping */ + *cfg->req_reg = cfg->req_val.value; + + /* Check for acknowledgment */ + /* Mask the I2CM SCL push/pull bit because it does not have an ack bit*/ + if (*cfg->ack_reg != (cfg->req_val.value & ~(MXC_F_IOMAN_I2CM0_REQ_SCL_PUSH_PULL))) { + return E_BUSY; + } + } else { + if (*cfg->ack_reg != cfg->req_val.value) { + /* Request pin mapping */ + *cfg->req_reg = cfg->req_val.value; + + /* Check for acknowledgment */ + if (*cfg->ack_reg != cfg->req_val.value) { + return E_BUSY; + } + } + } + + return E_NO_ERROR; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/ioman.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/ioman.h new file mode 100644 index 0000000..e005786 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/ioman.h @@ -0,0 +1,288 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-14 15:52:19 -0500 (Tue, 14 Jun 2016) $ + * $Revision: 23326 $ + * + ******************************************************************************/ + +/** + * @file ioman.h + * @brief IOMAN provides IO Management to the device. The functions in this + * API enable requesting port pin assignment and release for all peripherals + * with external I/O. Port pin mapping support is included for peripherals + * that can support more than one pin mapping in a package. + */ + +#ifndef _IOMAN_H_ +#define _IOMAN_H_ + +#include "mxc_config.h" +#include "ioman_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/** @brief Aliases for IOMAN package mapping field values. Refer to the + * User's Guide for pinouts for each mapping. + */ +typedef enum { + IOMAN_MAP_UNUSED = 0, /**< Pin is not used */ + IOMAN_MAP_A = 0, /**< Pin Mapping A */ + IOMAN_MAP_B = 1, /**< Pin Mapping B */ +} +ioman_map_t; + +/** @brief Typing of IOMAN Req and Ack register fields */ +typedef union { + uint32_t value; + mxc_ioman_spix_req_t spix; /**< SPIX IOMAN configuration struct */ + mxc_ioman_uart0_req_t uart; /**< UART IOMAN configuration struct, see mxc_ioman_uart0_req_t */ + mxc_ioman_i2cm0_req_t i2cm; /**< I2C Master 0 IOMAN configuration struct, see mxc_ioman_i2cm0_req_t */ + mxc_ioman_i2cs_req_t i2cs; /**< I2C Slave IOMAN configuration struct, see mxc_ioman_i2cs_req_t */ + mxc_ioman_spim0_req_t spim0; /**< SPI Master 0 IOMAN configuration struct, see mxc_ioman_spim0_req_t */ + mxc_ioman_spim1_req_t spim1; /**< SPI Master 1 IOMAN configuration struct, see mxc_ioman_spim1_req_t */ + mxc_ioman_spim2_req_t spim2; /**< SPI Master 2 IOMAN configuration struct, see mxc_ioman_spim1_req_t */ + mxc_ioman_spis_req_t spis; /**< SPI Slave IOMAN configuration struct, see mxc_ioman_spis_req_t */ + mxc_ioman_owm_req_t owm; /**< 1-Wire Master IOMAN configuration struct, see mxc_ioman_owm_req_t */ +} ioman_req_t; + +/** @brief IOMAN configuration object */ +typedef struct { + volatile uint32_t *req_reg; /** Pointer to an IOMAN request register */ + volatile uint32_t *ack_reg; /** Pointer to an IOMAN acknowledge register */ + ioman_req_t req_val; /** IOMAN request register value, see ioman_req_t */ +} ioman_cfg_t; + + +/***** Function Prototypes *****/ + +/** + * @brief Configure the IO Manager using the specified configuration object. + * @param cfg IOMAN configuration object + * @returns E_NO_ERROR Configuration successful + */ +int IOMAN_Config(const ioman_cfg_t *cfg); + +/** + * @brief Create an IOMAN configuration object for the SPI XIP module. Call IOMAN_Config with this object. + * @param core Request (1) or release (0) SPIX core external pins + * @param ss0 Request (1) or release (0) slave select 0 active out + * @param ss1 Request (1) or release (0) slave select 1 active out + * @param ss2 Request (1) or release (0) slave select 2 active out + * @param quad Request (1) or release (0) quad IO + * @param fast Request (1) or release (0) fast mode + * @returns io_man_cfg_t IOMAN configuration object for the SPI XIP module. + */ +ioman_cfg_t IOMAN_SPIX(int core, int ss0, int ss1, int ss2, int quad, int fast); + +/** + * @brief Create an IOMAN configuration object for a UART module. Call IOMAN_Config with this object. + * @param idx Index of the UART module + * @param io_map Set the pin mapping for RX/TX pins, see ioman_map_t + * @param cts_map Set the pin mapping for CTS pin, see ioman_map_t + * @param rts_map Set the pin mapping for RTS pin, see ioman_map_t + * @param io_en Request (1) or release (0) RX and TX pins + * @param cts_en Request (1) or release (0) CTS pin + * @param rts_en Request (1) or release (0) RTS pin + * @returns ioman_cfg_t IOMAN configuration object for the UART module + */ +ioman_cfg_t IOMAN_UART(int idx, ioman_map_t io_map, ioman_map_t cts_map, ioman_map_t rts_map, int io_en, int cts_en, int rts_en); + +/** + * @brief Create an IOMAN configuration object for the I2CM module. Call IOMAN_Config with this object. + * @param idx Index of the I2CM module + * @param io_en Request (1) or release (0) the I/O for the I2CM0 module + * @param scl_mode Set SCL in Push/Pull mode (1) or open-drain (0). + * @returns ioman_cfg_t IOMAN configuration object for the I2CM0 module. + */ +ioman_cfg_t IOMAN_I2CM(int idx, int io_en, int scl_mode); + +/** + * @brief Create an IOMAN configuration object for an I2C slave module. Call IOMAN_Config with this object. + * @param map Select the pin mapping for all configured pins, see ioman_map_t + * @param io_en Request (1) or release (0) the I/O for this module + * @returns ioman_cfg_t IOMAN configuration object for the I2CS module + */ +ioman_cfg_t IOMAN_I2CS(ioman_map_t map, int io_en); + +/** + * @brief Create an IOMAN configuration object for a SPI Master (SPIM) module. Call IOMAN_Config with this object. + * @param io_en Request (1) or release (0) the core IO for the module + * @param ss0 Request (1) or release (0) slave select 0 + * @param ss1 Request (1) or release (0) slave select 1 + * @param ss2 Request (1) or release (0) slave select 2 + * @param ss3 Request (1) or release (0) slave select 3 + * @param ss4 Request (1) or release (0) slave select 4 + * @param quad Request (1) or release (0) quad IO + * @param fast Request (1) or release (0) fast mode + * @returns ioman_cfg_t IOMAN configuration object for an SPIM0 module + */ +ioman_cfg_t IOMAN_SPIM0(int io_en, int ss0, int ss1, int ss2, int ss3, int ss4, int quad, int fast); + +/** + * @brief Create an IOMAN configuration object for a SPIM module. Call IOMAN_Config with this object. + * @param io_en Request (1) or release (0) the core IO for the module + * @param ss0 Request (1) or release (0) slave select 0 + * @param ss1 Request (1) or release (0) slave select 1 + * @param ss2 Request (1) or release (0) slave select 2 + * @param quad Request (1) or release (0) quad IO + * @param fast Request (1) or release (0) fast mode + * @returns ioman_cfg_t IOMAN configuration object for the SPIM1 module. + */ +ioman_cfg_t IOMAN_SPIM1(int io_en, int ss0, int ss1, int ss2, int quad, int fast); + +/** + * @brief Create an IOMAN configuration object for a SPI module. Call IOMAN_Config with this object. + * @param io_en Request (1) or release (0) the core IO for the module + * @param ss0 Request (1) or release (0) slave select 0 + * @param ss1 Request (1) or release (0) slave select 1 + * @param ss2 Request (1) or release (0) slave select 2 + * @param sr0 Request (1) or release (0) slave ready 0 + * @param sr1 Request (1) or release (0) slave ready 1 + * @param fast Request (1) or release (0) fast mode + * @returns ioman_cfg_t IOMAN configuration object for the SPIM2 module + */ +ioman_cfg_t IOMAN_SPIM2(int io_en, int ss0, int ss1, int ss2, int sr0, int sr1, int quad, int fast); + +/** + * @brief Create an IOMAN configuration object for a SPI module. Call IOMAN_Config with this object. + * @param io_en Request (1) or release (0) the core IO for the module + * @param quad Request (1) or release (0) quad IO + * @param fast Request (1) or release (0) fast mode + * @returns ioman_cfg_t IOMAN configuration object for the SPIM2 module + */ +ioman_cfg_t IOMAN_SPIS(int io_en, int quad, int fast); + +/** + * @brief Create an IOMAN configuration object for the 1-Wire Master module. Call IOMAN_Config with this object. + * @param io_en Request (1) or release (0) the core IO for the module + * @param epu Request (1) or release (0) external pullup + * @returns ioman_cfg_t IOMAN configuration object for the OWM module + */ +ioman_cfg_t IOMAN_OWM(int io_en, int epu); + +/** + * @} + */ + +/******************************************************************************/ +/* All the function prototypes above are implemented as macros below. The + * above prototypes are for simplicity in doxygen. + */ +#define IOMAN_SPIX(c, ss0, ss1, ss2, q, f) { \ + .req_reg = &MXC_IOMAN->spix_req, \ + .ack_reg = &MXC_IOMAN->spix_ack, \ + .req_val.spix = { .core_io_req = c, \ + .ss0_io_req = ss0, \ + .ss1_io_req = ss1, \ + .ss2_io_req = ss2, \ + .quad_io_req = q, \ + .fast_mode = f } } + +#define IOMAN_UART(i, im, cm, rm, ien, cen, ren) { \ + .req_reg = (uint32_t*)((unsigned int)(&MXC_IOMAN->uart0_req) + (i * 2*sizeof(uint32_t))), \ + .ack_reg = (uint32_t*)((unsigned int)(&MXC_IOMAN->uart0_ack) + (i * 2*sizeof(uint32_t))), \ + .req_val.uart = { .io_map = im, \ + .cts_map = cm, \ + .rts_map = rm, \ + .io_req = ien, \ + .cts_io_req = cen, \ + .rts_io_req = ren } } + +#define IOMAN_I2CM(i, ien, scl_mode) { \ + .req_reg = (uint32_t*)((unsigned int)(&MXC_IOMAN->i2cm0_req) + (i * 2*sizeof(uint32_t))), \ + .ack_reg = (uint32_t*)((unsigned int)(&MXC_IOMAN->i2cm0_ack) + (i * 2*sizeof(uint32_t))), \ + .req_val.i2cm = { .mapping_req = ien, \ + .scl_push_pull = scl_mode } } + +#define IOMAN_I2CS(m, ien) { \ + .req_reg = &MXC_IOMAN->i2cs_req, \ + .ack_reg = &MXC_IOMAN->i2cs_ack, \ + .req_val.i2cs = { .io_sel = m, \ + .mapping_req = ien } } + +#define IOMAN_SPIM0(io, ss0, ss1, ss2, ss3, ss4, q, f) { \ + .req_reg = &MXC_IOMAN->spim0_req, \ + .ack_reg = &MXC_IOMAN->spim0_ack, \ + .req_val.spim0 = { .core_io_req = io, \ + .ss0_io_req = ss0, \ + .ss1_io_req = ss1, \ + .ss2_io_req = ss2, \ + .ss3_io_req = ss3, \ + .ss4_io_req = ss4, \ + .quad_io_req = q, \ + .fast_mode = f } } + +#define IOMAN_SPIM1(io, ss0, ss1, ss2, q, f) { \ + .req_reg = &MXC_IOMAN->spim1_req, \ + .ack_reg = &MXC_IOMAN->spim1_ack, \ + .req_val.spim1 = { .core_io_req = io, \ + .ss0_io_req = ss0, \ + .ss1_io_req = ss1, \ + .ss2_io_req = ss2, \ + .quad_io_req = q, \ + .fast_mode = f } } + +#define IOMAN_SPIM2(io, ss0, ss1, ss2, sr0, sr1, q, f) { \ + .req_reg = &MXC_IOMAN->spim2_req, \ + .ack_reg = &MXC_IOMAN->spim2_ack, \ + .req_val.spim2 = { .mapping_req = 0, \ + .core_io_req = io, \ + .ss0_io_req = ss0, \ + .ss1_io_req = ss1, \ + .ss2_io_req = ss2, \ + .sr0_io_req = sr0, \ + .sr1_io_req = sr1, \ + .quad_io_req = q, \ + .fast_mode = f } } + +#define IOMAN_SPIS(io, q, f) { \ + .req_reg = &MXC_IOMAN->spis_req, \ + .ack_reg = &MXC_IOMAN->spis_ack, \ + .req_val.spis = { .core_io_req = io, \ + .quad_io_req = q, \ + .fast_mode = f } } + +#define IOMAN_OWM(io, p) { \ + .req_reg = &MXC_IOMAN->owm_req, \ + .ack_reg = &MXC_IOMAN->owm_ack, \ + .req_val.owm = { .mapping_req = io, \ + .epu_io_req = p } } + +#ifdef __cplusplus +} +#endif + +#endif /* _IOMAN_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/lp.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/lp.c new file mode 100644 index 0000000..fd1a088 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/lp.c @@ -0,0 +1,413 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-05-06 14:27:28 -0500 (Fri, 06 May 2016) $ + * $Revision: 22742 $ + * ******************************************************************************/ + +/***** Includes *****/ +#include "mxc_config.h" +#include "mxc_assert.h" +#include "lp.h" +#include "ioman_regs.h" + +/***** Definitions *****/ + +#ifndef LP0_PRE_HOOK +#define LP0_PRE_HOOK +#endif +#ifndef LP1_PRE_HOOK +#define LP1_PRE_HOOK +#endif +#ifndef LP1_POST_HOOK +#define LP1_POST_HOOK +#endif + +/***** Globals *****/ + +/***** Functions *****/ + +/* Clear all wake-up configuration */ +void LP_ClearWakeUpConfig(void) +{ + /* Clear GPIO WUD event and configuration registers, globally */ + MXC_PWRSEQ->reg1 |= (MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH | + MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH); + MXC_PWRSEQ->reg1 &= ~(MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH | + MXC_F_PWRSEQ_REG1_PWR_CLR_IO_CFG_LATCH); + + /* Mask off all wake-up sources */ + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_MSK_FLAGS_PWR_IOWAKEUP | + MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_PLUG_WAKEUP | + MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_REMOVE_WAKEUP | + MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR0 | + MXC_F_PWRSEQ_MSK_FLAGS_RTC_CMPR1 | + MXC_F_PWRSEQ_MSK_FLAGS_RTC_PRESCALE_CMP | + MXC_F_PWRSEQ_MSK_FLAGS_RTC_ROLLOVER); +} + +/* Clear wake-up flags */ +unsigned int LP_ClearWakeUpFlags(void) +{ + unsigned int flags_tmp; + + /* Get flags */ + flags_tmp = MXC_PWRSEQ->flags; + + /* Clear GPIO WUD event registers, globally */ + MXC_PWRSEQ->reg1 |= (MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH); + MXC_PWRSEQ->reg1 &= ~(MXC_F_PWRSEQ_REG1_PWR_CLR_IO_EVENT_LATCH); + + /* Clear power sequencer event flags (write-1-to-clear) */ + MXC_PWRSEQ->flags = flags_tmp; + + return flags_tmp; +} + +/* Configure the selected pin for wake-up detect */ +int LP_ConfigGPIOWakeUpDetect(const gpio_cfg_t *gpio, unsigned int act_high, lp_pu_pd_select_t wk_pu_pd) +{ + int result = E_NO_ERROR; + unsigned int pin; + + /* Check that port and pin are within range */ + MXC_ASSERT(gpio->port < MXC_GPIO_NUM_PORTS); + MXC_ASSERT(gpio->mask > 0); + + /* Ports 0-3 are controlled by wud_req0, while 4-7 are controlled by wud_req1 */ + if (gpio->port < 4) { + MXC_IOMAN->wud_req0 |= (gpio->mask << (gpio->port << 3)); + if (MXC_IOMAN->wud_ack0 != MXC_IOMAN->wud_req0) { /* Order of volatile access does not matter here */ + result = E_BUSY; + } + } else if (gpio->port < 8) { + MXC_IOMAN->wud_req1 |= (gpio->mask << ((gpio->port - 4) << 3)); + if (MXC_IOMAN->wud_ack1 != MXC_IOMAN->wud_req1) { /* Order of volatile access does not matter here */ + result = E_BUSY; + } + } else { + return E_NOT_SUPPORTED; + } + + if (result == E_NO_ERROR) { + + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + + if (gpio->mask & (1 << pin)) { + + /* Enable modifications to WUD configuration */ + MXC_PWRMAN->wud_ctrl = MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE; + + /* Select pad in WUD control */ + /* Note: Pads are numbered from 0-48; {0-7} => {P0.0-P0.7}, {8-15} => {P1.0-P1.7}, etc. */ + MXC_PWRMAN->wud_ctrl |= (gpio->port * 8) + pin; + + /* Configure sense level on this pad */ + MXC_PWRMAN->wud_ctrl |= (MXC_E_PWRMAN_PAD_MODE_ACT_HI_LO << MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS); + + if (act_high) { + /* Select active high with PULSE0 (backwards from what you'd expect) */ + MXC_PWRMAN->wud_pulse0 = 1; + } else { + /* Select active low with PULSE1 (backwards from what you'd expect) */ + MXC_PWRMAN->wud_pulse1 = 1; + } + + /* Clear out the pad mode */ + MXC_PWRMAN->wud_ctrl &= ~(MXC_F_PWRMAN_WUD_CTRL_PAD_MODE); + + /* Select this pad to have the wake-up function enabled */ + MXC_PWRMAN->wud_ctrl |= (MXC_E_PWRMAN_PAD_MODE_CLEAR_SET << MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS); + + /* Activate with PULSE1 */ + MXC_PWRMAN->wud_pulse1 = 1; + + if (wk_pu_pd != LP_NO_PULL) { + /* Select weak pull-up/pull-down on this pad while in LP1 */ + MXC_PWRMAN->wud_ctrl |= (MXC_E_PWRMAN_PAD_MODE_WEAK_HI_LO << MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS); + + /* Again, logic is opposite of what you'd expect */ + if (wk_pu_pd == LP_WEAK_PULL_UP) { + MXC_PWRMAN->wud_pulse0 = 1; + } else { + MXC_PWRMAN->wud_pulse1 = 1; + } + } + + /* Disable configuration each time, required by hardware */ + MXC_PWRMAN->wud_ctrl = 0; + } + } + } + + /* Disable configuration */ + MXC_IOMAN->wud_req0 = 0; + MXC_IOMAN->wud_req1 = 0; + + /* Enable IOWakeup, as there is at least 1 GPIO pin configured as a wake source */ + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_MSK_FLAGS_PWR_IOWAKEUP; + + return result; +} + +uint8_t LP_IsGPIOWakeUpSource(const gpio_cfg_t *gpio) +{ + uint8_t gpioWokeUp = 0; + + /* Check that port and pin are within range */ + MXC_ASSERT(gpio->port < MXC_GPIO_NUM_PORTS); + MXC_ASSERT(gpio->mask > 0); + + /* Ports 0-3 are wud_seen0, while 4-7 are wud_seen1*/ + if (gpio->port < 4) { + gpioWokeUp = (MXC_PWRMAN->wud_seen0 >> (gpio->port << 3)) & gpio->mask; + } else if (gpio->port < 8) { + gpioWokeUp = (MXC_PWRMAN->wud_seen1 >> ((gpio->port - 4) << 3)) & gpio->mask; + } else { + return E_NOT_SUPPORTED; + } + + return gpioWokeUp; +} + +int LP_ClearGPIOWakeUpDetect(const gpio_cfg_t *gpio) +{ + int result = E_NO_ERROR; + unsigned int pin; + + /* Check that port and pin are within range */ + MXC_ASSERT(gpio->port < MXC_GPIO_NUM_PORTS); + MXC_ASSERT(gpio->mask > 0); + + /* Ports 0-3 are controlled by wud_req0, while 4-7 are controlled by wud_req1*/ + if (gpio->port < 4) { + MXC_IOMAN->wud_req0 |= (gpio->mask << (gpio->port << 3)); + if (MXC_IOMAN->wud_ack0 != MXC_IOMAN->wud_req0) { /* Order of volatile access does not matter here */ + result = E_BUSY; + } + } else if (gpio->port < 8) { + MXC_IOMAN->wud_req1 |= (gpio->mask << ((gpio->port - 4) << 3)); + if (MXC_IOMAN->wud_ack1 != MXC_IOMAN->wud_req1) { /* Order of volatile access does not matter here */ + result = E_BUSY; + } + } else { + return E_NOT_SUPPORTED; + } + + if (result == E_NO_ERROR) { + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if (gpio->mask & (1 << pin)) { + + /* Enable modifications to WUD configuration */ + MXC_PWRMAN->wud_ctrl = MXC_F_PWRMAN_WUD_CTRL_CTRL_ENABLE; + + /* Select pad in WUD control */ + /* Note: Pads are numbered from 0-48; {0-7} => {P0.0-P0.7}, {8-15} => {P1.0-P1.7}, etc. */ + MXC_PWRMAN->wud_ctrl |= (gpio->port * 8) + pin; + + /* Clear out the pad mode */ + MXC_PWRMAN->wud_ctrl &= ~(MXC_F_PWRMAN_WUD_CTRL_PAD_MODE); + + /* Select the wake up function on this pad */ + MXC_PWRMAN->wud_ctrl |= (MXC_E_PWRMAN_PAD_MODE_CLEAR_SET << MXC_F_PWRMAN_WUD_CTRL_PAD_MODE_POS); + + /* disable wake up with PULSE0 */ + MXC_PWRMAN->wud_pulse0 = 1; + + /* Disable configuration each time, required by hardware */ + MXC_PWRMAN->wud_ctrl = 0; + } + } + } + + /* Disable configuration */ + MXC_IOMAN->wud_req0 = 0; + MXC_IOMAN->wud_req1 = 0; + + return result; +} + +int LP_ConfigUSBWakeUp(unsigned int plug_en, unsigned int unplug_en) +{ + /* Enable or disable wake on USB plug-in */ + if (plug_en) { + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_PLUG_WAKEUP; + } else { + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_PLUG_WAKEUP); + } + + /* Enable or disable wake on USB unplug */ + if (unplug_en) { + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_REMOVE_WAKEUP; + } else { + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_MSK_FLAGS_PWR_USB_REMOVE_WAKEUP); + } + + return E_NO_ERROR; +} + +int LP_ConfigRTCWakeUp(unsigned int comp0_en, unsigned int comp1_en, + unsigned int prescale_cmp_en, unsigned int rollover_en) +{ + /* Note: MXC_PWRSEQ.pwr_misc[0] should be set to have the mask be active low */ + + /* Enable or disable wake on RTC Compare 0 */ + if (comp0_en) { + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_FLAGS_RTC_CMPR0; + + } else { + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_FLAGS_RTC_CMPR0); + } + + /* Enable or disable wake on RTC Compare 1 */ + if (comp1_en) { + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_FLAGS_RTC_CMPR1; + + } else { + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_FLAGS_RTC_CMPR1); + } + + /* Enable or disable wake on RTC Prescaler */ + if (prescale_cmp_en) { + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_FLAGS_RTC_PRESCALE_CMP; + + } else { + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_FLAGS_RTC_PRESCALE_CMP); + } + + /* Enable or disable wake on RTC Rollover */ + if (rollover_en) { + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_FLAGS_RTC_ROLLOVER; + + } else { + MXC_PWRSEQ->msk_flags &= ~(MXC_F_PWRSEQ_FLAGS_RTC_ROLLOVER); + } + + return E_NO_ERROR; +} + + +int LP_EnterLP2(void) +{ + /* Clear SLEEPDEEP bit to avoid LP1/LP0 entry*/ + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + + /* Go into LP2 mode and wait for an interrupt to wake the processor */ + __WFI(); + + return E_NO_ERROR; +} + +int LP_EnterLP1(void) +{ + /* Turn on retention controller */ + MXC_PWRSEQ->retn_ctrl0 |= MXC_F_PWRSEQ_RETN_CTRL0_RETN_CTRL_EN; + + /* Clear the firstboot bit, which is generated by a POR event and locks out LPx modes */ + MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT); + + /* Set the LP1 select bit so CPU goes to LP1 during SLEEPDEEP */ + MXC_PWRSEQ->reg0 |= MXC_F_PWRSEQ_REG0_PWR_LP1; + + /* The SLEEPDEEP bit will cause a WFE() to trigger LP0/LP1 (depending on ..._REG0_PWR_LP1 state) */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + /* Performance-measurement hook, may be defined as nothing */ + LP1_PRE_HOOK; + + /* Dummy read to make sure SSB writes are complete */ + MXC_PWRSEQ->reg0; + + /* Enter LP1 -- sequence is per instructions from ARM, Ltd. */ + __SEV(); + __WFE(); + __WFE(); + + /* Performance-measurement hook, may be defined as nothing */ + LP1_POST_HOOK; + + /* Clear SLEEPDEEP bit */ + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + + /* No error */ + return E_NO_ERROR; +} + +void LP_EnterLP0(void) +{ + /* Turn off Auto GPIO Freeze/UnFreeze in sleep modes */ + MXC_PWRSEQ->reg1 &= ~MXC_F_PWRSEQ_REG1_PWR_AUTO_MBUS_GATE; + + /* Disable interrupts, ok not to save state as exit LP0 is a reset */ + __disable_irq(); + + /* Clear the firstboot bit, which is generated by a POR event and locks out LPx modes */ + MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT); + + /* Turn off retention controller */ + MXC_PWRSEQ->retn_ctrl0 &= ~(MXC_F_PWRSEQ_RETN_CTRL0_RETN_CTRL_EN); + + /* Turn off retention regulator */ + MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_RETREGEN_RUN | MXC_F_PWRSEQ_REG0_PWR_RETREGEN_SLP); + + /* LP0 ONLY to eliminate ~50nA of leakage on VDD12 */ + MXC_PWRSEQ->reg1 |= MXC_F_PWRSEQ_REG1_PWR_SRAM_NWELL_SW; + + /* Clear the LP1 select bit so CPU goes to LP0 during SLEEPDEEP */ + MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_LP1); + + /* The SLEEPDEEP bit will cause a WFE() to trigger LP0/LP1 (depending on ..._REG0_PWR_LP1 state) */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + /* Performance-measurement hook, may be defined as nothing */ + LP0_PRE_HOOK; + + /* Freeze GPIO using MBUS so that it doesn't change while digital core is alseep */ + MXC_PWRSEQ->reg1 |= MXC_F_PWRSEQ_REG1_PWR_MBUS_GATE; + + /* Dummy read to make sure SSB writes are complete */ + MXC_PWRSEQ->reg0; + + /* Go into LP0 -- sequence is per instructions from ARM, Ltd. */ + __SEV(); + __WFE(); + __WFE(); + + /* Catch the case where this code does not properly sleep */ + /* Unfreeze the GPIO by clearing MBUS_GATE (always safe to do) */ + MXC_PWRSEQ->reg1 &= ~(MXC_F_PWRSEQ_REG1_PWR_MBUS_GATE); + MXC_ASSERT_FAIL(); + while (1) { + __NOP(); + } + + /* Does not actually return */ +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/lp.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/lp.h new file mode 100644 index 0000000..1c1e738 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/lp.h @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-23 10:22:39 -0500 (Wed, 23 Mar 2016) $ + * $Revision: 22053 $ + * + ******************************************************************************/ + +/** + * @file lp.h + * @brief This is the high level API for the Lower Power + */ + +#ifndef _LP_H_ +#define _LP_H_ + +#include "gpio.h" +#include "pwrman_regs.h" +#include "pwrseq_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ +/** + * @brief Enumerations for pull-up and pull-downs + * + */ +typedef enum { + LP_WEAK_PULL_DOWN = -1, + LP_NO_PULL = 0, + LP_WEAK_PULL_UP = 1 +} +lp_pu_pd_select_t; + +/***** Function Prototypes *****/ + +/** + * @brief Gets the first boot flag + * + * @returns 0 if FIRST_BOOT was not set, or 1 if FIRST_BOOT was set + */ +__STATIC_INLINE unsigned int LP_IsFirstBoot() +{ + return ((MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT) >> MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT_POS); +} + +/** + * @brief Clears the first boot flag + * + */ +__STATIC_INLINE void LP_ClearFirstBoot() +{ + MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT; +} + +/** + * @brief Determines of program woke up from LP0 + * + * @returns 0 if not woken up from LP0, or 1 if woken from LP0 + */ +__STATIC_INLINE unsigned int LP_IsLP0WakeUp() +{ + //POR should be set and first boot clear + if((MXC_PWRMAN->pwr_rst_ctrl & MXC_F_PWRMAN_PWR_RST_CTRL_POR) && + ((MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT) == 0)) + return 1; + else + return 0; + +} + +__STATIC_INLINE unsigned int LP_GetWakeUpFlags(void) +{ + return MXC_PWRSEQ->flags; +} +/** + * @brief Clear ALL wake-up configuration on all pins. Disables wake-up entirely. + */ +void LP_ClearWakeUpConfig(void); + +/** + * @brief Read wake-up flags, clear flags, and return to caller. + * @returns Wake-up flags from Power Sequencer + */ +unsigned int LP_ClearWakeUpFlags(void); + +/** + * @brief This function configures one GPIO pin to wake the processor from LP0 or LP1. + * It is not used for LP2 wake-up, as normal GPIO interrupt processing is active in that mode. + * @param gpio GPIO pointer describing the port and pin for selected wake-up source + * @param act_high If non-zero, the signal is configured for active high wake-up. Otherwise, active low. + * @param wk_pu_pd Selection for the 1 Meg ohm pull-up or pull-down on this pin, see #lp_pu_pd_select_t + * @returns #E_NO_ERROR on success, error if unsuccessful. + */ +int LP_ConfigGPIOWakeUpDetect(const gpio_cfg_t *gpio, unsigned int act_high, lp_pu_pd_select_t wk_pu_pd); + +/** + * @brief Clear the wake-up configuration on one specific GPIO pin + * @param gpio GPIO pointer describing the port and pin for selected wake-up source + * @returns #E_NO_ERROR on success, error if unsuccessful. + */ +int LP_ClearGPIOWakeUpDetect(const gpio_cfg_t *gpio); + +/** + * @brief Check if a specific gpio triggered the wake up + * @param gpio GPIO pointer describing the port and pin(s) + * @returns 0 = gpio passed in did not trigger a wake up + * nonzero = at least one of the gpio passed in triggered a wake up + * the bit set represents which pin is the wake up source + */ +uint8_t LP_IsGPIOWakeUpSource(const gpio_cfg_t *gpio); + +/** + * @brief Wake on USB plug or unplug + * @param plug_en set to 1 to enable wake-up when USB VBUS is detected + * @param unplug_en set to 1 to enable wake-up when USB VBUS disappears + * @returns #E_NO_ERROR on success, error if unsuccessful. + */ +int LP_ConfigUSBWakeUp(unsigned int plug_en, unsigned int unplug_en); + +/** + * @brief Wake on any enabled event signal from RTC + * @param comp0_en set to 1 to enable wake-up when RTC Comparison 0 is set + * @param comp1_en set to 1 to enable wake-up when RTC Comparison 1 is set + * @param prescale_cmp_en set to 1 to enable wake-up when RTC Prescaler Compare is set + * @param rollover_en set to 1 to enable wake-up when RTC Roll-over is set + * @returns #E_NO_ERROR on success, error if unsuccessful. + */ +int LP_ConfigRTCWakeUp(unsigned int comp0_en, unsigned int comp1_en, unsigned int prescale_cmp_en, unsigned int rollover_en); + +/** + * @brief Enter LP2 power-saving mode + * @returns #E_NO_ERROR on success, error if unsuccessful. + */ +int LP_EnterLP2(void); + +/** + * @brief Enter LP1 mode, which saves CPU state and SRAM. Execution resumes after this call. + * @note Interrupts should be globally disabled before calling this function. + * @returns #E_NO_ERROR on success, error if unsuccessful. + */ +int LP_EnterLP1(void); + +/** + * @brief Enter the lowest-possible power mode, known as LP0. SRAM contents are lost. + * Waking up from LP0 is like a system reset. This function does not return. + * @note Interrupts are globally disabled upon entering this function. + */ +void LP_EnterLP0(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _LP_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/maa.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/maa.c new file mode 100644 index 0000000..efa64e6 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/maa.c @@ -0,0 +1,236 @@ +/** + * @file maa.c + * @brief Modular Arithmetic Accelerator (MAA) API Function Implementations. + */ +/* ***************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + **************************************************************************** */ + +/* **** Includes **** */ +#include +#include "mxc_assert.h" +#include "mxc_lock.h" +#include "mxc_sys.h" +#include "maa.h" + +/** + * @ingroup maa + * @{ + */ + +///@cond +#define maa_is_running() (MXC_MAA->ctrl & MXC_F_MAA_CTRL_START ? 1 : 0) + +/** + * Macro that translates from #mxc_maa_reg_select_t to a pointer for MAA memory operations. + */ +#define UMAA_REGFILE_TO_ADDR(base, x) ((base + (MXC_MAA_HALF_SIZE * x))) + +/** + * Macro that adjusts the pointer so that it is pointing to the last 32-bit word in the maa (sub-)segment + */ +#define UMAA_ADDR_INDEX_LAST_32BIT(x) ((uint8_t *)x + (MXC_MAA_HALF_SIZE-4)) +///@endcond + + +/* ************************************************************************* */ +mxc_maa_ret_t MAA_Init(void) +{ + SYS_MAA_Init(); + + return MXC_E_MAA_OK; +} + +/* ************************************************************************* */ +mxc_maa_ret_t MAA_WipeRAM(void) +{ + /* Check for running MAA */ + if (maa_is_running()) { + return MXC_E_MAA_ERR; + } + + /* Clear register files */ + memset((void *)MXC_MAA_MEM->seg0, 0, sizeof(MXC_MAA_MEM->seg0)); + memset((void *)MXC_MAA_MEM->seg1, 0, sizeof(MXC_MAA_MEM->seg1)); + memset((void *)MXC_MAA_MEM->seg2, 0, sizeof(MXC_MAA_MEM->seg2)); + memset((void *)MXC_MAA_MEM->seg3, 0, sizeof(MXC_MAA_MEM->seg3)); + memset((void *)MXC_MAA_MEM->seg4, 0, sizeof(MXC_MAA_MEM->seg4)); + memset((void *)MXC_MAA_MEM->seg5, 0, sizeof(MXC_MAA_MEM->seg5)); + + return MXC_E_MAA_OK; +} + +/* ************************************************************************* */ +mxc_maa_ret_t MAA_Load(mxc_maa_reg_select_t regfile, const uint8_t *data, unsigned int size, mxc_maa_endian_select_t flag) +{ + uint32_t *maaptr; + uint32_t fill; + unsigned int zerotmp; + + if ((regfile > MXC_E_REG_51) || (size > MXC_MAA_REG_SIZE)) { + /* Out of range */ + return MXC_E_MAA_ERR; + } + + if (flag == MXC_MAA_F_MEM_REVERSE) { + /* This is not currently implemented */ + return MXC_E_MAA_ERR; + } + + maaptr = (uint32_t *)UMAA_REGFILE_TO_ADDR(MXC_BASE_MAA_MEM, regfile); + + /* + * MAA (sub-)segments must be loaded with zero pad to a 64-bit boundary, or the "garbage bits" + * will case erroneous results. + */ + /* Find the ceiling for the closest 64-bit boundary based on the selected MAWS */ + zerotmp = (((MXC_MAA->maws & MXC_F_MAA_MAWS_MODLEN) >> MXC_F_MAA_MAWS_MODLEN_POS) + 63) & 0xfc0; + /* Convert to bytes */ + zerotmp /= 8; + + /* Fill uMAA memory in long word sized chunks */ + while (size > 3) { + *maaptr++ = (data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0]; + data += 4; + size -= 4; + zerotmp = (zerotmp > 4) ? (zerotmp - 4) : 0; + } + + /* Remainder */ + if (size) { + fill = data[0]; + fill |= ((size > 1) ? (data[1] << 8) : 0); + fill |= ((size > 2) ? (data[2] << 16) : 0); + *maaptr++ = fill; + + /* We just filled 4 bytes in this section */ + zerotmp = (zerotmp > 4) ? (zerotmp - 4) : 0; + } + + /* Wipe the remaining "garbage bits" */ + while (zerotmp) { + *maaptr++ = 0; + zerotmp = (zerotmp > 4) ? (zerotmp - 4) : 0; + } + + return MXC_E_MAA_OK; +} + +/* ************************************************************************* */ +mxc_maa_ret_t MAA_Unload(mxc_maa_reg_select_t regfile, uint8_t *data, unsigned int size, mxc_maa_endian_select_t flag) +{ + uint32_t *maaptr; + uint32_t fill; + + if ((regfile > MXC_E_REG_51) || (size > MXC_MAA_REG_SIZE)) { + /* Out of range */ + return MXC_E_MAA_ERR; + } + + if (flag == MXC_MAA_F_MEM_REVERSE) { + /* This is not currently implemented */ + return MXC_E_MAA_ERR; + } + + maaptr = (uint32_t *)UMAA_REGFILE_TO_ADDR(MXC_BASE_MAA_MEM, regfile); + + /* Unload uMAA memory in long word sized chunks */ + while (size > 3) { + fill = *maaptr++; + data[0] = fill & 0xff; + data[1] = (fill >> 8) & 0xff; + data[2] = (fill >> 16) & 0xff; + data[3] = (fill >> 24) & 0xff; + data += 4; + size -= 4; + } + + /* Remainder */ + if (size) { + fill = *maaptr; + data[0] = fill & 0xff; + if (size > 1) { + data[1] = (fill >> 8) & 0xff; + } + if (size > 2) { + data[2] = (fill >> 16) & 0xff; + } + } + + return MXC_E_MAA_OK; +} + +/* ************************************************************************* */ +mxc_maa_ret_t MAA_Run(mxc_maa_operation_t op, + mxc_maa_reg_select_t al, mxc_maa_reg_select_t bl, + mxc_maa_reg_select_t rl, mxc_maa_reg_select_t tl) +{ + if (maa_is_running()) { + /* Attempt to start the MAA while already running */ + return MXC_E_MAA_ERR; + } + + /* Clear out any previous flags */ + MXC_MAA->ctrl = 0x00000020; + + /* Construct memory segment selections, select operation, and start the uMAA */ + MXC_MAA->ctrl = (((al << MXC_F_MAA_CTRL_SEG_A_POS) & MXC_F_MAA_CTRL_SEG_A) | + ((bl << MXC_F_MAA_CTRL_SEG_B_POS) & MXC_F_MAA_CTRL_SEG_B) | + ((rl << MXC_F_MAA_CTRL_SEG_RES_POS) & MXC_F_MAA_CTRL_SEG_RES) | + ((tl << MXC_F_MAA_CTRL_SEG_TMP_POS) & MXC_F_MAA_CTRL_SEG_TMP) | + ((op << MXC_F_MAA_CTRL_OPSEL_POS) & MXC_F_MAA_CTRL_OPSEL) | + MXC_F_MAA_CTRL_START); + + /* Blocking wait for uMAA to complete. */ + while ((MXC_MAA->ctrl & MXC_F_MAA_CTRL_IF_DONE) == 0); + + if (MXC_MAA->ctrl & MXC_F_MAA_CTRL_IF_ERROR) { + /* MAA signaled error */ + return MXC_E_MAA_ERR; + } + + return MXC_E_MAA_OK; +} + +/* ************************************************************************* */ +mxc_maa_ret_t MAA_SetWordSize(unsigned int len) +{ + if ((len > MXC_MAA_REG_SIZE_BITS) || maa_is_running()) { + return MXC_E_MAA_ERR; + } + + /* Set bit length for calculation, and disable endian swap */ + MXC_MAA->maws = ((len << MXC_F_MAA_MAWS_MODLEN_POS) & MXC_F_MAA_MAWS_MODLEN); + + return MXC_E_MAA_OK; +} +/**@} end of ingroup maa */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/maa.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/maa.h new file mode 100644 index 0000000..03c7d95 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/maa.h @@ -0,0 +1,220 @@ +/** + * @file maa.h + * @brief Registers, Bit Masks and Bit Positions for the Modular Math + * Accelerator (MAA) module. + */ +/* ***************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 11:28:30 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24064 $ + * + **************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _MAA_H +#define _MAA_H + +/* **** Includes **** */ +#include + +#include "maa_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup maa MAA + * @ingroup periphlibs + * @details The API only supports synchronous operations due to the sensitive + * nature of the input and output data. + * @{ + */ + +/* **** Definitions **** */ + +/** + * Definition for the maximum MAA register size on this device in bytes, 128. + */ +#define MXC_MAA_REG_SIZE 0x80 +/** + * Definition for the maximum MAA register size on this device in bits, 1024. + */ +#define MXC_MAA_REG_SIZE_BITS (MXC_MAA_REG_SIZE << 3) + +/** + * @define Sub-register ("half size"), allowing 2x more operands in MAA at a time when MAWS <= MAX_SIZE/2 + */ +#define MXC_MAA_HALF_SIZE (MXC_MAA_REG_SIZE/2) + +/** Flags for MAA_Load() and MAA_Unload() */ +#define MXC_MAA_F_MEM_VERBATIM 0 +/** Flags for MAA_Load() and MAA_Unload() */ +#define MXC_MAA_F_MEM_REVERSE 1 + +/** + * Enumeration type for Segment and Sub-segment selection + */ +/* Warning: Do not change the assigned numbers/ordering without associated changes to UMAA_REGFILE_TO_ADDR(x) */ +typedef enum { + /* Register names when MAWS > 512 */ + MXC_E_REG_0 = 0, /**< Register name if MAA_MAWS > 512 */ + MXC_E_REG_1 = 2, /**< Register name if MAA_MAWS > 512 */ + MXC_E_REG_2 = 4, /**< Register name if MAA_MAWS > 512 */ + MXC_E_REG_3 = 6, /**< Register name if MAA_MAWS > 512 */ + MXC_E_REG_4 = 8, /**< Register name if MAA_MAWS > 512 */ + MXC_E_REG_5 = 10, /**< Register name if MAA_MAWS > 512 */ + /* Register names when MAWS < 512 */ + MXC_E_REG_00 = 0, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_01 = 1, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_10 = 2, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_11 = 3, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_20 = 4, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_21 = 5, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_30 = 6, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_31 = 7, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_40 = 8, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_41 = 9, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_50 = 10, /**< Register name if MAA_MAWS < 512 */ + MXC_E_REG_51 = 11 /**< Register name if MAA_MAWS < 512 */ +} mxc_maa_reg_select_t; + +/** + * Enumeration type for MAA operation select. + */ +typedef enum { + MXC_E_MAA_EXP = 0, /**< Exponentiate */ + MXC_E_MAA_SQR = 1, /**< Square */ + MXC_E_MAA_MUL = 2, /**< Multiply */ + MXC_E_MAA_SQRMUL = 3, /**< Square followed by Multiply */ + MXC_E_MAA_ADD = 4, /**< Addition */ + MXC_E_MAA_SUB = 5 /**< Subtraction */ +} mxc_maa_operation_t; + +/** + * Enumeration type to set special flags for loading & unloading data. + */ +typedef enum { + + MXC_E_MAA_VERBATIM = 0, /**< Copy bytes without reversal and right-justification */ + MXC_E_MAA_REVERSE /**< Reverse bytes and right-justify (bytes are loaded at the highest address, then descending) */ +} mxc_maa_endian_select_t; + +/** + * Enumeration type for MAA module specific return codes. + */ +typedef enum { + MXC_E_MAA_ERR = -1, /**< Error */ + MXC_E_MAA_OK = 0, /**< No Error */ + MXC_E_MAA_BUSY /**< MAA engine busy, try again later */ +} mxc_maa_ret_t; + +/** + * @brief Initialize the required clocks and enable the MAA peripheral + * module. + */ +mxc_maa_ret_t MAA_Init(void); + +/** + * @brief Erase all MAA register RAM + */ +mxc_maa_ret_t MAA_WipeRAM(void); + + +/** + * @brief Load the selected MAA register. + * + * @param regfile Selects the register to load. + * @param data Pointer to a data buffer to load into the register. + * @param size Size of the data to load. + * @param flag Reverse the data so that it will unload properly on + * little endian machines, see #mxc_maa_endian_select_t. + * + * @return #MXC_E_MAA_ERR if any parameter out of range. + * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. + * @return #MXC_E_MAA_OK if the selected register is loaded correctly. + */ +mxc_maa_ret_t MAA_Load(mxc_maa_reg_select_t regfile, const uint8_t *data, unsigned int size, mxc_maa_endian_select_t flag); + +/** + * @brief Unload (copy from) the selected MAA register + * + * @param regfile Selects the register to unload. + * @param data Pointer to a buffer to store the unloaded data. + * @param size Maximum size of the data to unload. + * @param flag Reverse the data so that it will unload properly on + * little endian machines, see #mxc_maa_endian_select_t. + * @return #MXC_E_MAA_ERR if any parameter out of range. + * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. + * @return #MXC_E_MAA_OK if the requested register data is copied correctly + * to @p data. + */ +mxc_maa_ret_t MAA_Unload(mxc_maa_reg_select_t regfile, uint8_t *data, unsigned int size, mxc_maa_endian_select_t flag); + +/** + * @brief Execute an MAA operation specified. + * + * @param op Operation to perform, see #mxc_maa_operation_t. + * @param al Segment to use for operand A, see #mxc_maa_reg_select_t. + * @param bl Segment to use for operand B. + * @param rl Segment which will hold result R after the operation is + * complete. + * @param tl Segment to use for temporary storage T. + * + * @return #MXC_E_MAA_ERR if any parameter out of range. + * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. + * @return #MXC_E_MAA_OK if the operation completed. + */ +mxc_maa_ret_t MAA_Run(mxc_maa_operation_t op, \ + mxc_maa_reg_select_t al, mxc_maa_reg_select_t bl, \ + mxc_maa_reg_select_t rl, mxc_maa_reg_select_t tl); + +/** + * @brief Set the bit length of the modulus. + * + * @param len Modulus size in bits (ie. \f$ ln_2(modulus) \f$ ) + * + * @return #MXC_E_MAA_ERR if any parameter out of range. + * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. + * @return #MXC_E_MAA_OK if the length is set as requested. + */ +mxc_maa_ret_t MAA_SetWordSize(unsigned int len); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_assert.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_assert.c new file mode 100644 index 0000000..8070c35 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_assert.c @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21839 $ + * + ******************************************************************************/ + +/** + * @file mxc_assert.c + * @brief Source for assertion failure. + */ + +#include "mxc_config.h" + +/***** Includes *****/ + +/***** Definitions *****/ + +/***** Globals *****/ + +/***** Functions *****/ + +/******************************************************************************/ +__weak void mxc_assert(const char *expr, const char *file, int line) +{ + while(1) {} +} + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_assert.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_assert.h new file mode 100644 index 0000000..a2720ac --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_assert.h @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21839 $ + * + ******************************************************************************/ + +/** + * @file mxc_assert.h + * @brief Assertion checks for debugging. + */ + +#ifndef _MXC_ASSERT_H_ +#define _MXC_ASSERT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Includes *****/ + +/***** Definitions *****/ + +#ifdef MXC_ASSERT_ENABLE +/* Use this to check that expr is true (non-zero) */ +#define MXC_ASSERT(expr) \ +if (!(expr)) \ +{ \ + mxc_assert(#expr, __FILE__, __LINE__); \ +} +/* Use this to fail without any expression checking */ +#define MXC_ASSERT_FAIL() mxc_assert("FAIL", __FILE__, __LINE__); +#else +#define MXC_ASSERT(expr) +#define MXC_ASSERT_FAIL() +#endif + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Assert an error when the given expression fails during debugging. + * @param expr String with the expression that failed the assertion. + * @param req File containing the failed assertion. + * @param line Line number for the failed assertion. + * @note This is defined as a weak function. Can be overridden at the + * application layer to print the debugging information. + * printf("%s, file: %s, line %d \n", expr, file, line); + */ +void mxc_assert(const char *expr, const char *file, int line); + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_ASSERT_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_config.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_config.h new file mode 100644 index 0000000..368abaf --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_config.h @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 12:50:27 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21840 $ + * + ******************************************************************************/ + +#ifndef _MXC_CONFIG_H +#define _MXC_CONFIG_H + +#include "mxc_device.h" +#include "mxc_errors.h" + +#endif /* _MXC_CONFIG_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_errors.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_errors.h new file mode 100644 index 0000000..868dcdd --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_errors.h @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-05-18 13:19:43 -0500 (Wed, 18 May 2016) $ + * $Revision: 22894 $ + * + ******************************************************************************/ + +/** +* @file mxc_errors.h +* @brief List of Common Errors +* @note A Negative Error Convention is used to avoid conflict with positive +* Non-Error returns. +* +*/ + +#ifndef _ERRORS_H_ +#define _ERRORS_H_ + +/** No Error */ +#define E_NO_ERROR 0 +/** No Error, success */ +#define E_SUCCESS 0 +/** Pointer is NULL */ +#define E_NULL_PTR -1 +/** No such device */ +#define E_NO_DEVICE -2 +/** Parameter not acceptable */ +#define E_BAD_PARAM -3 +/** Value not valid or allowed */ +#define E_INVALID -4 +/** Module not initialized */ +#define E_UNINITIALIZED -5 +/** Busy now, try again later */ +#define E_BUSY -6 +/** Operation not allowed in current state */ +#define E_BAD_STATE -7 +/** Generic error */ +#define E_UNKNOWN -8 +/** General communications error */ +#define E_COMM_ERR -9 +/** Operation timed out */ +#define E_TIME_OUT -10 +/** Expected response did not occur */ +#define E_NO_RESPONSE -11 +/** Operations resulted in unexpected overflow */ +#define E_OVERFLOW -12 +/** Operations resulted in unexpected underflow */ +#define E_UNDERFLOW -13 +/** Data or resource not available at this time */ +#define E_NONE_AVAIL -14 +/** Event was shutdown */ +#define E_SHUTDOWN -15 +/** Event was aborted */ +#define E_ABORT -16 +/** The requested operation is not supported */ +#define E_NOT_SUPPORTED -17 + +#endif /* _ERRORS_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_lock.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_lock.h new file mode 100644 index 0000000..28bb062 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_lock.h @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21839 $ + * + ******************************************************************************/ + +/** + * @file mxc_lock.h + * @brief Used to create exclusion for critical sections. + */ + +#ifndef _MXC_LOCK_H_ +#define _MXC_LOCK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Includes *****/ +#include "mxc_config.h" + +/***** Definitions *****/ + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Attempts to acquire the lock. + * @param lock Pointer to variable used for the lock. + * @param value Value to be place in the lock. Can not be 0. + * @details This in an interrupt safe function that can be used as a mutex. + The lock variable must remain in scope until the lock is released. + Will not block if another thread has acquired the lock. + * @returns E_NO_ERROR if everything successful, E_BUSY if lock is taken. + */ +__STATIC_INLINE int mxc_get_lock(uint32_t *lock, uint32_t value) +{ + do { + + // Return if the lock is taken by a different thread + if(__LDREXW((volatile unsigned long *)lock) != 0) { + return E_BUSY; + } + + // Attempt to take the lock + } while(__STREXW(value, (volatile unsigned long *)lock) != 0); + + // Do not start any other memory access until memory barrier is complete + __DMB(); + + return E_NO_ERROR; +} + +/** + * @brief Free the given lock. + * @param lock Pointer to variable used for the lock. + */ +__STATIC_INLINE void mxc_free_lock(uint32_t *lock) +{ + // Ensure memory operations complete before releasing lock + __DMB(); + *lock = 0; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_LOCK_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_sys.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_sys.c new file mode 100644 index 0000000..49bd542 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_sys.c @@ -0,0 +1,845 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-17 13:05:03 -0500 (Fri, 17 Jun 2016) $ + * $Revision: 23367 $ + * + ******************************************************************************/ + +#include +#include "mxc_config.h" +#include "mxc_assert.h" +#include "mxc_sys.h" +#include "ioman.h" +#include "clkman.h" +#include "pwrseq_regs.h" +#include "pwrman_regs.h" +#include "spix_regs.h" +#include "trim_regs.h" + +/***** Definitions *****/ +#define SYS_RTC_CLK 32768UL + +/******************************************************************************/ +uint32_t SYS_GetFreq(uint32_t clk_scale) +{ + uint32_t freq; + unsigned int clkdiv; + + if (clk_scale == MXC_V_CLKMAN_CLK_SCALE_DISABLED) { + freq = 0; + } else { + clkdiv = 1 << (clk_scale - 1); + freq = SystemCoreClock / clkdiv; + } + + return freq; +} + +/******************************************************************************/ +uint32_t SYS_CPU_GetFreq(void) +{ + return SYS_GetFreq(CLKMAN_GetClkScale(CLKMAN_CLK_CPU)); +} + +/******************************************************************************/ +int SYS_ADC_Init(void) +{ + /* Power up the ADC AFE, enable clocks */ + MXC_PWRMAN->pwr_rst_ctrl |= MXC_F_PWRMAN_PWR_RST_CTRL_AFE_POWERED; + MXC_CLKMAN->clk_ctrl |= MXC_F_CLKMAN_CLK_CTRL_ADC_CLOCK_ENABLE; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_AES_Init(void) +{ + /* Set up clocks for AES block */ + /* Enable crypto ring oscillator, which is used by all TPU components (AES, uMAA, etc.) */ + CLKMAN_CryptoClockEnable(1); + + /* Change prescaler to /1 */ + CLKMAN_SetClkScale(CLKMAN_CRYPTO_CLK_AES, CLKMAN_SCALE_DIV_1); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_GPIO_Init(void) +{ + if (CLKMAN_GetClkScale(CLKMAN_CLK_GPIO) == CLKMAN_SCALE_DISABLED) { + CLKMAN_SetClkScale(CLKMAN_CLK_GPIO, CLKMAN_SCALE_DIV_1); + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *uart_cfg, const sys_cfg_uart_t *sys_cfg) +{ + static int subsequent_call = 0; + int err, idx; + clkman_scale_t clk_scale; + uint32_t min_baud; + + if(sys_cfg == NULL) + return E_NULL_PTR; + + if (sys_cfg->clk_scale != CLKMAN_SCALE_AUTO) { + CLKMAN_SetClkScale(CLKMAN_CLK_UART, sys_cfg->clk_scale); + } else if (!subsequent_call) { + /* This clock divider is shared amongst all UARTs. Only change it if it + * hasn't already been configured. UART_Init() will check for validity + * for this baudrate. + */ + subsequent_call = 1; + + /* Setup the clock divider for the given baud rate */ + clk_scale = CLKMAN_SCALE_DISABLED; + do { + min_baud = ((SystemCoreClock >> clk_scale++) / (16 * (MXC_F_UART_BAUD_BAUD_DIVISOR >> MXC_F_UART_BAUD_BAUD_DIVISOR_POS))); + } while (uart_cfg->baud < min_baud && clk_scale < CLKMAN_SCALE_AUTO); + + /* check if baud rate cannot be reached */ + if(uart_cfg->baud < min_baud) + return E_BAD_STATE; + + CLKMAN_SetClkScale(CLKMAN_CLK_UART, clk_scale); + } + + if ((err = IOMAN_Config(&sys_cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + /* Reset the peripheral */ + idx = MXC_UART_GET_IDX(uart); + MXC_PWRMAN->peripheral_reset |= (MXC_F_PWRMAN_PERIPHERAL_RESET_UART0 << idx); + MXC_PWRMAN->peripheral_reset &= ~((MXC_F_PWRMAN_PERIPHERAL_RESET_UART0 << idx)); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_UART_Shutdown(mxc_uart_regs_t *uart) +{ + int err; + int idx = MXC_UART_GET_IDX(uart); + ioman_cfg_t io_cfg = (ioman_cfg_t)IOMAN_UART(idx, 0, 0, 0, 0, 0, 0); + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_UART_GetFreq(mxc_uart_regs_t *uart) +{ + return SYS_GetFreq(CLKMAN_GetClkScale(CLKMAN_CLK_UART)); +} + +/******************************************************************************/ +int SYS_I2CM_Init(mxc_i2cm_regs_t *i2cm, const sys_cfg_i2cm_t *cfg) +{ + int err; + + if(cfg == NULL) + return E_NULL_PTR; + + CLKMAN_SetClkScale(CLKMAN_CLK_I2CM, cfg->clk_scale); + MXC_CLKMAN->i2c_timer_ctrl = 1; + + if ((err = IOMAN_Config(&cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_I2CM_Shutdown(mxc_i2cm_regs_t *i2cm) +{ + int err; + int idx = MXC_I2CM_GET_IDX(i2cm); + ioman_cfg_t io_cfg = (ioman_cfg_t)IOMAN_I2CM(idx, 0, 0); + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_I2CM_GetFreq(mxc_i2cm_regs_t *i2cm) +{ + return SYS_GetFreq(CLKMAN_GetClkScale(CLKMAN_CLK_I2CM)); +} + +/******************************************************************************/ +int SYS_I2CS_Init(mxc_i2cs_regs_t *i2cs, const sys_cfg_i2cs_t *cfg) +{ + int err; + + if(cfg == NULL) + return E_NULL_PTR; + + CLKMAN_SetClkScale(CLKMAN_CLK_I2CS, cfg->clk_scale); + MXC_CLKMAN->i2c_timer_ctrl = 1; + + if ((err = IOMAN_Config(&cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_I2CS_Shutdown(mxc_i2cs_regs_t *i2cs) +{ + int err; + ioman_cfg_t io_cfg = (ioman_cfg_t)IOMAN_I2CS(0, 0); + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_I2CS_GetFreq(mxc_i2cs_regs_t *i2cs) +{ + uint32_t freq, clkdiv; + + if (CLKMAN_GetClkScale(CLKMAN_CLK_I2CS) == MXC_V_CLKMAN_CLK_SCALE_DISABLED) { + freq = 0; + } else { + clkdiv = 1 << (CLKMAN_GetClkScale(CLKMAN_CLK_I2CS) - 1); + freq = (SystemCoreClock / clkdiv); + } + + return freq; +} + +/******************************************************************************/ +int SYS_SPIM_Init(mxc_spim_regs_t *spim, const spim_cfg_t *spim_cfg, const sys_cfg_spim_t *sys_cfg) +{ + int err, idx; + clkman_scale_t clk_scale; + uint32_t max_baud; + + if(sys_cfg == NULL) + return E_NULL_PTR; + + idx = MXC_SPIM_GET_IDX(spim); + + if (sys_cfg->clk_scale != CLKMAN_SCALE_AUTO) { + if(spim_cfg->baud > ((SystemCoreClock >> (sys_cfg->clk_scale - 1))/2)) { + return E_BAD_PARAM; + } + CLKMAN_SetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIM0 + idx), sys_cfg->clk_scale); + } else { + + if(spim_cfg->baud > (SystemCoreClock/2)) { + return E_BAD_PARAM; + } + + /* Setup the clock divider for the given baud rate */ + clk_scale = CLKMAN_SCALE_DISABLED; + do { + max_baud = ((SystemCoreClock >> clk_scale++) / 2); + } while (spim_cfg->baud < max_baud && clk_scale < CLKMAN_SCALE_AUTO); + + if(clk_scale == CLKMAN_SCALE_AUTO) { + clk_scale--; + } + + CLKMAN_SetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIM0 + idx), clk_scale); + } + + if ((err = IOMAN_Config(&sys_cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_SPIM_Shutdown(mxc_spim_regs_t *spim) +{ + int err; + int idx = MXC_SPIM_GET_IDX(spim); + ioman_cfg_t io_cfg; + + switch(idx) { + case 0: + io_cfg = (ioman_cfg_t)IOMAN_SPIM0(0, 0, 0, 0, 0, 0, 0, 0); + break; + case 1: + io_cfg = (ioman_cfg_t)IOMAN_SPIM1(0, 0, 0, 0, 0, 0); + break; + case 2: + io_cfg = (ioman_cfg_t)IOMAN_SPIM2(0, 0, 0, 0, 0, 0, 0, 0); + break; + default: + return E_BAD_PARAM; + } + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_SPIM_GetFreq(mxc_spim_regs_t *spim) +{ + int idx = MXC_SPIM_GET_IDX(spim); + return SYS_GetFreq(CLKMAN_GetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIM0 + idx))); +} + +/******************************************************************************/ +int SYS_SPIX_Init(const sys_cfg_spix_t *sys_cfg, uint32_t baud) +{ + int err; + clkman_scale_t clk_scale; + uint32_t min_baud; + + if (sys_cfg->clk_scale != CLKMAN_SCALE_AUTO) { + CLKMAN_SetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIX), sys_cfg->clk_scale); + } else { + /* Setup the clock divider for the given baud rate */ + clk_scale = CLKMAN_SCALE_DISABLED; + do { + min_baud = ((SystemCoreClock >> clk_scale++) / (2 * + (MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK >> MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK_POS))); + } while (baud < min_baud && clk_scale < CLKMAN_SCALE_AUTO); + + /* check if baud rate cannot be reached */ + if(baud < min_baud) + return E_BAD_STATE; + + CLKMAN_SetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIX), clk_scale); + } + + if ((err = IOMAN_Config(&sys_cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_SPIX_Shutdown(void) +{ + int err; + ioman_cfg_t io_cfg = IOMAN_SPIX(0, 0, 0, 0, 0, 0); + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_SPIX_GetFreq(void) +{ + return SYS_GetFreq(CLKMAN_GetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIX))); +} + +/******************************************************************************/ +int SYS_SPIS_Init(const sys_cfg_spis_t *sys_cfg) +{ + int err; + + if (sys_cfg->clk_scale != CLKMAN_SCALE_AUTO) { + CLKMAN_SetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIS), sys_cfg->clk_scale); + } else { + CLKMAN_SetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIS), CLKMAN_SCALE_DIV_1); + } + + if ((err = IOMAN_Config(&sys_cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_SPIS_Shutdown(mxc_spis_regs_t *spis) +{ + int err; + ioman_cfg_t io_cfg = IOMAN_SPIS(0, 0, 0); + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_SPIS_GetFreq(mxc_spis_regs_t *spis) +{ + return SYS_GetFreq(CLKMAN_GetClkScale((clkman_clk_t)(CLKMAN_CLK_SPIS))); +} + +/******************************************************************************/ +int SYS_OWM_Init(mxc_owm_regs_t *owm, const sys_cfg_owm_t *sys_cfg) +{ + int err; + + if(sys_cfg == NULL) + return E_NULL_PTR; + + if (sys_cfg->clk_scale != CLKMAN_SCALE_AUTO) { + CLKMAN_SetClkScale(CLKMAN_CLK_OWM, sys_cfg->clk_scale); + } else { + CLKMAN_SetClkScale(CLKMAN_CLK_OWM, CLKMAN_SCALE_DIV_1); + } + + if ((err = IOMAN_Config(&sys_cfg->io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SYS_OWM_Shutdown(mxc_owm_regs_t *owm) +{ + int err; + + ioman_cfg_t io_cfg = IOMAN_OWM(0, 0); + + if ((err = IOMAN_Config(&io_cfg)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t SYS_OWM_GetFreq(mxc_owm_regs_t *owm) +{ + return SYS_GetFreq(CLKMAN_GetClkScale(CLKMAN_CLK_OWM)); +} + +/******************************************************************************/ +uint32_t SYS_TMR_GetFreq(mxc_tmr_regs_t *tmr) +{ + return SystemCoreClock; +} + +/******************************************************************************/ +int SYS_TMR_Init(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t *cfg) +{ + int pin, gpio_index, tmr_index; + + if (cfg != NULL) { + /* Make sure the given GPIO mapps to the given TMR */ + for (pin = 0; pin < MXC_GPIO_MAX_PINS_PER_PORT; pin++) { + if(cfg->mask & (1 << pin)) { + gpio_index = (MXC_GPIO_MAX_PINS_PER_PORT * cfg->port) + pin; + tmr_index = gpio_index % MXC_CFG_TMR_INSTANCES; + + if(tmr_index == MXC_TMR_GET_IDX(tmr)) + return GPIO_Config(cfg); + else + return E_BAD_PARAM; + } + } + + return E_BAD_PARAM; + + } else { + return E_NO_ERROR; + } +} + +/******************************************************************************/ +uint32_t SYS_SysTick_GetFreq(void) +{ + /* Determine is using internal (SystemCoreClock) or external (32768) clock */ + if ( (SysTick->CTRL & SysTick_CTRL_CLKSOURCE_Msk) || !(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) { + return SystemCoreClock; + } else { + return SYS_RTC_CLK; + } +} + +/******************************************************************************/ +uint32_t SYS_PT_GetFreq(void) +{ + return SYS_GetFreq(CLKMAN_GetClkScale(CLKMAN_CLK_PT)); +} + +/******************************************************************************/ +void SYS_PT_Init(sys_pt_clk_scale clk_scale) +{ + /* setup clock divider for pulse train clock */ + CLKMAN_SetClkScale(CLKMAN_CLK_PT, clk_scale); +} + +/******************************************************************************/ +int SYS_PT_Config(mxc_pt_regs_t *pt, const sys_cfg_pt_t *cfg) +{ + int pt_index; + + /* Make sure the given GPIO mapps to the given PT */ + pt_index = MXC_PT_GET_IDX(pt); + if(pt_index < 0) { + return E_NOT_SUPPORTED; + } + + /* Even number port */ + if(cfg->port%2 == 0) { + /* Pin number should match PT number */ + if(!(cfg->mask & (0x1 << pt_index))) { + return E_NOT_SUPPORTED; + } + } else { + /* Pin number+8 should match PT */ + if(!((cfg->mask << 8) & (0x1 << pt_index))) { + return E_NOT_SUPPORTED; + } + } + + return GPIO_Config(cfg); +} + +/******************************************************************************/ +void SYS_USB_Enable(uint8_t enable) +{ + /* Enable USB clock */ + CLKMAN_ClockGate(CLKMAN_USB_CLOCK, enable); + + if(enable) { + /* Enable USB Power */ + MXC_PWRMAN->pwr_rst_ctrl |= MXC_F_PWRMAN_PWR_RST_CTRL_USB_POWERED; + } else { + /* Disable USB Power */ + MXC_PWRMAN->pwr_rst_ctrl &= ~MXC_F_PWRMAN_PWR_RST_CTRL_USB_POWERED; + } +} + +/******************************************************************************/ +int SYS_SysTick_Config(uint32_t ticks, int clk_src) +{ + + if(ticks == 0) + return E_BAD_PARAM; + + /* If SystemClock, call default CMSIS config and return */ + if (clk_src) { + return SysTick_Config(ticks); + } else { + /* External clock source requested + enable RTC clock in run mode*/ + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN); + + /* Disable SysTick Timer */ + SysTick->CTRL = 0; + /* Check reload value for valid */ + if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) { + /* Reload value impossible */ + return E_BAD_PARAM; + } + /* set reload register */ + SysTick->LOAD = ticks - 1; + + /* set Priority for Systick Interrupt */ + NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); + + /* Load the SysTick Counter Value */ + SysTick->VAL = 0; + + /* Enable SysTick IRQ and SysTick Timer leaving clock source as external */ + SysTick->CTRL = SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; + + /* Function successful */ + return E_NO_ERROR; + } +} + +/******************************************************************************/ +int SYS_SysTick_Delay(uint32_t ticks) +{ + uint32_t cur_ticks, num_full, num_remain, previous_ticks, num_subtract, i; + uint32_t reload, value, ctrl; /* save/restore variables */ + + if(ticks == 0) + return E_BAD_PARAM; + + /* If SysTick is not enabled we can take it for our delay */ + if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) { + + /* Save current state in case it's disabled but already configured, restore at return.*/ + reload = SysTick->LOAD; + value = SysTick->VAL; + ctrl = SysTick->CTRL; + + /* get the number of ticks less than max RELOAD. */ + num_remain = ticks % SysTick_LOAD_RELOAD_Msk; + + /* if ticks is < Max SysTick Reload num_full will be 0, otherwise it will + give us the number of max SysTicks cycles required */ + num_full = (ticks - 1) / SysTick_LOAD_RELOAD_Msk; + + /* Do the required full systick countdowns */ + if (num_full) { + /* load the max count value into systick */ + SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; + /* load the starting value */ + SysTick->VAL = 0; + /*enable SysTick counter with SystemClock source internal, immediately forces LOAD register into VAL register */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; + /* CountFlag will get set when VAL reaches zero */ + for (i = num_full; i > 0; i--) { + do { + cur_ticks = SysTick->CTRL; + } while (!(cur_ticks & SysTick_CTRL_COUNTFLAG_Msk)); + } + /* Disable systick */ + SysTick->CTRL = 0; + } + /* Now handle the remainder of ticks */ + if (num_remain) { + SysTick->LOAD = num_remain; + SysTick->VAL = 0; + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; + /* wait for countflag to get set */ + do { + cur_ticks = SysTick->CTRL; + } while (!(cur_ticks & SysTick_CTRL_COUNTFLAG_Msk)); + /* Disable systick */ + SysTick->CTRL = 0; + } + + /* restore original state of SysTick and return */ + SysTick->LOAD = reload; + SysTick->VAL = value; + SysTick->CTRL = ctrl; + + return E_NO_ERROR; + + } else { + /* SysTick is enabled + When SysTick is enabled count flag can not be used + and the reload can not be changed. + Do not read the CTRL register -> clears count flag */ + + /* Get the reload value for wrap/reload case */ + reload = SysTick->LOAD; + + /* Read the starting systick value */ + previous_ticks = SysTick->VAL; + + do { + /* get current SysTick value */ + cur_ticks = SysTick->VAL; + /* Check for wrap/reload of timer countval */ + if (cur_ticks > previous_ticks) { + /* subtract count to 0 (previous_ticks) and wrap (reload value - cur_ticks) */ + num_subtract = (previous_ticks + (reload - cur_ticks)); + } else { + /* standard case (no wrap) + subtract off the number of ticks since last pass */ + num_subtract = (previous_ticks - cur_ticks); + } + /* check to see if we are done. */ + if (num_subtract >= ticks) + return E_NO_ERROR; + else + ticks -= num_subtract; + /* cur_ticks becomes previous_ticks for next timer read. */ + previous_ticks = cur_ticks; + } while (ticks > 0); + /* Should not ever be reached */ + return E_NO_ERROR; + } +} + +/******************************************************************************/ +int SYS_RTC_Init(void) +{ + /* Enable power for RTC for all LPx states */ + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN | + MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP); + + /* Enable clock to synchronizers */ + CLKMAN_SetClkScale(CLKMAN_CLK_SYNC, CLKMAN_SCALE_DIV_1); + + return E_NO_ERROR; +} + +/******************************************************************************/ +void SYS_IOMAN_UseVDDIO(const gpio_cfg_t *cfg) +{ + unsigned int startbit = (cfg->port * 8); + volatile uint32_t *use_vddioh_reg = &MXC_IOMAN->use_vddioh_0 + (startbit / 32); + *use_vddioh_reg &= ~cfg->mask << (startbit % 32); +} + +/******************************************************************************/ +void SYS_IOMAN_UseVDDIOH(const gpio_cfg_t *cfg) +{ + unsigned int startbit = (cfg->port * 8); + volatile uint32_t *use_vddioh_reg = &MXC_IOMAN->use_vddioh_0 + (startbit / 32); + *use_vddioh_reg |= cfg->mask << (startbit % 32); +} + +/******************************************************************************/ +void SYS_WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg) +{ + + if(cfg->clk == CLKMAN_WDT_SELECT_NANO_RING_OSCILLATOR) { + /*enable nanoring in run mode */ + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_NREN_RUN); + } else if(cfg->clk == CLKMAN_WDT_SELECT_32KHZ_RTC_OSCILLATOR) { + /*enabled RTC in run mode */ + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN); + } + + if(wdt == MXC_WDT0) { + /*select clock source */ + CLKMAN_WdtClkSelect(0, cfg->clk); + + /*Set scale of clock (only used for system clock as source) */ + CLKMAN_SetClkScale(CLKMAN_CLK_WDT0, cfg->clk_scale); + + /*Enable clock */ + CLKMAN_ClockGate(CLKMAN_WDT0_CLOCK, 1); + } else if (wdt == MXC_WDT1) { + /*select clock source */ + CLKMAN_WdtClkSelect(1, cfg->clk); + + /*Set scale of clock (only used for system clock as source) */ + CLKMAN_SetClkScale(CLKMAN_CLK_WDT1, cfg->clk_scale); + + /*Enable clock */ + CLKMAN_ClockGate(CLKMAN_WDT1_CLOCK, 1); + } +} + +/******************************************************************************/ +void SYS_PRNG_Init(void) +{ + /* Start crypto ring, unconditionally */ + CLKMAN_CryptoClockEnable(1); + + /* If we find the dividers in anything other than off, don't touch them */ + if (CLKMAN_GetClkScale(CLKMAN_CRYPTO_CLK_PRNG) == CLKMAN_SCALE_DISABLED) { + /* Div 1 mode */ + CLKMAN_SetClkScale(CLKMAN_CRYPTO_CLK_PRNG, CLKMAN_SCALE_DIV_1); + } + + if (CLKMAN_GetClkScale(CLKMAN_CLK_PRNG) == CLKMAN_SCALE_DISABLED) { + /* Div 1 mode */ + CLKMAN_SetClkScale(CLKMAN_CLK_PRNG, CLKMAN_SCALE_DIV_1); + } +} + +/******************************************************************************/ +void SYS_MAA_Init(void) +{ + /* Start crypto ring, unconditionally */ + CLKMAN_CryptoClockEnable(1); + + /* If we find the dividers in anything other than off, don't touch them */ + if (CLKMAN_GetClkScale(CLKMAN_CRYPTO_CLK_MAA) == CLKMAN_SCALE_DISABLED) { + /* Div 1 mode */ + CLKMAN_SetClkScale(CLKMAN_CRYPTO_CLK_MAA, CLKMAN_SCALE_DIV_1); + } +} + +/******************************************************************************/ +uint32_t SYS_SRAM_GetSize(void) +{ + uint32_t memSize; + + /* Read TRIM value*/ + int SRAMtrim = (MXC_TRIM->reg10_mem_size & MXC_F_TRIM_REG10_MEM_SIZE_SRAM) >> MXC_F_TRIM_REG10_MEM_SIZE_SRAM_POS; + + /* Decode trim value into memory size in bytes */ + switch(SRAMtrim) { + case MXC_V_TRIM_REG10_MEM_SRAM_THREE_FOURTHS_SIZE: + memSize = (MXC_SRAM_FULL_MEM_SIZE >> 2) * 3; + break; + + case MXC_V_TRIM_REG10_MEM_SRAM_HALF_SIZE: + memSize = MXC_SRAM_FULL_MEM_SIZE >> 1; + break; + + default: /* other values are FULL size */ + memSize = MXC_SRAM_FULL_MEM_SIZE; + break; + } + + /* Returns size in bytes */ + return memSize; +} + +/******************************************************************************/ +uint32_t SYS_FLASH_GetSize(void) +{ + uint32_t memSize; + + /* Read TRIM value */ + int FLASHtrim = (MXC_TRIM->reg10_mem_size & MXC_F_TRIM_REG10_MEM_SIZE_FLASH) >> MXC_F_TRIM_REG10_MEM_SIZE_FLASH_POS; + + /* Decode trim value into memory size in bytes*/ + switch(FLASHtrim) { + case MXC_V_TRIM_REG10_MEM_FLASH_THREE_FOURTHS_SIZE: + memSize = (MXC_FLASH_FULL_MEM_SIZE >> 2) * 3; + break; + case MXC_V_TRIM_REG10_MEM_FLASH_HALF_SIZE: + memSize = (MXC_FLASH_FULL_MEM_SIZE >> 1); + break; + case MXC_V_TRIM_REG10_MEM_FLASH_THREE_EIGHTHS_SIZE: + memSize = (MXC_FLASH_FULL_MEM_SIZE >> 3) * 3; + break; + case MXC_V_TRIM_REG10_MEM_FLASH_FOURTH_SIZE: + memSize = (MXC_FLASH_FULL_MEM_SIZE >> 2); + break; + default: /* other values are FULL size */ + memSize = MXC_FLASH_FULL_MEM_SIZE; + break; + } + + /* Returns size in bytes */ + return memSize; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_sys.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_sys.h new file mode 100644 index 0000000..0a16ea1 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_sys.h @@ -0,0 +1,445 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-05-18 16:40:40 -0500 (Wed, 18 May 2016) $ + * $Revision: 22910 $ + * + ******************************************************************************/ + +/** + * @file mxc_sys.h + * @brief System level header file. + */ + +#ifndef _MXC_SYS_H_ +#define _MXC_SYS_H_ + +#include "mxc_config.h" +#include "clkman.h" +#include "ioman.h" +#include "gpio.h" +#include "i2cm_regs.h" +#include "i2cs_regs.h" +#include "tmr_regs.h" +#include "pt_regs.h" +#include "wdt_regs.h" +#include "owm_regs.h" +#include "spis_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/** @brief System Configuration Object */ +typedef struct { + clkman_scale_t clk_scale; /** desired clock scale value for the peripheral */ + ioman_cfg_t io_cfg; /** IOMAN configuration object */ +} sys_cfg_t; + +/** @brief Watchdog System Configuration Object */ +typedef struct { + clkman_wdt_clk_select_t clk; /** select the clock source for the watchdog */ + clkman_scale_t clk_scale; /** desired clock scale value for the peripheral */ + /** clk_scale is only applied if the system clock is used as the clk */ +} sys_cfg_wdt_t; + +/** @brief UART System Configuration Object */ +typedef sys_cfg_t sys_cfg_uart_t; + +/** @brief I2CM System Configuration Object */ +typedef sys_cfg_t sys_cfg_i2cm_t; + +/** @brief I2CS System Configuration Object */ +typedef sys_cfg_t sys_cfg_i2cs_t; + +/** @brief SPIM System Configuration Object */ +typedef sys_cfg_t sys_cfg_spim_t; + +/** @brief SPIX System Configuration Object */ +typedef sys_cfg_t sys_cfg_spix_t; + +/** @brief SPIS System Configuration Object */ +typedef sys_cfg_t sys_cfg_spis_t; + +/** @brief OWM System Configuration Object */ +typedef sys_cfg_t sys_cfg_owm_t; + +/** @brief Timer System Configuration Object */ +typedef gpio_cfg_t sys_cfg_tmr_t; + +/** @brief Pulse Train System Configuration Object */ +typedef gpio_cfg_t sys_cfg_pt_t; +typedef clkman_scale_t sys_pt_clk_scale; + +/***** Include Files *****/ +/* These includes require the above types to be defined first */ +#include "uart.h" +#include "spim.h" + +/***** Function Prototypes *****/ + +/** + * @brief Get the frequency of a clock scaler + * @param clk_scale value of clk_scale field from clk_ctrl register + * @returns frequency in Hz + */ +uint32_t SYS_GetFreq(uint32_t clk_scale); + +/** + * @brief Get the frequency of the CPU + * @returns frequency in Hz + */ +uint32_t SYS_CPU_GetFreq(void); + +/** + * @brief System level initialization for ADC module. + * @returns E_NO_ERROR if everything is successful + */ +int SYS_ADC_Init(void); + +/** + * @brief System level initialization for AES module. + * @returns E_NO_ERROR if everything is successful + */ +int SYS_AES_Init(void); + +/** + * @brief System level initialization for GPIO module. + * @returns E_NO_ERROR if everything is successful + */ +int SYS_GPIO_Init(void); + +/** + * @brief System level initialization for UART module. + * @param uart Pointer to UART module registers + * @param uart_cfg UART configuration object + * @param sys_cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *uart_cfg, const sys_cfg_uart_t *sys_cfg); + +/** + * @brief System level shutdown for UART module + * @param uart Pointer to UART module registers + * @returns E_NO_ERROR if everything is successful + */ +int SYS_UART_Shutdown(mxc_uart_regs_t *uart); + +/** + * @brief Get the frequency of the UART module source clock + * @param uart Pointer to UART module registers + * @returns frequency in Hz + */ +uint32_t SYS_UART_GetFreq(mxc_uart_regs_t *uart); + +/** + * @brief System level initialization for I2CM module. + * @param i2cm Pointer to I2CM module registers + * @param cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_I2CM_Init(mxc_i2cm_regs_t *i2cm, const sys_cfg_i2cm_t *cfg); + +/** + * @brief System level shutdown for I2CM module + * @param i2cm Pointer to I2CM module registers + * @returns E_NO_ERROR if everything is successful + */ +int SYS_I2CM_Shutdown(mxc_i2cm_regs_t *i2cm); + +/** + * @brief Get the frequency of the I2CM module source clock + * @param i2cm Pointer to I2CM module registers + * @returns frequency in Hz + */ +uint32_t SYS_I2CM_GetFreq(mxc_i2cm_regs_t *i2cm); + +/** + * @brief System level initialization for I2CS module. + * @param i2cs Pointer to I2CS module registers + * @param cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_I2CS_Init(mxc_i2cs_regs_t *i2cs, const sys_cfg_i2cs_t *cfg); + +/** + * @brief System level shutdown for I2CS module + * @param i2cs Pointer to I2CS module registers + * @returns E_NO_ERROR if everything is successful + */ +int SYS_I2CS_Shutdown(mxc_i2cs_regs_t *i2cs); + +/** + * @brief Get the frequency of the I2CS module source clock + * @param i2cs Pointer to I2CS module registers + * @returns frequency in Hz + */ +uint32_t SYS_I2CS_GetFreq(mxc_i2cs_regs_t *i2cs); + +/** + * @brief System level initialization for SPIM module. + * @param spim Pointer to SPIM module registers + * @param spim_cfg SPIM configuration object + * @param sys_cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_SPIM_Init(mxc_spim_regs_t *spim, const spim_cfg_t *spim_cfg, const sys_cfg_spim_t *sys_cfg); + +/** + * @brief System level shutdown for SPIM module + * @param spim Pointer to SPIM module registers + * @returns E_NO_ERROR if everything is successful + */ +int SYS_SPIM_Shutdown(mxc_spim_regs_t *spim); + +/** + * @brief Get the frequency of the SPIM module source clock + * @param spim Pointer to SPIM module registers + * @returns frequency in Hz + */ +uint32_t SYS_SPIM_GetFreq(mxc_spim_regs_t *spim); + +/** + * @brief System level initialization for SPIX module. + * @param sys_cfg System configuration object + * @param baud Baud rate for clock divider configuration + * @returns E_NO_ERROR if everything is successful + */ +int SYS_SPIX_Init(const sys_cfg_spix_t *sys_cfg, uint32_t baud); + +/** + * @brief System level shutdown for SPIX module + * @returns E_NO_ERROR if everything is successful + */ +int SYS_SPIX_Shutdown(void); + +/** + * @brief Get the frequency of the SPIX module source clock + * @returns frequency in Hz + */ +uint32_t SYS_SPIX_GetFreq(void); + +/** + * @brief System level initialization for SPIS module. + * @param sys_cfg System configuration object. + * @returns E_NO_ERROR if everything is successful. + */ +int SYS_SPIS_Init(const sys_cfg_spix_t *sys_cfg); + +/** + * @brief System level shutdown for SPIS module + * @returns E_NO_ERROR if everything is successful + */ +int SYS_SPIS_Shutdown(mxc_spis_regs_t *spis); + +/** + * @brief Get the frequency of the SPIS module source clock + * @returns frequency in Hz + */ +uint32_t SYS_SPIS_GetFreq(mxc_spis_regs_t *spis); + +/** + * @brief System level initialization for OWM module. + * @param owm Pointer to OWM module registers + * @param owm_cfg OWM configuration object + * @param sys_cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_OWM_Init(mxc_owm_regs_t *owm, const sys_cfg_owm_t *sys_cfg); + +/** + * @brief System level shutdown for OWM module + * @param owm Pointer to OWM module registers + * @returns E_NO_ERROR if everything is successful + */ +int SYS_OWM_Shutdown(mxc_owm_regs_t *owm); + +/** + * @brief Get the frequency of the OWM module source clock + * @param owm Pointer to OWM module registers + * @returns frequency in Hz + */ +uint32_t SYS_OWM_GetFreq(mxc_owm_regs_t *owm); + +/** + * @brief System level initialization for TMR module. + * @param tmr Pointer to TMR module registers + * @param cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_TMR_Init(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t *cfg); + +/** + * @brief Get the frequency of the TMR module source clock + * @param spim Pointer to TMR module registers + * @returns frequency in Hz + */ +uint32_t SYS_TMR_GetFreq(mxc_tmr_regs_t *tmr); + +/** + * @brief Get the frequency of the Pulse Train module source clock + * @returns frequency in Hz + */ +uint32_t SYS_PT_GetFreq(void); + +/** + * @brief Initialize the global pulse train clock scale + * @param clk_scale scale the system clock for the PT clock + */ +void SYS_PT_Init(sys_pt_clk_scale clk_scale); + +/** + * @brief System level initialization for Pulse Train module. + * @param pt Pointer to PT module registers + * @param cfg System configuration object + * @returns E_NO_ERROR if everything is successful + */ +int SYS_PT_Config(mxc_pt_regs_t *pt, const sys_cfg_pt_t *cfg); + +/** + * @brief System level initialization for USB device. + * @param enable 1 to enable the peripheral, 0 to disable. + */ +void SYS_USB_Enable(uint8_t enable); + +/** + * @brief System Tick Configuration Helper + * + * The function enables selection of the external clock source for the + * System Tick Timer. It initializes the System Timer and its interrupt, + * and starts the System Tick Timer. Counter is in free running mode to generate + * periodic interrupts. + + * @param ticks Number of ticks between two interrupts. + * @param clk_src Selects between default SystemClock or External Clock. + * - 0 Use external clock source + * - 1 SystemClock + * @return E_NO_ERROR Function succeeded. + * @return E_INVALID Invalid reload value requested. + * + * @see CLKMAN_SetRTOSMode(uint8_t enable) if using the external clock source to drive the System Tick Timer + * + */ +int SYS_SysTick_Config(uint32_t ticks, int clk_src); + +/** + * @brief Disable System Tick timer + * + * + */ +__STATIC_INLINE void SYS_SysTick_Disable(void) +{ + SysTick->CTRL = 0; +} + +/** + * @brief Delay a requested number of SysTick Timer Ticks. + * @param ticks Number of System Ticks to delay. + * @note This delay function is based on the clock used for the SysTick timer + * if the SysTick timer is enabled. If the SysTick timer is + * not enabled, the current SysTick registers are saved and the + * timer will use the SystemClock as the source for the delay. + * The delay is measured in clock ticks and is not based on the + * SysTick interval. + * @returns E_NO_ERROR if everything is successful + */ +int SYS_SysTick_Delay(uint32_t ticks); + +/** + * @brief Get the frequency of the SysTick Timer + * @returns frequency in Hz + */ +uint32_t SYS_SysTick_GetFreq(void); + +/** + * @brief Delay a requested number of microseconds. + * @param us Number of microseconds to delay. + * @note Calls SYS_SysTick_Delay. + */ +__STATIC_INLINE void SYS_SysTick_DelayUs(uint32_t us) +{ + SYS_SysTick_Delay((uint32_t)(((uint64_t)SYS_SysTick_GetFreq() * us) / 1000000)); +} + +/** + * @brief System level initialization for RTC module. + * @returns E_NO_ERROR if everything is successful + */ +int SYS_RTC_Init(void); + +/** + * @brief Select VDDIO for the specified GPIO pin. + */ +void SYS_IOMAN_UseVDDIO(const gpio_cfg_t *cfg); + +/** + * @brief Select VDDIOH for the specified GPIO pin. + */ +void SYS_IOMAN_UseVDDIOH(const gpio_cfg_t *cfg); + +/** + * @brief System level initialization for Watchdog module. + * @param wdt Pointer to Watchdog module registers + * @param cfg Watchdog System configuration object + */ +void SYS_WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg); + +/** + * @brief System level initialization for PRNG module. + * Enable crypto clock and set divisors to 1 if disabled + */ +void SYS_PRNG_Init(void); + +/** + * @brief System level initialization for MAA module. + * Enable crypto clock and set divisors to 1 if disabled + */ +void SYS_MAA_Init(void); + +/* + * @brief Gets the size of the SRAM + * @returns size of SRAM in bytes + */ +uint32_t SYS_SRAM_GetSize(void); + +/* + * @brief Gets the size of the Flash + * @returns size of Flash in bytes + */ +uint32_t SYS_FLASH_GetSize(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _MXC_SYS_H_*/ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/owm.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/owm.c new file mode 100644 index 0000000..7647ec7 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/owm.c @@ -0,0 +1,591 @@ +/** + * @file owm.c + * @brief 1-Wire Master (OWM) API Function Implementations. + */ +/* ***************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-14 10:08:53 -0500 (Mon, 14 Mar 2016) $ + * $Revision: 21855 $ + * + **************************************************************************** */ + +/* **** Includes **** */ +#include +#include "mxc_assert.h" +#include "mxc_sys.h" +#include "owm.h" + +/** + * @ingroup owm + * @{ + */ +///@cond +/* **** Definitions **** */ +#define OWM_CLK_FREQ 1000000 //1-Wire requires 1MHz clock + +/* **** Globals **** */ +int LastDiscrepancy; +int LastDeviceFlag; + +/* **** Functions **** */ +static uint8_t CalculateCRC8(uint8_t* data, int len); +static uint8_t update_crc8(uint8_t crc, uint8_t value); +///@endcond + + +/* ************************************************************************* */ +int OWM_Init(mxc_owm_regs_t *owm, const owm_cfg_t *cfg, const sys_cfg_owm_t *sys_cfg) +{ + int err = 0; + uint32_t owm_clk, clk_div = 0; + uint32_t ext_pu_mode = 0; + uint32_t ext_pu_polarity = 0; + + // Check the OWM register pointer is valid + MXC_ASSERT(MXC_OWM_GET_IDX(owm) >= 0); + + if(cfg == NULL) { + return E_NULL_PTR; + } + + // Set system level configurations + if ((err = SYS_OWM_Init(owm, sys_cfg)) != E_NO_ERROR) { + return err; + } + + // Configure clk divisor to get 1MHz OWM clk + owm_clk = SYS_OWM_GetFreq(owm); + + if(owm_clk == 0) { + return E_UNINITIALIZED; + } + + // Return error if clk doesn't divide evenly to 1MHz + if(owm_clk % OWM_CLK_FREQ) { + return E_NOT_SUPPORTED; + } + + clk_div = (owm_clk / (OWM_CLK_FREQ)); + + // Can not support lower frequencies + if(clk_div == 0) { + return E_NOT_SUPPORTED; + } + + // Select the PU mode and polarity based on cfg input + switch(cfg->ext_pu_mode) { + case OWM_EXT_PU_ACT_HIGH: + ext_pu_mode = MXC_V_OWM_CFG_EXT_PULLUP_MODE_USED; + ext_pu_polarity = MXC_V_OWM_CTRL_STAT_EXT_PULLUP_POL_ACT_HIGH; + break; + case OWM_EXT_PU_ACT_LOW: + ext_pu_mode = MXC_V_OWM_CFG_EXT_PULLUP_MODE_USED; + ext_pu_polarity = MXC_V_OWM_CTRL_STAT_EXT_PULLUP_POL_ACT_LOW; + break; + case OWM_EXT_PU_UNUSED: + ext_pu_mode = MXC_V_OWM_CFG_EXT_PULLUP_MODE_UNUSED; + ext_pu_polarity = MXC_V_OWM_CTRL_STAT_EXT_PULLUP_POL_ACT_HIGH; + break; + default: + return E_BAD_PARAM; + } + + // Set clk divisor + owm->clk_div_1us = (clk_div << MXC_F_OWM_CLK_DIV_1US_DIVISOR_POS) & MXC_F_OWM_CLK_DIV_1US_DIVISOR; + + // Set configuration + owm->cfg = (((cfg->int_pu_en << MXC_F_OWM_CFG_INT_PULLUP_ENABLE_POS) & MXC_F_OWM_CFG_INT_PULLUP_ENABLE) | + ((ext_pu_mode << MXC_F_OWM_CFG_EXT_PULLUP_MODE_POS) & MXC_F_OWM_CFG_EXT_PULLUP_MODE) | + ((cfg->long_line_mode << MXC_F_OWM_CFG_LONG_LINE_MODE) & MXC_F_OWM_CFG_LONG_LINE_MODE_POS)); + + owm->ctrl_stat = (((ext_pu_polarity << MXC_F_OWM_CTRL_STAT_EXT_PULLUP_POL_POS) & MXC_F_OWM_CTRL_STAT_EXT_PULLUP_POL) | + ((cfg->overdrive_spec << MXC_F_OWM_CTRL_STAT_OD_SPEC_MODE_POS) & MXC_F_OWM_CTRL_STAT_OD_SPEC_MODE)); + + // Clear all interrupt flags + owm->intfl = owm->intfl; + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int OWM_Shutdown(mxc_owm_regs_t *owm) +{ + int err; + + // Disable and clear interrupts + owm->inten = 0; + owm->intfl = owm->intfl; + + // Release IO pins and disable clk + if ((err = SYS_OWM_Shutdown(owm)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int OWM_Reset(mxc_owm_regs_t *owm) +{ + owm->intfl = MXC_F_OWM_INTFL_OW_RESET_DONE; // Clear the reset flag + owm->ctrl_stat |= MXC_F_OWM_CTRL_STAT_START_OW_RESET; // Generate a reset pulse + while((owm->intfl & MXC_F_OWM_INTFL_OW_RESET_DONE) == 0); // Wait for reset time slot to complete + + return (!!(owm->ctrl_stat & MXC_F_OWM_CTRL_STAT_PRESENCE_DETECT)); // Return presence pulse detect status +} + +/* ************************************************************************* */ +int OWM_TouchByte(mxc_owm_regs_t *owm, uint8_t data) +{ + owm->cfg &= ~MXC_F_OWM_CFG_SINGLE_BIT_MODE; // Set to 8 bit mode + owm->intfl = (MXC_F_OWM_INTFL_TX_DATA_EMPTY | MXC_F_OWM_INTFL_RX_DATA_READY); // Clear the flags + owm->data = (data << MXC_F_OWM_DATA_TX_RX_POS) & MXC_F_OWM_DATA_TX_RX; // Write data + while((owm->intfl & MXC_F_OWM_INTFL_TX_DATA_EMPTY) == 0); // Wait for data to be sent + while((owm->intfl & MXC_F_OWM_INTFL_RX_DATA_READY) == 0); // Wait for data to be read + + return (owm->data >> MXC_F_OWM_DATA_TX_RX_POS) & 0xFF; // Return the data read +} + +/* ************************************************************************* */ +int OWM_WriteByte(mxc_owm_regs_t *owm, uint8_t data) +{ + // Send one byte of data and verify the data sent = data parameter + return (OWM_TouchByte(owm, data) == data) ? E_NO_ERROR : E_COMM_ERR; +} + +/* ************************************************************************* */ +int OWM_ReadByte(mxc_owm_regs_t *owm) +{ + // Read one byte of data + return OWM_TouchByte(owm, 0xFF); +} + +/* ************************************************************************* */ +int OWM_TouchBit(mxc_owm_regs_t *owm, uint8_t bit) +{ + MXC_OWM->cfg |= MXC_F_OWM_CFG_SINGLE_BIT_MODE; // Set to 1 bit mode + owm->intfl = (MXC_F_OWM_INTFL_TX_DATA_EMPTY | MXC_F_OWM_INTFL_RX_DATA_READY); // Clear the flags + owm->data = (bit << MXC_F_OWM_DATA_TX_RX_POS) & MXC_F_OWM_DATA_TX_RX; // Write data + while((owm->intfl & MXC_F_OWM_INTFL_TX_DATA_EMPTY) == 0); // Wait for data to be sent + while((owm->intfl & MXC_F_OWM_INTFL_RX_DATA_READY) == 0); // Wait for data to be read + + return (owm->data >> MXC_F_OWM_DATA_TX_RX_POS) & 0x1; // Return the bit read +} + +/* ************************************************************************* */ +int OWM_WriteBit(mxc_owm_regs_t *owm, uint8_t bit) +{ + // Send a bit and verify the bit sent = bit parameter + return (OWM_TouchBit(owm, bit) == bit) ? E_NO_ERROR : E_COMM_ERR; +} + +/* ************************************************************************* */ +int OWM_ReadBit(mxc_owm_regs_t *owm) +{ + // Read a bit + return OWM_TouchBit(owm, 1); +} + +/* ************************************************************************* */ +int OWM_Write(mxc_owm_regs_t *owm, uint8_t* data, int len) +{ + int num = 0; + + owm->cfg &= ~MXC_F_OWM_CFG_SINGLE_BIT_MODE; // Set to 8 bit mode + + while(num < len) { // Loop for number of bytes to write + owm->intfl = (MXC_F_OWM_INTFL_TX_DATA_EMPTY | MXC_F_OWM_INTFL_RX_DATA_READY | MXC_F_OWM_INTEN_LINE_SHORT); // Clear the flags + owm->data = (data[num] << MXC_F_OWM_DATA_TX_RX_POS) & MXC_F_OWM_DATA_TX_RX; // Write data + while((owm->intfl & MXC_F_OWM_INTFL_TX_DATA_EMPTY) == 0); // Wait for data to be sent + while((owm->intfl & MXC_F_OWM_INTFL_RX_DATA_READY) == 0); // Wait for data to be read + + // Verify data sent is correct + if(owm->data != data[num]) { + return E_COMM_ERR; + } + + // Check error flag + if(owm->intfl & MXC_F_OWM_INTEN_LINE_SHORT) { + return E_COMM_ERR; // Wire was low before transaction + } + + num++; // Keep track of how many bytes written + } + + return num; // Return number of bytes written +} + +/* ************************************************************************* */ +int OWM_Read(mxc_owm_regs_t *owm, uint8_t* data, int len) +{ + int num = 0; + + owm->cfg &= ~MXC_F_OWM_CFG_SINGLE_BIT_MODE; // Set to 8 bit mode + + while(num < len) { // Loop for number of bytes to read + owm->intfl = (MXC_F_OWM_INTFL_TX_DATA_EMPTY | MXC_F_OWM_INTFL_RX_DATA_READY | MXC_F_OWM_INTEN_LINE_SHORT); // Clear the flags + owm->data = 0xFF; // Write 0xFF for a read + while((owm->intfl & MXC_F_OWM_INTFL_TX_DATA_EMPTY) == 0); // Wait for data to be sent + while((owm->intfl & MXC_F_OWM_INTFL_RX_DATA_READY) == 0); // Wait for data to be read + + // Check error flag + if(owm->intfl & MXC_F_OWM_INTEN_LINE_SHORT) { + return E_COMM_ERR; // Wire was low before transaction + } + + // Store read data into buffer + data[num] = (owm->data >> MXC_F_OWM_DATA_TX_RX_POS) & MXC_F_OWM_DATA_TX_RX; + + num++; // Keep track of how many bytes read + } + + return num; // Return number of bytes read +} + +/* ************************************************************************* */ +int OWM_ReadROM(mxc_owm_regs_t *owm, uint8_t* ROMCode) +{ + int num_read = 0; + + // Send reset and wait for presence pulse + if(OWM_Reset(owm)) { + // Send Read ROM command code + if(OWM_WriteByte(owm, READ_ROM_COMMAND) == E_NO_ERROR) { + // Read 8 bytes and store in buffer + num_read = OWM_Read(owm, ROMCode, 8); + + // Check the number of bytes read + if(num_read != 8) { + return E_COMM_ERR; + } + } else { + // Write failed + return E_COMM_ERR; + } + } else { + // No presence pulse + return E_COMM_ERR; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int OWM_MatchROM(mxc_owm_regs_t *owm, uint8_t* ROMCode) +{ + int num_wrote = 0; + + // Send reset and wait for presence pulse + if(OWM_Reset(owm)) { + // Send match ROM command code + if(OWM_WriteByte(owm, MATCH_ROM_COMMAND) == E_NO_ERROR) { + // Write 8 bytes in ROMCode buffer + num_wrote = OWM_Write(owm, ROMCode, 8); + + // Check the number of bytes written + if(num_wrote != 8) { + return E_COMM_ERR; + } + } else { + // Write failed + return E_COMM_ERR; + } + } else { + // No presence pulse + return E_COMM_ERR; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int OWM_ODMatchROM(mxc_owm_regs_t *owm, uint8_t* ROMCode) +{ + int num_wrote = 0; + + // Set to standard speed + owm->cfg &= ~(MXC_F_OWM_CFG_OVERDRIVE); + + // Send reset and wait for presence pulse + if(OWM_Reset(owm)) { + // Send Overdrive match ROM command code + if(OWM_WriteByte(owm, OD_MATCH_ROM_COMMAND) == E_NO_ERROR) { + // Set overdrive + owm->cfg |= MXC_F_OWM_CFG_OVERDRIVE; + + // Write 8 bytes in ROMCode buffer + num_wrote = OWM_Write(owm, ROMCode, 8); + + // Check the number of bytes written + if(num_wrote != 8) { + return E_COMM_ERR; + } + } else { + // Write failed + return E_COMM_ERR; + } + } else { + // No presence pulse + return E_COMM_ERR; + } + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +int OWM_SkipROM(mxc_owm_regs_t *owm) +{ + // Send reset and wait for presence pulse + if(OWM_Reset(owm)) { + // Send skip ROM command code + return OWM_WriteByte(owm, SKIP_ROM_COMMAND); + } else { + // No presence pulse + return E_COMM_ERR; + } +} + +/* ************************************************************************* */ +int OWM_ODSkipROM(mxc_owm_regs_t *owm) +{ + // Set to standard speed + owm->cfg &= ~(MXC_F_OWM_CFG_OVERDRIVE); + + // Send reset and wait for presence pulse + if(OWM_Reset(owm)) { + // Send Overdrive skip ROM command code + if(OWM_WriteByte(owm, OD_SKIP_ROM_COMMAND) == E_NO_ERROR) { + // Set overdrive speed + owm->cfg |= MXC_F_OWM_CFG_OVERDRIVE; + + return E_NO_ERROR; + } else { + // Write failed + return E_COMM_ERR; + } + } else { + // No presence pulse + return E_COMM_ERR; + } +} + +/* ************************************************************************* */ +int OWM_Resume(mxc_owm_regs_t *owm) +{ + // Send reset and wait for presence pulse + if(OWM_Reset(owm)) { + // Send resume command code + return OWM_WriteByte(owm, RESUME_COMMAND); + } else { + // No presence pulse + return E_COMM_ERR; + } +} + +/* ************************************************************************* */ +int OWM_SearchROM(mxc_owm_regs_t *owm, int newSearch, uint8_t* ROMCode) +{ + int nibble_start_bit = 1; + int rom_byte_number = 0; + uint8_t rom_nibble_mask = 0x0F; + uint8_t search_direction = 0; + int readValue = 0; + int sentBits = 0; + int discrepancy = 0; + int bit_position = 0; + int discrepancy_mask = 0; + int last_zero = 0; + uint8_t crc8 = 0; + int search_result = 0; + + // Clear ROM array + memset(ROMCode, 0x0, 8); + + if(newSearch) { + // Reset all global variables to start search from begining + LastDiscrepancy = 0; + LastDeviceFlag = 0; + } + + // Check if the last call was the last device + if(LastDeviceFlag) { + // Reset the search + LastDiscrepancy = 0; + LastDeviceFlag = 0; + return 0; + } + + // Send reset and wait for presence pulse + if (OWM_Reset(owm)) { + // Send the search command + OWM_WriteByte(owm, SEARCH_ROM_COMMAND); + + // Set search ROM accelerator bit + owm->ctrl_stat |= MXC_F_OWM_CTRL_STAT_SRA_MODE; + + // Loop until through all ROM bytes 0-7 (this loops 2 times per byte) + while(rom_byte_number < 8) { + // Each loop finds the discrepancy bits and finds 4 bits (nibble) of the ROM + + // Set the search direction the same as last time for the nibble masked + search_direction = ROMCode[rom_byte_number] & rom_nibble_mask; + + // If the upper nibble is the mask then shift bits to lower nibble + if(rom_nibble_mask > 0x0F) { + search_direction = search_direction >> 4; + } + + // Get the last discrepancy bit position relative to the nibble start bit + bit_position = LastDiscrepancy - nibble_start_bit; + + // Check if last discrepancy is witin this nibble + if( (bit_position >= 0) && (bit_position < 4) ) { + // Last discrepancy is within this nibble + // Set the bit of the last discrepancy bit + search_direction |= (1 << (bit_position)); + } + + // Performs two read bits and a write bit for 4 bits of the ROM + readValue = OWM_TouchByte(owm, search_direction); + // Get discrepancy flags + discrepancy = readValue & 0xF; + // Get the 4 bits sent to select the ROM + sentBits = (readValue >> 4) & 0xF; + + // Store the bit location of the MSB discrepancy with sentbit = 0 + if(discrepancy) { + // Initialize bit_position to MSB of nibble + bit_position = 3; + + while(bit_position >= 0) { + // Get discrepancy flag of the current bit position + discrepancy_mask = discrepancy & (1 << bit_position); + + // If there is a discrepancy and the sent bit is 0 save this bit position + if( (discrepancy_mask) && !(sentBits & discrepancy_mask)) { + last_zero = nibble_start_bit + bit_position; + break; + } + + bit_position--; + } + } + + // Clear the nibble + ROMCode[rom_byte_number] &= ~rom_nibble_mask; + + // Store the sentBits in the ROMCode + if(rom_nibble_mask > 0x0F) { + ROMCode[rom_byte_number] |= (sentBits << 4); + } else { + ROMCode[rom_byte_number] |= sentBits; + } + + // Increment the nibble start bit and shift mask + nibble_start_bit += 4; + rom_nibble_mask <<= 4; + + // If the mask is 0 then go to new ROM byte rom_byte_number and reset mask + if (rom_nibble_mask == 0) { + rom_byte_number++; + rom_nibble_mask = 0x0F; + } + + } // End while(rom_byte_number < 8) + + // Clear search ROM accelerator + owm->ctrl_stat &= ~(MXC_F_OWM_CTRL_STAT_SRA_MODE); + + // Calculate CRC to verify ROM code is correct + crc8 = CalculateCRC8(ROMCode, 7); + + // If the search was successful then + if ((nibble_start_bit >= 65) && (crc8 == ROMCode[7])) { + // Search successful so set LastDiscrepancy,LastDeviceFlag,search_result + LastDiscrepancy = last_zero; + + // Check for last device + if (LastDiscrepancy == 0) { + LastDeviceFlag = 1; + } + + search_result = 1; + } + } // End if (OWM_Reset) + + // If no device found then reset counters so next 'search' will be like a first + if (!search_result || !ROMCode[0]) { + LastDiscrepancy = 0; + LastDeviceFlag = 0; + search_result = 0; + } + + return search_result; +} + +/* + * Calcualate CRC8 of the buffer of data provided + */ +uint8_t CalculateCRC8(uint8_t* data, int len) +{ + int i; + uint8_t crc = 0; + + for(i = 0; i < len; i++) { + crc = update_crc8(crc, data[i]); + } + + return crc; +} + +/* + * Calculate the CRC8 of the byte value provided with the current crc value + * provided Returns updated crc value + */ +uint8_t update_crc8(uint8_t crc, uint8_t val) +{ + uint8_t inc, tmp; + + for (inc = 0; inc < 8; inc++) { + tmp = (uint8_t)(crc << 7); // Save X7 bit value + crc >>= 1; // Shift crc + if (((tmp >> 7) ^ (val & 0x01)) == 1) { // If X7 xor X8 (input data) + crc ^= 0x8c; // XOR crc with X4 and X5, X1 = X7^X8 + crc |= 0x80; // Carry + } + val >>= 1; + } + + return crc; +} + +/**@} end of group owm */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/owm.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/owm.h new file mode 100644 index 0000000..ea40b53 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/owm.h @@ -0,0 +1,320 @@ +/** + * @file owm.h + * @brief Registers, Bit Masks and Bit Positions for the 1-Wire Master + * peripheral module. + */ +/* **************************************************************************** +* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +* +* $Date: 2016-03-14 10:08:53 -0500 (Mon, 14 Mar 2016) $ +* $Revision: 21855 $ +* +**************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _OWM_H_ +#define _OWM_H_ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "mxc_sys.h" +#include "owm_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup owm 1-Wire Master (OWM) + * @ingroup periphlibs + * @{ + */ + +/* **** Definitions **** */ + +/** + * Enumeration type for 1-Wire Overdrive Speed Options. + */ +typedef enum { + OWM_OVERDRIVE_UNUSED = MXC_V_OWM_CTRL_STAT_OD_SPEC_MODE_12US, /**< 12us Overdrive Speed Select. */ + OWM_OVERDRIVE_12US = MXC_V_OWM_CTRL_STAT_OD_SPEC_MODE_12US, /**< 12us Overdrive Speed Select. */ + OWM_OVERDRIVE_10US = MXC_V_OWM_CTRL_STAT_OD_SPEC_MODE_10US /**< 10us Overdrive Speed Select. */ +} owm_overdrive_t; + +/** + * Enumeration type for specifying options for 1-Wire external pullup mode. + */ +typedef enum { + OWM_EXT_PU_ACT_HIGH = 0, /**< Pullup pin is active high when enabled. */ + OWM_EXT_PU_ACT_LOW = 1, /**< Pullup pin is active low when enabled. */ + OWM_EXT_PU_UNUSED = 2, /**< Pullup pin is not used for an external pullup. */ +} owm_ext_pu_t; + +/** + * Structure type for 1-Wire Master configuration. + */ +typedef struct { + uint8_t int_pu_en; /**< 1 = internal pullup on. */ + owm_ext_pu_t ext_pu_mode; /**< See #owm_ext_pu_t. */ + uint8_t long_line_mode; /**< 1 = long line mode enable. */ + owm_overdrive_t overdrive_spec; /**< 0 = timeslot is 12us, 1 = timeslot is 10us. */ +} owm_cfg_t; + + +#define READ_ROM_COMMAND 0x33 /**< Read ROM Command */ +#define MATCH_ROM_COMMAND 0x55 /**< Match ROM Command */ +#define SEARCH_ROM_COMMAND 0xF0 /**< Search ROM Command */ +#define SKIP_ROM_COMMAND 0xCC /**< Skip ROM Command */ +#define OD_SKIP_ROM_COMMAND 0x3C /**< Overdrive Skip ROM Command */ +#define OD_MATCH_ROM_COMMAND 0x69 /**< Overdrive Match ROM Command */ +#define RESUME_COMMAND 0xA5 /**< Resume Command */ + +/* **** Globals **** */ + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize and enable OWM module. + * @param owm Pointer to OWM regs. + * @param cfg Pointer to OWM configuration. + * @param sys_cfg Pointer to system configuration object + * + * @retval #E_NO_ERROR if everything is successful + * @retval #E_NULL_PTR if parameter is a null pointer + * @retval #E_BUSY if IOMAN was not configured correctly + * @retval #E_UNINITIALIZED if OWM CLK disabled + * @retval #E_NOT_SUPPORTED if 1MHz CLK cannot be created with given system and owm CLK + * @retval #E_BAD_PARAM if bad cfg parameter passed in + */ +int OWM_Init(mxc_owm_regs_t *owm, const owm_cfg_t *cfg, const sys_cfg_owm_t *sys_cfg); + +/** + * @brief Shutdown OWM module. + * @param owm Pointer to OWM regs. + * @retval #E_NO_ERROR if everything is successful + * @retval #E_BUSY if IOMAN was not released + */ +int OWM_Shutdown(mxc_owm_regs_t *owm); + +/** + * @brief Send 1-Wire reset pulse. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @retval (0) = no presence pulse detected, (1) = presence pulse detected + */ +int OWM_Reset(mxc_owm_regs_t *owm); + +/** + * @brief Send and receive one byte of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @param data data to send + * @retval data read (1 byte) + */ +int OWM_TouchByte(mxc_owm_regs_t *owm, uint8_t data); + +/** + * @brief Write one byte of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @param data data to send + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if data written != data parameter + */ +int OWM_WriteByte(mxc_owm_regs_t *owm, uint8_t data); + +/** + * @brief Read one byte of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @retval data read (1 byte) + */ +int OWM_ReadByte(mxc_owm_regs_t *owm); + +/** + * @brief Send and receive one bit of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @param bit bit to send + * @retval bit read + */ +int OWM_TouchBit(mxc_owm_regs_t *owm, uint8_t bit); + +/** + * @brief Write one bit of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @param bit bit to send + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if bit written != bit parameter + */ +int OWM_WriteBit(mxc_owm_regs_t *owm, uint8_t bit); + +/** + * @brief Read one bit of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @retval bit read + */ +int OWM_ReadBit(mxc_owm_regs_t *owm); + +/** + * @brief Write multiple bytes of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @param data Pointer to buffer for write data. + * @param len Number of bytes to write. + * + * @retval Number of bytes written if successful + * @retval #E_COMM_ERR if line short detected before transaction + */ +int OWM_Write(mxc_owm_regs_t *owm, uint8_t* data, int len); + +/** + * @brief Read multiple bytes of data. Will block until transaction is complete. + * @param owm Pointer to OWM regs. + * @param data Pointer to buffer for read data. + * @param len Number of bytes to read. + * + * @retval Number of bytes read if successful + * @retval #E_COMM_ERR if line short detected before transaction + */ +int OWM_Read(mxc_owm_regs_t *owm, uint8_t* data, int len); + +/** + * @brief Starts 1-Wire communication with Read ROM command + * @note Only use the Read ROM command with one slave on the bus + * @param owm Pointer to OWM regs. + * @param ROMCode Pointer to buffer for ROM code read + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if reset, read or write fails + */ +int OWM_ReadROM(mxc_owm_regs_t *owm, uint8_t* ROMCode); + +/** + * @brief Starts 1-Wire communication with Match ROM command + * @param owm Pointer to OWM regs. + * @param ROMCode Pointer to buffer with ROM code to match + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if reset or write fails + */ +int OWM_MatchROM(mxc_owm_regs_t *owm, uint8_t* ROMCode); + +/** + * @brief Starts 1-Wire communication with Overdrive Match ROM command + * @note After Overdrive Match ROM command is sent, the OWM is set to + * overdrive speed. To set back to standard speed use OWM_SetOverdrive. + * @param owm Pointer to OWM regs. + * @param ROMCode Pointer to buffer with ROM code to match + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if reset or write fails + */ +int OWM_ODMatchROM(mxc_owm_regs_t *owm, uint8_t* ROMCode); + +/** + * @brief Starts 1-Wire communication with Skip ROM command + * @param owm Pointer to OWM regs. + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if reset or write fails + */ +int OWM_SkipROM(mxc_owm_regs_t *owm); + +/** + * @brief Starts 1-Wire communication with Overdrive Skip ROM command + * @note After Overdrive Skip ROM command is sent, the OWM is set to + * overdrive speed. To set back to standard speed use OWM_SetOverdrive + * @param owm Pointer to OWM regs. + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if reset or write fails + */ +int OWM_ODSkipROM(mxc_owm_regs_t *owm); + +/** + * @brief Starts 1-Wire communication with Resume command + * @param owm Pointer to OWM regs. + * @retval #E_NO_ERROR if everything is successful + * @retval #E_COMM_ERR if reset or write fails + */ +int OWM_Resume(mxc_owm_regs_t *owm); + +/** + * @brief Starts 1-Wire communication with Search ROM command + * @param owm Pointer to OWM regs. + * @param newSearch (1) = start new search, (0) = continue search for next ROM + * @param ROMCode Pointer to buffer with ROM code found + * @retval (1) = ROM found, (0) = no new ROM found, end of search + */ +int OWM_SearchROM(mxc_owm_regs_t *owm, int newSearch, uint8_t* ROMCode); + +/** + * @brief Clear interrupt flags. + * @param owm Pointer to OWM regs. + * @param mask Mask of interrupts to clear. + */ +__STATIC_INLINE void OWM_ClearFlags(mxc_owm_regs_t *owm, uint32_t mask) +{ + owm->intfl = mask; +} + +/** + * @brief Get interrupt flags. + * @param owm Pointer to OWM regs. + * @retval Mask of active flags. + */ +__STATIC_INLINE unsigned OWM_GetFlags(mxc_owm_regs_t *owm) +{ + return (owm->intfl); +} + +/** + * @brief Enables/Disables the External pullup + * @param owm Pointer to OWM regs. + * @param enable (1) = enable, (0) = disable + */ +__STATIC_INLINE void OWM_SetExtPullup(mxc_owm_regs_t *owm, int enable) +{ + if(enable) + owm->cfg |= MXC_F_OWM_CFG_EXT_PULLUP_ENABLE; + else + owm->cfg &= ~(MXC_F_OWM_CFG_EXT_PULLUP_ENABLE); +} + +/** + * @brief Enables/Disables Overdrive speed + * @param owm Pointer to OWM regs. + * @param enable (1) = overdrive, (0) = standard + */ +__STATIC_INLINE void OWM_SetOverdrive(mxc_owm_regs_t *owm, int enable) +{ + if(enable) + owm->cfg |= MXC_F_OWM_CFG_OVERDRIVE; + else + owm->cfg &= ~(MXC_F_OWM_CFG_OVERDRIVE); +} + +/**@} end of group owm */ +#ifdef __cplusplus +} +#endif + +#endif /* _OWM_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pmu.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pmu.c new file mode 100644 index 0000000..8dbd616 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pmu.c @@ -0,0 +1,236 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-21 16:19:28 -0500 (Tue, 21 Jun 2016) $ + * $Revision: 23450 $ + * + ******************************************************************************/ + +#include +#include +#include "mxc_config.h" +#include "mxc_assert.h" +#include "pmu.h" + +#if (MXC_PMU_REV == 0) +/* MAX32630 A1 & A2 Erratum #6: PMU only supports channels 0-4 -- workaround */ +#include "clkman_regs.h" +/* Channel 5 infinite loop program */ +static const uint32_t pmu_0[] = { + PMU_JUMP(0, 0, (uint32_t)pmu_0) +}; +#endif + +static void (*callbacks[MXC_CFG_PMU_CHANNELS])(int); + + +/******************************************************************************/ +void PMU_Handler(void) +{ + int channel; + uint32_t cfg1, cfg2; + mxc_pmu_regs_t *MXC_PMUn; + + for (channel = 0; channel < MXC_CFG_PMU_CHANNELS; channel++) { + MXC_PMUn = &MXC_PMU0[channel]; + + if (MXC_PMUn->cfg & MXC_F_PMU_CFG_INTERRUPT) { + cfg1 = MXC_PMUn->cfg; + /* Since any set flags will be cleared by the write-back below, mask them off */ + cfg2 = cfg1 & ~(MXC_F_PMU_CFG_LL_STOPPED | MXC_F_PMU_CFG_BUS_ERROR | MXC_F_PMU_CFG_TO_STAT); + + /* Clear the interrupt flag */ + MXC_PMUn->cfg = cfg2 | MXC_F_PMU_CFG_INTERRUPT; + + if (callbacks[channel]) { + callbacks[channel](cfg1); + } + } + } +} + +/******************************************************************************/ +int PMU_Start(unsigned int channel, const void *program_address, pmu_callback callback) +{ + if(channel >= MXC_CFG_PMU_CHANNELS) + return E_BAD_PARAM; + + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + uint32_t cfg = MXC_PMUn->cfg; + + /* is this channel already running? */ + if (cfg & MXC_F_PMU_CFG_ENABLE) { + return E_BUSY; + } + +#if (MXC_PMU_REV == 0) + /* MAX32630 A1 & A2 Erratum #6: PMU only supports channels 0-4 */ + if (channel == 5) { + /* Channel 5 is used for the work-around */ + return E_BUSY; + } + /* Select always-ON clock for PMU */ + MXC_CLKMAN->clk_gate_ctrl0 |= MXC_F_CLKMAN_CLK_GATE_CTRL0_PMU_CLK_GATER; + /* Start channel 5 with infinite-loop program */ + MXC_PMU5->cfg &= ~MXC_F_PMU_CFG_ENABLE; /* Clear enable and wipe W1C flags */ + MXC_PMU5->dscadr = (uint32_t)pmu_0; + MXC_PMU5->cfg = MXC_F_PMU_CFG_ENABLE | (0x1c << MXC_F_PMU_CFG_BURST_SIZE_POS); +#endif + /* Set callback */ + callbacks[channel] = callback; + + /* Set start op-code */ + MXC_PMUn->dscadr = (uint32_t)program_address; + + /* Configure the channel */ + cfg = (cfg & ~(MXC_F_PMU_CFG_MANUAL | MXC_F_PMU_CFG_BURST_SIZE)) | (0x1c << MXC_F_PMU_CFG_BURST_SIZE_POS); + + /* Enable if necessary */ + if (callback) { + cfg |= MXC_F_PMU_CFG_INT_EN; + } else { + cfg &= ~MXC_F_PMU_CFG_INT_EN; + } + + /* Start the channel */ + cfg |= MXC_F_PMU_CFG_ENABLE; + + /*If any W1C flags are set, this write will clear them */ + MXC_PMUn->cfg = cfg; + + return E_NO_ERROR; +} + +/******************************************************************************/ +void PMU_Stop(unsigned int channel) +{ + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + uint32_t cfg = MXC_PMUn->cfg; + + /* Since any set flags will be cleared by the write-back below, mask them off */ + cfg &= ~(MXC_F_PMU_CFG_LL_STOPPED | MXC_F_PMU_CFG_BUS_ERROR | MXC_F_PMU_CFG_TO_STAT | MXC_F_PMU_CFG_INTERRUPT); + + /* Clear the enable bit to stop the channel */ + cfg &= ~MXC_F_PMU_CFG_ENABLE; + + MXC_PMUn->cfg = cfg; + + /* Remove callback */ + callbacks[channel] = NULL; + +#if (MXC_PMU_REV == 0) + /* MAX32630 A1 & A2 Erratum #6: PMU only supports channels 0-4 */ + /* Check channels 0-4 for any running channels. If none found, stop channel 5 */ + if ((MXC_PMU0->cfg & MXC_F_PMU_CFG_ENABLE) == 0 && + (MXC_PMU1->cfg & MXC_F_PMU_CFG_ENABLE) == 0 && + (MXC_PMU2->cfg & MXC_F_PMU_CFG_ENABLE) == 0 && + (MXC_PMU3->cfg & MXC_F_PMU_CFG_ENABLE) == 0 && + (MXC_PMU4->cfg & MXC_F_PMU_CFG_ENABLE) == 0) { + + MXC_PMU5->cfg &= ~MXC_F_PMU_CFG_ENABLE; + } +#endif + +} + +/******************************************************************************/ +int PMU_SetCounter(unsigned int channel, unsigned int counter, uint16_t value) +{ + if((channel >= MXC_CFG_PMU_CHANNELS) || counter > 1) + return E_BAD_PARAM; + + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + + if (counter == 0) { + MXC_PMUn->loop = (MXC_PMUn->loop & ~MXC_F_PMU_LOOP_COUNTER_0) | (value << MXC_F_PMU_LOOP_COUNTER_0_POS); + } else { + MXC_PMUn->loop = (MXC_PMUn->loop & ~MXC_F_PMU_LOOP_COUNTER_1) | (value << MXC_F_PMU_LOOP_COUNTER_1_POS); + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int PMU_SetTimeout(unsigned int channel, pmu_ps_sel_t timeoutClkScale, pmu_to_sel_t timeoutTicks) +{ + if(channel >= MXC_CFG_PMU_CHANNELS) + return E_BAD_PARAM; + + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + uint32_t cfg = MXC_PMUn->cfg; + + /* Since any set flags will be cleared by the write-back below, mask them off */ + cfg &= ~(MXC_F_PMU_CFG_LL_STOPPED | MXC_F_PMU_CFG_BUS_ERROR | MXC_F_PMU_CFG_TO_STAT | MXC_F_PMU_CFG_INTERRUPT); + + /* Adjust timeout settings */ + cfg &= ~(MXC_F_PMU_CFG_TO_SEL | MXC_F_PMU_CFG_PS_SEL); + cfg |= ((timeoutClkScale << MXC_F_PMU_CFG_PS_SEL_POS) & MXC_F_PMU_CFG_PS_SEL) | + ((timeoutTicks << MXC_F_PMU_CFG_TO_SEL_POS) & MXC_F_PMU_CFG_TO_SEL); + + MXC_PMUn->cfg = cfg; + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t PMU_GetFlags(unsigned int channel) +{ + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + uint32_t cfg = MXC_PMUn->cfg; + + /* Mask off configuration bits leaving only flag bits */ + cfg &= ~(MXC_F_PMU_CFG_ENABLE | MXC_F_PMU_CFG_MANUAL | MXC_F_PMU_CFG_TO_SEL | MXC_F_PMU_CFG_PS_SEL | + MXC_F_PMU_CFG_INT_EN | MXC_F_PMU_CFG_BURST_SIZE); + + return cfg; +} + +/******************************************************************************/ +void PMU_ClearFlags(unsigned int channel, unsigned int mask) +{ + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + uint32_t cfg = MXC_PMUn->cfg; + + /* Since any set flags will be cleared by the write-back below, mask them off */ + cfg &= ~(MXC_F_PMU_CFG_LL_STOPPED | MXC_F_PMU_CFG_BUS_ERROR | MXC_F_PMU_CFG_TO_STAT | MXC_F_PMU_CFG_INTERRUPT); + + /* Now, apply the caller-supplied bits to clear */ + cfg |= mask; + + MXC_PMUn->cfg = cfg; +} + +/******************************************************************************/ +uint32_t PMU_IsActive(unsigned int channel) +{ + mxc_pmu_regs_t *MXC_PMUn = &MXC_PMU0[channel]; + return (MXC_PMUn->cfg & MXC_F_PMU_CFG_ENABLE); +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pmu.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pmu.h new file mode 100644 index 0000000..41ac34b --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pmu.h @@ -0,0 +1,286 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-21 16:14:41 -0500 (Tue, 21 Jun 2016) $ + * $Revision: 23446 $ + * + ******************************************************************************/ + +/** + * @file pmu.h + * @addtogroup pmu Peripheral Management Unit + * @{ + * @brief This is the API for the peripheral management unit. + */ + +#ifndef _PMU_H_ +#define _PMU_H_ + +#include "pmu_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// @brief Defines Clock scale used for Timeout +typedef enum { + PMU_PS_SEL_DISABLE = MXC_V_PMU_CFG_PS_SEL_DISABLE, // Timeout disabled + PMU_PS_SEL_DIV_2_8 = MXC_V_PMU_CFG_PS_SEL_DIV_2_8, // Timeout clk = PMU clock / 2^8 = 256 + PMU_PS_SEL_DIV_2_16 = MXC_V_PMU_CFG_PS_SEL_DIV_2_16, // Timeout clk = PMU clock / 2^16 = 65536 + PMU_PS_SEL_DIV_2_24 = MXC_V_PMU_CFG_PS_SEL_DIV_2_24 // Timeout clk = PMU clock / 2^24 = 16777216 +}pmu_ps_sel_t; + +/// @brief Defines the number of clk ticks for timeout duration +typedef enum { + PMU_TO_SEL_TICKS_4 = MXC_V_PMU_CFG_TO_SEL_TICKS_4, //timeout = 4 * Timeout clk period + PMU_TO_SEL_TICKS_8 = MXC_V_PMU_CFG_TO_SEL_TICKS_8, //timeout = 8 * Timeout clk period + PMU_TO_SEL_TICKS_16 = MXC_V_PMU_CFG_TO_SEL_TICKS_16, //timeout = 16 * Timeout clk period + PMU_TO_SEL_TICKS_32 = MXC_V_PMU_CFG_TO_SEL_TICKS_32, //timeout = 32 * Timeout clk period + PMU_TO_SEL_TICKS_64 = MXC_V_PMU_CFG_TO_SEL_TICKS_64, //timeout = 64 * Timeout clk period + PMU_TO_SEL_TICKS_128 = MXC_V_PMU_CFG_TO_SEL_TICKS_128, //timeout = 128 * Timeout clk period + PMU_TO_SEL_TICKS_256 = MXC_V_PMU_CFG_TO_SEL_TICKS_256, //timeout = 256 * Timeout clk period + PMU_TO_SEL_TICKS_512 = MXC_V_PMU_CFG_TO_SEL_TICKS_512 //timeout = 512 * Timeout clk period +}pmu_to_sel_t; + + +/* The macros like the one below are designed to help build static PMU programs + * as arrays of 32bit words. + */ +#define PMU_IS(interrupt, stop) ((!!interrupt) << PMU_INT_POS) | ((!!stop) << PMU_STOP_POS) + +typedef struct pmu_move_des_t { + uint32_t op_code : 3; /* 0x0 */ + uint32_t interrupt : 1; + uint32_t stop : 1; + uint32_t read_size : 2; + uint32_t read_inc : 1; + uint32_t write_size : 2; + uint32_t write_inc : 1; + uint32_t cont : 1; + uint32_t length : 20; + + uint32_t write_address; + uint32_t read_address; +} pmu_move_des_t; +#define PMU_MOVE(i, s, rs, ri, ws, wi, c, length, wa, ra) \ + (PMU_MOVE_OP | PMU_IS(i,s) | ((rs & 3) << PMU_MOVE_READS_POS) | ((!!ri) << PMU_MOVE_READI_POS) | \ + ((ws & 3) << PMU_MOVE_WRITES_POS) | ((!!wi) << PMU_MOVE_WRITEI_POS) | ((!!c) << PMU_MOVE_CONT_POS) | ((length & 0xFFFFF) << PMU_MOVE_LEN_POS)), wa, ra + +/* new_value = value | (old_value & ~ mask) */ +typedef struct pmu_write_des_t { + uint32_t op_code : 3; /* 0x1 */ + uint32_t interrupt : 1; + uint32_t stop : 1; + uint32_t : 3; + uint32_t write_method : 4; + uint32_t : 20; + + uint32_t write_address; + uint32_t value; + uint32_t mask; +} pmu_write_des_t; +#define PMU_WRITE(i, s, wm, a, v, m) (PMU_WRITE_OP | PMU_IS(i,s) | ((wm & 0xF) << PMU_WRITE_METHOD_POS)), a, v, m + +typedef struct pmu_wait_des_t { + uint32_t op_code : 3; /* 0x2 */ + uint32_t interrupt : 1; + uint32_t stop : 1; + uint32_t wait : 1; + uint32_t sel : 1; + uint32_t : 25; + + uint32_t mask1; + uint32_t mask2; + uint32_t wait_count; +} pmu_wait_des_t; +#define PMU_WAIT(i, s, sel, m1, m2, cnt) (PMU_WAIT_OP | PMU_IS(i,s) | ((cnt>0)?(1<user_entropy & MXC_F_PRNG_USER_ENTROPY_RND_NUM_READY); +} + +/** + * @brief Retrieve a seed value from the PRNG + * @note The PRNG hardware does not produce true random numbers. The output + * should be used as a seed to an approved random-number algorithm, per + * a certifying authority such as NIST or PCI. The approved algorithm + * will output random numbers which are cerfitied for use in encryption + * and authentication algorithms. + * + * @return This function returns a 16-bit seed value + */ +__STATIC_INLINE uint16_t PRNG_GetSeed(void) +{ + return MXC_PRNG->rnd_num; +} + +/** + * @brief Add user entropy to the PRNG entropy source + * + * @param entropy This value will be mixed into the PRNG entropy source + */ +__STATIC_INLINE void PRNG_AddUserEntropy(uint8_t entropy) +{ + MXC_PRNG->user_entropy = (uint32_t)entropy; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _PRNG_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pt.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pt.c new file mode 100644 index 0000000..66c6a3a --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pt.c @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21839 $ + * + ******************************************************************************/ + +#include +#include "pt.h" + +/******************************************************************************/ +void PT_Init(sys_pt_clk_scale clk_scale) +{ + //disable all pulse trains + MXC_PTG->enable = 0; + + //clear all interrupts + MXC_PTG->intfl = MXC_PTG->intfl; + + SYS_PT_Init(clk_scale); +} + +/******************************************************************************/ +int PT_PTConfig(mxc_pt_regs_t *pt, pt_pt_cfg_t *cfg, const sys_cfg_pt_t *sysCfg) +{ + int err; + uint32_t ptClock; + uint32_t rate; + + //check for valid base pointer + MXC_ASSERT(MXC_PT_GET_IDX(pt) >= 0); + + if(cfg == NULL) + return E_NULL_PTR; + + if(cfg->bps == 0) + return E_BAD_PARAM; + + //disable pulse train + PT_Stop(pt); + + //setup system GPIO configuration + if((err = SYS_PT_Config(pt, sysCfg)) != E_NO_ERROR) + return err; + + //get PT clock frequency from SYS level + ptClock = SYS_PT_GetFreq(); + + if(ptClock == 0) + return E_UNINITIALIZED; + + if(ptClock < (cfg->bps)) + return E_BAD_STATE; + + rate = (ptClock / (cfg->bps)); + + pt->rate_length = ((rate << MXC_F_PT_RATE_LENGTH_RATE_CONTROL_POS) + & MXC_F_PT_RATE_LENGTH_RATE_CONTROL) | + ((cfg->ptLength << MXC_F_PT_RATE_LENGTH_MODE_POS) + & MXC_F_PT_RATE_LENGTH_MODE); + + pt->train = cfg->pattern; + pt->loop = ((cfg->loop << MXC_F_PT_LOOP_COUNT_POS) & MXC_F_PT_LOOP_COUNT) | + ((cfg->loopDelay << MXC_F_PT_LOOP_DELAY_POS) & MXC_F_PT_LOOP_DELAY); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int PT_SqrWaveConfig(mxc_pt_regs_t *pt, uint32_t freq, const sys_cfg_pt_t *sysCfg) +{ + int err; + uint32_t ptClock; + uint32_t rate; + + //check for valid base pointer + MXC_ASSERT(MXC_PT_GET_IDX(pt) >= 0); + + if(freq == 0) + return E_BAD_PARAM; + + //disable pulse train + PT_Stop(pt); + + //setup system GPIO configuration + if((err = SYS_PT_Config(pt, sysCfg)) != E_NO_ERROR) + return err; + + //get PT clock frequency from SYS level + ptClock = SYS_PT_GetFreq(); + + if(ptClock == 0) + return E_UNINITIALIZED; + + if(ptClock < (2*freq)) + return E_BAD_STATE; + + rate = (ptClock / (2*freq)) + 1; + + pt->rate_length = ((rate << MXC_F_PT_RATE_LENGTH_RATE_CONTROL_POS) + & MXC_F_PT_RATE_LENGTH_RATE_CONTROL) | + (MXC_V_PT_RATE_LENGTH_MODE_SQUARE_WAVE << MXC_F_PT_RATE_LENGTH_MODE_POS); + + return E_NO_ERROR; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pt.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pt.h new file mode 100644 index 0000000..a39d018 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/pt.h @@ -0,0 +1,313 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 14:44:55 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22017 $ + * + ******************************************************************************/ + +/** + * @file pt.h + * @addtogroup pt Pulse Train + * @brief This is the high level API for the pulse train module + * @{ + * + */ + +#ifndef _PT_H +#define _PT_H + +#include "mxc_config.h" +#include "pt_regs.h" +#include "mxc_assert.h" +#include "mxc_sys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// @struct pt_pt_cfg_t +/// Pulse train mode configuration structure. @note Do not use for square wave +typedef struct { + uint32_t bps; ///< pulse train bit rate + uint32_t pattern; ///< Output pattern to shift out, starts at LSB + uint8_t ptLength; ///< Number of bits in pulse train, 0 = 32bits, 1 = non valid , 2 = 2 bits, ... + uint16_t loop; ///< Number of times to repeat the train, 0 = continuous + uint16_t loopDelay; ///< Delay between loops specified in bits Example: loopDelay = 4, delays time = time it takes to shift out 4 bits +} pt_pt_cfg_t; + +/** + * @brief This function initializes pulse train modules to a known stopped state + * and sets the global PT clock scale + * @param clk_scale scale the system clock for the global PT clock + */ +void PT_Init(sys_pt_clk_scale clk_scale); + +/** + * @brief Configures the pulse train in the specified mode. + * @details The parameters in config structure must be set before calling this function. + * This function should be used for configuring pulse train mode only. + * @note The pulse train cannot be running when this function is called + * + * @param pt pulse train to operate on + * @param cfg pointer to pulse train configuration + * @param sysCfg pointer to pulse train system GPIO configuration + * + * @returns E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int PT_PTConfig(mxc_pt_regs_t *pt, pt_pt_cfg_t *cfg, const sys_cfg_pt_t *sysCfg); + +/** + * @brief Configures the pulse train in the square wave mode. + * @details This function should be used for configuring square wave mode only. + * @note The pulse train cannot be running when this function is called + * + * @param pt pulse train to operate on + * @param freq square wave output frequency in Hz + * @param sysCfg pointer to pulse train system GPIO configuration + * + * @returns E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int PT_SqrWaveConfig(mxc_pt_regs_t *pt, uint32_t freq, const sys_cfg_pt_t *sysCfg); + +/** + * @brief Starts the pulse train specified + * + * @param pt pulse train to operate on + */ +__STATIC_INLINE void PT_Start(mxc_pt_regs_t *pt) +{ + int ptIndex = MXC_PT_GET_IDX(pt); + + MXC_PTG->enable |= (1 << ptIndex); + + //wait for PT to start + while( (MXC_PTG->enable & (1 << ptIndex)) == 0 ); +} + +/** + * @brief Start multiple pulse train modules together. + * + * @param pts set the bits of pulse trains to start + * Bit0-\>pt0, Bit1-\>pt1... etc. + */ +__STATIC_INLINE void PT_StartMulti(uint32_t pts) +{ + MXC_PTG->enable |= pts; + + //wait for PTs to start + while( (MXC_PTG->enable & pts) != pts ); +} + +/** + * @brief Stops a pulse train + * + * @param pt pulse train to operate on + */ +__STATIC_INLINE void PT_Stop(mxc_pt_regs_t *pt) +{ + int ptIndex = MXC_PT_GET_IDX(pt); + + MXC_PTG->enable &= ~(1 << ptIndex); +} + +/** + * @brief Stop multiple pulse trains together + * + * @param pts set the bits of pulse trains to stop + * Bit0-\>pt0, Bit1-\>pt1... etc. + */ +__STATIC_INLINE void PT_StopMulti(uint32_t pts) +{ + MXC_PTG->enable &= ~(pts); +} + +/** + * @brief Determines if the pulse train is running + * + * @param pt pulse train to operate on + * + * @return 0 = pulse train is off, non-zero = pulse train is on + */ +__STATIC_INLINE uint32_t PT_IsActive(mxc_pt_regs_t *pt) +{ + int ptIndex = MXC_PT_GET_IDX(pt); + + return (!!(MXC_PTG->enable & (1 << ptIndex))); +} + +/** + * @brief Determines if the pulse trains selected are running + * + * @param pts set the bits of pulse trains to check + * Bit0-\>pt0, Bit1-\>pt1... etc. + * + * @return 0 = all pulse trains are off, non-zero = at least one pulse train is on + */ +__STATIC_INLINE uint32_t PT_IsActiveMulti(uint32_t pts) +{ + return (MXC_PTG->enable & pts); +} + +/** + * @brief Sets the pattern of the pulse train + * + * @param pt Pointer to pulse train to operate on + * @param pattern output pattern + * + */ +__STATIC_INLINE void PT_SetPattern(mxc_pt_regs_t *pt, uint32_t pattern) +{ + pt->train = pattern; +} + +/** + * @brief Enable pulse train interrupt + * + * @param pts Pointer to pulse train to operate on + */ +__STATIC_INLINE void PT_EnableINT(mxc_pt_regs_t *pt) +{ + int ptIndex = MXC_PT_GET_IDX(pt); + + MXC_PTG->inten |= (1 << ptIndex); +} + +/** + * @brief Enable interrupts for the pulse trains selected + * + * @param pts set the bits of pulse trains to enable + * Bit0-\>pt0, Bit1-\>pt1... etc. + */ +__STATIC_INLINE void PT_EnableINTMulti(uint32_t pts) +{ + MXC_PTG->inten |= pts; +} + +/** + * @brief Disable pulse train interrupt + * + * @param pts pulse train to operate on + */ +__STATIC_INLINE void PT_DisableINT(mxc_pt_regs_t *pt) +{ + int ptIndex = MXC_PT_GET_IDX(pt); + + MXC_PTG->inten &= ~(1 << ptIndex); +} + +/** + * @brief Disable interrupts for the pulse trains selected + * + * @param pts set the bits of pulse trains to enable + * Bit0-\>pt0, Bit1-\>pt1... etc. + */ +__STATIC_INLINE void PT_DisableINTMulti(uint32_t pts) +{ + MXC_PTG->inten &= ~pts; +} +/** + * @brief Gets the pulse trains's interrupt flags + * + * @return The Pulse Train Flags, bits that are 1 are set. + */ +__STATIC_INLINE uint32_t PT_GetFlags(void) +{ + return MXC_PTG->intfl; +} + +/** + * @brief Clears the pulse train's interrupt flag + * + * @param mask bits to clear + * + */ +__STATIC_INLINE void PT_ClearFlags(uint32_t mask) +{ + MXC_PTG->intfl = mask; +} + +/** + * @brief Setup and enables a pulse train to restart after another pulse train has exited its loop. + * Each pulse train can have up to two restart triggers. + * + * @param ptToRestart pulse train to restart after \a ptStop ends + * @param ptStop pulse train that stops and triggers \a ptToRestart to begin + * @param restartIndex selects which restart trigger to set (0 or 1) + */ +__STATIC_INLINE void PT_SetRestart(mxc_pt_regs_t *ptToRestart, mxc_pt_regs_t *ptStop, uint8_t restartIndex) +{ + int ptStopIndex = MXC_PT_GET_IDX(ptStop); + + MXC_ASSERT(ptStopIndex >= 0); + + if(restartIndex) { + ptToRestart->restart |= (ptStopIndex << MXC_F_PT_RESTART_PT_Y_SELECT_POS) | + MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT; + } else { + ptToRestart->restart |= (ptStopIndex << MXC_F_PT_RESTART_PT_X_SELECT_POS) | + MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT; + } +} + +/** + * @brief Disable the restart for the specified pulse train + * + * @param ptToRestart pulse train to disable the restart + * @param restartIndex selects which restart trigger to disable (0 or 1) + */ +__STATIC_INLINE void PT_RestartDisable(mxc_pt_regs_t *ptToRestart, uint8_t restartIndex) +{ + if(restartIndex) + ptToRestart->restart &= ~MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT; + else + ptToRestart->restart &= ~MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT; +} + +/** + * @brief Resynchronize individual pulse trains together. + * Resync will stop those resync_pts; others will be still running + * + * @param resyncPts pulse train modules that need to be re-synced by bit number. + * Bit0-\>pt0, Bit1-\>pt1... etc. + */ +__STATIC_INLINE void PT_Resync(uint32_t resyncPts) +{ + MXC_PTG->resync = resyncPts; + while(MXC_PTG->resync); +} + +/**@}*/ +#ifdef __cplusplus +} +#endif + +#endif /* _PT_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/rtc.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/rtc.c new file mode 100644 index 0000000..1b283b8 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/rtc.c @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-22 12:05:05 -0500 (Tue, 22 Mar 2016) $ + * $Revision: 22032 $ + * + ******************************************************************************/ +/** + * @file rtc.c + * @addtogroup rtc Real-time Clock + * @{ + * @brief This is the high level API for the real-time clock module + */ + +#include "rtc.h" +#include "mxc_assert.h" +#include "mxc_sys.h" +#include + +/******************************************************************************/ +int RTC_Init(const rtc_cfg_t *cfg) +{ + int err; + int i = 0; + + //init function -> validate configuration pointer is not NULL + if (cfg == NULL) + return E_NULL_PTR; + //check to make sure that the passed in parameters, prescaler mask and snooze, are valid + if ((cfg->prescalerMask > ((rtc_prescale_t)cfg->prescaler)) || (cfg->snoozeCount > MXC_F_RTC_SNZ_VAL_VALUE)) + return E_INVALID; + + // Set system level configurations + if ((err = SYS_RTC_Init()) != E_NO_ERROR) { + return err; + } + + //disable rtc + MXC_RTCTMR->ctrl &= ~(MXC_F_RTC_CTRL_ENABLE); + + //disable all interrupts + MXC_RTCTMR->inten = 0; + + //clear all interrupts + MXC_RTCTMR->flags = RTC_FLAGS_CLEAR_ALL; + + //reset starting count + MXC_RTCTMR->timer = 0; + + //set the compare registers to the values passed in + for(i = 0; i < RTC_NUM_COMPARE; i++) + MXC_RTCTMR->comp[i] = cfg->compareCount[i]; + + // set the prescaler + MXC_RTCTMR->prescale = cfg->prescaler; + // set the prescale mask, checked it for validity on entry + MXC_RTCTMR->prescale_mask = cfg->prescalerMask; + + //set snooze mode (rtc_snooze_t) + MXC_RTCTMR->ctrl &= (~MXC_F_RTC_CTRL_SNOOZE_ENABLE); + MXC_RTCTMR->ctrl |= (cfg->snoozeMode << MXC_F_RTC_CTRL_SNOOZE_ENABLE_POS); + + //set the snooze count. Checked for validity on entry. + MXC_RTCTMR->snz_val = (cfg->snoozeCount << MXC_F_RTC_SNZ_VAL_VALUE_POS) & MXC_F_RTC_SNZ_VAL_VALUE; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + + //reset trim to defaults, trim disabled, trim faster override disabled + MXC_RTCTMR->trim_ctrl &= ~(MXC_F_RTC_TRIM_CTRL_TRIM_ENABLE_R | MXC_F_RTC_TRIM_CTRL_TRIM_FASTER_OVR_R); + + //set trim slower control bit to 0, which is trim faster by default + MXC_RTCTMR->trim_value &= ~(MXC_F_RTC_TRIM_VALUE_TRIM_SLOWER_CONTROL); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int RTC_SetCompare(uint8_t compareIndex, uint32_t counts) +{ + //check for invalid index + if (compareIndex >= RTC_NUM_COMPARE) + return E_INVALID; + + MXC_RTCTMR->comp[compareIndex] = counts; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t RTC_GetCompare(uint8_t compareIndex) +{ + //Debug Assert for Invalid Index + MXC_ASSERT(compareIndex < RTC_NUM_COMPARE); + //check for invalid index + if (compareIndex >= RTC_NUM_COMPARE) + return (uint32_t)(E_BAD_PARAM); /* Unsigned int, so if out of bounds we return 0xFFFFFFFD (-3) */ + + return MXC_RTCTMR->comp[compareIndex]; +} + +/******************************************************************************/ +int RTC_SetTrim(uint32_t trim, uint8_t trimSlow) +{ + // make sure rtc is disabled + if(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_ENABLE) + return E_BAD_STATE; // RTC is active, bad state + + // Can check against this because it starts at bit 0 in the register + // Need to check because too large of a value messes with the upper bits in + // the trim register. + if (trim > MXC_F_RTC_TRIM_VALUE_TRIM_VALUE) + return E_INVALID; + + // write the trim to the hardware trim_value register + MXC_RTCTMR->trim_value = (trim << MXC_F_RTC_TRIM_VALUE_TRIM_VALUE_POS) & MXC_F_RTC_TRIM_VALUE_TRIM_VALUE; + + if(trimSlow) + MXC_RTCTMR->trim_value |= MXC_F_RTC_TRIM_VALUE_TRIM_SLOWER_CONTROL; + else + MXC_RTCTMR->trim_value &= ~MXC_F_RTC_TRIM_VALUE_TRIM_SLOWER_CONTROL; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + + return E_NO_ERROR; +} + +/******************************************************************************/ +uint32_t RTC_GetTrim() +{ + return MXC_RTCTMR->trim_value; // return the register value for trim +} + +/******************************************************************************/ +int RTC_TrimEnable(void) +{ + // make sure rtc is disabled + if(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_ENABLE) + return E_BAD_STATE; // RTC is active, bad state + + MXC_RTCTMR->trim_ctrl = MXC_F_RTC_TRIM_CTRL_TRIM_ENABLE_R; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + + return E_NO_ERROR; +} + +/******************************************************************************/ +void RTC_TrimDisable(void) +{ + // clear the trim enable bit + MXC_RTCTMR->trim_ctrl &= ~MXC_F_RTC_TRIM_CTRL_TRIM_ENABLE_R; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + + return; +} + +/** + * @} + */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/rtc.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/rtc.h new file mode 100644 index 0000000..d61e408 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/rtc.h @@ -0,0 +1,446 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 10:05:23 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22008 $ + * + ******************************************************************************/ + +/** + * @file rtc.h + * @addtogroup rtc Real-time Clock + * @{ + * @brief This is the high level API for the real-time clock module + */ + +#ifndef _RTC_H +#define _RTC_H + +#include "mxc_config.h" +#include "rtc_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// @enum rtc_prescale_t Defines clock divider for 4096Hz input clock. +typedef enum { + RTC_PRESCALE_DIV_2_0 = MXC_V_RTC_PRESCALE_DIV_2_0, ///< (4.096kHz) divide input clock by \f$ 2^{0} = 1 \f$ (0x001) + RTC_PRESCALE_DIV_2_1 = MXC_V_RTC_PRESCALE_DIV_2_1, ///< (2.048kHz) divide input clock by \f$ 2^{1} = 2 \f$ (0x002) + RTC_PRESCALE_DIV_2_2 = MXC_V_RTC_PRESCALE_DIV_2_2, ///< (1.024kHz) divide input clock by \f$ 2^{2} = 4 \f$ + RTC_PRESCALE_DIV_2_3 = MXC_V_RTC_PRESCALE_DIV_2_3, ///< (512Hz) divide input clock by \f$ 2^{3} = 8 \f$ + RTC_PRESCALE_DIV_2_4 = MXC_V_RTC_PRESCALE_DIV_2_4, ///< (256Hz) divide input clock by \f$ 2^{4} = 16 \f$ + RTC_PRESCALE_DIV_2_5 = MXC_V_RTC_PRESCALE_DIV_2_5, ///< (128Hz) divide input clock by \f$ 2^{5} = 32 \f$ + RTC_PRESCALE_DIV_2_6 = MXC_V_RTC_PRESCALE_DIV_2_6, ///< (64Hz) divide input clock by \f$ 2^{6} = 64 \f$ + RTC_PRESCALE_DIV_2_7 = MXC_V_RTC_PRESCALE_DIV_2_7, ///< (32Hz) divide input clock by \f$ 2^{7} = 128 \f$ + RTC_PRESCALE_DIV_2_8 = MXC_V_RTC_PRESCALE_DIV_2_8, ///< (16Hz) divide input clock by \f$ 2^{8} = 256 \f$ + RTC_PRESCALE_DIV_2_9 = MXC_V_RTC_PRESCALE_DIV_2_9, ///< (8Hz) divide input clock by \f$ 2^{9} = 512 \f$ + RTC_PRESCALE_DIV_2_10 = MXC_V_RTC_PRESCALE_DIV_2_10, ///< (4Hz) divide input clock by \f$ 2^{10} = 1024 \f$ + RTC_PRESCALE_DIV_2_11 = MXC_V_RTC_PRESCALE_DIV_2_11, ///< (2Hz) divide input clock by \f$ 2^{11} = 2048 \f$ (0x07FF) + RTC_PRESCALE_DIV_2_12 = MXC_V_RTC_PRESCALE_DIV_2_12, ///< (1Hz) divide input clock by \f$ 2^{12} = 4096 \f$ (0x0FFF) +} rtc_prescale_t; + +/// @def RTC_CTRL_ACTIVE_TRANS Active Transaction Flags for the RTC +#define RTC_CTRL_ACTIVE_TRANS (MXC_F_RTC_CTRL_RTC_ENABLE_ACTIVE | \ + MXC_F_RTC_CTRL_OSC_GOTO_LOW_ACTIVE | \ + MXC_F_RTC_CTRL_OSC_FRCE_SM_EN_ACTIVE | \ + MXC_F_RTC_CTRL_OSC_FRCE_ST_ACTIVE | \ + MXC_F_RTC_CTRL_RTC_SET_ACTIVE | \ + MXC_F_RTC_CTRL_RTC_CLR_ACTIVE | \ + MXC_F_RTC_CTRL_ROLLOVER_CLR_ACTIVE | \ + MXC_F_RTC_CTRL_PRESCALE_CMPR0_ACTIVE | \ + MXC_F_RTC_CTRL_PRESCALE_UPDATE_ACTIVE | \ + MXC_F_RTC_CTRL_CMPR1_CLR_ACTIVE | \ + MXC_F_RTC_CTRL_CMPR0_CLR_ACTIVE | \ + MXC_F_RTC_CTRL_TRIM_ENABLE_ACTIVE | \ + MXC_F_RTC_CTRL_TRIM_SLOWER_ACTIVE | \ + MXC_F_RTC_CTRL_TRIM_CLR_ACTIVE | \ + MXC_F_RTC_CTRL_ACTIVE_TRANS_0) + +/// @def RTC_FLAGS_CLEAR_ALL Number of RTC compare registers +#define RTC_FLAGS_CLEAR_ALL (MXC_F_RTC_FLAGS_COMP0 | \ + MXC_F_RTC_FLAGS_COMP1| \ + MXC_F_RTC_FLAGS_PRESCALE_COMP | \ + MXC_F_RTC_FLAGS_OVERFLOW | \ + MXC_F_RTC_FLAGS_TRIM) +/// @enum rtc_snooze_t Defines the snooze modes +typedef enum { + RTC_SNOOZE_DISABLE = MXC_V_RTC_CTRL_SNOOZE_DISABLE, ///< Snooze Mode Disabled + RTC_SNOOZE_MODE_A = MXC_V_RTC_CTRL_SNOOZE_MODE_A, ///< COMP1 = COMP1 + RTC_SNZ_VALUE when snooze flag is set + RTC_SNOOZE_MODE_B = MXC_V_RTC_CTRL_SNOOZE_MODE_B, ///< COMP1 = RTC_TIMER + RTC_SNZ_VALUE when snooze flag is set +} rtc_snooze_t; /// Defines the snooze modes + +/// @def RTC_NUM_COMPARE Number of RTC compare registers +#define RTC_NUM_COMPARE 2 + +/// @brief A structure that represents the configuration of the RTC peripheral +typedef struct { + rtc_prescale_t prescaler; /// prescale value rtc_prescale_t + rtc_prescale_t prescalerMask; /// Mask value used to compare to the rtc prescale value, when the \f$ \big((Count_{prescaler}\,\&\,Prescale\,Mask) == 0\big) \f$, the prescale compare flag will be set. + uint32_t compareCount[RTC_NUM_COMPARE]; /// Values used for the RTC alarms. See RTC_SetCompare() and RTC_GetCompare() + uint32_t snoozeCount; /// The number of RTC ticks to snooze if enabled. + rtc_snooze_t snoozeMode; /// The desired snooze mode +} rtc_cfg_t; + +/** + * @brief Initializes the RTC + * @note Must setup clocking and power prior to this function. + * + * @param cfg configuration + * + * @retval E_NO_ERROR if everything is successful + * @retval E_NULL_PTR if cfg pointer is NULL + * @retval E_INVALID if comparison index, prescaler mask or snooze mask are + * out of bounds + */ +int RTC_Init(const rtc_cfg_t *cfg); + +/** + * @brief Enable and start the real-time clock continuing from its current value + */ +__STATIC_INLINE void RTC_Start(void) +{ + MXC_RTCTMR->ctrl |= MXC_F_RTC_CTRL_ENABLE; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Disable and stop the real-time clock + */ +__STATIC_INLINE void RTC_Stop(void) +{ + MXC_RTCTMR->ctrl &= ~(MXC_F_RTC_CTRL_ENABLE); + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Determines if the RTC is running or not. + * + * @retval 0 if Disabled, Non-zero if Active + */ +__STATIC_INLINE uint32_t RTC_IsActive(void) +{ + return (MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_ENABLE); +} + +/** + * @brief Set the current count of the RTC + * + * @param count count value to set current real-time count. + */ +__STATIC_INLINE void RTC_SetCount(uint32_t count) +{ + MXC_RTCTMR->timer = count; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Get the current timer value of the RTC. + * + * @retval The value of the RTC counter. + */ +__STATIC_INLINE uint32_t RTC_GetCount(void) +{ + return (MXC_RTCTMR->timer); +} + +/** + * @brief Set the comparator value + * + * @param compareIndex Index of comparator to set, see RTC_NUM_COMPARE + * for the total number of compare registers available. + * @param counts Unsigned 32-bit compare value to set. + * @retval E_NO_ERROR Compare count register set successfully for requested + * comparator. + * @retval E_INVALID compareIndex is \>= RTC_NUM_COMPARE. + */ +int RTC_SetCompare(uint8_t compareIndex, uint32_t counts); + +/** + * @brief Get the comparator value + * + * @param compareIndex Index of the comparator to get. See RTC_NUM_COMPARE + * for the total number of compare registers available. + * + * @retval uint32_t The current value of the specified compare register for the RTC + */ +uint32_t RTC_GetCompare(uint8_t compareIndex); + +/** + * @brief Set the prescale reload value for the real-time clock. + * @details The prescale reload value determines the number of 4kHz ticks + * occur before the timer is incremented. See @ref prescaler_val "Table" + * for accepted values and corresponding timer resolution. + * + * + * + *
Prescaler Settings and Corresponding RTC Resolutions
PRESCALE Prescale Reload 4kHz ticks in LSB Min Timer Value (sec) Max Timer Value (sec) Max Timer Value (Days) Max Timer Value (Years) + *
0h RTC_PRESCALE_DIV_2_0 1 0.00024 1048576 12 0.0 + *
1h RTC_PRESCALE_DIV_2_1 2 0.00049 2097152 24 0.1 + *
2h RTC_PRESCALE_DIV_2_2 4 0.00098 4194304 49 0.1 + *
3h RTC_PRESCALE_DIV_2_3 8 0.00195 8388608 97 0.3 + *
4h RTC_PRESCALE_DIV_2_4 16 0.00391 16777216 194 0.5 + *
5h RTC_PRESCALE_DIV_2_5 32 0.00781 33554432 388 1.1 + *
6h RTC_PRESCALE_DIV_2_6 64 0.01563 67108864 777 2.2 + *
7h RTC_PRESCALE_DIV_2_7 128 0.03125 134217728 1553 4.4 + *
8h RTC_PRESCALE_DIV_2_8 256 0.06250 268435456 3107 8.7 + *
9h RTC_PRESCALE_DIV_2_9 512 0.12500 536870912 6214 17.5 + *
Ah RTC_PRESCALE_DIV_2_10 1024 0.25000 1073741824 12428 34.9 + *
Bh RTC_PRESCALE_DIV_2_11 2048 0.50000 2147483648 24855 69.8 + *
Ch RTC_PRESCALE_DIV_2_12 4096 1.00000 4294967296 49710 139.6 + *
+ * + * @param prescaler Prescale value to set, see rtc_prescale_t. + */ +__STATIC_INLINE void RTC_SetPrescaler(rtc_prescale_t prescaler) +{ + MXC_RTCTMR->prescale = prescaler; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Get the current value of the real-time clock prescaler. + * + * @retval rtc_prescale_t Returns the current RTC prescaler setting, + * See rtc_prescale_t for values of the prescaler. + */ +__STATIC_INLINE rtc_prescale_t RTC_GetPrescaler(void) +{ + return (rtc_prescale_t)(MXC_RTCTMR->prescale); +} + +/** + * @brief Set the prescaler mask, which is used to set the RTC prescale counter + * compare flag when the prescaler timer matches the bits indicated + * by the mask. + * @param mask A bit mask that is used to set the prescale compare flag if the + * prescale timer has the corresponding bits set. @note This mask must + * be less than or equal to the prescaler reload value. + * See RTC_SetPrescaler() + * @details When \f$ \big((Count_{prescaler}\,\&\,Prescale\,Mask) == 0\big) \f$, the prescale compare flag is set + * @retval int Returns E_NO_ERROR if prescale value is valid and is set. + * @retval int Returns E_INVALID if mask is \> than prescaler value + */ +__STATIC_INLINE int RTC_SetPrescalerMask(rtc_prescale_t mask) +{ + if (mask > ((rtc_prescale_t)(MXC_RTCTMR->prescale))) { + return E_INVALID; + } + MXC_RTCTMR->prescale_mask = mask; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + return E_NO_ERROR; +} + +/** + * @brief Set the number of ticks for snooze mode. See RTC_Snooze(). + * @param count Sets the count used for snoozing when snooze mode is enabled and + * the snooze flag is set. + * @retval E_NO_ERROR If snooze value is set correctly and value is valid. + * @retval E_INVALID If SnoozeCount exceeds maximum supported, see MXC_F_RTC_SNZ_VAL_VALUE + * + */ +__STATIC_INLINE int RTC_SetSnoozeCount(uint32_t count) +{ + // Check to make sure max value is not being exceeded + if (count > MXC_F_RTC_SNZ_VAL_VALUE) + return E_INVALID; + + MXC_RTCTMR->snz_val = count; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); + return E_NO_ERROR; +} + +/** + * @brief Gets the Snooze Count that is currently loaded in the RTC timer + * @details Returns the current value for the Snooze. This value is used as + * part of the snooze calculation depending on the snooze mode. @see RTC_SetSnoozeMode + * @retval uint32_t value of the snooze register + * + */ +__STATIC_INLINE uint32_t RTC_GetSnoozeCount(void) +{ + return MXC_RTCTMR->snz_val; +} + +/** + * @brief Set the flags to activate the snooze + * @details Begins a snooze of the RTC. When this function is called + * the snooze count is determined based on the snooze mode. + * See RTC_GetCount() and RTC_SetSnoozeMode() + */ +__STATIC_INLINE void RTC_Snooze(void) +{ + MXC_RTCTMR->flags = MXC_F_RTC_FLAGS_SNOOZE_A | MXC_F_RTC_FLAGS_SNOOZE_B; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Sets the Snooze Mode. + * @details + * + *
Snooze Modes
ModeSnooze Time Calculation + *
RTC_SNOOZE_DISABLESnooze Disabled + *
RTC_SNOOZE_MODE_A\f$ compare1 = compare1 + snoozeCount \f$ + *
RTC_SNOOZE_MODE_B\f$ compare1 = count + snoozeCount \f$ + *
+ * \a count is the value of the RTC counter when RTC_Snooze() is called to begin snooze + */ +__STATIC_INLINE void RTC_SetSnoozeMode(rtc_snooze_t mode) +{ + uint32_t ctrl; + // Get the control register and mask off the non-snooze bits + ctrl = (MXC_RTCTMR->ctrl & ~(MXC_F_RTC_CTRL_SNOOZE_ENABLE)); + // set the requested snooze mode bits and save the settings + MXC_RTCTMR->ctrl = (ctrl | (mode << MXC_F_RTC_CTRL_SNOOZE_ENABLE_POS)); + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Enables the interrupts defined by the mask for the RTC. + * @details + * + *
RTC Interrupts
InterruptMask + *
Compare 0MXC_F_RTC_INTEN_COMP0 + *
Compare 1 \\ SnoozeMXC_F_RTC_INTEN_COMP1 + *
Prescale CompMXC_F_RTC_FLAGS_INTEN_COMP + *
RTC Count OverflowMXC_F_RTC_INTEN_OVERFLOW + *
TrimMXC_F_RTC_INTEN_TRIM + *
+ * @param mask set the bits of the interrupts to enable + */ +__STATIC_INLINE void RTC_EnableINT(uint32_t mask) +{ + MXC_RTCTMR->inten |= mask; +} + +/** + * @brief Disable RTC interrupts based on the mask, See @ref RTC_interrupts + * + * @param mask set the bits of the interrupts to disable + */ +__STATIC_INLINE void RTC_DisableINT(uint32_t mask) +{ + MXC_RTCTMR->inten &= ~mask; +} + +/** + * @brief Gets the RTC's interrupt flags + * + * @retval uint32_t interrupt flags + */ +__STATIC_INLINE uint32_t RTC_GetFlags(void) +{ + return (MXC_RTCTMR->flags); +} + +/** + * @brief Clears the RTC's interrupt flags based on the mask provided + * + * @param mask masked used to clear individual interrupt flags + */ +__STATIC_INLINE void RTC_ClearFlags(uint32_t mask) +{ + MXC_RTCTMR->flags = mask; + + //wait for pending actions to complete + while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +/** + * @brief Gets the active transaction flags + * + * @retval 0 = no active transactions , nonzero = active transactions bits + */ +__STATIC_INLINE uint32_t RTC_GetActiveTrans(void) +{ + return (MXC_RTCTMR->ctrl & RTC_CTRL_ACTIVE_TRANS); +} + +/** + * @brief Sets the trim value and trim slow/fast option + * @note Ensure RTC is disabled prior to calling this function + * + * @param trim trim value - maximum trim value setting of 0x03FFFF + * @param trimSlow 1 = trim slow, 0 = trim fast + * + * @retval E_NO_ERROR Trim value is valid and set. + * @retval E_INVALID Trim value exceeds max trim. + * @retval E_BAD_STATE RTC is not disabled. + * + */ +int RTC_SetTrim(uint32_t trim, uint8_t trimSlow); + +/** + * @brief Gets the trim value currently set + * @note Ensure RTC is disabled prior to calling this function + * + * @retval uint32_t Current trim value of RTC. + */ +uint32_t RTC_GetTrim(void); + +/** + * @brief Enabled the trim. + * @note Ensure RTC is disabled prior to calling this function + * @retval E_NO_ERROR Trim enabled + * @retval E_INVALID + */ +int RTC_TrimEnable(void); + +/** + * @brief Disable the trim. + */ +void RTC_TrimDisable(void); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* _RTC_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spim.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spim.c new file mode 100644 index 0000000..a132752 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spim.c @@ -0,0 +1,720 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-07-26 08:41:27 -0500 (Tue, 26 Jul 2016) $ + * $Revision: 23789 $ + * + ******************************************************************************/ + +/** + * @file spim.c + * @brief SPI Master driver source. + */ + +/***** Includes *****/ +#include +#include +#include "mxc_config.h" +#include "mxc_assert.h" +#include "mxc_lock.h" +#include "spim.h" + +/***** Definitions *****/ +#define SPIM_MAX_BYTE_LEN 32 +#define SPIM_MAX_PAGE_LEN 32 + +/***** Globals *****/ + +// Saves the state of the non-blocking requests +typedef struct { + spim_req_t *req; + unsigned head_rem; +} spim_req_head_t; + +static spim_req_head_t states[MXC_CFG_SPIM_INSTANCES]; + +/***** Functions *****/ + +static unsigned SPIM_ReadRXFIFO(mxc_spim_regs_t *spim, mxc_spim_fifo_regs_t *fifo, + uint8_t *data, unsigned len); + +static uint32_t SPIM_TransHandler(mxc_spim_regs_t *spim, spim_req_t *req, int spim_num); + +/******************************************************************************/ +int SPIM_Init(mxc_spim_regs_t *spim, const spim_cfg_t *cfg, const sys_cfg_spim_t *sys_cfg) +{ + int err, spim_num; + uint32_t spim_clk, clocks; + + spim_num = MXC_SPIM_GET_IDX(spim); + MXC_ASSERT(spim_num >= 0); + + // Check the input parameters + if(cfg == NULL) + return E_NULL_PTR; + + if(cfg->baud == 0) + return E_BAD_PARAM; + + // Set system level configurations + if ((err = SYS_SPIM_Init(spim, cfg, sys_cfg)) != E_NO_ERROR) { + return err; + } + + /* Configure the baud, make sure the SPIM clk is enabled and the baud + is less than the maximum */ + spim_clk = SYS_SPIM_GetFreq(spim); + if((spim_clk == 0) || ((spim_clk == SystemCoreClock) && ((spim_clk/2) < cfg->baud))) { + return E_BAD_PARAM; + } + + // Initialize state pointers + states[spim_num].req = NULL; + states[spim_num].head_rem = 0; + + // Drain the FIFOs, enable SPIM, enable SCK Feedback + spim->gen_ctrl = 0; + spim->gen_ctrl = (MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN | MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN | + MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN | MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE); + + // Set mode and page size + spim->mstr_cfg = (((cfg->mode << MXC_F_SPIM_MSTR_CFG_SPI_MODE_POS) & MXC_F_SPIM_MSTR_CFG_SPI_MODE) | + MXC_S_SPIM_MSTR_CFG_PAGE_32B | (0x2 << MXC_F_SPIM_MSTR_CFG_ACT_DELAY_POS)); + + // Configure the SSEL polarity + spim->ss_sr_polarity = ((cfg->ssel_pol << MXC_F_SPIM_SS_SR_POLARITY_SS_POLARITY_POS) & + MXC_F_SPIM_SS_SR_POLARITY_SS_POLARITY); + +#if(MXC_SPIM_REV == 0) + // Disable the feedback clock in modes 1 and 2 + if((cfg->mode == 1) || (cfg->mode == 2)) { + spim->gen_ctrl &= ~MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE; + spim->mstr_cfg |= (0x1 << MXC_F_SPIM_MSTR_CFG_SDIO_SAMPLE_POINT_POS); + } +#else + // Increase the RX FIFO margin + MXC_SPIM1->spcl_ctrl = ((MXC_SPIM1->spcl_ctrl & ~(MXC_F_SPIM_SPCL_CTRL_RX_FIFO_MARGIN)) | + (0x3 << MXC_F_SPIM_SPCL_CTRL_RX_FIFO_MARGIN_POS)); +#endif + + // Calculate the hi/lo clock setting + if(spim_clk/2 > cfg->baud) { + + /* Disable the feedback mode and use the sample mode with an appropriate hi/lo clk + to achieve the lower baud rate */ + spim->gen_ctrl &= ~MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE; + + clocks = (spim_clk / (2*cfg->baud)); + + if(clocks == 0 || clocks > 0x10) { + return E_BAD_PARAM; + } + + // 0 => 16 in the 4 bit field for HI_CLK and LO_CLK + if(clocks == 0x10) { + clocks = 0; + } + + } else { + // Continue to use feedback mode and set hi/lo clk to 1 + clocks = 1; + } + + spim->mstr_cfg |= (((clocks << MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK_POS) & MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK) | + ((clocks << MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK_POS) & MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK)); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SPIM_Shutdown(mxc_spim_regs_t *spim) +{ + int spim_num, err; + spim_req_t *temp_req; + + // Disable and clear interrupts + spim->inten = 0; + spim->intfl = spim->intfl; + + // Disable SPIM and FIFOS + spim->gen_ctrl &= ~(MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN | MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN | + MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN); + + // Call all of the pending callbacks for this SPIM + spim_num = MXC_SPIM_GET_IDX(spim); + if(states[spim_num].req != NULL) { + + // Save the request + temp_req = states[spim_num].req; + + // Unlock this SPIM + mxc_free_lock((uint32_t*)&states[spim_num].req); + + // Callback if not NULL + if(temp_req->callback != NULL) { + temp_req->callback(temp_req, E_SHUTDOWN); + } + } + + // Clear system level configurations + if ((err = SYS_SPIM_Shutdown(spim)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SPIM_Clocks(mxc_spim_regs_t *spim, uint32_t len, uint8_t ssel, uint8_t deass) +{ + int spim_num; + mxc_spim_fifo_regs_t *fifo; + uint16_t header = 0x1; + uint32_t num = len; + + // Make sure the SPIM has been initialized + if((spim->gen_ctrl & MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN) == 0) + return E_UNINITIALIZED; + + if(!(len > 0)) { + return E_NO_ERROR; + } + + // Check the previous transaction if we're switching the slave select + if((ssel != ((spim->mstr_cfg & MXC_F_SPIM_MSTR_CFG_SLAVE_SEL) >> + MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS)) && (spim->gen_ctrl & MXC_F_SPIM_GEN_CTRL_BB_SS_IN_OUT)) { + + // Return E_BUSY if the slave select is still asserted + return E_BUSY; + } + + // Attempt to lock this SPIM + spim_num = MXC_SPIM_GET_IDX(spim); + if(mxc_get_lock((uint32_t*)&states[spim_num].req, 1) != E_NO_ERROR) { + return E_BUSY; + } + + // Set which slave select we are using + spim->mstr_cfg = ((spim->mstr_cfg & ~MXC_F_SPIM_MSTR_CFG_SLAVE_SEL) | + ((ssel << MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS) & MXC_F_SPIM_MSTR_CFG_SLAVE_SEL)); + + //force deass to a 1 or 0 + deass = !!deass; + +#if(MXC_SPIM_REV == 0) + // Wait for all of the data to transmit + while(spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) {} + + // Disable the feedback clock, save state + uint32_t gen_ctrl = spim->gen_ctrl; + spim->gen_ctrl &= ~MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE; +#endif + + // Get the TX and RX FIFO for this SPIM + fifo = MXC_SPIM_GET_SPIM_FIFO(spim_num); + + // Send the headers to transmit the clocks + while(len > 32) { + fifo->trans_16[0] = header; + fifo->trans_16[0] = 0xF000; + fifo->trans_16[0] = 0xF000; + len -= 32; + } + + if(len) { + if(len < 32) { + header |= (len << 4); + } + header |= (deass << 13); + + fifo->trans_16[0] = header; + + if(len > 16) { + fifo->trans_16[0] = 0xF000; + } + fifo->trans_16[0] = 0xF000; + } + +#if(MXC_SPIM_REV == 0) + // Wait for all of the data to transmit + while(spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) {} + + // Restore feedback clock setting + spim->gen_ctrl |= (gen_ctrl & MXC_F_SPIM_GEN_CTRL_ENABLE_SCK_FB_MODE); +#endif + + // Unlock this SPIM + mxc_free_lock((uint32_t*)&states[spim_num].req); + + return num; +} + + +/******************************************************************************/ +int SPIM_Trans(mxc_spim_regs_t *spim, spim_req_t *req) +{ + int spim_num; + + // Make sure the SPIM has been initialized + if((spim->gen_ctrl & MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN) == 0) + return E_UNINITIALIZED; + + // Check the input parameters + if(req == NULL) + return E_NULL_PTR; + + if((req->rx_data == NULL) && (req->tx_data == NULL)) + return E_NULL_PTR; + + if(!(req->len > 0)) { + return E_NO_ERROR; + } + + // Check the previous transaction if we're switching the slave select + if((req->ssel != ((spim->mstr_cfg & MXC_F_SPIM_MSTR_CFG_SLAVE_SEL) >> + MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS)) && (spim->gen_ctrl & MXC_F_SPIM_GEN_CTRL_BB_SS_IN_OUT)) { + + // Return E_BUSY if the slave select is still asserted + return E_BUSY; + } + + // Attempt to register this write request + spim_num = MXC_SPIM_GET_IDX(spim); + if(mxc_get_lock((uint32_t*)&states[spim_num].req, (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + // Set which slave select we are using + spim->mstr_cfg = ((spim->mstr_cfg & ~MXC_F_SPIM_MSTR_CFG_SLAVE_SEL) | + ((req->ssel << MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS) & MXC_F_SPIM_MSTR_CFG_SLAVE_SEL)); + + //force deass to a 1 or 0 + req->deass = !!req->deass; + + // Clear the number of bytes counter + req->read_num = 0; + req->write_num = 0; + req->callback = NULL; + states[spim_num].head_rem = 0; + + // Start the transaction, keep calling the handler until complete + while(SPIM_TransHandler(spim, req, spim_num) != 0); + + if(req->tx_data == NULL) { + return req->read_num; + } + return req->write_num; +} + +/******************************************************************************/ +int SPIM_TransAsync(mxc_spim_regs_t *spim, spim_req_t *req) +{ + int spim_num; + + // Make sure the SPIM has been initialized + if((spim->gen_ctrl & MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN) == 0) + return E_UNINITIALIZED; + + // Check the input parameters + if(req == NULL) + return E_NULL_PTR; + + if((req->rx_data == NULL) && (req->tx_data == NULL)) + return E_NULL_PTR; + + if(!(req->len > 0)) { + return E_NO_ERROR; + } + + + // Check the previous transaction if we're switching the slave select + if((req->ssel != ((spim->mstr_cfg & MXC_F_SPIM_MSTR_CFG_SLAVE_SEL) >> + MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS)) && (spim->gen_ctrl & MXC_F_SPIM_GEN_CTRL_BB_SS_IN_OUT)) { + + // Return E_BUSY if the slave select is still asserted + return E_BUSY; + } + + // Attempt to register this write request + spim_num = MXC_SPIM_GET_IDX(spim); + if(mxc_get_lock((uint32_t*)&states[spim_num].req, (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + // Set which slave select we are using + spim->mstr_cfg = ((spim->mstr_cfg & ~MXC_F_SPIM_MSTR_CFG_SLAVE_SEL) | + ((req->ssel << MXC_F_SPIM_MSTR_CFG_SLAVE_SEL_POS) & MXC_F_SPIM_MSTR_CFG_SLAVE_SEL)); + + //force deass to a 1 or 0 + req->deass = !!req->deass; + + // Clear the number of bytes counter + req->read_num = 0; + req->write_num = 0; + states[spim_num].head_rem = 0; + + // Start the transaction, enable the interrupts + spim->inten = SPIM_TransHandler(spim, req, spim_num); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SPIM_AbortAsync(spim_req_t *req) +{ + int spim_num; + mxc_spim_regs_t *spim; + + // Check the input parameters + if(req == NULL) { + return E_BAD_PARAM; + } + + // Find the request, set to NULL + for(spim_num = 0; spim_num < MXC_CFG_SPIM_INSTANCES; spim_num++) { + if(req == states[spim_num].req) { + + spim = MXC_SPIM_GET_SPIM(spim_num); + + // Disable interrupts, clear the flags + spim->inten = 0; + spim->intfl = spim->intfl; + + // Reset the SPIM to cancel the on ongoing transaction + spim->gen_ctrl &= ~(MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN); + spim->gen_ctrl |= (MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN); + + // Unlock this SPIM + mxc_free_lock((uint32_t*)&states[spim_num].req); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_ABORT); + } + + return E_NO_ERROR; + } + } + + return E_BAD_PARAM; +} + +/******************************************************************************/ +void SPIM_Handler(mxc_spim_regs_t *spim) +{ + int spim_num; + uint32_t flags; + + // Clear the interrupt flags + spim->inten = 0; + flags = spim->intfl; + spim->intfl = flags; + + spim_num = MXC_SPIM_GET_IDX(spim); + + // Figure out if this SPIM has an active request + if((states[spim_num].req != NULL) && (flags)) { + spim->inten = SPIM_TransHandler(spim, states[spim_num].req, spim_num); + } +} + +/******************************************************************************/ +int SPIM_Busy(mxc_spim_regs_t *spim) +{ + // Check to see if there are any ongoing transactions + if((states[MXC_SPIM_GET_IDX(spim)].req == NULL) && + !(spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED)) { + + return E_NO_ERROR; + } + + return E_BUSY; +} + +/******************************************************************************/ +int SPIM_PrepForSleep(mxc_spim_regs_t *spim) +{ + if(SPIM_Busy(spim) != E_NO_ERROR) { + return E_BUSY; + } + + // Disable interrupts + spim->inten = 0; + return E_NO_ERROR; +} + +/******************************************************************************/ +static unsigned SPIM_ReadRXFIFO(mxc_spim_regs_t *spim, mxc_spim_fifo_regs_t *fifo, + uint8_t *data, unsigned len) +{ + unsigned num = 0; + unsigned avail = ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED) >> + MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS); + + // Get data from the RXFIFO + while(avail && (len - num)) { + + if((avail >= 4) && ((len-num) >= 4)) { + // Save data from the RXFIFO + uint32_t temp = fifo->rslts_32[0]; + data[num+0] = ((temp & 0x000000FF) >> 0); + data[num+1] = ((temp & 0x0000FF00) >> 8); + data[num+2] = ((temp & 0x00FF0000) >> 16); + data[num+3] = ((temp & 0xFF000000) >> 24); + num+=4; + avail-=4; + } else if ((avail >= 2) && ((len-num) >= 2)) { + // Save data from the RXFIFO + uint16_t temp = fifo->rslts_16[0]; + data[num+0] = ((temp & 0x00FF) >> 0); + data[num+1] = ((temp & 0xFF00) >> 8); + num+=2; + avail-=2; + } else { + // Save data from the RXFIFO + data[num] = fifo->rslts_8[0]; + num+=1; + avail-=1; + } + + // Check to see if there is more data in the FIFO + if(avail == 0) { + avail = ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED) >> + MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS); + } + } + + return num; +} + +uint16_t header_save; + + +/******************************************************************************/ +static uint32_t SPIM_TransHandler(mxc_spim_regs_t *spim, spim_req_t *req, int spim_num) +{ + uint8_t read, write; + uint16_t header; + uint32_t pages, bytes, inten; + unsigned remain, bytes_read, head_rem_temp, avail; + mxc_spim_fifo_regs_t *fifo; + + inten = 0; + + // Get the FIFOS for this UART + fifo = MXC_SPIM_GET_SPIM_FIFO(spim_num); + + // Figure out if we're reading + if(req->rx_data != NULL) { + read = 1; + } else { + read = 0; + } + + // Figure out if we're writing + if(req->tx_data != NULL) { + write = 1; + } else { + write = 0; + } + + // Read byte from the FIFO if we are reading + if(read) { + + // Read all of the data in the RXFIFO, or until we don't need anymore + bytes_read = SPIM_ReadRXFIFO(spim, fifo, &req->rx_data[req->read_num], + (req->len - req->read_num)); + + req->read_num += bytes_read; + + // Adjust head_rem if we are only reading + if(!write && (states[spim_num].head_rem > 0)) { + states[spim_num].head_rem -= bytes_read; + } + + // Figure out how many byte we have left to read + if(states[spim_num].head_rem > 0) { + remain = states[spim_num].head_rem; + } else { + remain = req->len - req->read_num; + } + + if(remain) { + + // Set the RX interrupts + if (remain > MXC_CFG_SPIM_FIFO_DEPTH) { + spim->fifo_ctrl = ((spim->fifo_ctrl & ~MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL) | + ((MXC_CFG_SPIM_FIFO_DEPTH - 2) << + MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL_POS)); + + } else { + spim->fifo_ctrl = ((spim->fifo_ctrl & ~MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL) | + ((remain - 1) << MXC_F_SPIM_FIFO_CTRL_RX_FIFO_AF_LVL_POS)); + } + + inten |= MXC_F_SPIM_INTEN_RX_FIFO_AF; + } + } + + // Figure out how many bytes we have left to send headers for + if(write) { + remain = req->len - req->write_num; + } else { + remain = req->len - req->read_num; + } + + // See if we need to send a new header + if(states[spim_num].head_rem <= 0 && remain) { + + // Set the transaction configuration in the header + header = ((write << 0) | (read << 1) | (req->width << 9)); + + if(remain >= SPIM_MAX_BYTE_LEN) { + + // Send a 32 byte header + if(remain == SPIM_MAX_BYTE_LEN) { + + header |= ((0x1 << 2) | (req->deass << 13)); + + // Save the number of bytes we need to write to the FIFO + bytes = SPIM_MAX_BYTE_LEN; + + } else { + // Send in increments of 32 byte pages + header |= (0x2 << 2); + pages = remain / SPIM_MAX_PAGE_LEN; + + if(pages >= 32) { + // 0 maps to 32 in the header + bytes = 32 * SPIM_MAX_PAGE_LEN; + } else { + header |= (pages << 4); + bytes = pages * SPIM_MAX_PAGE_LEN; + } + + // Check if this is the last header we will send + if((remain - bytes) == 0) { + header |= (req->deass << 13); + } + } + + header_save = header; + fifo->trans_16[0] = header; + + // Save the number of bytes we need to write to the FIFO + states[spim_num].head_rem = bytes; + + } else { + + // Send final header with the number of bytes remaining and if + // we want to de-assert the SS at the end of the transaction + header |= ((0x1 << 2) | (remain << 4) | (req->deass << 13)); + fifo->trans_16[0] = header; + states[spim_num].head_rem = remain; + } + } + + // Put data into the FIFO if we are writing + remain = req->len - req->write_num; + head_rem_temp = states[spim_num].head_rem; + if(write && head_rem_temp) { + + // Fill the FIFO + avail = (MXC_CFG_SPIM_FIFO_DEPTH - ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) >> + MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS)); + + // Use memcpy for everything except the last byte in odd length transactions + while((avail >= 2) && (head_rem_temp >= 2)) { + + unsigned length; + if(head_rem_temp < avail) { + length = head_rem_temp; + } else { + length = avail; + } + + // Only memcpy even numbers + length = ((length / 2) * 2); + + memcpy((void*)fifo->trans_32, &(req->tx_data[req->write_num]), length); + + head_rem_temp -= length; + req->write_num += length; + + avail = (MXC_CFG_SPIM_FIFO_DEPTH - ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) >> + MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS)); + } + + // Copy the last byte and pad with 0xF0 to not get confused as header + if((avail >= 1) && (head_rem_temp == 1)) { + + // Write the last byte + fifo->trans_16[0] = (0xF000 | req->tx_data[req->write_num]); + + avail -= 1; + req->write_num += 1; + head_rem_temp -= 1; + } + + states[spim_num].head_rem = head_rem_temp; + remain = req->len - req->write_num; + + // Set the TX interrupts + if(remain) { + + // Set the TX FIFO almost empty interrupt if we have to refill + spim->fifo_ctrl = ((spim->fifo_ctrl & ~MXC_F_SPIM_FIFO_CTRL_TX_FIFO_AE_LVL) | + ((MXC_CFG_SPIM_FIFO_DEPTH - 2) << MXC_F_SPIM_FIFO_CTRL_TX_FIFO_AE_LVL_POS)); + + inten |= MXC_F_SPIM_INTEN_TX_FIFO_AE; + + } + } + + // Check to see if we've finished reading and writing + if(((read && (req->read_num == req->len)) || !read) && + ((req->write_num == req->len) || !write)) { + + // Disable interrupts + spim->inten = 0; + + // Unlock this SPIM + mxc_free_lock((uint32_t*)&states[spim_num].req); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_NO_ERROR); + } + } + + // Enable the SPIM interrupts + return inten; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spim.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spim.h new file mode 100644 index 0000000..f9ed9b8 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spim.h @@ -0,0 +1,263 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-04-27 11:55:43 -0500 (Wed, 27 Apr 2016) $ + * $Revision: 22541 $ + * + ******************************************************************************/ + +/** + * @file spim.h + * @brief SPI Master driver header file. + */ + +#include "mxc_config.h" +#include "mxc_sys.h" +#include "spim_regs.h" + +#ifndef _SPIM_H_ +#define _SPIM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/// @brief Active levels for slave select lines. +typedef enum { + SPIM_SSEL0_HIGH = (0x1 << 0), + SPIM_SSEL0_LOW = 0, + SPIM_SSEL1_HIGH = (0x1 << 1), + SPIM_SSEL1_LOW = 0, + SPIM_SSEL2_HIGH = (0x1 << 2), + SPIM_SSEL2_LOW = 0, + SPIM_SSEL3_HIGH = (0x1 << 3), + SPIM_SSEL3_LOW = 0, + SPIM_SSEL4_HIGH = (0x1 << 4), + SPIM_SSEL4_LOW = 0 +} +spim_ssel_t; + +/// @brief Number of data lines to use. +typedef enum { + SPIM_WIDTH_1 = 0, + SPIM_WIDTH_2 = 1, + SPIM_WIDTH_4 = 2 +} spim_width_t; + +/// @brief SPIM configuration type. +typedef struct { + uint8_t mode; ///< SPIM mode to use, 0-3. + uint32_t ssel_pol; ///< Mask of active levels for slave select signals, use spim_ssel_t. + uint32_t baud; ///< Baud rate in Hz. +} spim_cfg_t; + +/// @brief SPIM Transaction request. +typedef struct spim_req spim_req_t; +struct spim_req { + uint8_t ssel; ///< Slave select number. + uint8_t deass; ///< De-assert slave select at the end of the transaction. + const uint8_t *tx_data; ///< TX buffer. + uint8_t *rx_data; ///< RX buffer. + spim_width_t width; ///< Number of data lines to use + unsigned len; ///< Number of bytes to send. + unsigned read_num; ///< Number of bytes read. + unsigned write_num; ///< Number of bytes written. + + /** + * @brief Callback for asynchronous request. + * @param spim_req_t* Pointer to the transaction request. + * @param int Error code. + */ + void (*callback)(spim_req_t*, int); +}; + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Initialize SPIM module. + * @param spim Pointer to SPIM regs. + * @param cfg Pointer to SPIM configuration. + * @param sys_cfg Pointer to system configuration object + * @returns #E_NO_ERROR if everything is successful + */ +int SPIM_Init(mxc_spim_regs_t *spim, const spim_cfg_t *cfg, const sys_cfg_spim_t *sys_cfg); + +/** + * @brief Shutdown SPIM module. + * @param spim Pointer to SPIM regs. + * @returns #E_NO_ERROR if everything is successful + */ +int SPIM_Shutdown(mxc_spim_regs_t *spim); + +/** + * @brief Send Clock cycles on SCK without reading or writing. + * @param spim Pointer to SPIM regs. + * @param len Number of clock cycles to send. + * @param ssel Slave select number. + * @param deass De-assert slave select at the end of the transaction. + * @returns Cycles transacted if everything is successful, error if unsuccessful. + */ +int SPIM_Clocks(mxc_spim_regs_t *spim, uint32_t len, uint8_t ssel, uint8_t deass); + +/** + * @brief Read/write SPIM data. Will block until transaction is complete. + * @param spim Pointer to SPIM regs. + * @param req Request for a SPIM transaction. + * @note Callback is ignored. + * @returns Bytes transacted if everything is successful, error if unsuccessful. + */ +int SPIM_Trans(mxc_spim_regs_t *spim, spim_req_t *req); + +/** + * @brief Asynchronously read/write SPIM data. + * @param spim Pointer to SPIM regs. + * @param req Request for a SPIM transaction. + * @note Request struct must remain allocated until callback. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int SPIM_TransAsync(mxc_spim_regs_t *spim, spim_req_t *req); + +/** + * @brief Abort asynchronous request. + * @param req Pointer to request for a SPIM transaction. + * @returns #E_NO_ERROR if request aborted, error if unsuccessful. + */ +int SPIM_AbortAsync(spim_req_t *req); + +/** + * @brief SPIM interrupt handler. + * @details This function should be called by the application from the interrupt + * handler if SPIM interrupts are enabled. Alternately, this function + * can be periodically called by the application if SPIM interrupts are + * disabled. + * @param spim Base address of the SPIM module. + */ +void SPIM_Handler(mxc_spim_regs_t *spim); + +/** + * @brief Check the SPIM to see if it's busy. + * @param spim Pointer to SPIM regs. + * @returns #E_NO_ERROR if idle, #E_BUSY if in use. + */ +int SPIM_Busy(mxc_spim_regs_t *spim); + +/** + * @brief Attempt to prepare the SPIM for sleep. + * @param spim Pointer to SPIM regs. +* @details Checks for any ongoing transactions. Disables interrupts if the SPIM + is idle. + * @returns #E_NO_ERROR if ready to sleep, #E_BUSY if not ready for sleep. + */ +int SPIM_PrepForSleep(mxc_spim_regs_t *spim); + +/** + * @brief Enables the SPIM without overwriting existing configuration. + * @param spim Pointer to SPIM regs. + */ +__STATIC_INLINE void SPIM_Enable(mxc_spim_regs_t *spim) +{ + spim->gen_ctrl |= (MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN | + MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN | MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN); +} + +/** + * @brief Drain all of the data in the RXFIFO. + * @param spim Pointer to UART regs. + */ +__STATIC_INLINE void SPIM_DrainRX(mxc_spim_regs_t *spim) +{ + uint32_t ctrl_save = spim->gen_ctrl; + spim->gen_ctrl = (ctrl_save & ~MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN); + spim->gen_ctrl = ctrl_save; +} + +/** + * @brief Drain all of the data in the TXFIFO. + * @param spim Pointer to UART regs. + */ +__STATIC_INLINE void SPIM_DrainTX(mxc_spim_regs_t *spim) +{ + uint32_t ctrl_save = spim->gen_ctrl; + spim->gen_ctrl = (ctrl_save & ~MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN); + spim->gen_ctrl = ctrl_save; +} + +/** + * @brief TX FIFO availability. + * @param spim Pointer to UART regs. + * @returns Number of empty bytes available in write FIFO. + */ +__STATIC_INLINE unsigned SPIM_NumWriteAvail(mxc_spim_regs_t *spim) +{ + return (MXC_CFG_SPIM_FIFO_DEPTH - ((spim->fifo_ctrl & + MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) >> MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS)); +} + +/** + * @brief RX FIFO availability. + * @param spim Pointer to UART regs. + * @returns Number of bytes in read FIFO. + */ +__STATIC_INLINE unsigned SPIM_NumReadAvail(mxc_spim_regs_t *spim) +{ + return ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED) >> + MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS); +} + +/** + * @brief Clear interrupt flags. + * @param spim Pointer to SPIM regs. + * @param mask Mask of interrupts to clear. + */ +__STATIC_INLINE void SPIM_ClearFlags(mxc_spim_regs_t *spim, uint32_t mask) +{ + spim->intfl = mask; +} + +/** + * @brief Get interrupt flags. + * @param spim Pointer to SPIM regs. + * @returns Mask of active flags. + */ +__STATIC_INLINE unsigned SPIM_GetFlags(mxc_spim_regs_t *spim) +{ + return (spim->intfl); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _SPIM_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spis.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spis.c new file mode 100644 index 0000000..503987d --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spis.c @@ -0,0 +1,457 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-03 16:00:49 -0500 (Wed, 03 Aug 2016) $ + * $Revision: 23914 $ + * + ******************************************************************************/ + +/** + * @file spis.c + * @brief SPI Slave driver source. + */ + +/***** Includes *****/ +#include +#include +#include "mxc_config.h" +#include "mxc_assert.h" +#include "mxc_lock.h" +#include "spis.h" + +/***** Definitions *****/ +#define SPIS_FIFO_BUFFER 6 + +/***** Globals *****/ + +static spis_req_t *states[MXC_CFG_SPIS_INSTANCES]; + +/***** Functions *****/ + +static uint32_t SPIS_TransHandler(mxc_spis_regs_t *spis, spis_req_t *req, int spis_num); + +/******************************************************************************/ +int SPIS_Init(mxc_spis_regs_t *spis, uint8_t mode, const sys_cfg_spis_t *sys_cfg) +{ + int err, spis_num; + + spis_num = MXC_SPIS_GET_IDX(spis); + MXC_ASSERT(spis_num >= 0); + + // Set system level configurations + if ((err = SYS_SPIS_Init(sys_cfg)) != E_NO_ERROR) { + return err; + } + + // Initialize state pointers + states[spis_num] = NULL; + + // Drain the FIFOs, enable SPIS + spis->gen_ctrl = 0; + spis->gen_ctrl = (MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN | MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN | + MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN); + + // Set the TX FIFO almost empty level + spis->fifo_ctrl = ((spis->fifo_ctrl & ~MXC_F_SPIS_FIFO_CTRL_TX_FIFO_AE_LVL) | + ((MXC_CFG_SPIS_FIFO_DEPTH - SPIS_FIFO_BUFFER) << MXC_F_SPIS_FIFO_CTRL_TX_FIFO_AE_LVL_POS)); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SPIS_Shutdown(mxc_spis_regs_t *spis) +{ + int spis_num, err; + spis_req_t *temp_req; + + // Disable and clear interrupts + spis->inten = 0; + spis->intfl = spis->intfl; + + // Disable SPIS and FIFOS + spis->gen_ctrl &= ~(MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN | MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN | + MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN); + + // Call all of the pending callbacks for this SPIS + spis_num = MXC_SPIS_GET_IDX(spis); + if(states[spis_num] != NULL) { + + // Save the request + temp_req = states[spis_num]; + + // Unlock this SPIS + mxc_free_lock((uint32_t*)&states[spis_num]); + + // Callback if not NULL + if(temp_req->callback != NULL) { + temp_req->callback(temp_req, E_SHUTDOWN); + } + } + + // Clear system level configurations + if ((err = SYS_SPIS_Shutdown(spis)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SPIS_Trans(mxc_spis_regs_t *spis, spis_req_t *req) +{ + int spis_num; + + // Make sure the SPIS has been initialized + if((spis->gen_ctrl & MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN) == 0) + return E_UNINITIALIZED; + + // Check the input parameters + if(req == NULL) + return E_NULL_PTR; + + if((req->rx_data == NULL) && (req->tx_data == NULL)) + return E_NULL_PTR; + + if(!(req->len > 0)) { + return E_NO_ERROR; + } + + // Attempt to register this write request + spis_num = MXC_SPIS_GET_IDX(spis); + if(mxc_get_lock((uint32_t*)&states[spis_num], (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + //force deass to a 1 or 0 + req->deass = !!req->deass; + + // Clear the number of bytes counter + req->read_num = 0; + req->write_num = 0; + req->callback = NULL; + + // Start the transaction, keep calling the handler until complete + spis->intfl = (MXC_F_SPIS_INTFL_SS_DEASSERTED | MXC_F_SPIS_INTFL_TX_UNDERFLOW); + while(SPIS_TransHandler(spis, req, spis_num) & (MXC_F_SPIS_INTEN_RX_FIFO_AF | + MXC_F_SPIS_INTEN_TX_FIFO_AE)) { + + if((req->tx_data != NULL) && (spis->intfl & MXC_F_SPIS_INTFL_TX_UNDERFLOW)) { + return E_UNDERFLOW; + } + + if((req->rx_data != NULL) && (spis->intfl & MXC_F_SPIS_INTFL_RX_LOST_DATA)) { + return E_OVERFLOW; + } + + if((req->deass) && (spis->intfl & MXC_F_SPIS_INTFL_SS_DEASSERTED)) { + if(((req->rx_data != NULL) && ((req->read_num + SPIS_NumReadAvail(spis)) < req->len)) || + ((req->tx_data != NULL) && (req->write_num < req->len))) { + + return E_COMM_ERR; + } + } + } + + if(req->tx_data == NULL) { + return req->read_num; + } + return req->write_num; +} + +/******************************************************************************/ +int SPIS_TransAsync(mxc_spis_regs_t *spis, spis_req_t *req) +{ + int spis_num; + + // Make sure the SPIS has been initialized + if((spis->gen_ctrl & MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN) == 0) + return E_UNINITIALIZED; + + // Check the input parameters + if(req == NULL) + return E_NULL_PTR; + + if((req->rx_data == NULL) && (req->tx_data == NULL)) + return E_NULL_PTR; + + if(!(req->len > 0)) { + return E_NO_ERROR; + } + + // Attempt to register this write request + spis_num = MXC_SPIS_GET_IDX(spis); + if(mxc_get_lock((uint32_t*)&states[spis_num], (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + //force deass to a 1 or 0 + req->deass = !!req->deass; + + // Clear the number of bytes counter + req->read_num = 0; + req->write_num = 0; + + // Start the transaction, enable the interrupts + spis->intfl = MXC_F_SPIS_INTFL_SS_DEASSERTED; + spis->inten = SPIS_TransHandler(spis, req, spis_num); + + if(spis->intfl & MXC_F_SPIS_INTFL_SS_DEASSERTED) { + return E_COMM_ERR; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int SPIS_AbortAsync(spis_req_t *req) +{ + int spis_num; + + // Check the input parameters + if(req == NULL) { + return E_BAD_PARAM; + } + + // Find the request, set to NULL + for(spis_num = 0; spis_num < MXC_CFG_SPIS_INSTANCES; spis_num++) { + if(req == states[spis_num]) { + + // Disable interrupts, clear the flags + MXC_SPIS_GET_SPIS(spis_num)->inten = 0; + MXC_SPIS_GET_SPIS(spis_num)->intfl = MXC_SPIS_GET_SPIS(spis_num)->intfl; + + // Unlock this SPIS + mxc_free_lock((uint32_t*)&states[spis_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_ABORT); + } + + return E_NO_ERROR; + } + } + + return E_BAD_PARAM; +} + +/******************************************************************************/ +void SPIS_Handler(mxc_spis_regs_t *spis) +{ + int spis_num; + uint32_t flags; + spis_req_t *req; + + // Clear the interrupt flags + spis->inten = 0; + flags = spis->intfl; + spis->intfl = flags; + + spis_num = MXC_SPIS_GET_IDX(spis); + req = states[spis_num]; + + // Check for errors + if((flags & MXC_F_SPIS_INTFL_TX_UNDERFLOW) && (req->tx_data != NULL)) { + // Unlock this SPIS + mxc_free_lock((uint32_t*)&states[spis_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_UNDERFLOW); + } + return; + } + if((flags & MXC_F_SPIS_INTFL_RX_LOST_DATA) && (req->rx_data != NULL)) { + // Unlock this SPIS + mxc_free_lock((uint32_t*)&states[spis_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_OVERFLOW); + } + return; + } + + // Check for deassert + if((flags & MXC_F_SPIS_INTFL_SS_DEASSERTED) && (req != NULL) && + (req->deass)) { + + if(((req->rx_data != NULL) && ((req->read_num + SPIS_NumReadAvail(spis)) < req->len)) || + ((req->tx_data != NULL) && (req->write_num < req->len))) { + + // Unlock this SPIS + mxc_free_lock((uint32_t*)&states[spis_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(states[spis_num], E_COMM_ERR); + } + + return; + } + } + + // Figure out if this SPIS has an active request + if(flags && (req != NULL)) { + + spis->inten = SPIS_TransHandler(spis, req, spis_num); + } +} + +/******************************************************************************/ +int SPIS_Busy(mxc_spis_regs_t *spis) +{ + // Check to see if there are any ongoing transactions + if(states[MXC_SPIS_GET_IDX(spis)] == NULL) { + return E_NO_ERROR; + } + + return E_BUSY; +} + +/******************************************************************************/ +int SPIS_PrepForSleep(mxc_spis_regs_t *spis) +{ + if(SPIS_Busy(spis) != E_NO_ERROR) { + return E_BUSY; + } + + // Disable interrupts + spis->inten = 0; + return E_NO_ERROR; +} + +/******************************************************************************/ +static uint32_t SPIS_TransHandler(mxc_spis_regs_t *spis, spis_req_t *req, int spis_num) +{ + uint8_t read, write; + uint32_t inten; + unsigned remain, avail, temp_len; + mxc_spis_fifo_regs_t *fifo; + + inten = 0; + + // Get the FIFOS for this UART + fifo = MXC_SPIS_GET_SPIS_FIFO(spis_num); + + // Figure out if we're reading + if(req->rx_data != NULL) { + read = 1; + } else { + read = 0; + } + + // Figure out if we're writing + if(req->tx_data != NULL) { + write = 1; + } else { + write = 0; + } + + // Put data into the FIFO if we are writing + if(write) { + + avail = SPIS_NumWriteAvail(spis); + remain = req->len - req->write_num; + + if(remain > avail) { + temp_len = avail; + } else { + temp_len = remain; + } + + memcpy((void*)fifo->tx_32, &(req->tx_data[req->write_num]), temp_len); + spis->intfl = MXC_F_SPIS_INTFL_TX_FIFO_AE; + req->write_num += temp_len; + remain = req->len - req->write_num; + + // Set the TX interrupts + if(remain) { + inten |= (MXC_F_SPIS_INTEN_TX_FIFO_AE | MXC_F_SPIS_INTFL_TX_UNDERFLOW); + } + } + + // Read from the FIFO if we are reading + if(read) { + + avail = SPIS_NumReadAvail(MXC_SPIS); + remain = req->len - req->read_num; + + if(remain > avail) { + temp_len = avail; + } else { + temp_len = remain; + } + + memcpy((void*)&req->rx_data[req->read_num], (void*)&(fifo->rx_8[0]), temp_len); + spis->intfl = MXC_F_SPIS_INTFL_RX_FIFO_AF; + req->read_num += temp_len; + remain = req->len - req->read_num; + + // Set the RX interrupts + if(remain) { + + // Adjust the almost full threshold + if (remain > (MXC_CFG_SPIS_FIFO_DEPTH - SPIS_FIFO_BUFFER)) { + spis->fifo_ctrl = ((spis->fifo_ctrl & ~MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL) | + ((MXC_CFG_SPIS_FIFO_DEPTH - SPIS_FIFO_BUFFER) << MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL_POS)); + + } else { + spis->fifo_ctrl = ((spis->fifo_ctrl & ~MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL) | + ((remain-1) << MXC_F_SPIS_FIFO_CTRL_RX_FIFO_AF_LVL_POS)); + } + + inten |= (MXC_F_SPIS_INTEN_RX_FIFO_AF | MXC_F_SPIS_INTFL_RX_LOST_DATA); + } + } + + // Check to see if we've finished reading and writing + if(((read && (req->read_num == req->len)) || !read) && + ((req->write_num == req->len) || !write)) { + + // Unlock this SPIS + mxc_free_lock((uint32_t*)&states[spis_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_NO_ERROR); + } + + return 0; + } + + // Enable deassert interrupt + if(req->deass) { + inten |= MXC_F_SPIS_INTEN_SS_DEASSERTED; + } + + return inten; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spis.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spis.h new file mode 100644 index 0000000..8858976 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spis.h @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-05-18 16:27:43 -0500 (Wed, 18 May 2016) $ + * $Revision: 22908 $ + * + ******************************************************************************/ + +/** + * @file spis.s + * @brief SPI Slave driver header file. + */ + +#include "mxc_config.h" +#include "mxc_sys.h" +#include "spis_regs.h" + +#ifndef _SPIS_H_ +#define _SPIS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/// @brief Number of data lines to use. +typedef enum { + SPIS_WIDTH_1 = 0, + SPIS_WIDTH_2 = 1, + SPIS_WIDTH_4 = 2 +} spis_width_t; + +/// @brief SPIS Transaction request. +typedef struct spis_req spis_req_t; +struct spis_req { + uint8_t deass; ///< End the transaction when SS is deasserted. + const uint8_t *tx_data; ///< TX buffer. + uint8_t *rx_data; ///< RX buffer. + spis_width_t width; ///< Number of data lines to use. + unsigned len; ///< Number of bytes to send. + unsigned read_num; ///< Number of bytes transacted. + unsigned write_num; ///< Number of bytes transacted. + + /** + * @brief Callback for asynchronous request. + * @param spis_req_t* Pointer to the transaction request. + * @param int Error code. + */ + void (*callback)(spis_req_t*, int); +}; + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Initialize SPIS module. + * @param spis Pointer to SPIS regs. + * @param cfg Pointer to SPIS configuration. + * @param mode SPI Mode to configure the slave. + * @param sys_cfg Pointer to system configuration object. + * @returns #E_NO_ERROR if everything is successful. + */ +int SPIS_Init(mxc_spis_regs_t *spis, uint8_t mode, const sys_cfg_spis_t *sys_cfg); + + +/** + * @brief Shutdown SPIS module. + * @param spis Pointer to SPIS regs. + * @returns #E_NO_ERROR if everything is successful + */ +int SPIS_Shutdown(mxc_spis_regs_t *spis); + +/** + * @brief Read/write SPIS data. Will block until transaction is complete. + * @param spis Pointer to SPIS regs. + * @param req Request for a SPIS transaction. + * @note Callback is ignored. + * @returns Bytes transacted if everything is successful, error if unsuccessful. + */ +int SPIS_Trans(mxc_spis_regs_t *spis, spis_req_t *req); + +/** + * @brief Asynchronously read/write SPIS data. + * @param spis Pointer to SPIS regs. + * @param req Request for a SPIS transaction. + * @note Request struct must remain allocated until callback. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int SPIS_TransAsync(mxc_spis_regs_t *spis, spis_req_t *req); + +/** + * @brief Abort asynchronous request. + * @param req Pointer to request for a SPIS transaction. + * @returns #E_NO_ERROR if request aborted, error if unsuccessful. + */ +int SPIS_AbortAsync(spis_req_t *req); + +/** + * @brief SPIS interrupt handler. + * @details This function should be called by the application from the interrupt + * handler if SPIS interrupts are enabled. Alternately, this function + * can be periodically called by the application if SPIS interrupts are + * disabled. + * @param spis Base address of the SPIS module. + */ +void SPIS_Handler(mxc_spis_regs_t *spis); + +/** + * @brief Check the SPIS to see if it's busy. + * @param spis Pointer to SPIS regs. + * @returns #E_NO_ERROR if idle, #E_BUSY if in use. + */ +int SPIS_Busy(mxc_spis_regs_t *spis); + +/** + * @brief Attempt to prepare the SPIS for sleep. + * @param spis Pointer to SPIS regs. +* @details Checks for any ongoing transactions. Disables interrupts if the SPIS + is idle. + * @returns #E_NO_ERROR if ready to sleep, #E_BUSY if not ready for sleep. + */ +int SPIS_PrepForSleep(mxc_spis_regs_t *spis); + +/** + * @brief Enables the SPIS without overwriting existing configuration. + * @param spis Pointer to SPIS regs. + */ +__STATIC_INLINE void SPIS_Enable(mxc_spis_regs_t *spis) +{ + spis->gen_ctrl |= (MXC_F_SPIS_GEN_CTRL_SPI_SLAVE_EN | + MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN | MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN); +} + +/** + * @brief Drain all of the data in the RXFIFO. + * @param spis Pointer to UART regs. + */ +__STATIC_INLINE void SPIS_DrainRX(mxc_spis_regs_t *spis) +{ + uint32_t ctrl_save = spis->gen_ctrl; + spis->gen_ctrl = (ctrl_save & ~MXC_F_SPIS_GEN_CTRL_RX_FIFO_EN); + spis->gen_ctrl = ctrl_save; +} + +/** + * @brief Drain all of the data in the TXFIFO. + * @param spis Pointer to UART regs. + */ +__STATIC_INLINE void SPIS_DrainTX(mxc_spis_regs_t *spis) +{ + uint32_t ctrl_save = spis->gen_ctrl; + spis->gen_ctrl = (ctrl_save & ~MXC_F_SPIS_GEN_CTRL_TX_FIFO_EN); + spis->gen_ctrl = ctrl_save; +} + +/** + * @brief TX FIFO availability. + * @param spis Pointer to UART regs. + * @returns Number of empty bytes available in write FIFO. + */ +__STATIC_INLINE unsigned SPIS_NumWriteAvail(mxc_spis_regs_t *spis) +{ + return (MXC_CFG_SPIS_FIFO_DEPTH - ((spis->fifo_stat & + MXC_F_SPIS_FIFO_STAT_TX_FIFO_USED) >> MXC_F_SPIS_FIFO_STAT_TX_FIFO_USED_POS)); +} + +/** + * @brief RX FIFO availability. + * @param spis Pointer to UART regs. + * @returns Number of bytes in read FIFO. + */ +__STATIC_INLINE unsigned SPIS_NumReadAvail(mxc_spis_regs_t *spis) +{ + return ((spis->fifo_stat & MXC_F_SPIS_FIFO_STAT_RX_FIFO_USED) >> + MXC_F_SPIS_FIFO_STAT_RX_FIFO_USED_POS); +} + +/** + * @brief Clear interrupt flags. + * @param spis Pointer to SPIS regs. + * @param mask Mask of interrupts to clear. + */ +__STATIC_INLINE void SPIS_ClearFlags(mxc_spis_regs_t *spis, uint32_t mask) +{ + spis->intfl = mask; +} + +/** + * @brief Get interrupt flags. + * @param spis Pointer to SPIS regs. + * @returns Mask of active flags. + */ +__STATIC_INLINE unsigned SPIS_GetFlags(mxc_spis_regs_t *spis) +{ + return (spis->intfl); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _SPIS_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spix.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spix.c new file mode 100644 index 0000000..590e4d7 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spix.c @@ -0,0 +1,292 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-05-31 17:30:09 -0500 (Tue, 31 May 2016) $ + * $Revision: 23119 $ + * + ******************************************************************************/ +/** + * @file spix.c + * @brief SPI execute in place driver. + */ + +/***** Includes *****/ +#include +#include "mxc_config.h" +#include "mxc_assert.h" +#include "spix.h" +#include "spix_regs.h" + +/***** Definitions *****/ +#define CMD_CLOCKS 8 +#define ADDR_3BYTE_CLOCKS 24 +#define ADDR_4BYTE_CLOCKS 32 + +/***** Globals *****/ + +/***** Functions *****/ + +/******************************************************************************/ +#if defined ( __GNUC__) +#undef IAR_SPIX_PRAGMA //Make sure this is not defined for GCC +#endif + +#if IAR_SPIX_PRAGMA +// IAR memory section declaration for the SPIX functions to be loaded in RAM. +#pragma section=".spix_config" +#endif + +#if(MXC_SPIX_REV == 0) + +#if defined ( __GNUC__ ) +__attribute__ ((section(".spix_config"), noinline)) +#endif /* __GNUC */ + +#if IAR_SPIX_PRAGMA +#pragma location=".spix_config" // IAR locate function in RAM section .spix_config +#pragma optimize=no_inline // IAR no inline optimization on this function +#endif /* IAR_PRAGMA */ + +static void SPIX_UpdateFBIgnore() +{ + // Update the feedback ignore clocks + uint8_t clocks = 0; + uint8_t no_cmd_clocks = 0; + + // Adjust the clocks for the command + if((MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH) == + MXC_S_SPIX_FETCH_CTRL_CMD_WIDTH_QUAD_IO) { + + clocks += CMD_CLOCKS/4; + } else if((MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH) == + MXC_S_SPIX_FETCH_CTRL_CMD_WIDTH_DUAL_IO) { + + clocks += CMD_CLOCKS/2; + } else { + + clocks += CMD_CLOCKS; + } + + // Adjust the clocks for the address + if((MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH) == + MXC_S_SPIX_FETCH_CTRL_ADDR_WIDTH_QUAD_IO) { + + if(MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR) { + clocks += ADDR_4BYTE_CLOCKS/4; + no_cmd_clocks += ADDR_4BYTE_CLOCKS/4; + } else { + clocks += ADDR_3BYTE_CLOCKS/4; + no_cmd_clocks += ADDR_3BYTE_CLOCKS/4; + } + + } else if((MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH) == + MXC_S_SPIX_FETCH_CTRL_ADDR_WIDTH_DUAL_IO) { + + if(MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR) { + clocks += ADDR_4BYTE_CLOCKS/2; + no_cmd_clocks += ADDR_4BYTE_CLOCKS/2; + } else { + clocks += ADDR_3BYTE_CLOCKS/2; + no_cmd_clocks += ADDR_3BYTE_CLOCKS/2; + } + } else { + + if(MXC_SPIX->fetch_ctrl & MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR) { + clocks += ADDR_4BYTE_CLOCKS; + no_cmd_clocks += ADDR_4BYTE_CLOCKS; + } else { + clocks += ADDR_3BYTE_CLOCKS; + no_cmd_clocks += ADDR_3BYTE_CLOCKS; + } + } + + // Adjust for the mode clocks + clocks += ((MXC_SPIX->mode_ctrl & MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS) >> + MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS_POS); + + // Set the FB Ignore clocks + MXC_SPIX->sck_fb_ctrl = ((MXC_SPIX->sck_fb_ctrl & ~MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS) | + (clocks << MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_POS)); + + MXC_SPIX->sck_fb_ctrl = ((MXC_SPIX->sck_fb_ctrl & ~MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_NO_CMD) | + (no_cmd_clocks << MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_NO_CMD_POS)); +} +#endif /* MXC_SPIX_REV==0 */ + +/******************************************************************************/ +#if defined ( __GNUC__ ) +__attribute__ ((section(".spix_config"), noinline)) +#endif /* __GNUC */ + +#if IAR_SPIX_PRAGMA +#pragma location=".spix_config" // IAR locate function in RAM section .spix_config +#pragma optimize=no_inline // IAR no inline optimization on this function +#endif /* IAR_SPIX_PRAGMA */ +int SPIX_ConfigClock(const sys_cfg_spix_t *sys_cfg, uint32_t baud, uint8_t sample) +{ + int err; + uint32_t spix_clk, clocks; + + // Check the input parameters + if(sys_cfg == NULL) { + return E_NULL_PTR; + } + + // Set system level configurations + if ((err = SYS_SPIX_Init(sys_cfg, baud)) != E_NO_ERROR) { + return err; + } + + // Configure the mode and baud + spix_clk = SYS_SPIX_GetFreq(); + if(spix_clk <= 0) { + return E_UNINITIALIZED; + } + + // Make sure that we can generate this frequency + clocks = (spix_clk / (2*baud)); + if((clocks <= 0) || (clocks >= 0x10)) { + return E_BAD_PARAM; + } + + // Set the baud + MXC_SPIX->master_cfg = ((MXC_SPIX->master_cfg & + ~(MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK | MXC_F_SPIX_MASTER_CFG_SCK_LO_CLK)) | + (clocks << MXC_F_SPIX_MASTER_CFG_SCK_HI_CLK_POS) | + (clocks << MXC_F_SPIX_MASTER_CFG_SCK_LO_CLK_POS)); + + if(sample != 0) { + // Use sample mode + MXC_SPIX->master_cfg = ((MXC_SPIX->master_cfg & ~MXC_F_SPIX_MASTER_CFG_SDIO_SAMPLE_POINT) | + (sample << MXC_F_SPIX_MASTER_CFG_SDIO_SAMPLE_POINT_POS)); + + MXC_SPIX->sck_fb_ctrl &= ~(MXC_F_SPIX_SCK_FB_CTRL_ENABLE_SCK_FB_MODE | + MXC_F_SPIX_SCK_FB_CTRL_INVERT_SCK_FB_CLK); + } else { + // Use Feedback mode + MXC_SPIX->master_cfg &= ~(MXC_F_SPIX_MASTER_CFG_SDIO_SAMPLE_POINT); + + MXC_SPIX->sck_fb_ctrl |= (MXC_F_SPIX_SCK_FB_CTRL_ENABLE_SCK_FB_MODE | + MXC_F_SPIX_SCK_FB_CTRL_INVERT_SCK_FB_CLK); + + +#if(MXC_SPIX_REV == 0) + SPIX_UpdateFBIgnore(); +#endif + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +#if defined ( __GNUC__ ) +__attribute__ ((section(".spix_config"), noinline)) +#endif /* __GNUC */ + +#if IAR_SPIX_PRAGMA +#pragma location=".spix_config" // IAR locate function in RAM section .spix_config +#pragma optimize=no_inline // IAR no inline optimization on this function +#endif /* IAR_SPIX_PRAGMA */ + +void SPIX_ConfigSlave(uint8_t ssel, uint8_t pol, uint8_t act_delay, uint8_t inact_delay) +{ + + // Set the slave select + MXC_SPIX->master_cfg = ((MXC_SPIX->master_cfg & ~MXC_F_SPIX_MASTER_CFG_SLAVE_SEL) | + (ssel << MXC_F_SPIX_MASTER_CFG_SLAVE_SEL_POS)); + + if(pol != 0) { + // Active high + MXC_SPIX->master_cfg &= ~(MXC_F_SPIX_MASTER_CFG_SS_ACT_LO); + } else { + // Active low + MXC_SPIX->master_cfg |= MXC_F_SPIX_MASTER_CFG_SS_ACT_LO; + } + + // Set the delays + MXC_SPIX->master_cfg = ((MXC_SPIX->master_cfg & ~(MXC_F_SPIX_MASTER_CFG_ACT_DELAY | + MXC_F_SPIX_MASTER_CFG_INACT_DELAY)) | + (act_delay << MXC_F_SPIX_MASTER_CFG_ACT_DELAY_POS) | + (inact_delay << MXC_F_SPIX_MASTER_CFG_INACT_DELAY_POS)); +} + +/******************************************************************************/ +#if defined ( __GNUC__ ) +__attribute__ ((section(".spix_config"), noinline)) +#endif /* __GNUC */ + +#if IAR_SPIX_PRAGMA +#pragma location=".spix_config" // IAR locate function in RAM section .spix_config +#pragma optimize=no_inline // IAR no inline optimization on this function +#endif /* IAR_SPIX_PRAGMA */ + +void SPIX_ConfigFetch(const spix_fetch_t *fetch) +{ + // Configure how the SPIX fetches data + MXC_SPIX->fetch_ctrl = (((fetch->cmd << MXC_F_SPIX_FETCH_CTRL_CMD_VALUE_POS) & MXC_F_SPIX_FETCH_CTRL_CMD_VALUE) | + ((fetch->cmd_width << MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH_POS) & MXC_F_SPIX_FETCH_CTRL_CMD_WIDTH) | + ((fetch->addr_width << MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS) & MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH) | + ((fetch->data_width << MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS) & MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH) | + ((fetch->addr_size << MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR_POS) & MXC_F_SPIX_FETCH_CTRL_FOUR_BYTE_ADDR)); + + // Set the command mode and clocks + MXC_SPIX->mode_ctrl = (((fetch->mode_clocks << MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS_POS) & MXC_F_SPIX_MODE_CTRL_MODE_CLOCKS) | + (!!fetch->no_cmd_mode << MXC_F_SPIX_MODE_CTRL_NO_CMD_MODE_POS)); + + MXC_SPIX->mode_data = (((fetch->mode_data << MXC_F_SPIX_MODE_DATA_MODE_DATA_BITS_POS) & MXC_F_SPIX_MODE_DATA_MODE_DATA_BITS) | + MXC_F_SPIX_MODE_DATA_MODE_DATA_OE); + +#if(MXC_SPIX_REV == 0) + SPIX_UpdateFBIgnore(); +#endif +} + +/******************************************************************************/ +#if defined ( __GNUC__ ) +__attribute__ ((section(".spix_config"), noinline)) +#endif /* __GNUC */ + +#if IAR_SPIX_PRAGMA +#pragma location=".spix_config" // IAR locate function in RAM section .spix_config +#pragma optimize=no_inline // IAR no inline optimization on this function +#endif /* IAR_SPIX_PRAGMA */ + +int SPIX_Shutdown(mxc_spix_regs_t *spix) +{ + int err; + + // Clear system level configurations + if ((err = SYS_SPIX_Shutdown()) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spix.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spix.h new file mode 100644 index 0000000..8d7ecde --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/spix.h @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-05-26 11:38:10 -0500 (Thu, 26 May 2016) $ + * $Revision: 23065 $ + * + ******************************************************************************/ + +/** + * @file spix.h + * @brief This is the high level API for the serial peripheral interface execute in place module. + * @warning If using this SPIX with IAR Embedded Workbench for Arm, it is required to define + * IAR_SPIX_PRAGMA=1. This should be done under Project->Options-> + * C/C++ Compiler->Preprocessor in the Defined Symbols input box. See the IAR documentation + * for additional information on how to set a preprocessor define in a project. + */ + +#include "mxc_sys.h" +#include "spix_regs.h" + +#ifndef _SPIX_H_ +#define _SPIX_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/// @brief Options for number of I/O pins to use during for each fetch stage +typedef enum { + SPIX_SINGLE_IO = MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_SINGLE, + SPIX_DUAL_IO = MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_DUAL_IO, + SPIX_QUAD_IO = MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_QUAD_IO +} spix_width_t; + +/// @brief Options for number of address bytes to use during fetch +typedef enum { + SPIX_3BYTE_FETCH_ADDR = 0, + SPIX_4BYTE_FETCH_ADDR = 1 +} spix_addr_size_t; + +/// @brief SPIX fetch configuration. +typedef struct { + spix_width_t cmd_width; ///< Number of I/O lines used for command SPI transaction. + spix_width_t addr_width; ///< Number of I/O lines used for address SPI transaction. + spix_width_t data_width; ///< Number of I/O lines used for data SPI transaction. + spix_addr_size_t addr_size; ///< Use 3 or 4 byte addresses for fetches. + uint8_t cmd; ///< Command value to initiate fetch. + uint8_t mode_clocks; ///< Number of SPI clocks required during mode phase of fetch. + uint8_t no_cmd_mode; ///< Read command sent only once. + uint16_t mode_data; ///< Data sent with mode clocks. +} spix_fetch_t; + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Configure SPI execute in place clocking. + * @param sys_cfg Pointer to system level configuration structure. + * @param mode SPI mode to use for the clocking. + * @param baud Frequency in hertz to set the clock to. May not be able to achieve with + * the given clock divider. + * @param sample Number of SPIX clocks to delay the sampling of the SDIO lines. Will use + * feedback mode if set to 0. + * @returns #E_NO_ERROR if everything is successful + */ +int SPIX_ConfigClock(const sys_cfg_spix_t *sys_cfg, uint32_t baud, uint8_t sample); + +/** + * @brief Configure SPI execute in place slave select. + * @param ssel Index of which slave select line to use. + * @param pol Polarity of slave select (0 for active low, 1 for active high). + * @param act_delay SPIX clocks between slave select assert and active SPI clock. + * @param inact_delay SPIX clocks between active SPI clock and slave select deassert. + */ +void SPIX_ConfigSlave(uint8_t ssel, uint8_t pol, uint8_t act_delay, uint8_t inact_delay); + +/** + * @brief Configure how the SPIX fetches data. + * @param fetch Pointer to configuration struct that describes how to fetch data. + */ +void SPIX_ConfigFetch(const spix_fetch_t *fetch); + +/** + * @brief Shutdown SPIX module. + * @param spix Pointer to SPIX regs. + * @returns #E_NO_ERROR if everything is successful + */ +int SPIX_Shutdown(mxc_spix_regs_t *spix); + + +#ifdef __cplusplus +} +#endif + +#endif /* _SPIX_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.c new file mode 100644 index 0000000..b54ef9c --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.c @@ -0,0 +1,389 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21839 $ + * + ******************************************************************************/ + +#include +#include "mxc_assert.h" +#include "tmr.h" + +static tmr_prescale_t prescaler[MXC_CFG_TMR_INSTANCES]; + +/******************************************************************************/ +int TMR_Init(mxc_tmr_regs_t *tmr, tmr_prescale_t prescale, const sys_cfg_tmr_t *sysCfg) +{ + int err; + int tmrNum; + + //get the timer number + tmrNum = MXC_TMR_GET_IDX(tmr); + + //check for valid pointer + MXC_ASSERT(tmrNum >= 0); + + //steup system GPIO config + if((err = SYS_TMR_Init(tmr, sysCfg)) != E_NO_ERROR) + return err; + + //save the prescale value for this timer + prescaler[tmrNum] = prescale; + + //Disable timer and clear settings + tmr->ctrl = 0; + + //reset all counts to 0 + tmr->count32 = 0; + tmr->count16_0 = 0; + tmr->count16_1 = 0; + + // Clear interrupt flag + tmr->intfl = MXC_F_TMR_INTFL_TIMER0 | MXC_F_TMR_INTFL_TIMER1; + + return E_NO_ERROR; +} + +/******************************************************************************/ +void TMR32_Config(mxc_tmr_regs_t *tmr, const tmr32_cfg_t *config) +{ + //stop timer + TMR32_Stop(tmr); + + //setup timer configuration register + //clear tmr2x16 (32bit mode), mode and polarity bits + tmr->ctrl &= ~(MXC_F_TMR_CTRL_TMR2X16 | MXC_F_TMR_CTRL_MODE | + MXC_F_TMR_CTRL_POLARITY); + + //set mode and polarity + tmr->ctrl |= ((config->mode << MXC_F_TMR_CTRL_MODE_POS) | + (config->polarity << MXC_F_TMR_CTRL_POLARITY_POS)); + + //setup timer Tick registers + tmr->term_cnt32 = config->compareCount; + + return; +} + +/******************************************************************************/ +void TMR32_PWMConfig(mxc_tmr_regs_t *tmr, const tmr32_cfg_pwm_t *config) +{ + //stop timer + TMR32_Stop(tmr); + + //setup timer configuration register + //clear tmr2x16 (32bit mode), mode and polarity bits + tmr->ctrl &= ~(MXC_F_TMR_CTRL_TMR2X16 | MXC_F_TMR_CTRL_MODE | + MXC_F_TMR_CTRL_POLARITY); + + //set mode and polarity + tmr->ctrl |= ((TMR32_MODE_PWM << MXC_F_TMR_CTRL_MODE_POS) | + (config->polarity << MXC_F_TMR_CTRL_POLARITY_POS)); + + tmr->pwm_cap32 = config->dutyCount; + + //setup timer Tick registers + tmr->count32 = 0; + tmr->term_cnt32 = config->periodCount; + + return; +} + +/******************************************************************************/ +void TMR16_Config(mxc_tmr_regs_t *tmr, uint8_t index, const tmr16_cfg_t *config) +{ + //stop timer + TMR16_Stop(tmr, index); + + if(index > 0) { //configure timer 16_1 + + //setup timer configuration register + tmr->ctrl |= MXC_F_TMR_CTRL_TMR2X16; //1 = 16bit mode + + //set mode + if(config->mode) + tmr->ctrl |= MXC_F_TMR_CTRL_MODE_16_1; + else + tmr->ctrl &= ~MXC_F_TMR_CTRL_MODE_16_1; + + //setup timer Ticks registers + tmr->term_cnt16_1 = config->compareCount; + } else { //configure timer 16_0 + + //setup timer configuration register + tmr->ctrl |= MXC_F_TMR_CTRL_TMR2X16; //1 = 16bit mode + + //set mode + if(config->mode) + tmr->ctrl |= MXC_F_TMR_CTRL_MODE_16_0; + else + tmr->ctrl &= ~MXC_F_TMR_CTRL_MODE_16_0; + + //setup timer Ticks registers + tmr->term_cnt16_0 = config->compareCount; + } + + return; +} + +/******************************************************************************/ +void TMR32_Start(mxc_tmr_regs_t *tmr) +{ + int tmrNum; + uint32_t ctrl; + + //get the timer number + tmrNum = MXC_TMR_GET_IDX(tmr); + + //prescaler gets reset to 0 when timer is disabled + //set the prescale to the saved value for this timer + ctrl = tmr->ctrl; + ctrl &= ~(MXC_F_TMR_CTRL_PRESCALE); //clear prescaler bits + ctrl |= prescaler[tmrNum] << MXC_F_TMR_CTRL_PRESCALE_POS; //set prescaler + ctrl |= MXC_F_TMR_CTRL_ENABLE0; //set enable to start the timer + + tmr->ctrl = ctrl; + + return; +} + +/******************************************************************************/ +void TMR16_Start(mxc_tmr_regs_t *tmr, uint8_t index) +{ + int tmrNum; + uint32_t ctrl; + + //get the timer number + tmrNum = MXC_TMR_GET_IDX(tmr); + + ctrl = tmr->ctrl; + + //prescaler gets reset to 0 when both 16 bit timers are disabled + //set the prescale to the saved value for this timer if is is not already set + if((ctrl & MXC_F_TMR_CTRL_PRESCALE) != ((uint32_t)prescaler[tmrNum] << MXC_F_TMR_CTRL_PRESCALE_POS)) { + ctrl &= ~(MXC_F_TMR_CTRL_PRESCALE); //clear prescaler bits + ctrl |= prescaler[tmrNum] << MXC_F_TMR_CTRL_PRESCALE_POS; //set prescaler + } + + if(index > 0) + ctrl |= MXC_F_TMR_CTRL_ENABLE1; //start timer 16_1 + else + ctrl |= MXC_F_TMR_CTRL_ENABLE0; //start timer 16_0 + + tmr->ctrl = ctrl; + + return; +} + +/******************************************************************************/ +uint32_t TMR_GetPrescaler(mxc_tmr_regs_t *tmr) +{ + int tmrNum; + + //get the timer number + tmrNum = MXC_TMR_GET_IDX(tmr); + + return ((uint32_t)prescaler[tmrNum]); +} + + +/******************************************************************************/ +int TMR32_GetPWMTicks(mxc_tmr_regs_t *tmr, uint8_t dutyPercent, uint32_t freq, uint32_t *dutyTicks, uint32_t *periodTicks) +{ + uint32_t timerClock; + uint32_t prescale; + uint64_t ticks; + + if(dutyPercent > 100) + return E_BAD_PARAM; + + if(freq == 0) + return E_BAD_PARAM; + + timerClock = SYS_TMR_GetFreq(tmr); + prescale = TMR_GetPrescaler(tmr); + + if(timerClock == 0 || prescale > TMR_PRESCALE_DIV_2_12) + return E_UNINITIALIZED; + + ticks = timerClock / (1 << (prescale & 0xF)) / freq; + + //make sure ticks is within a 32 bit value + if (!(ticks & 0xffffffff00000000) && (ticks & 0xffffffff)) { + *periodTicks = ticks; + + *dutyTicks = ((uint64_t)*periodTicks * dutyPercent) / 100; + + return E_NO_ERROR; + } + + return E_INVALID; +} + +/******************************************************************************/ +int TMR32_TimeToTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks) +{ + uint32_t unit_div0, unit_div1; + uint32_t timerClock; + uint32_t prescale; + uint64_t temp_ticks; + + timerClock = SYS_TMR_GetFreq(tmr); + prescale = TMR_GetPrescaler(tmr); + + if(timerClock == 0 || prescale > TMR_PRESCALE_DIV_2_12) + return E_UNINITIALIZED; + + switch (units) { + case TMR_UNIT_NANOSEC: + unit_div0 = 1000000; + unit_div1 = 1000; + break; + case TMR_UNIT_MICROSEC: + unit_div0 = 1000; + unit_div1 = 1000; + break; + case TMR_UNIT_MILLISEC: + unit_div0 = 1; + unit_div1 = 1000; + break; + case TMR_UNIT_SEC: + unit_div0 = 1; + unit_div1 = 1; + break; + default: + return E_BAD_PARAM; + } + + temp_ticks = (uint64_t)time * (timerClock / unit_div0) / (unit_div1 * (1 << (prescale & 0xF))); + + //make sure ticks is within a 32 bit value + if (!(temp_ticks & 0xffffffff00000000) && (temp_ticks & 0xffffffff)) { + *ticks = temp_ticks; + return E_NO_ERROR; + } + + return E_INVALID; +} + +/******************************************************************************/ +int TMR16_TimeToTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint16_t *ticks) +{ + uint32_t unit_div0, unit_div1; + uint32_t timerClock; + uint32_t prescale; + uint64_t temp_ticks; + + timerClock = SYS_TMR_GetFreq(tmr); + prescale = TMR_GetPrescaler(tmr); + + if(timerClock == 0 || prescale > TMR_PRESCALE_DIV_2_12) + return E_UNINITIALIZED; + + switch (units) { + case TMR_UNIT_NANOSEC: + unit_div0 = 1000000; + unit_div1 = 1000; + break; + case TMR_UNIT_MICROSEC: + unit_div0 = 1000; + unit_div1 = 1000; + break; + case TMR_UNIT_MILLISEC: + unit_div0 = 1; + unit_div1 = 1000; + break; + case TMR_UNIT_SEC: + unit_div0 = 1; + unit_div1 = 1; + break; + default: + return E_BAD_PARAM; + } + + temp_ticks = (uint64_t)time * (timerClock / unit_div0) / (unit_div1 * (1 << (prescale & 0xF))); + + //make sure ticks is within a 32 bit value + if (!(temp_ticks & 0xffffffffffff0000) && (temp_ticks & 0xffff)) { + *ticks = temp_ticks; + return E_NO_ERROR; + } + + return E_INVALID; +} + + +/******************************************************************************/ +int TMR_TicksToTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units) +{ + uint64_t temp_time = 0; + + uint32_t timerClock = SYS_TMR_GetFreq(tmr); + uint32_t prescale = TMR_GetPrescaler(tmr); + + if(timerClock == 0 || prescale > TMR_PRESCALE_DIV_2_12) + return E_UNINITIALIZED; + + tmr_unit_t temp_unit = TMR_UNIT_NANOSEC; + temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000000); + if (!(temp_time & 0xffffffff00000000)) { + *time = temp_time; + *units = temp_unit; + return E_NO_ERROR; + } + + temp_unit = TMR_UNIT_MICROSEC; + temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000); + if (!(temp_time & 0xffffffff00000000)) { + *time = temp_time; + *units = temp_unit; + return E_NO_ERROR; + } + + temp_unit = TMR_UNIT_MILLISEC; + temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / timerClock; + if (!(temp_time & 0xffffffff00000000)) { + *time = temp_time; + *units = temp_unit; + return E_NO_ERROR; + } + + temp_unit = TMR_UNIT_SEC; + temp_time = (uint64_t)ticks * (1 << (prescale & 0xF)) / timerClock; + if (!(temp_time & 0xffffffff00000000)) { + *time = temp_time; + *units = temp_unit; + return E_NO_ERROR; + } + + return E_INVALID; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.h new file mode 100644 index 0000000..e997a7e --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.h @@ -0,0 +1,619 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 14:44:55 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22017 $ + * + ******************************************************************************/ + +/** + * @file tmr.h + * @addtogroup timer Timer + * @{ + * @brief This is the high level API for the general purpose timer module + * + */ + +#ifndef _TIMER_H +#define _TIMER_H + +#include "mxc_config.h" +#include "tmr_regs.h" +#include "mxc_sys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +///@brief Define values for units of time +typedef enum { + /** nanosecond */ + TMR_UNIT_NANOSEC = 0, + /** microsecond */ + TMR_UNIT_MICROSEC, + /** millisecond */ + TMR_UNIT_MILLISEC, + /** second */ + TMR_UNIT_SEC, +} tmr_unit_t; + +///@brief Defines timer modes for 32-bit timers +typedef enum { + TMR32_MODE_ONE_SHOT = MXC_V_TMR_CTRL_MODE_ONE_SHOT, + TMR32_MODE_CONTINUOUS = MXC_V_TMR_CTRL_MODE_CONTINUOUS, + TMR32_MODE_COUNTER = MXC_V_TMR_CTRL_MODE_COUNTER, + TMR32_MODE_PWM = MXC_V_TMR_CTRL_MODE_PWM, + TMR32_MODE_CAPTURE = MXC_V_TMR_CTRL_MODE_CAPTURE, + TMR32_MODE_COMPARE = MXC_V_TMR_CTRL_MODE_COMPARE, + TMR32_MODE_GATED = MXC_V_TMR_CTRL_MODE_GATED, + TMR32_MODE_MEASURE = MXC_V_TMR_CTRL_MODE_MEASURE +} tmr32_mode_t; + +///@brief Defines timer modes for 16-bit timers +///@note 16-bit times only support One Shot and Continuous timers +typedef enum { + TMR16_MODE_ONE_SHOT = MXC_V_TMR_CTRL_MODE_ONE_SHOT, + TMR16_MODE_CONTINUOUS = MXC_V_TMR_CTRL_MODE_CONTINUOUS +} tmr16_mode_t; + +/// @brief Defines prescaler clock divider +typedef enum { + // divide input clock by 2^0 = 1 + TMR_PRESCALE_DIV_2_0 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1, + // divide input clock by 2^1 = 2 + TMR_PRESCALE_DIV_2_1 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2, + // divide input clock by 2^2 = 4 + TMR_PRESCALE_DIV_2_2 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4, + // divide input clock by 2^3 = 8 + TMR_PRESCALE_DIV_2_3 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_8, + // divide input clock by 2^4 = 16 + TMR_PRESCALE_DIV_2_4 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_16, + // divide input clock by 2^5 = 32 + TMR_PRESCALE_DIV_2_5 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_32, + // divide input clock by 2^6 = 64 + TMR_PRESCALE_DIV_2_6 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_64, + // divide input clock by 2^7 = 128 + TMR_PRESCALE_DIV_2_7 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_128, + // divide input clock by 2^8 = 256 + TMR_PRESCALE_DIV_2_8 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_256, + // divide input clock by 2^9 = 512 + TMR_PRESCALE_DIV_2_9 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_512, + // divide input clock by 2^10 = 1024 + TMR_PRESCALE_DIV_2_10 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1024, + // divide input clock by 2^11 = 2048 + TMR_PRESCALE_DIV_2_11 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2048, + // divide input clock by 2^12 = 4096 + TMR_PRESCALE_DIV_2_12 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4096, +} tmr_prescale_t; + +/// @brief Defines the polarity bit for pwm timer +typedef enum { + TMR_POLARITY_UNUSED = 0, + + TMR_POLARITY_INIT_LOW = 0, ///GPIO initial output level = low + TMR_POLARITY_INIT_HIGH = 1, ///GPIO initial output level = high + + TMR_POLARITY_RISING_EDGE = 0, ///timer trigger on GPIO rising edge + TMR_POLARITY_FALLING_EDGE = 1, ///timer trigger on GPIO falling edge +} tmr_polarity_t; + +/// @brief Defines the polarity bit for pwm timer +typedef enum { + TMR_PWM_INVERTED = 0, ///duty cycle = low pulse + TMR_PWM_NONINVERTED, ///duty cycle = high pulse +} tmr_pwm_polarity_t; + +/// @brief 32bit Timer Configurations (non-PWM) +typedef struct { + tmr32_mode_t mode; /// Desired timer mode + tmr_polarity_t polarity; /// Polarity for GPIO + uint32_t compareCount; /// Ticks to stop, reset back to 1, or compare timer +} tmr32_cfg_t; + +/// @brief PWM Mode Configurations +typedef struct { + tmr_pwm_polarity_t polarity; /// PWM polarity + uint32_t periodCount; /// PWM period in timer counts + uint32_t dutyCount; /// PWM duty in timer counts +} tmr32_cfg_pwm_t; + +/// @brief 16bit Timer Configurations +typedef struct { + tmr16_mode_t mode; /// Desired timer mode (only supports one shot or continuous timers) + uint16_t compareCount; /// Ticks to stop or reset timer +} tmr16_cfg_t; + + + +/** + * @brief Initializes the timer to a known state. + * @details This function initializes the timer to a known state and saves the + * prescaler. The timer will be left disabled. TMR_Init should be called + * before TMR_Config. + * + * @param tmr timer module to operate on + * @param prescale clock divider for the timer clock + * @param cfg pointer to timer system GPIO configuration + * (can be NULL if not using GPIO timer input/output functions) + * + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int TMR_Init(mxc_tmr_regs_t *tmr, tmr_prescale_t prescale, const sys_cfg_tmr_t *sysCfg); + +/** + * @brief Configures the timer in the specified mode. + * @details The parameters in config structure must be set before calling this function. + * This function should be used for configuring the timer in all 32 bit modes other than PWM. + * @note The timer cannot be running when this function is called + * + * @param tmr timer module to operate on + * @param config pointer to timer configuration + * + */ +void TMR32_Config(mxc_tmr_regs_t *tmr, const tmr32_cfg_t *config); + +/** + * @brief Configures the timer in PWM mode. + * @details The parameters in config structure must be set before calling this function. + * This function should be used for configuring the timer in PWM mode only. + * @note The timer cannot be running when this function is called + * + * @param tmr timer module to operate on + * @param config pointer to timer configuration + * + */ +void TMR32_PWMConfig(mxc_tmr_regs_t *tmr, const tmr32_cfg_pwm_t *config); + +/** + * @brief Configures the timer in the specified mode. + * @details The parameters in config structure must be set before calling this function. + * This function should be used for configuring the timer in all 16 bit modes. + * @note The timer cannot be running when this function is called + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * @param config pointer to timer configuration + * + */ +void TMR16_Config(mxc_tmr_regs_t *tmr, uint8_t index, const tmr16_cfg_t *config); + +/** + * @brief Starts the specified timer. + * + * @param tmr timer module to operate on + * + */ +void TMR32_Start(mxc_tmr_regs_t *tmr); + +/** + * @brief Starts the specified timer. + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + */ +void TMR16_Start(mxc_tmr_regs_t *tmr, uint8_t index); + +/** + * @brief Stops the specified 32 bit timer. + * @details All other timer states are left unchanged. + * + * @param tmr timer module to operate on + * + */ +__STATIC_INLINE void TMR32_Stop(mxc_tmr_regs_t *tmr) +{ + tmr->ctrl &= ~MXC_F_TMR_CTRL_ENABLE0; +} + +/** + * @brief Stop the specified 16 bit timer. + * @details All other timer states are left unchanged. + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + */ +__STATIC_INLINE void TMR16_Stop(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + tmr->ctrl &= ~MXC_F_TMR_CTRL_ENABLE1; + else + tmr->ctrl &= ~MXC_F_TMR_CTRL_ENABLE0; +} + +/** + * @brief Determines if the timer is running + * + * @param tmr timer module to operate on + * + * @return 0 = timer is off, non-zero = timer is on + */ +__STATIC_INLINE uint32_t TMR32_IsActive(mxc_tmr_regs_t *tmr) +{ + return (tmr->ctrl & MXC_F_TMR_CTRL_ENABLE0); +} + +/** + * @brief Determines if the timer is running + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + * @return 0 = timer is off, non-zero = timer is on + */ +__STATIC_INLINE uint32_t TMR16_IsActive(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + return (tmr->ctrl & MXC_F_TMR_CTRL_ENABLE1); + else + return (tmr->ctrl & MXC_F_TMR_CTRL_ENABLE0); +} + +/** + * @brief Enables the timer's interrupt + * + * @param tmr timer module to operate on + * + */ +__STATIC_INLINE void TMR32_EnableINT(mxc_tmr_regs_t *tmr) +{ + tmr->inten |= MXC_F_TMR_INTEN_TIMER0; +} + +/** + * @brief Enables the timer's interrupt + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + */ +__STATIC_INLINE void TMR16_EnableINT(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + tmr->inten |= MXC_F_TMR_INTEN_TIMER1; + else + tmr->inten |= MXC_F_TMR_INTEN_TIMER0; +} + +/** + * @brief Disables the timer's interrupt + * + * @param tmr timer module to operate on + * + */ +__STATIC_INLINE void TMR32_DisableINT(mxc_tmr_regs_t *tmr) +{ + tmr->inten &= ~MXC_F_TMR_INTEN_TIMER0; +} + +/** + * @brief Disables the timer's interrupt + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + */ +__STATIC_INLINE void TMR16_DisableINT(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + tmr->inten &= ~MXC_F_TMR_INTEN_TIMER1; + else + tmr->inten &= ~MXC_F_TMR_INTEN_TIMER0; +} + +/** + * @brief Gets the timer's interrupt flag + * + * @param tmr timer module to operate on + * + * @return 0 = flag not set, non-zero = flag is set + */ +__STATIC_INLINE uint32_t TMR32_GetFlag(mxc_tmr_regs_t *tmr) +{ + return (tmr->intfl & MXC_F_TMR_INTFL_TIMER0); +} + +/** + * @brief Gets the timer's interrupt flag + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + * @return 0 = flag not set, non-zero = flag is set + */ +__STATIC_INLINE uint32_t TMR16_GetFlag(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + return (tmr->intfl & MXC_F_TMR_INTFL_TIMER1); + else + return (tmr->intfl & MXC_F_TMR_INTFL_TIMER0); +} + +/** + * @brief Clears the timer interrupt flag + * + * @param tmr timer module to operate on + * + */ +__STATIC_INLINE void TMR32_ClearFlag(mxc_tmr_regs_t *tmr) +{ + tmr->intfl = MXC_F_TMR_INTFL_TIMER0; +} + +/** + * @brief Clears the timer interrupt flag for the specified index + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * + */ +__STATIC_INLINE void TMR16_ClearFlag(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + tmr->intfl = MXC_F_TMR_INTFL_TIMER1; + else + tmr->intfl = MXC_F_TMR_INTFL_TIMER0; +} + +/** + * @brief Set the current tick value to start counting from. + * + * @param tmr timer module to operate on + * @param count value to set the current ticks + * + */ +__STATIC_INLINE void TMR32_SetCount(mxc_tmr_regs_t *tmr, uint32_t count) +{ + tmr->count32 = count; +} + +/** + * @brief Set the current tick value to start counting from. + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * @param count value to set the current ticks + * + */ +__STATIC_INLINE void TMR16_SetCount(mxc_tmr_regs_t *tmr, uint8_t index, uint16_t count) +{ + if (index) + tmr->count16_1 = count; + else + tmr->count16_0 = count; +} + +/** + * @brief Gets the most current count value. + * + * @param tmr timer module to operate on + * + * @return current count value in ticks + */ +__STATIC_INLINE uint32_t TMR32_GetCount(mxc_tmr_regs_t *tmr) +{ + return (tmr->count32); +} + +/** + * @brief Gets the most current count value. + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer(0 = 16_0 or 1 = 16_1) + * + * @return current count value in ticks + */ +__STATIC_INLINE uint32_t TMR16_GetCount(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if(index) + return tmr->count16_1; + else + return tmr->count16_0; +} + +/** + * @brief Gets the most recent capture value. + * @details Used in Capture or Measure timer modes + * + * @param tmr timer module to operate on + * + * @return capture value in ticks + */ +__STATIC_INLINE uint32_t TMR32_GetCapture(mxc_tmr_regs_t *tmr) +{ + return (tmr->pwm_cap32); +} + +/** + * @brief Set a new compare tick value for timer + * @details Depending on the timer mode this is the tick value to + * stop the timer, reset ticks to 1, or compare the timer + * + * @param tmr timer module to operate on + * @param count new terminal/compare value in timer counts + * + */ +__STATIC_INLINE void TMR32_SetCompare(mxc_tmr_regs_t *tmr, uint32_t count) +{ + tmr->term_cnt32 = count; +} + +/** + * @brief Get compare tick value for timer + * @param tmr timer module to operate on + * @return compare value in ticks + * + */ +__STATIC_INLINE uint32_t TMR32_GetCompare(mxc_tmr_regs_t *tmr) +{ + return tmr->term_cnt32; +} + +/** + * @brief Set a new compare tick value for timer + * @details Depending on the timer mode this is the tick value to + * stop the timer, reset ticks to 1, or compare the timer + * + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * @param count new terminal/compare value in timer counts + * + */ +__STATIC_INLINE void TMR16_SetCompare(mxc_tmr_regs_t *tmr, uint8_t index, uint16_t count) +{ + if (index) + tmr->term_cnt16_1 = count; + else + tmr->term_cnt16_0 = count; +} + +/** + * @brief Get compare tick value for timer + * @param tmr timer module to operate on + * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) + * @return compare value in ticks + * + */ +__STATIC_INLINE uint32_t TMR16_GetCompare(mxc_tmr_regs_t *tmr, uint8_t index) +{ + if (index) + return tmr->term_cnt16_1; + return tmr->term_cnt16_0; +} + +/** + * @brief Returns the prescale value used by the timer + * + * @param tmr timer module to operate on + * + * @returns prescaler + */ +uint32_t TMR_GetPrescaler(mxc_tmr_regs_t *tmr); + +/** + * @brief Set a new duty cycle when the timer is used in PWM mode. + * + * @param tmr timer module to operate on + * @param dutyCount duty cycle value in timer counts + * + */ +__STATIC_INLINE void TMR32_SetDuty(mxc_tmr_regs_t *tmr, uint32_t dutyCount) +{ + tmr->pwm_cap32 = dutyCount; +} + +/** + * @brief Set a new duty cycle when the timer is used in PWM mode. + * + * @param tmr timer module to operate on + * @param dutyPercent duty cycle value in percent (0 to 100%) + * + */ +__STATIC_INLINE void TMR32_SetDutyPer(mxc_tmr_regs_t *tmr, uint32_t dutyPercent) +{ + uint32_t periodCount = tmr->term_cnt32; + tmr->pwm_cap32 = ((uint64_t)periodCount * dutyPercent) / 100; +} + +/** + * @brief Set a new period value for PWM timer + * + * @param tmr timer module to operate on + * @param count new period value in timer counts + * + */ +__STATIC_INLINE void TMR32_SetPeriod(mxc_tmr_regs_t *tmr, uint32_t period) +{ + tmr->term_cnt32 = period; +} + +/** + * @brief Converts frequency and duty cycle % to period and duty ticks + * @note TMR_Init should be called before this function to set the prescaler + * + * @param tmr timer module to operate on + * @param dutyPercent duty cycle in percent (0 to 100%) + * @param freq frequency of pwm signal in Hz + * @param dutyTicks calculated duty cycle in ticks + * @param periodTicks calculated period in ticks + * + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + * + */ +int TMR32_GetPWMTicks(mxc_tmr_regs_t *tmr, uint8_t dutyPercent, uint32_t freq, uint32_t *dutyTicks, uint32_t *periodTicks); + +/** + * @brief Converts a time and units to a number of ticks for the 32-bit timer. + * @note TMR_Init should be called before this function to set the prescaler + * + * @param tmr timer module to operate on + * @param time time value. + * @param unit time units. + * @param ticks calculated number of ticks. + * + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int TMR32_TimeToTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks); + +/** + * @brief Converts a time and units to a number of ticks for the 16-bit timer. + * @note TMR_Init should be called before this function to set the prescaler + * + * @param tmr timer module to operate on + * @param time time value. + * @param unit time units. + * @param ticks calculated number of ticks. + * + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int TMR16_TimeToTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint16_t *ticks); + +/** + * @brief Converts a number of ticks to a time and units for the timer. + * @note TMR_Init should be called before this function to set the prescaler + * + * @param tmr timer module to operate on + * @param ticks number of ticks. + * @param time calculated time value. + * @param units calculated time units. + * + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int TMR_TicksToTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _TIMER_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr_utils.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr_utils.c new file mode 100644 index 0000000..14f2181 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr_utils.c @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21839 $ + * + ******************************************************************************/ + +/** + * @file tmr_utils.c + * @brief Timer utility functions. + */ + +/***** Includes *****/ +#include +#include "mxc_assert.h" +#include "tmr.h" +#include "tmr_utils.h" + +/***** Definitions *****/ + +/***** Globals *****/ + +/***** Functions *****/ + +/******************************************************************************/ +void TMR_Delay(mxc_tmr_regs_t* tmr, unsigned long us) +{ + TMR_TO_Start(tmr, us); + + while(TMR_TO_Check(tmr) != E_TIME_OUT) {} +} + +/******************************************************************************/ +void TMR_TO_Start(mxc_tmr_regs_t* tmr, unsigned long us) +{ + unsigned clk_shift = 0; + uint64_t max_us; + uint32_t ticks; + + // Adjust the clk shift amout by how long the timeout is + // Start with the fastest clock to give the greatest accuracy + do { + max_us = (uint64_t)((0xFFFFFFFFUL / ((uint64_t)SystemCoreClock >> clk_shift++)) * 1000000UL); + } while(us > max_us); + + // Calculate the number of timer ticks we need to wait + TMR_Init(tmr, (tmr_prescale_t)clk_shift, NULL); + TMR32_TimeToTicks(tmr, us, TMR_UNIT_MICROSEC, &ticks); + + // Initialize the timer in one-shot mode + tmr32_cfg_t cfg; + cfg.mode = TMR32_MODE_ONE_SHOT; + cfg.compareCount = ticks; + TMR32_Stop(tmr); + TMR32_Config(tmr, &cfg); + + TMR32_ClearFlag(tmr); + TMR32_Start(tmr); +} + +/******************************************************************************/ +int TMR_TO_Check(mxc_tmr_regs_t* tmr) +{ + if(TMR32_GetFlag(tmr)) { + return E_TIME_OUT; + } + return E_NO_ERROR; +} + +/******************************************************************************/ +void TMR_TO_Stop(mxc_tmr_regs_t* tmr) +{ + TMR32_Stop(tmr); + TMR32_SetCount(tmr, 0x0); +} + +/******************************************************************************/ +void TMR_TO_Clear(mxc_tmr_regs_t* tmr) +{ + TMR32_ClearFlag(tmr); + TMR32_SetCount(tmr, 0x0); +} + +/******************************************************************************/ +unsigned TMR_TO_Elapsed(mxc_tmr_regs_t* tmr) +{ + uint32_t elapsed; + tmr_unit_t units; + + TMR_TicksToTime(tmr, TMR32_GetCount(tmr), &elapsed, &units); + + switch(units) { + case TMR_UNIT_NANOSEC: + default: + return (elapsed / 1000); + case TMR_UNIT_MICROSEC: + return (elapsed); + case TMR_UNIT_MILLISEC: + return (elapsed * 1000); + case TMR_UNIT_SEC: + return (elapsed * 1000000); + } +} + +/******************************************************************************/ +unsigned TMR_TO_Remaining(mxc_tmr_regs_t* tmr) +{ + uint32_t remaining_ticks, remaining_time; + tmr_unit_t units; + + remaining_ticks = TMR32_GetCompare(tmr) - TMR32_GetCount(tmr); + TMR_TicksToTime(tmr, remaining_ticks, &remaining_time, &units); + + switch(units) { + case TMR_UNIT_NANOSEC: + default: + return (remaining_time / 1000); + case TMR_UNIT_MICROSEC: + return (remaining_time); + case TMR_UNIT_MILLISEC: + return (remaining_time * 1000); + case TMR_UNIT_SEC: + return (remaining_time * 1000000); + } +} + +/******************************************************************************/ +void TMR_SW_Start(mxc_tmr_regs_t* tmr) +{ + TMR_TO_Start(tmr, 0xFFFFFFFF); +} + +/******************************************************************************/ +unsigned TMR_SW_Stop(mxc_tmr_regs_t* tmr) +{ + unsigned elapsed = TMR_TO_Elapsed(tmr); + TMR_TO_Stop(tmr); + return elapsed; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr_utils.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr_utils.h new file mode 100644 index 0000000..a671237 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr_utils.h @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 09:04:59 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22006 $ + * + ******************************************************************************/ + +/** + * @file tmr_utils.h + * @brief Timer utility functions. + */ + +#ifndef _TMR_UTILS_H +#define _TMR_UTILS_H + +/***** Includes *****/ +#include "mxc_config.h" +#include "tmr_regs.h" +#include "mxc_sys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ +#define SEC(s) (((unsigned long)s) * 1000000UL) +#define MSEC(ms) (ms * 1000UL) +#define USEC(us) (us) + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Delays for the specified number of microseconds. + * @param tmr TMR module to operate on + * @param us Number of microseconds to delay. + */ +void TMR_Delay(mxc_tmr_regs_t* tmr, unsigned long us); + +/** + * @brief Start the timeout time for the specified number of microseconds. + * @param tmr TMR module to operate on + * @param us Number of microseconds in the timeout. + */ +void TMR_TO_Start(mxc_tmr_regs_t* tmr, unsigned long us); + +/** + * @brief Check if the timeout has occured. + * @param tmr TMR module to operate on + * @returns E_NO_ERROR if the timeout has not occurred, E_TIME_OUT if it has. + */ +int TMR_TO_Check(mxc_tmr_regs_t* tmr); + +/** + * @brief Stops the timer for the timeout. + * @param tmr TMR module to operate on + */ +void TMR_TO_Stop(mxc_tmr_regs_t* tmr); + +/** + * @brief Clears the timeout flag. + * @param tmr TMR module to operate on + */ +void TMR_TO_Clear(mxc_tmr_regs_t* tmr); + +/** + * @brief Get the number of microseconds elapsed since to_start(). + * @param tmr TMR module to operate on + * @returns Number of microseconds since to_start(). + */ +unsigned TMR_TO_Elapsed(mxc_tmr_regs_t* tmr); + +/** + * @brief Get the number of microseconds remaining in the timeout. + * @param tmr TMR module to operate on + * @returns Number of microseconds since to_start(). + */ +unsigned TMR_TO_Remaining(mxc_tmr_regs_t* tmr); + +/** + * @brief Start the stopwatch. + */ +void TMR_SW_Start(mxc_tmr_regs_t* tmr); + +/** + * @brief Stop the stopwatch and return the number of microseconds that have elapsed. + * @param tmr TMR module to operate on + * @returns Number of microseconds since sw_start(). + */ +unsigned TMR_SW_Stop(mxc_tmr_regs_t* tmr); + +#ifdef __cplusplus +} +#endif + +#endif /* _TMR_UTILS_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/uart.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/uart.c new file mode 100644 index 0000000..643d385 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/uart.c @@ -0,0 +1,653 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-07-28 15:01:10 -0500 (Thu, 28 Jul 2016) $ + * $Revision: 23823 $ + * + ******************************************************************************/ + +/** + * @file uart.c + * @brief UART diver source. + */ + +/***** Includes *****/ +#include +#include "mxc_assert.h" +#include "mxc_lock.h" +#include "mxc_sys.h" +#include "uart.h" + +/***** Definitions *****/ +#define UART_ERRORS (MXC_F_UART_INTEN_RX_FIFO_OVERFLOW | \ + MXC_F_UART_INTEN_RX_FRAMING_ERR | \ + MXC_F_UART_INTEN_RX_PARITY_ERR) + +#define UART_READ_INTS (MXC_F_UART_INTEN_RX_FIFO_AF | \ + MXC_F_UART_INTEN_RX_FIFO_NOT_EMPTY | \ + MXC_F_UART_INTEN_RX_STALLED | \ + UART_ERRORS) + +#define UART_WRITE_INTS (MXC_F_UART_INTEN_TX_UNSTALLED | \ + MXC_F_UART_INTEN_TX_FIFO_AE) + +#define UART_RXFIFO_USABLE (MXC_UART_FIFO_DEPTH-3) + +/***** Globals *****/ + +// Saves the state of the non-blocking read requests +static uart_req_t *rx_states[MXC_CFG_UART_INSTANCES]; + +// Saves the state of the non-blocking write requests +static uart_req_t *tx_states[MXC_CFG_UART_INSTANCES]; + +/***** Functions *****/ +static void UART_WriteHandler(mxc_uart_regs_t *uart, uart_req_t *req, int uart_num); +static void UART_ReadHandler(mxc_uart_regs_t *uart, uart_req_t *req, int uart_num, + uint32_t flags); + +/******************************************************************************/ +int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t *sys_cfg) +{ + int err; + int uart_num; + uint32_t uart_clk; + uint8_t baud_shift; + uint16_t baud_div; + uint32_t baud, diff_baud; + uint32_t baud_1, diff_baud_1; + + // Check the input parameters + uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + // Set system level configurations + if(sys_cfg != NULL) { + if ((err = SYS_UART_Init(uart, cfg, sys_cfg)) != E_NO_ERROR) { + return err; + } + } + + // Initialize state pointers + rx_states[uart_num] = NULL; + tx_states[uart_num] = NULL; + + // Drain FIFOs and enable UART + uart->ctrl = 0; + uart->ctrl = (MXC_F_UART_CTRL_UART_EN | MXC_F_UART_CTRL_TX_FIFO_EN | + MXC_F_UART_CTRL_RX_FIFO_EN | + (UART_RXFIFO_USABLE << MXC_F_UART_CTRL_RTS_LEVEL_POS)); + + // Configure data size, stop bit, parity, cts, and rts + uart->ctrl |= ((cfg->size << MXC_F_UART_CTRL_DATA_SIZE_POS) | + (cfg->extra_stop << MXC_F_UART_CTRL_EXTRA_STOP_POS) | + (cfg->parity << MXC_F_UART_CTRL_PARITY_POS) | + (cfg->cts << MXC_F_UART_CTRL_CTS_EN_POS) | + (cfg->rts << MXC_F_UART_CTRL_RTS_EN_POS)); + + // Configure the baud rate and divisor + uart_clk = SYS_UART_GetFreq(uart); + MXC_ASSERT(uart_clk > 0); + + baud_shift = 2; + baud_div = (uart_clk / (cfg->baud * 4)); + + // Can not support higher frequencies + if(!baud_div) { + return E_NOT_SUPPORTED; + } + + // Decrease the divisor if baud_div is overflowing + while(baud_div > 0xFF) { + if(baud_shift == 0) { + return E_NOT_SUPPORTED; + } + baud_shift--; + baud_div = (uart_clk / (cfg->baud * (16 >> baud_shift))); + } + + // Adjust baud_div so we don't overflow with the calculations below + if(baud_div == 0xFF) { + baud_div = 0xFE; + } + if(baud_div == 0) { + baud_div = 1; + } + + // Figure out if the truncation increased the error + baud = (uart_clk / (baud_div * (16 >> baud_shift))); + baud_1 = (uart_clk / ((baud_div+1) * (16 >> baud_shift))); + + if(cfg->baud > baud) { + diff_baud = cfg->baud - baud; + } else { + diff_baud = baud - cfg->baud; + } + + if(cfg->baud > baud_1) { + diff_baud_1 = cfg->baud - baud_1; + } else { + diff_baud_1 = baud_1 - cfg->baud; + } + + if(diff_baud < diff_baud_1) { + uart->baud = ((baud_div & MXC_F_UART_BAUD_BAUD_DIVISOR) | + (baud_shift << MXC_F_UART_BAUD_BAUD_MODE_POS)); + } else { + uart->baud = (((baud_div+1) & MXC_F_UART_BAUD_BAUD_DIVISOR) | + (baud_shift << MXC_F_UART_BAUD_BAUD_MODE_POS)); + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int UART_Shutdown(mxc_uart_regs_t *uart) +{ + int uart_num, err; + uart_req_t *temp_req; + + uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + // Disable and clear interrupts + uart->inten = 0; + uart->intfl = uart->intfl; + + // Disable UART and FIFOS + uart->ctrl &= ~(MXC_F_UART_CTRL_UART_EN | MXC_F_UART_CTRL_TX_FIFO_EN | + MXC_F_UART_CTRL_RX_FIFO_EN); + + // Call all of the pending callbacks for this UART + if(rx_states[uart_num] != NULL) { + + // Save the request + temp_req = rx_states[uart_num]; + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + // Callback if not NULL + if(temp_req->callback != NULL) { + temp_req->callback(temp_req, E_SHUTDOWN); + } + } + + if(tx_states[uart_num] != NULL) { + + // Save the request + temp_req = tx_states[uart_num]; + + // Unlock this UART to write + mxc_free_lock((uint32_t*)&tx_states[uart_num]); + + // Callback if not NULL + if(temp_req->callback != NULL) { + temp_req->callback(temp_req, E_SHUTDOWN); + } + } + + // Clears system level configurations + if ((err = SYS_UART_Shutdown(uart)) != E_NO_ERROR) { + return err; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int UART_Write(mxc_uart_regs_t *uart, uint8_t* data, int len) +{ + int num, uart_num; + mxc_uart_fifo_regs_t *fifo; + + uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + if(data == NULL) { + return E_NULL_PTR; + } + + // Make sure the UART has been initialized + if(!(uart->ctrl & MXC_F_UART_CTRL_UART_EN)) { + return E_UNINITIALIZED; + } + + if(!(len > 0)) { + return E_NO_ERROR; + } + + // Lock this UART from writing + while(mxc_get_lock((uint32_t*)&tx_states[uart_num], 1) != E_NO_ERROR) {} + + // Get the FIFO for this UART + fifo = MXC_UART_GET_FIFO(uart_num); + + num = 0; + + while(num < len) { + + // Wait for TXFIFO to not be full + while((uart->tx_fifo_ctrl & MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY) == + MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY) {} + + // Write the data to the FIFO +#if(MXC_UART_REV == 0) + uart->intfl = MXC_F_UART_INTFL_TX_DONE; +#endif + fifo->tx = data[num++]; + } + + // Unlock this UART to write + mxc_free_lock((uint32_t*)&tx_states[uart_num]); + + return num; +} + +/******************************************************************************/ +int UART_Read(mxc_uart_regs_t *uart, uint8_t* data, int len, int *num) +{ + int num_local, remain, uart_num; + mxc_uart_fifo_regs_t *fifo; + + uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + if(data == NULL) { + return E_NULL_PTR; + } + + // Make sure the UART has been initialized + if(!(uart->ctrl & MXC_F_UART_CTRL_UART_EN)) { + return E_UNINITIALIZED; + } + + if(!(len > 0)) { + return E_NO_ERROR; + } + + // Lock this UART from reading + while(mxc_get_lock((uint32_t*)&rx_states[uart_num], 1) != E_NO_ERROR) {} + + // Get the FIFO for this UART + fifo = MXC_UART_GET_FIFO(uart_num); + + num_local = 0; + remain = len; + while(remain) { + + // Save the data in the FIFO + while((uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY) && remain) { + data[num_local] = fifo->rx; + num_local++; + remain--; + } + + // Break if there is an error + if(uart->intfl & UART_ERRORS) { + break; + } + } + + // Save the number of bytes read if pointer is valid + if(num != NULL) { + *num = num_local; + } + + // Check for errors + if(uart->intfl & MXC_F_UART_INTFL_RX_FIFO_OVERFLOW) { + + // Clear errors and return error code + uart->intfl = UART_ERRORS; + + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + return E_OVERFLOW; + + } else if(uart->intfl & (MXC_F_UART_INTFL_RX_FRAMING_ERR | + MXC_F_UART_INTFL_RX_PARITY_ERR)) { + + // Clear errors and return error code + uart->intfl = UART_ERRORS; + + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + return E_COMM_ERR; + } + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + return num_local; +} + +/******************************************************************************/ +int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req) +{ + int uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + // Check the input parameters + if(req->data == NULL) { + return E_NULL_PTR; + } + + // Make sure the UART has been initialized + if(!(uart->ctrl & MXC_F_UART_CTRL_UART_EN)) { + return E_UNINITIALIZED; + } + + if(!(req->len > 0)) { + return E_NO_ERROR; + } + + // Attempt to register this write request + if(mxc_get_lock((uint32_t*)&tx_states[uart_num], (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + // Clear the number of bytes counter + req->num = 0; + + // Start the write + UART_WriteHandler(uart, req, uart_num); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req) +{ + int uart_num; + uint32_t flags; + + uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + if(req->data == NULL) { + return E_NULL_PTR; + } + + // Make sure the UART has been initialized + if(!(uart->ctrl & MXC_F_UART_CTRL_UART_EN)) { + return E_UNINITIALIZED; + } + + if(!(req->len > 0)) { + return E_NO_ERROR; + } + + // Attempt to register this write request + if(mxc_get_lock((uint32_t*)&rx_states[uart_num], (uint32_t)req) != E_NO_ERROR) { + return E_BUSY; + } + + // Clear the number of bytes counter + req->num = 0; + + // Start the read + flags = uart->intfl; + uart->intfl = flags; + UART_ReadHandler(uart, req, uart_num, flags); + + return E_NO_ERROR; +} + +/******************************************************************************/ +int UART_AbortAsync(uart_req_t *req) +{ + int uart_num; + + // Figure out if this was a read or write request, find the request, set to NULL + for(uart_num = 0; uart_num < MXC_CFG_UART_INSTANCES; uart_num++) { + if(req == rx_states[uart_num]) { + + // Disable read interrupts, clear flags. + MXC_UART_GET_UART(uart_num)->inten &= ~UART_READ_INTS; + MXC_UART_GET_UART(uart_num)->intfl = UART_READ_INTS; + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_ABORT); + } + + return E_NO_ERROR; + } + + if(req == tx_states[uart_num]) { + + // Disable write interrupts, clear flags. + MXC_UART_GET_UART(uart_num)->inten &= ~(UART_WRITE_INTS); + MXC_UART_GET_UART(uart_num)->intfl = UART_WRITE_INTS; + + // Unlock this UART to write + mxc_free_lock((uint32_t*)&tx_states[uart_num]); + + // Callback if not NULL + if(req->callback != NULL) { + req->callback(req, E_ABORT); + } + + return E_NO_ERROR; + } + } + + return E_BAD_PARAM; +} + +/******************************************************************************/ +void UART_Handler(mxc_uart_regs_t *uart) +{ + int uart_num; + uint32_t flags; + + uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + flags = uart->intfl; + uart->intfl = flags; + + // Figure out if this UART has an active Read request + if((rx_states[uart_num] != NULL) && (flags & UART_READ_INTS)) { + UART_ReadHandler(uart, rx_states[uart_num], uart_num, flags); + } + + // Figure out if this UART has an active Write request + if((tx_states[uart_num] != NULL) && (flags & (UART_WRITE_INTS))) { + + UART_WriteHandler(uart, tx_states[uart_num], uart_num); + } +} +/******************************************************************************/ +int UART_Busy(mxc_uart_regs_t *uart) +{ + int uart_num = MXC_UART_GET_IDX(uart); + MXC_ASSERT(uart_num >= 0); + + // Check to see if there are any ongoing transactions or if the UART is disabled + if(((tx_states[uart_num] == NULL) && + !(uart->tx_fifo_ctrl & MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY) && +#if(MXC_UART_REV == 0) + (uart->intfl & MXC_F_UART_INTFL_TX_DONE)) || +#else + (uart->idle & MXC_F_UART_IDLE_TX_RX_IDLE)) || +#endif + !(uart->ctrl & MXC_F_UART_CTRL_UART_EN)) { + + return E_NO_ERROR; + } + + return E_BUSY; +} + +/******************************************************************************/ +int UART_PrepForSleep(mxc_uart_regs_t *uart) +{ + if(UART_Busy(uart) != E_NO_ERROR) { + return E_BUSY; + } + + // Leave read interrupts enabled, if already enabled + uart->inten &= UART_READ_INTS; + + return E_NO_ERROR; +} + +/******************************************************************************/ +static void UART_WriteHandler(mxc_uart_regs_t *uart, uart_req_t *req, int uart_num) +{ + int avail, remain; + mxc_uart_fifo_regs_t *fifo; + + // Disable write interrupts + uart->inten &= ~(UART_WRITE_INTS); + + // Get the FIFO for this UART + fifo = MXC_UART_GET_FIFO(uart_num); + + // Refill the TX FIFO + avail = UART_NumWriteAvail(uart); + remain = req->len - req->num; + + while(avail && remain) { + + // Write the data to the FIFO +#if(MXC_UART_REV == 0) + uart->intfl = MXC_F_UART_INTFL_TX_DONE; +#endif + fifo->tx = req->data[req->num++]; + remain--; + avail--; + } + + // All of the bytes have been written to the FIFO + if(!remain) { + + // Unlock this UART to write + mxc_free_lock((uint32_t*)&tx_states[uart_num]); + + if(req->callback != NULL) { + req->callback(req, E_NO_ERROR); + } + + } else { + + // Interrupt when there is one byte left in the TXFIFO + uart->tx_fifo_ctrl = ((MXC_UART_FIFO_DEPTH - 1) << MXC_F_UART_TX_FIFO_CTRL_FIFO_AE_LVL_POS); + + // Enable almost empty interrupt + uart->inten |= (MXC_F_UART_INTEN_TX_FIFO_AE); + } +} + +/******************************************************************************/ +static void UART_ReadHandler(mxc_uart_regs_t *uart, uart_req_t *req, int uart_num, + uint32_t flags) +{ + int avail, remain; + mxc_uart_fifo_regs_t *fifo; + + // Disable interrupts + uart->inten &= ~UART_READ_INTS; + + // Get the FIFO for this UART, uart_num + fifo = MXC_UART_GET_FIFO(uart_num); + + // Save the data in the FIFO while we still need data + avail = UART_NumReadAvail(uart); + remain = req->len - req->num; + while(avail && remain) { + req->data[req->num++] = fifo->rx; + remain--; + avail--; + } + + // Check for errors + if(flags & MXC_F_UART_INTFL_RX_FIFO_OVERFLOW) { + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + if(req->callback != NULL) { + req->callback(req, E_OVERFLOW); + } + + return; + } + + if(flags & (MXC_F_UART_INTFL_RX_FRAMING_ERR | + MXC_F_UART_INTFL_RX_PARITY_ERR)) { + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + if(req->callback != NULL) { + req->callback(req, E_COMM_ERR); + } + + return; + } + + // Check to see if we're done receiving + if(remain == 0) { + + // Unlock this UART to read + mxc_free_lock((uint32_t*)&rx_states[uart_num]); + + if(req->callback != NULL) { + req->callback(req, E_NO_ERROR); + } + + return; + } + + if(remain == 1) { + uart->inten |= (MXC_F_UART_INTEN_RX_FIFO_NOT_EMPTY | UART_ERRORS); + + } else { + // Set the RX FIFO AF threshold + if(remain < UART_RXFIFO_USABLE) { + uart->rx_fifo_ctrl = ((remain - 1) << + MXC_F_UART_RX_FIFO_CTRL_FIFO_AF_LVL_POS); + } else { + uart->rx_fifo_ctrl = (UART_RXFIFO_USABLE << + MXC_F_UART_RX_FIFO_CTRL_FIFO_AF_LVL_POS); + } + uart->inten |= (MXC_F_UART_INTEN_RX_FIFO_AF | UART_ERRORS); + } +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/uart.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/uart.h new file mode 100644 index 0000000..0d57373 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/uart.h @@ -0,0 +1,271 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-21 16:16:33 -0500 (Tue, 21 Jun 2016) $ + * $Revision: 23447 $ + * + ******************************************************************************/ + +/** + * @file uart.h + * @brief UART driver header file. + */ + +#include "mxc_config.h" +#include "mxc_sys.h" +#include "uart_regs.h" + +#ifndef _UART_H_ +#define _UART_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/***** Definitions *****/ + +/// @brief Defines number of data bits per transmission/reception +typedef enum { + UART_DATA_SIZE_5_BITS = MXC_V_UART_CTRL_DATA_SIZE_5_BITS, + UART_DATA_SIZE_6_BITS = MXC_V_UART_CTRL_DATA_SIZE_6_BITS, + UART_DATA_SIZE_7_BITS = MXC_V_UART_CTRL_DATA_SIZE_7_BITS, + UART_DATA_SIZE_8_BITS = MXC_V_UART_CTRL_DATA_SIZE_8_BITS +} +uart_data_size_t; + +/// @brief Defines number of data bits per transmission/reception +typedef enum { + UART_PARITY_DISABLE = MXC_V_UART_CTRL_PARITY_DISABLE, + UART_PARITY_ODD = MXC_V_UART_CTRL_PARITY_ODD, + UART_PARITY_EVEN = MXC_V_UART_CTRL_PARITY_EVEN, + UART_PARITY_MARK = MXC_V_UART_CTRL_PARITY_MARK +} uart_parity_t; + +/// @brief UART configuration type. +typedef struct { + uint8_t extra_stop; ///< 0 for one stop bit, 1 for two stop bits. + uint8_t cts; ///< 1 to enable CTS. + uint8_t rts; ///< 1 to enable RTS. + uint32_t baud; ///< Baud rate in Hz. + uart_data_size_t size; ///< Number of bits in each character. + uart_parity_t parity; ///< Even or odd parity. +} uart_cfg_t; + +/** + * @brief Type alias for UART request structure + */ +typedef struct uart_req uart_req_t; + +/** + * @brief Type alias \c uart_async_callback for function signature: \code void callback)(uart_req_t* , int error_code) \endcode + * @param uart_req_t* Pointer to the transaction request. + * @param error_code Return code for the UART request. @see mxc_errors.h. + */ +typedef void (*uart_async_callback)(uart_req_t*, int); + +/// @brief UART Transaction request, must remain allocated until callback has completed. +struct uart_req { + uint8_t *data; ///< Data buffer for characters. + unsigned len; ///< Length of characters in data to send or receive. + unsigned num; ///< Number of characters actually sent or received. + uart_async_callback callback; ///< A callback function pointer with alias signature \c uart_async_callback +}; + + +/***** Globals *****/ + +/***** Function Prototypes *****/ + +/** + * @brief Initialize and enable UART module. + * @param uart Pointer to UART regs. + * @param cfg Pointer to UART configuration. + * @param sys_cfg Pointer to system configuration object + * @returns #E_NO_ERROR if everything is successful + */ +int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t *sys_cfg); + +/** + * @brief Shutdown UART module. + * @param uart Pointer to UART regs. + * @returns #E_NO_ERROR if everything is successful + */ +int UART_Shutdown(mxc_uart_regs_t *uart); + +/** + * @brief Write UART data. Will block until transaction is complete. + * @param uart Pointer to UART regs. + * @param data Pointer to buffer for write data. + * @param len Number of bytes to write. + * @note Will return once data has been put into FIFO, not necessarily transmitted. + * @returns Number of bytes written if successful, error if unsuccessful. + */ +int UART_Write(mxc_uart_regs_t *uart, uint8_t* data, int len); + +/** + * @brief Read UART data. Will block until transaction is complete. + * @param uart Pointer to UART regs. + * @param data Pointer to buffer for read data. + * @param len Number of bytes to read. + * @param num Optional pointer to number of bytes actually read. + * Pass NULL if undesired. + * @returns Number of bytes read is successful, error if unsuccessful. + */ +int UART_Read(mxc_uart_regs_t *uart, uint8_t* data, int len, int *num); + +/** + * @brief Asynchronously Write UART data. + * @param uart Pointer to UART regs. + * @param req Request for a UART transaction. + * @note Request struct must remain allocated until callback. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req); + +/** + * @brief Asynchronously Read UART data. + * @param uart Pointer to UART regs. + * @param req Pointer to request for a UART transaction. + * @note Request struct must remain allocated until callback. + * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. + */ +int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req); + +/** + * @brief Abort asynchronous request. + * @param req Pointer to request for a UART transaction. + * @returns #E_NO_ERROR if request aborted, error if unsuccessful. + */ +int UART_AbortAsync(uart_req_t *req); + +/** + * @brief UART interrupt handler. + * @details This function should be called by the application from the interrupt + * handler if UART interrupts are enabled. Alternately, this function + * can be periodically called by the application if UART interrupts are + * disabled. Only necessary to call this when using asynchronous functions. + * @param uart Pointer to UART regs. + */ +void UART_Handler(mxc_uart_regs_t *uart); + +/** + * @brief Check to see if the UART is busy. + * @param uart Pointer to UART regs. + * @returns #E_NO_ERROR if idle, #E_BUSY if in use. + */ +int UART_Busy(mxc_uart_regs_t *uart); + +/** + * @brief Attempt to prepare the UART for sleep. + * @param uart Pointer to UART regs. + * @details Checks for any ongoing transactions. Disables interrupts if the I2CM + is idle. + * @returns #E_NO_ERROR if ready to sleep, #E_BUSY if not ready for sleep. + */ +int UART_PrepForSleep(mxc_uart_regs_t *uart); + +/** + * @brief Enables the UART without overwriting existing configuration. + * @param uart Pointer to UART regs. + */ +__STATIC_INLINE void UART_Enable(mxc_uart_regs_t *uart) +{ + uart->ctrl |= (MXC_F_UART_CTRL_UART_EN | MXC_F_UART_CTRL_TX_FIFO_EN | + MXC_F_UART_CTRL_RX_FIFO_EN); +} + +/** + * @brief Drain all of the data in the RXFIFO. + * @param uart Pointer to UART regs. + */ +__STATIC_INLINE void UART_DrainRX(mxc_uart_regs_t *uart) +{ + uint32_t ctrl_save = uart->ctrl; + uart->ctrl = (ctrl_save & ~MXC_F_UART_CTRL_RX_FIFO_EN); + uart->ctrl = ctrl_save; +} + +/** + * @brief Drain all of the data in the TXFIFO. + * @param uart Pointer to UART regs. + */ +__STATIC_INLINE void UART_DrainTX(mxc_uart_regs_t *uart) +{ + uint32_t ctrl_save = uart->ctrl; + uart->ctrl = (ctrl_save & ~MXC_F_UART_CTRL_TX_FIFO_EN); + uart->ctrl = ctrl_save; +} + +/** + * @brief Write FIFO availability. + * @param uart Pointer to UART regs. + * @returns Number of empty bytes available in write FIFO. + */ +__STATIC_INLINE unsigned UART_NumWriteAvail(mxc_uart_regs_t *uart) +{ + return (MXC_UART_FIFO_DEPTH - (uart->tx_fifo_ctrl & MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY)); +} + +/** + * @brief Read FIFO availability. + * @param uart Pointer to UART regs. + * @returns Number of bytes in read FIFO. + */ +__STATIC_INLINE unsigned UART_NumReadAvail(mxc_uart_regs_t *uart) +{ + return (uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY); +} + +/** + * @brief Clear interrupt flags. + * @param uart Pointer to UART regs. + * @param mask Mask of interrupts to clear. + */ +__STATIC_INLINE void UART_ClearFlags(mxc_uart_regs_t *uart, uint32_t mask) +{ + uart->intfl = mask; +} + +/** + * @brief Get interrupt flags. + * @param uart Pointer to UART regs. + * @returns Mask of active flags. + */ +__STATIC_INLINE unsigned UART_GetFlags(mxc_uart_regs_t *uart) +{ + return (uart->intfl); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _UART_H_ */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt.c new file mode 100644 index 0000000..d9b9095 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt.c @@ -0,0 +1,286 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 15:44:11 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22024 $ + * + ******************************************************************************/ + +/** + * @file wdt.c + * @brief Watchdog driver source. + */ + +#include +#include "wdt.h" + +static uint32_t interruptEnable = 0; //keeps track to interrupts to enable in start function + +/******************************************************************************/ +int WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg, uint8_t unlock_key) +{ + if ((wdt == NULL) || (cfg == NULL)) + return E_NULL_PTR; + + //setup watchdog clock + SYS_WDT_Init(wdt, cfg); + + //unlock ctrl to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable all interrupts + interruptEnable = 0; + wdt->enable = interruptEnable; + + //enable the watchdog clock and clear all other settings + wdt->ctrl = MXC_F_WDT_CTRL_EN_CLOCK; + + //clear all interrupt flags + wdt->flags = WDT_FLAGS_CLEAR_ALL; + + //lock ctrl to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_EnableInt(mxc_wdt_regs_t *wdt, wdt_period_t int_period, uint8_t unlock_key) +{ + //unlock ctrl to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //stop timer and clear interval period + wdt->ctrl &= ~(MXC_F_WDT_CTRL_INT_PERIOD | MXC_F_WDT_CTRL_EN_TIMER); + + //set interval period + wdt->ctrl |= (int_period << MXC_F_WDT_CTRL_INT_PERIOD_POS); + + //enable timeout interrupt + interruptEnable |= MXC_F_WDT_ENABLE_TIMEOUT; + + //lock ctrl to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_DisableInt(mxc_wdt_regs_t *wdt, uint8_t unlock_key) +{ + //unlock register to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable timeout interrupt + interruptEnable &= ~MXC_F_WDT_ENABLE_TIMEOUT; + wdt->enable = interruptEnable; + + //lock register to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_EnableWait(mxc_wdt_regs_t *wdt, wdt_period_t wait_period, uint8_t unlock_key) +{ + // Make sure wait_period is valid + if (wait_period >= WDT_PERIOD_MAX) + return E_INVALID; + + //unlock ctrl to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //stop timer and clear wait period + wdt->ctrl &= ~(MXC_F_WDT_CTRL_WAIT_PERIOD | MXC_F_WDT_CTRL_EN_TIMER); + + //set wait period + wdt->ctrl |= (wait_period << MXC_F_WDT_CTRL_WAIT_PERIOD_POS); + + //enable wait interrupt + interruptEnable |= MXC_F_WDT_ENABLE_PRE_WIN; + + //lock ctrl to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_DisableWait(mxc_wdt_regs_t *wdt, uint8_t unlock_key) +{ + //unlock register to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable wait interrupt + interruptEnable &= ~MXC_F_WDT_ENABLE_PRE_WIN; + wdt->enable = interruptEnable; + + //lock register to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_EnableReset(mxc_wdt_regs_t *wdt, wdt_period_t rst_period, uint8_t unlock_key) +{ + // Make sure wait_period is valid + if (rst_period >= WDT_PERIOD_MAX) + return E_INVALID; + + //unlock ctrl to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //stop timer and clear reset period + wdt->ctrl &= ~(MXC_F_WDT_CTRL_RST_PERIOD | MXC_F_WDT_CTRL_EN_TIMER); + + //set reset period + wdt->ctrl |= (rst_period << MXC_F_WDT_CTRL_RST_PERIOD_POS); + + //enable reset0 + interruptEnable |= MXC_F_WDT_ENABLE_RESET_OUT; + + //lock ctrl to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_DisableReset(mxc_wdt_regs_t *wdt, uint8_t unlock_key) +{ + //unlock register to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable reset0 + interruptEnable &= ~MXC_F_WDT_ENABLE_RESET_OUT; + wdt->enable = interruptEnable; + + //lock register to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT_Start(mxc_wdt_regs_t *wdt, uint8_t unlock_key) +{ + //check if watchdog is already running + if(WDT_IsActive(wdt)) + return E_BAD_STATE; + + //unlock ctrl to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + WDT_Reset(wdt); + + //enable interrupts + wdt->enable = interruptEnable; + + //start timer + wdt->ctrl |= MXC_F_WDT_CTRL_EN_TIMER; + + //lock ctrl to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +void WDT_Reset(mxc_wdt_regs_t *wdt) +{ + //reset the watchdog counter + wdt->clear = MXC_V_WDT_RESET_KEY_0; + wdt->clear = MXC_V_WDT_RESET_KEY_1; + + //clear all interrupt flags + wdt->flags = WDT_FLAGS_CLEAR_ALL; + + //wait for all interrupts to clear + while(wdt->flags != 0) { + wdt->flags = WDT_FLAGS_CLEAR_ALL; + } + + return; +} + +/******************************************************************************/ +int WDT_Stop(mxc_wdt_regs_t *wdt, uint8_t unlock_key) +{ + //unlock ctrl to be writable + wdt->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (wdt->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disabled the timer and interrupts + wdt->enable = 0; + wdt->ctrl &= ~(MXC_F_WDT_CTRL_EN_TIMER); + + //lock ctrl to read-only + wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; + + return E_NO_ERROR; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt.h new file mode 100644 index 0000000..ffcabad --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt.h @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 15:44:11 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22024 $ + * + ******************************************************************************/ + +/** + * @file wdt.h + * @addtogroup wdt WDT + * @{ + * @brief This is the high level API for the watchdog timer interface module + * + */ + +#ifndef _WDT_H +#define _WDT_H + +#include "mxc_config.h" +#include "wdt_regs.h" +#include "mxc_assert.h" +#include "mxc_sys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WDT_FLAGS_CLEAR_ALL (MXC_F_WDT_FLAGS_TIMEOUT| \ + MXC_F_WDT_FLAGS_PRE_WIN | \ + MXC_F_WDT_FLAGS_RESET_OUT) +/** @enum wdt_period_t */ +/** @brief Enumeration for the Watchdog Timer Period */ +typedef enum { + WDT_PERIOD_2_31_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_31_CLKS, /**< 2^31 WDT clocks. */ + WDT_PERIOD_2_30_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_30_CLKS, /**< 2^30 WDT clocks. */ + WDT_PERIOD_2_29_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_29_CLKS, /**< 2^29 WDT clocks. */ + WDT_PERIOD_2_28_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_28_CLKS, /**< 2^28 WDT clocks. */ + WDT_PERIOD_2_27_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_27_CLKS, /**< 2^27 WDT clocks. */ + WDT_PERIOD_2_26_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_26_CLKS, /**< 2^26 WDT clocks. */ + WDT_PERIOD_2_25_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_25_CLKS, /**< 2^25 WDT clocks. */ + WDT_PERIOD_2_24_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_24_CLKS, /**< 2^24 WDT clocks. */ + WDT_PERIOD_2_23_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_23_CLKS, /**< 2^23 WDT clocks. */ + WDT_PERIOD_2_22_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_22_CLKS, /**< 2^22 WDT clocks. */ + WDT_PERIOD_2_21_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_21_CLKS, /**< 2^21 WDT clocks. */ + WDT_PERIOD_2_20_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_20_CLKS, /**< 2^20 WDT clocks. */ + WDT_PERIOD_2_19_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_19_CLKS, /**< 2^19 WDT clocks. */ + WDT_PERIOD_2_18_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_18_CLKS, /**< 2^18 WDT clocks. */ + WDT_PERIOD_2_17_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_17_CLKS, /**< 2^17 WDT clocks. */ + WDT_PERIOD_2_16_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_16_CLKS, /**< 2^16 WDT clocks. */ + WDT_PERIOD_MAX /**< Maximum Period is Max - 1 */ +} wdt_period_t; + +/** + * @brief Initializes system level clocks and sets watchdog in a known disabled state + * @note The clk_scale in cfg is only used if the system clock is selected for clk. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param cfg Watchdog system configuration, see sys_cfg_wdt_t. + * @param unlock_key Watchdog unlock key + * + * @retval E_NO_ERROR Watchdog Timer initialized as requested + * @retval E_NULL_PTR NULL pointer for Watchdog Timer Instance or Configuration parameters. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg, uint8_t unlock_key); + +/** + * @brief Configures and enables the interrupt timeout for the watchdog specified. + * + * @param wdt Watchdog module to operate on + * @param int_period Interrupt period as defined by wdt_period_t. + * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY. + * + * @retval E_NO_ERROR Interrupt enabled + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT_EnableInt(mxc_wdt_regs_t *wdt, wdt_period_t int_period, uint8_t unlock_key); + +/** + * @brief Disables the interrupt timeout for the watchdog specified. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY. + * + * @retval E_NO_ERROR Interrupt disabled. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT_DisableInt(mxc_wdt_regs_t *wdt, uint8_t unlock_key); + +/** + * @brief Configures and enables the pre-window timeout for the watchdog specified. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param wait_period Pre-window period, see wdt_period_t for accepted values. + * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY. + * + * @retval E_NO_ERROR Pre-window timeout set to wait_period + * @retval E_BAD_STATE WDT unable to be unlocked + * @retval E_INVALID Requested Period is greater than the maximum supported + */ +int WDT_EnableWait(mxc_wdt_regs_t *wdt, wdt_period_t wait_period, uint8_t unlock_key); + +/** + * @brief Disables the pre-window timeout for the watchdog specified. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY. + * + * @retval E_NO_ERROR Wait disabled. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT_DisableWait(mxc_wdt_regs_t *wdt, uint8_t unlock_key); + +/** + * @brief Configures and enables the reset timeout for the watchdog specified. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param rst_period Reset period, see wdt_period_t for accepted values. + * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY. + * + * @retval E_NO_ERROR Watchdog Timer Reset enabled with the rst_period time. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + * @retval E_INVALID Requested Period is greater than the maximum supported + */ +int WDT_EnableReset(mxc_wdt_regs_t *wdt, wdt_period_t rst_period, uint8_t unlock_key); + +/** + * @brief Disables the reset timeout for the watchdog specified. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY. + * + * @retval E_NO_ERROR Reset disabled. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT_DisableReset(mxc_wdt_regs_t *wdt, uint8_t unlock_key); + +/** + * @brief Gets the watchdog interrupt flags + * + * @param wdt Pointer to the Watchdog Timer Instance. + * + * @retval uint32_t Value of the Watchdog Timer Flags. + * + */ +__STATIC_INLINE uint32_t WDT_GetFlags(mxc_wdt_regs_t *wdt) +{ + return (wdt->flags); +} + +/** + * @brief Clears the watchdog interrupt flags based on the mask + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param mask Watchdog Flags to clear + * + */ +__STATIC_INLINE void WDT_ClearFlags(mxc_wdt_regs_t *wdt, uint32_t mask) +{ + wdt->flags = mask; +} + +/** + * @brief Starts the specified Watchdog Timer instance. + * + * @param wdt Pointer to the Watchdog Timer instance + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR Interrupt enabled. + * @retval E_BAD_STATE WDT2 Already Running + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + * + */ +int WDT_Start(mxc_wdt_regs_t *wdt, uint8_t unlock_key); + +/** + * @brief Feeds the watchdog specified. + * + * @param wdt Watchdog module to operate on + * + */ +void WDT_Reset(mxc_wdt_regs_t *wdt); + +/** + * @brief Stops the watchdog specified. + * + * @param wdt Pointer to the Watchdog Timer Instance + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR Interrupt enabled. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT_Stop(mxc_wdt_regs_t *wdt, uint8_t unlock_key); + +/** + * @brief Determines if the watchdog is running + * + * @param wdt Pointer to the Watchdog Timer Instance + * + * @retval 0 Watchdog timer is Disabled. + * @retval non-zero Watchdog timer is Active + */ +__STATIC_INLINE int WDT_IsActive(mxc_wdt_regs_t *wdt) +{ + return (!!(wdt->ctrl & MXC_F_WDT_CTRL_EN_TIMER)); +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* _WDT_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt2.c b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt2.c new file mode 100644 index 0000000..d0c93fc --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt2.c @@ -0,0 +1,269 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 15:44:11 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22024 $ + * + ******************************************************************************/ + +/** + * @file wdt2.c + * @brief Watchdog 2 driver source. + */ +#include +#include "wdt2.h" +#include "pwrseq_regs.h" + +static uint32_t interruptEnable = 0; //keeps track to interrupts to enable in start function + +/******************************************************************************/ +int WDT2_Init(uint8_t runInSleep, uint8_t unlock_key) +{ + //enable nanoring in run and sleep mode + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_NREN_RUN); + + //unlock ctrl to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable all interrupts + interruptEnable = 0; + MXC_WDT2->enable = interruptEnable; + + //enable the watchdog clock and clear all other settings + MXC_WDT2->ctrl = (MXC_F_WDT2_CTRL_EN_CLOCK); + + //clear all interrupt flags + MXC_WDT2->flags = WDT2_FLAGS_CLEAR_ALL; + + if(runInSleep) { + // turn on nanoring during sleep + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_NREN_SLP); + //turn on timer during sleep + MXC_WDT2->ctrl |= MXC_F_WDT2_CTRL_EN_TIMER_SLP; + } else { + // turn off nanoring during sleep + MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_NREN_SLP); + //turn off timer during sleep + MXC_WDT2->ctrl &= ~(MXC_F_WDT2_CTRL_EN_TIMER_SLP); + } + + //lock ctrl to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT2_EnableWakeUp(wdt2_period_t int_period, uint8_t unlock_key) +{ + // Make sure interrupt period is valid + if (int_period >= WDT2_PERIOD_MAX) + return E_INVALID; + + //unlock ctrl to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + //stop timer and clear interval period + MXC_WDT2->ctrl &= ~(MXC_F_WDT2_CTRL_INT_PERIOD | MXC_F_WDT2_CTRL_EN_TIMER); + + //set interval period + MXC_WDT2->ctrl |= (int_period << MXC_F_WDT2_CTRL_INT_PERIOD_POS); + + //enable timeout wake-up + interruptEnable |= MXC_F_WDT2_ENABLE_TIMEOUT; + + //lock ctrl to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + // Enable wake-up + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_MSK_FLAGS_PWR_NANORING_WAKEUP_FLAG; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT2_DisableWakeUp(uint8_t unlock_key) +{ + //unlock register to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable timeout wake-up + interruptEnable &= ~MXC_F_WDT2_ENABLE_TIMEOUT; + MXC_WDT2->enable = interruptEnable; + + //lock register to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + // disable wake-up + MXC_PWRSEQ->msk_flags &= ~MXC_F_PWRSEQ_MSK_FLAGS_PWR_NANORING_WAKEUP_FLAG; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT2_EnableReset(wdt2_period_t rst_period, uint8_t unlock_key) +{ + // Make sure reset period is valid + if (rst_period >= WDT2_PERIOD_MAX) + return E_INVALID; + + //unlock ctrl to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + //stop timer and clear reset period + MXC_WDT2->ctrl &= ~(MXC_F_WDT2_CTRL_RST_PERIOD | MXC_F_WDT2_CTRL_EN_TIMER); + + //set reset period + MXC_WDT2->ctrl |= (rst_period << MXC_F_WDT2_CTRL_RST_PERIOD_POS); + + //int flag has to be clear before interrupt enable can be written + MXC_WDT2->flags = MXC_F_WDT2_FLAGS_RESET_OUT; + + //enable reset0 + interruptEnable |= MXC_F_WDT2_ENABLE_RESET_OUT; + + //lock ctrl to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + //enable RSTN on WDT2 reset + MXC_PWRSEQ->msk_flags |= MXC_F_PWRSEQ_MSK_FLAGS_PWR_WATCHDOG_RSTN_FLAG; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT2_DisableReset(uint8_t unlock_key) +{ + //unlock register to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disable reset + interruptEnable &= ~MXC_F_WDT2_ENABLE_RESET_OUT; + MXC_WDT2->enable = interruptEnable; + + //lock register to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + //disable RSTN on WDT2 reset + MXC_PWRSEQ->msk_flags &= ~MXC_F_PWRSEQ_MSK_FLAGS_PWR_WATCHDOG_RSTN_FLAG; + + return E_NO_ERROR; +} + +/******************************************************************************/ +int WDT2_Start(uint8_t unlock_key) +{ + //check if watchdog is already running + if(WDT2_IsActive()) + return E_BAD_STATE; + + //unlock ctrl to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + WDT2_Reset(); + + //enable interrupts + MXC_WDT2->enable = interruptEnable; + + //start timer + MXC_WDT2->ctrl |= (MXC_F_WDT2_CTRL_EN_TIMER); + + //lock ctrl to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + return E_NO_ERROR; +} + +/******************************************************************************/ +void WDT2_Reset(void) +{ + //reset the watchdog counter + MXC_WDT2->clear = MXC_V_WDT2_RESET_KEY_0; + MXC_WDT2->clear = MXC_V_WDT2_RESET_KEY_1; + + //clear all interrupt flags + MXC_WDT2->flags = WDT2_FLAGS_CLEAR_ALL; + + //wait for all interrupts to clear + while(MXC_WDT2->flags != 0) { + MXC_WDT2->flags = WDT2_FLAGS_CLEAR_ALL; + } + + return; +} + +/******************************************************************************/ +int WDT2_Stop(uint8_t unlock_key) +{ + //check if watchdog is not running + if(!WDT2_IsActive()) + return E_BAD_STATE; + + //unlock ctrl to be writable + MXC_WDT2->lock_ctrl = unlock_key; + + //check to make sure it unlocked + if (MXC_WDT2->lock_ctrl & 0x01) + return E_BAD_STATE; + + //disabled the timer and interrupts + MXC_WDT2->enable = 0; + MXC_WDT2->ctrl &= ~(MXC_F_WDT2_CTRL_EN_TIMER); + + //lock ctrl to read-only + MXC_WDT2->lock_ctrl = MXC_V_WDT2_LOCK_KEY; + + return E_NO_ERROR; +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt2.h b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt2.h new file mode 100644 index 0000000..856aa5b --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/mxc/wdt2.h @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-21 15:44:11 -0500 (Mon, 21 Mar 2016) $ + * $Revision: 22024 $ + * + ******************************************************************************/ + +/** + * @file wdt2.h + * @addtogroup wdt WDT + * @{ + * @brief This is the high level API for the watchdog timer interface module + * + */ + +#ifndef _WDT2_H +#define _WDT2_H + +#include "mxc_config.h" +#include "wdt2_regs.h" +#include "mxc_assert.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WDT2_FLAGS_CLEAR_ALL (MXC_F_WDT2_FLAGS_TIMEOUT| \ + MXC_F_WDT2_FLAGS_RESET_OUT) +/** + * @enum wdt2_period_t + * @brief WatchDog Timer 2 Period Settings + */ +typedef enum { + WDT2_PERIOD_2_25_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_25_NANO_CLKS, /**< 2^25 WDT clocks. */ + WDT2_PERIOD_2_24_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_24_NANO_CLKS, /**< 2^24 WDT clocks. */ + WDT2_PERIOD_2_23_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_23_NANO_CLKS, /**< 2^23 WDT clocks. */ + WDT2_PERIOD_2_22_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_22_NANO_CLKS, /**< 2^22 WDT clocks. */ + WDT2_PERIOD_2_21_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_21_NANO_CLKS, /**< 2^21 WDT clocks. */ + WDT2_PERIOD_2_20_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_20_NANO_CLKS, /**< 2^20 WDT clocks. */ + WDT2_PERIOD_2_19_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_19_NANO_CLKS, /**< 2^19 WDT clocks. */ + WDT2_PERIOD_2_18_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_18_NANO_CLKS, /**< 2^18 WDT clocks. */ + WDT2_PERIOD_2_17_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_17_NANO_CLKS, /**< 2^17 WDT clocks. */ + WDT2_PERIOD_2_16_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_16_NANO_CLKS, /**< 2^16 WDT clocks. */ + WDT2_PERIOD_2_15_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_15_NANO_CLKS, /**< 2^15 WDT clocks. */ + WDT2_PERIOD_2_14_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_14_NANO_CLKS, /**< 2^14 WDT clocks. */ + WDT2_PERIOD_2_13_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_13_NANO_CLKS, /**< 2^13 WDT clocks. */ + WDT2_PERIOD_2_12_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_12_NANO_CLKS, /**< 2^12 WDT clocks. */ + WDT2_PERIOD_2_11_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_11_NANO_CLKS, /**< 2^11 WDT clocks. */ + WDT2_PERIOD_2_10_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_10_NANO_CLKS, /**< 2^10 WDT clocks. */ + WDT2_PERIOD_MAX /**< Maximum Period is Max - 1 */ +} wdt2_period_t; + + + +/** + * @brief Initializes the NanoRing for the watchdog clock and sets watchdog in a known disabled state + * @param runInSleep If non-zero, the WDT2 operates in Sleep Modes for the device, + * 0 disables the WDT2 during Sleep Modes. + * @param unlock_key The WDT2 unlock key value, use MXC_V_WDT2_UNLOCK_KEY + * + * @retval E_NO_ERROR Watchdog Timer initialized as requested + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + + */ +int WDT2_Init(uint8_t runInSleep, uint8_t unlock_key); + +/** + * @brief Configures and enables the wake-up timeout for the watchdog specified. + * + * @param int_period Interrupt period. + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR WDT2 Interrupt period enabled with the int_period time. + * @retval E_INVALID Requested Period is greater than the maximum supported + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + * + */ +int WDT2_EnableWakeUp(wdt2_period_t int_period, uint8_t unlock_key); + +/** + * @brief Disables the interrupt timeout for the watchdog specified. + * + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR Wakeup disabled. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT2_DisableWakeUp(uint8_t unlock_key); + +/** + * @brief Configures and enables the reset timeout for the watchdog specified. + * + * @param rst_period Reset period. + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR Reset timeout enabled with the rst_period time. + * @retval E_INVALID Requested Period is greater than the maximum supported + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT2_EnableReset(wdt2_period_t rst_period, uint8_t unlock_key); + +/** + * @brief Disables the reset timeout for the watchdog specified. + * + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR Reset disabled. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT2_DisableReset(uint8_t unlock_key); + +/** + * @brief Gets the watchdog interrupt flags + * + * @retval 0 = flags not set, non-zero = flag is set + */ +__STATIC_INLINE uint32_t WDT2_GetFlags(void) +{ + return (MXC_WDT2->flags); +} + +/** + * @brief Clears the watchdog interrupt flags based on the mask + * + * @param mask bits to clear + * + */ +__STATIC_INLINE void WDT2_ClearFlags(uint32_t mask) +{ + MXC_WDT2->flags = mask; +} + +/** + * @brief Starts the watchdog specified. + * + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR if everything is successful, error if unsuccessful. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT2_Start(uint8_t unlock_key); + +/** + * @brief Feeds the watchdog specified. + * + * @retval E_NO_ERROR if everything is successful, error if unsuccessful. + */ +void WDT2_Reset(void); + +/** + * @brief Stops the WatchDog Timer 2. + * + * @param unlock_key Key to unlock watchdog. + * + * @retval E_NO_ERROR if everything is successful, error if unsuccessful. + * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock. + */ +int WDT2_Stop(uint8_t unlock_key); + +/** + * @brief Determines if the watchdog is running + * + * @retval 0 = watchdog timer is off, non-zero = watchdog timer is on + */ +__STATIC_INLINE int WDT2_IsActive(void) +{ + return (!!(MXC_WDT2->ctrl & MXC_F_WDT2_CTRL_EN_TIMER)); +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* _WDT_H */ diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/objects.h b/targets/TARGET_Maxim/TARGET_MAX32625/objects.h new file mode 100644 index 0000000..53d1371 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/objects.h @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef MBED_OBJECTS_H +#define MBED_OBJECTS_H + +#include "cmsis.h" +#include "PortNames.h" +#include "PeripheralNames.h" +#include "PinNames.h" +#include "gpio_object.h" +#include "gpio_regs.h" +#include "uart_regs.h" +#include "i2cm_regs.h" +#include "spim_regs.h" +#include "pt_regs.h" +#include "adc_regs.h" +#include "uart.h" +#include "adc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct port_s { + PortName port; + uint32_t mask; + __IO uint32_t *reg_out; + __I uint32_t *reg_in; + PinMode mode; +}; + +struct gpio_irq_s { + uint8_t port; + uint8_t pin; + uint8_t rise_en; + uint8_t fall_en; + uint32_t id; +}; + +struct serial_s { + int index; + mxc_uart_regs_t *uart; + mxc_uart_fifo_regs_t *fifo; + uint32_t id; + uart_cfg_t cfg; + sys_cfg_uart_t sys_cfg; + PinName tx_pin; +}; + +struct i2c_s { + mxc_i2cm_regs_t *i2c; + mxc_i2cm_fifo_regs_t *fifo; + int start_pending; +}; + +struct spi_s { + int index; + mxc_spim_regs_t *spi; +}; + +struct pwmout_s { + mxc_pt_regs_t *pwm; + int period; + int pulse_width; +}; + +struct analogin_s { + mxc_adc_regs_t *adc; + mxc_adc_chsel_t channel; +}; + +typedef struct { + volatile uint32_t *reg_req; + volatile uint32_t *reg_ack; + uint32_t req_val; + uint32_t ack_mask; +} pin_function_t; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/pinmap.c b/targets/TARGET_Maxim/TARGET_MAX32625/pinmap.c new file mode 100644 index 0000000..d2ca7aa --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/pinmap.c @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed_assert.h" +#include "pinmap.h" +#include "objects.h" +#include "gpio_regs.h" + +void pin_function(PinName name, int function) +{ + MBED_ASSERT(name != (PinName)NC); + + if ((function >= 0) && (function <= 0xF)) { + unsigned int port = PINNAME_TO_PORT(name); + unsigned int pin = PINNAME_TO_PIN(name); + uint32_t temp = MXC_GPIO->func_sel[port] & ~(0xF << (pin*4)); + MXC_GPIO->func_sel[port] = temp | ((uint32_t)function << (pin*4)); + } else { + /* Assume this is a pointer to a pin function object */ + pin_function_t *obj = (pin_function_t*)function; + + if ((*obj->reg_ack & obj->ack_mask) != obj->req_val) { + /* Request pin mapping */ + *obj->reg_req |= obj->req_val; + + /* Check for acknowledgment */ + MBED_ASSERT((*obj->reg_ack & obj->ack_mask) == obj->req_val); + } + } +} + +void pin_mode(PinName name, PinMode mode) +{ + MBED_ASSERT(name != (PinName)NC); + unsigned int port = PINNAME_TO_PORT(name); + unsigned int pin = PINNAME_TO_PIN(name); + + /* Must set mode while retaining direction */ + + /* Get the current direction */ + uint32_t curr_mode = (MXC_GPIO->out_mode[port] >> (pin * 4)) & 0xF; + PinDirection direction = PIN_OUTPUT; + if ((curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP) || + (curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN) || + (curr_mode == MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z)) { + direction = PIN_INPUT; + } + + /* Set mode based on current direction */ + pin_dir_mode(name, direction, mode); +} + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/port_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/port_api.c new file mode 100644 index 0000000..adce69a --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/port_api.c @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "port_api.h" +#include "pinmap.h" +#include "gpio_api.h" +#include "gpio_regs.h" +#include "clkman_regs.h" + +PinName port_pin(PortName port, int pin_n) +{ + return (PinName)((port << PORT_SHIFT) | pin_n); +} + +void port_init(port_t *obj, PortName port, int mask, PinDirection direction) +{ + obj->port = port; + obj->mask = mask; + obj->reg_out = &MXC_GPIO->out_val[port]; + obj->reg_in = &MXC_GPIO->in_val[port]; + obj->mode = PullDefault; + + /* Ensure that the GPIO clock is enabled */ + MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1; + + uint32_t i; + // The function is set per pin: reuse gpio logic + for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { + if (obj->mask & (1 << i)) { + gpio_set(port_pin(obj->port, i)); + pin_dir_mode(port_pin(obj->port, i), direction, obj->mode); + } + } +} + +void port_mode(port_t *obj, PinMode mode) +{ + uint32_t i; + obj->mode = mode; + // The mode is set per pin: reuse pinmap logic + for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { + if (obj->mask & (1 << i)) { + pin_mode(port_pin(obj->port, i), mode); + } + } +} + +void port_dir(port_t *obj, PinDirection direction) +{ + uint32_t i; + // The mode is set per pin: reuse gpio logic + for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { + if (obj->mask & (1 << i)) { + pin_dir_mode(port_pin(obj->port, i), direction, obj->mode); + } + } +} + +void port_write(port_t *obj, int value) +{ + *obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask); +} + +int port_read(port_t *obj) +{ + return (*obj->reg_in & obj->mask); +} + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/pwmout_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/pwmout_api.c new file mode 100644 index 0000000..ec8a3cf --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/pwmout_api.c @@ -0,0 +1,221 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed_assert.h" +#include "cmsis.h" +#include "pwmout_api.h" +#include "pinmap.h" +#include "clkman_regs.h" +#include "PeripheralPins.h" + +#define MXC_GPIO_OUT_MODE_FIELD_WIDTH 4 +#define MXC_GPIO_OUT_MODE_FIELD_MASK ((uint32_t)0xFFFFFFFF >> (32 - MXC_GPIO_OUT_MODE_FIELD_WIDTH)) +#define MXC_GPIO_FUNC_SEL_FIELD_WIDTH 4 +#define MXC_GPIO_FUNC_SEL_FIELD_MASK ((uint32_t)0xFFFFFFFF >> (32 - MXC_GPIO_FUNC_SEL_FIELD_WIDTH)) + + +//****************************************************************************** +void pwmout_init(pwmout_t* obj, PinName pin) +{ + // Make sure the pin is free for GPIO use + unsigned int port = (unsigned int)pin >> PORT_SHIFT; + unsigned int port_pin = (unsigned int)pin & ~(0xFFFFFFFF << PORT_SHIFT); + MBED_ASSERT(MXC_GPIO->free[port] & (0x1 << port_pin)); + + int i = 0; + PinMap pwm = PinMap_PWM[0]; + + // Check if there is a pulse train already active on this port + int pin_func = (MXC_GPIO->func_sel[port] & (MXC_GPIO_FUNC_SEL_FIELD_MASK << (port_pin * MXC_GPIO_FUNC_SEL_FIELD_WIDTH))) >> + (port_pin * MXC_GPIO_FUNC_SEL_FIELD_WIDTH); + MBED_ASSERT((pin_func < 1) || (pin_func > 3)); + + // Search through PinMap_PWM to find the pin + while (pwm.pin != pin) { + pwm = PinMap_PWM[++i]; + } + + // Find a free PT instance on this pin + while (pwm.pin == pin) { + + // Check to see if this PT instance is free + if (((mxc_pt_regs_t*)pwm.peripheral)->rate_length & MXC_F_PT_RATE_LENGTH_MODE) { + break; + } + + pwm = PinMap_PWM[++i]; + + // Raise an assertion if we can not allocate another PT instance. + MBED_ASSERT(pwm.pin == pin); + } + + // Enable the clock + MXC_CLKMAN->sys_clk_ctrl_7_pt = MXC_S_CLKMAN_CLK_SCALE_DIV_1; + + // Set the obj pointer to the propper PWM instance + obj->pwm = (mxc_pt_regs_t*)pwm.peripheral; + + // Initialize object period and pulse width + obj->period = -1; + obj->pulse_width = -1; + + // Disable the output + obj->pwm->train = 0x0; + obj->pwm->rate_length = 0x0; + + // Configure the pin + pin_mode(pin, (PinMode)PullNone); + pin_function(pin, pwm.function); + + // default to 20ms: standard for servos, and fine for e.g. brightness control + pwmout_period_us(obj, 20000); + pwmout_write (obj, 0); + + // Set the drive mode to normal + MXC_SET_FIELD(&MXC_GPIO->out_mode[port], + (MXC_GPIO_OUT_MODE_FIELD_MASK << (port_pin * MXC_GPIO_OUT_MODE_FIELD_WIDTH)), + (MXC_V_GPIO_OUT_MODE_NORMAL << (port_pin * MXC_GPIO_OUT_MODE_FIELD_WIDTH))); + + // Enable this PWM channel + MXC_PTG->enable |= (1 << MXC_PT_GET_IDX(obj->pwm)); +} + +//****************************************************************************** +void pwmout_free(pwmout_t* obj) +{ + // Set the registers to the reset value + obj->pwm->train = 0; + obj->pwm->rate_length = 0x08000000; +} + +//****************************************************************************** +static void pwmout_update(pwmout_t* obj) +{ + // Calculate and set the divider ratio + int div = (obj->period * (SystemCoreClock / 1000000))/32; + if (div < 2) { + div = 2; + } + MXC_SET_FIELD(&obj->pwm->rate_length, MXC_F_PT_RATE_LENGTH_RATE_CONTROL, div); + + // Change the duty cycle to adjust the pulse width + obj->pwm->train = (0xFFFFFFFF << (32 - ((32 * obj->pulse_width) / obj->period))); +} + + +//****************************************************************************** +void pwmout_write(pwmout_t* obj, float percent) +{ + // Saturate percent if outside of range + if(percent < 0.0f) { + percent = 0.0f; + } else if(percent > 1.0f) { + percent = 1.0f; + } + + // Resize the pulse width to set the duty cycle + pwmout_pulsewidth_us(obj, (int)(percent*obj->period)); +} + +//****************************************************************************** +float pwmout_read(pwmout_t* obj) +{ + // Check for when pulsewidth or period equals 0 + if((obj->pulse_width == 0) || (obj->period == 0)) { + return 0; + } + + // Return the duty cycle + return ((float)obj->pulse_width / (float)obj->period); +} + +//****************************************************************************** +void pwmout_period(pwmout_t* obj, float seconds) +{ + pwmout_period_us(obj, (int)(seconds * 1000000.0f)); +} + +//****************************************************************************** +void pwmout_period_ms(pwmout_t* obj, int ms) +{ + pwmout_period_us(obj, ms * 1000); +} + +//****************************************************************************** +void pwmout_period_us(pwmout_t* obj, int us) +{ + // Check the range of the period + MBED_ASSERT((us >= 0) && (us <= (int)(SystemCoreClock / 32))); + + // Set pulse width to half the period if uninitialized + if (obj->pulse_width == -1) { + obj->pulse_width = us / 2; + } + + // Save the period + obj->period = us; + + // Update the registers + pwmout_update(obj); +} + +//****************************************************************************** +void pwmout_pulsewidth(pwmout_t* obj, float seconds) +{ + pwmout_pulsewidth_us(obj, (int)(seconds * 1000000.0f)); +} + +//****************************************************************************** +void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) +{ + pwmout_pulsewidth_us(obj, ms * 1000); +} + +//****************************************************************************** +void pwmout_pulsewidth_us(pwmout_t* obj, int us) +{ + // Check the range of the pulsewidth + MBED_ASSERT((us >= 0) && (us <= (int)(SystemCoreClock / 32))); + + // Initialize period to double the pulsewidth if uninitialized + if (obj->period == -1) { + obj->period = 2 * us; + } + + // Save the pulsewidth + obj->pulse_width = us; + + // Update the register + pwmout_update(obj); +} + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/rtc_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/rtc_api.c new file mode 100644 index 0000000..703ea79 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/rtc_api.c @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "rtc_api.h" +#include "lp_ticker_api.h" +#include "rtc.h" +#include "lp.h" + +#define PRESCALE_VAL RTC_PRESCALE_DIV_2_0 // Set the divider for the 4kHz clock +#define SHIFT_AMT (RTC_PRESCALE_DIV_2_12 - PRESCALE_VAL) + +#define WINDOW 1000 + +static int rtc_inited = 0; +static volatile uint32_t overflow_cnt = 0; + +static uint64_t rtc_read64(void); + +//****************************************************************************** +static void overflow_handler(void) +{ + overflow_cnt++; + RTC_ClearFlags(MXC_F_RTC_FLAGS_ASYNC_CLR_FLAGS); +} + +//****************************************************************************** +void rtc_init(void) +{ + if (rtc_inited) { + return; + } + rtc_inited = 1; + + overflow_cnt = 0; + + /* Enable power for RTC for all LPx states */ + MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN | + MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP); + + /* Enable clock to synchronizers */ + CLKMAN_SetClkScale(CLKMAN_CLK_SYNC, CLKMAN_SCALE_DIV_1); + + // Prepare interrupt handlers + NVIC_SetVector(RTC0_IRQn, (uint32_t)lp_ticker_irq_handler); + NVIC_EnableIRQ(RTC0_IRQn); + NVIC_SetVector(RTC3_IRQn, (uint32_t)overflow_handler); + NVIC_EnableIRQ(RTC3_IRQn); + + // Enable wakeup on RTC rollover + LP_ConfigRTCWakeUp(0, 0, 0, 1); + + /* RTC registers are only reset on a power cycle. Do not reconfigure the RTC + * if it is already running. + */ + if (!RTC_IsActive()) { + rtc_cfg_t cfg = {0}; + cfg.prescaler = PRESCALE_VAL; + cfg.snoozeMode = RTC_SNOOZE_DISABLE; + + int retval = RTC_Init(&cfg); + MBED_ASSERT(retval == E_NO_ERROR); + + RTC_EnableINT(MXC_F_RTC_FLAGS_OVERFLOW); + RTC_Start(); + } +} + +//****************************************************************************** +void lp_ticker_init(void) +{ + rtc_init(); +} + +//****************************************************************************** +void rtc_free(void) +{ + if (RTC_IsActive()) { + // Clear and disable RTC + MXC_RTCTMR->ctrl |= MXC_F_RTC_CTRL_CLEAR; + RTC_Stop(); + } +} + +//****************************************************************************** +int rtc_isenabled(void) +{ + return RTC_IsActive(); +} + +//****************************************************************************** +time_t rtc_read(void) +{ + uint32_t ovf_cnt_1, ovf_cnt_2, timer_cnt; + uint32_t ovf1, ovf2; + + // Make sure RTC is setup before trying to read + if (!rtc_inited) { + rtc_init(); + } + + // Ensure coherency between overflow_cnt and timer + do { + ovf_cnt_1 = overflow_cnt; + ovf1 = RTC_GetFlags() & MXC_F_RTC_FLAGS_OVERFLOW; + timer_cnt = RTC_GetCount(); + ovf2 = RTC_GetFlags() & MXC_F_RTC_FLAGS_OVERFLOW; + ovf_cnt_2 = overflow_cnt; + } while ((ovf_cnt_1 != ovf_cnt_2) || (ovf1 != ovf2)); + + // Account for an unserviced interrupt + if (ovf1) { + ovf_cnt_1++; + } + + return (timer_cnt >> SHIFT_AMT) + (ovf_cnt_1 << (32 - SHIFT_AMT)); +} + +//****************************************************************************** +static uint64_t rtc_read64(void) +{ + uint32_t ovf_cnt_1, ovf_cnt_2, timer_cnt; + uint32_t ovf1, ovf2; + uint64_t current_us; + + // Make sure RTC is setup before trying to read + if (!rtc_inited) { + rtc_init(); + } + + // Ensure coherency between overflow_cnt and timer + do { + ovf_cnt_1 = overflow_cnt; + ovf1 = RTC_GetFlags() & MXC_F_RTC_FLAGS_OVERFLOW; + timer_cnt = RTC_GetCount(); + ovf2 = RTC_GetFlags() & MXC_F_RTC_FLAGS_OVERFLOW; + ovf_cnt_2 = overflow_cnt; + } while ((ovf_cnt_1 != ovf_cnt_2) || (ovf1 != ovf2)); + + // Account for an unserviced interrupt + if (ovf1) { + ovf_cnt_1++; + } + + current_us = (((uint64_t)timer_cnt * 1000000) >> SHIFT_AMT) + (((uint64_t)ovf_cnt_1 * 1000000) << (32 - SHIFT_AMT)); + + return current_us; +} + +//****************************************************************************** +void rtc_write(time_t t) +{ + // Make sure RTC is setup before accessing + if (!rtc_inited) { + rtc_init(); + } + + RTC_Stop(); + RTC_SetCount(t << SHIFT_AMT); + overflow_cnt = t >> (32 - SHIFT_AMT); + RTC_Start(); +} + +//****************************************************************************** +void lp_ticker_set_interrupt(timestamp_t timestamp) +{ + uint32_t comp_value; + uint64_t curr_ts64; + uint64_t ts64; + + // Note: interrupts are disabled before this function is called. + + // Disable the alarm while it is prepared + RTC_DisableINT(MXC_F_RTC_INTEN_COMP0); + + curr_ts64 = rtc_read64(); + ts64 = (uint64_t)timestamp | (curr_ts64 & 0xFFFFFFFF00000000ULL); + + // If this event is older than a recent window, it must be in the future + if ((ts64 < (curr_ts64 - WINDOW)) && ((curr_ts64 - WINDOW) < curr_ts64)) { + ts64 += 0x100000000ULL; + } + + uint32_t timer = RTC_GetCount(); + if (ts64 <= curr_ts64) { + // This event has already occurred. Set the alarm to expire immediately. + comp_value = timer + 1; + } else { + comp_value = (ts64 << SHIFT_AMT) / 1000000; + } + + // Ensure that the compare value is far enough in the future to guarantee the interrupt occurs. + if ((comp_value < (timer + 2)) && (comp_value > (timer - 10))) { + comp_value = timer + 2; + } + + MXC_RTCTMR->comp[0] = comp_value; + MXC_RTCTMR->flags = MXC_F_RTC_FLAGS_ASYNC_CLR_FLAGS; + RTC_EnableINT(MXC_F_RTC_INTEN_COMP0); + + // Enable wakeup from RTC + LP_ConfigRTCWakeUp(1, 0, 0, 1); + + // Wait for pending transactions + while (MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING); +} + +//****************************************************************************** +inline void lp_ticker_disable_interrupt(void) +{ + RTC_DisableINT(MXC_F_RTC_INTEN_COMP0); +} + +//****************************************************************************** +inline void lp_ticker_clear_interrupt(void) +{ + RTC_ClearFlags(MXC_F_RTC_FLAGS_ASYNC_CLR_FLAGS); +} + +//****************************************************************************** +inline uint32_t lp_ticker_read(void) +{ + return rtc_read64(); +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c new file mode 100644 index 0000000..eab9d1e --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c @@ -0,0 +1,371 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include +#include "mbed_assert.h" +#include "cmsis.h" +#include "serial_api.h" +#include "gpio_api.h" +#include "uart.h" +#include "uart_regs.h" +#include "ioman_regs.h" +#include "PeripheralPins.h" + +#define DEFAULT_BAUD 9600 + +#define UART_ERRORS (MXC_F_UART_INTFL_RX_FRAMING_ERR | \ + MXC_F_UART_INTFL_RX_PARITY_ERR | \ + MXC_F_UART_INTFL_RX_FIFO_OVERFLOW) + +// Variables for managing the stdio UART +int stdio_uart_inited; +serial_t stdio_uart; + +// Variables for interrupt driven +static uart_irq_handler irq_handler; +static serial_t *objs[MXC_CFG_UART_INSTANCES]; + +static void usurp_pin(PinName, int); + +//****************************************************************************** +void serial_init(serial_t *obj, PinName tx, PinName rx) +{ + // Determine which uart is associated with each pin + UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); + UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); + UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); + + // Make sure that both pins are pointing to the same uart + MBED_ASSERT(uart != (UARTName)NC); + + // Set the obj pointer to the proper uart + obj->uart = (mxc_uart_regs_t*)uart; + + // Set the uart index + obj->index = MXC_UART_GET_IDX(obj->uart); + obj->fifo = (mxc_uart_fifo_regs_t*)MXC_UART_GET_BASE_FIFO(obj->index); + + // Manage stdio UART + if (uart == STDIO_UART) { + stdio_uart_inited = 1; + memcpy(&stdio_uart, obj, sizeof(serial_t)); + } + + // Save transmit pin for break function + obj->tx_pin = tx; + + // Merge pin function requests for use with CMSIS init func + ioman_req_t io_req = {0}; + pin_function_t *pin_func = NULL; + if (tx != NC) { + pin_func = (pin_function_t *)pinmap_find_function(tx, PinMap_UART_TX); + io_req.value = pin_func->req_val; + } + if (rx != NC) { + pin_func = (pin_function_t *)pinmap_find_function(rx, PinMap_UART_RX); + io_req.value |= pin_func->req_val; + } + + // Using req and ack pointers of last pin function lookup + obj->sys_cfg.io_cfg.req_reg = pin_func->reg_req; + obj->sys_cfg.io_cfg.ack_reg = pin_func->reg_ack; + obj->sys_cfg.io_cfg.req_val = io_req; + obj->sys_cfg.clk_scale = CLKMAN_SCALE_DIV_8; + + // Configure the UART with default parameters + obj->cfg.extra_stop = 0; + obj->cfg.cts = 0; + obj->cfg.rts = 0; + obj->cfg.baud = DEFAULT_BAUD; + obj->cfg.size = UART_DATA_SIZE_8_BITS; + obj->cfg.parity = UART_PARITY_DISABLE; + + int retval = UART_Init(obj->uart, &obj->cfg, &obj->sys_cfg); + MBED_ASSERT(retval == E_NO_ERROR); +} + +//****************************************************************************** +void serial_baud(serial_t *obj, int baudrate) +{ + obj->cfg.baud = baudrate; + int retval = UART_Init(obj->uart, &obj->cfg, NULL); + MBED_ASSERT(retval == E_NO_ERROR); +} + +//****************************************************************************** +void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) +{ + switch (data_bits) { + case 5: + obj->cfg.size = UART_DATA_SIZE_5_BITS; + break; + case 6: + obj->cfg.size = UART_DATA_SIZE_6_BITS; + break; + case 7: + obj->cfg.size = UART_DATA_SIZE_7_BITS; + break; + case 8: + obj->cfg.size = UART_DATA_SIZE_8_BITS; + break; + default: + MBED_ASSERT(0); + break; + } + + switch (parity) { + case ParityNone: + obj->cfg.parity = UART_PARITY_DISABLE; + break; + case ParityOdd : + obj->cfg.parity = UART_PARITY_ODD; + break; + case ParityEven: + obj->cfg.parity = UART_PARITY_EVEN; + break; + case ParityForced1: + case ParityForced0: + default: + MBED_ASSERT(0); + break; + } + + switch (stop_bits) { + case 1: + obj->cfg.extra_stop = 0; + break; + case 2: + obj->cfg.extra_stop = 1; + break; + default: + MBED_ASSERT(0); + break; + } + + int retval = UART_Init(obj->uart, &obj->cfg, NULL); + MBED_ASSERT(retval == E_NO_ERROR); +} + +//****************************************************************************** +void uart_handler(serial_t *obj) +{ + if (obj && obj->id) { + irq_handler(obj->id, RxIrq); + } +} + +void uart0_handler(void) { uart_handler(objs[0]); } +void uart1_handler(void) { uart_handler(objs[1]); } +void uart2_handler(void) { uart_handler(objs[2]); } + +//****************************************************************************** +void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) +{ + irq_handler = handler; + obj->id = id; +} + +//****************************************************************************** +void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) +{ + switch (obj->index) { + case 0: + NVIC_SetVector(UART0_IRQn, (uint32_t)uart0_handler); + NVIC_EnableIRQ(UART0_IRQn); + break; + case 1: + NVIC_SetVector(UART1_IRQn, (uint32_t)uart1_handler); + NVIC_EnableIRQ(UART1_IRQn); + break; + case 2: + NVIC_SetVector(UART2_IRQn, (uint32_t)uart2_handler); + NVIC_EnableIRQ(UART2_IRQn); + break; + default: + MBED_ASSERT(0); + } + + if (irq == RxIrq) { + // Enable RX FIFO Threshold Interrupt + if (enable) { + // Clear pending interrupts + obj->uart->intfl = obj->uart->intfl; + obj->uart->inten |= (MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY | UART_ERRORS); + } else { + // Clear pending interrupts + obj->uart->intfl = obj->uart->intfl; + obj->uart->inten &= ~(MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY | UART_ERRORS); + } + } else if (irq == TxIrq) { + // Set TX Almost Empty level to interrupt when empty + MXC_SET_FIELD(&obj->uart->tx_fifo_ctrl, MXC_F_UART_RX_FIFO_CTRL_FIFO_AF_LVL, + (MXC_UART_FIFO_DEPTH - 1) << MXC_F_UART_TX_FIFO_CTRL_FIFO_AE_LVL_POS); + + // Enable TX Almost Empty Interrupt + if (enable) { + // Clear pending interrupts + obj->uart->intfl = obj->uart->intfl; + obj->uart->inten |= MXC_F_UART_INTFL_TX_FIFO_AE; + } else { + // Clear pending interrupts + obj->uart->intfl = obj->uart->intfl; + obj->uart->inten &= ~MXC_F_UART_INTFL_TX_FIFO_AE; + } + } else { + MBED_ASSERT(0); + } +} + +//****************************************************************************** +int serial_getc(serial_t *obj) +{ + int c; + + // Wait for data to be available + while ((obj->uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY) == 0); + + c = obj->fifo->rx; + + return c; +} + +//****************************************************************************** +void serial_putc(serial_t *obj, int c) +{ + // Wait for room in the FIFO without blocking interrupts. + while (UART_NumWriteAvail(obj->uart) == 0); + + // Must clear before every write to the buffer to know that the FIFO + // is empty when the TX DONE bit is set + obj->uart->intfl = MXC_F_UART_INTFL_TX_DONE; + obj->fifo->tx = (uint8_t)c; +} + +//****************************************************************************** +int serial_readable(serial_t *obj) +{ + return UART_NumReadAvail(obj->uart); +} + +//****************************************************************************** +int serial_writable(serial_t *obj) +{ + return UART_NumWriteAvail(obj->uart); +} + +//****************************************************************************** +void serial_clear(serial_t *obj) +{ + // Clear the RX and TX FIFOs + UART_DrainRX(obj->uart); + UART_DrainTX(obj->uart); +} + +//****************************************************************************** +void serial_break_set(serial_t *obj) +{ + // Make sure that nothing is being sent + while (((obj->uart->tx_fifo_ctrl & MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY) + >> MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY_POS) > 0); + while (!(obj->uart->intfl & MXC_F_UART_INTFL_TX_DONE)); + + // Configure TX to output 0 + usurp_pin(obj->tx_pin, 0); + + // GPIO is setup now, but we need to unmap UART from the pin + pin_function_t *pin_func = (pin_function_t *)pinmap_find_function(obj->tx_pin, PinMap_UART_TX); + *pin_func->reg_req &= ~MXC_F_IOMAN_UART_REQ_IO_REQ; + MBED_ASSERT((*pin_func->reg_ack & MXC_F_IOMAN_UART_ACK_IO_ACK) == 0); +} + +//****************************************************************************** +void serial_break_clear(serial_t *obj) +{ + // Configure TX to output 1 + usurp_pin(obj->tx_pin, 1); + // Return TX to UART control + serial_pinout_tx(obj->tx_pin); +} + +//****************************************************************************** +void serial_pinout_tx(PinName tx) +{ + pinmap_pinout(tx, PinMap_UART_TX); +} + +//****************************************************************************** +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +{ + pin_function_t rtscts_pin_func = {0}; + + obj->cfg.cts = 0; + obj->cfg.rts = 0; + + if ((FlowControlCTS == type) || (FlowControlRTSCTS == type)) { + UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); + UARTName uart = (UARTName)pinmap_merge(uart_cts, (UARTName)obj->uart); + // Assert pin is usable with existing uart + MBED_ASSERT(uart != (UARTName)NC); + + pin_function_t *pin_func; + pin_func = (pin_function_t *)pinmap_find_function(txflow, PinMap_UART_CTS); + rtscts_pin_func.req_val |= pin_func->req_val; + + obj->cfg.cts = 1; + } + + if ((FlowControlRTS == type) || (FlowControlRTSCTS == type)) { + UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); + UARTName uart = (UARTName)pinmap_merge(uart_rts, (UARTName)obj->uart); + MBED_ASSERT(uart != (UARTName)NC); + + pin_function_t *pin_func; + pin_func = (pin_function_t *)pinmap_find_function(rxflow, PinMap_UART_RTS); + rtscts_pin_func.req_val |= pin_func->req_val; + + obj->cfg.rts = 1; + } + + obj->sys_cfg.io_cfg.req_val.value |= rtscts_pin_func.req_val; + + int retval = UART_Init(obj->uart, &obj->cfg, &obj->sys_cfg); + MBED_ASSERT(retval == E_NO_ERROR); +} + +//****************************************************************************** +static void usurp_pin(PinName pin, int state) +{ + gpio_t gpio; + gpio_init_out(&gpio, pin); + gpio_write(&gpio, state); +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/sleep.c b/targets/TARGET_Maxim/TARGET_MAX32625/sleep.c new file mode 100644 index 0000000..560a440 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/sleep.c @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "sleep_api.h" +#include "lp.h" + +void sleep(void) +{ + LP_EnterLP2(); +} + +// Low-power stop mode +void deepsleep(void) +{ + sleep(); +} diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c new file mode 100644 index 0000000..e8bb11a --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed_assert.h" +#include "spi_api.h" // mbed HAL +#include "spim_regs.h" // bare metal +#include "spim.h" // Maxim CMSIS driver +#include "pinmap.h" +#include "PeripheralPins.h" + +//****************************************************************************** +void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) +{ + // Make sure pins are pointing to the same SPI instance + SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI); + SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO); + SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK); + SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL); + + SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); + SPIName spi_cntl; + + // Control is SCK and optionaly SS + if ((SPIName)spi_ssel != (SPIName)NC) { + spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); + } else { + spi_cntl = spi_sclk; + } + + SPIName spi = (SPIName)pinmap_merge(spi_data, spi_cntl); + + MBED_ASSERT((SPIName)spi != (SPIName)NC); + + obj->spi = (mxc_spim_regs_t *)spi; + + // Merge pin function requests for use with CMSIS init func + ioman_req_t io_req; + pin_function_t *pin_func; + pin_func = (pin_function_t *)pinmap_find_function(mosi, PinMap_SPI_MOSI); + io_req.value = pin_func->req_val; + pin_func = (pin_function_t *)pinmap_find_function(miso, PinMap_SPI_MISO); + io_req.value |= pin_func->req_val; + pin_func = (pin_function_t *)pinmap_find_function(sclk, PinMap_SPI_SCLK); + io_req.value |= pin_func->req_val; + if ((SPIName)spi_ssel != (SPIName)NC) { + pin_func = (pin_function_t *)pinmap_find_function(ssel, PinMap_SPI_SSEL); + io_req.value |= pin_func->req_val; + } + + // Using req and ack pointers of last pin function lookup + sys_cfg_spim_t sys_cfg; + sys_cfg.io_cfg.req_reg = pin_func->reg_req; + sys_cfg.io_cfg.ack_reg = pin_func->reg_ack; + sys_cfg.io_cfg.req_val = io_req; + sys_cfg.clk_scale = CLKMAN_SCALE_AUTO; + + // Defaults + spim_cfg_t spim_cfg; + spim_cfg.mode = 0; + spim_cfg.ssel_pol = 0; + spim_cfg.baud = 1000000; + + SPIM_Init(obj->spi, &spim_cfg, &sys_cfg); + + obj->index = MXC_SPIM_GET_IDX(obj->spi); +} + +//****************************************************************************** +void spi_format(spi_t *obj, int bits, int mode, int slave) +{ + // Check the validity of the inputs + MBED_ASSERT(bits == 8); + + // Only supports master mode + MBED_ASSERT(!slave); + + // Set the mode + obj->spi->mstr_cfg &= ~(MXC_F_SPIM_MSTR_CFG_SPI_MODE); + obj->spi->mstr_cfg |= (mode << MXC_F_SPIM_MSTR_CFG_SPI_MODE_POS); +} + +//****************************************************************************** +void spi_frequency(spi_t *obj, int hz) +{ + // Maximum frequency is half the system frequency + MBED_ASSERT((unsigned int)hz <= (SystemCoreClock / 2)); + unsigned clocks = ((SystemCoreClock / 2) / hz); + + // Figure out the divider ratio + int clk_div = 1; + while(clk_div < 10) { + if(clocks < 0x10) { + break; + } + clk_div++; + clocks = clocks >> 1; + } + + // Turn on the SPI clock + if(obj->index == 0) { + MXC_CLKMAN->sys_clk_ctrl_11_spi0 = clk_div; + } else if(obj->index == 1) { + MXC_CLKMAN->sys_clk_ctrl_12_spi1 = clk_div; + } else if(obj->index == 2) { + MXC_CLKMAN->sys_clk_ctrl_13_spi2 = clk_div; + } else { + MBED_ASSERT(0); + } + + // Set the number of clocks to hold sclk high and low + MXC_SET_FIELD(&obj->spi->mstr_cfg, + (MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK | MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK), + ((clocks << MXC_F_SPIM_MSTR_CFG_SCK_HI_CLK_POS) | (clocks << MXC_F_SPIM_MSTR_CFG_SCK_LO_CLK_POS))); +} + +//****************************************************************************** +int spi_master_write(spi_t *obj, int value) +{ + spim_req_t req; + uint8_t out; + uint8_t in; + + out = value; + + req.ssel = 0; + req.deass = 0; + req.tx_data = &out; + req.rx_data = ∈ + req.width = SPIM_WIDTH_1; + req.len = 1; + req.ssel = 0; + req.deass = 1; + req.callback = NULL; + + SPIM_Trans(obj->spi, &req); + + return *req.rx_data; +} + +//****************************************************************************** +int spi_busy(spi_t *obj) +{ + return SPIM_Busy(obj->spi); +} + +//****************************************************************************** +uint8_t spi_get_module(spi_t *obj) +{ + return obj->index; +} + diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/us_ticker.c b/targets/TARGET_Maxim/TARGET_MAX32625/us_ticker.c new file mode 100644 index 0000000..5da2417 --- /dev/null +++ b/targets/TARGET_Maxim/TARGET_MAX32625/us_ticker.c @@ -0,0 +1,257 @@ +/******************************************************************************* + * Copyright (c) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include +#include "mbed_error.h" +#include "us_ticker_api.h" +#include "PeripheralNames.h" +#include "tmr.h" + +#define US_TIMER MXC_TMR0 +#define US_TIMER_IRQn TMR0_0_IRQn + +static int us_ticker_inited = 0; +static uint32_t ticks_per_us; +static uint32_t tick_win; +static volatile uint64_t current_cnt; // Hold the current ticks +static volatile uint64_t event_cnt; // Holds the value of the next event + +#define MAX_TICK_VAL ((uint64_t)0xFFFFFFFF * ticks_per_us) + +//****************************************************************************** +static inline void inc_current_cnt(uint32_t inc) +{ + // Overflow the ticker when the us ticker overflows + current_cnt += inc; + if (current_cnt > MAX_TICK_VAL) { + current_cnt -= (MAX_TICK_VAL + 1); + } +} + +//****************************************************************************** +static inline int event_passed(uint64_t current, uint64_t event) +{ + // Determine if the event has already happened. + // If the event is behind the current ticker, within a window, + // then the event has already happened. + if (((current < tick_win) && ((event < current) || + (event > (MAX_TICK_VAL - (tick_win - current))))) || + ((event < current) && (event > (current - tick_win)))) { + return 1; + } + + return 0; +} + +//****************************************************************************** +static inline uint64_t event_diff(uint64_t current, uint64_t event) +{ + // Check to see if the ticker will overflow before the event + if(current <= event) { + return (event - current); + } + + return ((MAX_TICK_VAL - current) + event); +} + +//****************************************************************************** +static void tmr_handler(void) +{ + uint32_t cmp = TMR32_GetCompare(US_TIMER); + TMR32_SetCompare(US_TIMER, 0xFFFFFFFF); // reset to max value to prevent further interrupts + TMR32_ClearFlag(US_TIMER); + NVIC_ClearPendingIRQ(US_TIMER_IRQn); + + inc_current_cnt(cmp); + + if (event_passed(current_cnt + TMR32_GetCount(US_TIMER), event_cnt)) { + // the timestamp has expired + event_cnt = 0xFFFFFFFFFFFFFFFFULL; // reset to max value + us_ticker_irq_handler(); + } else { + uint64_t diff = event_diff(current_cnt, event_cnt); + if (diff < (uint64_t)0xFFFFFFFF) { + // the event occurs before the next overflow + TMR32_SetCompare(US_TIMER, diff); + + // Since the timer keeps counting after the terminal value is reached, it is possible that the new + // terminal value is in the past. + if (TMR32_GetCompare(US_TIMER) < TMR32_GetCount(US_TIMER)) { + // the timestamp has expired + TMR32_SetCompare(US_TIMER, 0xFFFFFFFF); // reset to max value to prevent further interrupts + TMR32_ClearFlag(US_TIMER); + NVIC_ClearPendingIRQ(US_TIMER_IRQn); + event_cnt = 0xFFFFFFFFFFFFFFFFULL; // reset to max value + us_ticker_irq_handler(); + } + } + } +} + +//****************************************************************************** +void us_ticker_init(void) +{ + if (us_ticker_inited) { + return; + } + + us_ticker_inited = 1; + current_cnt = 0; + event_cnt = 0xFFFFFFFFFFFFFFFFULL; // reset to max value + ticks_per_us = SystemCoreClock / 1000000; + tick_win = SystemCoreClock / 100; // Set the tick window to 10ms + + int retval = TMR_Init(US_TIMER, TMR_PRESCALE_DIV_2_0, NULL); + MBED_ASSERT(retval == E_NO_ERROR); + + tmr32_cfg_t cfg; + cfg.mode = TMR32_MODE_CONTINUOUS; + cfg.polarity = TMR_POLARITY_UNUSED; + cfg.compareCount = 0xFFFFFFFF; + TMR32_Config(US_TIMER, &cfg); + + NVIC_SetVector(US_TIMER_IRQn, (uint32_t)tmr_handler); + NVIC_EnableIRQ(US_TIMER_IRQn); + TMR32_EnableINT(US_TIMER); + + TMR32_Start(US_TIMER); +} + +//****************************************************************************** +void us_ticker_deinit(void) +{ + TMR32_Stop(US_TIMER); + TMR32_DisableINT(US_TIMER); + TMR32_ClearFlag(US_TIMER); + us_ticker_inited = 0; +} + +//****************************************************************************** +uint32_t us_ticker_read(void) +{ + uint64_t current_cnt1, current_cnt2; + uint32_t cmp, cnt; + uint32_t flag1, flag2; + + if (!us_ticker_inited) { + us_ticker_init(); + } + + // Ensure coherency between current_cnt and TMR32_GetCount() + do { + current_cnt1 = current_cnt; + flag1 = TMR32_GetFlag(US_TIMER); + cmp = TMR32_GetCompare(US_TIMER); + cnt = TMR32_GetCount(US_TIMER); + flag2 = TMR32_GetFlag(US_TIMER); + current_cnt2 = current_cnt; + } while ((current_cnt1 != current_cnt2) || (flag1 != flag2)); + + // Account for an unserviced interrupt + if (flag1) { + current_cnt1 += cmp; + } + + current_cnt1 += cnt; + + return (current_cnt1 / ticks_per_us); +} + +//****************************************************************************** +void us_ticker_set_interrupt(timestamp_t timestamp) +{ + // Note: interrupts are disabled before this function is called. + + TMR32_Stop(US_TIMER); + + if (TMR32_GetFlag(US_TIMER)) { + TMR32_ClearFlag(US_TIMER); + NVIC_ClearPendingIRQ(US_TIMER_IRQn); + inc_current_cnt(TMR32_GetCompare(US_TIMER)); + } + + // add and reset the current count value + inc_current_cnt(TMR32_GetCount(US_TIMER)); + TMR32_SetCount(US_TIMER, 0); + + // add the number of cycles that the timer is disabled here for + inc_current_cnt(200); + + event_cnt = (uint64_t)timestamp * ticks_per_us; + + // Check to see if the event has already passed + if (!event_passed(current_cnt, event_cnt)) { + uint64_t diff = event_diff(current_cnt, event_cnt); + if (diff < (uint64_t)0xFFFFFFFF) { + // the event occurs before the next overflow + TMR32_SetCompare(US_TIMER, diff); + } else { + // the event occurs after the next overflow + TMR32_SetCompare(US_TIMER, 0xFFFFFFFF); // set to max + } + } else { + // the requested timestamp occurs in the past + // set the timer up to immediately expire + TMR32_SetCompare(US_TIMER, 1); + } + + TMR32_Start(US_TIMER); +} + +//****************************************************************************** +void us_ticker_disable_interrupt(void) +{ + // There are no more events, set timer overflow to the max + TMR32_SetCompare(US_TIMER, 0xFFFFFFFF); +} + +//****************************************************************************** +void us_ticker_clear_interrupt(void) +{ + // cleared in the local handler +} + +//****************************************************************************** +void us_ticker_set(timestamp_t timestamp) +{ + TMR32_Stop(US_TIMER); + current_cnt = (uint64_t)timestamp * ticks_per_us; + TMR32_SetCount(US_TIMER, 0); + TMR32_SetCompare(US_TIMER, 0xFFFFFFFF); + TMR32_Start(US_TIMER); + + if (((uint64_t)timestamp * ticks_per_us) >= event_cnt) { + // The next timestamp has elapsed. Trigger the interrupt to handle it. + NVIC_SetPendingIRQ(US_TIMER_IRQn); + } +} diff --git a/targets/TARGET_Maxim/mbed_rtx.h b/targets/TARGET_Maxim/mbed_rtx.h index f8ad272..1099d4a 100644 --- a/targets/TARGET_Maxim/mbed_rtx.h +++ b/targets/TARGET_Maxim/mbed_rtx.h @@ -62,6 +62,21 @@ #define OS_CLOCK 48000000 #endif +#elif defined(TARGET_MAX32625) + +#ifndef INITIAL_SP +#define INITIAL_SP (0x20028000UL) +#endif +#ifndef OS_TASKCNT +#define OS_TASKCNT 14 +#endif +#ifndef OS_MAINSTKSIZE +#define OS_MAINSTKSIZE 256 +#endif +#ifndef OS_CLOCK +#define OS_CLOCK 96000000 +#endif + #endif #endif // MBED_MBED_RTX_H diff --git a/targets/targets.json b/targets/targets.json index b9d3395..de57a06 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1815,6 +1815,16 @@ "features": ["BLE"], "release_versions": ["2", "5"] }, + "MAX32625NEXPAQ": { + "inherits": ["Target"], + "core": "Cortex-M4F", + "macros": ["__SYSTEM_HFX=96000000","TARGET=MAX32625","TARGET_REV=0x4132"], + "extra_labels": ["Maxim", "MAX32625"], + "supported_toolchains": ["GCC_ARM", "IAR", "ARM"], + "progen": {"target": "max32625nexpaq"}, + "device_has": ["ANALOGIN", "ERROR_RED", "I2C", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES"], + "release_versions": ["2", "5"] + }, "EFM32": { "inherits": ["Target"], "extra_labels": ["Silicon_Labs", "EFM32"],