




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、配置GPI0口,這里由于不使用中斷,所以將中斷引一、首先建立這樣一個全局的觀念:An droid 中sen sor在An droid系統(tǒng)架構(gòu)中的位置及其工作。方框 圖如下:從以上方框圖中,可以看出An droid中sen sor在系統(tǒng)分為四層:驅(qū)動層(Sen sorDriver )、硬件抽象層(Native )、中間層(Framework)、應(yīng)用層(Java)。硬件抽象層 與中間層可以合并一起作 為Framework層。針對我們xx這里一個具體的Gsensor,下面將以具體的源 碼形式來講解以上的這個系統(tǒng)框 圖。二、驅(qū)動層 (Sensor Driver Layer )芯片ADXL345 GSe
2、nsor,至于硬件的具體工作原理,須分析ADXL345勺Datasheet。驅(qū)動源碼位于:xxcustomcommonkernelaccelerometeradxl345目錄。由于ADXL345是以I2C形式接口掛接到Linux系統(tǒng),因此同時需要分析Linux的I2C子系統(tǒng) 架構(gòu)(略)。其源碼位于:1、xxplatformxxker neldriversi2c2、kern eldriversi2c查看ADXL345.c文件,分析針對于其硬件工作原理的幾個函數(shù)。硬件初始化:cppview_pla in copy_1. static int adxl345_init_client(struct i
3、2c_client *client, int reset_cali)2.3. 4.4.struct adxl345_i2c_data *obj = i2c_get_clie ntdata(clie nt);6.5.int res = 0;1.adxl345_gpio_co nfig();腳配置成輸入輸出口檢測設(shè)備ID,通過讀ADXL345的設(shè)置電源模式,ADXL345有5.res = ADXL345_CheckDevicelD(clie nt); /DEVID寄存器16.17.if(res != ADXL345_SUCCESS)9.ret
4、urn res;5.26.27. res = ADXL345_SetPowerMode(clie nt, false);/幾種電源模式,這里設(shè)置false值指不讓芯片處于messure模式2.if(res != ADXL345_SUCCESS) return res;res = ADXL345_SetBWRate(clie nt, ADXL345_BW_100HZ);if(res != ADXL345_SUCCESS ) 0 x2
5、C-BW=100Hz return res;設(shè)置帶寬,100Hz53./設(shè)置數(shù)據(jù)格式,具體見datasheet54.55. res = ADXL345_SetDataFormat(clie nt, ADXL345_FULL_RES|ADXL345_RANGE_2G );56.56.if(res != ADXL345_SUCCESS) 0 x2C-BW=100Hz8.return res;5.66.60.gse nsor_ga in.x = gse nsor_ga in.y = gse nsor_ga in.z = obj-reso-se nsitivit
6、y;1./設(shè)置中斷寄存器,關(guān)閉中斷3.94.95.res = ADXL345_SetIntEnable(client, 0 x00);/disable INTif(res != ADXL345_SUCCESS)return res;if(0 != reset_cali)/*reset calibrati on only in power on*/res = ADXL345_ResetCalibratio n(clie nt); if(res !=
7、ADXL345_SUCCESS)02.103.return res;104.105.#ifdef CONFIG_ADXL345_LOWPASS106.106.memset(&obj-fir, 0 x00, sizeof(obj-fir);108.109. #endif13.return ADXL345_SUCCESS;114.114.函數(shù)的分析都注釋在原理里,紅色部分。具體寄存器的設(shè)置查看ADXL345的 datasheet,具體I2C的通信查看I2C.C文件(i2c控制器的驅(qū)動)。關(guān)鍵問題:這里有個問題,沒有弄懂,就是從AD
8、XL345數(shù)據(jù)寄存器里讀取原始數(shù)據(jù)之 后,這個數(shù)據(jù)并不是我們應(yīng)用程序所要用的,它需要 轉(zhuǎn)化,經(jīng)過查看代碼,可以發(fā)現(xiàn)這樣 段注釋:/*sign, map: only used in accelerometer/magnetic field*sometimes, the sen sor output n eed to be remapped before report ing to framework.*the sig n is only -1 or +1 to alig n the sig n for frameworks coord in atesystem*the map alig n th
9、e value for frameworks coord in ate system. Take accelerometer*as an exmaple:*assume HAL receives orig inal accelerati on: acc = 100, 0, 100*sig n = 1, -1, 1, 0;*map = HWM_CODE_ACC_Y, HWM_CODE_ACC_X, HWM_CODE_ACC_Z, 0;*accord ing to the above sig n & map, the sen sor output n eed to remap as y, -x,
10、z:*float resolution = un it_numerator*GRAVITY_EARTH/u nit_de nomi nator;*acc_x = sig n O*accmapO*resoluti on;*acc_y = sig n1*accmap1*resolutio n;*acc_z = sig n 2*accmap2*resoluti on;*/struct hwmse n_convert s8 sig n C_MAX_HWMSEN_EVENT_NUM;u8 mapC_MAX_HWMSEN_EVENT_NUM;這樣一個轉(zhuǎn)換算法的物理意義是怎樣的? ?三、硬件抽象層(Nati
11、ve)硬件抽象層主要是提供硬件層實(shí)現(xiàn)的接口,其代 碼路徑如下:hardwarelibhardwarei ncludehardware sen sors.h其中:struct sensors_module_t 為 sensor 模塊的定義。struct sen sors_module_t struct hw_module_t com mon;int (*get_se nsors_list)(struct sen sors_module_t* module,struct sen sor_t con st* list);Struct sensor_t為某一個sensor的描述性定義。struct s
12、en sor_t 傳感器的名稱*/傳感器的ven dor */const char* n ame;/*const char* ven dor;/*intversi on;/*inthan dle;/*inttype;/*傳感器的版本*/傳感器的句柄*/傳感器的類型*/floatmaxRa nge; /*傳感器的最大范圍*/floatresoluti on;/*傳感器的辨析率*/floatpower;/*傳感器的耗能(估計(jì)值,mA單位)*/void*reserved9;struct sen sors_eve nt_t表示傳感器的數(shù)據(jù)* Union of the various types of
13、sen sor data* that can be retur ned.*/typedef struct sen sors_eve nt_t in t32_t versi on; /* must be sizeof(struct sen sors_eve nt_t) */in t32_t sen sor; /* sen sor ide ntifier */in t32_t type; /* sen sor type */in t32_t reservedO; /* reserved */in t64_t timestamp; /* time is in nano sec ond */union
14、 float data16;/* accelerati on values are in meter per sec ond per sec ond (m/sA2) */ sen sors_vec_t acceleratio n;/* magn etic vector values are in micro-Tesla (uT) */sen sors_vec_t magn etic;sen sors_vec_t orie ntatio n; /* orie ntati on values are in degrees */sen sors_vec_t gyro; /* gyroscope va
15、lues are in rad/s */float temperature; /* temperature is in degrees cen tigrade (Celsius) */float dista nee; /* dista nee in cen timeters */float light; /* light in SI lux units */float pressure; /* pressure in hectopascal (hPa) */;uin t32_treserved14; sen sors_eve nt_t;顯然,在看完這些數(shù)據(jù)結(jié)構(gòu)之后,我們都會有這樣一個疑問:這里
16、只是申明了一些 結(jié)構(gòu)體,而這些結(jié)構(gòu)體在使用時需要定義,而且結(jié)構(gòu)體中還有一些 函數(shù)指針,這些函數(shù)指針?biāo)鶎?yīng)的函數(shù)實(shí)現(xiàn)又在哪里呢?顯然,那必定還要有一個.c源 文件來實(shí)現(xiàn)這樣的一些函數(shù)。經(jīng)過搜索,其文件名 為:sensors_hwmsen.c,路徑為:xxksourcehardwaresensorhwmsen。在 這里,你會看至U get_sensors_list等函數(shù)的 實(shí)現(xiàn)。四、中間層(Framework)這里,我也把它叫做JNI層,這里實(shí)現(xiàn)了 JNI接口。其源碼目錄如下:frameworksbasecorej ni an droid_hardware_Se nsorMa nager.cpp在
17、源碼里,我們可以看到JNI接口的函數(shù)列表:static JNINativeMethod gMethods = n ativeClass In it, ()V,(void*) nativeClassl nit ,se nsors_module_i nit,()I,(void*)se nsors_module_i nit ,se nsors_module_get_ next_se nsor,(La ndroid/hardware/Se nsor;l)l,(void*)se nsors_module_get_ next_se nsor ,-se nsors_create_queue, ()1, (v
18、oid*)se nsors_create_queue ,se nsors_destroy_queue, (l)V,(void*)se nsors_destroy_queue ,se nsors_e nable_se nsor, (ILjava/la ng/Stri ng;ll)Z,(void*)se nsors_e nable_se nsor ,se nsors_data_poll, (lFlJ)l,(void*)se nsors_data_poll ,;這些JNI接口所對應(yīng)的實(shí)現(xiàn),請看源碼。當(dāng)然了,你可能又有疑 問了,上層Java又是怎樣來調(diào)用這些本地接口的呢?在android_hardware_SensorManager.cpp 源碼下面有這樣一個函數(shù):萬里雪飄。int register_a ndroid_hardware_Se nsorMa nagerJNIE nv *env)return jn iRegisterNativeMethods(e nv, a ndroid/hardware/Se nsorMa nager, gMethods, NELEM(gMethods)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 渠道開發(fā)合同
- 瓷磚采購合同藥店裝修
- 互聯(lián)網(wǎng)廣告效果監(jiān)測與分析服務(wù)合同
- 2025-2030年中國非晶材料行業(yè)十三五規(guī)劃與發(fā)展風(fēng)險評估報告
- 2025-2030年中國防凍劑行業(yè)運(yùn)行現(xiàn)狀及發(fā)展趨勢預(yù)測報告
- 2025-2030年中國錫礦采選市場競爭格局及運(yùn)營趨勢分析報告
- 2025-2030年中國表演服市場運(yùn)行動態(tài)及前景趨勢分析報告
- 液化氣站送氣工合同
- 2025-2030年中國自助回單打印終端市場發(fā)展?fàn)顩r及營銷戰(zhàn)略研究報告
- 2025-2030年中國聚苯硫醚市場十三五規(guī)劃及投資風(fēng)險評估報告
- 企業(yè)承包經(jīng)營合同范本
- 2025年01月公安部第三研究所公開招聘人民警察筆試筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 教師讀書分享《給教師的建議》課件
- 人民警察紀(jì)律條令試卷含答案
- 婚姻矛盾糾紛調(diào)解培訓(xùn)課件
- 《工程熱力學(xué)》(第四版)配套教學(xué)課件
- 國內(nèi)外旅游公共服務(wù)研究的文獻(xiàn)綜述
- 2022年北京市專升本英語真題
- 鍺的提取方法
- 有害物質(zhì)管控清單(歐盟)
- 乙酸乙酯的制備ppt課件
評論
0/150
提交評論