2022年8月29日 星期一

[Raspberry Pi ] 查詢 Software and Hardware Version of a Raspberry Pi

 

How to Check the Software and Hardware Version of a Raspberry Pi

 Type the following commands , you will get all information about Raspberry Pi
  • cat /etc/os-release
  • uname -a
  • cat /proc/cpuinfo | grep Model



 2019 年發布的Raspberry Pi 4  ,被發現有 USB-C 的充電問題,而小改款  v1.2 解決了此問題! 

2022年8月12日 星期五

[Linux 程式設計] 關於GCC

 

1. 後面的-lxxxx 如果是linux他的位置在哪裡? 

(base) ubuntu@ubuntu1804:/usr/lib$ cat  /etc/ld.so.conf.d/x86_64-linux-gnu.conf


# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
(base) ubuntu@ubuntu1804:/usr/lib$ pwd
/usr/lib

2. 標準函式庫為何不用帶-lxxx

 因為gcc 預設會連結標準函式庫 libc.so.xx

3. 如果使用opensource 專案時要使用 -lxxxx 這部分該怎使用如果他的lib名稱 不是lib<project>
 
  如果不是標準名稱就得用library全名. 主要還是要指定 -L<lib目錄>  , 指名library的位置, 如果不是放在library 的搜尋路徑上的話



(base) ubuntu@ubuntu1804:~$ gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)


----------
相關課程: 
https://www.ittraining.com.tw/ittraining/it-elearning/el-linux-embedded/e-linuxsys#tab01

2022年8月1日 星期一

Jupyter notebook 延伸工具

 

超好用的2個Jupyter notebook 延伸工具
  • Table of content : 針對Markdown cell 提供目錄
  • autopep8:  python代碼格式化工具






(2) 安裝 Jupyter notebook extensions

打開Anaconda Prompt  , 執行

pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install

(3) 重新開啓Jupyter Notebook, Enable "Table of content "






2022年7月6日 星期三

[Linux 系統程式設計] 關於sigaction 的 SA_RESTART flag

 

Linux 系統程式設計


 #include <signal.h>

       int sigaction(int signum, const struct sigaction *restrict act,
                     struct sigaction *restrict oldact);
   The sigaction structure is defined as something like:

           struct sigaction {
               void     (*sa_handler)(int);
               void     (*sa_sigaction)(int, siginfo_t *, void *);
               sigset_t   sa_mask;
               int        sa_flags;
               void     (*sa_restorer)(void);
           };

在sigaction結構中, 有一個 sa_flags 欄位可以設定為 SA_RESTART , 這代表什麼意思呢? 原文如下
SA_RESTART     
       If a blocked call to one of the following interfaces is
       interrupted by a signal handler, then the call is automatically
       restarted after the signal handler returns if the SA_RESTART flag
       was used; otherwise the call fails with the error EINTR.


例如, Socket programming 的 accept() 就是一個blocked system call,當程序停留在這個系統呼叫時, 若收到signal 則會跳到對應的signal handler去執行, 那signal handler 執行完成後呢? 

其結果可以是繼續回到原呼叫 accept() 的狀態, 就好像沒有跳出去一樣,  或者讓 accept() 直接返回, 並且返回錯誤碼為 EINTR .

OK, 那要繼續回到原呼叫 accept() 的狀態,,可以在sigaction結構的sa_flags 設定SA_RESTART , 再呼叫sigaction() 中進行設定即可

       
    struct sigaction sa;
   sa.sa_handler = &signal_handler;
   sa.sa_flags = SA_RESTART;
   sigfillset(&sa.sa_mask);
   if (sigaction(SIGUSR1, &sa, NULL) == -1) {
      fprintf(stderr,"error\n");
   }

2022年6月25日 星期六

UART over TTL/RS232

 

UART 是軟體層面的 serial 通訊協議(也可以借力 UART IC來完成)。定義baudrate, start bit, stop bit , data bit, parity check 等等, 但這些0和1都是只邏輯的0和1。而實際走的硬體訊號, 則要看使用的是TTL還是 RS232。TTL和 RS232 描述的是 Physical 電氣訊號。

TTL (transistor-transistor logic) 就是定義 0V 為 0,Vcc 為 1 , 一般 MCU、SoC 都會用的方式。  RS-232 定義 -3 to -25V 為 0, 而+3V~+25V為1。不過 RS232 是一個完善的標準通訊規範,所以尚包含硬體流量控制的機制及 Connector 的型式(如DB-9) 等內容。正常的PC 用的就是RS232 界面。不過若僅僅只是做基本的傳輸,不是拿來接數據機(Modem)這類的,其實也只是用了其中3條通訊線而已,TXD, RXD, GND。現在你懂了,為何 UART over TTL 只有3條訊號線的原因。

Source image: https://components101.com/


PC(RS232)—----- UART ——MCU (5V), 因為電壓不同所以要做level shifter , 這可以使用MX232之類的IC來完成. UART over RS-232 (上) 及 UART over TTL (下) 傳送 01010101的電壓圖。總之,我送0/1, 你要解讀成0/1, 而不是解讀成1/0。
Source Image: https://www.sparkfun.com/

相關文章: 


相關課程: 
[1] Linux 驅動程式設計 -實作LINUX UART/TTY Driver
[2] ARM Boot loader 設計-實作UART
[3] MUC 韌體設計-UART驅動


2022年6月22日 星期三

[C語言]字串處理函式:strspn, strpbrk



size_t strspn(const char *str1, const char *str2)  傳回str1包含了str2 字串中的字元,共有有多少個。
char *strpbrk(const char *str1, const char *str2)  傳回str1中出現str2字串中字元的位置。若沒有找到傳回NULL. 

char *d =strpbrk("my phone number is 23167736", "0123456789")
print("%c",d); ==> 卬出2

========================

 以處理HTTP header 的字串為例,  我們要逐行取出HTTP header的內容,  但要如何逐行進行呢? 
以下是使用 strspn(), strpbrk() 函式來完成的
 




參考: 
[1]程式參考


[2]   https://github.com/troglobit/merecat/blob/master/src/libhttpd.c




2022年5月30日 星期一

Disables dynamic cpufreq

 



Boot loader程式放入 Pi3中, 一開機剛開始跑的時候,LED 閃爍頻率都很正常 , 但大約經過約10秒左右 , 時間會變快 . 例如LED 0.5sec閃爍一次 , 經過10sec後變快小於0.5sec閃爍,是哪裡的設定需要再做調整修改 ?



#Disables dynamic cpufreq driver

add this line "force_turbo=1" to config.txt  . 

you can also google DVFS to get more information