2020年10月4日 星期日

[Linux] Kernel函式庫

Kernel

●忙碌等待(busy wait)

會占住CPU,不讓CPU處理其他事,不適合長時間使用.
#include <linux/delay.h>
void mdelay(unsigned long msecs); //毫秒
void udelay(unsigned long msecs); //微秒
void ndelay(unsigned long msecs); //奈秒


不忙碌等待(non-busy wait)
#include <linux/delay.h>
void ssleep(unsigned int seconds);
void msleep(unsigned int mecs);
unsigned long msleep_interruptible(unsigned int mecs);


[C] 函式庫(Library)

ASCII ->Hex
unsigned long int strtoul(const char *str, char **endptr, int base)
str: string
endptr:
base: 這是基數,2~36,或者是特殊值0。

●取絕對值
#include <stdlib.h>
int abs (int j);

●讓程式空轉以達到延遲
__NOP();

●小寫字母轉大寫
int toupper(int c);




access
http://naeilproj.blogspot.com/2015/08/linux-c-c.html


bswap_32
https://man7.org/linux/man-pages/man3/bswap.3.html


dump_stack();
#include <linux/kprobes.h>
#include <asm/traps.h>



stroul
char ptr; 
u32 value stroul("1234", ptr, 10);
把string 1234轉成value 1234
10表10進位(base)

●atoi
value → string

strcat

sscanf

strstr
char *p strstr("abcde", "de")
在abcde中找de, *p為d的位置




2020年9月18日 星期五

[C#] StatusStrip

 1.從工具箱拉StatusStrip,並照下步驟拉兩個StatusLabel.


2.第一個StatusStrip叫Status並修改外觀,第二個無預設名稱.






3.toolStripStatusLabel2.Text = "Test";













2020年9月15日 星期二

[C#] byte/char/string轉換



●byte → char

byte[] byte1 = new byte[5]{0x01,0x02,0x03,0x04,0x05};
char[] char1 = Encoding.ASCII.GetChars(byte1);


●char → byte

char[] char1 = new char[5]{a,b,c,d,e};
byte[] byte1 = Encoding.Default.GetBytes(char1 );


●string  → char[]

string string1 = "abcde";
char[] char1 = string1.ToCharArray(); 


●string  → byte[]
string string1 = "abcde"; 
byte[] byte1 = Encoding.UTF8.GetBytes(string1);
 

●byte[]  → string


byte[] byte1 = new byte[5] { 0x31, 0x32, 0x33, 0x34, 0x35 };
string string1 = Encoding.UTF8.GetString(byte1);



2020年8月12日 星期三

[Linux] Note

 thread介紹

https://blog.gtwang.org/programming/pthread-multithreading-programming-in-c-tutorial/



Ubuntu Linux 中使用網路芳鄰分享目錄


cross compiler: 編譯出來的程式不是給自己用

各版本kernel code
https://elixir.bootlin.com/linux/v5.18.3/source/net