<div dir="ltr">I am not happy with my code at all, I can please provide some suggestions.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 30, 2019 at 12:17 AM Niteesh <<a href="mailto:gsnb.gn@gmail.com">gsnb.gn@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;line-height:19px;white-space:pre-wrap"><div>arm_pl011_context pl011_context;<br></div><div>rpi_fb_context fb_context;</div><div><span style="color:rgb(86,156,214)">char</span> <span style="color:rgb(156,220,254)">uart_instance</span>[<span style="color:rgb(181,206,168)">20</span>];</div><br><br><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">output_char_serial</span>(<span style="color:rgb(86,156,214)">char</span> <span style="color:rgb(156,220,254)">c</span>)</div><div>{</div><div> <span style="color:rgb(220,220,170)">arm_pl011_write_polled</span>(&<span style="color:rgb(156,220,254)">pl011_context</span>.<span style="color:rgb(156,220,254)">base</span>, c);</div><div>}</div><br><div><span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">output_char_fb</span>(<span style="color:rgb(86,156,214)">char</span> <span style="color:rgb(156,220,254)">c</span>)</div><div>{</div><div> <span style="color:rgb(220,220,170)">fbcons_write_polled</span>(&<span style="color:rgb(156,220,254)">fb_context</span>.<span style="color:rgb(156,220,254)">base</span>, c);</div><div>}</div><br><br><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> *<span style="color:rgb(220,220,170)">get_reg_of_node</span>(<span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">void</span> *<span style="color:rgb(156,220,254)">fdt</span>, <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">node</span>)</div><div>{</div><div> <span style="color:rgb(86,156,214)">int</span> len;</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">uint32_t</span> *val;</div><br><div> val = <span style="color:rgb(220,220,170)">fdt_getprop</span>(fdt, node, <span style="color:rgb(206,145,120)">"reg"</span>, &len);</div><div> <span style="color:rgb(197,134,192)">if</span> (val == <span style="color:rgb(86,156,214)">NULL</span> || len < <span style="color:rgb(181,206,168)">4</span>) {</div><div> <span style="color:rgb(197,134,192)">return</span> <span style="color:rgb(86,156,214)">NULL</span>;</div><div> }</div><br><div> <span style="color:rgb(197,134,192)">return</span> (<span style="color:rgb(86,156,214)">void</span> *) <span style="color:rgb(220,220,170)">fdt32_to_cpu</span>(<span style="color:rgb(156,220,254)">val</span>[<span style="color:rgb(181,206,168)">0</span>]);</div><div>}</div><br><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">arm_pl011_init_ctx</span>(</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">void</span> *<span style="color:rgb(156,220,254)">fdt</span>,</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span> *serial</div><div>)</div><div>{</div><div> arm_pl011_context *ctx = &pl011_context;</div><div> <span style="color:rgb(86,156,214)">int</span> node;</div><br><div> <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(220,220,170)">strcmp</span>(serial, <span style="color:rgb(206,145,120)">"uart0"</span>) == <span style="color:rgb(181,206,168)">0</span>) {</div><br><div> <span style="color:rgb(220,220,170)">rtems_termios_device_context_initialize</span>(&<span style="color:rgb(156,220,254)">ctx</span>-><span style="color:rgb(156,220,254)">base</span>, <span style="color:rgb(206,145,120)">"UART"</span>);</div><div> node = <span style="color:rgb(220,220,170)">fdt_path_offset</span>(fdt, serial); </div><div> <span style="color:rgb(156,220,254)">ctx</span>-><span style="color:rgb(156,220,254)">regs</span> = <span style="color:rgb(220,220,170)">get_reg_of_node</span>(fdt, node); </div><div> }</div><div>}</div><br><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">console_select</span>( <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span> *<span style="color:rgb(156,220,254)">console</span> )</div><div>{</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span> *opt;</div><br><div> opt = <span style="color:rgb(220,220,170)">rpi_cmdline_get_arg</span>(<span style="color:rgb(206,145,120)">"--console="</span>);</div><br><div> <span style="color:rgb(197,134,192)">if</span> ( opt ) {</div><div> <span style="color:rgb(197,134,192)">if</span> ( <span style="color:rgb(220,220,170)">strncmp</span>( opt, <span style="color:rgb(206,145,120)">"fbcons"</span>, <span style="color:rgb(86,156,214)">sizeof</span>( <span style="color:rgb(206,145,120)">"fbcons"</span> ) - <span style="color:rgb(181,206,168)">1</span> ) == <span style="color:rgb(181,206,168)">0</span> ) {</div><div> <span style="color:rgb(197,134,192)">if</span> ( <span style="color:rgb(220,220,170)">rpi_video_is_initialized</span>() > <span style="color:rgb(181,206,168)">0</span> ) {</div><div> <span style="color:rgb(220,220,170)">strcpy</span>(uart_instance, <span style="color:rgb(206,145,120)">"/dev/fbcons"</span>);</div><div> BSP_output_char = output_char_fb;</div><div> }</div><div> }<span style="color:rgb(197,134,192)">else</span>{</div><br><div> <span style="color:rgb(197,134,192)">if</span> ( console == <span style="color:rgb(86,156,214)">NULL</span> ){</div><div> <span style="color:rgb(220,220,170)">bsp_fatal</span>( BSP_FATAL_CONSOLE_NO_DEV );</div><div> }</div><div> BSP_output_char = output_char_serial;</div><div> <span style="color:rgb(220,220,170)">strcpy</span>(uart_instance, <span style="color:rgb(206,145,120)">"/dev/ttyS0"</span>);</div><div> }</div><div> }</div><div>}</div><br><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">uart_probe</span>(<span style="color:rgb(86,156,214)">void</span>)</div><div>{</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">void</span> *fdt;</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span> *console;</div><div> <span style="color:rgb(86,156,214)">int</span> node;</div><br><div> fdt = <span style="color:rgb(220,220,170)">bsp_fdt_get</span>();</div><div> node = <span style="color:rgb(220,220,170)">fdt_path_offset</span>(fdt, <span style="color:rgb(206,145,120)">"/chosen"</span>); </div><br><div> console = <span style="color:rgb(220,220,170)">fdt_getprop</span>(fdt, node, <span style="color:rgb(206,145,120)">"stdout-path"</span>, <span style="color:rgb(86,156,214)">NULL</span>);</div><br><div> node = <span style="color:rgb(220,220,170)">fdt_path_offset</span>(fdt, <span style="color:rgb(206,145,120)">"/aliases"</span>);</div><br><div> <span style="color:rgb(86,156,214)">int</span> offset = <span style="color:rgb(220,220,170)">fdt_first_property_offset</span>(fdt, node);</div><br><div> <span style="color:rgb(197,134,192)">while</span> (offset >= <span style="color:rgb(181,206,168)">0</span>) {</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">struct</span> fdt_property *prop;</div><div> </div><div> prop = <span style="color:rgb(220,220,170)">fdt_get_property_by_offset</span>(fdt, offset, <span style="color:rgb(86,156,214)">NULL</span>);</div><div> </div><div> <span style="color:rgb(197,134,192)">if</span> (prop != <span style="color:rgb(86,156,214)">NULL</span>) {</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span> *name;</div><br><div> name = <span style="color:rgb(220,220,170)">fdt_string</span>(fdt, <span style="color:rgb(220,220,170)">fdt32_to_cpu</span>(<span style="color:rgb(156,220,254)">prop</span>-><span style="color:rgb(156,220,254)">nameoff</span>));</div><div> <span style="color:rgb(197,134,192)">if</span>(<span style="color:rgb(220,220,170)">strstr</span>(name, <span style="color:rgb(206,145,120)">"serial"</span>) != <span style="color:rgb(86,156,214)">NULL</span>) {</div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span> *serial;</div><div> serial = <span style="color:rgb(156,220,254)">prop</span>-><span style="color:rgb(156,220,254)">data</span>;</div><br><div> <span style="color:rgb(220,220,170)">arm_pl011_init_ctx</span>(fdt, serial);</div><div> }</div><div> }</div><br><div> offset = <span style="color:rgb(220,220,170)">fdt_next_property_offset</span>(fdt, offset);</div><div> }</div><div> <span style="color:rgb(220,220,170)">console_select</span>(console);</div><div>}</div><br><br><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">output_char</span>(<span style="color:rgb(86,156,214)">char</span> <span style="color:rgb(156,220,254)">c</span>)</div><div>{</div><div> <span style="color:rgb(220,220,170)">uart_probe</span>();</div><div> (*BSP_output_char)(c);</div><div>}</div><br><div>rtems_status_code <span style="color:rgb(220,220,170)">console_initialize</span>(</div><div> rtems_device_major_number <span style="color:rgb(156,220,254)">major</span>,</div><div> rtems_device_minor_number <span style="color:rgb(156,220,254)">minor</span>,</div><div> <span style="color:rgb(86,156,214)">void</span> *arg</div><div>)</div><div>{</div><br><div> <span style="color:rgb(220,220,170)">rtems_termios_initialize</span>();</div><div> </div><div> <span style="color:rgb(220,220,170)">rtems_termios_device_install</span>(</div><div> <span style="color:rgb(206,145,120)">"/dev/ttyS0"</span>,</div><div> &arm_pl011_fns,</div><div> <span style="color:rgb(86,156,214)">NULL</span>,</div><div> &<span style="color:rgb(156,220,254)">pl011_context</span>.<span style="color:rgb(156,220,254)">base</span></div><div> );</div><div> </div><div> <span style="color:rgb(220,220,170)">rtems_termios_device_install</span>(</div><div> <span style="color:rgb(206,145,120)">"/dev/fbcons"</span>,</div><div> &fbcons_fns,</div><div> <span style="color:rgb(86,156,214)">NULL</span>,</div><div> &<span style="color:rgb(156,220,254)">fb_context</span>.<span style="color:rgb(156,220,254)">base</span>);</div><br><div> <span style="color:rgb(220,220,170)">link</span>(uart_instance, CONSOLE_DEVICE_NAME);</div><br><div> <span style="color:rgb(197,134,192)">return</span> RTEMS_SUCCESSFUL;</div><div>}</div><br><div>BSP_output_char_function_type BSP_output_char = output_char;</div><br><div>BSP_polling_getchar_function_type BSP_poll_char = <span style="color:rgb(86,156,214)">NULL</span>;</div><br><div><span style="color:rgb(220,220,170)">RTEMS_SYSINIT_ITEM</span>(</div><div> uart_probe,</div><div> RTEMS_SYSINIT_BSP_START,</div><div> RTEMS_SYSINIT_ORDER_LAST</div><div>);</div></div></div></div>
</blockquote></div>