aboutsummaryrefslogtreecommitdiffstats
path: root/src/gos
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-11-27 20:39:28 +0100
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-11-27 20:39:28 +0100
commit5a99092b794373966e444296c57991631e712c70 (patch)
tree3e2853ab9730ece7398f508238ac2707e485b346 /src/gos
parenteaf0b19fb8428b9e2e47798294d6ba83a56d186e (diff)
parentf16ee702727a811288749a0722ddb138dd559fa8 (diff)
downloaduGFX-5a99092b794373966e444296c57991631e712c70.tar.gz
uGFX-5a99092b794373966e444296c57991631e712c70.tar.bz2
uGFX-5a99092b794373966e444296c57991631e712c70.zip
Merge branch 'master' of https://bitbucket.org/Tectu/ugfx
Diffstat (limited to 'src/gos')
-rw-r--r--src/gos/gos.h17
-rw-r--r--src/gos/gos_arduino.h2
-rw-r--r--src/gos/gos_options.h5
-rw-r--r--src/gos/gos_rules.h11
-rw-r--r--src/gos/gos_x_heap.c11
-rw-r--r--src/gos/gos_x_heap.h42
6 files changed, 55 insertions, 33 deletions
diff --git a/src/gos/gos.h b/src/gos/gos.h
index c3cdca50..1c4ef865 100644
--- a/src/gos/gos.h
+++ b/src/gos/gos.h
@@ -176,6 +176,23 @@
void gfxFree(void *ptr);
/**
+ * @brief Use gfxAlloc and gfxFree to implement malloc() and free()
+ *
+ * @notes Sometimes your application will include functions that
+ * want to internally use malloc() and free(). As the default
+ * implementations of these in your C library are almost
+ * invariably incorrect for an embedded platform, this option
+ * allows you to emulate those calls with gfxAlloc() and gfxFree().
+ * An example is the C library routine rand() which on many
+ * implementations internally uses malloc().
+ *
+ * @api
+ */
+ #ifndef GFX_EMULATE_MALLOC
+ #define GFX_EMULATE_MALLOC FALSE
+ #endif
+
+ /**
* @brief Yield the current thread
* @details Give up the rest of the current time slice for this thread in order to give other threads
* a chance to run.
diff --git a/src/gos/gos_arduino.h b/src/gos/gos_arduino.h
index 6a18aaec..3019d271 100644
--- a/src/gos/gos_arduino.h
+++ b/src/gos/gos_arduino.h
@@ -31,7 +31,7 @@
/* Type definitions */
/*===========================================================================*/
-typedef bool bool_t;
+typedef unsigned char bool_t;
#if 0
// Already defined by Arduino
diff --git a/src/gos/gos_options.h b/src/gos/gos_options.h
index 4b33f5ac..0c6fd7a7 100644
--- a/src/gos/gos_options.h
+++ b/src/gos/gos_options.h
@@ -181,9 +181,10 @@
#define GFX_FREERTOS_USE_TRACE FALSE
#endif
/**
- * @brief How much RAM should uGFX use for the heap
+ * @brief How much RAM should uGFX use for the heap when using its own internal heap allocator
* @details Defaults to 0.
- * @note Only used when the generic ugfx heap code is used (GFX_USE_OS_RAW32, GFX_USE_OS_ARDUINO, GFX_US_OS_KEIL, GFX_USE_OS_CMSIS)
+ * @note Only used when the internal ugfx heap allocator is used
+ * (GFX_USE_OS_RAW32, GFX_USE_OS_ARDUINO, GFX_US_OS_KEIL, GFX_USE_OS_CMSIS)
* @note If 0 then the standard C runtime malloc(), free() and realloc()
* are used.
* @note If it is non-zero then this is the number of bytes of RAM
diff --git a/src/gos/gos_rules.h b/src/gos/gos_rules.h
index b0184eb0..d2e64ff1 100644
--- a/src/gos/gos_rules.h
+++ b/src/gos/gos_rules.h
@@ -32,5 +32,16 @@
#error "GOS: GFX_FREERTOS_USE_TRACE is only available for the FreeRTOS port."
#endif
+#if GFX_EMULATE_MALLOC
+ #if GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX || GFX_USE_OS_ECOS || \
+ (GFX_OS_HEAP_SIZE == 0 && (GFX_USE_OS_RAW32 || GFX_USE_OS_ARDUINO || GFX_USE_OS_CMSIS || GFX_USE_OS_KEIL))
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GOS: Cannot emulate malloc as gfxAlloc() internally uses malloc on this platform"
+ #endif
+ #undef GFX_EMULATE_MALLOC
+ #define GFX_EMULATE_MALLOC FALSE
+ #endif
+#endif
+
#endif /* _GOS_RULES_H */
/** @} */
diff --git a/src/gos/gos_x_heap.c b/src/gos/gos_x_heap.c
index cd78f403..7e79d1c6 100644
--- a/src/gos/gos_x_heap.c
+++ b/src/gos/gos_x_heap.c
@@ -194,3 +194,14 @@
#endif
#endif /* GOS_NEED_X_HEAP */
+
+#if GFX_EMULATE_MALLOC
+ #include <stdlib.h>
+
+ void* malloc(size_t size) {
+ return gfxAlloc(size);
+ }
+ void free(void *ptr) {
+ gfxFree(ptr);
+ }
+#endif
diff --git a/src/gos/gos_x_heap.h b/src/gos/gos_x_heap.h
index 3612989c..0fbfc905 100644
--- a/src/gos/gos_x_heap.h
+++ b/src/gos/gos_x_heap.h
@@ -5,38 +5,10 @@
* http://ugfx.org/license.html
*/
-/**
- * The raw32 GOS implementation supports any 32 bit processor with or without an
- * underlying operating system. It uses cooperative multi-tasking. Be careful
- * when writing device drivers not to disturb the assumptions this creates by performing
- * call-backs to uGFX code unless you define the INTERRUPTS_OFF() and INTERRUPTS_ON() macros.
- * It still requires some C runtime library support...
- * enough startup to initialise the stack, interrupts, static data etc and call main().
- * setjmp() and longjmp() - for threading
- * memcpy() - for heap and threading
- * malloc(), realloc and free() - if GFX_OS_HEAP_SIZE == 0
- *
- * You must also define the following routines in your own code so that timing functions will work...
- * systemticks_t gfxSystemTicks(void);
- * systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
- */
#ifndef _GOS_X_HEAP_H
#define _GOS_X_HEAP_H
-#if GOS_NEED_X_HEAP
-
-
-/*===========================================================================*/
-/* Special Macros */
-/*===========================================================================*/
-
-/**
- * @brief Set the maximum size of the heap.
- * @note If set to 0 then the C runtime library malloc() and free() are used.
- */
-#ifndef GFX_OS_HEAP_SIZE
- #define GFX_OS_HEAP_SIZE 0
-#endif
+#if GOS_NEED_X_HEAP || defined(__DOXYGEN__)
/*===========================================================================*/
/* Type definitions */
@@ -46,7 +18,17 @@
extern "C" {
#endif
- #if GFX_OS_HEAP_SIZE != 0
+ #if GFX_OS_HEAP_SIZE != 0 || defined(__DOXYGEN__)
+ /**
+ * @brief Take a chunk of memory and add it to the available heap
+ * @note Memory added must obviously not already be on the heap.
+ * @note It is allowable to add multiple non-contiguous blocks of memory
+ * to the heap. If however it is contiguous with a previously added block
+ * it will get merged with the existing block in order to allow
+ * allocations that span the boundary.
+ * @pre GFX_OS_HEAP_SIZE != 0 and an operating system that uses the
+ * internal ugfx heap allocator rather than its own allocator.
+ */
void gfxAddHeapBlock(void *ptr, size_t sz);
#endif