SAM3X-EK display example: initialize external SDRAM and use it for display bitmap.
authoraleph <aleph@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 10 Mar 2011 17:50:19 +0000 (17:50 +0000)
committeraleph <aleph@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 10 Mar 2011 17:50:19 +0000 (17:50 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4763 38d2e660-2303-0410-9eaa-f027e97ec537

boards/sam3x-ek/.spec
boards/sam3x-ek/examples/display/.spec
boards/sam3x-ek/examples/display/display.mk
boards/sam3x-ek/examples/display/main.c
boards/sam3x-ek/examples/display/project.bertos

index db0492e7a9d48ec98cddf38d902e50db251e2048..14d85c03ffc2fb6b06c5058b56ced61af8c3c047 100644 (file)
@@ -20,7 +20,7 @@ description = '''
 
        <tr>
                <td><b>Peripherals</b></td>
-               <td>timers, UART, LCD display</td>
+               <td>timers, UART, SDRAM, LCD display</td>
        </tr>
 </table>
 </p>
index ef4e0b2b2d0a943d6d4c20354fb1e37fe5756ee1..f18c5849ad6e3d6d2b3fe04021dcd3b7909398d9 100644 (file)
@@ -2,8 +2,8 @@ name = 'Display and keyboard handling'
 description="""
 <h2>Overview</h2>
 <p>
-This example application demonstrates the usage of display libraries, keyboard
-drivers and menu creation.
+This example application demonstrates the usage of LCD driver, SDRAM configuration,
+display libraries, keyboard drivers and menu creation.
 <\p>
 <p>
 Use the main menu to launch various demo programs; scroll down using the "left click"
index ad6062d66db34d87275574f777221b2d054be961..4cb1a03ea5f6d6e6fdf3e60da9ef62d89a80a217 100644 (file)
@@ -19,6 +19,7 @@ display_HW_PATH = boards/sam3x-ek
 
 # Files automatically generated by the wizard. DO NOT EDIT, USE display_USER_CSRC INSTEAD!
 display_WIZARD_CSRC = \
+       bertos/struct/heap.c \
        bertos/cpu/cortex-m3/hw/switch_ctx_cm3.c \
        bertos/mware/event.c \
        bertos/gfx/bitmap.c \
index 86d5123b7e8a69c021ad71862c4f24bb26a88799..ac7ad2f75a86e26c7881f23fbe8f7fa7faabea26 100644 (file)
@@ -30,7 +30,7 @@
  *
  * -->
  *
- * \brief Atmel SAM3X-EK simple demo
+ * \brief Atmel SAM3X-EK testcase
  *
  * \author Stefano Fedrigo <aleph@develer.com>
  */
 
 #include "hw/hw_led.h"
 #include "hw/hw_lcd.h"
+#include "hw/hw_sdram.h"
 
 #include <cfg/debug.h>
 #include <cpu/irq.h>
+#include <struct/heap.h>
 #include <drv/timer.h>
 #include <drv/kbd.h>
 #include <drv/lcd_hx8347.h>
@@ -71,8 +73,9 @@
        static PROC_DEFINE_STACK(led_stack, PROC_STACK_SIZE);
 #endif
 
+static struct Heap heap;
 static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)];
-static Bitmap lcd_bitmap;
+static Bitmap *lcd_bitmap;
 extern Font font_gohu;
 static int lcd_brightness = LCD_BACKLIGHT_MAX;
 static Process *hp_proc, *lp_proc, *led_proc;
@@ -208,14 +211,16 @@ static void res_process(void)
        {
                /* Show context switch (in clock cycles) */
                c = spinner[i % countof(spinner)];
-               text_xprintf(&lcd_bitmap, 3, 0, TEXT_CENTER | TEXT_FILL, "%c Context switch %c", c, c);
-               text_xprintf(&lcd_bitmap, 5, 0, TEXT_FILL, " %lu clock cycles", end - start);
+               text_xprintf(lcd_bitmap, 3, 0, TEXT_CENTER | TEXT_FILL, "%c Context switch %c", c, c);
+               text_xprintf(lcd_bitmap, 5, 0, TEXT_FILL, " %lu clock cycles", end - start);
                /* Show context switch (in usec) */
-               text_xprintf(&lcd_bitmap, 6, 0, TEXT_FILL,
+               text_xprintf(lcd_bitmap, 6, 0, TEXT_FILL,
                        " %lu.%lu usec",
                                ((end - start) * 1000000) / CPU_FREQ,
                                ((end - start) * (100000000 / CPU_FREQ)) % 100);
-               lcd_hx8347_blitBitmap(&lcd_bitmap);
+               text_xprintf(lcd_bitmap, 8, 0, TEXT_FILL,
+                       " Free heap memory: %u bytes", heap_freeSpace(&heap));
+               lcd_hx8347_blitBitmap(lcd_bitmap);
                timer_delay(5);
                if (kbd_peek() & KEY_MASK)
                        break;
@@ -225,7 +230,7 @@ static void res_process(void)
 static void context_switch_test(Bitmap *bm)
 {
        const Font *old_font = bm->font;
-       gfx_setFont(&lcd_bitmap, &font_gohu);
+       gfx_setFont(lcd_bitmap, &font_gohu);
 
        gfx_bitmapClear(bm);
        text_xprintf(bm, 0, 0, TEXT_FILL,
@@ -234,7 +239,7 @@ static void context_switch_test(Bitmap *bm)
 
        res_process();
 
-       gfx_setFont(&lcd_bitmap, old_font);
+       gfx_setFont(lcd_bitmap, old_font);
 }
 
 static void uptime(Bitmap *bm)
@@ -246,7 +251,7 @@ static void uptime(Bitmap *bm)
                ticks_t clock = ticks_to_ms(timer_clock_unlocked());
 
                /* Display uptime (in ticks) */
-               text_xprintf(&lcd_bitmap, 2, 0, TEXT_FILL | TEXT_CENTER,
+               text_xprintf(lcd_bitmap, 2, 0, TEXT_FILL | TEXT_CENTER,
                                "seconds: %lu", clock / 1000);
                lcd_hx8347_blitBitmap(bm);
                timer_delay(5);
@@ -305,34 +310,50 @@ static void NORETURN soft_reset(Bitmap * bm)
 
 static struct MenuItem main_items[] =
 {
-       { (const_iptr_t)"LED blinking", 0, (MenuHook)led_test, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Graphics demo", 0, (MenuHook)show_logo, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Bouncing logo", 0, (MenuHook)bouncing_logo, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Screen saver demo", 0, (MenuHook)screen_saver, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Scheduling test", 0, (MenuHook)context_switch_test, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Show uptime", 0, (MenuHook)uptime, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Display brightness", 0, (MenuHook)setBrightness, (iptr_t)&lcd_bitmap },
-       { (const_iptr_t)"Reboot", 0, (MenuHook)soft_reset, (iptr_t)&lcd_bitmap },
+       { (const_iptr_t)"LED blinking", 0, (MenuHook)led_test, NULL },
+       { (const_iptr_t)"Graphics demo", 0, (MenuHook)show_logo, NULL },
+       { (const_iptr_t)"Bouncing logo", 0, (MenuHook)bouncing_logo, NULL },
+       { (const_iptr_t)"Screen saver demo", 0, (MenuHook)screen_saver, NULL },
+       { (const_iptr_t)"Scheduling test", 0, (MenuHook)context_switch_test, NULL },
+       { (const_iptr_t)"Show uptime", 0, (MenuHook)uptime, NULL },
+       { (const_iptr_t)"Display brightness", 0, (MenuHook)setBrightness, NULL },
+       { (const_iptr_t)"Reboot", 0, (MenuHook)soft_reset, NULL },
        { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
 };
-static struct Menu main_menu = { main_items, "BeRTOS", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0, lcd_hx8347_blitBitmap };
+static struct Menu main_menu = { main_items, "BeRTOS", MF_STICKY | MF_SAVESEL, NULL, 0, lcd_hx8347_blitBitmap };
 
 
 int main(void)
 {
+       unsigned i;
+
        IRQ_ENABLE;
 
        kdbg_init();
        LED_INIT();
        timer_init();
        proc_init();
+       sdram_init();
+
+       heap_init(&heap, (void *)SDRAM_BASE, SDRAM_SIZE);
+       lcd_bitmap = heap_allocmem(&heap, RAST_SIZE(LCD_WIDTH, LCD_HEIGHT));
+       if (lcd_bitmap)
+               kprintf("Allocated memory for display raster, addr 0x%x\n", (unsigned)lcd_bitmap);
+       else
+       {
+               kprintf("Error allocating memory for LCD raster!\n");
+               return 0;
+       }
+       for (i = 0; main_items[i].label; i++)
+               main_items[i].userdata = lcd_bitmap;
+       main_menu.bitmap = lcd_bitmap;
 
        lcd_hx8347_init();
        lcd_setBacklight(lcd_brightness);
 
-       gfx_bitmapInit(&lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT);
-       gfx_setFont(&lcd_bitmap, &font_luBS14);
-       lcd_hx8347_blitBitmap(&lcd_bitmap);
+       gfx_bitmapInit(lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT);
+       gfx_setFont(lcd_bitmap, &font_luBS14);
+       lcd_hx8347_blitBitmap(lcd_bitmap);
 
        kbd_init();
 
index 89422d66fb754e976b5b1b66d46b2a30fef392df..304aa088cfe61f357a3179d742e089f865c4ef6c 100644 (file)
@@ -21,9 +21,9 @@ S'path'
 p10
 Varm-none-eabi-gcc
 p11
-ssS'PROJECT_SRC_PATH_FROM_MAKEFILE'
+ssS'PROJECT_HW_PATH_FROM_MAKEFILE'
 p12
-Vboards/sam3x-ek/examples/display
+Vboards/sam3x-ek
 p13
 sS'ENABLED_MODULES'
 p14
@@ -36,13 +36,13 @@ aS'menu'
 p18
 aS'signal'
 p19
-aS'debug'
-p20
 aS'kernel'
-p21
+p20
 aS'text_format'
-p22
+p21
 aS'sprintf'
+p22
+aS'debug'
 p23
 aS'timer'
 p24
@@ -52,28 +52,30 @@ aS'formatwr'
 p26
 aS'lcd_hx8347'
 p27
-asS'CPU_NAME'
+aS'heap'
 p28
-VSAM3X8
+asS'CPU_NAME'
 p29
-sS'PROJECT_HW_PATH'
+VSAM3X8
 p30
-S'../..'
+sS'PROJECT_HW_PATH'
 p31
-sS'PROJECT_SRC_PATH'
+S'../..'
 p32
-S'.'
+sS'PROJECT_SRC_PATH'
 p33
-sS'PRESET'
+S'.'
 p34
-I01
-sS'PROJECT_HW_PATH_FROM_MAKEFILE'
+sS'PRESET'
 p35
-Vboards/sam3x-ek
+I01
+sS'PROJECT_SRC_PATH_FROM_MAKEFILE'
 p36
-sS'OUTPUT'
+Vboards/sam3x-ek/examples/display
 p37
-(lp38
+sS'OUTPUT'
+p38
+(lp39
 S'codelite'
-p39
+p40
 as.
\ No newline at end of file