2018年6月29日 星期五

STM32F4discovery + Jlink + OpenOCD 0.9.0

1. 安裝openocd
$ sudo apt-get install openocd
2. 查看ST-LINK的vid和pid
pi@raspberrypi:~ $ lsusb
Bus 001 Device 007: ID 1366:0105 SEGGER
3. 修改stm32f4discovery.cfg,將stlink-v2-1.cfg 改為 jlink.cfg 將transport select hla_swd 改為 transport select swd
# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
# http://www.st.com/internet/evalboard/product/252419.jsp

source [find interface/jlink.cfg]

transport select swd

source [find target/stm32f4x.cfg]

reset_config srst_only
4. 啟用openocd
$ sudo openocd -f board/stm32f4discovery.cfg
5. 參考來源 https://blog.csdn.net/u013944565/article/details/78569746 https://www.linuxidc.com/Linux/2015-08/121321.htm https://stackoverflow.com/questions/31638347/stm32f0-st-link-v2-openocd-0-9-0-open-failed

STM32F4discovery + ST-link v2.1 + OpenOCD 0.9.0

1. 安裝openocd
$ sudo apt-get install openocd
2. 查看ST-LINK的vid和pid
pi@raspberrypi:~ $ lsusb
Bus 001 Device 006: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)
3. 修改stm32f4discovery.cfg,將stlink-v2.cfg 改為 stlink-v2-1.cfg
# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
# http://www.st.com/internet/evalboard/product/252419.jsp

source [find interface/stlink-v2-1.cfg]

transport select hla_swd

source [find target/stm32f4x.cfg]

reset_config srst_only
4. 啟用openocd
$ sudo openocd -f board/stm32f4discovery.cfg
5. 參考來源 https://blog.csdn.net/u013944565/article/details/78569746 https://www.linuxidc.com/Linux/2015-08/121321.htm https://stackoverflow.com/questions/31638347/stm32f0-st-link-v2-openocd-0-9-0-open-failed

2018年6月24日 星期日

SDK編譯

1. 安裝toolchain
$ sudo chmod 777 /opt

$ make install-glibc-toolchain
2. arm-none-linux-gnueabi-gcc -v 出現: No such file or directory
$ sudo apt-get install ia32-libs
3. make menuconfig 出現: *** Unable to find the ncurses libraries or the *** required header files. *** 'make menuconfig' requires the ncurses libraries. *** *** Install ncurses (ncurses-devel) and try again. ***
$ sudo apt-get install libncurses5-dev
4. make menuconfig 出現: /bin/bash: dialog: command not found
$ sudo apt-get install dialog
5. configure: error: GNU M4 1.4 is required
$ sudo apt-get install m4
6. ./bootstrap: 18: ./bootstrap: aclocal: not found
$ sudo apt-get install automake
7. ./bootstrap: 20: ./bootstrap: libtoolize: not found
$ sudo apt-get install libtool
8. *** [flex.info] Error 1
$ sudo apt-get install flex
9. WARNING: `makeinfo' is missing on your system. You should only need it if you modified a `.texi' or `.texinfo' file, or any other file indirectly affecting the aspect of the manual. The spurious call might also be the consequence of using a buggy `make' (AIX, DU, IRIX). You might want to install the `Texinfo' package or the `GNU make' package. Grab either from any GNU archive site.
$ sudo apt-get install texinfo
10. ../../ylwrap: line 111: yacc: command not found
$ sudo apt-get install bison
11. /bin/sh: 1: lzop: not found
$ sudo apt-get install lzop
12. "mkimage" command not found - U-Boot images will not be built
$ sudo apt-get install uboot-mkimage

2018年6月1日 星期五

義法

推薦行程:


Day 1 國內-巴黎,機票選擇當天抵達

Day 2 巴黎藝術時尚一日:羅浮宮-聖母院-香榭麗舍大街-凱旋門

Day 3 巴黎-米蘭:艾菲爾鐵塔-塞納河遊船-老佛爺購物,晚上乘坐夜火車前往米蘭

Day 4 米蘭-威尼斯:米蘭大教堂-埃曼紐爾二世拱廊-聖馬可廣場-嘆息橋

Day 5 威尼斯-佛羅倫斯,威尼斯外島彩色島-聖馬可大教堂-貢多拉,傍晚出發前往佛羅倫斯

Day 6 佛羅倫斯藝術一日:佛羅倫斯美術學院-聖母百花大教堂-烏菲茲美術館

Day 7 佛羅倫斯-羅馬:皮蒂宮-特萊維噴泉-西班牙廣場

Day 8 羅馬:遊覽梵蒂岡博物館、聖彼得大教堂、聖天使堡….

Day 9 羅馬尋古一日:鬥獸場-真理之口-威尼斯廣場

Day 10 離開羅馬

Day 11 抵達國內


> 巴黎
建議遊玩天數3天


【巴黎市區】
艾菲爾鐵塔、凱旋門、羅浮宮、巴黎聖母院是巴黎著名四大地標建築,如果在巴黎只有一天時間,那就參觀這四個景點吧。

【巴黎近郊】
凡爾賽宮,楓丹白露宮、迪士尼、山谷購物村、吉維尼小鎮,均是可以從巴黎一日往返的近郊遊玩熱門地。

【聖米歇爾山】
> 米蘭
【米蘭市區】
【聖西羅球場】

> 威尼斯
【主島】
【外島】

> 佛羅倫斯
建議遊玩天數2天


