void setupLED(void) { #if defined(ARCH_SI32) // Enable Crossbar 1 to use LED SET_REG(XBAR1_SET, 0x80000000); SET_REG(XBAR0H_SET, 0x80000000); // Set LED 3 as push pull output SET_REG(GPIO_OUTMD_SET(PORT_BANK3), 0x00000001); SET_REG(GPIO_MDSEL_SET(PORT_BANK3), 0x00000001); #elif defined(ARC_STM32) // todo, swap out hardcoded pin/bank with macro u32 rwmVal; /* read-write-modify place holder var */ /* Setup APB2 (GPIOA) */ rwmVal = GET_REG(RCC_APB2ENR); rwmVal |= 0x00000004; SET_REG(RCC_APB2ENR, rwmVal); /* Setup GPIOA Pin 5 as PP Out */ SET_REG(GPIO_CRL(GPIOA), 0x00100000); rwmVal = GET_REG(GPIO_CRL(GPIOA)); rwmVal &= 0xFF0FFFFF; rwmVal |= 0x00100000; SET_REG(GPIO_CRL(GPIOA), rwmVal); setPin(GPIOA, 5); #endif // defined(ARCH_SI32) }
Inline void set_cr_cnf(uint32_t reg, uint_t p, int_t v) { if (p < 8) { sil_andw((void*)GPIO_CRL(reg), ~CR_CNF_MASK(p)); sil_orw((void*)GPIO_CRL(reg), CR_CNF(p, v)); } else if (8 <= p && p < 16) { sil_andw((void*)GPIO_CRH(reg), ~CR_CNF_MASK(p - 8)); sil_orw((void*)GPIO_CRH(reg), CR_CNF(p - 8, v)); } }
static void setupLED (void) { // todo, swap out hardcoded pin/bank with macro u32 rwmVal; /* read-write-modify place holder var */ /* Setup APB2 (GPIOA) */ rwmVal = GET_REG(RCC_APB2ENR); rwmVal |= 0x00000004; SET_REG(RCC_APB2ENR,rwmVal); /* Setup GPIOA Pin 5 as PP Out */ SET_REG(GPIO_CRL(GPIOA), 0x00100000); rwmVal = GET_REG(GPIO_CRL(GPIOA)); rwmVal &= 0xFF0FFFFF; rwmVal |= 0x00100000; SET_REG(GPIO_CRL(GPIOA),rwmVal); setPin(GPIOA,5); }
void gpio_set_mode(uint32_t gpioport, uint8_t mode, uint8_t cnf, uint16_t gpios) { uint16_t i, offset = 0; uint32_t crl = 0, crh = 0, tmp32 = 0; /* * We want to set the config only for the pins mentioned in gpios, * but keeping the others, so read out the actual config first. */ crl = GPIO_CRL(gpioport); crh = GPIO_CRH(gpioport); /* Iterate over all bits, use i as the bitnumber. */ for (i = 0; i < 16; i++) { /* Only set the config if the bit is set in gpios. */ if (!((1 << i) & gpios)) { continue; } /* Calculate bit offset. */ offset = (i < 8) ? (i * 4) : ((i - 8) * 4); /* Use tmp32 to either modify crl or crh. */ tmp32 = (i < 8) ? crl : crh; /* Modify bits are needed. */ tmp32 &= ~(0xf << offset); /* Clear the bits first. */ tmp32 |= (mode << offset) | (cnf << (offset + 2)); /* Write tmp32 into crl or crh, leave the other unchanged. */ crl = (i < 8) ? tmp32 : crl; crh = (i >= 8) ? tmp32 : crh; } GPIO_CRL(gpioport) = crl; GPIO_CRH(gpioport) = crh; }