《海思 —— 通过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。

  海思3520\3520_SDK\Hi3521A V100R001C01SPC030\00.hardware\01.Hi3520DV300\chip\document_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\n", argv[0], argv[0]);
        EXIT("", -1);
    }

    shmid = shmget(0x2234, sizeof(addr_value), IPC_CREAT | 0666); 
    if(shmid == -1)
    {
        printf("shmget is failed \n");
    }

    p_addr = shmat(shmid, NULL, 0);

    if (HI_SUCCESS != LOG_CREATE(LOG_LEVEL_DEBUG, 2048))
    {
        printf("create logqueue error.\n");
        return -1;
    }

    
    if (argc == 2)
    {
        if( StrToNumber(argv[1], &ulAddr) == HI_SUCCESS)
        {
            printf("====dump memory %#lX====\n", ulAddr);
            #ifdef PC_EMULATOR
            #define SHAREFILE "../shm"
            printf("**** is Emulator, use share file : %s ****\n", 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\n", argv[1], ulOld);
            
            if(ulAddr == 0x1222003c)
            {
                add_value = ulOld;
                p_addr->value[0] = add_value;
                printf("GPIO13 = 0x%x\n", add_value);
            }


            
#if 0
            printf("NewValue:");
            scanf("%s", strNew);
            if (StrToNumber(strNew, &ulNew) == HI_SUCCESS)
            {
                *(U32*)pMem = ulNew;
            }
            else
            {
                printf("Input Error\n");
            }
#endif
        }
        else
        {
            printf("Please input address like 0x12345\n");
        }
    }
    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 \n", argv[1], ulOld, ulNew);
            *(U32*)pMem = ulNew;
        }
    }
    else
    {
        printf("xxx\n");
    }
    return 0;
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
posted @ 2019-12-10 19:59  一个不知道干嘛的小萌新  阅读(945)  评论(0编辑  收藏  举报