1 // Author: Xianjun Jiao ([email protected]; [email protected]) 2 // SPDX-FileCopyrightText: 2023 UGent 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 5 // Use this example together with fast_reg_log_analyzer.m (notter release) 6 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <string.h> 10 #include <unistd.h> 11 #include <fcntl.h> 12 #include <sys/mman.h> 13 #include <stdint.h> 14 15 int main() 16 { 17 unsigned int bram_size = 0x10000; // 64KB, aligned with openwifi hw .bd and devicetree 18 off_t bram_pbase = 0x83c40000; // physical base address, aligned with openwifi hw .bd and devicetree (this example: xpu @ 32bit boards) 19 uint32_t *bram32_vptr; 20 int fd, i, j; 21 uint32_t tsf_reg[524288*2]; 22 FILE *fp; 23 // Map the BRAM physical address into user space getting a virtual address for it 24 if ((fd = open("/dev/mem", O_RDONLY | O_SYNC)) != -1) { 25 bram32_vptr = (uint32_t *)mmap(NULL, bram_size, PROT_READ, MAP_SHARED, fd, bram_pbase); 26 27 fp = fopen ("fast_reg_log.bin", "wb"); 28 if (fp == NULL) { 29 printf("fopen fast_reg_log.bin failed! %d\n", (int)fp); 30 close(fd); 31 return(0); 32 } 33 34 for (j=0; j<10; j++) { 35 for (i=0; i<(524288*2); i=i+2) { 36 tsf_reg[i+0] = (*(bram32_vptr+57)); // read xpu register 57: rssi trx agc cca status 37 tsf_reg[i+1] = (*(bram32_vptr+58)); // read xpu register 58: low 32bit of tsf 38 } 39 40 // for (i=0; i<1024; i++) { 41 // printf("%d %x\n", tsf[i], reg[i]); 42 // } 43 // memcpy(buf, bram64_vptr, bram_size); 44 45 fwrite(tsf_reg, sizeof(uint32_t), 524288*2, fp); 46 } 47 48 fclose(fp); 49 // printf("%016llx\n", buf[65532]); 50 // printf("%016llx\n", buf[65533]); 51 // printf("%016llx\n", buf[65534]); 52 // printf("%016llx\n", buf[65535]); 53 // //for(i=0; i<32; i++) { 54 // // printf("0x%02x\n", buf[i]); 55 // //} 56 57 close(fd); 58 } 59 return(0); 60 } 61