打印
[资料工具]

NV32 BOS位操作指令时间测试

[复制链接]
576|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
萧洛毫|  楼主 | 2018-2-27 09:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
萧洛毫|  楼主 | 2018-2-27 09:23 | 只看该作者
#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);  
}

使用特权

评论回复
板凳
萧洛毫|  楼主 | 2018-2-27 09:23 | 只看该作者
/******************************************************************************
*
* [url=home.php?mod=space&uid=247401]@brief[/url] define interrupt service routines referenced by the vector table.
*
* Note: Only "vectors.c" should include this header file.
*
*******************************************************************************
******************************************************************************/

#ifndef __ISR_H
#define __ISR_H


/* Example */
/*
#undef  VECTOR_036
#define VECTOR_036 RTC_Isr

// ISR(s) are defined in your project directory.
extern void RTC_Isr(void);
*/

/*!
* @brief define interrupt service routine for different vectors.
*
*/
#undef  VECTOR_036
#define VECTOR_036      RTC_Isr          /*!< Vector 36 points to RTC interrupt service routine */

extern void RTC_Isr(void);

#endif  //__ISR_H

/* End of "isr.h" */

使用特权

评论回复
地板
余三水| | 2018-2-27 23:29 | 只看该作者
没看懂,哪个是位操作指令呢?

使用特权

评论回复
5
tomyoct| | 2018-2-28 15:49 | 只看该作者
BOS位操作指令和另一个主贴之间的GPIO位带有什么操作的区别呢?

使用特权

评论回复
6
smilingangel| | 2018-3-18 15:50 | 只看该作者
这个代码的还是看下的,,不错的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

53

主题

254

帖子

0

粉丝