Fixed the black rows yay!

This commit is contained in:
Lee Lup Yuen 2022-12-18 10:46:22 +08:00
parent 57f228f6fb
commit 3aeb586bae
4 changed files with 31 additions and 20 deletions

View file

@ -4688,25 +4688,25 @@ This prevents `sinfo` from garbling the `printf` output...
NuttShell (NSH) NuttX-11.0.0-RC2
```
FYI: `printf` Console Output Stream is locked and unlocked with a Mutex...
FYI: `printf` Console Output Stream is locked and unlocked with a Mutex. Let's log the locking and unlocking of the Mutex...
https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_libfilelock.c#L39-L64
[nuttx/libs/libc/stdio/lib_libfilelock.c](https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_libfilelock.c#L39-L64)
```c
void flockfile(FAR struct file_struct *stream)
{
up_putc('{');////
up_putc('{'); // Log the Mutex Locking
nxrmutex_lock(&stream->fs_lock);
}
...
void funlockfile(FAR struct file_struct *stream)
{
up_putc('}');////
up_putc('}'); // Log the Mutex Unlocking
nxrmutex_unlock(&stream->fs_lock);
}
```
Output log shows that `{` and `}` are nested...
Output log shows that `{` and `}` (Mutex Locking and Unlocking) are nested...
```text
nx_start_application: Starting init thread
@ -4729,12 +4729,12 @@ Let's print the Thread ID and Mutex Count...
void flockfile(FAR struct file_struct *stream)
{
nxrmutex_lock(&stream->fs_lock);
_info("%p, thread=%d, mutex.count=%d\n", stream, gettid(), stream->fs_lock.count); ////
_info("%p, thread=%d, mutex.count=%d\n", stream, gettid(), stream->fs_lock.count); // Log the Thread ID and Mutex Count
}
void funlockfile(FAR struct file_struct *stream)
{
_info("%p, thread=%d, mutex.count=%d\n", stream, gettid(), stream->fs_lock.count); ////
_info("%p, thread=%d, mutex.count=%d\n", stream, gettid(), stream->fs_lock.count); // Log the Thread ID and Mutex Count
nxrmutex_unlock(&stream->fs_lock);
}
```
@ -4750,22 +4750,22 @@ funlockfile: 0x40a5cc78, thread=2, mutex.count=3
funlockfile: 0x40a5cc78, thread=2, mutex.count=2
```
That's because [`nxrmutex_lock`](https://github.com/apache/nuttx/blob/master/include/nuttx/mutex.h#L335-L377) allows the Mutex to be locked multiple times within the same thread.
Why? That's because [`nxrmutex_lock`](https://github.com/apache/nuttx/blob/master/include/nuttx/mutex.h#L335-L377) allows the Mutex to be locked multiple times __within the same thread.__
FYI: Here's how we verify whether our code is called by multiple CPU Cores...
```c
#include "../arch/arm64/src/common/arm64_arch.h" ////
_info("up_cpu_index=%d\n", MPIDR_TO_CORE(GET_MPIDR())); ////
#include "../arch/arm64/src/common/arm64_arch.h"
_info("up_cpu_index=%d\n", MPIDR_TO_CORE(GET_MPIDR()));
// Shows: `up_cpu_index=0`
_info("mpidr_el1=%p\n", read_sysreg(mpidr_el1)); ////
_info("mpidr_el1=%p\n", read_sysreg(mpidr_el1));
// Shows `mpidr_el1=0x80000000`
```
FYI: How `printf` works...
[`printf`](https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_printf.c#L32-L51_ calls...
[`printf`](https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_printf.c#L32-L51) calls...
- [`vfprintf`](https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_vfprintf.c#L34-L56), which calls...
- [`libvsprintf`](https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_libvsprintf.c#L1336-L1381), which calls...
- [`vsprintf_internal`](https://github.com/apache/nuttx/blob/master/libs/libc/stdio/lib_libvsprintf.c#L171-L1332), which calls...

View file

@ -1152,6 +1152,7 @@ pub export fn hello_main(
// _ = c.sleep(1);
// Init Timing Controller TCON0 (in C)
// https://github.com/lupyuen2/wip-pinephone-nuttx/blob/tcon2/arch/arm64/src/a64/a64_tcon0.c#L180-L474
_ = a64_tcon0_init();
// Init PMIC (in Zig)
@ -1161,9 +1162,11 @@ pub export fn hello_main(
// _ = c.sleep(1);
// Enable MIPI DSI Block (in C)
// https://github.com/apache/nuttx/blob/master/arch/arm64/src/a64/a64_mipi_dsi.c#L526-L914
_ = a64_mipi_dsi_enable();
// Enable MIPI Display Physical Layer (in C)
// https://github.com/apache/nuttx/blob/master/arch/arm64/src/a64/a64_mipi_dphy.c#L86-L162
_ = a64_mipi_dphy_enable();
// Reset LCD Panel (in Zig)
@ -1180,13 +1183,15 @@ pub export fn hello_main(
// TODO: Remove this: dsi.panel_init();
// Start MIPI DSI HSC and HSD (in C)
// https://github.com/apache/nuttx/blob/master/arch/arm64/src/a64/a64_mipi_dsi.c#L914-L993
_ = a64_mipi_dsi_start();
// Init Display Engine (in C)
// https://github.com/lupyuen2/wip-pinephone-nuttx/blob/tcon2/arch/arm64/src/a64/a64_de.c
_ = a64_de_init();
// Wait 160 milliseconds
_ = c.usleep(160000);
_ = c.usleep(160_000);
// Render Graphics with Display Engine (in C)
// https://github.com/lupyuen/pinephone-nuttx/blob/main/test/test_a64_de.c

View file

@ -104,9 +104,6 @@ int render_graphics(void)
DEBUGASSERT(overlayInfo[1].fblen == (overlayInfo[1].sarea.w) * overlayInfo[1].sarea.h * 4);
DEBUGASSERT(overlayInfo[1].stride == overlayInfo[1].sarea.w * 4);
// Fill Framebuffer with Test Pattern
test_pattern();
// Init the UI Blender for PinePhone's A64 Display Engine
int ret = a64_de_blender_init();
DEBUGASSERT(ret == OK);
@ -120,6 +117,7 @@ int render_graphics(void)
#endif // !__NuttX__
// Init the Base UI Channel
// https://github.com/lupyuen2/wip-pinephone-nuttx/blob/tcon2/arch/arm64/src/a64/a64_de.c
ret = a64_de_ui_channel_init(
1, // UI Channel Number (1 for Base UI Channel)
planeInfo.fbmem, // Start of frame buffer memory
@ -133,6 +131,7 @@ int render_graphics(void)
DEBUGASSERT(ret == OK);
// Init the 2 Overlay UI Channels
// https://github.com/lupyuen2/wip-pinephone-nuttx/blob/tcon2/arch/arm64/src/a64/a64_de.c
int i;
for (i = 0; i < sizeof(overlayInfo) / sizeof(overlayInfo[0]); i++)
{
@ -151,13 +150,19 @@ int render_graphics(void)
}
// Set UI Blender Route, enable Blender Pipes and apply the settings
// https://github.com/lupyuen2/wip-pinephone-nuttx/blob/tcon2/arch/arm64/src/a64/a64_de.c
ret = a64_de_enable(CHANNELS);
DEBUGASSERT(ret == OK);
// Fill Framebuffer with Test Pattern.
// Must be called after Display Engine is Enabled, or black rows will appear.
test_pattern();
return OK;
}
// Fill the Framebuffers with a Test Pattern
// Fill the Framebuffers with a Test Pattern.
// Must be called after Display Engine is Enabled, or black rows will appear.
static void test_pattern(void)
{
// Zero the Framebuffers
@ -188,7 +193,7 @@ static void test_pattern(void)
fb0[i] = 0x80800000;
}
// This is needed to reduce the missing lines, not sure why
// Needed to fix black rows, not sure why
ARM64_DMB();
ARM64_DSB();
ARM64_ISB();
@ -202,7 +207,7 @@ static void test_pattern(void)
// Colours are in ARGB 8888 format
fb1[i] = 0x80FFFFFF;
// This is needed to reduce the missing lines, not sure why
// Needed to fix black rows, not sure why
ARM64_DMB();
ARM64_DSB();
ARM64_ISB();
@ -234,7 +239,7 @@ static void test_pattern(void)
fb2[p] = 0x00000000; // Transparent Black in ARGB 8888 Format
}
// This is needed to reduce the missing lines, not sure why
// Needed to fix black rows, not sure why
ARM64_DMB();
ARM64_DSB();
ARM64_ISB();

View file

@ -11,6 +11,7 @@ static int write_dcs(const uint8_t *buf, size_t len)
assert(len > 0);
// Do DCS Short Write or Long Write depending on command length
// https://github.com/apache/nuttx/blob/master/arch/arm64/src/a64/a64_mipi_dsi.c#L366-L526
switch (len)
{
// DCS Short Write (without parameter)