zoukankan      html  css  js  c++  java
  • [笔记].关于Nios II的数据类型的一点想法

    鄙人觉得Nios II HAL自带的数据类型宏真的不好用,而且还有个alt_前缀,移植很麻烦。

    代码1 alt_types.h

    #ifndef __ALT_TYPES_H__
    #define __ALT_TYPES_H__
    
    /******************************************************************************
    *                                                                             *
    * License Agreement                                                           *
    *                                                                             *
    * Copyright (c) 2003 Altera Corporation, San Jose, California, USA.           *
    * All rights reserved.                                                        *
    *                                                                             *
    ******************************************************************************/
    
    /* 
     * Don't declare these typedefs if this file is included by assembly source.
     */
    #ifndef ALT_ASM_SRC
    typedef signed char  alt_8;
    typedef unsigned char  alt_u8;
    typedef signed short alt_16;
    typedef unsigned short alt_u16;
    typedef signed long alt_32;
    typedef unsigned long alt_u32;
    typedef long long alt_64;
    typedef unsigned long long alt_u64;
    #endif
    
    #define ALT_INLINE        __inline__
    #define ALT_ALWAYS_INLINE __attribute__ ((always_inline))
    #define ALT_WEAK          __attribute__((weak))
    
    #endif /* __ALT_TYPES_H__ */
    

    我习惯于使用STM32的数据类型宏,因为都是32位的RISC处理器,所以都是通用的,推荐大家也使用。哈哈,看起来都比较清爽。

    代码2 my_types.h

    // copy from stm32f10x_type.h
    
    #ifndef MY_TYPES_H_
    #define MY_TYPES_H_
    
    typedef signed long  s32;
    typedef signed short s16;
    typedef signed char  s8;
    
    typedef signed long  const sc32;  /* Read Only */
    typedef signed short const sc16;  /* Read Only */
    typedef signed char  const sc8;   /* Read Only */
    
    typedef volatile signed long  vs32;
    typedef volatile signed short vs16;
    typedef volatile signed char  vs8;
    
    typedef volatile signed long  const vsc32;  /* Read Only */
    typedef volatile signed short const vsc16;  /* Read Only */
    typedef volatile signed char  const vsc8;   /* Read Only */
    
    typedef unsigned long  u32;
    typedef unsigned short u16;
    typedef unsigned char  u8;
    
    typedef unsigned long  const uc32;  /* Read Only */
    typedef unsigned short const uc16;  /* Read Only */
    typedef unsigned char  const uc8;   /* Read Only */
    
    typedef volatile unsigned long  vu32;
    typedef volatile unsigned short vu16;
    typedef volatile unsigned char  vu8;
    
    typedef volatile unsigned long  const vuc32;  /* Read Only */
    typedef volatile unsigned short const vuc16;  /* Read Only */
    typedef volatile unsigned char  const vuc8;   /* Read Only */
    
    typedef enum {FALSE = 0, TRUE = !FALSE} bool;
    
    #endif /* MY_TYPES_H_ */
    

    下面给个my_types.h的使用范例。

    代码3 PIO寄存器结构体

    #include "my_types.h"
    
    // PIO Data structure
    typedef struct
    {
        vu32 DATA           : 32;
        vu32 DIRECTION      : 32;
        vu32 INTERRUPT_MASK : 32;
        vu32 EDGE_CAPTURE   : 32;
    
    }PIO_T;
    
     安德鲁® / CC BY 2.5     FPGA Run!
  • 相关阅读:
    推荐系统相关算法
    特征的生命周期
    数学知识索引
    蓄水池(Reservoir_sampling)抽样算法简记
    数赛刷题代码学习及课程学习链接
    逻辑回归(LR)总结复习
    我的面试问题记录
    开发中遇到的一些问题
    K-Means聚类和EM算法复习总结
    常见概率分布图表总结
  • 原文地址:https://www.cnblogs.com/yuphone/p/1887687.html
Copyright © 2011-2022 走看看