2020/7/31

Bookmarks : reading input device

5. Event interface
~~~~~~~~~~~~~~~~~~
  Should you want to add event device support into any application (X, gpm,
svgalib ...) I >vojtech@ucw.cz< will be happy to provide you any help I
can. Here goes a description of the current state of things, which is going
to be extended, but not changed incompatibly as time goes:

  You can use blocking and nonblocking reads, also select() on the
/dev/input/eventX devices, and you'll always get a whole number of input
events on a read. Their layout is:

struct input_event {
	struct timeval time;
	unsigned short type;
	unsigned short code;
	unsigned int value;
};

  'time' is the timestamp, it returns the time at which the event happened.
Type is for example EV_REL for relative moment, EV_KEY for a keypress or
release. More types are defined in include/uapi/linux/input-event-codes.h.

  'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete
list is in include/uapi/linux/input-event-codes.h.

  'value' is the value the event carries. Either a relative change for
EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for
release, 1 for keypress and 2 for autorepeat.
所以對/dev/input/eventX 讀取,會得到的資料內容是 input_event structure


上面ref link 的 example (keymonitor.c) :

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <string.h>


static const char * const evval[]={
	"RELEASED",
	"PRESSED",
	"REPEATED"
};

int main(void)
{
	const char *dev="/dev/input/by-path/platform-i8042-serio-0-event-kbd";
	struct input_event ev;
	ssize_t n;
	int fd;

	fd = open(dev, O_RDONLY);
	if (fd==-1) {
		fprintf(stderr,"Cannot open %s: %s\n",dev,strerror(errno));
		return EXIT_FAILURE;
	}

	while(1) {
		n = read(fd, &ev, sizeof(ev));
		if (n == (ssize_t)-1) {
			if (errno==EINTR)
				continue;
			else
				break;
		}else
		if (n != sizeof(ev)) {
			errno = EIO;
			break;
		}

		if(ev.type == EV_KEY && ev.value >= 0 && ev.value <= 2)
			printf("%s 0x%04x (%d)\n",evval[ev.value],(int)ev.code,(int)ev.code);

	}
	fflush(stdout);
	fprintf(stderr,"%s.\n",strerror(errno));
	return EXIT_FAILURE;
}

要注意 /dev/input/by-path/platform-i8042-serio-0-event-kbd 的權限。
link 到 event3,event 的權限 是 input group。
所以要把user 加入 input group

實際執行:

:~/test/input$ ./keymonitor 
RELEASED 0x001c (28)
PRESSED 0x0002 (2)
1RELEASED 0x0002 (2)
PRESSED 0x0003 (3)
2RELEASED 0x0003 (3)
PRESSED 0x0004 (4)
3RELEASED 0x0004 (4)
PRESSED 0x0005 (5)
4RELEASED 0x0005 (5)
PRESSED 0x0006 (6)
5RELEASED 0x0006 (6)
PRESSED 0x001e (30)
aRELEASED 0x001e (30)
PRESSED 0x0030 (48)
bRELEASED 0x0030 (48)
PRESSED 0x002e (46)
cRELEASED 0x002e (46)
PRESSED 0x001d (29)
REPEATED 0x001d (29)
REPEATED 0x001d (29)
REPEATED 0x001d (29)
REPEATED 0x001d (29)
REPEATED 0x001d (29)
REPEATED 0x001d (29)
REPEATED 0x001d (29)
PRESSED 0x002e (46)
^C

即使不在console 不在 focus,也會擷取到keyboard input.
... 有點像 keylogger...

bookmarks : tty 做 serial 傳輸,特殊字元問題

古老的問題,又再次遇到。
使用 serial port , tty device 做傳輸的時候,測試時,想用 echo. cat 做基本傳送測試。
常常會遇到 自動送出 0x0d, 或是送出0x0d 時,被加入一個 0x0d 的現象。
這是因為 linux tty 是 terminal 裝置,所以遇到特殊的控制字元時,會自動做特殊轉換。 轉換。

就用 stty 來設定,叫他不要自動轉換舊可以..

看看現在tty 的設定狀況:
# stty -F /dev/ttyS1
speed 9600 baud; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-brkint -imaxbel
變更,不要處理 nl, cr 的轉換
# stty -F /dev/ttyS1 -onlcr