【聖母百花大教堂】

> 羅馬
建議遊玩天數2天

【羅馬市區】
鬥獸場、許願池、萬神殿、西班牙台階、圖拉真柱…..

【梵蒂岡】
聖彼得大教堂

https://kknews.cc/travel/k844g28.html
https://kknews.cc/travel/59nb56k.html
https://kknews.cc/zh-tw/travel/j8z4q6q.html
http://www.musictravel.tw/?action=travel&id=53#

2018年5月23日 星期三

Raspberry Pi - 格式化隨身碟

格式化U盘的方法:
首先执行sudo fdisk -l查看你的u盘的序号,通常是/dev/sdb之类的,U盘分区通常是/dev/sdb1

对于u盘我们一般格式化为FAT格式或者FAT32格式,不过在linux下这些会都显示为FAT格式。我们只需要执行命令:
sudo mkfs.vfat -F 32 /dev/sdb1即可将u盘格式化为fat32格式。
假如你要把指定磁盘格式化为NTFS格式那么你需要
sudo apt-get install ntfsprogs
来安装ntfs读写工具,然后执行sudo mkfs.ntfs /dev/sda1,此过程会很慢。对于要格式化为linux ext格式的分区就更容易了:
sudo mkfs.ext4 /dev/sda1 # 格式化为ext4分区 
sudo mkfs.ext3 /dev/sda1 # 格式化为ext3分区 
sudo mkfs.ext2 /dev/sda1 #格式化为ext2分区
參考來源 https://www.jianshu.com/p/0ea8e7b7d64d

2018年5月18日 星期五

Debug STM32F4 with Jlink driver

1. 下載Windows版本 J-Link Software and Documentation Pack
https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack

2. 打開J-Link Commander,輸入命令與STM32F4連線
J-Link> usb

J-Link> device Cortex-M4

J-Link> speed 2000

J-Link> power on

J-Link> connect
3. 其它命令 3.1 mem32: Read 32-bit items.
J-Link> mem32 <Addr>, <NumItems>
3.2 w4: Write 32-bit items.
J-Link> w4 <Addr>, <Data>
3.3 loadbin: Load *.bin file into target memory.
J-Link> loadbin <filename>, <addr>
3.4 savebin: Saves target memory into binary file.
J-Link> savebin <filename>, <addr>, <NumBytes> <hex>
3.5 verifybin Veries if the specified binary is already in the target memory at the specified address.
J-Link> verifybin <filename>, <addr>

2018年5月16日 星期三

工程名詞

1. 打除水泥
電輾仔


2. 鋼筋工程
斤仔車
田嬰

3. 水電工程


4. 板模組立
巴達
砰模
濟模 
腳路


5. 灌漿: 
恐固力
南仔控
碰鋪車
空不雷沙
速拉不
哈利


http://bbs.civilgroup.org/viewtopic.php?t=9227

廚房、浴室設備

1. 廚房
瓦斯爐: 櫻花牌 G9522G
抽油煙機: 櫻花牌 R-7722
烘碗機: 櫻花牌 Q-9580

2. 主衛浴室
馬桶: TOTO全自動馬桶 CES9574T
面盆、龍頭: TOTO下嵌盆 LW586CGU、TOTO龍頭 TLS03301P
淋浴設備: TOTO沐浴柱 TWM10
配件: TOTO暖房乾燥機 TYB3031AA
      TOTO明鏡 MST800T
      TOTO衛生紙架 AD03
      TOTO雙桿毛巾架 AD08
      TOTO置衣平台 AD15

3. 次衛浴室
馬桶: TOTO單體馬桶 CW886SGU、TOTO衛洗麗 TCF6601T
面盆、龍頭: TOTO下嵌盆 L546GU、TOTO龍頭 TLS03301P
淋浴設備: TOTO升降桿 TBW01016B、TOTO淋浴龍頭 TBS03302P
配件: 阿拉斯加或順風浴室排風扇
      TOTO明鏡 MST800T
      TOTO衛生紙架 AD03
      TOTO雙桿毛巾架 AD08
      TOTO置衣平台 AD15

2018年4月15日 星期日

Bring up 技巧

1. 用Dstream透過Jtag接口抓住CPU,
1.1 先讓Dstream可停住CPU或free run

2. 調整Baud rate,打印字串
2.1 如無法打印字串,調整程式裡的Baud rate
2.2 可用程式打印0x0505,打出一個正弦波,再用示波器測量一個波型的週期,來推算頻率。

2018年4月12日 星期四

OpenJTAG与JLink的区别比较

OpenJTAG与JLink的区别比较:

相同点:都同时具备USB转JTAG、USB转串口功能

差别:
1. 操作系统:
OpenJTAG可以用在Windows、Linux下;
JLink只能用在Windows下,在Linux下它的调试功能无法使用,只能使用“JLink+USB转串口2合1”中的USB转串口功能

2. 集成开发环境:
OpenJTAG能用在所有支持GDB调试协议的工具上,比如IAR、Eclipse、winarm,不能用在支持RDI协议的工具上,比如ADS。
JLink支持多种调试协议RDI、GDB调试,几乎所有Windows下的工具都支持,比如ADS、Keil MDK、IAR

3. 对Flash的烧写:
OpenJTAG、JLink对FLASH的烧写功能几乎一样强。
但是对于S3C2410、S3C2440来说,OpenJTAG更胜一筹:OpenJTAG可以烧写NAND Flash;JLink理论上也行,但是没人实现这点。

