#include <linux/module.h> #include <linux/init.h> #include <linux/uaccess.h> #include <linux/proc_fs.h> #define TIMEOUT_FREQ(timer) ((HZ * timer) / 1000) #define PROCNAME "timer" MODULE_LICENSE("Dual BSD/GPL"); static struct timer_list tickfn; static unsigned int timer1 = 1000; static void sample_timeout(unsigned long arg) { struct timer_list *tick = (struct timer_list *) arg; int ret; ret = mod_timer(tick, jiffies + TIMEOUT_FREQ(timer1)); printk(KERN_INFO "mod_timer: %d (%lu)\n", ret, jiffies); } static int sample_proc_read(char *buf, char **start, off_t offset, int count, int *eof, void *data) { char *p = buf; p += sprintf(p, "timer1 = %d (ms)\n", timer1); *eof = 1; if ((p - buf) > PAGE_SIZE) return -ENOBUFS; return p - buf; } static int sample_proc_write(struct file *file, const char *buffer, unsigned long count, void *data) { char buf[16]; char *ptr = (char *) buf; if (count > sizeof(buf)) return -EINVAL; if (copy_from_user(buf, buffer, count)) return -EFAULT; while (*ptr && (*ptr == ' ' || *ptr == '\t')) ptr++; timer1 = simple_strtoul(ptr, &ptr, 10); mod_timer(&tickfn, jiffies + TIMEOUT_FREQ(timer1)); return count; } static void sample_init_timer(void) { init_timer(&tickfn); tickfn.function = sample_timeout; tickfn.data = (unsigned long) &tickfn; tickfn.expires = jiffies + TIMEOUT_FREQ(timer1); add_timer(&tickfn); } static void sample_exit_timer(void) { int ret; ret = del_timer(&tickfn); } static int sample_init_proc(void) { struct proc_dir_entry *entry; entry = create_proc_entry(PROCNAME, 0666, NULL); if (entry == NULL) { printk(KERN_WARNING "sample: unable to create proc entry\n"); return -ENOMEM; } entry->read_proc = (read_proc_t *) sample_proc_read; entry->write_proc = (write_proc_t *) sample_proc_write; return 0; } static void sample_exit_proc(void) { remove_proc_entry(PROCNAME, NULL); } static int __init sample_init(void) { sample_init_proc(); sample_init_timer(); printk(KERN_INFO "driver loaded\n"); return 0; } static void __exit sample_exit(void) { int ret = 0; sample_exit_proc(); sample_exit_timer(); printk(KERN_INFO "driver unloaded (%d)\n", ret); } module_init(sample_init); module_exit(sample_exit);
2018年2月13日 星期二
Linux kernel - 創建一個無窮的timer
Linux kernel - 創建一個5秒的timer
#include <linux/module.h> #include <linux/init.h> MODULE_LICENSE("Dual BSD/GPL"); #define TIMEOUT_VALUE (5 * HZ) static struct timer_list tickfn; static void sample_timeout(unsigned long arg) { struct timer_list *tick = (struct timer_list *) arg; printk(KERN_INFO "ptr %p\n", tick); } static int __init sample_init(void) { printk(KERN_INFO "driver loaded\n"); init_timer(&tickfn); tickfn.function = sample_timeout; tickfn.data = (unsigned long) &tickfn; tickfn.expires = jiffies + TIMEOUT_VALUE; add_timer(&tickfn); return 0; } static void __exit sample_exit(void) { int ret; ret = del_timer_sync(&tickfn); printk(KERN_INFO "driver unloaded (%d)\n", ret); } module_init(sample_init); module_exit(sample_exit);
Linux kernel - tasklet範例
#include <linux/init.h> #include <linux/module.h> //#include <linux/kernel.h> #include <linux/interrupt.h> #include <linux/slab.h> #include <linux/delay.h> MODULE_LICENSE("Dual BSD/GPL"); static void f(unsigned long name); static DECLARE_TASKLET(t1, f, (unsigned long)"t1"); static DECLARE_TASKLET_DISABLED(t2, f, (unsigned long)"t2"); static struct tasklet_struct *t3; static void f(unsigned long name) { printk(KERN_INFO "%s, on cpu %d\n", (char *)name, smp_processor_id()); } static void f3(unsigned long name) { static u32 c = 0; tasklet_schedule(t3); //msleep(1000); //mdelay(1000); if (!(c++ % 2000000)) printk(KERN_INFO "%s, on cpu %d\n", (char *)name, smp_processor_id()); } static int hello_init(void) { printk(KERN_INFO "Hello kernel\n"); t3 = kzalloc(sizeof (struct tasklet_struct), GFP_KERNEL); tasklet_init(t3, f3, (unsigned long)"t3"); tasklet_schedule(&t1); tasklet_schedule(&t2); tasklet_schedule(t3); tasklet_enable(&t2); return 0; } static void hello_exit(void) { tasklet_kill(&t1); tasklet_kill(&t2); tasklet_kill(t3); printk(KERN_INFO "Goodbye kernel\n"); } module_init(hello_init); module_exit(hello_exit);
Linux kernel - 建立/sys文件系统獲取所有行程狀態
#include <linux/module.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/sched.h> MODULE_LICENSE("Dual BSD/GPL"); #define PROCNAME "sample" static void *as_start(struct seq_file *m, loff_t *pos) { loff_t n = *pos; struct task_struct *tp = NULL; seq_printf(m, "%lld (%s)\n", n, __func__); if (n == 0) seq_printf(m, "=== seq_file header ===\n"); rcu_read_lock(); if (n == 0) return (&init_task); for_each_process(tp) { n--; if (n <= 0) { return (tp); } } return 0; } static void *as_next(struct seq_file *m, void *p, loff_t *pos) { struct task_struct *tp = (struct task_struct *) p; seq_printf(m, "%lld (%s)\n", *pos, __func__); (*pos)++; tp = next_task(tp); if (tp == &init_task) return NULL; return (tp); } static void as_stop(struct seq_file *m, void *p) { seq_printf(m, "%p (%s)\n", p, __func__); rcu_read_unlock(); } static int as_show(struct seq_file *m, void *p) { struct task_struct *tp = (struct task_struct *) p; seq_printf(m, "%p (%s)\n", tp, __func__); seq_printf(m, "[%s] pid = %d\n", tp->comm, tp->pid); #if 0 seq_printf(m, " tgid = %d\n", tp->tgid); seq_printf(m, " state = %ld\n", tp->state); seq_printf(m, " mm = 0x%p\n", tp->mm); seq_printf(m, " utime = %lu\n", tp->utime); seq_printf(m, " stime = %lu\n", tp->stime); seq_printf(m, " oomkilladj = %d\n", tp->oomkilladj); #endif seq_printf(m, "\n"); return 0; } /* seq_file handler */ static struct seq_operations sample_seq_op = { .start = as_start, .next = as_next, .stop = as_stop, .show = as_show, }; static int sample_proc_open(struct inode *inode, struct file *file) { return seq_open(file, &sample_seq_op); } /* procfs handler */ static struct file_operations sample_proc_fops = { .open = sample_proc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, }; static int sample_init(void) { #if 1 struct proc_dir_entry *entry; entry = create_proc_entry(PROCNAME, S_IRUGO | S_IWUGO, NULL); if (entry) entry->proc_fops = &sample_proc_fops; #else proc_create(PROCNAME, 0, NULL, &sample_proc_fops); #endif printk(KERN_INFO "driver loaded\n"); return 0; } static void sample_exit(void) { remove_proc_entry(PROCNAME, NULL); printk(KERN_INFO "driver unloaded\n"); } module_init(sample_init); module_exit(sample_exit);
Linux kernel - 建立/sys文件系统訪問kernel - seq_open
#include <linux/module.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> MODULE_LICENSE("Dual BSD/GPL"); #define PROCNAME "sample" static char *data_message[] = { "Fedora", "Red Hat", "Debian", "Ubuntu", 0 }; static void *as_start(struct seq_file *m, loff_t *pos) { loff_t n = *pos; char **ptr; int i; seq_printf(m, "%lld (%s)\n", n, __func__); if (n == 0) seq_printf(m, "=== seq_file header ===\n"); ptr = data_message; for (i = 0; ptr[i]; i++) { n--; if (n < 0) { return (void *) (i + 1); } } return 0; } static void *as_next(struct seq_file *m, void *p, loff_t *pos) { int n = (int) p; char **ptr; seq_printf(m, "%u (%s)\n", n, __func__); (*pos)++; ptr = data_message; if (ptr[n]) return (void *) (n + 1); return 0; } static void as_stop(struct seq_file *m, void *p) { int n = (int) p; seq_printf(m, "%u (%s)\n", n, __func__); } static int as_show(struct seq_file *m, void *p) { int n = (int) p - 1; seq_printf(m, "%u (%s)\n", (int) p, __func__); seq_printf(m, "[%d] %s\n", n, data_message[n]); return 0; } /* seq_file handler */ static struct seq_operations sample_seq_op = { .start = as_start, .next = as_next, .stop = as_stop, .show = as_show, }; static int sample_proc_open(struct inode *inode, struct file *file) { return seq_open(file, &sample_seq_op); } /* procfs handler */ static struct file_operations sample_proc_fops = { .open = sample_proc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, }; static int sample_init(void) { #if 1 struct proc_dir_entry *entry; entry = create_proc_entry(PROCNAME, S_IRUGO | S_IWUGO, NULL); if (entry) entry->proc_fops = &sample_proc_fops; #else proc_create(PROCNAME, 0, NULL, &sample_proc_fops); #endif printk(KERN_INFO "driver loaded\n"); return 0; } static void sample_exit(void) { remove_proc_entry(PROCNAME, NULL); printk(KERN_INFO "driver unloaded\n"); } module_init(sample_init); module_exit(sample_exit);
Linux kernel - 建立/sys文件系统訪問kernel - single_open
#include <linux/module.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> MODULE_LICENSE("Dual BSD/GPL"); #define PROCNAME "sample" #define CMD "hello world" static int sample_proc_show(struct seq_file *m, void *v) { seq_printf(m, "%s\n", CMD); return 0; } static int sample_proc_open(struct inode *inode, struct file *file) { return single_open(file, sample_proc_show, NULL); } static const struct file_operations sample_proc_fops = { .open = sample_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int sample_init(void) { #if 1 struct proc_dir_entry *entry; entry = create_proc_entry(PROCNAME, S_IRUGO | S_IWUGO, NULL); if (entry) entry->proc_fops = &sample_proc_fops; #else proc_create(PROCNAME, 0, NULL, &sample_proc_fops); #endif printk(KERN_INFO "driver loaded\n"); return 0; } static void sample_exit(void) { remove_proc_entry(PROCNAME, NULL); printk(KERN_INFO "driver unloaded\n"); } module_init(sample_init); module_exit(sample_exit);
Linux kernel - 建立讀寫屬性的proc entry
#include <linux/module.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <asm/uaccess.h> MODULE_LICENSE("Dual BSD/GPL"); #define PROCNAME "sample" static int sample_flag = 0; static int sample_proc_read(char *buf, char **start, off_t offset, int count, int *eof, void *data) { int len = 0; #if 0 printk(KERN_INFO "buf=%p, *start=%p, offset=%d, count=%d, *eof=%d, data=%p\n", buf, *start, (int)offset, count, *eof, data); #endif len += sprintf(buf + len, "%d\n", sample_flag); if (len > PAGE_SIZE) return -ENOBUFS; return len; } static int sample_proc_write(struct file *file, const char *buffer, unsigned long count, void *data) { char buf[16]; unsigned long len = count; int n; printk(KERN_INFO "len = %d\n", (int)len); if (len >= sizeof(buf)) len = sizeof(buf) - 1; /* asm/uacacess.h */ if (copy_from_user(buf, buffer, len)) return -EFAULT; buf[len] = '\0'; n = simple_strtol(buf, NULL, 10); if (n == 0) sample_flag = 0; else sample_flag = 1; return (len); } static int sample_init(void) { struct proc_dir_entry *entry; entry = create_proc_entry(PROCNAME, 0666, NULL); if (entry == NULL) { printk(KERN_WARNING "proc: unable to create proc entry\n"); return -ENOMEM; } entry->read_proc = sample_proc_read; entry->write_proc = sample_proc_write; printk(KERN_INFO "driver loaded\n"); return 0; } static void sample_exit(void) { remove_proc_entry(PROCNAME, NULL); printk(KERN_INFO "driver unloaded\n"); } module_init(sample_init); module_exit(sample_exit);
Linux kernel - 建立唯讀屬性proc entry
#include <linux/module.h> #include <linux/proc_fs.h> MODULE_LICENSE("Dual BSD/GPL"); #define PROCNAME "sample" static int sample_read_proc(char *buf, char **start, off_t offset, int count, int *eof, void *data) { int len = 0; #if 0 printk(KERN_INFO "buf=%p, *start=%p, offset=%d, count=%d, *eof=%d, data=%p\n", buf, *start, (int)offset, count, *eof, data); #endif len += sprintf(buf + len, "Hello world\n"); if (len > PAGE_SIZE) return -ENOBUFS; return len; } static int sample_init(void) { struct proc_dir_entry *entry; entry = create_proc_read_entry(PROCNAME, S_IRUGO | S_IWUGO, NULL, sample_read_proc, NULL); if (entry == NULL) printk(KERN_WARNING "proc: unable to create proc entry\n"); printk(KERN_INFO "driver loaded\n"); return 0; } static void sample_exit(void) { remove_proc_entry(PROCNAME, NULL); printk(KERN_INFO "driver unloaded\n"); } module_init(sample_init); module_exit(sample_exit);
Linux kernel - 建立proc entry的資料夾
#include <linux/module.h> #include <linux/init.h> #include <linux/uaccess.h> #include <linux/proc_fs.h> MODULE_LICENSE("Dual BSD/GPL"); #define PROCDIR "mydir" #define PROCSYMLINK "myuptime" #define PROCNAME "timer" static unsigned int timer1 = 1000; static struct proc_dir_entry *dir_entry; static struct proc_dir_entry *symlink_entry; static int sample_proc_read(char *buf, char **start, off_t offset, int count, int *eof, void *data) { char *p = buf; p += sprintf(p, "timer1 = %d (ms)\n", timer1); *eof = 1; if ((p - buf) > PAGE_SIZE) return -ENOBUFS; return p - buf; } static int sample_proc_write(struct file *file, const char *buffer, unsigned long count, void *data) { char buf[16]; char *ptr = (char *) buf; if (count > sizeof(buf)) return -EINVAL; if (copy_from_user(buf, buffer, count)) return -EFAULT; while (*ptr && (*ptr == ' ' || *ptr == '\t')) ptr++; timer1 = simple_strtoul(ptr, &ptr, 10); return count; } static int sample_init_proc(void) { struct proc_dir_entry *entry; dir_entry = proc_mkdir(PROCDIR, NULL); if (dir_entry) { entry = create_proc_entry(PROCNAME, 0666, dir_entry); if (entry == NULL) { printk(KERN_WARNING "sample: unable to create proc entry\n"); return -ENOMEM; } entry->read_proc = (read_proc_t *) sample_proc_read; entry->write_proc = (write_proc_t *) sample_proc_write; symlink_entry = proc_symlink(PROCSYMLINK, dir_entry, "../uptime"); if (symlink_entry == NULL) { printk(KERN_WARNING "sample: unable to create symlink proc entry\n"); return -ENOMEM; } } return 0; } static void sample_exit_proc(void) { if (dir_entry) { remove_proc_entry(PROCNAME, dir_entry); remove_proc_entry(PROCSYMLINK, dir_entry); remove_proc_entry(PROCDIR, NULL); dir_entry = NULL; } } static int __init sample_init(void) { sample_init_proc(); printk(KERN_INFO "driver loaded\n"); return 0; } static void __exit sample_exit(void) { int ret = 0; sample_exit_proc(); printk(KERN_INFO "driver unloaded (%d)\n", ret); } module_init(sample_init); module_exit(sample_exit);
投資新手必讀書籍
必讀- 典藏世紀智慧:投機教父科斯托蘭尼精選 初階 中階 高階 都必須讀 不同階段會有不同的幫助 新手區 債券 債券天王葛洛斯 基本面 葛拉漢教你看懂財務報表 心理面 活著就是贏家 進階 心理面 股市作手回憶錄 -做對加碼 心理面 從20萬到10億 : 張松允的獨門投資術 心理面 避險基金交易祕辛 還有絕對值得一玩的 現金流遊戲 ----------- Job建議閱讀順序 新手區: 1.技術分析:外匯操作實戰技巧與心法/許強 2.資金控管、策略、程式交易:計量技術操盤策略(上)、計量技術操盤策略(下) 、海龜特訓班or海龜投資法則、《交易大師TradeStation》 3.總經:看準市場脈動投機術 4.財報:第一次看財務報表就上手/趙曉蓮 進階區: 1心理:作手-獨自排徊在天堂與地獄之間 2心理:股票作手回憶錄 3心理:金融怪傑(上) 、金融怪傑(下) 、新金融怪傑(上) 、新金融怪傑(下) (如果你聽國外經理人的演講,他們會大推這本書,這幾本是任何階段都會有收獲的書) 4心理:八敗人生 專業區: 0總經基礎教科書:國際經濟學(下冊)/克魯曼Krugman (經濟學教科書,我讀了不少,但亞洲金融風暴、LTCM、南美金融違約等事件都有提及的,也只有它了) 1總經:避險基金交易秘辛 2總經:貨幣戰爭 (我認為每個人都應該看的好書) 3總經心理歷史: <典藏世紀智慧>:投機教父科斯托蘭尼精選 4.總經:美元危機 至於台股的教科書,我覺得沒有一本能推薦的,建議滑滑輪出一本 如需書籍連結,請見http://www.wretch.cc/blog/phigroup/15547878 ------------------ 獵獵豹: 黑天鵝效應 投機客養成教育(上) 、投機客養成教育(下) 專業投機原理(一) 、 專業投機原理(二) ---------------- Mr.X推薦書籍 股價趨勢技術分析(上) 、股價趨勢技術分析(下) 市場互動技術分析 墨菲論市場互動分析:教您掌握全球金融市場關係的獲利法則 金融市場技術分析(上) 、金融市場技術分析(下) 巨波投資法 看準市場脈動投資術 景氣為什麼會循環 ------------------- 歐斯麥建議書籍 新手區: 觀念:與巴菲特同步買進、巴菲特寫給股東的信、彼得林區選股戰略 財報:操盤人教你看財務報表 技術:點線賺錢術 K線:強力陰陽線、主控戰略K線 總經:看準市場脈動投機術 傳記類可看資本家的冒險 心理:投資心理學 股票作手回憶錄 波浪:艾略特波浪理論-市場行為的關鍵 了解系列: 了解外資:從投機到投資 , 打敗外資賺大錢 了解金融史:歷史上的投機事業、貪婪時代, 投機-貪婪的智慧 其他:牛頓達爾文及投資股票、股價棉花與尼羅河密碼 專欄作家奶爸推薦 進階區: 技術指標與波浪理論 國際視野區: 1.文明衝突與世界秩序的重建 2.石油的政治經濟學
Yotube 範例音樂 - 快樂音樂下載,悲傷音樂下載,婚禮音樂下載
2018年2月11日 星期日
小台指期交易時間、小台指期保證金、小台指期最後交易日
1. 商品合約規格 小型臺股期指(MTX) 一般交易時間:上午08:45~下午01:45 盤後交易時間:下午03:00~次日上午05:00 交易月份:3.6.9.12 最小跳動值:一點50元 2. 商品保證金 原始保證金:20,750元 維持保證金:16,000元 3. 最後交易日 http://www.taifex.com.tw/chinese/4/Calendar.asp 4. 參考來源 http://www.taifex.com.tw/chinese/2/TX.asp http://www.taifex.com.tw/chinese/5/IndexMargining.asp http://www.taifex.com.tw/chinese/4/Calendar.asp
大台指期交易時間、大台指期保證金、大台指期最後交易日
1. 商品合約規格 臺股期指(TX) 一般交易時間:上午08:45~下午01:45 盤後交易時間:下午03:00~次日上午05:00 交易月份:3.6.9.12 最小跳動值:一點200元 2. 商品保證金 原始保證金:83,000元 維持保證金:64,000元 3. 最後交易日 http://www.taifex.com.tw/chinese/4/Calendar.asp 4. 參考來源 http://www.taifex.com.tw/chinese/2/TX.asp http://www.taifex.com.tw/chinese/5/IndexMargining.asp http://www.taifex.com.tw/chinese/4/Calendar.asp
小道瓊期貨交易時間、小道瓊期貨保證金、小道瓊期貨最後交易日
1. 商品合約規格 商品種類/代號:小道瓊工業股價指數(YM) 本地交易時間:06:00~05:00 交易月份:3.6.9.12 最小跳動值:一點5美元 2. 商品保證金 原始保證金:5830 USD 維持保證金:5300 USD 當沖保證金:2915 USD 3. 最後交易日 4. 小道瓊期貨怎麼交易 : 需要先到期貨公司辦理,海外期貨帳戶開戶 透過該公司的交易平台,匯入足夠保證金,下單即可 5. 參考來源 https://www.capitalfutures.com.tw/product/specs-us.asp http://www.capitalfutures.com.tw/product/deposit.asp?xy=2&xt=2 https://www.capitalfutures.com.tw/product/finalday_us.asp?xy=4&xt=2
2018年2月3日 星期六
期貨筆記
1. 觀察美股走勢 美國指數: Dow紐約瓊斯工業平均指數、S&P500指數、Nasdaq那斯達克綜合指數、費城半導體 當地交易時間: 週一至週五 09:30 ~ 16:00 台灣交易時間: -------- 夏令時間 --------- T日21:30 ~ T+1日04:00 -------- 冬令時間 --------- T日22:30 ~ T+1日05:00 2. 觀察前日三大法人期貨未平倉數量 3. 觀察前日三大法人買賣超 同一帳戶不能同時擁有同月份的多單跟空單,如需空多單並存鎖住利潤,可利用 1. 買賣大小台指期 2. 買賣跨月份的期貨 3. 利用另一個戶頭來買賣 參考來源 http://www.cnyes.com/economy/indicator/GlobalTime/GlobalTime_Major.aspx
2018年2月1日 星期四
Arduino Uno ATmega16U2文件
ATmega16U2 https://www.microchip.com/wwwproducts/en/ATMEGA16U2 ATmega8U2/16U2/32U2 - Complete Datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/doc7799.pdf ATmega8U2/16U2/32U2 - Summary Datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/7799S.pdf
訂閱:
文章 (Atom)