ref:


這一篇 說,直接指定 raw mode 舊可以:
# stty -F /dev/ttyS1 raw

另外,echo command 也會自動加上 0x0d,不要他送的話,要加上 -n option:
# echo -n abc

附帶,要送非 ascii,也就是用 hex code 來寫,要用 -e
# echo -en '\x12\x34'

2020/7/27

刪最後一行 - sed

sed -i '$d' <file>
因為 rndis 的 server key 每 update 一次就變一次,這個commmand 其實是用來刪 .ssn/known_key

  • -i : inplace, 直接修改那個file
  • $ : 最後一行
  • d : 刪除


另外,這一篇 說...
通常用(/)做分隔符號,但也可以使用(|),(@),(^),(!)作為分隔符號。

2020/7/23

dump Audio Codec I2C Registers

一般Audio Codec 都是使用I2C控制。
要 dump I2C register 的話...

文件說,driver 有用 regmap, 使用devm_regmap_init_i2c( ) 註冊 i2 driver 的話,
在,舉例來說,codec 在 i2c2,address 0x12:
/sys/kernel/debug/regmap/2-0012/
之下的register, cat 出來...

但是用 amixer cset 修改 register,cat 出來的 register value 都沒變...
所以可能是 driver 沒寫好。


另外就是用 i2cdump
因為 I2C Audio Codec Driver 一定有註冊,所以用
i2cdump: can't set address to 0x12: Device or resource bus

