In the last two articles on Forth, I’ve ranted about how it’s stunning but strange, and then gotten you set up on a basic system and blinked some LEDs. and while I’ve pointed you at the multitasker, we haven’t made much real use of it yet. getting started on a Forth system like this is about half the battle. working inside the microcontroller is different from compiling for the microcontroller, and figuring out the workflow, how to technique problems, and where the beneficial resources are isn’t necessarily obvious. Plus, there’s some terrific features of Mecrisp-Stellaris Forth that you might not notice until you’ve hacked on the system for a while.

Ideally, you’d peek over the carry of someone doing their thing, and you’d see some of how they work. That’s the goal of this piece. If you’ve already flashed in our version of Mecrisp-Stellaris-plus-Embello, you’re ready to follow along. If not, go back and do your homework real quick. We’ll still be here when you’re done. A lot of this post will be very certain to the Mecrisp-Stellaris flavor of Forth, but given that it runs on tons of ARM chips out there, this isn’t a bad place to be.

Getting Acclimatized

The first thing you’re going to need to get used to in Forth is the stack. You know that old chestnut about people only being able to keep five (seven?) things in their mind at one time? Forth puts that to the test.

Last time, I briefly pointed out the .s (“print stack”) command. In the Hackaday Edition, I’ve re-defined the conventional Mecrisp .s to be a little bit less verbose, and to my eyes a lot more readable. If you find yourself hitting .s a lot, and you will, I’ve also written a function that (temporarily) overwrites the “ok.” prompt by appending a stack printout to it, whenever you hit enter. type print.stack and hit enter one a lot more time to see how it works. hitting the reset button, or typing reset will wipe everything in RAM, and that includes the stack-printing prompt, so you’ll be back to a clean slate.

Now is probably a good time to play around with the stack operators. have you read the Mecrisp glossary? check out the list of stack juggling operations there. turn on print.stack and play around until they all make sense.

Have you run words yet? It spits out a linked list of every word that Forth knows, along with the memory locations where they live, and some extra details — too much detail, unless you’re debugging the system itself. There’s an extra, nonstandard, word in Mecrisp that just prints out the function names: list. give that a shot now. If you haven’t already defined a few words, do so.

: hw .” hello, world!” cr ;
is a good one to have on hand.

Layers in Memory

Mecrisp-Stellaris’ memory is divided into two gross locations: RAM and flash. All words that are provided before the “— Mecrisp-Stellaris Core —” mark are in RAM, and will be lost on reset or power-down. new RAM functions will be appended to the front of the list.

After the “— Mecrisp-Stellaris Core —” mark come functions in flash. In the early parts of flash, before “— Flash Dictionary —” is the conventional Mecrisp Forth core. From there until “<>” are words taken from the Mecrisp distribution that are normally useful, including some debugging functions and multitasking. preceding “<>” are the contributions from the Embello libraries, including a lot of GPIO definitions, and those before “<>” were added just for this post series.

What’s not evident is that all of these markers with brackets surrounding them are cornerstones. These allow you clear out flash up until that memory location. So if you’ve added some extra functions into flash, and want to clear back out to the Hackaday edition default state, you can type <>. The extra functions will be erased, and the chip reset. (Note that this loses whatever was in RAM!) The command eraseflash will get you back to the “— Flash Dictionary —” marker.

Overwriting History

If you define a word twice with the same name, you’ll have two versions of the word in the dictionary. When a word is called or compiled, the interpreter looks through memory, from the top of RAM down, and then from the end of flash back to the beginning. Words with the same name in RAM thus get called before those in flash. What can be particularly odd about Forth is that, because it compiles in real-time, the word that is referred to in any calling word is the one that was on the top at the time the calling word was defined. Making tangled histories is a sure way to go insane.

: foo .” foo!” ;
: bar foo .” bar!” ;
bar foo! bar! ঠিক আছে.
: foo .” bizzle!” ; Redefine foo. ঠিক আছে.
foo bizzle! ঠিক আছে.
bar foo! bar! ঠিক আছে.

On the other hand, here’s a great way to work that takes advantage of these various memory features. RAM gets erased on every reset, giving you a clean slate, but by using cornerstones, flash isn’t immutable either. Of course, the deeper in flash you have to erase,অনেকগুলি শব্দ আপনাকে পরে পুনরায় সংজ্ঞায়িত করতে হবে, অনুমান করে যে তাদের মধ্যে কয়েকটি দরকারী ছিল। এটি একটি স্তরযুক্ত কৌশলকে বিকাশের প্রস্তাব দেয়, যা ফ্ল্যাশে অন্তরঙ্গের সবচেয়ে “কোর” শব্দগুলির সাথে। এটিও প্রাকৃতিক কারণ শব্দগুলি বলা হবে সংজ্ঞায়িত করা দরকার, তাই বুনিয়াদিগুলি নির্ধারণ করা প্রথমটি যাই হোক না কেন।

