/*----------------------------------------------------------------------------*/ void pinSetFunction(struct Pin pin, uint8_t function) { volatile uint32_t * const reg = calcControlReg(pin.data); const uint32_t value = *reg; switch (function) { case PIN_DEFAULT: { /* Some pins have default function value other than zero */ bool alternate; alternate = pin.data.port == 0 && (pin.data.offset == 0 || (pin.data.offset >= 10 && pin.data.offset <= 11)); alternate = alternate || (pin.data.port == 1 && pin.data.offset <= 3); function = alternate ? 1 : 0; break; } case PIN_ANALOG: *reg = value & ~IOCON_DIGITAL; return; } *reg = (value & ~IOCON_FUNC_MASK) | IOCON_FUNC(function); }
static BSP_START_TEXT_SECTION __attribute__((flatten)) rtems_status_code lpc24xx_pin_set_function( #ifdef ARM_MULTILIB_ARCH_V4 volatile uint32_t *pinsel, uint32_t pinsel_mask, uint32_t pinsel_value, #else volatile uint32_t *iocon, lpc24xx_pin_range pin_range, #endif volatile uint32_t *fio_dir, uint32_t fio_bit ) { #ifdef ARM_MULTILIB_ARCH_V4 rtems_interrupt_level level; rtems_interrupt_disable(level); *pinsel = (*pinsel & ~pinsel_mask) | pinsel_value; rtems_interrupt_enable(level); #else uint32_t iocon_extra = 0; /* TODO */ switch (pin_range.fields.type) { case LPC17XX_PIN_TYPE_I2C_FAST_PLUS: iocon_extra |= IOCON_HS; break; case LPC17XX_PIN_TYPE_OPEN_DRAIN: iocon_extra |= IOCON_OD; break; default: break; } *iocon = IOCON_FUNC(pin_range.fields.function) | iocon_extra; #endif return RTEMS_SUCCESSFUL; }