Simplest way to post code to blogger for me:
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:scroll">
In HTML mode put code in "Here"
</pre>
3019/01/19
2020/06/04
Ruby Gem on Mac
# install hombrew ruby, so no mess-up with ruby come with Mac
brew install ruby
# add below path to your environment
export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH="/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"
# install gem fastlyctl, you will find installed bin file in /usr/local/lib/ruby/gems/2.7.0/bin
gem install fastlyctl
# try it
fastlyctl version
Reference
https://stackoverflow.com/questions/51126403/you-dont-have-write-permissions-for-the-library-ruby-gems-2-3-0-directory-ma
2020/05/06
How tokio join macro works
tokio's join macro is pretty amazing
To find out how this join! macro works exactly, you can do blow to expand the macro to see exact code generated.
rustup toolchain install nightly
cargo install cargo-expand
cargo expandYou will find the expanded code like below
2020/05/05
Usage of serde_json
Some sample code shows behavior of serde_json.
I used to write code like
val.as_object().unwrap().get("field_name").unwrap().as_object().unwrap().get_("sub_field_name").as_str().unwrap().
Turns out that using index of serde_json makes code much less verbose.
2020/04/06
Rust Sync/Await
This blog https://os.phil-opp.com/async-await/ explains well the underlying mechanism of Rust sync and await.
Some useful quote of this long blog that helps to:
- Get an general idea of underlying mechanism
- How to use async/await
Quotes starts from here:
----------------------------------
There are two forms of multitasking: Cooperative, Preemptive multitasking.
The disadvantage of preemption is that each task requires its own stack. Compared to a shared stack, this results in a higher memory usage per task and often limits the number of tasks in the system.
cooperative multitasking lets each task run until it voluntarily gives up control of the CPU.
The idea is that either the programmer or the compiler inserts yield operations into the program.
The idea behind async/await is to let the programmer write code that looks like normal synchronous code, but is turned into asynchronous code by the compiler.
What the compiler does behind this scenes is to transform the body of the async function into a state machine, with each .await call representing a different state.
With a single future, we can always wait for each future manually using a loop as described above. However, this approach is very inefficient and not practical for programs that create a large number of futures.
The purpose of an executor is to allow spawning futures as independent tasks, typically through some sort of spawn method. The executor is then responsible for polling all futures until they are completed. The big advantage of managing all futures in a central place is that the executor can switch to a different future whenever a future returns Poll::Pending. Thus, asynchronous operations are run in parallel and the CPU is kept busy.
Many executor implementations can also take advantage of systems with multiple CPU cores. They create a thread pool that is able to utilize all cores if there is enough work available and use techniques such as work stealing to balance the load between cores. There are also special executor implementations for embedded systems that optimize for low latency and memory overhead.
----------------------------------
Some useful quote of this long blog that helps to:
- Get an general idea of underlying mechanism
- How to use async/await
Quotes starts from here:
----------------------------------
There are two forms of multitasking: Cooperative, Preemptive multitasking.
The disadvantage of preemption is that each task requires its own stack. Compared to a shared stack, this results in a higher memory usage per task and often limits the number of tasks in the system.
cooperative multitasking lets each task run until it voluntarily gives up control of the CPU.
The idea is that either the programmer or the compiler inserts yield operations into the program.
The idea behind async/await is to let the programmer write code that looks like normal synchronous code, but is turned into asynchronous code by the compiler.
What the compiler does behind this scenes is to transform the body of the async function into a state machine, with each .await call representing a different state.
With a single future, we can always wait for each future manually using a loop as described above. However, this approach is very inefficient and not practical for programs that create a large number of futures.
The purpose of an executor is to allow spawning futures as independent tasks, typically through some sort of spawn method. The executor is then responsible for polling all futures until they are completed. The big advantage of managing all futures in a central place is that the executor can switch to a different future whenever a future returns Poll::Pending. Thus, asynchronous operations are run in parallel and the CPU is kept busy.
Many executor implementations can also take advantage of systems with multiple CPU cores. They create a thread pool that is able to utilize all cores if there is enough work available and use techniques such as work stealing to balance the load between cores. There are also special executor implementations for embedded systems that optimize for low latency and memory overhead.
----------------------------------
2019/09/03
Golden summary of Encryption
Encryption helps ensure confidentiality. Hashing can help ensure integrity. Digital signatures or message authentication codes (MAC, including keyed hashing such as HMAC) can be used to verify authenticity.
2019/02/16
Notes of Creating Heroku Python App
Master Tutorial
---------------------------
https://devcenter.heroku.com/articles/getting-started-with-python
Install the pipenv
----------------------------
reference:
https://docs.python-guide.org/dev/virtualenvs/#virtualenvironments-ref
you only need to install the part with "Installing Pipenv"
pipenv install -r requirements.txt
pipenv shell # use ctrl+d to exit
pipenv run python main.py
App Create and Deploy
----------------------------
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
Run local
----------------------------
pipenv shell
python manage.py collectstatic
heroku local web
# then open the browser
---------------------------
https://devcenter.heroku.com/articles/getting-started-with-python
Install the pipenv
----------------------------
reference:
https://docs.python-guide.org/dev/virtualenvs/#virtualenvironments-ref
you only need to install the part with "Installing Pipenv"
pipenv install -r requirements.txt
pipenv shell # use ctrl+d to exit
pipenv run python main.py
App Create and Deploy
----------------------------
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
Run local
----------------------------
pipenv shell
python manage.py collectstatic
heroku local web
# then open the browser
2018/12/02
Communication between a working thread and UI thread
Some API like requesting user location, needs to be called in the main UI thread. How to send a message from a working thread to main UI thread? Here is an example:
2018/11/23
語含とバイオリン
妻の作文
語含がバイオリンと出会ったのは小学校三年生の夏でした。小一の時にお父さんの仕事の関係で平塚に引っ越してきて、学校も習い事のスイミングも新しい環境の中に溶け込むまで、二年程かかりました。少し落ち着いて今なら楽器を一つ初めてもいいかと思った時には、小学校三年生になり、遅いスタートになってしまいました。
しかし、いま振り返って見ると、その時が語含にとって最適な時期だと思っています。幼児期から、語含は自ら進んで学ぼうとするタイプではないです。スイミングも、三歳からはじめ、やめたい気持ちを何とか説得して上級クラスを卒業するまで七年もかけました。小三の頃スイミングがやっと順調に進み、もう一つの習い事を増やしたのがバイオリンです。最初は言葉で表現しきれない美しい音色に感動され、「習ってもいいかもしれない」と言ってくれた語含に、私の心の中ではむしろ前向きに捉え続けさせようという肯定的な思いが強かったです。
実際スタートして見たら、毎日家での稽古は苦しみの時間でした。その大変さは、思い出すと今も心が苦しいです。構える姿勢を保つのに、無言の涙、弓を持つようになり、思うように音が出せなくて悔しい涙、新曲に入ると、また指が思うように動かなくて焦りの涙、最初の一❘二年は毎日のようにいろいろな意味での涙がバイオリンに染み込むほどでした。
きらきら星を一年程弾く心の準備で、最初の頃は泣くと、気持ちを共有して慰めたり、十五分でも途中で休ませて、腰を鍛える簡単な筋トレーニングを少し入れたりしていました。それでも半年過ぎて、泣く事が癖になったと感じた時は、二人でルールを決めました。辛くても途中は休まない、できた時はカレンダにーシールを貼ったり、大げさに褒めたりするなど、とにかく稽古の時間を苦しみから解放させる工夫をしました。
徐々に、その成果が現れ、新しい曲に入るようになると、またほかの困難に遭遇しました。指の位置が分からなかったり、覚えられなかったり、練習が嫌になったりするのが出始めました。泣くのは大分回数が減りましたが、無言で涙流しながら、理由を聞くと返事もしないまま、目をつぶるかまいかのように視線は下向きに可憐な様子でバイオリンを弾くのは、見る側として見れば、お母さんにいじめられているとアピールするかのような感じでした。何回かは練習の途中で私が見てられなくて「やめよう!」と言い出した時がありました。でもその時に限って、意外と語含は一度もやめる話を出していないです。代わりに、泣きながら「ママ、はじめようよ。」と声を震えながら私と向き合いました。
そのような姿を見ると、私は語含が実にバイオリンが好きだと感じ、改めてルールを見直しました。家で稽古する時は、お母さんの指示に従う、二人で力合わせてもわからないのは、先生に質問する、うまく行かないところはスピードを落として丁寧に正確にリズムをとらえるなど、二人で話し合い、このやり方でうまく行ったら続ける方針にしました。
今は、練習の途中ではほとんど泣かなくなりました。まれに、泣く時といえば自分で懸命に練習したのに、うまく行かなかった時です。今まで、二回ほど先生の前で、泣いた事覚えています。たぶん自分で悔しかったかもしれないです。家に戻って、二人でこんな会話をしました。「語含、家で本当に練習頑張ったよね、でも、涙を我慢したくても、我慢できなかったよね。どうしたら、できるようになるかしら?」語含は、また無言でした。私は、暫く考えて「語含、私たちにとって先生の指導は本当に貴重な言葉、限られた時間に泣き止まないとその時間は戻れない、次のレッスンはまた一週間後になる、勿体ないよね、その時は、今の事に集中して、ここに来るまでどう頑張ったなど過ぎたことは考えないで欲しい。」「語含、約束して、大事なところは、今この瞬間に集中してね。」
そこから、確かに泣き虫の語含も良くなりつつ、バイオリンのおかげで本当に成長しました。今年夏休みには、私がいない間、発表会の曲アーモルを一人で練習し続けていました。二巻の「二人のてき弾兵」曲を習うとき、足りなかった勢いは、二月頃からキックボクシングを習い始め気持ちを込めて表現できるようになりました。今年の九月発表会では、今まで見たことの無い語含らしいひじの動きで、アーモルをメリハリつけて表現できました。これは、夏休み前から朝晩一日二回は必ずバイオリンを練習するという計画を実行してきた自身の努力があって、自分の音色を感じることが出来たと思います。本人も満足した様子でした。八月からはジムのスケジュールが変わり火曜日のバイオリンレッスンと重なるところが多いですが、両方よく頑張ってきました。自ら支度して行き、帰りは私とジムの前で打ち合わせして着替えてバイオリン教室に向かいます。体を鍛えて、汗を流すとともに気持ちもスッキリする体験を自分で感じ取ったようです。
今六年生の語含は二月の入試を向けて、金土日塾も通いながら準備しています。入試を考えたのも、やはり大好きになったバイオリンを大好きな先生の元で継続して指導を受けるためです。じっくり考えると、バイオリンが語含の心の中で占める割合がだんだん大きくなる感じです。今の生活の中心はバイオリン、そしてボクシングに塾の勉強です。
忙しい毎日ですが、「毎日小さな目標を持って達成させる、一週間が勝負」だとお話した奥村先生の言葉を肝に銘じています。将来、何になるかという理想ははっきりしていないが、今やるべきことをコツコツやりこなせる力は、バイオリンを通して培えると私は思います。
まだまだ、たくさんの創造もつかない困難があるかもしれないが、何年後は語含が自分の力で乗り越えることを望みながら、日々努力を重ねたいです。
語含がバイオリンと出会ったのは小学校三年生の夏でした。小一の時にお父さんの仕事の関係で平塚に引っ越してきて、学校も習い事のスイミングも新しい環境の中に溶け込むまで、二年程かかりました。少し落ち着いて今なら楽器を一つ初めてもいいかと思った時には、小学校三年生になり、遅いスタートになってしまいました。
しかし、いま振り返って見ると、その時が語含にとって最適な時期だと思っています。幼児期から、語含は自ら進んで学ぼうとするタイプではないです。スイミングも、三歳からはじめ、やめたい気持ちを何とか説得して上級クラスを卒業するまで七年もかけました。小三の頃スイミングがやっと順調に進み、もう一つの習い事を増やしたのがバイオリンです。最初は言葉で表現しきれない美しい音色に感動され、「習ってもいいかもしれない」と言ってくれた語含に、私の心の中ではむしろ前向きに捉え続けさせようという肯定的な思いが強かったです。
実際スタートして見たら、毎日家での稽古は苦しみの時間でした。その大変さは、思い出すと今も心が苦しいです。構える姿勢を保つのに、無言の涙、弓を持つようになり、思うように音が出せなくて悔しい涙、新曲に入ると、また指が思うように動かなくて焦りの涙、最初の一❘二年は毎日のようにいろいろな意味での涙がバイオリンに染み込むほどでした。
きらきら星を一年程弾く心の準備で、最初の頃は泣くと、気持ちを共有して慰めたり、十五分でも途中で休ませて、腰を鍛える簡単な筋トレーニングを少し入れたりしていました。それでも半年過ぎて、泣く事が癖になったと感じた時は、二人でルールを決めました。辛くても途中は休まない、できた時はカレンダにーシールを貼ったり、大げさに褒めたりするなど、とにかく稽古の時間を苦しみから解放させる工夫をしました。
徐々に、その成果が現れ、新しい曲に入るようになると、またほかの困難に遭遇しました。指の位置が分からなかったり、覚えられなかったり、練習が嫌になったりするのが出始めました。泣くのは大分回数が減りましたが、無言で涙流しながら、理由を聞くと返事もしないまま、目をつぶるかまいかのように視線は下向きに可憐な様子でバイオリンを弾くのは、見る側として見れば、お母さんにいじめられているとアピールするかのような感じでした。何回かは練習の途中で私が見てられなくて「やめよう!」と言い出した時がありました。でもその時に限って、意外と語含は一度もやめる話を出していないです。代わりに、泣きながら「ママ、はじめようよ。」と声を震えながら私と向き合いました。
そのような姿を見ると、私は語含が実にバイオリンが好きだと感じ、改めてルールを見直しました。家で稽古する時は、お母さんの指示に従う、二人で力合わせてもわからないのは、先生に質問する、うまく行かないところはスピードを落として丁寧に正確にリズムをとらえるなど、二人で話し合い、このやり方でうまく行ったら続ける方針にしました。
今は、練習の途中ではほとんど泣かなくなりました。まれに、泣く時といえば自分で懸命に練習したのに、うまく行かなかった時です。今まで、二回ほど先生の前で、泣いた事覚えています。たぶん自分で悔しかったかもしれないです。家に戻って、二人でこんな会話をしました。「語含、家で本当に練習頑張ったよね、でも、涙を我慢したくても、我慢できなかったよね。どうしたら、できるようになるかしら?」語含は、また無言でした。私は、暫く考えて「語含、私たちにとって先生の指導は本当に貴重な言葉、限られた時間に泣き止まないとその時間は戻れない、次のレッスンはまた一週間後になる、勿体ないよね、その時は、今の事に集中して、ここに来るまでどう頑張ったなど過ぎたことは考えないで欲しい。」「語含、約束して、大事なところは、今この瞬間に集中してね。」
そこから、確かに泣き虫の語含も良くなりつつ、バイオリンのおかげで本当に成長しました。今年夏休みには、私がいない間、発表会の曲アーモルを一人で練習し続けていました。二巻の「二人のてき弾兵」曲を習うとき、足りなかった勢いは、二月頃からキックボクシングを習い始め気持ちを込めて表現できるようになりました。今年の九月発表会では、今まで見たことの無い語含らしいひじの動きで、アーモルをメリハリつけて表現できました。これは、夏休み前から朝晩一日二回は必ずバイオリンを練習するという計画を実行してきた自身の努力があって、自分の音色を感じることが出来たと思います。本人も満足した様子でした。八月からはジムのスケジュールが変わり火曜日のバイオリンレッスンと重なるところが多いですが、両方よく頑張ってきました。自ら支度して行き、帰りは私とジムの前で打ち合わせして着替えてバイオリン教室に向かいます。体を鍛えて、汗を流すとともに気持ちもスッキリする体験を自分で感じ取ったようです。
今六年生の語含は二月の入試を向けて、金土日塾も通いながら準備しています。入試を考えたのも、やはり大好きになったバイオリンを大好きな先生の元で継続して指導を受けるためです。じっくり考えると、バイオリンが語含の心の中で占める割合がだんだん大きくなる感じです。今の生活の中心はバイオリン、そしてボクシングに塾の勉強です。
忙しい毎日ですが、「毎日小さな目標を持って達成させる、一週間が勝負」だとお話した奥村先生の言葉を肝に銘じています。将来、何になるかという理想ははっきりしていないが、今やるべきことをコツコツやりこなせる力は、バイオリンを通して培えると私は思います。
まだまだ、たくさんの創造もつかない困難があるかもしれないが、何年後は語含が自分の力で乗り越えることを望みながら、日々努力を重ねたいです。
2018/11/18
2018/11/16
Android UI, Line Layout in Constrait Layout
This example show 6 line layout containers in a constraint layout, looks like below:
The layout XML is like
The layout XML is like
2018/11/08
Track Ecc Patent
The patent for track ECC could be found at:
https://patents.google.com/patent/US9632863B2
Parity bit is generated from each bit in the sectors on a track.
LLR(log likelyhood ratio) of each bit is adjusted during track ecc decoding.
bit with least absolute value of LLR will be chosen to adjust.
https://patents.google.com/patent/US9632863B2
Parity bit is generated from each bit in the sectors on a track.
LLR(log likelyhood ratio) of each bit is adjusted during track ecc decoding.
bit with least absolute value of LLR will be chosen to adjust.
2018/11/07
Home Studio Setup For Rookie
Few weeks ago, I was asked to setup a proper audio recording system at home to my daughter playing violin. I knew nothing about audio recording at then and only got experience to record from iPhone. I spent a lot of time to do the research about what to buy and how to setup. And finally I end up with a good enough audio recording system with limited budget.
And there is my list of buying(on Amazon JP), I hope it can save you some google time.
Condenser Microphone
audio-technica AT2035
http://amzn.asia/d/aDJhgiJ
150 USD
Microphone Stand
CLASSIC PRO MSB/BLACK
It holds the microphone
http://amzn.asia/d/j5WdTIi
25 USD
Canon Cable
audio-technica ATL458A/3.0
Connects Microphone AT2035 and Audio Interface Focusrite Scarlett Solo
http://amzn.asia/d/8mpnUgx
20 USD
Audio Interface
Focusrite Scarlett Solo G2 2in 2out
Connects Audio Interface and Mac Book
http://amzn.asia/d/eED3yGC
100 USD
Mac Computer with Audacity
Audacity is an open source free audio recording software, good enough for me.
I said Mac computer here because I found Audacity on Windows 10 has signal cut off problem even with driver properly installed. Mac needs no driver, and Audacity works smoothly without any problem.
And there is my list of buying(on Amazon JP), I hope it can save you some google time.
Condenser Microphone
audio-technica AT2035
http://amzn.asia/d/aDJhgiJ
150 USD
Microphone Stand
CLASSIC PRO MSB/BLACK
It holds the microphone
http://amzn.asia/d/j5WdTIi
25 USD
Canon Cable
audio-technica ATL458A/3.0
Connects Microphone AT2035 and Audio Interface Focusrite Scarlett Solo
http://amzn.asia/d/8mpnUgx
20 USD
Audio Interface
Focusrite Scarlett Solo G2 2in 2out
Connects Audio Interface and Mac Book
http://amzn.asia/d/eED3yGC
100 USD
Mac Computer with Audacity
Audacity is an open source free audio recording software, good enough for me.
I said Mac computer here because I found Audacity on Windows 10 has signal cut off problem even with driver properly installed. Mac needs no driver, and Audacity works smoothly without any problem.
2018/07/29
Access GitHub Page by Own Domain Name
https://blog.csdn.net/yucicheung/article/details/79560027
fastly
fastly
nonssl.global.fastly.net185.199.108.153 2018/03/28
Linux Kernal Module Exported Symbol
How LKM A can call functions exported by LKM B?
When LKM B is loaded, Exported symbols are registered to system symbol table in Linux kernel.
When LKM A is loaded, system do binary search in system symbol table and other modules' symbol table to resolve symbols referenced by LKM A.
Reference
https://www.slideshare.net/shimosawa/nlkb20150221
When LKM B is loaded, Exported symbols are registered to system symbol table in Linux kernel.
When LKM A is loaded, system do binary search in system symbol table and other modules' symbol table to resolve symbols referenced by LKM A.
Reference
https://www.slideshare.net/shimosawa/nlkb20150221
GNU's LMA and VMA
What is LMA and VMA
Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This is the address the section will have when the output file is run. The second is the LMA, or load memory address. This is the address at which the section will be loaded. In most cases the two addresses will be the same. An example of when they might be different is when a data section is loaded into ROM, and then copied into RAM when the program starts up (this technique is often used to initialize global variables in a ROM based system). In this case the ROM address would be the LMA, and the RAM address would be the VMA.
You can see the sections in an object file by using the objdump program with the -h option.
Configure LMA/VMA in Linker Script
The full description of an output section looks like this:
section [address] [(type)] : [AT(lma)]
{
output-section-command
output-section-command
...
} [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp]
Generating Binary Image (to burn to Flash)
objcopy can be used to generate a raw binary file by using an
output target of `binary' (e.g., use `-O binary'). When
objcopy generates a raw binary file, it will essentially produce
a memory dump of the contents of the input object file. All symbols and
relocation information will be discarded. The memory dump will start at
the load address of the lowest section copied into the output file.Move LMA to VMA
GNU toolchain does not have scattering mechanism like that in ARM toolchain. so BSS (zero init) part needs to be init by startup code. no library to do that.
How to find out the .bss part? via __bss_start__ and __bss_end__
_cstartup:
/* Relocate .fastcode section (copy from ROM to RAM) */
LDR r0,=__fastcode_load
LDR r1,=__fastcode_start
LDR r2,=__fastcode_end
.fastcode : {
__fastcode_load = LOADADDR (.fastcode);
__fastcode_start = .;
*(.glue_7t) *(.glue_7)
*isr.o (.text.*)
*(.text.fastcode)
*(.text.Blinky_dispatch)
/* add other modules here ... */
. = ALIGN (4);
__fastcode_end = .;
} >RAM AT>ROM
Reference
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/scripts.html#BASIC-SCRIPT-CONCEPTS
https://www.embedded.com/design/mcus-processors-and-socs/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
http://www.delorie.com/gnu/docs/binutils/ld_19.html
http://www.delorie.com/gnu/docs/binutils/ld_33.html
https://ftp.gnu.org/old-gnu/Manuals/binutils-2.12/html_chapter/binutils_3.html
2018/03/16
Install Old Kernel In Ubuntu
In Synaptics
Find below packets to install.
linux-headers-4.4.0-XX
linux-headers-4.4.0-XX-generic
linux-image-4.4.0-XX-generic
linux-image-extra-4.4.0-XX-generic
linux-signed-image-4.4.0-XX-generic
Find below packets to install.
linux-headers-4.4.0-XX
linux-headers-4.4.0-XX-generic
linux-image-4.4.0-XX-generic
linux-image-extra-4.4.0-XX-generic
linux-signed-image-4.4.0-XX-generic
Windows Blue Screen: ATTEMPTED_SWITCH_FROM_DPC
While debugging my windows driver, I got a blue screen with error code ATTEMPTED_SWITCH_FROM_DPC,
MS doc says one cannot wait in a DPC:
A wait operation, attach process, or yield was attempted from a DPC routine. This is an illegal operation.
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/bug-check-0xb8--attempted-switch-from-dpc
I think it relates to locking a resource with WdfWaitLockAcquire(), which is called in a completion function of a IO request.
MS doc says:
If the driver services the I/O request by creating I/O activity on the device, the driver typically calls WdfRequestComplete from its EvtInterruptDpc or EvtDpcFunc callback function.
https://docs.microsoft.com/en-us/windows-hardware/drivers/wdf/completing-i-o-requests
So the completion function could be called in the DPC context.
I can use spin lock though:
On the other hand, they can acquire and release a driver's executive spin lock with KeAcquireSpinLockAtDpcLevel and KeReleaseSpinLockFromDpcLevel, which run faster than KeAcquireSpinLock and KeReleaseSpinLock.
https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/guidelines-for-writing-dpc-routines
MS doc says one cannot wait in a DPC:
A wait operation, attach process, or yield was attempted from a DPC routine. This is an illegal operation.
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/bug-check-0xb8--attempted-switch-from-dpc
I think it relates to locking a resource with WdfWaitLockAcquire(), which is called in a completion function of a IO request.
MS doc says:
If the driver services the I/O request by creating I/O activity on the device, the driver typically calls WdfRequestComplete from its EvtInterruptDpc or EvtDpcFunc callback function.
https://docs.microsoft.com/en-us/windows-hardware/drivers/wdf/completing-i-o-requests
So the completion function could be called in the DPC context.
I can use spin lock though:
On the other hand, they can acquire and release a driver's executive spin lock with KeAcquireSpinLockAtDpcLevel and KeReleaseSpinLockFromDpcLevel, which run faster than KeAcquireSpinLock and KeReleaseSpinLock.
https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/guidelines-for-writing-dpc-routines
2018/02/10
Program Loading Pratice on ARM Platform
The GNU toolchain and ARM toolchain have different approaches for handling the program's linking and loading.
A program have several sections for code and data. Normally in ARM embedded system, before invoking a program's "main" function, code/data sections needs to be located at exact position of the memory as specified in the linking time.
An simple example explaining what is happening at the early phase of program running
- A program image is loaded in to DRAM, each sections in the image are in their loading address now. The ARM toolchain call it loading address, GNU toolchain call it LMA(loading memory address), I will call it LMA now on.
- The next step is to make each section in the image to be relocated to their execution address as specified in the linking time. ARM toolchain calls it execution address. GNU toolchain call it VMA(virtual memory address), I will call it VMA from now on.
ARM toolchain using Scatter-loading mechanism to get section from LMA to VMA. For details, see http://wikigu.blogspot.jp/2017/01/arm-scatter-file-explain.html
One thing needs to be noted here is that, each section in ARM toolchain generated AXF file(ELF format) has the same LMA and VMA. The actually LMA/VMA mapping information is in linker generated InRoot$$Section. When ARM library function "__main" function is called, the section are copied from LMA to VMA according to info in InRoot$$Section.
GNU toolchain does not have similar Scattering-loading mechanism as the ARM. The LMA and VMA specified in the linker file are actually put in the ELF's header information. The LMA information is actually in the ELF's programmer's p_paddr.
The startup code of the image is responsible for copying the section from the LMA to VMA. There is no library function call provided by toolchain to do that.
Below is a good example.
https://www.embedded.com/design/mcus-processors-and-socs/4026075/Building-Bare-Metal-ARM-Systems-with-GNU-Part-2
https://www.embedded.com/design/mcus-processors-and-socs/4026080/Building-Bare-Metal-ARM-Systems-with-GNU-Part-3
A program have several sections for code and data. Normally in ARM embedded system, before invoking a program's "main" function, code/data sections needs to be located at exact position of the memory as specified in the linking time.
An simple example explaining what is happening at the early phase of program running
- A program image is loaded in to DRAM, each sections in the image are in their loading address now. The ARM toolchain call it loading address, GNU toolchain call it LMA(loading memory address), I will call it LMA now on.
- The next step is to make each section in the image to be relocated to their execution address as specified in the linking time. ARM toolchain calls it execution address. GNU toolchain call it VMA(virtual memory address), I will call it VMA from now on.
ARM toolchain using Scatter-loading mechanism to get section from LMA to VMA. For details, see http://wikigu.blogspot.jp/2017/01/arm-scatter-file-explain.html
One thing needs to be noted here is that, each section in ARM toolchain generated AXF file(ELF format) has the same LMA and VMA. The actually LMA/VMA mapping information is in linker generated InRoot$$Section. When ARM library function "__main" function is called, the section are copied from LMA to VMA according to info in InRoot$$Section.
GNU toolchain does not have similar Scattering-loading mechanism as the ARM. The LMA and VMA specified in the linker file are actually put in the ELF's header information. The LMA information is actually in the ELF's programmer's p_paddr.
The startup code of the image is responsible for copying the section from the LMA to VMA. There is no library function call provided by toolchain to do that.
Below is a good example.
https://www.embedded.com/design/mcus-processors-and-socs/4026075/Building-Bare-Metal-ARM-Systems-with-GNU-Part-2
https://www.embedded.com/design/mcus-processors-and-socs/4026080/Building-Bare-Metal-ARM-Systems-with-GNU-Part-3
Subscribe to:
Posts (Atom)
Post Code on Blogger
Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...
-
Explain There is not interrupt PIN for PCIe interrupt. When device wants to raise an interrupt, an interrupt message is sent to host via ...
-
Configure Space Addressing One of the major improvements the PCI Local Bus had over other I/O architectures was its configuration mechanism...
-
Example goes here: String url3 = " https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=barack%20obama " ; JsonpR...