4. 如何选择:
如果是学习Linux,那么OpenJTAG比较适用;
如果比较喜欢ADS、Keil等工具,那么JLink比较适用;
如果你的开发板是S3C2410、S3C2440,那么OpenJTAG绝对适用。


https://blog.csdn.net/fhq1989312/article/details/6791907

使用 OpenOCD 調適 ARM Cortex A9 CPU

http://jamesgodzilla.blogspot.tw/2013/04/openocd-jtag-adaptor-arm-cortex-a9-cpu.html

bootcmd

> printenv

baudrate=115200
bootcmd=run ll
bootdelay=1
bootflash=mmc rescan 0; fatload mmc 0 0x200000 uImage; bootm 0x200000;
boottftp=tftpboot 0x200000 uImage; bootm 0x200000;
ethact=opv5xc_pse
ethaddr=00:11:22:33:55:00
ipaddr=192.168.1.1
linux.img=uImage.0801
ll=mmc rescan;fatload mmc 0 0x200000 ${linux.img};bootm 0x200000
lu=mmc rescan;fatload mmc 0 0x200000 ${u-boot.img}
nandboot=nand read 0x200000 0x400000 0x2800000;bootm 0x200000
nanduu=sf probe 0;sf erase 0 0x80000;sf write 0x200000 0 0x80000
netmask=255.255.0.0
serverip=192.168.1.100
stderr=serial
stdin=serial
stdout=serial
u-boot.img=u-boot.bin
updateNandMloader=nand erase 0 0x200000;mmc rescan 0;fatload mmc 0 0x200000 miniloader_sec.bin;nand write 0x200000 0 0x8000;nand write 0x200000 0x8000 0x8000
updateNandUboot=nand erase 0x200000 0x200000;mmc rescan 0;fatload mmc 0 0x300000 u-boot_sec.bin;nand write 0x300000 0x200000 0x80000;nand write 0x300000 0x300000 0x80000
updateNandUimage=nand erase 0x400000 0x2800000;mmc rescan 0;fatload mmc 0 0x200000 uImage.cpio;nand write 0x200000 0x400000 0x2800000
uu=sf probe 0;sf erase 0 0x40000;sf write 0x200000 0 0x40000

Environment size: 1169/65532 bytes

POP封装还是SCP封装好?

POP封装是把内存和处理器封装到了一起,属于堆叠结构,直接带来的好处是芯片面积变小,大大节省PCB尺寸;
另外三星4412的POP封装内存芯片采用的是LPDDR2,在与DDR3同样速度的情况下能显著降低功耗;
采用POP封装还有一点好处是,产品在LAYOUT的时候不用考虑DDR内存布线的等长等技术要求,
减少工程师在设计过程中的潜在风险,不过,因为考虑到POP封装间距比较小,所以设计的时候需要在芯片的引脚扇出上下一些功夫。
 
采用SCP封装可以灵活配置外围内存的大小(1G或者2G),而且SCP的球间距比较大,这样线路板可以用比较少的成本来完成设计;
4412 SCP的封装芯片在总体成本上也会比POP低一些。

FPGA與CPLD的區別

http://www.oldfriend.url.tw/Quartus/CPLD_FPGA.htm

https://kknews.cc/zh-tw/tech/mgb3q6.html

2018年3月21日 星期三

嵌入式1 - 預處理指令#define

1 . 用預處理指令#define 聲明一個常數,用以表明1年中有多少秒(忽略閏年問題) 
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL 
我在這想看到幾件事情: 
1) #define 語法的基本知識(例如:不能以分號結束,括號的使用,等等) 
2)懂得預處理器將為你計算常數表達式的值,因此,直接寫出你是如何計算一年中有多少秒而不是計算出實際的值,是更清晰而沒有代價的。 
3) 意識到這個表達式將使一個16位機的整型數溢出-因此要用到長整型符號L,告訴編譯器這個常數是的長整型數。 
4) 如果你在你的表達式中用到UL(表示無符號長整型),那麼你有了一個好的起點。記住,第一印象很重要。


http://b8807053.pixnet.net/blog/post/3610969-%E5%B5%8C%E5%85%A5%E5%BC%8F%E7%B6%93%E5%85%B8%E9%9D%A2%E8%A9%A6%E9%A1%8C

2018年3月14日 星期三

Skyscanner

2018全球節慶匯總:早早準備,盡情狂歡
https://www.skyscanner.com.tw/news/a-summary-of-global-festival-in-2018-03?utm_source=newsletter&utm_medium=email&utm_campaign=TW-2018-03-13&utm_content=Newsletter&utm_term=article-6b2d012177f8448cb496465f198303cb&associateid=EML_TRA_00161_00026

2018最佳訂票時機出爐!
https://www.skyscanner.com.tw/news/bttb-2018?utm_source=newsletter&utm_medium=email&utm_campaign=TW-2018-03-13&utm_content=Newsletter&utm_term=article-5dd2d63567264b849e799ecf64d45353&associateid=EML_TRA_00161_00026

婚攝菜單

七夕活動 + 雅緻晚禮服

1. 拍照服務 
拍攝150組贈120組圖檔
拍攝當天新娘4套禮服
拍攝當天新郎4套西服
造型、彩妝、飾品整體造配
一天拍照行程包含內外景拍攝 (8小時內)
15x24吋 40組PVC一體成型水晶相本 (含數位美編18P + 相本提袋)
28吋無框畫
謝卡200張

