/** * @brief This function Sets bit value at given address * @param Address SRAM or Peripheral Address * Can choose any address between : * 0x20000000 - 0x2001FFFC | for SRAM * 0x40000000 - 0x40007FFC : APB1 | * 0x40010000 - 0x40057fff : APB2 | for Peripheral * 0x40020000 - 0x4007FFFC : AHB1 | * or Use Register Address: (uint32_t)&(GPIOD->BSRR) * @param pin Pin Value from Word * @return None */ void Bitband_Setbit(uint32_t Address, uint8_t pin) { if (Address >= 0x20000000 && Address <= 0x2001FFFC) { BITBAND_SRAM_SetBit(Address, pin); } else if((Address >= 0x40000000 && Address <= 0x40007FFC) || (Address >= 0x40010000 && Address <= 0x40057fff) ||(Address >= 0x40020000 && Address <= 0x4007FFFC)) { BITBAND_Peri_SetBit(Address, pin); } }
/*********************************************************************//** * @brief c_entry: main function * @param[in] none * @return int **********************************************************************/ int c_entry(void) { /* Main Program */ uint32_t temp; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu _DBG(menu); /* test Bit-banding SRAM first --------------------------------------------------------- */ _DBG_("Test bit-band SRAM... "); //read variable at VAR_ADDRESS temp = (*(volatile uint32_t *)(VAR_ADDRESS)); //print temp value _DBG("The value at address "); _DBH32(VAR_ADDRESS); _DBG(": "); _DBH32(temp); _DBG_(""); /* Use bitband function to read VAR_BIT value */ temp = BITBAND_SRAM_GetBit(VAR_ADDRESS,VAR_BIT); _DBG("Use bit-band function to get value at bit 3: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* clear bit */ BITBAND_SRAM_ClearBit(VAR_ADDRESS,VAR_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(VAR_ADDRESS)); _DBG("Value after clear bit 3 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* Set bit */ BITBAND_SRAM_SetBit(VAR_ADDRESS,VAR_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(VAR_ADDRESS)); _DBG("Value after set bit 3 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); _DBG_(""); /* Then, test Bit-banding PERI --------------------------------------------------------- */ _DBG_("Test bit-band PERIPHERAL... "); LPC_SPI->SPCR =(1<<5)|(1<<3)|(10<<8); /* Read the current value of peripheral register */ temp = (*(volatile uint32_t *)(PERI_ADDRESS)); _DBG("The value of peripheral register at "); _DBH32(PERI_ADDRESS); _DBG(": ");_DBG_(""); _DBH32(temp); _DBG_(""); /* Use bitband function to read VAR_BIT value */ temp = BITBAND_PERI_GetBit(PERI_ADDRESS,PERI_BIT); _DBG("Use bit-band function to get value at bit 5: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* clear bit */ BITBAND_PERI_ClearBit(PERI_ADDRESS,PERI_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(PERI_ADDRESS)); _DBG("Peripheral register after clear bit 5 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* Set bit */ BITBAND_PERI_SetBit(PERI_ADDRESS,PERI_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(PERI_ADDRESS)); _DBG("Peripheral register after set bit 5 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); while (1); return 0; }