#include "common.h"
#include "ics.h"
#include "rtc.h"
#include "uart.h"
#include "systick.h"
#include "bme.h"
#include "sysinit.h"
#include "start.h"
#define GPIO_ALIAS_OFFSET 0x000F0000L
#define GPIOB_PDOR_ALIAS (((uint32_t)&GPIOB->PDOR)-GPIO_ALIAS_OFFSET)
int main (void);
void RTC_Task(void);
uint32_t BME_LogicANDPwithC(void);
uint32_t BME_LogicANDPwithBME(void);
uint32_t BME_LogicORPwithC(void);
uint32_t BME_LogicORPwithBME(void);
uint32_t BME_LogicOXRPwithC(void);
uint32_t BME_LogicOXRPwithBME(void);
uint32_t BME_LogicSETPwithC(void);
uint32_t BME_LogicSETPwithBME(void);
uint32_t BME_LogicCLEARPwithC(void);
uint32_t BME_LogicCLEARPwithBME(void);
uint32_t BME_BFIwithC(uint32_t *pAddr, uint8_t u8BitPos, uint8_t u8FieldWidth, uint32_t u32Data);
uint32_t BME_BFIwithBME(void);
int main (void)
{
sysinit();
printf("\r\nRunning the BME_Timetest_demo project.\r\n");
printf("Logic AND operation.\r\n");
printf("Logic operation in C takes %d ticks!\r\n", BME_LogicANDPwithC());
printf("Logic operation with BME takes %d ticks!\r\n", BME_LogicANDPwithBME());
printf("Logic OR operation.\r\n");
printf("Logic operation in C takes %d ticks!\r\n", BME_LogicORPwithC());
printf("Logic operation with BME takes %d ticks!\r\n", BME_LogicORPwithBME());
printf("Logic OXR operation.\r\n");
printf("Logic operation in C takes %d ticks!\r\n", BME_LogicOXRPwithC());
printf("Logic operation with BME takes %d ticks!\r\n", BME_LogicOXRPwithBME());
printf("Logic BIT-SET operation.\r\n");
printf("Logic operation in C takes %d ticks!\r\n", BME_LogicSETPwithC());
printf("Logic operation with BME takes %d ticks!\r\n", BME_LogicSETPwithBME());
printf("Logic BIT-CLEAR operation.\r\n");
printf("Logic operation in C takes %d ticks!\r\n", BME_LogicCLEARPwithC());
printf("Logic operation with BME takes %d ticks!\r\n", BME_LogicCLEARPwithBME());
GPIOB->PDDR |= (0xF << 16);
GPIOB->PIDR &= ~(0xF << 16);
printf("Bit field operation in C takes %d ticks!\r\n", BME_BFIwithC((uint32_t*)&GPIOB->PDOR,16,4-1, 5<<16)); /*!< bit width -1 as 3rd parameter */
printf("Bit field operation with BME takes %d ticks!\r\n", BME_BFIwithBME());
printf("Test completed!\n");
while(1)
{
}
}
/******************C***AND**********************************/
uint32_t BME_LogicANDPwithC(void)
{
uint32_t i=0;
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
GPIOA->PDOR &= 0x02; //AND
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/******************BME*********AND********************************/
uint32_t BME_LogicANDPwithBME(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
BME_AND(&GPIOA->PDOR) = 0x02; //寄存器中的数据与0x02执行AND
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************C************OR*************************************/
uint32_t BME_LogicORPwithC(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
GPIOA->PDOR |= 0x02; //OR
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************BME************OR*************************************/
uint32_t BME_LogicORPwithBME(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
BME_OR(&GPIOA->PDOR) = 0x02; //寄存器中的数据与0x02执行OR
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************C************XOR*************************************/
uint32_t BME_LogicOXRPwithC(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
GPIOA->PDOR ^= 0x02; //XOR
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************BME************XOR*************************************/
uint32_t BME_LogicOXRPwithBME(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
BME_XOR(&GPIOA->PDOR) = 0x02; //寄存器中的数据与0x02执行异或
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************C************BIT-SET*************************************/
uint32_t BME_LogicSETPwithC(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
GPIOA->PDOR |= 0x02; //SET
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************BME************BIT-SET*************************************/
uint32_t BME_LogicSETPwithBME(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
BME_BIT_SET(&GPIOA->PDOR,0); //寄存器对应位置1
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************C************BIT-CLEAR*************************************/
uint32_t BME_LogicCLEARPwithC(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
//PDOR第一位清零
GPIOA->PDOR &= ~0x01;
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/*******************BME************BIT-CLEAR*************************************/
uint32_t BME_LogicCLEARPwithBME(void)
{
uint32_t u32LogicOPTicks;
GPIOA->PDDR |= 0xff;
GPIOA->PIDR &= ~0xff;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
BME_BIT_CLEAR(&GPIOA->PDOR,0); //寄存器对应位清零
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/***************************************************************************
*在以 u8BitPos为起始位,宽度为u8FieldWidth+1,的区域内插入输入数据u32Data
******************************************************************************/
uint32_t BME_BFIwithC(uint32_t *pAddr, uint8_t u8BitPos, uint8_t u8FieldWidth, uint32_t u32Data)
{
uint32_t u32RegVal;
uint32_t u32Mask;
uint32_t u32LogicOPTicks;
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
u32RegVal = *pAddr;
u32Mask = ((1 << (u8FieldWidth+1)) - 1) << u8BitPos;
u32RegVal = (u32RegVal & ~u32Mask)|((u32Data) & u32Mask);
*pAddr = u32RegVal;
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
/************************************************************************
* write 5 to bit 19..16
**************************************************************************/
uint32_t BME_BFIwithBME(void)
{
uint32_t u32LogicOPTicks;
uint32_t u32Data = (0x5 << 16);
uint32_t u32Addr = GPIOB_PDOR_ALIAS;
GPIOB->PDDR |= (0xF << 16);
GPIOB->PDOR = 0;
GPIOB->PIDR &= ~(0xF << 16);
SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = 0x0;
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk);
BME_BITFIELD_INSERT(u32Addr,16,4) = u32Data; /* write 5 to bit 19..16 */
u32LogicOPTicks = SysTick->VAL;
return (SysTick->LOAD - u32LogicOPTicks);
}
|