আপনি compilletoram কল করে র্যাম (ডিফল্ট) থেকে একটি নতুন শব্দ কম্পাইল করতে পারেন অথবা কম্পাইলটফ্ল্যাশ ইনভোকেট করে ফ্ল্যাশ করতে পারেন। RAM তে আপনার শব্দ প্রোটোটাইপ। আপনি চান হিসাবে অনেক বার হিসাবে তাদের overwrite complimatiary মনে রাখবেন, কিন্তু মনে রাখবেন যে আপনি কলিং ইতিহাস অক্ষত রাখতে আপস্ট্রিম কিছু পরিবর্তন করার পরে কোন নির্ভরশীল শব্দ পুনরায় সংজ্ঞায়িত করতে হবে। একবার আপনি বিকাশের একটি অংশে তৈরি হয়ে গেলে, রিসেট এবং পরিষ্কার RAM টাইপ করুন। এখন ফ্ল্যাশ মধ্যে এই শব্দ redefine। আপনি যদি নীচে থেকে আপনার আবেদনটি বিকাশ করেন তবে আপনি এটি খুঁজে পাবেন যে এই সমস্ত চমত্কারভাবে একসাথে হ্যা। যখন আপনি ইতিমধ্যে ফ্ল্যাশে লিখিত কিছুতে একটি বাগ আবিষ্কার করেছেন, তখন Cornerstones উদ্ধারের জন্য আসে।

অবশেষে, এগিয়ে সংজ্ঞা এই স্তরযুক্ত প্রকৃতি সত্যিই সহজ হতে পারে। উদাহরণস্বরূপ, ফ্ল্যাশে সংজ্ঞায়িত একটি ফাংশন init প্রতিটি রিসেট চালানো হয়। এটি প্রসেসর গতি এবং সিস্টেম টিক সেট করার মতো জিনিসগুলি অন্তর্ভুক্ত করে, আপনি সম্ভবত সাথে জগাখিচুড়ি করতে চান না। কারণ আপনি initwrite ortwrite করতে পারেন, এবং সংকলনের সময় কোনও সংকলন শব্দগুলি ব্যবহার করে, আপনি কেবল আপনার কার্যকারিতাটি init: init init init। “Howdy!” সিআর;। প্রথম “init” হল নতুন শব্দটির নাম, এবং দ্বিতীয়টি প্রাক-বিদ্যমান init, এবং সমস্ত সেটআপ করার কল করছে। সংজ্ঞা বাকি সঙ্গে খেলতে আপনার। পুনঃসূচনা, সবকিছু এটি সংজ্ঞায়িত করা হয় কিনতে হবে সবকিছু সম্পন্ন করা হবে।

প্রাণী আরামদায়ক

আমি একটি সম্পাদক (ভিম) -এ অনেক কোড লিখি এবং তারপর চারপাশে খেলতে চিপে এটি পাঠান। অত্যন্ত বিশেষ করে, আমি Fort_Upload.sh নামে একটি স্ক্রিপ্ট লিখেছিলাম যা নিম্নরূপ রয়েছে:

[[$ 1]] && শব্দ = $ 1 || টার্ম = / dev / ttyusb0
বিলম্ব = 0.2.
পড়ার সময় -আর এফ; ইকো “$ F” করবেন না; ইকো “$ F”> $ মেয়াদ; ঘুমানো $ {বিলম্ব} গুলি; সম্পন্ন

সিরিয়াল পোর্টে একটি ফাইল পাঠানোর জন্য, এবং এভাবে এগিয়ে, fors_upload.sh

Leave A Comment

Recommended Posts

এক্সবক্স ওয়ান মূল্য মাত্র $ 249 এ নেমে: 500 গিগাবাইট কনসোল, ওয়্যারলেস কন্ট্রোলার, সম্পূর্ণ ফ্রি গেম

মাইক্রোসফ্টের ভিডিও গেম ভক্তদের জন্য কিছু দুর্দান্ত খবর রয়েছে যারা এখনও প্লেস্টেশন 3 বা এক্সবক্স 360 থেকে আপগ্রেড করতে পারেনি third তৃতীয়টির জন্য। সময় দুই মাসেরও কম সময়ে, সফ্টওয়্যার জায়ান্ট তার এক্সবক্স ওয়ান হার্ডওয়্যারের দাম কমানোর সিদ্ধান্ত নিয়েছে। অভ্যন্তরীণ সিদ্ধান্তটি এই আগত […]

pmojk

সেরা আইফোন 7 পাশাপাশি 7 প্লাস স্ক্রিন প্রোটেক্টর

ঠিক এখানে সবচেয়ে সেরা আইফোন 7 পাশাপাশি আইফোন 7 প্লাস স্ক্রিন প্রোটেক্টরগুলি যা আপনি স্ক্র্যাচগুলির বিরুদ্ধে স্ক্রিনটি রক্ষা করতে আপনার ব্র্যান্ডের নতুন স্মার্টফোনের জন্য পেতে পারেন। আপনি যদি ব্র্যান্ড নিউ আইফোন 7 বা আইফোন 7 প্লাসের পক্ষে বর্তমান হার্ডওয়্যার থেকে দূরে সরে […]

pmojk