2. 訂婚當天
雅緻晚禮服1套

3. 結婚當天
雅緻白紗禮服1套
敬酒雅緻禮服1套 + 送客雅緻禮服1套
訂製兩位新人結婚捧花、胸花、鮮花套組
雙方主婚人胸花2對、伴郎伴娘胸花6對
新娘禮車車頭綵、迎娶車隊車門把花24朵

4. 結婚禮盒
包含簽名簿、禮金簿、簽字筆、喜字貼紙、緣粉、春仔花、紅包袋、扇子、親家帖、儀條

5. 七夕活動好禮
照片旋轉音樂盒
青鳥愛情樹
樂芙掛勾
安妮公主飾品架
10吋桌框 (電子婚卡換)
專屬3D婚紗MV
6折攝影貴賓券乙張
50吋海報簽名綢 (Only you手機殼2入換)
50吋海報簽名綢

6. 打卡禮
調理罐 (J.S專屬杯墊換)

7. 特別禮
布拉格婚紗片場免費拍攝

8. LINE@禮
水底婚紗攝影

9. 首次預約禮
升級香榭謝卡禮盒 200 + 200 = 400張
升級一套VIP禮服 (棚內拍攝)
迷你婚紗側錄30秒 (含專屬隨身碟)

10. 加購商品
喜帖 25/35元
安瓶 500元
NuBra 1980元
增組 800元
VIP晚禮服 3800元
VIP白紗 6800元
增加禮服/套 2500元
當天訂婚/結婚彩妝 3800元

每週年贈送週年紀念照10吋1組相片 (含卡紙) ?

2018年3月1日 星期四

餐廳注意事項

1. 餐廳
最多容納桌數? 36桌

2. 菜色
菜色價位?8月才能得知夏季菜色
何時確定菜色價位? 8月

3. 費用
加收服務費? 無
可否試菜? 7折
尾款現金或信用卡付款? 現金

4. 素食
有全素餐或奶蛋素餐? 有全素餐
素食管費用? 800元

5. 桌數
每桌幾人? 10人
何時需確定桌數? 8 月
預備桌幾桌? 2桌
未使用預備桌? 餐廳吸收
未達保證桌數? 寄桌,冷盤需帶回

6. 場地佈置
入門拱門? 有
禮桌? 有
照片架? 有

7. 各桌佈置
桌卡? 餐廳提供

8. 硬體
燈光?餐廳人員控制
音樂?需自行控制,自帶筆電
可否提前測試影片? 可

9. 時間
開始佈置時間? 早上11:00
結束時間限制? 無
新娘休息室開發時間? 早上11:00

10. 交通
交通地圖? 有
新娘車專用車位? 有
遊覽車專用車位? 無,需停至餐廳後方

11. 水酒
水酒贈送? 1瓶紅酒,2瓶飲料
飲料款式和費用? 果汁,50元
紅酒款式和費用? 進口紅酒,350元
啤酒款式和費用? 金牌啤酒,60元
冰塊費用? 無需冰塊

12. 其它
送客喜糖? 自備
簽名溥、禮簿、胸花名牌? 自備
司儀? 餐廳可提供簡單進場介紹

13. 當天注意事項
MV提前測試?
新娘、新秘、婚攝餐點準備?
水酒以需要方式自取?
預留新娘車車位?
新娘車車頂固定架?

2018年2月13日 星期二

Linux kernel - 創建一個無窮的timer

#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);

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 範例音樂 - 快樂音樂下載,悲傷音樂下載,婚禮音樂下載

1. 快樂音樂
https://www.youtube.com/watch?v=TwkkLki40tA&list=PL6rcH5B64dUc3SUGJ4RlDg8mxk667MCrh

2. 悲傷音樂
https://www.youtube.com/watch?v=i9yO8_r4-j0&list=PL6rcH5B64dUeIcvmyVAcItHWk6CveyyBl

3. 戲劇音樂
https://www.youtube.com/watch?v=ojBHz6i9Lkc&list=PL6rcH5B64dUcrYTnOu11NV_s14DY0Ml26

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年1月31日 星期三

Arduino Uno ATmega328文件

ATmega328
https://www.microchip.com/wwwproducts/en/ATmega328

ATmega328/P - Complete Datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf

ATmega328/P - Summary Datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Summary.pdf

權證筆記

> 認購權證:依照履約價格「購買」標的物的權利
預期未來股票上漲,要買入「認購權證」

> 認售權證:依照履約價格「販賣」標的物的權利
預期未來股票下跌,要買入「認售權證」

> 投資權證有幾個特色
1. 投資門檻低
2. 權證槓桿比率高
3. 損失有限,最多虧損整筆資金
4. 透過權證操作

> 權證適合下面兩種類型的投資人
1. 權證適合對未來股價有所預測,資金不足的投資人
2. 股市操作經驗豐富,操作短線的投資人

> 下面兩種類型投資人,盡量避免投資權證
1. 不了解權證,剛進入股票市場的投資人
2. 無法常常關注股票行情的投資人

> 影響權證價格的 5 大因素
1. 履約價格:到期時規定買進或賣出的價格
2. 權證所對應的股票價格
3. 市場利率:投資人對於所借的資金而需支付的代價
4. 股票波動率:指股票價格隨著時間經過的波動的程度
5. 存續期間:指權證距離到期日的天數

