zoukankan      html  css  js  c++  java
  • 《通过himm读取指定引脚并保存在共享内存中》

    1.需要读取海思核心板的几个引脚的状态

      将要读取的引脚设置为输入模式(还用注意引脚是否被复用

    2.修改himm源码去读取

      在海思SDK  xxx/osdrv/tools/board_tools/reg-tools-1.0.0/source/tools/下 提供了himm的读写工具源码。

      我需要读取的是GPIO13_0,GPIO13_1,GPIO13_2,GPIO13_3。

      海思35203520_SDKHi3521A V100R001C01SPC0300.hardware1.Hi3520DV300chipdocument_cn中的《Hi3521A/Hi3520DV300 H.264编解码处理器用户指南.pdf》13.5章可依查看到有关GPIO的描述

      

       

      

       所以读取GPIO13的数据寄存器,地址为0x1222_003C。(具体为什么是3C,因为我读取的是0123引脚也就是00_0011_1100,数据屏蔽机制)

      然后就可以在himm里面进行判断,如果是这个地址,将读出来的值放到共享内存中。

    /******************************************************************************
    
      Copyright (C), 2001-2011, Hisilicon Tech. Co., Ltd.
    
     ******************************************************************************
      File Name     : himd.c
      Version       : Initial Draft
      Author        : Hisilicon multimedia software group
      Created       : 2005/7/1
      Last Modified :
      Description   : HI Memory Modify
      Function List :
      History       :
      1.Date        : 2005/7/27
        Author      : T41030
        Modification: Created file
    
    ******************************************************************************/
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "memmap.h"
    #include "hi.h"
    #include "strfunc.h"
    #include <sys/ipc.h>
    #include <sys/shm.h>
    #include "btools.h"
    
    #ifdef __cplusplus
    #if __cplusplus
    extern "C"{
    #endif
    #endif /* __cplusplus */
    
    #define DEFAULT_MD_LEN 128
    
    typedef struct _addr_value{
        unsigned char value[2]
    }addr_value;
    
    HI_RET himm(int argc , char* argv[])
    {
        U32 ulAddr = 0;
        U32 ulOld, ulNew;
        char strNew[16];
        VOID* pMem  = NULL;
        unsigned char add_value;
        int shmid;
        addr_value *p_addr = NULL;
    
        if (argc <= 1)
        {
            printf("usage: %s <address> <Value>. sample: %s 0x80040000 0x123
    ", argv[0], argv[0]);
            EXIT("", -1);
        }
    
        shmid = shmget(0x2234, sizeof(addr_value), IPC_CREAT | 0666); 
        if(shmid == -1)
        {
            printf("shmget is failed 
    ");
        }
    
        p_addr = shmat(shmid, NULL, 0);
    
        if (HI_SUCCESS != LOG_CREATE(LOG_LEVEL_DEBUG, 2048))
        {
            printf("create logqueue error.
    ");
            return -1;
        }
    
        
        if (argc == 2)
        {
            if( StrToNumber(argv[1], &ulAddr) == HI_SUCCESS)
            {
                printf("====dump memory %#lX====
    ", ulAddr);
                #ifdef PC_EMULATOR
                #define SHAREFILE "../shm"
                printf("**** is Emulator, use share file : %s ****
    ", SHAREFILE);
                pMem = mmapfile(SHAREFILE , DEFAULT_MD_LEN);
                if (NULL == pMem)
                {
                    EXIT("Memory Map error.", -1);
                }
                pMem += ulAddr;
                #else        
                pMem = memmap(ulAddr, DEFAULT_MD_LEN);
                #endif
                ulOld = *(U32*)pMem;
                
                /*hi_hexdump(STDOUT, pMem, DEFAULT_MD_LEN, 16);*/
                printf("%s: 0x%08lX
    ", argv[1], ulOld);
                
                if(ulAddr == 0x1222003c)
                {
                    add_value = ulOld;
                    p_addr->value[0] = add_value;
                    printf("GPIO13 = 0x%x
    ", add_value);
                }
    
    
                
    #if 0
                printf("NewValue:");
                scanf("%s", strNew);
                if (StrToNumber(strNew, &ulNew) == HI_SUCCESS)
                {
                    *(U32*)pMem = ulNew;
                }
                else
                {
                    printf("Input Error
    ");
                }
    #endif
            }
            else
            {
                printf("Please input address like 0x12345
    ");
            }
        }
        else if (argc == 3)
        {
            if( StrToNumber(argv[1], &ulAddr) == HI_SUCCESS &&  
                StrToNumber(argv[2], &ulNew) == HI_SUCCESS)
            {
                pMem = memmap(ulAddr, DEFAULT_MD_LEN);
                ulOld = *(U32*)pMem;
                /*hi_hexdump(STDOUT, pMem, DEFAULT_MD_LEN, 16);*/
                printf("%s: 0x%08lX --> 0x%08lX 
    ", argv[1], ulOld, ulNew);
                *(U32*)pMem = ulNew;
            }
        }
        else
        {
            printf("xxx
    ");
        }
        return 0;
    }
    
    #ifdef __cplusplus
    #if __cplusplus
    }
    #endif
    #endif /* __cplusplus */
  • 相关阅读:
    开博说两句
    学习总结 (持续更新)
    ip代理 120203
    [vs2005]关于预编绎网站的问题[已预编译此应用程序的错误]
    JAVA类基础
    集合类和泛型
    IO流——字符流
    多线程和包
    多态和内部类
    抽象类与接口
  • 原文地址:https://www.cnblogs.com/zhuangquan/p/12018842.html
Copyright © 2011-2022 走看看