{"id":4303,"date":"2024-04-27T12:54:08","date_gmt":"2024-04-27T07:24:08","guid":{"rendered":"https:\/\/cthecosmos.com\/?p=4303"},"modified":"2024-04-27T12:54:08","modified_gmt":"2024-04-27T07:24:08","slug":"%f0%9d%90%81%f0%9d%90%88%f0%9d%90%93-%f0%9d%90%81%f0%9d%90%80%f0%9d%90%8d%f0%9d%90%83%f0%9d%90%88%f0%9d%90%8d%f0%9d%90%86","status":"publish","type":"post","link":"https:\/\/cthecosmos.com\/?p=4303","title":{"rendered":"~~~ \ud835\udc01\ud835\udc08\ud835\udc13 \ud835\udc01\ud835\udc00\ud835\udc0d\ud835\udc03\ud835\udc08\ud835\udc0d\ud835\udc06 ~~~"},"content":{"rendered":"\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-e486743970a0d60fb265b3f8bd95773b\" style=\"font-size:17px;line-height:1.8\">In the realm of embedded systems, manipulating individual bits within memory or peripheral registers is an everyday task. But with traditional methods, this seemingly simple task often leads to complexities, inefficiencies, and potential pitfalls. Bit-banding is a feature in ARM Cortex-M architectures that elegantly tackles these challenges.<br><br>\ud835\udc16\ud835\udc21\ud835\udc32 \ud835\udc2e\ud835\udc2c\ud835\udc1e \ud835\udc01\ud835\udc22t \ud835\udc01\ud835\udc1a\ud835\udc27\ud835\udc1d\ud835\udc22\ud835\udc27\ud835\udc20?<br><br>Imagine you&#8217;re in a library, and you want to borrow a specific book. Typically, you&#8217;d need to:<br><br>&#8211; Visit the shelf (read the current list of borrowed books).<br>&#8211; Remove the book you want (modify the list).<br>&#8211; Update the library&#8217;s records with the new list (write the modified list back).<br><br>In the world of embedded systems, when you need to modify a single bit within a memory word, you often follow a similar process:<br><br>&#8211; Read the entire word from memory.<br>&#8211; Modify the desired bit.<br>&#8211; Write the entire word back to memory.<br><br>This &#8220;read-modify-write&#8221; sequence isn&#8217;t just complex; it&#8217;s risky. What if, between your reading and writing, another process modifies the word? You&#8217;d unintentionally overwrite that change, leading to data corruption and unpredictable behaviour.<br><br>In the ARM Cortex-M3 and M4 architectures, the memory map is well-defined, with specific regions allocated for various tasks. Two of these regions, important to our discussion on bit-banding, are the bit-band region and the alias region.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"978\" height=\"631\" data-attachment-id=\"4304\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=4304\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/ponbitbanding.png?fit=978%2C631&amp;ssl=1\" data-orig-size=\"978,631\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ponbitbanding\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/ponbitbanding.png?fit=978%2C631&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/ponbitbanding.png?resize=978%2C631&#038;ssl=1\" alt=\"\" class=\"wp-image-4304\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-09efe410c78ae6a0f50f037efdde0101\" style=\"font-size:17px;line-height:1.8\"><br>\ud835\udc01\ud835\udc22\ud835\udc2d-\ud835\udc01\ud835\udc1a\ud835\udc27\ud835\udc1d \ud835\udc11\ud835\udc1e\ud835\udc20\ud835\udc22\ud835\udc28\ud835\udc27:<br>&#8211; This is the actual memory space where the data resides.<br>&#8211; It spans a 1MB block of memory, starting from 0x20000000 and ending at 0x200FFFFF.<br>&#8211; Think of this region as a large storage room where each bit of data is like an item stored in a box.<br><br>\ud835\udc00\ud835\udc25\ud835\udc22\ud835\udc1a\ud835\udc2c \ud835\udc11\ud835\udc1e\ud835\udc20\ud835\udc22\ud835\udc28\ud835\udc27:<br>&#8211; This is a much larger memory space dedicated to providing direct access to individual bits in the bit-band region.<br>&#8211; It&#8217;s 32 times larger than the bit-band region, ranging from 0x22000000 to 0x23FFFFFF.<br>&#8211; Imagine this region as a massive directory or index, where each bit from the bit-band region gets its own dedicated section.<br><br>For every single bit in the bit-band region, there&#8217;s a corresponding 32-bit word in the alias region. This means, if you want to manipulate a specific bit, you don&#8217;t need to fetch the entire word, alter the bit, and then write it back. Instead, you directly access the corresponding 32-bit word in the alias region and make your changes there, ensuring atomicity and efficiency.<br>Consider the ARM Cortex-M3 and M4 architectures:<br><br><strong>Numerical Example:<\/strong><br><br><strong><em>Bit-Band Region<\/em><\/strong>: A 1MB block from <em>0x20000000 <\/em>to <em>0x200FFFFF<\/em>.<br><strong><em>Alias Region<\/em><\/strong>: A region 32 times larger, from <em>0x22000000 <\/em>to <em>0x23FFFFFF<\/em>.<br><br>Now, let&#8217;s say you want to modify the <strong>5th b<\/strong>it of the word at address <strong><em>0x20000020<\/em><\/strong>. Using bit-banding, you&#8217;d access its alias address:<br><br><strong><em>Alias address = Alias base + (32 * (Bit-band address &#8211; Bit-band base)) + (4 * bit number)<\/em><\/strong><br><br>Plug in our values:<br><br><strong><em>Alias address <\/em><\/strong>= 0x22000000 + (32 * (0x20000020 &#8211; 0x20000000)) + (4 * 5) = 0x220000A8<br><br>By simply writing a value to <em>0x220000A8<\/em>, you&#8217;d be directly modifying the 5th bit of the word at <em>0x20000020<\/em>.<br><br><br>Img Src: Cortex M3 Technical reference manual.<\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-878ec8f28ba5434dcc07a1ce23a5101f\" style=\"font-size:17px\">LinkedIn Post: <a href=\"https:\/\/www.linkedin.com\/posts\/t-yashwanth-naidu_earlycareer-embeddedsystems-learning-activity-7114473505252933632-QqKc\/?utm_source=share&amp;utm_medium=member_desktop\">https:\/\/www.linkedin.com\/posts\/t-yashwanth-naidu_earlycareer-embeddedsystems-learning-activity-7114473505252933632-QqKc\/?utm_source=share&amp;utm_medium=member_desktop<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-white-color has-text-color has-background has-link-color has-medium-font-size wp-elements-486e7799b35920eece0029316d5e98bd\" style=\"background:linear-gradient(135deg,rgb(35,23,11) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%)\">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><strong>An Article by: <\/strong>Yashwanth Naidu Tikkisetty<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bit-banding in ARM Cortex-M architectures simplifies the manipulation of individual bits within memory or peripheral registers, addressing complexities and inefficiencies. By providing direct access to specific bits through the alias region, it ensures atomicity and efficiency, avoiding the risk of data corruption. This feature significantly streamlines embedded systems development and enhances reliability.<\/p>\n<a href=\"https:\/\/cthecosmos.com\/?p=4303\" class=\"more-link\">Read More <span class=\"screen-reader-text\">~~~ \ud835\udc01\ud835\udc08\ud835\udc13 \ud835\udc01\ud835\udc00\ud835\udc0d\ud835\udc03\ud835\udc08\ud835\udc0d\ud835\udc06 ~~~<\/span><\/a>","protected":false},"author":120055267,"featured_media":4307,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[769112296,28627,30181,5495,952411],"tags":[255243,18591260,116003630,4998580,772321195,772321193,1354040],"class_list":{"0":"post-4303","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-c-concepts-hub","8":"category-embedded","9":"category-embedded-systems","10":"category-operating-system","11":"category-short-articles","12":"tag-arm","13":"tag-arm-cortex","14":"tag-bit-banding","15":"tag-bit-wise","16":"tag-c-programming","17":"tag-embedded-systems","18":"tag-short-article","20":"fallback-thumbnail"},"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/ponbitbanding-1.png?fit=978%2C631&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8CiEf-17p","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/users\/120055267"}],"replies":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4303"}],"version-history":[{"count":4,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4303\/revisions"}],"predecessor-version":[{"id":4309,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4303\/revisions\/4309"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/media\/4307"}],"wp:attachment":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}