名詞解釋
> 權利金 = 內含價值 + 時間價值
1. 內含價值: 權證立即拿去履約,可以拿回來的利潤
內含價值 = (標的股價 - 履約價) x 行使比例
認購權證的內含價值 = 權的股價 > 履約價
認售權證的內含價值 = 標的股價 > 履約價

2. 時間價值: 反映權證未來在價內狀態有可能的價值
時間價值 = 權利金 - 內含權值
價外權證沒有內含價值,只有時間價值

> 履約價格
履約價 跟 標的物股價 的關係
可分為 價內、價平、價外。

1. 價內權證
認購權證:標的股價大於權證履約價 
認售權證:標的股價小於權證履約價

2. 價平權證
權證履約價 = 標的物股價

3. 價外權證
認購權證:標的股價小於權證履約價
認售權證:標的股價大於權證履約價

            股價 > 履約價    股價 = 履約價    股價 < 履約價
認購權證     價內 (獲利)      價平            價外
認售權譇     價外             價平            價內 (獲利)

> 行使比例
行使比例越高,享受權證槓桿倍數越大

A 權證價格為0.8 履約價為125元 行使比例為1  半年後到期
台積電 (2330) 目前價格為 120元
當一個禮拜後 台積電 (2330) 由 120元 變成 130元時 
權證價格會由 0.8元 變成約 5.8 元  ( 0.8+ (130-125)*1 = 5.8 )
權證漲幅約 625%

2018年1月26日 星期五

經濟專業名詞

> 消費者物價指數: (CPI) consumer price index

> 通澎率 = (CPI(今年) - CPI(去年)) / CPI(去年) 

股市專業名詞

> 可扣抵稅額: 要大於自己所得稅額,才有節稅效果

> 股票殖利率 = [現金股利] 除以 [股價]
若能 > 5% 最好

> 指數股票型證券投資信託基金: ETF (Exchange Traded Funds)

> 周轉率 = 股票交易數量 / 股票發行總數

> 每股盈餘: EPS (Earning per Share)
EPS = 公司淨賺的錢 / 股票發行總數

> 本益比 = 股價 / EPS

2018年1月25日 星期四

現金股利、股票股利計算方式

假如公司今年宣布發放
現金股利 1.5 元
股票股利 1 元

1. 現金股利 1.5 元表示

每一股配發 1.5 元

所以當我們買一張股票 (1000 股)

就可以收到 1,500 的現金股利 = 1000 股 X 1.5 元 = 1,500元


2. 股票股利 1 元表示

每一股配發 1 元

所以當我們買一張股票 (1 股面額 10 元)

就可以收到 1000 股能配 100 股 = 1000 股 / (10 元 / 1 元) = 100 股

=================================================================
參考價怎麼算呢?

a. 除息是用「減法」:股價減股息

b. 除權是用「除法」:股價除以(1+配股率)

c. 若同時除權息:

(股價減股息)除以(1+配股率)

 

假如現在股價為 82 元

現金股利 1.5 元,股票股利 1 元

a. 單看除息的參考價為:82-1.5= 80.5

b. 單看除權參考價為:82/(1+0.1)= 74.5

c. 同時除權息之參考價: (82-1.5)/(1+0.1)= 73.2

2018年1月17日 星期三

Raspberry Pi - 查看device tree

1. 安裝device-tree-compiler套件
$ sudo apt-get install device-tree-compiler
2. 查看device tree
$ dtc -I fs /proc/device-tree

Raspberry Pi - Raspberry Pi 3同時開啟藍芽跟串列埠

修改/boot/config.txt,加入以下三行
core_freq=250
dtoverlay=pi3-miniuart-bt
enable_uart=1

2018年1月16日 星期二

架設PPPoE Server/Client - 使用pon和poff

1. PPPoE Client
- Trigger PPPoE client to dial-up
pon dsl-provider
- Hang up the PPPoE session
poff
2. PPPoE Server組態設置 - Install pppoe
$ sudo apt-get install pppoe
- /etc/ppp/options - /etc/ppp/pppoe-server-options
auth
require-chap
default-mru
default-asyncmap
lcp-echo-interval 60
lcp-echo-failure 5
ms-dns 168.95.1.1
ms-dns 168.95.1.10
noipdefault
noipx
nodefaultroute
+ipv6
- /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
user * 1234 *
3. 啟用pppoe-server - User mode
/usr/sbin/pppoe-server -I eth0 -L 192.168.1.1 -R 192.168.1.10-100
- Kenrel mode
/usr/sbin/pppoe-server -k -I eth0 -L 192.168.1.1 -R 192.168.1.10-100

架設PPPoE Server/Client - 使用pppd

1. PPPoE Client

- User mode for IPv4
pppd pty "pppoe -I eth1 -m 1412" user user password 1234 usepeerdns nodetach noipdefault defaultroute mtu 1492 mru 1492 &
- User mode for IPv6
pppd pty "pppoe -I eth1 -m 1412" user user password 1234 usepeerdns nodetach noipdefault defaultroute mtu 1492 mru 1492 +ipv6 &
- Kernel mode IPv4
pppd plugin /usr/lib/pppd/2.4.5/rp-pppoe.so eth1 user user password 1234 usepeerdns nodetach noipdefault defaultroute mtu 1492 mru 1492 &
- Kernel mode IPv6
pppd plugin /usr/lib/pppd/2.4.5/rp-pppoe.so eth1 user user password 1234 usepeerdns nodetach noipdefault defaultroute mtu 1492 mru 1492 +ipv6 &
2. PPPoE Server - User mode
/usr/sbin/pppoe-server -I eth0 -L 192.168.1.1 -R 192.168.1.10-100
- Kenrel mode
/usr/sbin/pppoe-server -k -I eth0 -L 192.168.1.1 -R 192.168.1.10-100

