structobs_kernel_param{constchar*str;int(*setup_func)(char*);int early;};/*
* Only for really core code. See moduleparam.h for the normal way.
* Force the alignment so the compiler doesn't space elements of the
* obs_kernel_param "array" too far apart in .init.setup.
*/#define__setup_param(str, unique_id, fn, early)\staticconstchar __setup_str_##unique_id[] __initconst \__aligned(1)= str;\staticstructobs_kernel_param __setup_##unique_id \__used __section(".init.setup")\__aligned(__alignof__(structobs_kernel_param))\={ __setup_str_##unique_id, fn, early }#define__setup(str, fn)\__setup_param(str, fn, fn,0)//一般用于bootargs传递参数/*
如:__setup("irqaffinity=", irq_affinity_setup);对应的设备树
chosen: chosen {
bootargs = "console=ttyMSM0,115200n8 ... irqaffinity=0-3 ...";
};
*/
工作队列
/*
include/linux/workqueue.h
*/structwork_struct{atomic_long_t data;structlist_head entry;work_func_t func;#ifdefCONFIG_LOCKDEPstructlockdep_map lockdep_map;#endifANDROID_KABI_RESERVE(1);ANDROID_KABI_RESERVE(2);};#defineWORK_DATA_INIT()ATOMIC_LONG_INIT((unsignedlong)WORK_STRUCT_NO_POOL)#defineWORK_DATA_STATIC_INIT()\ATOMIC_LONG_INIT((unsignedlong)(WORK_STRUCT_NO_POOL | WORK_STRUCT_STATIC))structdelayed_work{structwork_struct work;structtimer_list timer;/* target workqueue and CPU ->timer uses to queue ->work */structworkqueue_struct*wq;int cpu;ANDROID_KABI_RESERVE(1);ANDROID_KABI_RESERVE(2);};/**
* schedule_work - put work task in global workqueue
* @work: job to be done
*/staticinline bool schedule_work(structwork_struct*work){returnqueue_work(system_wq, work);}#define__INIT_WORK(_work, _func, _onstack)\do{\__init_work((_work), _onstack);\(_work)->data =(atomic_long_t)WORK_DATA_INIT();\INIT_LIST_HEAD(&(_work)->entry);\(_work)->func =(_func);\}while(0)#endif#defineINIT_WORK(_work, _func)\__INIT_WORK((_work),(_func),0)
python3在windows上的串口测试代码
import threading
from time import*import re
import serial
import serial.tools.list_ports
#扫描串口defserial_scanf():
port_list =list(serial.tools.list_ports.comports())iflen(port_list)==0:print('无可用串口')else:for i inrange(0,len(port_list)):print(port_list[i])#打开串口defserial_open(port, bps):global ser
try:
ser = serial.Serial(port, bps, stopbits=1, bytesize=8, timeout=0.01)return ser
except Exception as result:print("Open serial {} failed".format(port))
sleep(1)print(result)returnFalse#关闭串口defserial_close():
ser.close()#发送数据defserial_send(buf):len= ser.write(buf.encode('utf-8'))len+= ser.write("\r\n".encode('utf-8'))returnlen#接收数据defserial_recv(expect ="OK", timeout =6):
response=''
start_time = time()while1:
data = ser.readline()if data !=b'':
response += data.decode('utf-8')if re.findall("OK",data.decode('utf-8'))or time()- start_time > timeout :breakprint(response)if expect =="":return response
if re.findall(expect,response):returnTrueelse:returnFalseif __name__ =="__main__":
serial_scanf()
serial_open("COM28",115200)
serial_send("AT")str= serial_recv()print(str)