要加上 -f force
# i2cdump  -f -y 2 0x12
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 00 06 00 60 50 5b 23 00 00 60 00 e1 91 00 00    ..?.`P[#..`.??..
10: 03 00 00 00 00 00 01 00 03 b0 1f 9f 20 b6 0b 6d    ?.....?.???? ??m
20: 37 00 28 00 5e 3f 9f e0 0b 02 58 3e a2 e1 60 08    7.(.^?????X>??`?
30: 12 38 72 e7 c8 17 1f 25 23 f5 43 1f 00 00 ca fb    ?8r????%#?C?..??
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
這種方法,配合 amixer cset 修改register,發現會做對應的變更。
所以應該有效。

rndis ubuntu & config by hand

board 用 g_ether/ndis 接到 ubuntu.
採用 static ip

接上後, ubuntu 週期出現 網路中斷,重新連線的訊息。
dmesg 看 kernel message 正常。

所以在 UI 右上,network manager 上,把那個 rndis interface 刪掉。
改用ifconfig 設定。
這樣舊 OK 了。

麻煩的是,每次 board 重新開機, g_ether 的 MAC 就會換,所以 ubuntu 上 network manager 就會出現新的 network interface。
都要再刪除一次。


用 command console 操作..
刪除network manager 上顯示的network connection
nmcli connection delete "Wired connectin 1"

然後手動..
ifconfig enp0s20u3u4c2 10.0.1.1 netmask 255.255.255.0
interface name 用 ip addr 或是 dmesg 可以看到。

Wired connection 1 是在右上角的 network manager icon 顯示的。

conda install tensorflow -- (& keras)

這是時代的進步?
只是 create 一個 env, 就全自動安裝了 ? (snpe 要 python 3.6)
(base) charles-chang@beaver:~$ conda create -name tensorflow python=3.6
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/charles-chang/miniconda3/envs/ame

  added / updated specs:
    - tensorflow


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _tflow_select-2.3.0        |              mkl           2 KB
    absl-py-0.9.0              |           py38_0         165 KB
    astunparse-1.6.3           |             py_0          17 KB
    blinker-1.4                |           py38_0          22 KB
    brotlipy-0.7.0             |py38h7b6447c_1000         322 KB
    c-ares-1.15.0              |    h7b6447c_1001          89 KB
    ca-certificates-2020.6.24  |                0         125 KB
    cachetools-4.1.0           |             py_1          15 KB
    certifi-2020.6.20          |           py38_0         156 KB
    cffi-1.14.0                |   py38he30daa8_1         225 KB
    chardet-3.0.4              |        py38_1003         174 KB
    click-7.1.2                |             py_0          71 KB
    cryptography-2.9.2         |   py38h1ba5d50_0         556 KB
    gast-0.3.3                 |             py_0          14 KB
    google-auth-1.17.2         |             py_0          55 KB
    google-auth-oauthlib-0.4.1 |             py_2          20 KB
    google-pasta-0.2.0         |             py_0          46 KB
    grpcio-1.27.2              |   py38hf8bcb03_0         1.3 MB
    h5py-2.10.0                |   py38hd6299e0_1         948 KB
    hdf5-1.10.6                |       hb1b8bf9_0         3.7 MB
    idna-2.10                  |             py_0          50 KB
    keras-preprocessing-1.1.0  |             py_1          37 KB
    libedit-3.1.20191231       |       h14c3975_1         116 KB
    libffi-3.3                 |       he6710b0_2          50 KB
    libprotobuf-3.12.3         |       hd408876_0         2.9 MB
    markdown-3.1.1             |           py38_0         116 KB
    mkl_fft-1.1.0              |   py38h23d657b_0         150 KB
    numpy-1.18.5               |   py38ha1c710e_0           5 KB
    numpy-base-1.18.5          |   py38hde5b4d6_0         4.1 MB
    oauthlib-3.1.0             |             py_0          91 KB
    opt_einsum-3.1.0           |             py_0          54 KB
    pip-20.1.1                 |           py38_1         1.7 MB
    protobuf-3.12.3            |   py38he6710b0_0         648 KB
    pyasn1-0.4.8               |             py_0          57 KB
    pyasn1-modules-0.2.7       |             py_0          68 KB
    pycparser-2.20             |             py_2          94 KB
    pyjwt-1.7.1                |           py38_0          33 KB
    pyopenssl-19.1.0           |             py_1          48 KB
    pysocks-1.7.1              |           py38_0          28 KB
    python-3.8.3               |       hcff3b4d_2        49.1 MB
    requests-2.24.0            |             py_0          56 KB
    requests-oauthlib-1.3.0    |             py_0          23 KB
    rsa-4.0                    |             py_0          29 KB
    scipy-1.5.0                |   py38h0b6359f_0        14.5 MB
    setuptools-49.2.0          |           py38_0         737 KB
    sqlite-3.32.3              |       h62c20be_0         1.1 MB
    tensorboard-2.2.1          |     pyh532a8cf_0         2.4 MB
    tensorboard-plugin-wit-1.6.0|             py_0         630 KB
    tensorflow-2.2.0           |mkl_py38h6d3daf0_0           4 KB
    tensorflow-base-2.2.0      |mkl_py38h5059a2d_0       127.2 MB
    tensorflow-estimator-2.2.0 |     pyh208ff02_0         254 KB
    termcolor-1.1.0            |           py38_1           8 KB
    tk-8.6.10                  |       hbc83047_0         3.0 MB
    urllib3-1.25.9             |             py_0         103 KB
    werkzeug-1.0.1             |             py_0         240 KB
    wrapt-1.12.1               |   py38h7b6447c_1          50 KB
    ------------------------------------------------------------
                                           Total:       217.8 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  _tflow_select      pkgs/main/linux-64::_tflow_select-2.3.0-mkl
  absl-py            pkgs/main/linux-64::absl-py-0.9.0-py38_0
  astunparse         pkgs/main/noarch::astunparse-1.6.3-py_0
  blas               pkgs/main/linux-64::blas-1.0-mkl
  blinker            pkgs/main/linux-64::blinker-1.4-py38_0
  brotlipy           pkgs/main/linux-64::brotlipy-0.7.0-py38h7b6447c_1000
  c-ares             pkgs/main/linux-64::c-ares-1.15.0-h7b6447c_1001
  ca-certificates    pkgs/main/linux-64::ca-certificates-2020.6.24-0
  cachetools         pkgs/main/noarch::cachetools-4.1.0-py_1
  certifi            pkgs/main/linux-64::certifi-2020.6.20-py38_0
  cffi               pkgs/main/linux-64::cffi-1.14.0-py38he30daa8_1
  chardet            pkgs/main/linux-64::chardet-3.0.4-py38_1003
  click              pkgs/main/noarch::click-7.1.2-py_0
  cryptography       pkgs/main/linux-64::cryptography-2.9.2-py38h1ba5d50_0
  gast               pkgs/main/noarch::gast-0.3.3-py_0
  google-auth        pkgs/main/noarch::google-auth-1.17.2-py_0
  google-auth-oauth~ pkgs/main/noarch::google-auth-oauthlib-0.4.1-py_2
  google-pasta       pkgs/main/noarch::google-pasta-0.2.0-py_0
  grpcio             pkgs/main/linux-64::grpcio-1.27.2-py38hf8bcb03_0
  h5py               pkgs/main/linux-64::h5py-2.10.0-py38hd6299e0_1
  hdf5               pkgs/main/linux-64::hdf5-1.10.6-hb1b8bf9_0
  idna               pkgs/main/noarch::idna-2.10-py_0
  intel-openmp       pkgs/main/linux-64::intel-openmp-2020.1-217
  keras-preprocessi~ pkgs/main/noarch::keras-preprocessing-1.1.0-py_1
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.33.1-h53a641e_7
  libedit            pkgs/main/linux-64::libedit-3.1.20191231-h14c3975_1
  libffi             pkgs/main/linux-64::libffi-3.3-he6710b0_2
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.1.0-hdf63c60_0
  libgfortran-ng     pkgs/main/linux-64::libgfortran-ng-7.3.0-hdf63c60_0
  libprotobuf        pkgs/main/linux-64::libprotobuf-3.12.3-hd408876_0
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.1.0-hdf63c60_0
  markdown           pkgs/main/linux-64::markdown-3.1.1-py38_0
  mkl                pkgs/main/linux-64::mkl-2020.1-217
  mkl-service        pkgs/main/linux-64::mkl-service-2.3.0-py38he904b0f_0
  mkl_fft            pkgs/main/linux-64::mkl_fft-1.1.0-py38h23d657b_0
  mkl_random         pkgs/main/linux-64::mkl_random-1.1.1-py38h0573a6f_0
  ncurses            pkgs/main/linux-64::ncurses-6.2-he6710b0_1
  numpy              pkgs/main/linux-64::numpy-1.18.5-py38ha1c710e_0
  numpy-base         pkgs/main/linux-64::numpy-base-1.18.5-py38hde5b4d6_0
  oauthlib           pkgs/main/noarch::oauthlib-3.1.0-py_0
  openssl            pkgs/main/linux-64::openssl-1.1.1g-h7b6447c_0
  opt_einsum         pkgs/main/noarch::opt_einsum-3.1.0-py_0
  pip                pkgs/main/linux-64::pip-20.1.1-py38_1
  protobuf           pkgs/main/linux-64::protobuf-3.12.3-py38he6710b0_0
  pyasn1             pkgs/main/noarch::pyasn1-0.4.8-py_0
  pyasn1-modules     pkgs/main/noarch::pyasn1-modules-0.2.7-py_0
  pycparser          pkgs/main/noarch::pycparser-2.20-py_2
  pyjwt              pkgs/main/linux-64::pyjwt-1.7.1-py38_0
  pyopenssl          pkgs/main/noarch::pyopenssl-19.1.0-py_1
  pysocks            pkgs/main/linux-64::pysocks-1.7.1-py38_0
  python             pkgs/main/linux-64::python-3.8.3-hcff3b4d_2
  readline           pkgs/main/linux-64::readline-8.0-h7b6447c_0
  requests           pkgs/main/noarch::requests-2.24.0-py_0
  requests-oauthlib  pkgs/main/noarch::requests-oauthlib-1.3.0-py_0
  rsa                pkgs/main/noarch::rsa-4.0-py_0
  scipy              pkgs/main/linux-64::scipy-1.5.0-py38h0b6359f_0
  setuptools         pkgs/main/linux-64::setuptools-49.2.0-py38_0
  six                pkgs/main/noarch::six-1.15.0-py_0
  sqlite             pkgs/main/linux-64::sqlite-3.32.3-h62c20be_0
  tensorboard        pkgs/main/noarch::tensorboard-2.2.1-pyh532a8cf_0
  tensorboard-plugi~ pkgs/main/noarch::tensorboard-plugin-wit-1.6.0-py_0
  tensorflow         pkgs/main/linux-64::tensorflow-2.2.0-mkl_py38h6d3daf0_0
  tensorflow-base    pkgs/main/linux-64::tensorflow-base-2.2.0-mkl_py38h5059a2d_0
  tensorflow-estima~ pkgs/main/noarch::tensorflow-estimator-2.2.0-pyh208ff02_0
  termcolor          pkgs/main/linux-64::termcolor-1.1.0-py38_1
  tk                 pkgs/main/linux-64::tk-8.6.10-hbc83047_0
  urllib3            pkgs/main/noarch::urllib3-1.25.9-py_0
  werkzeug           pkgs/main/noarch::werkzeug-1.0.1-py_0
  wheel              pkgs/main/linux-64::wheel-0.34.2-py38_0
  wrapt              pkgs/main/linux-64::wrapt-1.12.1-py38h7b6447c_1
  xz                 pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3


Proceed ([y]/n)? 


Downloading and Extracting Packages
grpcio-1.27.2        | 1.3 MB    | ############################################################################## | 100% 
numpy-base-1.18.5    | 4.1 MB    | ############################################################################## | 100% 
tensorboard-plugin-w | 630 KB    | ############################################################################## | 100% 
requests-oauthlib-1. | 23 KB     | ############################################################################## | 100% 
cryptography-2.9.2   | 556 KB    | ############################################################################## | 100% 
_tflow_select-2.3.0  | 2 KB      | ############################################################################## | 100% 
brotlipy-0.7.0       | 322 KB    | ############################################################################## | 100% 
numpy-1.18.5         | 5 KB      | ############################################################################## | 100% 
pyjwt-1.7.1          | 33 KB     | ############################################################################## | 100% 
ca-certificates-2020 | 125 KB    | ############################################################################## | 100% 
absl-py-0.9.0        | 165 KB    | ############################################################################## | 100% 
python-3.8.3         | 49.1 MB   | ############################################################################## | 100% 
blinker-1.4          | 22 KB     | ############################################################################## | 100% 
h5py-2.10.0          | 948 KB    | ############################################################################## | 100% 
pyasn1-0.4.8         | 57 KB     | ############################################################################## | 100% 
c-ares-1.15.0        | 89 KB     | ############################################################################## | 100% 
mkl_fft-1.1.0        | 150 KB    | ############################################################################## | 100% 
tensorflow-2.2.0     | 4 KB      | ############################################################################## | 100% 
werkzeug-1.0.1       | 240 KB    | ############################################################################## | 100% 
pysocks-1.7.1        | 28 KB     | ############################################################################## | 100% 
urllib3-1.25.9       | 103 KB    | ############################################################################## | 100% 
setuptools-49.2.0    | 737 KB    | ############################################################################## | 100% 
cffi-1.14.0          | 225 KB    | ############################################################################## | 100% 
pyopenssl-19.1.0     | 48 KB     | ############################################################################## | 100% 
requests-2.24.0      | 56 KB     | ############################################################################## | 100% 
opt_einsum-3.1.0     | 54 KB     | ############################################################################## | 100% 
keras-preprocessing- | 37 KB     | ############################################################################## | 100% 
google-auth-1.17.2   | 55 KB     | ############################################################################## | 100% 
certifi-2020.6.20    | 156 KB    | ############################################################################## | 100% 
rsa-4.0              | 29 KB     | ############################################################################## | 100% 
idna-2.10            | 50 KB     | ############################################################################## | 100% 
chardet-3.0.4        | 174 KB    | ############################################################################## | 100% 
libedit-3.1.20191231 | 116 KB    | ############################################################################## | 100% 
libprotobuf-3.12.3   | 2.9 MB    | ############################################################################## | 100% 
tk-8.6.10            | 3.0 MB    | ############################################################################## | 100% 
click-7.1.2          | 71 KB     | ############################################################################## | 100% 
wrapt-1.12.1         | 50 KB     | ############################################################################## | 100% 
markdown-3.1.1       | 116 KB    | ############################################################################## | 100% 
oauthlib-3.1.0       | 91 KB     | ############################################################################## | 100% 
tensorboard-2.2.1    | 2.4 MB    | ############################################################################## | 100% 
sqlite-3.32.3        | 1.1 MB    | ############################################################################## | 100% 
tensorflow-base-2.2. | 127.2 MB  | ############################################################################## | 100% 
google-auth-oauthlib | 20 KB     | ############################################################################## | 100% 
libffi-3.3           | 50 KB     | ############################################################################## | 100% 
google-pasta-0.2.0   | 46 KB     | ############################################################################## | 100% 
termcolor-1.1.0      | 8 KB      | ############################################################################## | 100% 
pycparser-2.20       | 94 KB     | ############################################################################## | 100% 
protobuf-3.12.3      | 648 KB    | ############################################################################## | 100% 
astunparse-1.6.3     | 17 KB     | ############################################################################## | 100% 
pyasn1-modules-0.2.7 | 68 KB     | ############################################################################## | 100% 
scipy-1.5.0          | 14.5 MB   | ############################################################################## | 100% 
pip-20.1.1           | 1.7 MB    | ############################################################################## | 100% 
hdf5-1.10.6          | 3.7 MB    | ############################################################################## | 100% 
gast-0.3.3           | 14 KB     | ############################################################################## | 100% 
tensorflow-estimator | 254 KB    | ############################################################################## | 100% 
cachetools-4.1.0     | 15 KB     | ############################################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate ame
#
# To deactivate an active environment, use
#
#     $ conda deactivate
還不清楚問什麼... 先在這裡紀錄一下...
在三台機器上試過,跟 conda 版本無關,有些會這樣,有些不會。
還有,安裝的是 INTEL Floating Library 的版本 (MKL),不是 GPU 版本的 tensorflow.
要改用 gpu 版本,只要..
conda install tensorflow-gpu
舊可以。
-- 官網寫的是錯的,他說只有 tensorflow 1.X 要分 CPU/GPU, 2.X 是不用的。
結果 2.X 也一樣,沒有加 "-gpu" 話,裝的是 CPU板。

另外,測試 tensorflow 是否 gpu 版,根據 這一篇
>l>>import tensorflow as tf
>>>tf.config.experimental.list_physical_devices('GPU')
2020-07-23 09:19:31.565159: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-07-23 09:19:31.659710: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), 
but there must be at least one NUMA node, so returning NUMA node zero
2020-07-23 09:19:31.660556: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GT 740M computeCapability: 3.5
coreClock: 1.0325GHz coreCount: 2 deviceMemorySize: 1.96GiB deviceMemoryBandwidth: 13.41GiB/s
2020-07-23 09:19:31.683972: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-07-23 09:19:31.992823: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-07-23 09:19:32.124542: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-07-23 09:19:32.178241: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-07-23 09:19:32.432432: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-07-23 09:19:32.481091: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-07-23 09:19:32.959076: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-07-23 09:19:32.959311: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), 
but there must be at least one NUMA node, so returning NUMA node zero
2020-07-23 09:19:32.959740: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), 
but there must be at least one NUMA node, so returning NUMA node zero
2020-07-23 09:19:32.960028: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]


2021/4/21 update:

依照Tensorflow、Keras傻瓜式安裝教學 的說明,如果是 tensorflow 2.0 以上。
keras 是內建的。
因為 tensorflow 已經把 keras 內建了。
可以用:
>> import tensorflow.keras as keras
>> keras.__version__
'2.3.0-tf' 

要檢查 tensorflow 有沒有找到gpu,也可以參考這一篇 官方 api:
import tensorflow as tf
tf.test.is_gpu_available()
就會看到一堆 load cuda library 的 output message,最後回答 true



如果不是 gpu 版本,tensorflow 會安裝 2.6,導致 keras 版本不相容。
所以最好是指定版本:
conda create -name tensorflow tensorflow=2.4.1

2020/7/21

trace_i2c_read 在哪裡

在 i2c-core-base.c 中出現的 trace_i2c_read() trace_i2c_write(),grep 的結果只有出現過一次,所以是在哪裡宣告/實做的?
因為有 trace_ 所以往上找 include..

include/trace/events/i2c.h:
TRACE_EVENT_FN(i2c_write,
               TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg,
                        int num),
               TP_ARGS(adap, msg, num),
               TP_STRUCT__entry(
                       __field(int,     adapter_nr              )
        ...
這個很像,宣告出原型,而且有被 include.

所以找 TRACE_EVENT_FN:
最後, include/linux/tracepoint.h:
#define TRACE_EVENT_FN(name, proto, args, struct,               \
                assign, print, reg, unreg)                      \
        DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
      

....

#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
        extern struct tracepoint __tracepoint_##name;                   \
        static inline void trace_##name(proto)                          \
        {                                                               \
                if (static_key_false(&__tracepoint_##name.key))         \
找到...

2020/7/18

Linux(beta) for Chromebook

A new featture in Chromebook ..

enable this option,, then, it starts installing...

then.. a new app appears..

It's a linux console..

The apt command works!


注音盲打還是有點....

結果 是 run 在 container 裏..

2020/7/17

Connect Mono Codec AK4737 to Stereo I2S CPU

AK4637 是單 channel (MONO) 的 code,可是很多cpu 的 i2s 最小 channel 卻是 2
所以會不會不能接?

data sheet 中的 Audio Interface Format中有幾種 mode 可以選,
其中有一個...

FCK 就是 WCLK (word)
可以看到,一個 word (FCK High) 是被使用的,接著的 word (FCK Low) 是 Dont' Care
這剛好是 2 channel 資料中選 1 channel 的意思。

所以猜.. 在這個 mode 下,對接的 cpu i2s 可以使用 2 channel (stereo) 輸出。
-- 當然,只有一側會輸出。

這個 mode 是..

就是 default mode
Mode. 2 : DIF1 = 1, DIF0 = 0

是 reg 07 (Mode Control 3):



看錯了,I2S format 永遠ignore 掉另一個 word (channel),跟 Mode 無關。
實際上應該要用 Mode 3 : I2S Compatible Mode 才對。

ethernet mac address . in dts

drivers/net/ethernet ...
macaddr = of_get_mac_address(..)

drivers/of/of_net.c:
const void *of_get_mac_address(struct device_node *np)
{
    const void *addr;

    addr = of_get_mac_addr(np, "mac-address");
    if (addr)
        return addr;

    addr = of_get_mac_addr(np, "local-mac-address");
    if (addr)
        return addr;

    return of_get_mac_addr(np, "address");
}
grep 一下所有的 dts, mac-addr,結果都是 local-mac-address,少數有 mac-address.
但是形式都一樣..
       mac-address = [ 02 A1 A2 A3 A4 A5 ];

2020/7/10

Screenshot Editor , for linux

因為整個沒用 Windows 了,所以以前 screenshot. edit 用 Paint.NET 都不能用了。
用 Gimp 的話,動做太多,
大家都用 kolourpaint

這一篇:Linux 上也有小畫家 就有很好的說明。

簡單來說,一般 screenshot 後的動作:
  • screenshot
  • select region
  • copy selection, paste to new file
  • save new file
這幾個基本的動作順序都跟 Paint.NET 時一樣。

果然,Project Home Page 的說明就是..
KolourPaint 是一個簡易的繪圖軟體,相較於多功能的 GIMP,KolourPaint 功能較為簡單,拿來處理簡單的螢幕截圖或是創作構圖還滿方便快速

Bookmarks: Raspberry PI SPI只有 master 沒有 slave mode

雖然 cpu 的 datasheet 寫 SPI 支援 master/slave mode,但是 目前沒有 driver 支援 slave mode。
所以 唯一的作法就是用 CPU 模擬。 (bit-bang),目前的實做,最高到 1kb/s


說是這樣說,實際找了一下,沒有人實做 slave mode...

2020/7/8

reading notes on AK4637 datasheet

只是動手一下,免得念的時候睡著..

24bit Mono Codec. with MIC and Speaker AMP.
-- 所以 MIC 也有 AMP ?

真的! 有 MIC AMP with Auto Level Control (避免爆音)
ALC 是 MIC 跟 Speaker 都有。

錄音的部份...
  • Wind Noise Reduction Filter
  • Analog and Digital Input

播放的部份... 好像沒蛇麼特殊的。

Master CLK
  • PLL Mode : MCKI 輸入,跟 BICK 輸入
  • 外部 : MCKI 輸入
所以 MCKI 輸入算內部PLL 還是外部?

Sampling Frequency .. Supoort 的 Sampling Rate 竟然跟 CLK Mode 有關係。

I2C Bus : Ver 1.0, 400kHz Fast-Mode

block diagram :


Routing 還算簡單.. Speaker OUT 的 input(DAC input) 就有:經過EQ 跟 Direct 兩種。
EQ 只有一組,所以 MIC 跟 I2S input 共用。

果然,針對中間這部份...

其中的三個 Switch/Selector,可以把 input 區分為幾種 Mode..
ADCPF, PFSDO 的 0.1 選擇,在上圖可以看到。
PFDAC1-0 的話,
  • 00 : 選擇 EQ path
  • 01 : 選擇 I2S 直接輸出
系統default 是...
ADCPF: 1.
PFDAC10 :00
PFSDO : 1

也就是.. MIC 輸入經果 EQ,I2S 直接輸出不經過 EQ

2020/7/7

busybox mount nfs client

busybox 的 mount feature 有一項 "CONFIG_FEATURE_MOUNT_NFS"
但是在 menuconfig 的時候,這一項的說明是..
"Support mounting NFS file systems on Linux < 2.6.23"
help 寫的是..
Enable mounting of NFS file systems on Linux kernels prior
to version 2.6.23. Note that in this case mounting of NFS
over IPv6 will not be possible.

Note that this option links in RPC support from libc,
which is rather large (~10 kbytes on uclibc).
所以是 kernel version < 2.6.23 才需要。

測試結果...
4.14 版本的 kernel 的 NFS 功能都 enable 之後,busybox 的這個 feature_mount_nfs 沒開,
用 busybox 的 mount 舊可以正常 mount nfs 了。

mount 時有點小問題..
# mount -t nfs  172.16.200.1:/home/charles-chang nn
[  771.469492] svc: failed to register lockdv1 RPC service (errno 111).
[  771.475845] lockd_up: makesock failed, error=-111
參考這一篇,mount 時加上 -o nolock ,或是client 端也啟動 portmap 服務,都可以解決問題。
我就用簡單的 -o unlock,測試 OK

另外,雖然 nfs server 是 NFSv4,但是 kernel 的 nfs fearture 只有 enable 到 v3,mount service 就是 v3,
同一個 share folder ,另一個kernel 有 v4 的 evb mount 起來,就是 v4

2020/7/6

bookmark : shell script 中的各種括號..

為避免這摸好的說明不見,所以轉貼一下.. (其實就是 copy 人家的內容...)

雙 (( 用在運算上..
((var++))
((var = 3))
for ((i = 0; i < VAL; i++))
echo $((var + 2))
用說括號 (( 刮起來的變數,不必加 $

方括號 [ 用在判斷
$ VAR=2
$ if [ $VAR -eq 2 ]
> then
> echo 'yes'
> fi
yes

接著的這個說明我不了解...
兩格個方括號用在 ? extended function ? 在regular expression 的 =~ 上使用.
$ VAR='some string'
$ if [[ $VAR =~ [a-z] ]]; then
> echo 'is alphabetic'
> fi
is alphabetic

大括號 { 用在區分變數名稱
$ foo='stage'
$ echo $fooone
           ... returns empty line
$ echo ${foo}one
stageone
大括號同時還有處理變數內容的功能..
$ var="abcdefg"; echo ${var%d*}
abc

2020/7/1

gitlab . add ssh key

原來使用 https 已經很 OK,但是單一太大的 repo,出現了 Error。
網路上說,是因為超過http 的 max block size。
改用 ssh 就 OK

所以..

其實就是把你機器上的 .ssh/id_rsa.public 的內容,貼到 gitlab 的 settings -- sshkey 裡舊可以了。
跟你的 username. login name, email 都沒關係。

然後,舊可以用 git@gitlab.com:checko 來 access gitlab repo (不用 https://gitlab.com/checko)

xclip 從 command line 操作剪貼簿

要加 ssh key 進入 gitlab 時,從他的說明文件 看到的。
install xclip 之後,舊可以在 command line 操作剪貼簿了。
以 gitlab 的這個範例來說,他是要把 id_rsa.public 的內容放到剪貼簿中..
xclip -sel clip < ~/.ssh/id_ed25519.pub
做完這個動作後,在 gitlab page 舊可以用ctrl-v 貼上..

這... 有一個缺點,xclip 依靠 X,所以ssh 到 remote 的時候,沒有 DISPLAY,會不能用。