Raspberry Pi - 架設PPPoE server

         ----------------------------------------------
         |        eth0          |         eth1        |
       LAN PC                 Router                WAN
  ip: 10.1.1.10          eth0: 10.1.1.1
  gw: 255.255.255.0      eth1: DHCP

1. 安裝pppoe套件
$ sudo apt-get install pppoe
2. /etc/ppp/options,無需修改 3. 修改/etc/ppp/pppoe-server-options
auth
require-chap
default-mru
default-asyncmap
lcp-echo-interval 30
lcp-echo-failure 5
ms-dns 168.95.1.1
ms-dns 168.95.1.10
noipdefault
noipx
nodefaultroute
require-chap: 使用chap認證方式,帳號密碼需加於/etc/ppp/chap-secrets require-pap: 使用pap認證方式,帳號密碼需加於/etc/ppp/pap-secrets ms-dns: DNS伺服器位址 +ipv6: 如需支持IPv6 4. 設置chap認證方式的帳號密碼,修改/etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
user * 1234 *
5. 啟用pppoe-server
sudo pppoe-server -I eth0 -L 10.1.1.1 -R 10.1.1.10-20
-I: 設置綁定的介面 -L: 設置綁定介面的位址 -R: 設置pppoe-server所分配的位址,可用"-"來設置範圍 6. 啟用IPv4 forwarding功能
$ sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
7. 設置iptables,啟用DNAT功能
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
8. eth1介面的位址,在網路線插入時,dhcpcd會自動啟用去取得位址
$ ps -aux | grep dhcp
root       314  0.0  0.2   2884  1988 ?        Ss   14:04   0:00 /sbin/dhcpcd -q -b
9. 使用Windows寬頻連線測試
10.1 建立寬頻連線後,pppoe server會新增一個ppp0連線,位址為10.1.1.1
10.2 建立寬頻連線後,PC會取得位址為10.1.1.10,DNS位址如設置的168.95.1.1和8.8.8.8
11. 在使上用wireshark抓取封包,過濾條件為"pppoed || pppoes"
12. 參考來源 https://linux.die.net/man/8/pppoe-server https://linux.die.net/man/8/pppd

2018年1月11日 星期四

暫存器處理

#define ARM_SAI_MODE_Pos   8
#define ARM_SAI_MODE_Msk   (1U << ARM_SAI_MODE_Pos)


 /* Get HCLK prescaler */
  tmp = RCC->CFGR & RCC_CFGR_HPRE;
  tmp = tmp >> 4;
  presc = APBAHBPrescTable[tmp];

static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};

2018年1月10日 星期三

STM32F407 USART PRINTF

Enalbe GPIO clock & UART clock
0x40023830 |= 0x00000004
0x40023840 |= 0x00040000

Connect PXx to USARTx_Tx & Rx
0x40020824 &= ~(0xF << 8)
0x40020824 |= 0x07 << 8
0x40020824 &= ~(0xF << 12)
0x40020824 |= 0x07 << 12

Configure USART Tx as alternate function 
0x40020800 |= 0x02 << (10 * 2)
0x40020808 |= 0x02 << (10 * 2)
0x40020804 |= 0x00 << 10
0x4402080C |= 0x01 << (10 * 2)

Configure USART Rx as alternate function
0x40020800 |= 0x02 << (11 * 2)
0x40020808 |= 0x02 << (11 * 2)
0x40020804 |= 0x00 << 11
0x4402080C |= 0x01 << (11 * 2)


================================================================
0x40023830 = 0x00000004
RCC_AHB1PeriphClockCmd /* Enable GPIO clock */

#define EVAL_COM1_TX_GPIO_CLK            RCC_AHB1Periph_GPIOC
#define EVAL_COM1_RX_GPIO_CLK            RCC_AHB1Periph_GPIOC

#define RCC_AHB1Periph_GPIOC             ((uint32_t)0x00000004)

RCC->AHB1ENR
#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define RCC_BASE              (AHB1PERIPH_BASE + 0x3800)
__IO uint32_t AHB1ENR;       /*!< RCC AHB1 peripheral clock register, Address offset: 0x30

================================================================
0x40023840 = 0x00040000
RCC_APB1PeriphClockCmd /* Enable UART clock */

#define EVAL_COM1_CLK                    RCC_APB1Periph_USART3
#define RCC_APB1Periph_USART3            ((uint32_t)0x00040000)

RCC->APB1ENR
#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define RCC_BASE              (AHB1PERIPH_BASE + 0x3800)
__IO uint32_t APB1ENR;       /*!< RCC APB1 peripheral clock enable register, Address offset: 0x40 

=================================================================
0x40020800 = 0x07 << 8
GPIO_PinAFConfig /* Connect PXx to USARTx_Tx*/

GPIOx->AFR
#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define GPIOC_BASE            (AHB1PERIPH_BASE + 0x0800)
 __IO uint32_t AFR[2];   /*!< GPIO alternate function registers, Address offset: 0x20-0x24 

#define GPIO_PinSource10           ((uint8_t)0x0A)
#define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping */

0x07 << ((0x0A & 0x07) * 4)


0x40020800 = 0x07 << 12
#define GPIO_PinSource11           ((uint8_t)0x0B)
#define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping */

0x07 << ((0x0B & 0x07) * 4)

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

#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define GPIOC_BASE            (AHB1PERIPH_BASE + 0x0800)

0x40020800 |= 0x02 << (10 * 2)
__IO uint32_t MODER;    /*!< GPIO port mode register,               Address offset: 0x00
GPIO_Mode_AF   = 0x02, /*!< GPIO Alternate function Mode */

0x40020808 |= 0x02 << (10 * 2)
__IO uint32_t OSPEEDR;  /*!< GPIO port output speed register,       Address offset: 0x08
GPIO_Speed_50MHz  = 0x02, /*!< Fast speed */

0x40020804 |= 0x00 << 10
__IO uint32_t OTYPER;   /*!< GPIO port output type register,        Address offset: 0x04
GPIO_OType_PP = 0x00,

0x4402080C |= 0x01 << (10 * 2)
__IO uint32_t PUPDR;    /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C
GPIO_PuPd_UP     = 0x01,

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

#define PERIPH_BASE           ((uint32_t)0x40000000)
#define APB1PERIPH_BASE       PERIPH_BASE
#define USART3_BASE           (APB1PERIPH_BASE + 0x4800)

0x40004810 |= 0x0000
__IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 
#define USART_StopBits_1                     ((uint16_t)0x0000)

0x4000480C |= 0x0 | 0x0 | 0x4 | 0x8
__IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C
#define USART_WordLength_8b                  ((uint16_t)0x0000)
#define USART_Parity_No                      ((uint16_t)0x0000)
#define USART_Mode_Rx                        ((uint16_t)0x0004)
#define USART_Mode_Tx                        ((uint16_t)0x0008)

0x40004814 |= 0x0
__IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14
#define USART_HardwareFlowControl_None       ((uint16_t)0x0000)




__IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08

期貨筆記

期貨交易到期月份的意義?
以現在為例,目前是2月份,所以存在當月及連續月期貨為:2、3月 
另外連續三個季月,最接近的是3、6、9月,但是3月和連續月重覆 
所以要加上12月 
所以目前存在市場上,就是2、3、6、9、12月,總共五個月的期貨契約 

期貨的交易規則為,每個契約月份的星期三結算 ,也就是說 
2月份的期貨,會在2月的第三個星期三結算,也就是2/15日 
所以,2/16日後,市場上就不存在2月的期貨契約 的 

想要操作就必須買賣3月份的期貨,而3月份期貨會在3月份的第三個星期三結算 
依此類推,因為期貨有存在的期限,所以如果你不想在短時間內,被迫結算 
可以交易遠月份的期貨契約,也就是3、6、9、12月的 
那到期時間就會長很多,但是注意一下,遠月份的期貨契約成交量會很小 
流通性很差


為什麼要操作期指?
期指在功能上具有避險、套利、投機、價格發現的功能,利用期指好處多:
1.可規避系統風險。當持有現股時,認為現股具有上漲潛力,但無奈大環境不佳時,
則可利用放空期指來避掉系統風險。

2.可以單純看趨勢而不用費力找主流股。買賣股票有選股的煩惱,而期貨的標的物單純化,
只要研究大盤走勢即可,當投資人看好未來股市時,藉由買進期貨來增加投資部位的槓桿;看壞大盤時,
可藉由放空期貨獲利或藉由期貨來規避現貨下跌風險。

3.具有較大的槓桿。期貨最大的特色在於具有高度財務槓桿的優點,只要繳交5%~15%保證金即可交易,
槓桿倍數約10~20倍。

4.期指的交易稅遠低於股票的千分之3。因此在交易成本上,作期指的操作的成本遠低於股票。

參考來源
http://jsinfo2.wls.com.tw/z/zm/zme/zmea.djhtm

2018年1月9日 星期二

現股、融資、融券,電子下單操作

買賣股票的類別:現股、融資、融券 

融資、融券則有4個組合 

當日單:
    1.融資買進(看多) + 融券賣出       → 就是所謂的「當沖」,當日有買有賣同股票、同張數,資券相抵
    2.融券賣出(放空) + 融資買進(回補) → 就是所謂的「當沖」,當日有買有賣同股票、同張數,資券相抵
隔日單:
    1.融資買進(看多) + 融資賣出 
    2.融券賣出(放空) + 融券買進(回補) 

2018年1月3日 星期三

行政院農業委員會 - TGAP下載

行政院農業委員會 - TGAP下載
http://taft.coa.gov.tw/lp.asp?ctNode=276&CtUnit=80&BaseDSD=7&role=C

稻米良好農業規範
https://www.afa.gov.tw/Public/saftyAgriculture/2011315154037055.pdf

芋良好農業規範
https://taft.coa.gov.tw/public/data/01411465771.pdf

WM8994 文件

Data Sheet
https://d3uzseaevmutz1.cloudfront.net/pubs/proDatasheet/WM8994_v4.5.pdf

WM8960 文件

Data Sheet
https://d3uzseaevmutz1.cloudfront.net/pubs/proDatasheet/WM8960_v4.2.pdf

WM8960 6158 FL32 M REV1 Example Configurations
https://d3uzseaevmutz1.cloudfront.net/pubs/manual/WM8960_6158_FL32_M_REV1_Example_Configurations.pdf

Synopsys embARC 文件

embarc.org
http://embarc.org/

Git Hub
https://github.com/foss-for-synopsys-dwc-arc-processors

embARC OSP Documentation
https://embarc.org/embarc_osp/doc/embARC_Document/html/index.html

embARC OSP Wiki 
https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/wiki

GNU Toolchain for ARC documentation!
https://embarc.org/toolchain/

Keil MDK & CMSIS 文件

Getting Started Guides (PDF) - Getting Started with MDK
https://armkeil.blob.core.windows.net/product/mdk5-getting-started.pdf

CMSIS drvier
http://www.keil.com/pack/doc/CMSIS/Driver/html/index.html

MDK Version 5 CMSIS
http://www2.keil.com/mdk5/cmsis/

STM32F407VG 相關文件

1. Home > Microcontrollers > STM32 32-bit ARM Cortex MCUs > STM32 High Performance MCUs > STM32F4 Series > STM32F407/417 > STM32F407VG

Microcontrollers
http://www.st.com/en/microcontrollers.html

STM32 32-bit ARM Cortex MCUs
http://www.st.com/en/microcontrollers/stm32-32-bit-arm-cortex-mcus.html

STM32 High Performance MCUs
http://www.st.com/en/microcontrollers/stm32-high-performance-mcus.html?querycriteria=productId=SC2154

STM32F4 Series
http://www.st.com/en/microcontrollers/stm32f4-series.html?querycriteria=productId=SS1577

STM32F407/417
http://www.st.com/en/microcontrollers/stm32f407-417.html?querycriteria=productId=LN11

STM32F407VG
http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32-high-performance-mcus/stm32f4-series/stm32f407-417/stm32f407vg.html

STM32F4DISCOVERY
http://www.st.com/en/evaluation-tools/stm32f4discovery.html

STM32F4 DSP and standard peripherals library
http://www.st.com/en/embedded-software/stsw-stm32065.html

STMicroelectronics STM32F4 Series Device Support, Drivers and Examples
http://www.keil.com/dd2/stmicroelectronics/stm32f407vg/

2. Product Specifications
http://www.st.com/content/ccc/resource/technical/document/datasheet/ef/92/76/6d/bb/c2/4f/f7/DM00037051.pdf/files/DM00037051.pdf/jcr:content/translations/en.DM00037051.pdf

3. Reference Manuals
http://www.st.com/content/ccc/resource/technical/document/reference_manual/3d/6d/5a/66/b4/99/40/d4/DM00031020.pdf/files/DM00031020.pdf/jcr:content/translations/en.DM00031020.pdf

4. Programming Manuals
http://www.st.com/content/ccc/resource/technical/document/programming_manual/6c/3a/cb/e7/e4/ea/44/9b/DM00046982.pdf/files/DM00046982.pdf/jcr:content/translations/en.DM00046982.pdf

ARM MBED

https://os.mbed.com/

STM支援的mbed的板子
https://os.mbed.com/platforms/?tvend=10

Raspberry Pi - 硬體文件

1. Raspberry Pi 1
1.1 BCM2835 Peripheral specification
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf

1.2 GPU documentation
https://docs.broadcom.com/docs/12358545

1.3 ARM1176JZF-S Technical Reference Manual
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0301h/index.html

2. Raspberry Pi 2
2.1 BCM2836 ARM-local peripherals
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf

2.2 Cortex-A7 MPcore Processor Reference Manual
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0464f/index.html

Raspberry Pi - 查詢樹莓派開發板版本

1. 查詢樹莓派開發板版本,有兩個方法。

2. 查詢/proc/device-tree/model
$ cat /proc/device-tree/model
Raspberry Pi 3 Model B Rev 1.2
3. 查詢/proc/cpuinfo,獲得Revision為a02082,查詢下表,得知此開發版為3B v1.2的版本。
$ cat /proc/cpuinfo

...
...
Hardware        : BCM2835
Revision        : a02082
Serial          : 0000000012345678
Old-style revision codes ==================================================== Code Model Revision RAM Manufacturer 0002 B 1.0 256 MB Egoman 0003 B 1.0 256 MB Egoman 0004 B 2.0 256 MB Sony UK 0005 B 2.0 256 MB Qisda 0006 B 2.0 256 MB Egoman 0007 A 2.0 256 MB Egoman 0008 A 2.0 256 MB Sony UK 0009 A 2.0 256 MB Qisda 000d B 2.0 512 MB Egoman 000e B 2.0 512 MB Sony UK 000f B 2.0 512 MB Egoman 0010 B+ 1.0 512 MB Sony UK 0011 CM1 1.0 512 MB Sony UK 0012 A+ 1.1 256 MB Sony UK 0013 B+ 1.2 512 MB Embest 0014 CM1 1.0 512 MB Embest 0015 A+ 1.1 256 MB / 512 MB Embest New-style revision codes in use: ==================================================== Code Model Revision RAM Manufacturer 900021 A+ 1.1 512 MB Sony UK 900032 B+ 1.2 512 MB Sony UK 900092 Zero 1.2 512 MB Sony UK 900093 Zero 1.3 512 MB Sony UK 9000c1 Zero W 1.1 512 MB Sony UK 920093 Zero 1.3 512 MB Embest a01040 2B 1.0 1 GB Sony UK a01041 2B 1.1 1 GB Sony UK a02082 3B 1.2 1 GB Sony UK a020a0 CM3 1.0 1 GB Sony UK a21041 2B 1.1 1 GB Embest a22042 2B 1.2 1 GB Embest a22082 3B 1.2 1 GB Embest a32082 3B 1.2 1 GB Sony Japan 4. 參考來源 https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md