haitao il y a 1 an
Parent
commit
7c576aabe9
100 fichiers modifiés avec 25604 ajouts et 715 suppressions
  1. 2 2
      app/CORE/startup_stm32f2xx.s
  2. BIN
      app/DOC/nandflash验证通过.docx
  3. 300 0
      app/HARDWARE/includes/cJSON.h
  4. 77 0
      app/HARDWARE/includes/delay.h
  5. 49 0
      app/HARDWARE/includes/led.h
  6. 28 0
      app/HARDWARE/includes/log.h
  7. 27 21
      app/HARDWARE/includes/usart.h
  8. 3156 0
      app/HARDWARE/sources/cJSON.c
  9. 266 0
      app/HARDWARE/sources/delay.c
  10. 82 0
      app/HARDWARE/sources/led.c
  11. 62 0
      app/HARDWARE/sources/log.c
  12. 68 76
      app/HARDWARE/sources/usart.c
  13. 35 0
      app/MDKProject/JLinkLog.txt
  14. 39 0
      app/MDKProject/JLinkSettings.ini
  15. 2485 132
      app/MDKProject/Listings/lora_gateway.map
  16. 650 0
      app/MDKProject/Listings/os_cpu_a.lst
  17. 25 25
      app/MDKProject/Listings/startup_stm32f2xx.lst
  18. 210 192
      app/MDKProject/lora_gateway.uvguix.16936
  19. 299 10
      app/MDKProject/lora_gateway.uvoptx
  20. 127 2
      app/MDKProject/lora_gateway.uvprojx
  21. BIN
      app/OBJ/at_cmd.crf
  22. 43 0
      app/OBJ/at_cmd.d
  23. BIN
      app/OBJ/cjson.crf
  24. 45 0
      app/OBJ/cjson.d
  25. BIN
      app/OBJ/delay.crf
  26. 44 0
      app/OBJ/delay.d
  27. BIN
      app/OBJ/demo_nand_fatfs.crf
  28. BIN
      app/OBJ/diskio.crf
  29. BIN
      app/OBJ/ebt3001.crf
  30. 37 0
      app/OBJ/ebt3001.d
  31. BIN
      app/OBJ/ff.crf
  32. BIN
      app/OBJ/led.crf
  33. 36 0
      app/OBJ/led.d
  34. BIN
      app/OBJ/log.crf
  35. 39 0
      app/OBJ/log.d
  36. BIN
      app/OBJ/lora_gateway.axf
  37. 3 21
      app/OBJ/lora_gateway.build_log.htm
  38. 1166 188
      app/OBJ/lora_gateway.htm
  39. 18 0
      app/OBJ/lora_gateway.lnp
  40. 318 46
      app/OBJ/lora_gateway_Target 1.dep
  41. BIN
      app/OBJ/main.crf
  42. 12 0
      app/OBJ/main.d
  43. BIN
      app/OBJ/nandflash.crf
  44. BIN
      app/OBJ/os_core.crf
  45. 4 0
      app/OBJ/os_core.d
  46. 1 0
      app/OBJ/os_cpu_a.d
  47. BIN
      app/OBJ/os_cpu_c.crf
  48. 4 0
      app/OBJ/os_cpu_c.d
  49. BIN
      app/OBJ/os_flag.crf
  50. 4 0
      app/OBJ/os_flag.d
  51. BIN
      app/OBJ/os_mbox.crf
  52. 4 0
      app/OBJ/os_mbox.d
  53. BIN
      app/OBJ/os_mem.crf
  54. 4 0
      app/OBJ/os_mem.d
  55. BIN
      app/OBJ/os_mutex.crf
  56. 4 0
      app/OBJ/os_mutex.d
  57. BIN
      app/OBJ/os_q.crf
  58. 4 0
      app/OBJ/os_q.d
  59. BIN
      app/OBJ/os_sem.crf
  60. 4 0
      app/OBJ/os_sem.d
  61. BIN
      app/OBJ/os_task.crf
  62. 4 0
      app/OBJ/os_task.d
  63. BIN
      app/OBJ/os_time.crf
  64. 4 0
      app/OBJ/os_time.d
  65. BIN
      app/OBJ/os_tmr.crf
  66. 4 0
      app/OBJ/os_tmr.d
  67. BIN
      app/OBJ/stm32f2xx_it.crf
  68. BIN
      app/OBJ/sx1276-board.crf
  69. 43 0
      app/OBJ/sx1276-board.d
  70. BIN
      app/OBJ/sx1276.crf
  71. 10 0
      app/OBJ/sx1276.d
  72. BIN
      app/OBJ/ucos_ii.crf
  73. 15 0
      app/OBJ/ucos_ii.d
  74. BIN
      app/OBJ/usart.crf
  75. 321 0
      app/SX1278/radio.h
  76. 396 0
      app/SX1278/sx1276-board.c
  77. 122 0
      app/SX1278/sx1276-board.h
  78. 1868 0
      app/SX1278/sx1276.c
  79. 396 0
      app/SX1278/sx1276.h
  80. 1128 0
      app/SX1278/sx1276Regs-Fsk.h
  81. 565 0
      app/SX1278/sx1276Regs-LoRa.h
  82. 109 0
      app/UCOS-II/CONFIG/app_cfg.h
  83. 91 0
      app/UCOS-II/CONFIG/includes.h
  84. 143 0
      app/UCOS-II/CONFIG/os_cfg.h
  85. 128 0
      app/UCOS-II/Ports/os_cpu.h
  86. 246 0
      app/UCOS-II/Ports/os_cpu_a.asm
  87. 401 0
      app/UCOS-II/Ports/os_cpu_c.c
  88. 312 0
      app/UCOS-II/Ports/os_dbg.c
  89. 314 0
      app/UCOS-II/Ports/os_dbg_r.c
  90. 2028 0
      app/UCOS-II/Source/os_core.c
  91. 1215 0
      app/UCOS-II/Source/os_flag.c
  92. 647 0
      app/UCOS-II/Source/os_mbox.c
  93. 456 0
      app/UCOS-II/Source/os_mem.c
  94. 735 0
      app/UCOS-II/Source/os_mutex.c
  95. 893 0
      app/UCOS-II/Source/os_q.c
  96. 629 0
      app/UCOS-II/Source/os_sem.c
  97. 1263 0
      app/UCOS-II/Source/os_task.c
  98. 264 0
      app/UCOS-II/Source/os_time.c
  99. 1073 0
      app/UCOS-II/Source/os_tmr.c
  100. 0 0
      app/UCOS-II/Source/ucos_ii.c

+ 2 - 2
app/CORE/startup_stm32f2xx.s

@@ -33,7 +33,7 @@
 ;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Stack_Size      EQU     0x00008000
+Stack_Size      EQU     0x00001000
 
                 AREA    STACK, NOINIT, READWRITE, ALIGN=3
 Stack_Mem       SPACE   Stack_Size
@@ -44,7 +44,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00008000
+Heap_Size       EQU     0x00001000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

BIN
app/DOC/nandflash验证通过.docx


+ 300 - 0
app/HARDWARE/includes/cJSON.h

@@ -0,0 +1,300 @@
+/*
+  Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+#ifndef cJSON__h
+#define cJSON__h
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
+#define __WINDOWS__
+#endif
+
+#ifdef __WINDOWS__
+
+/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention.  For windows you have 3 define options:
+
+CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
+CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
+CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
+
+For *nix builds that support visibility attribute, you can define similar behavior by
+
+setting default visibility to hidden by adding
+-fvisibility=hidden (for gcc)
+or
+-xldscope=hidden (for sun cc)
+to CFLAGS
+
+then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
+
+*/
+
+#define CJSON_CDECL __cdecl
+#define CJSON_STDCALL __stdcall
+
+/* export symbols by default, this is necessary for copy pasting the C and header file */
+#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
+#define CJSON_EXPORT_SYMBOLS
+#endif
+
+#if defined(CJSON_HIDE_SYMBOLS)
+#define CJSON_PUBLIC(type)   type CJSON_STDCALL
+#elif defined(CJSON_EXPORT_SYMBOLS)
+#define CJSON_PUBLIC(type)   __declspec(dllexport) type CJSON_STDCALL
+#elif defined(CJSON_IMPORT_SYMBOLS)
+#define CJSON_PUBLIC(type)   __declspec(dllimport) type CJSON_STDCALL
+#endif
+#else /* !__WINDOWS__ */
+#define CJSON_CDECL
+#define CJSON_STDCALL
+
+#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
+#define CJSON_PUBLIC(type)   __attribute__((visibility("default"))) type
+#else
+#define CJSON_PUBLIC(type) type
+#endif
+#endif
+
+/* project version */
+#define CJSON_VERSION_MAJOR 1
+#define CJSON_VERSION_MINOR 7
+#define CJSON_VERSION_PATCH 15
+
+#include <stddef.h>
+
+/* cJSON Types: */
+#define cJSON_Invalid (0)
+#define cJSON_False  (1 << 0)
+#define cJSON_True   (1 << 1)
+#define cJSON_NULL   (1 << 2)
+#define cJSON_Number (1 << 3)
+#define cJSON_String (1 << 4)
+#define cJSON_Array  (1 << 5)
+#define cJSON_Object (1 << 6)
+#define cJSON_Raw    (1 << 7) /* raw json */
+
+#define cJSON_IsReference 256
+#define cJSON_StringIsConst 512
+
+/* The cJSON structure: */
+typedef struct cJSON
+{
+    /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
+    struct cJSON *next;
+    struct cJSON *prev;
+    /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
+    struct cJSON *child;
+
+    /* The type of the item, as above. */
+    int type;
+
+    /* The item's string, if type==cJSON_String  and type == cJSON_Raw */
+    char *valuestring;
+    /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
+    int valueint;
+    /* The item's number, if type==cJSON_Number */
+    double valuedouble;
+
+    /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
+    char *string;
+} cJSON;
+
+typedef struct cJSON_Hooks
+{
+      /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
+      void *(CJSON_CDECL *malloc_fn)(size_t sz);
+      void (CJSON_CDECL *free_fn)(void *ptr);
+} cJSON_Hooks;
+
+typedef int cJSON_bool;
+
+/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
+ * This is to prevent stack overflows. */
+#ifndef CJSON_NESTING_LIMIT
+#define CJSON_NESTING_LIMIT 1000
+#endif
+
+/* returns the version of cJSON as a string */
+CJSON_PUBLIC(const char*) cJSON_Version(void);
+
+/* Supply malloc, realloc and free functions to cJSON */
+CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
+
+/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
+/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
+CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
+CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
+/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
+/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
+CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
+CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
+
+/* Render a cJSON entity to text for transfer/storage. */
+CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
+/* Render a cJSON entity to text for transfer/storage without any formatting. */
+CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
+/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
+CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
+/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
+/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
+CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
+/* Delete a cJSON entity and all subentities. */
+CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
+
+/* Returns the number of items in an array (or object). */
+CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
+/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
+CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
+/* Get item "string" from object. Case insensitive. */
+CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
+CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
+CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
+/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
+CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
+
+/* Check item type and return its value */
+CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
+CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
+
+/* These functions check the type of an item */
+CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
+
+/* These calls create a cJSON item of the appropriate type. */
+CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
+CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
+CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
+/* raw json */
+CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
+CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
+
+/* Create a string where valuestring references a string so
+ * it will not be freed by cJSON_Delete */
+CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
+/* Create an object/array that only references it's elements so
+ * they will not be freed by cJSON_Delete */
+CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
+CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
+
+/* These utilities create an Array of count items.
+ * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
+CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
+CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
+CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
+CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
+
+/* Append item to the specified array/object. */
+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
+/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
+ * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
+ * writing to `item->string` */
+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
+/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
+
+/* Remove/Detach items from Arrays/Objects. */
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
+CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
+CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
+CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
+
+/* Update array items. */
+CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
+
+/* Duplicate a cJSON item */
+CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
+/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
+ * need to be released. With recurse!=0, it will duplicate any children connected to the item.
+ * The item->next and ->prev pointers are always zero on return from Duplicate. */
+/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
+ * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
+CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
+
+/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
+ * The input pointer json cannot point to a read-only address area, such as a string constant, 
+ * but should point to a readable and writable address area. */
+CJSON_PUBLIC(void) cJSON_Minify(char *json);
+
+/* Helper functions for creating and adding items to an object at the same time.
+ * They return the added item or NULL on failure. */
+CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
+CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
+CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
+CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
+CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
+
+/* When assigning an integer value, it needs to be propagated to valuedouble too. */
+#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
+/* helper for the cJSON_SetNumberValue macro */
+CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
+#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
+/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
+CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
+
+/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
+#define cJSON_SetBoolValue(object, boolValue) ( \
+    (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
+    (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
+    cJSON_Invalid\
+)
+
+/* Macro for iterating over an array or object */
+#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
+
+/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
+CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
+CJSON_PUBLIC(void) cJSON_free(void *object);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 77 - 0
app/HARDWARE/includes/delay.h

@@ -0,0 +1,77 @@
+#ifndef __DELAY_H
+#define __DELAY_H
+#include "stm32f2xx.h"
+
+//////////////////////////////////////////////////////////////////////////////////	 
+//本程序只供学习使用,未经作者许可,不得用于其它任何用途
+//ALIENTEK STM32开发板
+//使用SysTick的普通计数模式对延迟进行管理(适合STM32F10x系列)
+//包括delay_us,delay_ms
+//正点原子@ALIENTEK
+//技术论坛:www.openedv.com
+//创建日期:2010/1/1
+//版本:V1.8
+//版权所有,盗版必究。
+//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
+//All rights reserved
+//********************************************************************************
+//V1.2修改说明
+//修正了中断中调用出现死循环的错误
+//防止延时不准确,采用do while结构!
+//V1.3修改说明
+//增加了对UCOSII延时的支持.
+//如果使用ucosII,delay_init会自动设置SYSTICK的值,使之与ucos的TICKS_PER_SEC对应.
+//delay_ms和delay_us也进行了针对ucos的改造.
+//delay_us可以在ucos下使用,而且准确度很高,更重要的是没有占用额外的定时器.
+//delay_ms在ucos下,可以当成OSTimeDly来用,在未启动ucos时,它采用delay_us实现,从而准确延时
+//可以用来初始化外设,在启动了ucos之后delay_ms根据延时的长短,选择OSTimeDly实现或者delay_us实现.
+//V1.4修改说明 20110929
+//修改了使用ucos,但是ucos未启动的时候,delay_ms中中断无法响应的bug.
+//V1.5修改说明 20120902
+//在delay_us加入ucos上锁,防止由于ucos打断delay_us的执行,可能导致的延时不准。
+//V1.6修改说明 20150109
+//在delay_ms加入OSLockNesting判断。
+//V1.7修改说明 20150319
+//修改OS支持方式,以支持任意OS(不限于UCOSII和UCOSIII,理论上任意OS都可以支持)
+//添加:delay_osrunning/delay_ostickspersec/delay_osintnesting三个宏定义
+//添加:delay_osschedlock/delay_osschedunlock/delay_ostimedly三个函数
+//V1.8修改说明 20150519
+//修正UCOSIII支持时的2个bug:
+//delay_tickspersec改为:delay_ostickspersec
+//delay_intnesting改为:delay_osintnesting
+////////////////////////////////////////////////////////////////////////////////// 
+	 
+void delay_init(void);
+void delay_ms(u16 nms);
+void delay_us(u32 nus);
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 49 - 0
app/HARDWARE/includes/led.h

@@ -0,0 +1,49 @@
+#ifndef __LED_H
+#define	__LED_H
+#include "stm32f2xx.h"
+//引脚定义
+/*******************************************************/
+
+#define LED_PIN                  GPIO_Pin_6                 
+#define LED_GPIO_PORT            GPIOF                      
+#define LED_GPIO_CLK             RCC_AHB1Periph_GPIOF
+
+#define NET_STATUS_LED_PIN                  GPIO_Pin_8                
+#define NET_STATUS_LED_GPIO_PORT            GPIOF                      
+#define NET_STATUS_LED_GPIO_CLK             RCC_AHB1Periph_GPIOF
+
+#define STATUS_LED_PIN                  GPIO_Pin_7                 
+#define STATUS_LED_GPIO_PORT            GPIOF                      
+#define STATUS_LED_GPIO_CLK             RCC_AHB1Periph_GPIOF
+
+/************************************************************/
+
+
+/** 控制LED灯亮灭的宏,
+	* LED低电平亮,设置ON=0,OFF=1
+	* 若LED高电平亮,把宏设置成ON=1 ,OFF=0 即可
+	*/
+#define ON  1
+#define OFF 0
+
+/* 带参宏,可以像内联函数一样使用 */
+#define LED(a)	if (a)	\
+					GPIO_SetBits(LED_GPIO_PORT,LED_PIN);\
+					else		\
+					GPIO_ResetBits(LED_GPIO_PORT,LED_PIN)
+#define NET_STATUS_LED(a)	if (a)	\
+					GPIO_SetBits(NET_STATUS_LED_GPIO_PORT,NET_STATUS_LED_PIN);\
+					else		\
+					GPIO_ResetBits(NET_STATUS_LED_GPIO_PORT,NET_STATUS_LED_PIN)
+					
+#define STATUS_LED(a)	if (a)	\
+					GPIO_SetBits(STATUS_LED_GPIO_PORT,STATUS_LED_PIN);\
+					else		\
+					GPIO_ResetBits(STATUS_LED_GPIO_PORT,STATUS_LED_PIN)
+
+
+void LED_GPIO_Config(void);
+void NET_STATUS_LED_Config(void);
+void STATUS_LED_Config(void);
+#endif
+					

+ 28 - 0
app/HARDWARE/includes/log.h

@@ -0,0 +1,28 @@
+/*
+ * log.h
+ *
+ *  Created on: Nov 7, 2022
+ *      Author: tangm
+ */
+
+#ifndef INC_LOG_H_
+#define INC_LOG_H_
+
+#include <stdarg.h>
+
+#define LOG_LEN_MAX 256
+
+typedef enum LOG_LEVEL_U
+{
+	LOG_NONE = 0,
+	LOG_INFO,
+	LOG_DEBUG,
+	LOG_WARN,
+	LOG_ERROR,
+	LOG_MAX,
+}logLevel_t;
+
+void LogPrint(logLevel_t logLevel, const char *func, const int line, char * fmt, ...);
+
+#define LOG_PRINT(logLevel, fmt, ...) LogPrint(logLevel, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
+#endif /* INC_LOG_H_ */

+ 27 - 21
app/HARDWARE/includes/usart.h

@@ -7,32 +7,32 @@
 
 //通讯网口引脚定义
 /*******************************************************/
-#define EBT_USART                             USART6
-#define EBT_USART_CLK                         RCC_APB2Periph_USART6
-#define EBT_USART_BAUDRATE                    9600  //串口波特率
+#define DEBUG_USART                             USART6
+#define DEBUG_USART_CLK                         RCC_APB2Periph_USART6
+#define DEBUG_USART_BAUDRATE                    115200  //串口波特率
 
-#define EBT_USART_RX_GPIO_PORT                GPIOC
-#define EBT_USART_RX_GPIO_CLK                 RCC_AHB1Periph_GPIOC
-#define EBT_USART_RX_PIN                      GPIO_Pin_7
-#define EBT_USART_RX_AF                       GPIO_AF_USART6
-#define EBT_USART_RX_SOURCE                   GPIO_PinSource7
+#define DEBUG_USART_RX_GPIO_PORT                GPIOC
+#define DEBUG_USART_RX_GPIO_CLK                 RCC_AHB1Periph_GPIOC
+#define DEBUG_USART_RX_PIN                      GPIO_Pin_7
+#define DEBUG_USART_RX_AF                       GPIO_AF_USART6
+#define DEBUG_USART_RX_SOURCE                   GPIO_PinSource7
 
-#define EBT_USART_TX_GPIO_PORT                GPIOC
-#define EBT_USART_TX_GPIO_CLK                 RCC_AHB1Periph_GPIOC
-#define EBT_USART_TX_PIN                      GPIO_Pin_6
-#define EBT_USART_TX_AF                       GPIO_AF_USART6
-#define EBT_USART_TX_SOURCE                   GPIO_PinSource6
+#define DEBUG_USART_TX_GPIO_PORT                GPIOC
+#define DEBUG_USART_TX_GPIO_CLK                 RCC_AHB1Periph_GPIOC
+#define DEBUG_USART_TX_PIN                      GPIO_Pin_6
+#define DEBUG_USART_TX_AF                       GPIO_AF_USART6
+#define DEBUG_USART_TX_SOURCE                   GPIO_PinSource6
 
-#define EBT_USART_IRQHandler                  USART6_IRQHandler
-#define EBT_USART_IRQ                 				USART6_IRQn
+#define DEBUG_USART_IRQHandler                  USART6_IRQHandler
+#define DEBUG_USART_IRQ                 				USART6_IRQn
 
 //通讯网口DMA
-#define EBT_USART_DR_BASE               (USART6_BASE+0x04)		//DR寄存器
-#define EBT_USART_DMA_CLK               RCC_AHB1Periph_DMA2	
-#define EBT_USART_DMA_CHANNEL           DMA_Channel_5
-#define EBT_USART_DMA_STREAM            DMA2_Stream1
+#define DEBUG_USART_DR_BASE               (USART6_BASE+0x04)		//DR寄存器
+#define DEBUG_USART_DMA_CLK               RCC_AHB1Periph_DMA2	
+#define DEBUG_USART_DMA_CHANNEL           DMA_Channel_5
+#define DEBUG_USART_DMA_STREAM            DMA2_Stream1
 
-#define SENDBUFF_SIZE                     5000				//dma空间大小
+#define BUFF_SIZE                     5000				//dma空间大小
 
 /************************************************************/
 //232引脚定义
@@ -83,5 +83,11 @@ void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
 void Usart_SendString( USART_TypeDef * pUSARTx, char *str);
 
 void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
-void NVIC_Configuration();
+void USART_DMA_Config(void);
+void DEBUG_USART_Config(void);
+
+
+extern uint8_t UART6_RX_BUF[BUFF_SIZE];
+extern uint8_t UART6_RX_STAT;
+extern uint32_t UART6_RX_NUM;
 #endif /* __USART1_H */

Fichier diff supprimé car celui-ci est trop grand
+ 3156 - 0
app/HARDWARE/sources/cJSON.c


+ 266 - 0
app/HARDWARE/sources/delay.c

@@ -0,0 +1,266 @@
+#include "delay.h"
+
+#define 	SYSTEM_SUPPORT_OS 1
+////////////////////////////////////////////////////////////////////////////////// 	 
+//如果需要使用OS,则包括下面的头文件即可.
+#if SYSTEM_SUPPORT_OS
+#include "includes.h"					//ucos 使用	  
+#endif
+//////////////////////////////////////////////////////////////////////////////////	 
+//本程序只供学习使用,未经作者许可,不得用于其它任何用途
+//ALIENTEK STM32开发板
+//使用SysTick的普通计数模式对延迟进行管理(适合STM32F10x系列)
+//包括delay_us,delay_ms
+//正点原子@ALIENTEK
+//技术论坛:www.openedv.com
+//创建日期:2010/1/1
+//版本:V1.8
+//版权所有,盗版必究。
+//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
+//All rights reserved
+//********************************************************************************
+//V1.2修改说明
+//修正了中断中调用出现死循环的错误
+//防止延时不准确,采用do while结构!
+//V1.3修改说明
+//增加了对UCOSII延时的支持.
+//如果使用ucosII,delay_init会自动设置SYSTICK的值,使之与ucos的TICKS_PER_SEC对应.
+//delay_ms和delay_us也进行了针对ucos的改造.
+//delay_us可以在ucos下使用,而且准确度很高,更重要的是没有占用额外的定时器.
+//delay_ms在ucos下,可以当成OSTimeDly来用,在未启动ucos时,它采用delay_us实现,从而准确延时
+//可以用来初始化外设,在启动了ucos之后delay_ms根据延时的长短,选择OSTimeDly实现或者delay_us实现.
+//V1.4修改说明 20110929
+//修改了使用ucos,但是ucos未启动的时候,delay_ms中中断无法响应的bug.
+//V1.5修改说明 20120902
+//在delay_us加入ucos上锁,防止由于ucos打断delay_us的执行,可能导致的延时不准。
+//V1.6修改说明 20150109
+//在delay_ms加入OSLockNesting判断。
+//V1.7修改说明 20150319
+//修改OS支持方式,以支持任意OS(不限于UCOSII和UCOSIII,理论上任意OS都可以支持)
+//添加:delay_osrunning/delay_ostickspersec/delay_osintnesting三个宏定义
+//添加:delay_osschedlock/delay_osschedunlock/delay_ostimedly三个函数
+//V1.8修改说明 20150519
+//修正UCOSIII支持时的2个bug:
+//delay_tickspersec改为:delay_ostickspersec
+//delay_intnesting改为:delay_osintnesting
+//////////////////////////////////////////////////////////////////////////////////  
+
+static u8  fac_us=0;							//us延时倍乘数			   
+static u16 fac_ms=0;							//ms延时倍乘数,在ucos下,代表每个节拍的ms数
+
+
+#if SYSTEM_SUPPORT_OS							//如果SYSTEM_SUPPORT_OS定义了,说明要支持OS了(不限于UCOS).
+//当delay_us/delay_ms需要支持OS的时候需要三个与OS相关的宏定义和函数来支持
+//首先是3个宏定义:
+//    delay_osrunning:用于表示OS当前是否正在运行,以决定是否可以使用相关函数
+//delay_ostickspersec:用于表示OS设定的时钟节拍,delay_init将根据这个参数来初始哈systick
+// delay_osintnesting:用于表示OS中断嵌套级别,因为中断里面不可以调度,delay_ms使用该参数来决定如何运行
+//然后是3个函数:
+//  delay_osschedlock:用于锁定OS任务调度,禁止调度
+//delay_osschedunlock:用于解锁OS任务调度,重新开启调度
+//    delay_ostimedly:用于OS延时,可以引起任务调度.
+
+//本例程仅作UCOSII和UCOSIII的支持,其他OS,请自行参考着移植
+//支持UCOSII
+#ifdef 	OS_CRITICAL_METHOD						//OS_CRITICAL_METHOD定义了,说明要支持UCOSII				
+#define delay_osrunning		OSRunning			//OS是否运行标记,0,不运行;1,在运行
+#define delay_ostickspersec	OS_TICKS_PER_SEC	//OS时钟节拍,即每秒调度次数
+#define delay_osintnesting 	OSIntNesting		//中断嵌套级别,即中断嵌套次数
+#endif
+
+//支持UCOSIII
+#ifdef 	CPU_CFG_CRITICAL_METHOD					//CPU_CFG_CRITICAL_METHOD定义了,说明要支持UCOSIII	
+#define delay_osrunning		OSRunning			//OS是否运行标记,0,不运行;1,在运行
+#define delay_ostickspersec	OSCfg_TickRate_Hz	//OS时钟节拍,即每秒调度次数
+#define delay_osintnesting 	OSIntNestingCtr		//中断嵌套级别,即中断嵌套次数
+#endif
+
+
+//us级延时时,关闭任务调度(防止打断us级延迟)
+void delay_osschedlock(void)
+{
+#ifdef CPU_CFG_CRITICAL_METHOD   				//使用UCOSIII
+	OS_ERR err; 
+	OSSchedLock(&err);							//UCOSIII的方式,禁止调度,防止打断us延时
+#else											//否则UCOSII
+	OSSchedLock();								//UCOSII的方式,禁止调度,防止打断us延时
+#endif
+}
+
+//us级延时时,恢复任务调度
+void delay_osschedunlock(void)
+{	
+#ifdef CPU_CFG_CRITICAL_METHOD   				//使用UCOSIII
+	OS_ERR err; 
+	OSSchedUnlock(&err);						//UCOSIII的方式,恢复调度
+#else											//否则UCOSII
+	OSSchedUnlock();							//UCOSII的方式,恢复调度
+#endif
+}
+
+//调用OS自带的延时函数延时
+//ticks:延时的节拍数
+void delay_ostimedly(u32 ticks)
+{
+#ifdef CPU_CFG_CRITICAL_METHOD
+	OS_ERR err; 
+	OSTimeDly(ticks,OS_OPT_TIME_PERIODIC,&err);	//UCOSIII延时采用周期模式
+#else
+	OSTimeDly(ticks);							//UCOSII延时
+#endif 
+}
+ 
+//systick中断服务函数,使用ucos时用到
+void SysTick_Handler(void)
+{	
+	if(delay_osrunning==1)						//OS开始跑了,才执行正常的调度处理
+	{
+		OSIntEnter();							//进入中断
+		OSTimeTick();       					//调用ucos的时钟服务程序               
+		OSIntExit();       	 					//触发任务切换软中断
+	}
+}
+#endif
+
+			   
+//初始化延迟函数
+//当使用OS的时候,此函数会初始化OS的时钟节拍
+//SYSTICK的时钟固定为HCLK时钟的1/8
+//SYSCLK:系统时钟
+void delay_init()
+{
+#if SYSTEM_SUPPORT_OS  							//如果需要支持OS.
+	u32 reload;
+#endif
+	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);	//选择外部时钟  HCLK/8
+	fac_us=SystemCoreClock/8000000;				//为系统时钟的1/8  
+#if SYSTEM_SUPPORT_OS  							//如果需要支持OS.
+	reload=SystemCoreClock/8000000;				//每秒钟的计数次数 单位为K	   
+	reload*=1000000/delay_ostickspersec;		//根据delay_ostickspersec设定溢出时间
+												//reload为24位寄存器,最大值:16777216,在72M下,约合1.86s左右	
+	fac_ms=1000/delay_ostickspersec;			//代表OS可以延时的最少单位	   
+
+	SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk;   	//开启SYSTICK中断
+	SysTick->LOAD=reload; 						//每1/delay_ostickspersec秒中断一次	
+	SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;   	//开启SYSTICK    
+
+#else
+	fac_ms=(u16)fac_us*1000;					//非OS下,代表每个ms需要的systick时钟数   
+#endif
+}								    
+
+#if SYSTEM_SUPPORT_OS  							//如果需要支持OS.
+//延时nus
+//nus为要延时的us数.		    								   
+void delay_us(u32 nus)
+{		
+	u32 ticks;
+	u32 told,tnow,tcnt=0;
+	u32 reload=SysTick->LOAD;					//LOAD的值	    	 
+	ticks=nus*fac_us; 							//需要的节拍数	  		 
+	tcnt=0;
+	delay_osschedlock();						//阻止OS调度,防止打断us延时
+	told=SysTick->VAL;        					//刚进入时的计数器值
+	while(1)
+	{
+		tnow=SysTick->VAL;	
+		if(tnow!=told)
+		{	    
+			if(tnow<told)tcnt+=told-tnow;		//这里注意一下SYSTICK是一个递减的计数器就可以了.
+			else tcnt+=reload-tnow+told;	    
+			told=tnow;
+			if(tcnt>=ticks)break;				//时间超过/等于要延迟的时间,则退出.
+		}  
+	};
+	delay_osschedunlock();						//恢复OS调度									    
+}
+//延时nms
+//nms:要延时的ms数
+void delay_ms(u16 nms)
+{	
+	if(delay_osrunning&&delay_osintnesting==0)	//如果OS已经在跑了,并且不是在中断里面(中断里面不能任务调度)	    
+	{		 
+		if(nms>=fac_ms)							//延时的时间大于OS的最少时间周期 
+		{ 
+   			delay_ostimedly(nms/fac_ms);		//OS延时
+		}
+		nms%=fac_ms;							//OS已经无法提供这么小的延时了,采用普通方式延时    
+	}
+	delay_us((u32)(nms*1000));					//普通方式延时  
+}
+#else //不用OS时
+//延时nus
+//nus为要延时的us数.		    								   
+void delay_us(u32 nus)
+{		
+	u32 temp;	    	 
+	SysTick->LOAD=nus*fac_us; 					//时间加载	  		 
+	SysTick->VAL=0x00;        					//清空计数器
+	SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;	//开始倒数	  
+	do
+	{
+		temp=SysTick->CTRL;
+	}while((temp&0x01)&&!(temp&(1<<16)));		//等待时间到达   
+	SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;	//关闭计数器
+	SysTick->VAL =0X00;      					 //清空计数器	 
+}
+//延时nms
+//注意nms的范围
+//SysTick->LOAD为24位寄存器,所以,最大延时为:
+//nms<=0xffffff*8*1000/SYSCLK
+//SYSCLK单位为Hz,nms单位为ms
+//对72M条件下,nms<=1864 
+void delay_ms(u16 nms)
+{	 		  	  
+	u32 temp;		   
+	SysTick->LOAD=(u32)nms*fac_ms;				//时间加载(SysTick->LOAD为24bit)
+	SysTick->VAL =0x00;							//清空计数器
+	SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;	//开始倒数  
+	do
+	{
+		temp=SysTick->CTRL;
+	}while((temp&0x01)&&!(temp&(1<<16)));		//等待时间到达   
+	SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;	//关闭计数器
+	SysTick->VAL =0X00;       					//清空计数器	  	    
+} 
+#endif 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 82 - 0
app/HARDWARE/sources/led.c

@@ -0,0 +1,82 @@
+#include "led.h"
+
+void LED_GPIO_Config(void)
+{		
+		/*定义一个GPIO_InitTypeDef类型的结构体*/
+		GPIO_InitTypeDef GPIO_InitStructure;
+
+		/*开启LED相关的GPIO外设时钟*/
+		RCC_AHB1PeriphClockCmd ( LED_GPIO_CLK, ENABLE); 
+
+		/*选择要控制的GPIO引脚*/															   
+		GPIO_InitStructure.GPIO_Pin = LED_PIN;	
+
+		/*设置引脚模式为输出模式*/
+		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   
+    
+    /*设置引脚的输出类型为推挽输出*/
+    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+    
+    /*设置引脚为上拉模式*/
+    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+
+		/*设置引脚速率为2MHz */   
+		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
+
+		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
+		GPIO_Init(LED_GPIO_PORT, &GPIO_InitStructure);	
+}
+
+void NET_STATUS_LED_Config(void)
+{
+			/*定义一个GPIO_InitTypeDef类型的结构体*/
+		GPIO_InitTypeDef GPIO_InitStructure;
+
+		/*开启NET_STATUS_LED相关的GPIO外设时钟*/
+		RCC_AHB1PeriphClockCmd ( NET_STATUS_LED_GPIO_CLK, ENABLE); 
+
+		/*选择要控制的GPIO引脚*/															   
+		GPIO_InitStructure.GPIO_Pin = NET_STATUS_LED_PIN;	
+
+		/*设置引脚模式为输出模式*/
+		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   
+    
+    /*设置引脚的输出类型为推挽输出*/
+    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+    
+    /*设置引脚为上拉模式*/
+    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+
+		/*设置引脚速率为2MHz */   
+		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
+
+		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
+		GPIO_Init(NET_STATUS_LED_GPIO_PORT, &GPIO_InitStructure);	
+}
+
+void STATUS_LED_Config(void)
+{
+				/*定义一个GPIO_InitTypeDef类型的结构体*/
+		GPIO_InitTypeDef GPIO_InitStructure;
+
+		/*开启STATUS_LED相关的GPIO外设时钟*/
+		RCC_AHB1PeriphClockCmd ( STATUS_LED_GPIO_CLK, ENABLE); 
+
+		/*选择要控制的GPIO引脚*/															   
+		GPIO_InitStructure.GPIO_Pin = STATUS_LED_PIN;	
+
+		/*设置引脚模式为输出模式*/
+		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   
+    
+    /*设置引脚的输出类型为推挽输出*/
+    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+    
+    /*设置引脚为上拉模式*/
+    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+
+		/*设置引脚速率为2MHz */   
+		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
+
+		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
+		GPIO_Init(STATUS_LED_GPIO_PORT, &GPIO_InitStructure);	
+}

+ 62 - 0
app/HARDWARE/sources/log.c

@@ -0,0 +1,62 @@
+/*
+ * log.c
+ *
+ *  Created on: Nov 7, 2022
+ *      Author: tangm
+ */
+#include "log.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include "usart.h"
+///重定向c库函数printf到串口,重定向后可使用printf函数
+int fputc(int ch, FILE *f)
+{
+		/* 发送一个字节数据到串口 */
+		USART_SendData(USART_232, (uint8_t) ch);
+		
+		/* 等待发送完毕 */
+		while (USART_GetFlagStatus(USART_232, USART_FLAG_TXE) == RESET);		
+	
+		return (ch);
+}
+
+///重定向c库函数scanf到串口,重写向后可使用scanf、getchar等函数
+int fgetc(FILE *f)
+{
+		/* 等待串口输入数据 */
+		while (USART_GetFlagStatus(USART_232, USART_FLAG_RXNE) == RESET);
+
+		return (int)USART_ReceiveData(USART_232);
+}
+
+void LogPrint(logLevel_t logLevel, const char *func, const int line, char * fmt, ...)
+{
+	va_list args;
+	va_start(args, fmt);
+	char buf[LOG_LEN_MAX];
+	vsnprintf(buf, sizeof(buf), fmt, args);
+	va_end(args);
+	switch (logLevel)
+	{
+#ifdef _LOG_INFO
+		case LOG_INFO:
+			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "INFO", func, line, buf);
+			break;
+#endif
+#ifdef _LOG_DEBUG
+		case LOG_DEBUG:
+			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "DEBUG", func, line, buf);
+			break;
+#endif
+#ifdef _LOG_WARN
+		case LOG_WARN:
+			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "WARN", func, line, buf);
+			break;
+#endif
+		case LOG_ERROR:
+			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "ERROR", func, line, buf);
+			break;
+		default:
+			break;
+	}
+}

+ 68 - 76
app/HARDWARE/sources/usart.c

@@ -1,20 +1,8 @@
 #include "usart.h"
 
-uint8_t SendBuff[SENDBUFF_SIZE];
-
- /**
-  * @brief  配置嵌套向量中断控制器NVIC分组
-  * @param  无
-  * @retval 无
-  */
-static void NVIC_Configuration(void)
-{
-  NVIC_InitTypeDef NVIC_InitStructure;
-  
-  /* 嵌套向量中断控制器组选择 */
-  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-  
-}
+uint8_t UART6_RX_BUF[BUFF_SIZE];
+uint8_t UART6_RX_STAT=0;
+uint32_t UART6_RX_NUM = 0;	
 
 
  /**
@@ -22,40 +10,74 @@ static void NVIC_Configuration(void)
   * @param  无
   * @retval 无
   */
-void EBT_USART_Config(void)
+void DEBUG_USART_Config(void)
 {
   USART_InitTypeDef USART_InitStruct;
   GPIO_InitTypeDef GPIO_InitStruct;
 
   // Enable USART6 clock
-  RCC_APB2PeriphClockCmd(EBT_USART_CLK, ENABLE);
+  RCC_APB2PeriphClockCmd(DEBUG_USART_CLK, ENABLE);
 
   // Enable GPIOC clock
-  RCC_AHB1PeriphClockCmd(EBT_USART_RX_GPIO_CLK, ENABLE);
+  RCC_AHB1PeriphClockCmd(DEBUG_USART_RX_GPIO_CLK, ENABLE);
 
   // Configure USART6 pins
-  GPIO_InitStruct.GPIO_Pin = EBT_USART_RX_PIN | EBT_USART_TX_PIN;  // USART6_TX (PC6) and USART6_RX (PC7)
+  GPIO_InitStruct.GPIO_Pin = DEBUG_USART_RX_PIN | DEBUG_USART_TX_PIN;  // USART6_TX (PC6) and USART6_RX (PC7)
   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
   GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
-  GPIO_Init(GPIOC, &GPIO_InitStruct);
+  GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct);
 
   // Connect USART6 pins to AF8
-  GPIO_PinAFConfig(EBT_USART_RX_GPIO_PORT, EBT_USART_RX_SOURCE, EBT_USART_RX_AF);
-  GPIO_PinAFConfig(EBT_USART_TX_GPIO_PORT, EBT_USART_TX_SOURCE, EBT_USART_TX_AF);
+  GPIO_PinAFConfig(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_SOURCE, DEBUG_USART_RX_AF);
+  GPIO_PinAFConfig(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_SOURCE, DEBUG_USART_TX_AF);
 
   // Configure USART6
-  USART_InitStruct.USART_BaudRate = EBT_USART_BAUDRATE;
+  USART_InitStruct.USART_BaudRate = DEBUG_USART_BAUDRATE;
   USART_InitStruct.USART_WordLength = USART_WordLength_8b;
   USART_InitStruct.USART_StopBits = USART_StopBits_1;
   USART_InitStruct.USART_Parity = USART_Parity_No;
   USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
   USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
-  USART_Init(EBT_USART, &USART_InitStruct);
+  USART_Init(DEBUG_USART, &USART_InitStruct);
+	
 
+	NVIC_InitTypeDef NVIC_InitStructure;
+	NVIC_InitStructure.NVIC_IRQChannel 					 = DEBUG_USART_IRQ;      //IRQ通道
+	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;          		 //主优先级
+	NVIC_InitStructure.NVIC_IRQChannelSubPriority		 = 1;                //从优先级
+	NVIC_InitStructure.NVIC_IRQChannelCmd				 = ENABLE;           //使能通道
+	NVIC_Init(&NVIC_InitStructure);
+	
   // Enable USART6
-  USART_Cmd(EBT_USART, ENABLE);
+	USART_ITConfig(DEBUG_USART, USART_IT_IDLE, ENABLE); //开启空闲中断
+	DMA_Cmd(DEBUG_USART_DMA_STREAM, ENABLE);						//使能DMA接收
+  USART_Cmd(DEBUG_USART, ENABLE);
+	USART_ClearFlag(DEBUG_USART, USART_FLAG_TC);
+	
+
+}
+
+void DEBUG_USART_IRQHandler(void)
+{
+	uint16_t clear;
+	if(USART_GetITStatus(DEBUG_USART,USART_IT_IDLE)!=RESET)
+	{
+		//清除空闲中断
+		clear=USART6->SR;
+		clear=USART6->DR;
+		//关闭DMA
+		DMA_Cmd(DEBUG_USART_DMA_STREAM,DISABLE);
+		UART6_RX_NUM=BUFF_SIZE-DMA_GetCurrDataCounter(DEBUG_USART_DMA_STREAM);
+		//清除DMA中断
+		DMA_ClearFlag(DEBUG_USART_DMA_STREAM,DMA_IT_TCIF1);
+		DMA_Cmd(DEBUG_USART_DMA_STREAM, ENABLE);
+		//接收状态置位
+		UART6_RX_STAT=1;
+		
+	}
+	
 }
 
 /**
@@ -65,26 +87,21 @@ void EBT_USART_Config(void)
   */
 void USART_DMA_Config(void)
 {
+	// 使能串口和DMA时钟
+  RCC_APB2PeriphClockCmd(DEBUG_USART_CLK, ENABLE);
+  RCC_AHB1PeriphClockCmd(DEBUG_USART_DMA_CLK, ENABLE);
+	
   DMA_InitTypeDef DMA_InitStructure;
-
-  /*开启DMA时钟*/
-  RCC_AHB1PeriphClockCmd(EBT_USART_DMA_CLK, ENABLE);
   
-  /* 复位初始化DMA数据流 */
-  DMA_DeInit(EBT_USART_DMA_STREAM);
-
-  /* 确保DMA数据流复位完成 */
-  while (DMA_GetCmdStatus(EBT_USART_DMA_STREAM) != DISABLE)  {
-  }
-  DMA_InitStructure.DMA_Channel = EBT_USART_DMA_CHANNEL;  
+  DMA_InitStructure.DMA_Channel = DEBUG_USART_DMA_CHANNEL;  
   /*设置DMA源:串口数据寄存器地址*/
-  DMA_InitStructure.DMA_PeripheralBaseAddr = EBT_USART_DR_BASE;	 
+  DMA_InitStructure.DMA_PeripheralBaseAddr = DEBUG_USART_DR_BASE;	 
   /*内存地址(要传输的变量的指针)*/
-  DMA_InitStructure.DMA_Memory0BaseAddr = (u32)SendBuff;
-  /*方向:从内存到外设*/		
+  DMA_InitStructure.DMA_Memory0BaseAddr = (u32)UART6_RX_BUF;
+  /*方向:从外设到内存*/		
   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;	
   /*传输大小DMA_BufferSize=SENDBUFF_SIZE*/	
-  DMA_InitStructure.DMA_BufferSize = SENDBUFF_SIZE;
+  DMA_InitStructure.DMA_BufferSize = BUFF_SIZE;
   /*外设地址不增*/	    
   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 
   /*内存地址自增*/
@@ -94,7 +111,7 @@ void USART_DMA_Config(void)
   /*内存数据单位 8bit*/
   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;	
   /*DMA模式:不断循环*/
-  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;	 
+  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;	 
   /*优先级:中*/	
   DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;      
   /*禁用FIFO*/
@@ -105,31 +122,25 @@ void USART_DMA_Config(void)
   /*外设突发传输 1个节拍*/
   DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;    
   /*配置DMA2的数据流*/		   
-  DMA_Init(EBT_USART_DMA_STREAM, &DMA_InitStructure);
-  //配置DMA中断
-	DMA_ITConfig(EBT_USART_DMA_STREAM, DMA_IT_TC, ENABLE);
+  DMA_Init(DEBUG_USART_DMA_STREAM, &DMA_InitStructure);
+	USART_DMACmd(DEBUG_USART,USART_DMAReq_Rx,ENABLE);
+	DMA_ITConfig(DEBUG_USART_DMA_STREAM,DMA_IT_TC,ENABLE);
 	NVIC_InitTypeDef NVIC_InitStructure;
-  NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
-  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
-  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
-  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
-  NVIC_Init(&NVIC_InitStructure);
-	
+	NVIC_InitStructure.NVIC_IRQChannel                   = DMA2_Stream5_IRQn ;//串口1发送中断通道
+	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;                 //抢占优先级
+	NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 2;		          //子优先级
+	NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;			  //IRQ通道使能
+	NVIC_Init(&NVIC_InitStructure);
 	
-  /*使能DMA*/
-  DMA_Cmd(EBT_USART_DMA_STREAM, ENABLE);
-  
-  /* 等待DMA数据流有效*/
-  while(DMA_GetCmdStatus(EBT_USART_DMA_STREAM) != ENABLE)
-  {
-  }   
 }
-void DMA2_Stream1_IRQHandler() {
+
+void DMA2_Stream5_IRQHandler() {
     if (DMA_GetITStatus(DMA2_Stream1, DMA_IT_TCIF1)) 
 		{
         DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1);
     }
 }
+
 /*
 	485串口在未配置情况下,初始化的参数
 */
@@ -286,24 +297,5 @@ void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch)
 	while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);	
 }
 
-///重定向c库函数printf到串口,重定向后可使用printf函数
-int fputc(int ch, FILE *f)
-{
-		/* 发送一个字节数据到串口 */
-		USART_SendData(USART_232, (uint8_t) ch);
-		
-		/* 等待发送完毕 */
-		while (USART_GetFlagStatus(USART_232, USART_FLAG_TXE) == RESET);		
-	
-		return (ch);
-}
-
-///重定向c库函数scanf到串口,重写向后可使用scanf、getchar等函数
-int fgetc(FILE *f)
-{
-		/* 等待串口输入数据 */
-		while (USART_GetFlagStatus(USART_232, USART_FLAG_RXNE) == RESET);
 
-		return (int)USART_ReceiveData(USART_232);
-}
 /*********************************************END OF FILE**********************/

+ 35 - 0
app/MDKProject/JLinkLog.txt

@@ -0,0 +1,35 @@
+T3164 6314:296 SEGGER J-Link V6.46 Log File (0000ms, 34349ms total)
+T3164 6314:296 DLL Compiled: May 23 2019 17:49:56 (0000ms, 34349ms total)
+T3164 6314:296 Logging started @ 2023-07-03 16:36 (0000ms, 34349ms total)
+T3164 6314:296 JLINK_SetWarnOutHandler(...) (0000ms, 34349ms total)
+T3164 6314:296 JLINK_OpenEx(...)
+Firmware: J-Link V9 compiled May  7 2021 16:26:12
+Hardware: V9.40
+S/N: 69407005
+Feature(s): RDI, GDB, FlashDL, FlashBP, JFlash
+TELNET listener socket opened on port 19021WEBSRV 
+Starting webserver (0036ms, 34385ms total)
+T3164 6314:296 WEBSRV Webserver running on local port 19080 (0036ms, 34385ms total)
+T3164 6314:296   returns O.K. (0036ms, 34385ms total)
+T3164 6314:333 JLINK_GetEmuCaps()  returns 0xB9FF7BBF (0000ms, 34385ms total)
+T3164 6314:333 JLINK_TIF_GetAvailable(...) (0001ms, 34386ms total)
+T3164 6314:334 JLINK_SetErrorOutHandler(...) (0000ms, 34386ms total)
+T3164 6314:334 JLINK_ExecCommand("ProjectFile = "D:\Project\Lora_gateway_sx1278\app\MDKProject\JLinkSettings.ini"", ...).   returns 0x00 (0001ms, 34387ms total)
+T3164 6314:335 JLINK_ExecCommand("Device = STM32F207ZGTx", ...). Device "STM32F207ZG" selected.  returns 0x00 (0001ms, 34388ms total)
+T3164 6314:336 JLINK_ExecCommand("DisableConnectionTimeout", ...).   returns 0x01 (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetHardwareVersion()  returns 0x16F30 (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetDLLVersion()  returns 64600 (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetFirmwareString(...) (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetDLLVersion()  returns 64600 (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetCompileDateTime() (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetFirmwareString(...) (0000ms, 34388ms total)
+T3164 6314:336 JLINK_GetHardwareVersion()  returns 0x16F30 (0000ms, 34388ms total)
+T3164 6314:336 JLINK_TIF_Select(JLINKARM_TIF_SWD)  returns 0x00 (0002ms, 34390ms total)
+T3164 6314:338 JLINK_SetSpeed(500) (0000ms, 34390ms total)
+T3164 6314:338 JLINK_GetId() >0x10B TIF> >0x10F TIF> >0x10B TIF> >0x10F TIF>STM32 (connect): Can not attach to CPU. Trying connect under reset. >0x10B TIF> >0x10F TIF> >0x10B TIF> >0x10F TIF>
+  ***** Error: STM32: Connecting to CPU via connect under reset failed. >0x10B TIF> >0x10F TIF> >0x10B TIF> >0x10F TIF>STM32 (connect): Can not attach to CPU. Trying connect under reset. >0x10B TIF> >0x10F TIF> >0x10B TIF> >0x10F TIF>
+  ***** Error: STM32: Connecting to CPU via connect under reset failed.
+  returns 0x00000000 (0711ms, 35101ms total)
+T3164 6316:406 JLINK_Close() (0010ms, 35111ms total)
+T3164 6316:406  (0010ms, 35111ms total)
+T3164 6316:406 Closed (0010ms, 35111ms total)

+ 39 - 0
app/MDKProject/JLinkSettings.ini

@@ -0,0 +1,39 @@
+[BREAKPOINTS]
+ForceImpTypeAny = 0
+ShowInfoWin = 1
+EnableFlashBP = 2
+BPDuringExecution = 0
+[CFI]
+CFISize = 0x00
+CFIAddr = 0x00
+[CPU]
+MonModeVTableAddr = 0xFFFFFFFF
+MonModeDebug = 0
+MaxNumAPs = 0
+LowPowerHandlingMode = 0
+OverrideMemMap = 0
+AllowSimulation = 1
+ScriptFile=""
+[FLASH]
+CacheExcludeSize = 0x00
+CacheExcludeAddr = 0x00
+MinNumBytesFlashDL = 0
+SkipProgOnCRCMatch = 1
+VerifyDownload = 1
+AllowCaching = 1
+EnableFlashDL = 2
+Override = 0
+Device="ARM7"
+[GENERAL]
+WorkRAMSize = 0x00
+WorkRAMAddr = 0x00
+RAMUsageLimit = 0x00
+[SWO]
+SWOLogFile=""
+[MEM]
+RdOverrideOrMask = 0x00
+RdOverrideAndMask = 0xFFFFFFFF
+RdOverrideAddr = 0xFFFFFFFF
+WrOverrideOrMask = 0x00
+WrOverrideAndMask = 0xFFFFFFFF
+WrOverrideAddr = 0xFFFFFFFF

Fichier diff supprimé car celui-ci est trop grand
+ 2485 - 132
app/MDKProject/Listings/lora_gateway.map


+ 650 - 0
app/MDKProject/Listings/os_cpu_a.lst

@@ -0,0 +1,650 @@
+
+
+
+ARM Macro Assembler    Page 1 
+
+
+    1 00000000         ;*******************************************************
+                       *************************************************
+    2 00000000         ;                                               uC/OS-II
+                       
+    3 00000000         ;                                         The Real-Time 
+                       Kernel
+    4 00000000         ;
+    5 00000000         ;                               (c) Copyright 1992-2006,
+                        Micrium, Weston, FL
+    6 00000000         ;                                          All Rights Re
+                       served
+    7 00000000         ;
+    8 00000000         ;                                           ARM Cortex-M
+                       3 Port
+    9 00000000         ;
+   10 00000000         ; File      : OS_CPU_A.ASM
+   11 00000000         ; Version   : V2.89
+   12 00000000         ; By        : Jean J. Labrosse
+   13 00000000         ;             Brian Nagel
+   14 00000000         ;
+   15 00000000         ; For       : ARMv7M Cortex-M3
+   16 00000000         ; Mode      : Thumb2
+   17 00000000         ; Toolchain : RealView Development Suite
+   18 00000000         ;             RealView Microcontroller Development Kit (
+                       MDK)
+   19 00000000         ;             ARM Developer Suite (ADS)
+   20 00000000         ;             Keil uVision
+   21 00000000         ;*******************************************************
+                       *************************************************
+   22 00000000         
+   23 00000000         ;*******************************************************
+                       *************************************************
+   24 00000000         ;                                           PUBLIC FUNCT
+                       IONS
+   25 00000000         ;*******************************************************
+                       *************************************************
+   26 00000000         
+   27 00000000                 EXTERN           OSRunning   ; External referenc
+                                                            es
+   28 00000000                 EXTERN           OSPrioCur
+   29 00000000                 EXTERN           OSPrioHighRdy
+   30 00000000                 EXTERN           OSTCBCur
+   31 00000000                 EXTERN           OSTCBHighRdy
+   32 00000000                 EXTERN           OSIntExit
+   33 00000000                 EXTERN           OSTaskSwHook
+   34 00000000                 EXTERN           OS_CPU_ExceptStkBase
+   35 00000000         
+   36 00000000         
+   37 00000000                 EXPORT           OS_CPU_SR_Save ; Functions decl
+                                                            ared in this file
+   38 00000000                 EXPORT           OS_CPU_SR_Restore
+   39 00000000                 EXPORT           OSStartHighRdy
+   40 00000000                 EXPORT           OSCtxSw
+   41 00000000                 EXPORT           OSIntCtxSw
+   42 00000000                 EXPORT           PendSV_Handler
+   43 00000000         
+   44 00000000         ;*******************************************************
+                       *************************************************
+   45 00000000         ;                                                EQUATES
+
+
+
+ARM Macro Assembler    Page 2 
+
+
+                       
+   46 00000000         ;*******************************************************
+                       *************************************************
+   47 00000000         
+   48 00000000 E000ED04 
+                       NVIC_INT_CTRL
+                               EQU              0xE000ED04  ; Interrupt control
+                                                             state register.
+   49 00000000 E000ED22 
+                       NVIC_SYSPRI14
+                               EQU              0xE000ED22  ; System priority r
+                                                            egister (priority 1
+                                                            4).
+   50 00000000 000000FF 
+                       NVIC_PENDSV_PRI
+                               EQU              0xFF        ; PendSV priority v
+                                                            alue (lowest).
+   51 00000000 10000000 
+                       NVIC_PENDSVSET
+                               EQU              0x10000000  ; Value to trigger 
+                                                            PendSV exception.
+   52 00000000         
+   53 00000000         ;*******************************************************
+                       *************************************************
+   54 00000000         ;                                      CODE GENERATION D
+                       IRECTIVES
+   55 00000000         ;*******************************************************
+                       *************************************************
+   56 00000000         
+   57 00000000                 AREA             |.text|, CODE, READONLY, ALIGN=
+2
+   58 00000000                 THUMB
+   59 00000000                 REQUIRE8
+   60 00000000                 PRESERVE8
+   61 00000000         
+   62 00000000         ;*******************************************************
+                       *************************************************
+   63 00000000         ;                                   CRITICAL SECTION MET
+                       HOD 3 FUNCTIONS
+   64 00000000         ;
+   65 00000000         ; Description: Disable/Enable interrupts by preserving t
+                       he state of interrupts.  Generally speaking you
+   66 00000000         ;              would store the state of the interrupt di
+                       sable flag in the local variable 'cpu_sr' and then
+   67 00000000         ;              disable interrupts.  'cpu_sr' is allocate
+                       d in all of uC/OS-II's functions that need to
+   68 00000000         ;              disable interrupts.  You would restore th
+                       e interrupt disable state by copying back 'cpu_sr'
+   69 00000000         ;              into the CPU's status register.
+   70 00000000         ;
+   71 00000000         ; Prototypes :     OS_CPU_SR  OS_CPU_SR_Save(void);
+   72 00000000         ;                  void       OS_CPU_SR_Restore(OS_CPU_S
+                       R cpu_sr);
+   73 00000000         ;
+   74 00000000         ;
+   75 00000000         ; Note(s)    : 1) These functions are used in general li
+                       ke this:
+   76 00000000         ;
+   77 00000000         ;                 void Task (void *p_arg)
+
+
+
+ARM Macro Assembler    Page 3 
+
+
+   78 00000000         ;                 {
+   79 00000000         ;                 #if OS_CRITICAL_METHOD == 3          /
+                       * Allocate storage for CPU status register */
+   80 00000000         ;                     OS_CPU_SR  cpu_sr;
+   81 00000000         ;                 #endif
+   82 00000000         ;
+   83 00000000         ;                          :
+   84 00000000         ;                          :
+   85 00000000         ;                     OS_ENTER_CRITICAL();             /
+                       * cpu_sr = OS_CPU_SaveSR();                */
+   86 00000000         ;                          :
+   87 00000000         ;                          :
+   88 00000000         ;                     OS_EXIT_CRITICAL();              /
+                       * OS_CPU_RestoreSR(cpu_sr);                */
+   89 00000000         ;                          :
+   90 00000000         ;                          :
+   91 00000000         ;                 }
+   92 00000000         ;*******************************************************
+                       *************************************************
+   93 00000000         
+   94 00000000         OS_CPU_SR_Save
+   95 00000000 F3EF 8010       MRS              R0, PRIMASK ; Set prio int mask
+                                                             to mask all (excep
+                                                            t faults)
+   96 00000004 B672            CPSID            I
+   97 00000006 4770            BX               LR
+   98 00000008         
+   99 00000008         OS_CPU_SR_Restore
+  100 00000008 F380 8810       MSR              PRIMASK, R0
+  101 0000000C 4770            BX               LR
+  102 0000000E         
+  103 0000000E         ;*******************************************************
+                       *************************************************
+  104 0000000E         ;                                          START MULTITA
+                       SKING
+  105 0000000E         ;                                       void OSStartHigh
+                       Rdy(void)
+  106 0000000E         ;
+  107 0000000E         ; Note(s) : 1) This function triggers a PendSV exception
+                        (essentially, causes a context switch) to cause
+  108 0000000E         ;              the first task to start.
+  109 0000000E         ;
+  110 0000000E         ;           2) OSStartHighRdy() MUST:
+  111 0000000E         ;              a) Setup PendSV exception priority to low
+                       est;
+  112 0000000E         ;              b) Set initial PSP to 0, to tell context 
+                       switcher this is first run;
+  113 0000000E         ;              c) Set the main stack to OS_CPU_ExceptStk
+                       Base;
+  114 0000000E         ;              d) Set OSRunning to TRUE;
+  115 0000000E         ;              e) Trigger PendSV exception;
+  116 0000000E         ;              f) Enable interrupts (tasks will run with
+                        interrupts enabled).
+  117 0000000E         ;*******************************************************
+                       *************************************************
+  118 0000000E         
+  119 0000000E         OSStartHighRdy
+  120 0000000E 481F            LDR              R0, =NVIC_SYSPRI14 ; Set the Pe
+                                                            ndSV exception prio
+
+
+
+ARM Macro Assembler    Page 4 
+
+
+                                                            rity
+  121 00000010 F04F 01FF       LDR              R1, =NVIC_PENDSV_PRI
+  122 00000014 7001            STRB             R1, [R0]
+  123 00000016         
+  124 00000016 2000            MOVS             R0, #0      ; Set the PSP to 0 
+                                                            for initial context
+                                                             switch call
+  125 00000018 F380 8809       MSR              PSP, R0
+  126 0000001C         
+  127 0000001C 481C            LDR              R0, =OS_CPU_ExceptStkBase ; Ini
+                                                            tialize the MSP to 
+                                                            the OS_CPU_ExceptSt
+                                                            kBase
+  128 0000001E 6801            LDR              R1, [R0]
+  129 00000020 F381 8808       MSR              MSP, R1
+  130 00000024         
+  131 00000024 481B            LDR              R0, =OSRunning 
+                                                            ; OSRunning = TRUE
+  132 00000026 2101            MOVS             R1, #1
+  133 00000028 7001            STRB             R1, [R0]
+  134 0000002A         
+  135 0000002A 481B            LDR              R0, =NVIC_INT_CTRL ; Trigger th
+                                                            e PendSV exception 
+                                                            (causes context swi
+                                                            tch)
+  136 0000002C F04F 5180       LDR              R1, =NVIC_PENDSVSET
+  137 00000030 6001            STR              R1, [R0]
+  138 00000032         
+  139 00000032 B662            CPSIE            I           ; Enable interrupts
+                                                             at processor level
+                                                            
+  140 00000034         
+  141 00000034         OSStartHang
+  142 00000034 E7FE            B                OSStartHang ; Should never get 
+                                                            here
+  143 00000036         
+  144 00000036         
+  145 00000036         ;*******************************************************
+                       *************************************************
+  146 00000036         ;                               PERFORM A CONTEXT SWITCH
+                        (From task level)
+  147 00000036         ;                                           void OSCtxSw
+                       (void)
+  148 00000036         ;
+  149 00000036         ; Note(s) : 1) OSCtxSw() is called when OS wants to perf
+                       orm a task context switch.  This function
+  150 00000036         ;              triggers the PendSV exception which is wh
+                       ere the real work is done.
+  151 00000036         ;*******************************************************
+                       *************************************************
+  152 00000036         
+  153 00000036         OSCtxSw
+  154 00000036 4818            LDR              R0, =NVIC_INT_CTRL ; Trigger th
+                                                            e PendSV exception 
+                                                            (causes context swi
+                                                            tch)
+  155 00000038 F04F 5180       LDR              R1, =NVIC_PENDSVSET
+  156 0000003C 6001            STR              R1, [R0]
+  157 0000003E 4770            BX               LR
+
+
+
+ARM Macro Assembler    Page 5 
+
+
+  158 00000040         
+  159 00000040         ;*******************************************************
+                       *************************************************
+  160 00000040         ;                             PERFORM A CONTEXT SWITCH (
+                       From interrupt level)
+  161 00000040         ;                                         void OSIntCtxS
+                       w(void)
+  162 00000040         ;
+  163 00000040         ; Notes:    1) OSIntCtxSw() is called by OSIntExit() whe
+                       n it determines a context switch is needed as
+  164 00000040         ;              the result of an interrupt.  This functio
+                       n simply triggers a PendSV exception which will
+  165 00000040         ;              be handled when there are no more interru
+                       pts active and interrupts are enabled.
+  166 00000040         ;*******************************************************
+                       *************************************************
+  167 00000040         
+  168 00000040         OSIntCtxSw
+  169 00000040 4815            LDR              R0, =NVIC_INT_CTRL ; Trigger th
+                                                            e PendSV exception 
+                                                            (causes context swi
+                                                            tch)
+  170 00000042 F04F 5180       LDR              R1, =NVIC_PENDSVSET
+  171 00000046 6001            STR              R1, [R0]
+  172 00000048 4770            BX               LR
+  173 0000004A         
+  174 0000004A         ;*******************************************************
+                       *************************************************
+  175 0000004A         ;                                         HANDLE PendSV 
+                       EXCEPTION
+  176 0000004A         ;                                     void OS_CPU_PendSV
+                       Handler(void)
+  177 0000004A         ;
+  178 0000004A         ; Note(s) : 1) PendSV is used to cause a context switch.
+                         This is a recommended method for performing
+  179 0000004A         ;              context switches with Cortex-M3.  This is
+                        because the Cortex-M3 auto-saves half of the
+  180 0000004A         ;              processor context on any exception, and r
+                       estores same on return from exception.  So only
+  181 0000004A         ;              saving of R4-R11 is required and fixing u
+                       p the stack pointers.  Using the PendSV exception
+  182 0000004A         ;              this way means that context saving and re
+                       storing is identical whether it is initiated from
+  183 0000004A         ;              a thread or occurs due to an interrupt or
+                        exception.
+  184 0000004A         ;
+  185 0000004A         ;           2) Pseudo-code is:
+  186 0000004A         ;              a) Get the process SP, if 0 then skip (go
+                       to d) the saving part (first context switch);
+  187 0000004A         ;              b) Save remaining regs r4-r11 on process 
+                       stack;
+  188 0000004A         ;              c) Save the process SP in its TCB, OSTCBC
+                       ur->OSTCBStkPtr = SP;
+  189 0000004A         ;              d) Call OSTaskSwHook();
+  190 0000004A         ;              e) Get current high priority, OSPrioCur =
+                        OSPrioHighRdy;
+  191 0000004A         ;              f) Get current ready thread TCB, OSTCBCur
+                        = OSTCBHighRdy;
+  192 0000004A         ;              g) Get new process SP from TCB, SP = OSTC
+
+
+
+ARM Macro Assembler    Page 6 
+
+
+                       BHighRdy->OSTCBStkPtr;
+  193 0000004A         ;              h) Restore R4-R11 from new process stack;
+                       
+  194 0000004A         ;              i) Perform exception return which will re
+                       store remaining context.
+  195 0000004A         ;
+  196 0000004A         ;           3) On entry into PendSV handler:
+  197 0000004A         ;              a) The following have been saved on the p
+                       rocess stack (by processor):
+  198 0000004A         ;                 xPSR, PC, LR, R12, R0-R3
+  199 0000004A         ;              b) Processor mode is switched to Handler 
+                       mode (from Thread mode)
+  200 0000004A         ;              c) Stack is Main stack (switched from Pro
+                       cess stack)
+  201 0000004A         ;              d) OSTCBCur      points to the OS_TCB of 
+                       the task to suspend
+  202 0000004A         ;                 OSTCBHighRdy  points to the OS_TCB of 
+                       the task to resume
+  203 0000004A         ;
+  204 0000004A         ;           4) Since PendSV is set to lowest priority in
+                        the system (by OSStartHighRdy() above), we
+  205 0000004A         ;              know that it will only be run when no oth
+                       er exception or interrupt is active, and
+  206 0000004A         ;              therefore safe to assume that context bei
+                       ng switched out was using the process stack (PSP).
+  207 0000004A         ;*******************************************************
+                       *************************************************
+  208 0000004A         
+  209 0000004A         PendSV_Handler
+  210 0000004A B672            CPSID            I           ; Prevent interrupt
+                                                            ion during context 
+                                                            switch
+  211 0000004C F3EF 8009       MRS              R0, PSP     ; PSP is process st
+                                                            ack pointer
+  212 00000050 B128            CBZ              R0, PendSV_Handler_Nosave ; Ski
+                                                            p register save the
+                                                             first time
+  213 00000052         
+  214 00000052 3820            SUBS             R0, R0, #0x20 ; Save remaining 
+                                                            regs r4-11 on proce
+                                                            ss stack
+  215 00000054 E880 0FF0       STM              R0, {R4-R11}
+  216 00000058         
+  217 00000058 4910            LDR              R1, =OSTCBCur ; OSTCBCur->OSTCB
+                                                            StkPtr = SP;
+  218 0000005A 6809            LDR              R1, [R1]
+  219 0000005C 6008            STR              R0, [R1]    ; R0 is SP of proce
+                                                            ss being switched o
+                                                            ut
+  220 0000005E         
+  221 0000005E         ; At this point, entire context of process has been save
+                       d
+  222 0000005E         PendSV_Handler_Nosave
+  223 0000005E B500            PUSH             {R14}       ; Save LR exc_retur
+                                                            n value
+  224 00000060 480F            LDR              R0, =OSTaskSwHook 
+                                                            ; OSTaskSwHook();
+  225 00000062 4780            BLX              R0
+  226 00000064 F85D EB04       POP              {R14}
+
+
+
+ARM Macro Assembler    Page 7 
+
+
+  227 00000068         
+  228 00000068 480E            LDR              R0, =OSPrioCur ; OSPrioCur = OS
+                                                            PrioHighRdy;
+  229 0000006A 490F            LDR              R1, =OSPrioHighRdy
+  230 0000006C 780A            LDRB             R2, [R1]
+  231 0000006E 7002            STRB             R2, [R0]
+  232 00000070         
+  233 00000070 480A            LDR              R0, =OSTCBCur ; OSTCBCur  = OST
+                                                            CBHighRdy;
+  234 00000072 490E            LDR              R1, =OSTCBHighRdy
+  235 00000074 680A            LDR              R2, [R1]
+  236 00000076 6002            STR              R2, [R0]
+  237 00000078         
+  238 00000078 6810            LDR              R0, [R2]    ; R0 is new process
+                                                             SP; SP = OSTCBHigh
+                                                            Rdy->OSTCBStkPtr;
+  239 0000007A E890 0FF0       LDM              R0, {R4-R11} ; Restore r4-11 fr
+                                                            om new process stac
+                                                            k
+  240 0000007E 3020            ADDS             R0, R0, #0x20
+  241 00000080 F380 8809       MSR              PSP, R0     ; Load PSP with new
+                                                             process SP
+  242 00000084 F04E 0E04       ORR              LR, LR, #0x04 ; Ensure exceptio
+                                                            n return uses proce
+                                                            ss stack
+  243 00000088 B662            CPSIE            I
+  244 0000008A 4770            BX               LR          ; Exception return 
+                                                            will restore remain
+                                                            ing context
+  245 0000008C         
+  246 0000008C                 END
+              E000ED22 
+              00000000 
+              00000000 
+              E000ED04 
+              00000000 
+              00000000 
+              00000000 
+              00000000 
+              00000000 
+Command Line: --debug --xref --diag_suppress=9931 --cpu=Cortex-M3 --apcs=interw
+ork --depend=..\obj\os_cpu_a.d -o..\obj\os_cpu_a.o -I.\RTE\_Target_1 -ID:\workS
+oftware\stm32Software\mdk\mdkpack\Keil\STM32F2xx_DFP\2.9.0\Drivers\CMSIS\Device
+\ST\STM32F2xx\Include -ID:\workSoftware\stm32Software\mdk\mdkcore\ARM\CMSIS\Inc
+lude --predefine="__MICROLIB SETA 1" --predefine="__UVISION_VERSION SETA 529" -
+-predefine="STM32F207xx SETA 1" --list=.\listings\os_cpu_a.lst ..\UCOS-II\Ports
+\os_cpu_a.asm
+
+
+
+ARM Macro Assembler    Page 1 Alphabetic symbol ordering
+Relocatable symbols
+
+.text 00000000
+
+Symbol: .text
+   Definitions
+      At line 57 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      None
+Comment: .text unused
+OSCtxSw 00000036
+
+Symbol: OSCtxSw
+   Definitions
+      At line 153 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 40 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSCtxSw used once
+OSIntCtxSw 00000040
+
+Symbol: OSIntCtxSw
+   Definitions
+      At line 168 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 41 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSIntCtxSw used once
+OSStartHang 00000034
+
+Symbol: OSStartHang
+   Definitions
+      At line 141 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 142 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSStartHang used once
+OSStartHighRdy 0000000E
+
+Symbol: OSStartHighRdy
+   Definitions
+      At line 119 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 39 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSStartHighRdy used once
+OS_CPU_SR_Restore 00000008
+
+Symbol: OS_CPU_SR_Restore
+   Definitions
+      At line 99 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 38 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OS_CPU_SR_Restore used once
+OS_CPU_SR_Save 00000000
+
+Symbol: OS_CPU_SR_Save
+   Definitions
+      At line 94 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 37 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OS_CPU_SR_Save used once
+PendSV_Handler 0000004A
+
+Symbol: PendSV_Handler
+
+
+
+ARM Macro Assembler    Page 2 Alphabetic symbol ordering
+Relocatable symbols
+
+   Definitions
+      At line 209 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 42 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: PendSV_Handler used once
+PendSV_Handler_Nosave 0000005E
+
+Symbol: PendSV_Handler_Nosave
+   Definitions
+      At line 222 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 212 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: PendSV_Handler_Nosave used once
+9 symbols
+
+
+
+ARM Macro Assembler    Page 1 Alphabetic symbol ordering
+Absolute symbols
+
+NVIC_INT_CTRL E000ED04
+
+Symbol: NVIC_INT_CTRL
+   Definitions
+      At line 48 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 135 in file ..\UCOS-II\Ports\os_cpu_a.asm
+      At line 154 in file ..\UCOS-II\Ports\os_cpu_a.asm
+      At line 169 in file ..\UCOS-II\Ports\os_cpu_a.asm
+
+NVIC_PENDSVSET 10000000
+
+Symbol: NVIC_PENDSVSET
+   Definitions
+      At line 51 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 136 in file ..\UCOS-II\Ports\os_cpu_a.asm
+      At line 155 in file ..\UCOS-II\Ports\os_cpu_a.asm
+      At line 170 in file ..\UCOS-II\Ports\os_cpu_a.asm
+
+NVIC_PENDSV_PRI 000000FF
+
+Symbol: NVIC_PENDSV_PRI
+   Definitions
+      At line 50 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 121 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: NVIC_PENDSV_PRI used once
+NVIC_SYSPRI14 E000ED22
+
+Symbol: NVIC_SYSPRI14
+   Definitions
+      At line 49 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 120 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: NVIC_SYSPRI14 used once
+4 symbols
+
+
+
+ARM Macro Assembler    Page 1 Alphabetic symbol ordering
+External symbols
+
+OSIntExit 00000000
+
+Symbol: OSIntExit
+   Definitions
+      At line 32 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      None
+Comment: OSIntExit unused
+OSPrioCur 00000000
+
+Symbol: OSPrioCur
+   Definitions
+      At line 28 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 228 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSPrioCur used once
+OSPrioHighRdy 00000000
+
+Symbol: OSPrioHighRdy
+   Definitions
+      At line 29 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 229 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSPrioHighRdy used once
+OSRunning 00000000
+
+Symbol: OSRunning
+   Definitions
+      At line 27 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 131 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSRunning used once
+OSTCBCur 00000000
+
+Symbol: OSTCBCur
+   Definitions
+      At line 30 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 217 in file ..\UCOS-II\Ports\os_cpu_a.asm
+      At line 233 in file ..\UCOS-II\Ports\os_cpu_a.asm
+
+OSTCBHighRdy 00000000
+
+Symbol: OSTCBHighRdy
+   Definitions
+      At line 31 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 234 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSTCBHighRdy used once
+OSTaskSwHook 00000000
+
+Symbol: OSTaskSwHook
+   Definitions
+      At line 33 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 224 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OSTaskSwHook used once
+OS_CPU_ExceptStkBase 00000000
+
+
+
+
+ARM Macro Assembler    Page 2 Alphabetic symbol ordering
+External symbols
+
+Symbol: OS_CPU_ExceptStkBase
+   Definitions
+      At line 34 in file ..\UCOS-II\Ports\os_cpu_a.asm
+   Uses
+      At line 127 in file ..\UCOS-II\Ports\os_cpu_a.asm
+Comment: OS_CPU_ExceptStkBase used once
+8 symbols
+356 symbols in table

+ 25 - 25
app/MDKProject/Listings/startup_stm32f2xx.lst

@@ -52,44 +52,44 @@ ARM Macro Assembler    Page 1
    33 00000000         ;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
    34 00000000         ; </h>
    35 00000000         
-   36 00000000 00008000 
+   36 00000000 00001000 
                        Stack_Size
-                               EQU              0x00008000
+                               EQU              0x00001000
    37 00000000         
    38 00000000                 AREA             STACK, NOINIT, READWRITE, ALIGN
 =3
    39 00000000         Stack_Mem
                                SPACE            Stack_Size
-   40 00008000         __initial_sp
-   41 00008000         
-   42 00008000         
+   40 00001000         __initial_sp
+   41 00001000         
+   42 00001000         
 
 
 
 ARM Macro Assembler    Page 2 
 
 
-   43 00008000         ; <h> Heap Configuration
-   44 00008000         ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
-   45 00008000         ; </h>
-   46 00008000         
-   47 00008000 00008000 
+   43 00001000         ; <h> Heap Configuration
+   44 00001000         ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
+   45 00001000         ; </h>
+   46 00001000         
+   47 00001000 00001000 
                        Heap_Size
-                               EQU              0x00008000
-   48 00008000         
-   49 00008000                 AREA             HEAP, NOINIT, READWRITE, ALIGN=
+                               EQU              0x00001000
+   48 00001000         
+   49 00001000                 AREA             HEAP, NOINIT, READWRITE, ALIGN=
 3
    50 00000000         __heap_base
    51 00000000         Heap_Mem
                                SPACE            Heap_Size
-   52 00008000         __heap_limit
-   53 00008000         
-   54 00008000                 PRESERVE8
-   55 00008000                 THUMB
-   56 00008000         
-   57 00008000         
-   58 00008000         ; Vector Table Mapped to Address 0 at Reset
-   59 00008000                 AREA             RESET, DATA, READONLY
+   52 00001000         __heap_limit
+   53 00001000         
+   54 00001000                 PRESERVE8
+   55 00001000                 THUMB
+   56 00001000         
+   57 00001000         
+   58 00001000         ; Vector Table Mapped to Address 0 at Reset
+   59 00001000                 AREA             RESET, DATA, READONLY
    60 00000000                 EXPORT           __Vectors
    61 00000000                 EXPORT           __Vectors_End
    62 00000000                 EXPORT           __Vectors_Size
@@ -862,7 +862,7 @@ Symbol: Stack_Mem
    Uses
       None
 Comment: Stack_Mem unused
-__initial_sp 00008000
+__initial_sp 00001000
 
 Symbol: __initial_sp
    Definitions
@@ -902,7 +902,7 @@ Symbol: __heap_base
    Uses
       At line 402 in file ..\CORE\startup_stm32f2xx.s
 Comment: __heap_base used once
-__heap_limit 00008000
+__heap_limit 00001000
 
 Symbol: __heap_limit
    Definitions
@@ -1876,7 +1876,7 @@ Symbol: WWDG_IRQHandler
 ARM Macro Assembler    Page 1 Alphabetic symbol ordering
 Absolute symbols
 
-Heap_Size 00008000
+Heap_Size 00001000
 
 Symbol: Heap_Size
    Definitions
@@ -1884,7 +1884,7 @@ Symbol: Heap_Size
    Uses
       At line 51 in file ..\CORE\startup_stm32f2xx.s
 Comment: Heap_Size used once
-Stack_Size 00008000
+Stack_Size 00001000
 
 Symbol: Stack_Size
    Definitions

Fichier diff supprimé car celui-ci est trop grand
+ 210 - 192
app/MDKProject/lora_gateway.uvguix.16936


+ 299 - 10
app/MDKProject/lora_gateway.uvoptx

@@ -103,7 +103,7 @@
         <bEvRecOn>1</bEvRecOn>
         <bSchkAxf>0</bSchkAxf>
         <bTchkAxf>0</bTchkAxf>
-        <nTsel>3</nTsel>
+        <nTsel>4</nTsel>
         <sDll></sDll>
         <sDllPa></sDllPa>
         <sDlgDll></sDlgDll>
@@ -114,9 +114,14 @@
         <tDlgDll></tDlgDll>
         <tDlgPa></tDlgPa>
         <tIfile></tIfile>
-        <pMon>BIN\CMSIS_AGDI.dll</pMon>
+        <pMon>Segger\JL2CM3.dll</pMon>
       </DebugOpt>
       <TargetDriverDllRegistry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>JL2CM3</Key>
+          <Name>-U69407005 -O78 -S6 -ZTIFSpeedSel500 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM)</Name>
+        </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Key>ARMRTXEVENTFLAGS</Key>
@@ -140,7 +145,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>CMSIS_AGDI</Key>
-          <Name>-X"WCH CMSIS-DAP" -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM)</Name>
+          <Name>-X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -153,7 +158,7 @@
         <Mm>
           <WinNumber>1</WinNumber>
           <SubType>8</SubType>
-          <ItemText>temp</ItemText>
+          <ItemText>UART6_RX_BUF</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>
@@ -163,7 +168,7 @@
       <DebugFlag>
         <trace>0</trace>
         <periodic>1</periodic>
-        <aLwin>1</aLwin>
+        <aLwin>0</aLwin>
         <aCover>0</aCover>
         <aSer1>0</aSer1>
         <aSer2>0</aSer2>
@@ -201,7 +206,7 @@
       <pMultCmdsp></pMultCmdsp>
       <DebugDescription>
         <Enable>1</Enable>
-        <EnableFlashSeq>1</EnableFlashSeq>
+        <EnableFlashSeq>0</EnableFlashSeq>
         <EnableLog>0</EnableLog>
         <Protocol>2</Protocol>
         <DbgClock>10000000</DbgClock>
@@ -211,7 +216,7 @@
 
   <Group>
     <GroupName>USER</GroupName>
-    <tvExp>1</tvExp>
+    <tvExp>0</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
@@ -719,6 +724,54 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
+    <File>
+      <GroupNumber>4</GroupNumber>
+      <FileNumber>41</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\HARDWARE\sources\delay.c</PathWithFileName>
+      <FilenameWithoutPath>delay.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>4</GroupNumber>
+      <FileNumber>42</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\HARDWARE\sources\cJSON.c</PathWithFileName>
+      <FilenameWithoutPath>cJSON.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>4</GroupNumber>
+      <FileNumber>43</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\HARDWARE\sources\log.c</PathWithFileName>
+      <FilenameWithoutPath>log.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>4</GroupNumber>
+      <FileNumber>44</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\HARDWARE\sources\led.c</PathWithFileName>
+      <FilenameWithoutPath>led.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
 
   <Group>
@@ -729,7 +782,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>41</FileNumber>
+      <FileNumber>45</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -741,7 +794,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>42</FileNumber>
+      <FileNumber>46</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -753,7 +806,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>43</FileNumber>
+      <FileNumber>47</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -765,4 +818,240 @@
     </File>
   </Group>
 
+  <Group>
+    <GroupName>Sx1278</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>6</GroupNumber>
+      <FileNumber>48</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\SX1278\sx1276.c</PathWithFileName>
+      <FilenameWithoutPath>sx1276.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>6</GroupNumber>
+      <FileNumber>49</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\SX1278\sx1276-board.c</PathWithFileName>
+      <FilenameWithoutPath>sx1276-board.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>UCOSII_CORE</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>50</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_core.c</PathWithFileName>
+      <FilenameWithoutPath>os_core.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>51</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_flag.c</PathWithFileName>
+      <FilenameWithoutPath>os_flag.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>52</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_mbox.c</PathWithFileName>
+      <FilenameWithoutPath>os_mbox.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>53</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_mem.c</PathWithFileName>
+      <FilenameWithoutPath>os_mem.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>54</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_mutex.c</PathWithFileName>
+      <FilenameWithoutPath>os_mutex.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>55</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_q.c</PathWithFileName>
+      <FilenameWithoutPath>os_q.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>56</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_sem.c</PathWithFileName>
+      <FilenameWithoutPath>os_sem.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>57</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_task.c</PathWithFileName>
+      <FilenameWithoutPath>os_task.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>58</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_time.c</PathWithFileName>
+      <FilenameWithoutPath>os_time.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>7</GroupNumber>
+      <FileNumber>59</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Source\os_tmr.c</PathWithFileName>
+      <FilenameWithoutPath>os_tmr.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>UCOSII_PORT</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>8</GroupNumber>
+      <FileNumber>60</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Ports\os_cpu.h</PathWithFileName>
+      <FilenameWithoutPath>os_cpu.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>8</GroupNumber>
+      <FileNumber>61</FileNumber>
+      <FileType>2</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Ports\os_cpu_a.asm</PathWithFileName>
+      <FilenameWithoutPath>os_cpu_a.asm</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>8</GroupNumber>
+      <FileNumber>62</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\Ports\os_cpu_c.c</PathWithFileName>
+      <FilenameWithoutPath>os_cpu_c.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>UCOSII_CONFIG</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>9</GroupNumber>
+      <FileNumber>63</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\CONFIG\includes.h</PathWithFileName>
+      <FilenameWithoutPath>includes.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>9</GroupNumber>
+      <FileNumber>64</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\UCOS-II\CONFIG\os_cfg.h</PathWithFileName>
+      <FilenameWithoutPath>os_cfg.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
 </ProjectOpt>

+ 127 - 2
app/MDKProject/lora_gateway.uvprojx

@@ -325,7 +325,7 @@
             <uThumb>0</uThumb>
             <uSurpInc>0</uSurpInc>
             <uC99>1</uC99>
-            <uGnu>1</uGnu>
+            <uGnu>0</uGnu>
             <useXO>0</useXO>
             <v6Lang>1</v6Lang>
             <v6LangP>1</v6LangP>
@@ -338,7 +338,7 @@
               <MiscControls></MiscControls>
               <Define>USE_STDPERIPH_DRIVER</Define>
               <Undefine></Undefine>
-              <IncludePath>..\CORE;..\Libraries\inc;..\USER;..\HARDWARE\includes;..\USER\FatFS\src</IncludePath>
+              <IncludePath>..\CORE;..\Libraries\inc;..\USER;..\HARDWARE\includes;..\USER\FatFS\src;..\SX1278;..\UCOS-II\CONFIG;..\UCOS-II\Ports;..\UCOS-II\Source</IncludePath>
             </VariousControls>
           </Cads>
           <Aads>
@@ -597,6 +597,26 @@
               <FileType>1</FileType>
               <FilePath>..\HARDWARE\sources\malloc.c</FilePath>
             </File>
+            <File>
+              <FileName>delay.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\HARDWARE\sources\delay.c</FilePath>
+            </File>
+            <File>
+              <FileName>cJSON.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\HARDWARE\sources\cJSON.c</FilePath>
+            </File>
+            <File>
+              <FileName>log.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\HARDWARE\sources\log.c</FilePath>
+            </File>
+            <File>
+              <FileName>led.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\HARDWARE\sources\led.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -619,6 +639,111 @@
             </File>
           </Files>
         </Group>
+        <Group>
+          <GroupName>Sx1278</GroupName>
+          <Files>
+            <File>
+              <FileName>sx1276.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\SX1278\sx1276.c</FilePath>
+            </File>
+            <File>
+              <FileName>sx1276-board.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\SX1278\sx1276-board.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>UCOSII_CORE</GroupName>
+          <Files>
+            <File>
+              <FileName>os_core.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_core.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_flag.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_flag.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_mbox.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_mbox.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_mem.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_mem.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_mutex.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_mutex.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_q.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_q.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_sem.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_sem.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_task.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_task.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_time.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_time.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_tmr.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Source\os_tmr.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>UCOSII_PORT</GroupName>
+          <Files>
+            <File>
+              <FileName>os_cpu.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\UCOS-II\Ports\os_cpu.h</FilePath>
+            </File>
+            <File>
+              <FileName>os_cpu_a.asm</FileName>
+              <FileType>2</FileType>
+              <FilePath>..\UCOS-II\Ports\os_cpu_a.asm</FilePath>
+            </File>
+            <File>
+              <FileName>os_cpu_c.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\UCOS-II\Ports\os_cpu_c.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>UCOSII_CONFIG</GroupName>
+          <Files>
+            <File>
+              <FileName>includes.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\UCOS-II\CONFIG\includes.h</FilePath>
+            </File>
+            <File>
+              <FileName>os_cfg.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\UCOS-II\CONFIG\os_cfg.h</FilePath>
+            </File>
+          </Files>
+        </Group>
       </Groups>
     </Target>
   </Targets>

BIN
app/OBJ/at_cmd.crf


+ 43 - 0
app/OBJ/at_cmd.d

@@ -0,0 +1,43 @@
+..\obj\at_cmd.o: ..\HARDWARE\sources\at_cmd.c
+..\obj\at_cmd.o: ..\HARDWARE\includes\at_cmd.h
+..\obj\at_cmd.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdbool.h
+..\obj\at_cmd.o: ..\HARDWARE\includes\delay.h
+..\obj\at_cmd.o: ..\USER\stm32f2xx.h
+..\obj\at_cmd.o: ..\CORE\core_cm3.h
+..\obj\at_cmd.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\at_cmd.o: ..\CORE\core_cmInstr.h
+..\obj\at_cmd.o: ..\CORE\core_cmFunc.h
+..\obj\at_cmd.o: ..\USER\system_stm32f2xx.h
+..\obj\at_cmd.o: ..\USER\stm32f2xx_conf.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\at_cmd.o: ..\USER\stm32f2xx.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\at_cmd.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\at_cmd.o: ..\Libraries\inc\misc.h
+..\obj\at_cmd.o: ..\HARDWARE\includes\usart.h
+..\obj\at_cmd.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdio.h
+..\obj\at_cmd.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\string.h
+..\obj\at_cmd.o: ..\HARDWARE\includes\log.h
+..\obj\at_cmd.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdarg.h

BIN
app/OBJ/cjson.crf


+ 45 - 0
app/OBJ/cjson.d

@@ -0,0 +1,45 @@
+..\obj\cjson.o: ..\HARDWARE\sources\cJSON.c
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\string.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdio.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\math.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdlib.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\limits.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\ctype.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\float.h
+..\obj\cjson.o: ..\HARDWARE\includes\cJSON.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stddef.h
+..\obj\cjson.o: ..\HARDWARE\includes\malloc.h
+..\obj\cjson.o: ..\USER\stm32f2xx.h
+..\obj\cjson.o: ..\CORE\core_cm3.h
+..\obj\cjson.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\cjson.o: ..\CORE\core_cmInstr.h
+..\obj\cjson.o: ..\CORE\core_cmFunc.h
+..\obj\cjson.o: ..\USER\system_stm32f2xx.h
+..\obj\cjson.o: ..\USER\stm32f2xx_conf.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\cjson.o: ..\USER\stm32f2xx.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\cjson.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\cjson.o: ..\Libraries\inc\misc.h

BIN
app/OBJ/delay.crf


+ 44 - 0
app/OBJ/delay.d

@@ -0,0 +1,44 @@
+..\obj\delay.o: ..\HARDWARE\sources\delay.c
+..\obj\delay.o: ..\HARDWARE\includes\delay.h
+..\obj\delay.o: ..\USER\stm32f2xx.h
+..\obj\delay.o: ..\CORE\core_cm3.h
+..\obj\delay.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\delay.o: ..\CORE\core_cmInstr.h
+..\obj\delay.o: ..\CORE\core_cmFunc.h
+..\obj\delay.o: ..\USER\system_stm32f2xx.h
+..\obj\delay.o: ..\USER\stm32f2xx_conf.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\delay.o: ..\USER\stm32f2xx.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\delay.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\delay.o: ..\Libraries\inc\misc.h
+..\obj\delay.o: ..\UCOS-II\CONFIG\includes.h
+..\obj\delay.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdarg.h
+..\obj\delay.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdio.h
+..\obj\delay.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdlib.h
+..\obj\delay.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\math.h
+..\obj\delay.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\delay.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\delay.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/demo_nand_fatfs.crf


BIN
app/OBJ/diskio.crf


BIN
app/OBJ/ebt3001.crf


+ 37 - 0
app/OBJ/ebt3001.d

@@ -0,0 +1,37 @@
+..\obj\ebt3001.o: ..\HARDWARE\sources\ebt3001.c
+..\obj\ebt3001.o: ..\HARDWARE\includes\ebt3001.h
+..\obj\ebt3001.o: ..\USER\stm32f2xx.h
+..\obj\ebt3001.o: ..\CORE\core_cm3.h
+..\obj\ebt3001.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\ebt3001.o: ..\CORE\core_cmInstr.h
+..\obj\ebt3001.o: ..\CORE\core_cmFunc.h
+..\obj\ebt3001.o: ..\USER\system_stm32f2xx.h
+..\obj\ebt3001.o: ..\USER\stm32f2xx_conf.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\ebt3001.o: ..\USER\stm32f2xx.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\ebt3001.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\ebt3001.o: ..\Libraries\inc\misc.h
+..\obj\ebt3001.o: ..\HARDWARE\includes\delay.h

BIN
app/OBJ/ff.crf


BIN
app/OBJ/led.crf


+ 36 - 0
app/OBJ/led.d

@@ -0,0 +1,36 @@
+..\obj\led.o: ..\HARDWARE\sources\led.c
+..\obj\led.o: ..\HARDWARE\includes\led.h
+..\obj\led.o: ..\USER\stm32f2xx.h
+..\obj\led.o: ..\CORE\core_cm3.h
+..\obj\led.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\led.o: ..\CORE\core_cmInstr.h
+..\obj\led.o: ..\CORE\core_cmFunc.h
+..\obj\led.o: ..\USER\system_stm32f2xx.h
+..\obj\led.o: ..\USER\stm32f2xx_conf.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\led.o: ..\USER\stm32f2xx.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\led.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\led.o: ..\Libraries\inc\misc.h

BIN
app/OBJ/log.crf


+ 39 - 0
app/OBJ/log.d

@@ -0,0 +1,39 @@
+..\obj\log.o: ..\HARDWARE\sources\log.c
+..\obj\log.o: ..\HARDWARE\includes\log.h
+..\obj\log.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdarg.h
+..\obj\log.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdio.h
+..\obj\log.o: ..\HARDWARE\includes\usart.h
+..\obj\log.o: ..\USER\stm32f2xx.h
+..\obj\log.o: ..\CORE\core_cm3.h
+..\obj\log.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\log.o: ..\CORE\core_cmInstr.h
+..\obj\log.o: ..\CORE\core_cmFunc.h
+..\obj\log.o: ..\USER\system_stm32f2xx.h
+..\obj\log.o: ..\USER\stm32f2xx_conf.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\log.o: ..\USER\stm32f2xx.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\log.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\log.o: ..\Libraries\inc\misc.h

BIN
app/OBJ/lora_gateway.axf


+ 3 - 21
app/OBJ/lora_gateway.build_log.htm

@@ -17,34 +17,17 @@ Library Manager: ArmAr.exe V5.06 update 6 (build 750)
 Hex Converter:   FromElf.exe V5.06 update 6 (build 750)
 CPU DLL:         SARMCM3.DLL V5.29.0.0
 Dialog DLL:      DCM.DLL V1.17.3.0
-Target DLL:      CMSIS_AGDI.dll V1.32.0.0
+Target DLL:      Segger\JL2CM3.dll V2.99.36.0
 Dialog DLL:      TCM.DLL V1.36.5.0
  
 <h2>Project:</h2>
 D:\Project\Lora_gateway_sx1278\app\MDKProject\lora_gateway.uvprojx
-Project File Date:  06/13/2023
+Project File Date:  07/03/2023
 
 <h2>Output:</h2>
 *** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin'
 Build target 'Target 1'
-compiling usart.c...
-..\HARDWARE\includes\usart.h(86): warning:  #1295-D: Deprecated declaration NVIC_Configuration - give arg types
-  void NVIC_Configuration();
-..\HARDWARE\sources\usart.c(12): warning:  #177-D: variable "NVIC_InitStructure"  was declared but never referenced
-    NVIC_InitTypeDef NVIC_InitStructure;
-..\HARDWARE\sources\usart.c(10): warning:  #177-D: function "NVIC_Configuration"  was declared but never referenced
-  static void NVIC_Configuration(void)
-..\HARDWARE\sources\usart.c: 3 warnings, 0 errors
-compiling main.c...
-..\HARDWARE\includes\usart.h(86): warning:  #1295-D: Deprecated declaration NVIC_Configuration - give arg types
-  void NVIC_Configuration();
-..\USER\main.c: 1 warning, 0 errors
-linking...
-..\OBJ\lora_gateway.axf: Error: L6218E: Undefined symbol Debug_USART_Config (referred from main.o).
-Not enough information to list image symbols.
-Not enough information to list load addresses in the image map.
-Finished: 2 information, 0 warning and 1 error messages.
-"..\OBJ\lora_gateway.axf" - 1 Error(s), 4 Warning(s).
+"..\OBJ\lora_gateway.axf" - 0 Error(s), 0 Warning(s).
 
 <h2>Software Packages used:</h2>
 
@@ -58,7 +41,6 @@ Package Vendor: Keil
   D:\workSoftware\stm32Software\mdk\mdkpack\Keil\STM32F2xx_DFP\2.9.0\Drivers\CMSIS\Device\ST\STM32F2xx\Include
 
 <h2>Collection of Component Files used:</h2>
-Target not created.
 Build Time Elapsed:  00:00:00
 </pre>
 </body>

Fichier diff supprimé car celui-ci est trop grand
+ 1166 - 188
app/OBJ/lora_gateway.htm


+ 18 - 0
app/OBJ/lora_gateway.lnp

@@ -39,9 +39,27 @@
 "..\obj\usart.o"
 "..\obj\nandflash.o"
 "..\obj\malloc.o"
+"..\obj\delay.o"
+"..\obj\cjson.o"
+"..\obj\log.o"
+"..\obj\led.o"
 "..\obj\cc936.o"
 "..\obj\diskio.o"
 "..\obj\ff.o"
+"..\obj\sx1276.o"
+"..\obj\sx1276-board.o"
+"..\obj\os_core.o"
+"..\obj\os_flag.o"
+"..\obj\os_mbox.o"
+"..\obj\os_mem.o"
+"..\obj\os_mutex.o"
+"..\obj\os_q.o"
+"..\obj\os_sem.o"
+"..\obj\os_task.o"
+"..\obj\os_time.o"
+"..\obj\os_tmr.o"
+"..\obj\os_cpu_a.o"
+"..\obj\os_cpu_c.o"
 --library_type=microlib --strict --scatter "..\OBJ\lora_gateway.sct"
 --summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols
 --info sizes --info totals --info unused --info veneers

Fichier diff supprimé car celui-ci est trop grand
+ 318 - 46
app/OBJ/lora_gateway_Target 1.dep


BIN
app/OBJ/main.crf


+ 12 - 0
app/OBJ/main.d

@@ -40,3 +40,15 @@
 ..\obj\main.o: ..\HARDWARE\includes\usart.h
 ..\obj\main.o: ..\HARDWARE\includes\malloc.h
 ..\obj\main.o: ..\USER\demo_nand_fatfs.h
+..\obj\main.o: ..\HARDWARE\includes\cjson.h
+..\obj\main.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stddef.h
+..\obj\main.o: ..\HARDWARE\includes\delay.h
+..\obj\main.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\string.h
+..\obj\main.o: ..\UCOS-II\CONFIG\includes.h
+..\obj\main.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdarg.h
+..\obj\main.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdlib.h
+..\obj\main.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\math.h
+..\obj\main.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\main.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\main.o: ..\UCOS-II\Ports\os_cpu.h
+..\obj\main.o: ..\HARDWARE\includes\led.h

BIN
app/OBJ/nandflash.crf


BIN
app/OBJ/os_core.crf


+ 4 - 0
app/OBJ/os_core.d

@@ -0,0 +1,4 @@
+..\obj\os_core.o: ..\UCOS-II\Source\os_core.c
+..\obj\os_core.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_core.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_core.o: ..\UCOS-II\Ports\os_cpu.h

+ 1 - 0
app/OBJ/os_cpu_a.d

@@ -0,0 +1 @@
+..\obj\os_cpu_a.o: ..\UCOS-II\Ports\os_cpu_a.asm

BIN
app/OBJ/os_cpu_c.crf


+ 4 - 0
app/OBJ/os_cpu_c.d

@@ -0,0 +1,4 @@
+..\obj\os_cpu_c.o: ..\UCOS-II\Ports\os_cpu_c.c
+..\obj\os_cpu_c.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_cpu_c.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_cpu_c.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_flag.crf


+ 4 - 0
app/OBJ/os_flag.d

@@ -0,0 +1,4 @@
+..\obj\os_flag.o: ..\UCOS-II\Source\os_flag.c
+..\obj\os_flag.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_flag.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_flag.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_mbox.crf


+ 4 - 0
app/OBJ/os_mbox.d

@@ -0,0 +1,4 @@
+..\obj\os_mbox.o: ..\UCOS-II\Source\os_mbox.c
+..\obj\os_mbox.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_mbox.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_mbox.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_mem.crf


+ 4 - 0
app/OBJ/os_mem.d

@@ -0,0 +1,4 @@
+..\obj\os_mem.o: ..\UCOS-II\Source\os_mem.c
+..\obj\os_mem.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_mem.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_mem.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_mutex.crf


+ 4 - 0
app/OBJ/os_mutex.d

@@ -0,0 +1,4 @@
+..\obj\os_mutex.o: ..\UCOS-II\Source\os_mutex.c
+..\obj\os_mutex.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_mutex.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_mutex.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_q.crf


+ 4 - 0
app/OBJ/os_q.d

@@ -0,0 +1,4 @@
+..\obj\os_q.o: ..\UCOS-II\Source\os_q.c
+..\obj\os_q.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_q.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_q.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_sem.crf


+ 4 - 0
app/OBJ/os_sem.d

@@ -0,0 +1,4 @@
+..\obj\os_sem.o: ..\UCOS-II\Source\os_sem.c
+..\obj\os_sem.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_sem.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_sem.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_task.crf


+ 4 - 0
app/OBJ/os_task.d

@@ -0,0 +1,4 @@
+..\obj\os_task.o: ..\UCOS-II\Source\os_task.c
+..\obj\os_task.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_task.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_task.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_time.crf


+ 4 - 0
app/OBJ/os_time.d

@@ -0,0 +1,4 @@
+..\obj\os_time.o: ..\UCOS-II\Source\os_time.c
+..\obj\os_time.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_time.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_time.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/os_tmr.crf


+ 4 - 0
app/OBJ/os_tmr.d

@@ -0,0 +1,4 @@
+..\obj\os_tmr.o: ..\UCOS-II\Source\os_tmr.c
+..\obj\os_tmr.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\os_tmr.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\os_tmr.o: ..\UCOS-II\Ports\os_cpu.h

BIN
app/OBJ/stm32f2xx_it.crf


BIN
app/OBJ/sx1276-board.crf


+ 43 - 0
app/OBJ/sx1276-board.d

@@ -0,0 +1,43 @@
+..\obj\sx1276-board.o: ..\SX1278\sx1276-board.c
+..\obj\sx1276-board.o: ..\SX1278\radio.h
+..\obj\sx1276-board.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdbool.h
+..\obj\sx1276-board.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\sx1276-board.o: ..\SX1278\sx1276.h
+..\obj\sx1276-board.o: ..\SX1278\sx1276Regs-Fsk.h
+..\obj\sx1276-board.o: ..\SX1278\sx1276Regs-LoRa.h
+..\obj\sx1276-board.o: ..\SX1278\sx1276-board.h
+..\obj\sx1276-board.o: ..\HARDWARE\includes\delay.h
+..\obj\sx1276-board.o: ..\USER\stm32f2xx.h
+..\obj\sx1276-board.o: ..\CORE\core_cm3.h
+..\obj\sx1276-board.o: ..\CORE\core_cmInstr.h
+..\obj\sx1276-board.o: ..\CORE\core_cmFunc.h
+..\obj\sx1276-board.o: ..\USER\system_stm32f2xx.h
+..\obj\sx1276-board.o: ..\USER\stm32f2xx_conf.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_adc.h
+..\obj\sx1276-board.o: ..\USER\stm32f2xx.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_can.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_crc.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_cryp.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_dac.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_dbgmcu.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_dcmi.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_dma.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_exti.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_flash.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_fsmc.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_hash.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_gpio.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_i2c.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_iwdg.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_pwr.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_rcc.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_rng.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_rtc.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_sdio.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_spi.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_syscfg.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_tim.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_usart.h
+..\obj\sx1276-board.o: ..\Libraries\inc\stm32f2xx_wwdg.h
+..\obj\sx1276-board.o: ..\Libraries\inc\misc.h
+..\obj\sx1276-board.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdio.h

BIN
app/OBJ/sx1276.crf


+ 10 - 0
app/OBJ/sx1276.d

@@ -0,0 +1,10 @@
+..\obj\sx1276.o: ..\SX1278\sx1276.c
+..\obj\sx1276.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\math.h
+..\obj\sx1276.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\string.h
+..\obj\sx1276.o: ..\SX1278\radio.h
+..\obj\sx1276.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdbool.h
+..\obj\sx1276.o: D:\workSoftware\stm32Software\mdk\mdkcore\ARM\ARMCC\Bin\..\include\stdint.h
+..\obj\sx1276.o: ..\SX1278\sx1276.h
+..\obj\sx1276.o: ..\SX1278\sx1276Regs-Fsk.h
+..\obj\sx1276.o: ..\SX1278\sx1276Regs-LoRa.h
+..\obj\sx1276.o: ..\SX1278\sx1276-board.h

BIN
app/OBJ/ucos_ii.crf


+ 15 - 0
app/OBJ/ucos_ii.d

@@ -0,0 +1,15 @@
+..\obj\ucos_ii.o: ..\UCOS-II\Source\ucos_ii.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\ucos_ii.h
+..\obj\ucos_ii.o: ..\UCOS-II\CONFIG\app_cfg.h
+..\obj\ucos_ii.o: ..\UCOS-II\CONFIG\os_cfg.h
+..\obj\ucos_ii.o: ..\UCOS-II\Ports\os_cpu.h
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_core.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_flag.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_mbox.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_mem.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_mutex.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_q.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_sem.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_task.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_time.c
+..\obj\ucos_ii.o: ..\UCOS-II\Source\os_tmr.c

BIN
app/OBJ/usart.crf


+ 321 - 0
app/SX1278/radio.h

@@ -0,0 +1,321 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2013 Semtech
+
+Description: Generic radio driver definition
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __RADIO_H__
+#define __RADIO_H__
+#include "stdbool.h"	//bool¶¨Òå
+#include "stdint.h"	//uint8_tµÈÊý¾ÝÀàÐͶ¨Òå
+
+/*!
+ * Radio driver supported modems
+ */
+typedef enum
+{
+    MODEM_FSK = 0,
+    MODEM_LORA,
+}RadioModems_t;
+
+/*!
+ * Radio driver internal state machine states definition
+ */
+typedef enum
+{
+    RF_IDLE = 0,
+    RF_RX_RUNNING,
+    RF_TX_RUNNING,
+    RF_CAD,
+}RadioState_t;
+
+/*!
+ * \brief Radio driver callback functions
+ */
+typedef struct
+{
+    /*!
+     * \brief  Tx Done callback prototype.
+     */
+    void    ( *TxDone )( void );
+    /*!
+     * \brief  Tx Timeout callback prototype.
+     */
+    void    ( *TxTimeout )( void );
+    /*!
+     * \brief Rx Done callback prototype.
+     *
+     * \param [IN] payload Received buffer pointer
+     * \param [IN] size    Received buffer size
+     * \param [IN] rssi    RSSI value computed while receiving the frame [dBm]
+     * \param [IN] snr     Raw SNR value given by the radio hardware
+     *                     FSK : N/A ( set to 0 )
+     *                     LoRa: SNR value in dB
+     */
+    void    ( *RxDone )( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
+    /*!
+     * \brief  Rx Timeout callback prototype.
+     */
+    void    ( *RxTimeout )( void );
+    /*!
+     * \brief Rx Error callback prototype.
+     */
+    void    ( *RxError )( void );
+    /*!
+     * \brief  FHSS Change Channel callback prototype.
+     *
+     * \param [IN] currentChannel   Index number of the current channel
+     */
+    void ( *FhssChangeChannel )( uint8_t currentChannel );
+
+    /*!
+     * \brief CAD Done callback prototype.
+     *
+     * \param [IN] channelDetected    Channel Activity detected during the CAD
+     */
+    void ( *CadDone ) ( bool channelActivityDetected );
+}RadioEvents_t;
+
+/*!
+ * \brief Radio driver definition
+ */
+struct Radio_s
+{
+    /*!
+     * \brief Initializes the radio
+     *
+     * \param [IN] events Structure containing the driver callback functions
+     */
+    void    ( *Init )( RadioEvents_t *events );
+    /*!
+     * Return current radio status
+     *
+     * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
+     */
+    RadioState_t ( *GetStatus )( void );
+    /*!
+     * \brief Configures the radio with the given modem
+     *
+     * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 
+     */
+    void    ( *SetModem )( RadioModems_t modem );
+    /*!
+     * \brief Sets the channel frequency
+     *
+     * \param [IN] freq         Channel RF frequency
+     */
+    void    ( *SetChannel )( uint32_t freq );
+    /*!
+     * \brief Sets the channels configuration
+     *
+     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] freq       Channel RF frequency
+     * \param [IN] rssiThresh RSSI threshold
+     *
+     * \retval isFree         [true: Channel is free, false: Channel is not free]
+     */
+    bool    ( *IsChannelFree )( RadioModems_t modem, uint32_t freq, int16_t rssiThresh );
+    /*!
+     * \brief Generates a 32 bits random value based on the RSSI readings
+     *
+     * \remark This function sets the radio in LoRa modem mode and disables 
+     *         all interrupts.
+     *         After calling this function either Radio.SetRxConfig or
+     *         Radio.SetTxConfig functions must be called.
+     *
+     * \retval randomValue    32 bits random value
+     */
+    uint32_t ( *Random )( void );
+    /*!
+     * \brief Sets the reception parameters
+     *
+     * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] bandwidth    Sets the bandwidth
+     *                          FSK : >= 2600 and <= 250000 Hz
+     *                          LoRa: [0: 125 kHz, 1: 250 kHz,
+     *                                 2: 500 kHz, 3: Reserved] 
+     * \param [IN] datarate     Sets the Datarate
+     *                          FSK : 600..300000 bits/s
+     *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
+     *                                10: 1024, 11: 2048, 12: 4096  chips]
+     * \param [IN] coderate     Sets the coding rate (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
+     * \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 
+     *                          FSK : >= 2600 and <= 250000 Hz
+     *                          LoRa: N/A ( set to 0 ) 
+     * \param [IN] preambleLen  Sets the Preamble length
+     *                          FSK : Number of bytes 
+     *                          LoRa: Length in symbols (the hardware adds 4 more symbols)
+     * \param [IN] symbTimeout  Sets the RxSingle timeout value (LoRa only) 
+     *                          FSK : N/A ( set to 0 ) 
+     *                          LoRa: timeout in symbols
+     * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
+     * \param [IN] payloadLen   Sets payload length when fixed lenght is used
+     * \param [IN] crcOn        Enables/Disables the CRC [0: OFF, 1: ON]
+     * \param [IN] FreqHopOn    Enables disables the intra-packet frequency hopping
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: OFF, 1: ON]
+     * \param [IN] HopPeriod    Number of symbols bewteen each hop
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: Number of symbols
+     * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: not inverted, 1: inverted]
+     * \param [IN] rxContinuous Sets the reception in continuous mode
+     *                          [false: single mode, true: continuous mode]
+     */
+    void    ( *SetRxConfig )( RadioModems_t modem, uint32_t bandwidth,
+                              uint32_t datarate, uint8_t coderate,
+                              uint32_t bandwidthAfc, uint16_t preambleLen,
+                              uint16_t symbTimeout, bool fixLen,
+                              uint8_t payloadLen,
+                              bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
+                              bool iqInverted, bool rxContinuous );
+    /*!
+     * \brief Sets the transmission parameters
+     *
+     * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa] 
+     * \param [IN] power        Sets the output power [dBm]
+     * \param [IN] fdev         Sets the frequency deviation (FSK only)
+     *                          FSK : [Hz]
+     *                          LoRa: 0
+     * \param [IN] bandwidth    Sets the bandwidth (LoRa only)
+     *                          FSK : 0
+     *                          LoRa: [0: 125 kHz, 1: 250 kHz,
+     *                                 2: 500 kHz, 3: Reserved] 
+     * \param [IN] datarate     Sets the Datarate
+     *                          FSK : 600..300000 bits/s
+     *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
+     *                                10: 1024, 11: 2048, 12: 4096  chips]
+     * \param [IN] coderate     Sets the coding rate (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
+     * \param [IN] preambleLen  Sets the preamble length
+     *                          FSK : Number of bytes 
+     *                          LoRa: Length in symbols (the hardware adds 4 more symbols)
+     * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
+     * \param [IN] crcOn        Enables disables the CRC [0: OFF, 1: ON]
+     * \param [IN] FreqHopOn    Enables disables the intra-packet frequency hopping
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: OFF, 1: ON]
+     * \param [IN] HopPeriod    Number of symbols bewteen each hop
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: Number of symbols
+     * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: not inverted, 1: inverted]
+     * \param [IN] timeout      Transmission timeout [ms]
+     */
+    void    ( *SetTxConfig )( RadioModems_t modem, int8_t power, uint32_t fdev, 
+                              uint32_t bandwidth, uint32_t datarate,
+                              uint8_t coderate, uint16_t preambleLen,
+                              bool fixLen, bool crcOn, bool FreqHopOn,
+                              uint8_t HopPeriod, bool iqInverted, uint32_t timeout );
+    /*!
+     * \brief Checks if the given RF frequency is supported by the hardware
+     *
+     * \param [IN] frequency RF frequency to be checked
+     * \retval isSupported [true: supported, false: unsupported]
+     */
+    bool    ( *CheckRfFrequency )( uint32_t frequency );
+    /*!
+     * \brief Computes the packet time on air in us for the given payload
+     *
+     * \Remark Can only be called once SetRxConfig or SetTxConfig have been called
+     *
+     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] pktLen     Packet payload length
+     *
+     * \retval airTime        Computed airTime (us) for the given packet payload length
+     */
+    uint32_t  ( *TimeOnAir )( RadioModems_t modem, uint8_t pktLen );
+    /*!
+     * \brief Sends the buffer of size. Prepares the packet to be sent and sets
+     *        the radio in transmission
+     *
+     * \param [IN]: buffer     Buffer pointer
+     * \param [IN]: size       Buffer size
+     */
+    void    ( *Send )( uint8_t *buffer, uint8_t size );
+    /*!
+     * \brief Sets the radio in sleep mode
+     */
+    void    ( *Sleep )( void );
+    /*!
+     * \brief Sets the radio in standby mode
+     */
+    void    ( *Standby )( void );
+    /*!
+     * \brief Sets the radio in reception mode for the given time
+     * \param [IN] timeout Reception timeout [ms]
+     *                     [0: continuous, others timeout]
+     */
+    void    ( *Rx )( uint32_t timeout );
+    /*!
+     * \brief Start a Channel Activity Detection
+     */
+    void    ( *StartCad )( void );
+    /*!
+     * \brief Reads the current RSSI value
+     *
+     * \retval rssiValue Current RSSI value in [dBm]
+     */
+    int16_t ( *Rssi )( RadioModems_t modem );
+    /*!
+     * \brief Writes the radio register at the specified address
+     *
+     * \param [IN]: addr Register address
+     * \param [IN]: data New register value
+     */
+    void    ( *Write )( uint8_t addr, uint8_t data );
+    /*!
+     * \brief Reads the radio register at the specified address
+     *
+     * \param [IN]: addr Register address
+     * \retval data Register value
+     */
+    uint8_t ( *Read )( uint8_t addr );
+    /*!
+     * \brief Writes multiple radio registers starting at address
+     *
+     * \param [IN] addr   First Radio register address
+     * \param [IN] buffer Buffer containing the new register's values
+     * \param [IN] size   Number of registers to be written
+     */
+    void    ( *WriteBuffer )( uint8_t addr, uint8_t *buffer, uint8_t size );
+    /*!
+     * \brief Reads multiple radio registers starting at address
+     *
+     * \param [IN] addr First Radio register address
+     * \param [OUT] buffer Buffer where to copy the registers data
+     * \param [IN] size Number of registers to be read
+     */
+    void    ( *ReadBuffer )( uint8_t addr, uint8_t *buffer, uint8_t size );
+    /*!
+     * \brief Sets the maximum payload length.
+     *
+     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] max        Maximum payload length in bytes
+     */
+    void ( *SetMaxPayloadLength )( RadioModems_t modem, uint8_t max );
+
+};
+
+/*!
+ * \brief Radio driver
+ *
+ * \remark This variable is defined and initialized in the specific radio
+ *         board implementation
+ */
+extern const struct Radio_s Radio;
+
+#endif // __RADIO_H__

+ 396 - 0
app/SX1278/sx1276-board.c

@@ -0,0 +1,396 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2013 Semtech
+
+Description: SX1276 driver specific target board functions implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#include "radio.h"
+#include "sx1276.h"
+#include "sx1276-board.h"
+#include "delay.h"
+#include "stdio.h"
+
+//复位脚
+#define SX1278_RST_PIN_INDEX	GPIO_Pin_11
+#define SX1278_RST_PIN_GROUP	GPIOB
+//SPI引脚
+#define SX1278_CS_PIN_INDEX	GPIO_Pin_12
+#define SX1278_CS_PIN_GROUP	GPIOB
+#define SX1278_SCK_PIN_INDEX	GPIO_Pin_13
+#define SX1278_SCK_PIN_GROUP	GPIOB
+#define SX1278_MISO_PIN_INDEX	GPIO_Pin_14
+#define SX1278_MISO_PIN_GROUP	GPIOB
+#define SX1278_MOSI_PIN_INDEX	GPIO_Pin_15
+#define SX1278_MOSI_PIN_GROUP	GPIOB
+//DIO0引脚(这里修改了需要手动修改中断初始化和中断函数)
+#define SX1278_DIO0_PIN_INDEX	GPIO_Pin_6
+#define SX1278_DIO0_PIN_GROUP	GPIOG
+//DIO1引脚(这里修改了需要手动修改中断初始化和中断函数)
+//#define SX1278_DIO1_PIN_INDEX	GPIO_Pin_1
+//#define SX1278_DIO1_PIN_GROUP	GPIOB
+
+/*!
+ * Radio driver structure initialization
+ */
+const struct Radio_s Radio =
+{
+    SX1276Init,
+    SX1276GetStatus,
+    SX1276SetModem,
+    SX1276SetChannel,
+    SX1276IsChannelFree,
+    SX1276Random,
+    SX1276SetRxConfig,
+    SX1276SetTxConfig,
+    SX1276CheckRfFrequency,
+    SX1276GetTimeOnAir,
+    SX1276Send,
+    SX1276SetSleep,
+    SX1276SetStby, 
+    SX1276SetRx,
+    SX1276StartCad,
+    SX1276ReadRssi,
+    SX1276Write,
+    SX1276Read,
+    SX1276WriteBuffer,
+    SX1276ReadBuffer,
+    SX1276SetMaxPayloadLength
+};
+
+/*!
+ * Antenna switch GPIO pins objects
+ */
+/* 我们的RA-01/02模组的天线切换开关由硬件自动控制,不需要软件控制
+Gpio_t AntSwitchLf;
+Gpio_t AntSwitchHf;*/
+
+/*!
+ * Tx and Rx timers
+ */
+/*TimerEvent_t TxTimeoutTimer;
+TimerEvent_t RxTimeoutTimer;
+TimerEvent_t RxTimeoutSyncWord;*/
+
+//实现ms级延时
+//delayMs:延时的ms数
+void SX1276DelayMs(uint32_t delayMs){
+	delay_ms(delayMs);
+}
+
+//定时器初始化(RX,TX,SyncWord定时完成后都需要调用 SX1276OnTimeoutIrq() 函数)
+void SX1276TimerInit(void){
+}
+void TIM2_Int_Init(u16 arr,u16 psc)
+{
+	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
+	NVIC_InitTypeDef NVIC_InitStructure;
+
+	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //时钟使能
+
+	TIM2->CR1 |= TIM_CR1_URS;	//如果不设置这个会导致定时器启动的时候立即进入中断
+	
+	//定时器TIM3初始化
+	TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值	
+	TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
+	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
+	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数模式
+	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
+ 
+	TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE ); //使能指定的TIM3中断,允许更新中断
+	
+	//中断优先级NVIC设置
+	NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;  //TIM3中断
+	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
+	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;  //从优先级3级
+	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
+	NVIC_Init(&NVIC_InitStructure);  //初始化NVIC寄存器
+	
+	TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
+
+	TIM_Cmd(TIM2, ENABLE);  //启动TIM		
+}
+
+void TIM3_Int_Init(u16 arr,u16 psc)
+{
+  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
+	NVIC_InitTypeDef NVIC_InitStructure;
+
+	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟使能
+
+	TIM3->CR1 |= TIM_CR1_URS;	//如果不设置这个会导致定时器启动的时候立即进入中断
+	
+	//定时器TIM3初始化
+	TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值	
+	TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
+	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
+	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数模式
+	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
+ 
+	TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); //使能指定的TIM3中断,允许更新中断
+	
+	//中断优先级NVIC设置
+	NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  //TIM3中断
+	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
+	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //从优先级3级
+	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
+	NVIC_Init(&NVIC_InitStructure);  //初始化NVIC寄存器
+	
+	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
+
+	TIM_Cmd(TIM3, ENABLE);  //启动TIM					 
+}
+
+void TIM4_Int_Init(u16 arr,u16 psc)
+{
+  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
+	NVIC_InitTypeDef NVIC_InitStructure;
+
+	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //时钟使能
+
+	TIM4->CR1 |= TIM_CR1_URS;	//如果不设置这个会导致定时器启动的时候立即进入中断
+	
+	//定时器TIM3初始化
+	TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值	
+	TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
+	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
+	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数模式
+	TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
+ 
+	TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE ); //使能指定的TIM3中断,允许更新中断
+	
+	//中断优先级NVIC设置
+	NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;  //TIM3中断
+	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
+	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;  //从优先级3级
+	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
+	NVIC_Init(&NVIC_InitStructure);  //初始化NVIC寄存器
+	
+	TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
+
+	TIM_Cmd(TIM4, ENABLE);  //启动TIM					 
+}
+
+//定时器3中断服务程序
+void TIM3_IRQHandler(void)   //TIM3中断
+{
+	if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)  //检查TIM3更新中断发生与否
+	{
+		TIM_ClearITPendingBit(TIM3, TIM_IT_Update  );  //清除TIMx更新中断标志
+		TIM_Cmd(TIM3, DISABLE);  //失能TIMx
+		SX1276OnTimeoutIrq();	//发生中断后需要调用 SX1276OnTimeoutIrq 函数
+		//printf("\r\ntimer irq\r\n");
+	}
+}
+
+//开启 tx 超时定时器,定时timeoutMs 毫秒
+void SX1276TxTimeoutTimerStart( uint32_t timeoutMs ){
+	//这里简化使用了一个定时器,实际工程中最好使用独立的3个定时器,或者使用软件定时器
+	TIM3_Int_Init((timeoutMs * 10) -1,(12000-1));//10Khz的计数频率,计数到10次为1ms 
+}
+
+//关闭 tx 超时定时器
+void SX1276TxTimeoutTimerStop(void){
+	///这里简化使用了一个定时器,实际工程中最好使用独立的3个定时器,或者使用软件定时器
+	TIM_Cmd(TIM3, DISABLE);  //失能TIMx
+}
+
+//开启 RX 超时定时器,定时timeoutMs 毫秒
+void SX1276RxTimeoutTimerStart( uint32_t timeoutMs ){
+	//这里简化使用了一个定时器,实际工程中最好使用独立的3个定时器,或者使用软件定时器
+	TIM3_Int_Init((timeoutMs * 10) -1,7199);//10Khz的计数频率,计数到10次为1ms 
+}
+
+//关闭 RX 超时定时器
+void SX1276RxTimeoutTimerStop(void){
+	///这里简化使用了一个定时器,实际工程中最好使用独立的3个定时器,或者使用软件定时器
+	TIM_Cmd(TIM3, DISABLE);  //失能TIMx	
+}
+
+//开启 SyncWord 超时定时器,定时timeoutMs 毫秒
+void SX1276SyncWordTimeoutTimerStart( uint32_t timeoutMs ){
+	//这里简化使用了一个定时器,实际工程中最好使用独立的3个定时器,或者使用软件定时器
+	TIM3_Int_Init((timeoutMs * 10) -1,7199);//10Khz的计数频率,计数到10次为1ms 
+}
+
+//关闭 SyncWord 超时定时器
+void SX1276SyncWordTimeoutTimerStop(void){
+	///这里简化使用了一个定时器,实际工程中最好使用独立的3个定时器,或者使用软件定时器
+	TIM_Cmd(TIM3, DISABLE);  //失能TIMx	
+}
+
+//初始化SPI(cs低使能,极性SPI_CPOL_High,相位SPI_CPHA_2Edge,SPI_FirstBit_MSB)和Rst脚
+void SX1276IoInit( void )
+{
+	GPIO_InitTypeDef  GPIO_InitStructure;
+	SPI_InitTypeDef  SPI_InitStructure;
+	
+	//初始化一个gpio用来控制spi1的cs
+	RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);	    
+	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	 //IO口速度为50MHz,这里不用传参,直接写死用最大速度50MHZ
+	GPIO_InitStructure.GPIO_Pin = SX1278_CS_PIN_INDEX;
+	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;	//设置为推挽输出
+	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+	GPIO_Init(SX1278_CS_PIN_GROUP, &GPIO_InitStructure);	//初始化GPIO
+
+	//SPI的初始化
+	RCC_APB2PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);//SPI时钟使能
+	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;	//设置为推挽输出
+	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+	GPIO_InitStructure.GPIO_Pin = SX1278_SCK_PIN_INDEX|SX1278_MISO_PIN_INDEX|SX1278_MOSI_PIN_INDEX;
+	GPIO_Init(SX1278_SCK_PIN_GROUP, &GPIO_InitStructure);	//初始化GPIO
+
+	//配置SPI
+	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
+	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//设置SPI工作模式:设置为主SPI
+	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		//设置SPI的数据大小:SPI发送接收8位帧结构
+	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;		//设置时钟极性(串行同步时钟的空闲状态为高电平还是低电平)
+	SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;	//设置相位(串行同步时钟的第几个跳变沿(上升或下降)数据被采样)
+	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		//NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:设置为软件控制(SSI控制)
+	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;		//定义波特率预分频的值:波特率预分频值为256(256是最低,可以设置完成之后调整速度,如果速度过快导致通信失败再调小)
+	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
+	SPI_InitStructure.SPI_CRCPolynomial = 7;	//CRC值计算的多项式(CRC校验相关)
+	SPI_Init(SPI1,&SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
+	
+	SPI_Cmd(SPI1,ENABLE); //使能SPI外设
+}
+
+DioIrqHandler **g_irqHandlers;
+
+//初始化DIO(上升沿)中断,将 DIO0~5 的GPIO中断函数调用 irqHandlers[0]~irqHandlers[5]
+void SX1276IoIrqInit( DioIrqHandler **irqHandlers )
+{
+	EXTI_InitTypeDef EXTI_InitStructure;
+ 	NVIC_InitTypeDef NVIC_InitStructure;
+	GPIO_InitTypeDef  GPIO_InitStructure;
+	
+	g_irqHandlers=irqHandlers;
+	//初始化DIO0
+	 // 使能外部IO时钟
+  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
+  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	 //IO口速度为50MHz,这里不用传参,直接写死用最大速度50MHZ
+	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
+	GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
+	GPIO_InitStructure.GPIO_Pin = SX1278_DIO0_PIN_INDEX;
+	GPIO_Init(SX1278_DIO0_PIN_GROUP, &GPIO_InitStructure);	//初始化GPIO
+	
+	//配置中断
+	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOG,EXTI_PinSource6);//设置映射线关系(这里的 GPIO_PortSourceGPIOX 刚好是0-5,所以直接用pinName/16表示,GPIO_PinSourceXX刚好是0-15,所以用pinName%16表示了)
+	EXTI_InitStructure.EXTI_Line=EXTI_Line6;	//中断线u8_pinNum
+	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//外部中断
+	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;//上升降沿触发
+	EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能中断
+	EXTI_Init(&EXTI_InitStructure);//配置中断
+
+	//配置中断优先级
+	NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;	//外部中断XX
+	//stm32f103c8例子中这个优先级对应抢占优先级2子优先级3
+	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x02;	//抢占优先级
+	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;   //子优先级
+	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	//使能中断
+	NVIC_Init(&NVIC_InitStructure);   //配置优先级
+	
+	EXTI_ClearITPendingBit(EXTI_Line6);//清除中断标志位
+}
+#if 0
+//外部中断线0中断处理函数,这里需要回调对应的函数
+void EXTI0_IRQHandler(void){
+	g_irqHandlers[0]();
+	EXTI_ClearITPendingBit(EXTI_Line0);//清除中断标志位
+}
+
+//外部中断线1中断处理函数,这里需要回调对应的函数
+void EXTI1_IRQHandler(void){
+	g_irqHandlers[1]();
+	EXTI_ClearITPendingBit(EXTI_Line1);//清除中断标志位
+}
+#endif
+//处理DIO tx中断或者Rx中断数据
+void EXTI6_IRQHandler(void)
+{
+	g_irqHandlers[0]();
+	EXTI_ClearITPendingBit(EXTI_Line6);//清除中断标志位
+}
+//将SPI、DIO0~5和Rst脚的中断去初始化
+void SX1276IoDeInit( void )
+{
+	//这里省略去初始化的功能了
+}
+
+//判断频率是否合法
+//如果不限制频率可以直接return true
+bool SX1276CheckRfFrequency( uint32_t frequency )
+{
+    // Implement check. Currently all frequencies are supported
+    return true;
+}
+
+/**
+  * 硬复位
+  * 将rst引脚拉低1ms,然后将复位脚设置为无上下拉的输入模式
+  */
+void SX1276Reset( void )
+{
+	GPIO_InitTypeDef  GPIO_InitStructure;
+	
+	RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);	    //使能指定端口时钟(这里是为了方便ABC全开了)
+	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	 //IO口速度为50MHz,这里不用传参,直接写死用最大速度50MHZ
+	GPIO_InitStructure.GPIO_Pin = SX1278_RST_PIN_INDEX;
+	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;	//设置为推挽输出
+	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+	GPIO_Init(SX1278_RST_PIN_GROUP, &GPIO_InitStructure);	//初始化GPIO
+
+	GPIO_ResetBits(SX1278_RST_PIN_GROUP,SX1278_RST_PIN_INDEX);	//输出低电平
+	delay_ms(1);
+	
+	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;//浮空输入
+	GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
+	GPIO_Init(SX1278_RST_PIN_GROUP, &GPIO_InitStructure);	//初始化GPIO
+	delay_ms(6);
+}
+
+/**
+  * 设置SPI的片选脚的电平(低电平使能,高电平取消)
+  * lev:true的时候高电平,false的时候低电平
+  */
+void Sx1276SetNSS(bool lev )
+{
+	if(lev){
+		GPIO_SetBits(SX1278_CS_PIN_GROUP,SX1278_CS_PIN_INDEX);	//输出高电平
+	}else{
+		GPIO_ResetBits(SX1278_CS_PIN_GROUP,SX1278_CS_PIN_INDEX);	//输出低电平
+	}
+}
+
+/**
+  * SPI读写函数,data是发送的数据,返回值是接收到的数据
+  */
+uint8_t Sx1276SpiInOut(uint16_t data )
+{
+	//完成SPI的读写功能
+	uint16_t retry=0;				 	
+	while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET){//检查指定的SPI标志位设置与否:发送缓存空标志位(缓冲区空了就可以拷贝数据了)
+		if((retry++)>2000){
+			//超时了
+			return 0xff;
+		}
+	}
+	SPI_I2S_SendData(SPI1, data); //通过外设SPIx发送一个数据
+	retry=0;
+
+	while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET){ //检查指定的SPI标志位设置与否:接受缓存非空标志位(非空了就表示接收数据完成了)
+		if((retry++)>2000){
+			//超时了
+			return 0xff;
+		}
+	}
+	return SPI_I2S_ReceiveData(SPI1); //返回通过SPIx最近接收的数据
+}

+ 122 - 0
app/SX1278/sx1276-board.h

@@ -0,0 +1,122 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2013 Semtech
+
+Description: SX1276 driver specific target board functions implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_ARCH_H__
+#define __SX1276_ARCH_H__
+#include "stdbool.h"
+#include "stdint.h"
+#include "sx1276.h"
+
+/*!
+ * \brief Radio hardware registers initialization definition
+ *
+ * \remark Can be automatically generated by the SX1276 GUI (not yet implemented)
+ */
+#define RADIO_INIT_REGISTERS_VALUE                \
+{                                                 \
+    { MODEM_FSK , REG_LNA                , 0x23 },\
+    { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
+    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
+    { MODEM_FSK , REG_AFCFEI             , 0x01 },\
+    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
+    { MODEM_FSK , REG_OSC                , 0x07 },\
+    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
+    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
+    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
+    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
+    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
+    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
+    { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
+    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
+    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
+    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
+}                                                 \
+
+#define RF_MID_BAND_THRESH                          525000000
+
+/*!
+ * \brief Initializes the radio I/Os pins interface
+ */
+void SX1276IoInit( void );
+
+/*!
+ * \brief Initializes DIO IRQ handlers
+ *
+ * \param [IN] irqHandlers Array containing the IRQ callback functions
+ */
+void SX1276IoIrqInit( DioIrqHandler **irqHandlers );
+
+/*!
+ * \brief De-initializes the radio I/Os pins interface. 
+ *
+ * \remark Useful when going in MCU lowpower modes
+ */
+void SX1276IoDeInit( void );
+
+/*!
+ * \brief Gets the board PA selection configuration
+ *
+ * \param [IN] channel Channel frequency in Hz
+ * \retval PaSelect RegPaConfig PaSelect value
+ */
+uint8_t SX1276GetPaSelect( uint32_t channel );
+
+/*!
+ * \brief Initializes the RF Switch I/Os pins interface
+ */
+void SX1276AntSwInit( void );
+
+/*!
+ * \brief De-initializes the RF Switch I/Os pins interface 
+ *
+ * \remark Needed to decrease the power consumption in MCU lowpower modes
+ */
+void SX1276AntSwDeInit( void );
+
+/*!
+ * \brief Controls the antena switch if necessary.
+ *
+ * \remark see errata note
+ *
+ * \param [IN] rxTx [1: Tx, 0: Rx]
+ */
+void SX1276SetAntSw( uint8_t rxTx );
+
+/*!
+ * \brief Checks if the given RF frequency is supported by the hardware
+ *
+ * \param [IN] frequency RF frequency to be checked
+ * \retval isSupported [true: supported, false: unsupported]
+ */
+bool SX1276CheckRfFrequency( uint32_t frequency );
+
+
+void Sx1276SetNSS(bool enable );
+uint8_t Sx1276SpiInOut(uint16_t data );
+void SX1276TimerInit(void);
+void SX1276TxTimeoutTimerStart( uint32_t timeoutMs );
+void SX1276TxTimeoutTimerStop(void);
+void SX1276RxTimeoutTimerStart( uint32_t timeoutMs );
+void SX1276RxTimeoutTimerStop(void);
+void SX1276SyncWordTimeoutTimerStart( uint32_t timeoutMs );
+void SX1276SyncWordTimeoutTimerStop(void);
+void SX1276Reset( void );
+void SX1276DelayMs(uint32_t delayMs);
+
+/*!
+ * Radio hardware and global parameters
+ */
+extern SX1276_t SX1276;
+
+#endif // __SX1276_ARCH_H__

Fichier diff supprimé car celui-ci est trop grand
+ 1868 - 0
app/SX1278/sx1276.c


+ 396 - 0
app/SX1278/sx1276.h

@@ -0,0 +1,396 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_H__
+#define __SX1276_H__
+
+#include "sx1276Regs-Fsk.h"
+#include "sx1276Regs-LoRa.h"
+#include "radio.h"
+
+/*!
+ * Radio wakeup time from SLEEP mode
+ */
+#define RADIO_OSC_STARTUP                           1 // [ms]
+
+/*!
+ * Radio PLL lock and Mode Ready delay which can vary with the temperature
+ */
+#define RADIO_SLEEP_TO_RX                           2 // [ms]
+
+/*!
+ * Radio complete Wake-up Time with margin for temperature compensation
+ */
+#define RADIO_WAKEUP_TIME                           ( RADIO_OSC_STARTUP + RADIO_SLEEP_TO_RX )
+
+/*!
+ * Radio FSK modem parameters
+ */
+typedef struct
+{
+    int8_t   Power;
+    uint32_t Fdev;
+    uint32_t Bandwidth;
+    uint32_t BandwidthAfc;
+    uint32_t Datarate;
+    uint16_t PreambleLen;
+    bool     FixLen;
+    uint8_t  PayloadLen;
+    bool     CrcOn;
+    bool     IqInverted;
+    bool     RxContinuous;
+    uint32_t TxTimeout;
+}RadioFskSettings_t;
+
+/*!
+ * Radio FSK packet handler state
+ */
+typedef struct
+{
+    uint8_t  PreambleDetected;
+    uint8_t  SyncWordDetected;
+    int8_t   RssiValue;
+    int32_t  AfcValue;
+    uint8_t  RxGain;
+    uint16_t Size;
+    uint16_t NbBytes;
+    uint8_t  FifoThresh;
+    uint8_t  ChunkSize;
+}RadioFskPacketHandler_t;
+
+/*!
+ * Radio LoRa modem parameters
+ */
+typedef struct
+{
+    int8_t   Power;
+    uint32_t Bandwidth;
+    uint32_t Datarate;
+    bool     LowDatarateOptimize;
+    uint8_t  Coderate;
+    uint16_t PreambleLen;
+    bool     FixLen;
+    uint8_t  PayloadLen;
+    bool     CrcOn;
+    bool     FreqHopOn;
+    uint8_t  HopPeriod;
+    bool     IqInverted;
+    bool     RxContinuous;
+    uint32_t TxTimeout;
+}RadioLoRaSettings_t;
+
+/*!
+ * Radio LoRa packet handler state
+ */
+typedef struct
+{
+    int8_t SnrValue;
+    int16_t RssiValue;
+    uint8_t Size;
+}RadioLoRaPacketHandler_t;
+
+/*!
+ * Radio Settings
+ */
+typedef struct
+{
+    RadioState_t             State;
+    RadioModems_t            Modem;
+    uint32_t                 Channel;
+    RadioFskSettings_t       Fsk;
+    RadioFskPacketHandler_t  FskPacketHandler;
+    RadioLoRaSettings_t      LoRa;
+    RadioLoRaPacketHandler_t LoRaPacketHandler;
+}RadioSettings_t;
+
+/*!
+ * Radio hardware and global parameters
+ */
+typedef struct SX1276_s
+{
+    /* GPIO和硬件相关,移植到 sx1276-board.c 中了
+		Gpio_t        Reset;
+    Gpio_t        DIO0;
+    Gpio_t        DIO1;
+    Gpio_t        DIO2;
+    Gpio_t        DIO3;
+    Gpio_t        DIO4;
+    Gpio_t        DIO5;
+    Spi_t         Spi;*/
+    RadioSettings_t Settings;
+}SX1276_t;
+
+/*!
+ * Hardware IO IRQ callback function definition
+ */
+typedef void ( DioIrqHandler )( void );
+
+/*!
+ * SX1276 definitions
+ */
+#define XTAL_FREQ                                   32000000
+#define FREQ_STEP                                   61.03515625
+
+#define RX_BUFFER_SIZE                              256
+
+/*!
+ * ============================================================================
+ * Public functions prototypes
+ * ============================================================================
+ */
+
+/*!
+ * \brief Initializes the radio
+ *
+ * \param [IN] events Structure containing the driver callback functions
+ */
+void SX1276Init( RadioEvents_t *events );
+
+/*!
+ * Return current radio status
+ *
+ * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
+ */
+RadioState_t SX1276GetStatus( void );
+
+/*!
+ * \brief Configures the radio with the given modem
+ *
+ * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 
+ */
+void SX1276SetModem( RadioModems_t modem );
+
+/*!
+ * \brief Sets the channels configuration
+ *
+ * \param [IN] freq         Channel RF frequency
+ */
+void SX1276SetChannel( uint32_t freq );
+
+/*!
+ * \brief Sets the channels configuration
+ *
+ * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+ * \param [IN] freq       Channel RF frequency
+ * \param [IN] rssiThresh RSSI threshold
+ *
+ * \retval isFree         [true: Channel is free, false: Channel is not free]
+ */
+bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh );
+
+/*!
+ * \brief Generates a 32 bits random value based on the RSSI readings
+ *
+ * \remark This function sets the radio in LoRa modem mode and disables 
+ *         all interrupts.
+ *         After calling this function either SX1276SetRxConfig or
+ *         SX1276SetTxConfig functions must be called.
+ *
+ * \retval randomValue    32 bits random value
+ */
+uint32_t SX1276Random( void );
+
+/*!
+ * \brief Sets the reception parameters
+ *
+ * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ *
+ * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa]
+ * \param [IN] bandwidth    Sets the bandwidth
+ *                          FSK : >= 2600 and <= 250000 Hz
+ *                          LoRa: [0: 125 kHz, 1: 250 kHz,
+ *                                 2: 500 kHz, 3: Reserved] 
+ * \param [IN] datarate     Sets the Datarate
+ *                          FSK : 600..300000 bits/s
+ *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
+ *                                10: 1024, 11: 2048, 12: 4096  chips]
+ * \param [IN] coderate     Sets the coding rate (LoRa only)
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
+ * \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 
+ *                          FSK : >= 2600 and <= 250000 Hz
+ *                          LoRa: N/A ( set to 0 ) 
+ * \param [IN] preambleLen  Sets the Preamble length
+ *                          FSK : Number of bytes 
+ *                          LoRa: Length in symbols (the hardware adds 4 more symbols)
+ * \param [IN] symbTimeout  Sets the RxSingle timeout value (LoRa only) 
+ *                          FSK : N/A ( set to 0 ) 
+ *                          LoRa: timeout in symbols
+ * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
+ * \param [IN] payloadLen   Sets payload length when fixed lenght is used
+ * \param [IN] crcOn        Enables/Disables the CRC [0: OFF, 1: ON]
+ * \param [IN] FreqHopOn    Enables disables the intra-packet frequency hopping
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: [0: OFF, 1: ON]
+ * \param [IN] HopPeriod    Number of symbols bewteen each hop
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: Number of symbols
+ * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: [0: not inverted, 1: inverted]
+ * \param [IN] rxContinuous Sets the reception in continuous mode
+ *                          [false: single mode, true: continuous mode]
+ */
+void SX1276SetRxConfig( RadioModems_t modem, uint32_t bandwidth,
+                         uint32_t datarate, uint8_t coderate,
+                         uint32_t bandwidthAfc, uint16_t preambleLen,
+                         uint16_t symbTimeout, bool fixLen,
+                         uint8_t payloadLen,
+                         bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
+                         bool iqInverted, bool rxContinuous );
+
+/*!
+ * \brief Sets the transmission parameters
+ *
+ * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ *
+ * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa] 
+ * \param [IN] power        Sets the output power [dBm]
+ * \param [IN] fdev         Sets the frequency deviation (FSK only)
+ *                          FSK : [Hz]
+ *                          LoRa: 0
+ * \param [IN] bandwidth    Sets the bandwidth (LoRa only)
+ *                          FSK : 0
+ *                          LoRa: [0: 125 kHz, 1: 250 kHz,
+ *                                 2: 500 kHz, 3: Reserved] 
+ * \param [IN] datarate     Sets the Datarate
+ *                          FSK : 600..300000 bits/s
+ *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
+ *                                10: 1024, 11: 2048, 12: 4096  chips]
+ * \param [IN] coderate     Sets the coding rate (LoRa only)
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
+ * \param [IN] preambleLen  Sets the preamble length
+ *                          FSK : Number of bytes 
+ *                          LoRa: Length in symbols (the hardware adds 4 more symbols)
+ * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
+ * \param [IN] crcOn        Enables disables the CRC [0: OFF, 1: ON]
+ * \param [IN] FreqHopOn    Enables disables the intra-packet frequency hopping
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: [0: OFF, 1: ON]
+ * \param [IN] HopPeriod    Number of symbols bewteen each hop
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: Number of symbols
+ * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
+ *                          FSK : N/A ( set to 0 )
+ *                          LoRa: [0: not inverted, 1: inverted]
+ * \param [IN] timeout      Transmission timeout [ms]
+ */
+void SX1276SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev, 
+                        uint32_t bandwidth, uint32_t datarate,
+                        uint8_t coderate, uint16_t preambleLen,
+                        bool fixLen, bool crcOn, bool FreqHopOn,
+                        uint8_t HopPeriod, bool iqInverted, uint32_t timeout );
+
+/*!
+ * \brief Computes the packet time on air in us for the given payload
+ *
+ * \Remark Can only be called once SetRxConfig or SetTxConfig have been called
+ *
+ * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+ * \param [IN] pktLen     Packet payload length
+ *
+ * \retval airTime        Computed airTime (us) for the given packet payload length
+ */
+uint32_t SX1276GetTimeOnAir( RadioModems_t modem, uint8_t pktLen );
+
+/*!
+ * \brief Sends the buffer of size. Prepares the packet to be sent and sets
+ *        the radio in transmission
+ *
+ * \param [IN]: buffer     Buffer pointer
+ * \param [IN]: size       Buffer size
+ */
+void SX1276Send( uint8_t *buffer, uint8_t size );
+    
+/*!
+ * \brief Sets the radio in sleep mode
+ */
+void SX1276SetSleep( void );
+
+/*!
+ * \brief Sets the radio in standby mode
+ */
+void SX1276SetStby( void );
+
+/*!
+ * \brief Sets the radio in reception mode for the given time
+ * \param [IN] timeout Reception timeout [ms] [0: continuous, others timeout]
+ */
+void SX1276SetRx( uint32_t timeout );
+
+/*!
+ * \brief Start a Channel Activity Detection
+ */
+void SX1276StartCad( void );
+
+/*!
+ * \brief Reads the current RSSI value
+ *
+ * \retval rssiValue Current RSSI value in [dBm]
+ */
+int16_t SX1276ReadRssi( RadioModems_t modem );
+
+/*!
+ * \brief Writes the radio register at the specified address
+ *
+ * \param [IN]: addr Register address
+ * \param [IN]: data New register value
+ */
+void SX1276Write( uint8_t addr, uint8_t data );
+
+/*!
+ * \brief Reads the radio register at the specified address
+ *
+ * \param [IN]: addr Register address
+ * \retval data Register value
+ */
+uint8_t SX1276Read( uint8_t addr );
+
+/*!
+ * \brief Writes multiple radio registers starting at address
+ *
+ * \param [IN] addr   First Radio register address
+ * \param [IN] buffer Buffer containing the new register's values
+ * \param [IN] size   Number of registers to be written
+ */
+void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Reads multiple radio registers starting at address
+ *
+ * \param [IN] addr First Radio register address
+ * \param [OUT] buffer Buffer where to copy the registers data
+ * \param [IN] size Number of registers to be read
+ */
+void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Sets the maximum payload length.
+ *
+ * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+ * \param [IN] max        Maximum payload length in bytes
+ */
+void SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
+
+/*!
+ * \brief Set the RF Switch I/Os pins in Low Power mode
+ *
+ * \param [IN] status enable or disable
+ */
+void SX1276SetAntSwLowPower( bool status );
+
+void SX1276OnTimeoutIrq( void );
+
+#endif // __SX1276_H__

Fichier diff supprimé car celui-ci est trop grand
+ 1128 - 0
app/SX1278/sx1276Regs-Fsk.h


+ 565 - 0
app/SX1278/sx1276Regs-LoRa.h

@@ -0,0 +1,565 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2013 Semtech
+
+Description: SX1276 LoRa modem registers and bits definitions
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_REGS_LORA_H__
+#define __SX1276_REGS_LORA_H__
+
+/*!
+ * ============================================================================
+ * SX1276 Internal registers Address
+ * ============================================================================
+ */
+#define REG_LR_FIFO                                 0x00 
+// Common settings
+#define REG_LR_OPMODE                               0x01 
+#define REG_LR_FRFMSB                               0x06 
+#define REG_LR_FRFMID                               0x07
+#define REG_LR_FRFLSB                               0x08 
+// Tx settings
+#define REG_LR_PACONFIG                             0x09 
+#define REG_LR_PARAMP                               0x0A 
+#define REG_LR_OCP                                  0x0B 
+// Rx settings
+#define REG_LR_LNA                                  0x0C 
+// LoRa registers
+#define REG_LR_FIFOADDRPTR                          0x0D 
+#define REG_LR_FIFOTXBASEADDR                       0x0E 
+#define REG_LR_FIFORXBASEADDR                       0x0F 
+#define REG_LR_FIFORXCURRENTADDR                    0x10 
+#define REG_LR_IRQFLAGSMASK                         0x11 
+#define REG_LR_IRQFLAGS                             0x12 
+#define REG_LR_RXNBBYTES                            0x13 
+#define REG_LR_RXHEADERCNTVALUEMSB                  0x14 
+#define REG_LR_RXHEADERCNTVALUELSB                  0x15 
+#define REG_LR_RXPACKETCNTVALUEMSB                  0x16 
+#define REG_LR_RXPACKETCNTVALUELSB                  0x17 
+#define REG_LR_MODEMSTAT                            0x18 
+#define REG_LR_PKTSNRVALUE                          0x19 
+#define REG_LR_PKTRSSIVALUE                         0x1A 
+#define REG_LR_RSSIVALUE                            0x1B 
+#define REG_LR_HOPCHANNEL                           0x1C 
+#define REG_LR_MODEMCONFIG1                         0x1D 
+#define REG_LR_MODEMCONFIG2                         0x1E 
+#define REG_LR_SYMBTIMEOUTLSB                       0x1F 
+#define REG_LR_PREAMBLEMSB                          0x20 
+#define REG_LR_PREAMBLELSB                          0x21 
+#define REG_LR_PAYLOADLENGTH                        0x22 
+#define REG_LR_PAYLOADMAXLENGTH                     0x23 
+#define REG_LR_HOPPERIOD                            0x24 
+#define REG_LR_FIFORXBYTEADDR                       0x25
+#define REG_LR_MODEMCONFIG3                         0x26
+#define REG_LR_FEIMSB                               0x28
+#define REG_LR_FEIMID                               0x29
+#define REG_LR_FEILSB                               0x2A
+#define REG_LR_RSSIWIDEBAND                         0x2C
+#define REG_LR_TEST2F                               0x2F
+#define REG_LR_TEST30                               0x30
+#define REG_LR_DETECTOPTIMIZE                       0x31
+#define REG_LR_INVERTIQ                             0x33
+#define REG_LR_TEST36                               0x36
+#define REG_LR_DETECTIONTHRESHOLD                   0x37
+#define REG_LR_SYNCWORD                             0x39
+#define REG_LR_TEST3A                               0x3A
+#define REG_LR_INVERTIQ2                            0x3B
+
+// end of documented register in datasheet
+// I/O settings
+#define REG_LR_DIOMAPPING1                          0x40
+#define REG_LR_DIOMAPPING2                          0x41
+// Version
+#define REG_LR_VERSION                              0x42
+// Additional settings
+#define REG_LR_PLLHOP                               0x44
+#define REG_LR_TCXO                                 0x4B
+#define REG_LR_PADAC                                0x4D
+#define REG_LR_FORMERTEMP                           0x5B
+#define REG_LR_BITRATEFRAC                          0x5D
+#define REG_LR_AGCREF                               0x61
+#define REG_LR_AGCTHRESH1                           0x62
+#define REG_LR_AGCTHRESH2                           0x63
+#define REG_LR_AGCTHRESH3                           0x64
+#define REG_LR_PLL                                  0x70
+
+/*!
+ * ============================================================================
+ * SX1276 LoRa bits control definition
+ * ============================================================================
+ */
+
+/*!
+ * RegFifo
+ */
+
+/*!
+ * RegOpMode
+ */
+#define RFLR_OPMODE_LONGRANGEMODE_MASK              0x7F 
+#define RFLR_OPMODE_LONGRANGEMODE_OFF               0x00 // Default
+#define RFLR_OPMODE_LONGRANGEMODE_ON                0x80 
+
+#define RFLR_OPMODE_ACCESSSHAREDREG_MASK            0xBF 
+#define RFLR_OPMODE_ACCESSSHAREDREG_ENABLE          0x40 
+#define RFLR_OPMODE_ACCESSSHAREDREG_DISABLE         0x00 // Default
+
+#define RFLR_OPMODE_FREQMODE_ACCESS_MASK            0xF7
+#define RFLR_OPMODE_FREQMODE_ACCESS_LF              0x08 // Default
+#define RFLR_OPMODE_FREQMODE_ACCESS_HF              0x00 
+
+#define RFLR_OPMODE_MASK                            0xF8 
+#define RFLR_OPMODE_SLEEP                           0x00 
+#define RFLR_OPMODE_STANDBY                         0x01 // Default
+#define RFLR_OPMODE_SYNTHESIZER_TX                  0x02 
+#define RFLR_OPMODE_TRANSMITTER                     0x03 
+#define RFLR_OPMODE_SYNTHESIZER_RX                  0x04 
+#define RFLR_OPMODE_RECEIVER                        0x05 
+// LoRa specific modes
+#define RFLR_OPMODE_RECEIVER_SINGLE                 0x06 
+#define RFLR_OPMODE_CAD                             0x07 
+
+/*!
+ * RegFrf (MHz)
+ */
+#define RFLR_FRFMSB_434_MHZ                         0x6C // Default
+#define RFLR_FRFMID_434_MHZ                         0x80 // Default
+#define RFLR_FRFLSB_434_MHZ                         0x00 // Default
+
+/*!
+ * RegPaConfig
+ */
+#define RFLR_PACONFIG_PASELECT_MASK                 0x7F 
+#define RFLR_PACONFIG_PASELECT_PABOOST              0x80 
+#define RFLR_PACONFIG_PASELECT_RFO                  0x00 // Default
+
+#define RFLR_PACONFIG_MAX_POWER_MASK                0x8F
+
+#define RFLR_PACONFIG_OUTPUTPOWER_MASK              0xF0 
+ 
+/*!
+ * RegPaRamp
+ */
+#define RFLR_PARAMP_TXBANDFORCE_MASK                0xEF 
+#define RFLR_PARAMP_TXBANDFORCE_BAND_SEL            0x10 
+#define RFLR_PARAMP_TXBANDFORCE_AUTO                0x00 // Default
+
+#define RFLR_PARAMP_MASK                            0xF0 
+#define RFLR_PARAMP_3400_US                         0x00 
+#define RFLR_PARAMP_2000_US                         0x01 
+#define RFLR_PARAMP_1000_US                         0x02
+#define RFLR_PARAMP_0500_US                         0x03 
+#define RFLR_PARAMP_0250_US                         0x04 
+#define RFLR_PARAMP_0125_US                         0x05 
+#define RFLR_PARAMP_0100_US                         0x06 
+#define RFLR_PARAMP_0062_US                         0x07 
+#define RFLR_PARAMP_0050_US                         0x08 
+#define RFLR_PARAMP_0040_US                         0x09 // Default
+#define RFLR_PARAMP_0031_US                         0x0A 
+#define RFLR_PARAMP_0025_US                         0x0B 
+#define RFLR_PARAMP_0020_US                         0x0C 
+#define RFLR_PARAMP_0015_US                         0x0D 
+#define RFLR_PARAMP_0012_US                         0x0E 
+#define RFLR_PARAMP_0010_US                         0x0F 
+
+/*!
+ * RegOcp
+ */
+#define RFLR_OCP_MASK                               0xDF 
+#define RFLR_OCP_ON                                 0x20 // Default
+#define RFLR_OCP_OFF                                0x00   
+
+#define RFLR_OCP_TRIM_MASK                          0xE0
+#define RFLR_OCP_TRIM_045_MA                        0x00
+#define RFLR_OCP_TRIM_050_MA                        0x01   
+#define RFLR_OCP_TRIM_055_MA                        0x02 
+#define RFLR_OCP_TRIM_060_MA                        0x03 
+#define RFLR_OCP_TRIM_065_MA                        0x04 
+#define RFLR_OCP_TRIM_070_MA                        0x05 
+#define RFLR_OCP_TRIM_075_MA                        0x06 
+#define RFLR_OCP_TRIM_080_MA                        0x07  
+#define RFLR_OCP_TRIM_085_MA                        0x08
+#define RFLR_OCP_TRIM_090_MA                        0x09 
+#define RFLR_OCP_TRIM_095_MA                        0x0A 
+#define RFLR_OCP_TRIM_100_MA                        0x0B  // Default
+#define RFLR_OCP_TRIM_105_MA                        0x0C 
+#define RFLR_OCP_TRIM_110_MA                        0x0D 
+#define RFLR_OCP_TRIM_115_MA                        0x0E 
+#define RFLR_OCP_TRIM_120_MA                        0x0F 
+#define RFLR_OCP_TRIM_130_MA                        0x10
+#define RFLR_OCP_TRIM_140_MA                        0x11   
+#define RFLR_OCP_TRIM_150_MA                        0x12 
+#define RFLR_OCP_TRIM_160_MA                        0x13 
+#define RFLR_OCP_TRIM_170_MA                        0x14 
+#define RFLR_OCP_TRIM_180_MA                        0x15 
+#define RFLR_OCP_TRIM_190_MA                        0x16 
+#define RFLR_OCP_TRIM_200_MA                        0x17  
+#define RFLR_OCP_TRIM_210_MA                        0x18
+#define RFLR_OCP_TRIM_220_MA                        0x19 
+#define RFLR_OCP_TRIM_230_MA                        0x1A 
+#define RFLR_OCP_TRIM_240_MA                        0x1B
+
+/*!
+ * RegLna
+ */
+#define RFLR_LNA_GAIN_MASK                          0x1F 
+#define RFLR_LNA_GAIN_G1                            0x20 // Default
+#define RFLR_LNA_GAIN_G2                            0x40 
+#define RFLR_LNA_GAIN_G3                            0x60 
+#define RFLR_LNA_GAIN_G4                            0x80 
+#define RFLR_LNA_GAIN_G5                            0xA0 
+#define RFLR_LNA_GAIN_G6                            0xC0 
+
+#define RFLR_LNA_BOOST_LF_MASK                      0xE7 
+#define RFLR_LNA_BOOST_LF_DEFAULT                   0x00 // Default
+
+#define RFLR_LNA_BOOST_HF_MASK                      0xFC 
+#define RFLR_LNA_BOOST_HF_OFF                       0x00 // Default
+#define RFLR_LNA_BOOST_HF_ON                        0x03 
+
+/*!
+ * RegFifoAddrPtr
+ */
+#define RFLR_FIFOADDRPTR                            0x00 // Default
+
+/*!
+ * RegFifoTxBaseAddr
+ */
+#define RFLR_FIFOTXBASEADDR                         0x80 // Default
+
+/*!
+ * RegFifoTxBaseAddr
+ */
+#define RFLR_FIFORXBASEADDR                         0x00 // Default
+
+/*!
+ * RegFifoRxCurrentAddr (Read Only)
+ */
+
+/*!
+ * RegIrqFlagsMask
+ */
+#define RFLR_IRQFLAGS_RXTIMEOUT_MASK                0x80 
+#define RFLR_IRQFLAGS_RXDONE_MASK                   0x40 
+#define RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK          0x20 
+#define RFLR_IRQFLAGS_VALIDHEADER_MASK              0x10 
+#define RFLR_IRQFLAGS_TXDONE_MASK                   0x08 
+#define RFLR_IRQFLAGS_CADDONE_MASK                  0x04 
+#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL_MASK       0x02 
+#define RFLR_IRQFLAGS_CADDETECTED_MASK              0x01 
+
+/*!
+ * RegIrqFlags
+ */
+#define RFLR_IRQFLAGS_RXTIMEOUT                     0x80 
+#define RFLR_IRQFLAGS_RXDONE                        0x40 
+#define RFLR_IRQFLAGS_PAYLOADCRCERROR               0x20 
+#define RFLR_IRQFLAGS_VALIDHEADER                   0x10 
+#define RFLR_IRQFLAGS_TXDONE                        0x08 
+#define RFLR_IRQFLAGS_CADDONE                       0x04 
+#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL            0x02 
+#define RFLR_IRQFLAGS_CADDETECTED                   0x01 
+
+/*!
+ * RegFifoRxNbBytes (Read Only)
+ */
+
+/*!
+ * RegRxHeaderCntValueMsb (Read Only)
+ */
+
+/*!
+ * RegRxHeaderCntValueLsb (Read Only)
+ */
+
+/*!
+ * RegRxPacketCntValueMsb (Read Only)
+ */
+
+/*!
+ * RegRxPacketCntValueLsb (Read Only)
+ */
+
+/*!
+ * RegModemStat (Read Only)
+ */
+#define RFLR_MODEMSTAT_RX_CR_MASK                   0x1F 
+#define RFLR_MODEMSTAT_MODEM_STATUS_MASK            0xE0 
+ 
+/*!
+ * RegPktSnrValue (Read Only)
+ */
+
+/*!
+ * RegPktRssiValue (Read Only)
+ */
+
+/*!
+ * RegRssiValue (Read Only)
+ */
+
+/*!
+ * RegHopChannel (Read Only)
+ */
+#define RFLR_HOPCHANNEL_PLL_LOCK_TIMEOUT_MASK       0x7F 
+#define RFLR_HOPCHANNEL_PLL_LOCK_FAIL               0x80 
+#define RFLR_HOPCHANNEL_PLL_LOCK_SUCCEED            0x00 // Default
+                                                    
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_MASK           0xBF
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_ON             0x40
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_OFF            0x00 // Default
+
+#define RFLR_HOPCHANNEL_CHANNEL_MASK                0x3F 
+
+/*!
+ * RegModemConfig1
+ */
+#define RFLR_MODEMCONFIG1_BW_MASK                   0x0F 
+#define RFLR_MODEMCONFIG1_BW_7_81_KHZ               0x00 
+#define RFLR_MODEMCONFIG1_BW_10_41_KHZ              0x10 
+#define RFLR_MODEMCONFIG1_BW_15_62_KHZ              0x20 
+#define RFLR_MODEMCONFIG1_BW_20_83_KHZ              0x30 
+#define RFLR_MODEMCONFIG1_BW_31_25_KHZ              0x40 
+#define RFLR_MODEMCONFIG1_BW_41_66_KHZ              0x50 
+#define RFLR_MODEMCONFIG1_BW_62_50_KHZ              0x60 
+#define RFLR_MODEMCONFIG1_BW_125_KHZ                0x70 // Default
+#define RFLR_MODEMCONFIG1_BW_250_KHZ                0x80 
+#define RFLR_MODEMCONFIG1_BW_500_KHZ                0x90 
+                                                    
+#define RFLR_MODEMCONFIG1_CODINGRATE_MASK           0xF1 
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_5            0x02
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_6            0x04 // Default
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_7            0x06 
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_8            0x08 
+                                                    
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK       0xFE 
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_ON         0x01 
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF        0x00 // Default
+
+/*!
+ * RegModemConfig2
+ */
+#define RFLR_MODEMCONFIG2_SF_MASK                   0x0F 
+#define RFLR_MODEMCONFIG2_SF_6                      0x60 
+#define RFLR_MODEMCONFIG2_SF_7                      0x70 // Default
+#define RFLR_MODEMCONFIG2_SF_8                      0x80 
+#define RFLR_MODEMCONFIG2_SF_9                      0x90 
+#define RFLR_MODEMCONFIG2_SF_10                     0xA0 
+#define RFLR_MODEMCONFIG2_SF_11                     0xB0 
+#define RFLR_MODEMCONFIG2_SF_12                     0xC0 
+
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK     0xF7 
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON       0x08 
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF      0x00 
+
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK         0xFB 
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON           0x04 
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF          0x00 // Default
+ 
+#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK       0xFC 
+#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB            0x00 // Default
+
+/*!
+ * RegSymbTimeoutLsb
+ */
+#define RFLR_SYMBTIMEOUTLSB_SYMBTIMEOUT             0x64 // Default
+
+/*!
+ * RegPreambleLengthMsb
+ */
+#define RFLR_PREAMBLELENGTHMSB                      0x00 // Default
+
+/*!
+ * RegPreambleLengthLsb
+ */
+#define RFLR_PREAMBLELENGTHLSB                      0x08 // Default
+
+/*!
+ * RegPayloadLength
+ */
+#define RFLR_PAYLOADLENGTH                          0x0E // Default
+
+/*!
+ * RegPayloadMaxLength
+ */
+#define RFLR_PAYLOADMAXLENGTH                       0xFF // Default
+
+/*!
+ * RegHopPeriod
+ */
+#define RFLR_HOPPERIOD_FREQFOPPINGPERIOD            0x00 // Default
+
+/*!
+ * RegFifoRxByteAddr (Read Only)
+ */
+
+/*!
+ * RegModemConfig3
+ */
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK  0xF7 
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON    0x08 
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF   0x00 // Default
+
+#define RFLR_MODEMCONFIG3_AGCAUTO_MASK              0xFB 
+#define RFLR_MODEMCONFIG3_AGCAUTO_ON                0x04 // Default 
+#define RFLR_MODEMCONFIG3_AGCAUTO_OFF               0x00 
+
+/*!
+ * RegFeiMsb (Read Only)
+ */
+
+/*!
+ * RegFeiMid (Read Only)
+ */
+
+/*!
+ * RegFeiLsb (Read Only)
+ */
+
+/*!
+ * RegRssiWideband (Read Only)
+ */
+
+/*!
+ * RegDetectOptimize
+ */
+#define RFLR_DETECTIONOPTIMIZE_MASK                 0xF8
+#define RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12          0x03 // Default
+#define RFLR_DETECTIONOPTIMIZE_SF6                  0x05
+
+/*!
+ * RegInvertIQ
+ */
+#define RFLR_INVERTIQ_RX_MASK                       0xBF
+#define RFLR_INVERTIQ_RX_OFF                        0x00
+#define RFLR_INVERTIQ_RX_ON                         0x40
+#define RFLR_INVERTIQ_TX_MASK                       0xFE
+#define RFLR_INVERTIQ_TX_OFF                        0x01
+#define RFLR_INVERTIQ_TX_ON                         0x00
+
+/*!
+ * RegDetectionThreshold
+ */
+#define RFLR_DETECTIONTHRESH_SF7_TO_SF12            0x0A // Default
+#define RFLR_DETECTIONTHRESH_SF6                    0x0C
+
+/*!
+ * RegInvertIQ2
+ */
+#define RFLR_INVERTIQ2_ON                           0x19
+#define RFLR_INVERTIQ2_OFF                          0x1D
+
+/*!
+ * RegDioMapping1
+ */
+#define RFLR_DIOMAPPING1_DIO0_MASK                  0x3F
+#define RFLR_DIOMAPPING1_DIO0_00                    0x00  // Default
+#define RFLR_DIOMAPPING1_DIO0_01                    0x40
+#define RFLR_DIOMAPPING1_DIO0_10                    0x80
+#define RFLR_DIOMAPPING1_DIO0_11                    0xC0
+
+#define RFLR_DIOMAPPING1_DIO1_MASK                  0xCF
+#define RFLR_DIOMAPPING1_DIO1_00                    0x00  // Default
+#define RFLR_DIOMAPPING1_DIO1_01                    0x10
+#define RFLR_DIOMAPPING1_DIO1_10                    0x20
+#define RFLR_DIOMAPPING1_DIO1_11                    0x30
+
+#define RFLR_DIOMAPPING1_DIO2_MASK                  0xF3
+#define RFLR_DIOMAPPING1_DIO2_00                    0x00  // Default
+#define RFLR_DIOMAPPING1_DIO2_01                    0x04
+#define RFLR_DIOMAPPING1_DIO2_10                    0x08
+#define RFLR_DIOMAPPING1_DIO2_11                    0x0C
+
+#define RFLR_DIOMAPPING1_DIO3_MASK                  0xFC
+#define RFLR_DIOMAPPING1_DIO3_00                    0x00  // Default
+#define RFLR_DIOMAPPING1_DIO3_01                    0x01
+#define RFLR_DIOMAPPING1_DIO3_10                    0x02
+#define RFLR_DIOMAPPING1_DIO3_11                    0x03
+
+/*!
+ * RegDioMapping2
+ */
+#define RFLR_DIOMAPPING2_DIO4_MASK                  0x3F
+#define RFLR_DIOMAPPING2_DIO4_00                    0x00  // Default
+#define RFLR_DIOMAPPING2_DIO4_01                    0x40
+#define RFLR_DIOMAPPING2_DIO4_10                    0x80
+#define RFLR_DIOMAPPING2_DIO4_11                    0xC0
+
+#define RFLR_DIOMAPPING2_DIO5_MASK                  0xCF
+#define RFLR_DIOMAPPING2_DIO5_00                    0x00  // Default
+#define RFLR_DIOMAPPING2_DIO5_01                    0x10
+#define RFLR_DIOMAPPING2_DIO5_10                    0x20
+#define RFLR_DIOMAPPING2_DIO5_11                    0x30
+
+#define RFLR_DIOMAPPING2_MAP_MASK                   0xFE
+#define RFLR_DIOMAPPING2_MAP_PREAMBLEDETECT         0x01
+#define RFLR_DIOMAPPING2_MAP_RSSI                   0x00  // Default
+
+/*!
+ * RegVersion (Read Only)
+ */
+
+/*!
+ * RegPllHop
+ */
+#define RFLR_PLLHOP_FASTHOP_MASK                    0x7F
+#define RFLR_PLLHOP_FASTHOP_ON                      0x80
+#define RFLR_PLLHOP_FASTHOP_OFF                     0x00 // Default
+
+/*!
+ * RegTcxo
+ */
+#define RFLR_TCXO_TCXOINPUT_MASK                    0xEF
+#define RFLR_TCXO_TCXOINPUT_ON                      0x10
+#define RFLR_TCXO_TCXOINPUT_OFF                     0x00  // Default
+
+/*!
+ * RegPaDac
+ */
+#define RFLR_PADAC_20DBM_MASK                       0xF8
+#define RFLR_PADAC_20DBM_ON                         0x07
+#define RFLR_PADAC_20DBM_OFF                        0x04  // Default
+
+/*!
+ * RegFormerTemp
+ */
+
+/*!
+ * RegBitrateFrac
+ */
+#define RF_BITRATEFRAC_MASK                         0xF0
+
+/*!
+ * RegAgcRef
+ */
+
+/*!
+ * RegAgcThresh1
+ */
+
+/*!
+ * RegAgcThresh2
+ */
+
+/*!
+ * RegAgcThresh3
+ */
+
+/*!
+ * RegPll
+ */
+#define RF_PLL_BANDWIDTH_MASK                       0x3F
+#define RF_PLL_BANDWIDTH_75                         0x00
+#define RF_PLL_BANDWIDTH_150                        0x40
+#define RF_PLL_BANDWIDTH_225                        0x80
+#define RF_PLL_BANDWIDTH_300                        0xC0  // Default
+
+#endif // __SX1276_REGS_LORA_H__

+ 109 - 0
app/UCOS-II/CONFIG/app_cfg.h

@@ -0,0 +1,109 @@
+/*
+*********************************************************************************************************
+*                                              EXAMPLE CODE
+*
+*                          (c) Copyright 2003-2013; Micrium, Inc.; Weston, FL
+*
+*               All rights reserved.  Protected by international copyright laws.
+*               Knowledge of the source code may NOT be used to develop a similar product.
+*               Please help us continue to provide the Embedded community with the finest
+*               software available.  Your honesty is greatly appreciated.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                                      APPLICATION CONFIGURATION
+*
+*                                     ST Microelectronics STM32
+*                                              on the
+*
+*                                     Micrium uC-Eval-STM32F107
+*                                        Evaluation Board
+*
+* Filename      : app_cfg.h
+* Version       : V1.00
+* Programmer(s) : EHS
+*********************************************************************************************************
+*/
+
+#ifndef  __APP_CFG_H__
+#define  __APP_CFG_H__
+
+
+/*
+*********************************************************************************************************
+*                                       MODULE ENABLE / DISABLE
+*********************************************************************************************************
+*/
+
+#define  APP_CFG_SERIAL_EN                          DEF_ENABLED
+
+
+#define  BSP_CFG_LED_SPI2_EN                        DEF_ENABLED       /* Enable/disable LEDs on SPI port.                     */
+#define  BSP_CFG_LED_PIOC_EN                        DEF_ENABLED       /* Enable/disable PIOC LEDs.                            */
+
+
+/*
+*********************************************************************************************************
+*                                              TASKS NAMES
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*                                            TASK PRIORITIES
+*********************************************************************************************************
+*/
+
+#define  APP_TASK_START_PRIO                        4
+
+#define  OS_TASK_TMR_PRIO                   (OS_LOWEST_PRIO - 2)
+
+
+/*
+*********************************************************************************************************
+*                                            TASK STACK SIZES
+*                             Size of the task stacks (# of OS_STK entries)
+*********************************************************************************************************
+*/
+
+#define  APP_TASK_START_STK_SIZE                    128
+#define  APP_CFG_TASK_LED_STK_SIZE                  128
+
+#define  BUFF_SIZE                                  1000
+
+
+/*
+*********************************************************************************************************
+*                                    BSP CONFIGURATION: RS-232
+*********************************************************************************************************
+*/
+
+#define  BSP_CFG_SER_COMM_SEL             			BSP_SER_COMM_UART_02
+#define  BSP_CFG_TS_TMR_SEL                    		2
+
+
+/*
+*********************************************************************************************************
+*                                     TRACE / DEBUG CONFIGURATION
+*********************************************************************************************************
+*/
+
+#if 0
+#define  TRACE_LEVEL_OFF                       		0
+#define  TRACE_LEVEL_INFO                      		1
+#define  TRACE_LEVEL_DEBUG                     		2
+#endif
+
+#define  APP_TRACE_LEVEL                			TRACE_LEVEL_INFO
+#define  APP_TRACE                      			BSP_Ser_Printf
+
+#define  APP_TRACE_INFO(x)            ((APP_TRACE_LEVEL >= TRACE_LEVEL_INFO)  ? (void)(APP_TRACE x) : (void)0)
+#define  APP_TRACE_DEBUG(x)           ((APP_TRACE_LEVEL >= TRACE_LEVEL_DEBUG) ? (void)(APP_TRACE x) : (void)0)
+
+
+
+#endif

+ 91 - 0
app/UCOS-II/CONFIG/includes.h

@@ -0,0 +1,91 @@
+/*
+*********************************************************************************************************
+*                                              EXAMPLE CODE
+*
+*                          (c) Copyright 2003-2013; Micrium, Inc.; Weston, FL
+*
+*               All rights reserved.  Protected by international copyright laws.
+*               Knowledge of the source code may NOT be used to develop a similar product.
+*               Please help us continue to provide the Embedded community with the finest
+*               software available.  Your honesty is greatly appreciated.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                                           MASTER INCLUDES
+*
+*                                     ST Microelectronics STM32
+*                                              on the
+*
+*                                     Micrium uC-Eval-STM32F107
+*                                        Evaluation Board
+*
+* Filename      : includes.h
+* Version       : V1.00
+* Programmer(s) : EHS
+*********************************************************************************************************
+*/
+
+#ifndef  INCLUDES_PRESENT
+#define  INCLUDES_PRESENT
+
+
+/*
+*********************************************************************************************************
+*                                         STANDARD LIBRARIES
+*********************************************************************************************************
+*/
+
+#include  <stdarg.h>
+#include  <stdio.h>
+#include  <stdlib.h>
+#include  <math.h>
+
+
+/*
+*********************************************************************************************************
+*                                              LIBRARIES
+*********************************************************************************************************
+*/
+
+
+
+
+/*
+*********************************************************************************************************
+*                                              APP / BSP
+*********************************************************************************************************
+*/
+#include "delay.h"
+
+
+
+/*
+*********************************************************************************************************
+*                                                 OS
+*********************************************************************************************************
+*/
+
+#include  <ucos_ii.h>
+
+
+/*
+*********************************************************************************************************
+*                                                 ST
+*********************************************************************************************************
+*/
+#include "stm32f2xx.h"
+
+
+
+/*
+*********************************************************************************************************
+*                                            INCLUDES END
+*********************************************************************************************************
+*/
+
+
+#endif
+

+ 143 - 0
app/UCOS-II/CONFIG/os_cfg.h

@@ -0,0 +1,143 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                  uC/OS-II Configuration File for V2.8x
+*
+*                               (c) Copyright 2005-2009, Micrium, Weston, FL
+*                                          All Rights Reserved
+*
+*
+* File    : OS_CFG.H
+* By      : Jean J. Labrosse
+* Version : V2.88
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micri祄 to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef OS_CFG_H
+#define OS_CFG_H
+
+
+                                       /* ---------------------- MISCELLANEOUS ----------------------- */
+#define OS_APP_HOOKS_EN           0    /* Application-defined hooks are called from the uC/OS-II hooks */
+#define OS_ARG_CHK_EN             0    /* Enable (1) or Disable (0) argument checking                  */
+#define OS_CPU_HOOKS_EN           1    /* uC/OS-II hooks are found in the processor port files         */
+
+#define OS_DEBUG_EN               0    /* Enable(1) debug variables                                    */
+
+#define OS_EVENT_MULTI_EN         0    /* Include code for OSEventPendMulti()                          */
+#define OS_EVENT_NAME_EN          1    /* Enable names for Sem, Mutex, Mbox and Q                      */
+
+#define OS_LOWEST_PRIO           63    /* Defines the lowest priority that can be assigned ...         */
+                                       /* ... MUST NEVER be higher than 254!                           */
+
+#define OS_MAX_EVENTS            10    /* Max. number of event control blocks in your application      */
+#define OS_MAX_FLAGS              5    /* Max. number of Event Flag Groups    in your application      */
+#define OS_MAX_MEM_PART           5    /* Max. number of memory partitions                             */
+#define OS_MAX_QS                 5    /* Max. number of queue control blocks in your application      */
+#define OS_MAX_TASKS             10    /* Max. number of tasks in your application, MUST be >= 2       */
+
+#define OS_SCHED_LOCK_EN          1    /* Include code for OSSchedLock() and OSSchedUnlock()           */
+
+#define OS_TICK_STEP_EN           1    /* Enable tick stepping feature for uC/OS-View                  */
+#define OS_TICKS_PER_SEC        200    /* Set the number of ticks in one second                        */
+
+
+                                       /* --------------------- TASK STACK SIZE ---------------------- */
+#define OS_TASK_TMR_STK_SIZE    128    /* Timer      task stack size (# of OS_STK wide entries)        */
+#define OS_TASK_STAT_STK_SIZE   128    /* Statistics task stack size (# of OS_STK wide entries)        */
+#define OS_TASK_IDLE_STK_SIZE   128    /* Idle       task stack size (# of OS_STK wide entries)        */
+
+
+                                       /* --------------------- TASK MANAGEMENT ---------------------- */
+#define OS_TASK_CHANGE_PRIO_EN    1    /*     Include code for OSTaskChangePrio()                      */
+#define OS_TASK_CREATE_EN         1    /*     Include code for OSTaskCreate()                          */
+#define OS_TASK_CREATE_EXT_EN     1    /*     Include code for OSTaskCreateExt()                       */
+#define OS_TASK_DEL_EN            1    /*     Include code for OSTaskDel()                             */
+#define OS_TASK_NAME_EN           1    /*     Enable task names                                        */
+#define OS_TASK_PROFILE_EN        1    /*     Include variables in OS_TCB for profiling                */
+#define OS_TASK_QUERY_EN          1    /*     Include code for OSTaskQuery()                           */
+#define OS_TASK_STAT_EN           1    /*     Enable (1) or Disable(0) the statistics task             */
+#define OS_TASK_STAT_STK_CHK_EN   1    /*     Check task stacks from statistic task                    */
+#define OS_TASK_SUSPEND_EN        1    /*     Include code for OSTaskSuspend() and OSTaskResume()      */
+#define OS_TASK_SW_HOOK_EN        1    /*     Include code for OSTaskSwHook()                          */
+#define OS_TASK_REG_TBL_SIZE      1    /*     Size of task variables array (#of INT32U entries)        */
+
+
+                                       /* ----------------------- EVENT FLAGS ------------------------ */
+#define OS_FLAG_EN                1    /* Enable (1) or Disable (0) code generation for EVENT FLAGS    */
+#define OS_FLAG_ACCEPT_EN         1    /*     Include code for OSFlagAccept()                          */
+#define OS_FLAG_DEL_EN            1    /*     Include code for OSFlagDel()                             */
+#define OS_FLAG_NAME_EN           1    /*     Enable names for event flag group                        */
+#define OS_FLAG_QUERY_EN          1    /*     Include code for OSFlagQuery()                           */
+#define OS_FLAG_WAIT_CLR_EN       1    /* Include code for Wait on Clear EVENT FLAGS                   */
+#define OS_FLAGS_NBITS           16    /* Size in #bits of OS_FLAGS data type (8, 16 or 32)            */
+
+
+                                       /* -------------------- MESSAGE MAILBOXES --------------------- */
+#define OS_MBOX_EN                1    /* Enable (1) or Disable (0) code generation for MAILBOXES      */
+#define OS_MBOX_ACCEPT_EN         1    /*     Include code for OSMboxAccept()                          */
+#define OS_MBOX_DEL_EN            1    /*     Include code for OSMboxDel()                             */
+#define OS_MBOX_PEND_ABORT_EN     1    /*     Include code for OSMboxPendAbort()                       */
+#define OS_MBOX_POST_EN           1    /*     Include code for OSMboxPost()                            */
+#define OS_MBOX_POST_OPT_EN       1    /*     Include code for OSMboxPostOpt()                         */
+#define OS_MBOX_QUERY_EN          1    /*     Include code for OSMboxQuery()                           */
+
+
+                                       /* --------------------- MEMORY MANAGEMENT -------------------- */
+#define OS_MEM_EN                 1    /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */
+#define OS_MEM_NAME_EN            1    /*     Enable memory partition names                            */
+#define OS_MEM_QUERY_EN           1    /*     Include code for OSMemQuery()                            */
+
+
+                                       /* ---------------- MUTUAL EXCLUSION SEMAPHORES --------------- */
+#define OS_MUTEX_EN               1    /* Enable (1) or Disable (0) code generation for MUTEX          */
+#define OS_MUTEX_ACCEPT_EN        1    /*     Include code for OSMutexAccept()                         */
+#define OS_MUTEX_DEL_EN           1    /*     Include code for OSMutexDel()                            */
+#define OS_MUTEX_QUERY_EN         1    /*     Include code for OSMutexQuery()                          */
+
+
+                                       /* ---------------------- MESSAGE QUEUES ---------------------- */
+#define OS_Q_EN                   1    /* Enable (1) or Disable (0) code generation for QUEUES         */
+#define OS_Q_ACCEPT_EN            1    /*     Include code for OSQAccept()                             */
+#define OS_Q_DEL_EN               1    /*     Include code for OSQDel()                                */
+#define OS_Q_FLUSH_EN             1    /*     Include code for OSQFlush()                              */
+#define OS_Q_PEND_ABORT_EN        1    /*     Include code for OSQPendAbort()                          */
+#define OS_Q_POST_EN              1    /*     Include code for OSQPost()                               */
+#define OS_Q_POST_FRONT_EN        1    /*     Include code for OSQPostFront()                          */
+#define OS_Q_POST_OPT_EN          1    /*     Include code for OSQPostOpt()                            */
+#define OS_Q_QUERY_EN             1    /*     Include code for OSQQuery()                              */
+
+
+                                       /* ------------------------ SEMAPHORES ------------------------ */
+#define OS_SEM_EN                 1    /* Enable (1) or Disable (0) code generation for SEMAPHORES     */
+#define OS_SEM_ACCEPT_EN          1    /*    Include code for OSSemAccept()                            */
+#define OS_SEM_DEL_EN             1    /*    Include code for OSSemDel()                               */
+#define OS_SEM_PEND_ABORT_EN      1    /*    Include code for OSSemPendAbort()                         */
+#define OS_SEM_QUERY_EN           1    /*    Include code for OSSemQuery()                             */
+#define OS_SEM_SET_EN             1    /*    Include code for OSSemSet()                               */
+
+
+                                       /* --------------------- TIME MANAGEMENT ---------------------- */
+#define OS_TIME_DLY_HMSM_EN       1    /*     Include code for OSTimeDlyHMSM()                         */
+#define OS_TIME_DLY_RESUME_EN     1    /*     Include code for OSTimeDlyResume()                       */
+#define OS_TIME_GET_SET_EN        1    /*     Include code for OSTimeGet() and OSTimeSet()             */
+#define OS_TIME_TICK_HOOK_EN      1    /*     Include code for OSTimeTickHook()                        */
+
+
+                                       /* --------------------- TIMER MANAGEMENT --------------------- */
+#define OS_TMR_EN                 1    /* Enable (1) or Disable (0) code generation for TIMERS         */
+#define OS_TMR_CFG_MAX           16    /*     Maximum number of timers                                 */
+#define OS_TMR_CFG_NAME_EN        1    /*     Determine timer names                                    */
+#define OS_TMR_CFG_WHEEL_SIZE     8    /*     Size of timer wheel (#Spokes)                            */
+#define OS_TMR_CFG_TICKS_PER_SEC 100    /*     Rate at which timer management task runs (Hz)            */
+#define OS_TASK_TMR_PRIO					3u   //软件定时器的优先级设为最高,3 
+#endif

+ 128 - 0
app/UCOS-II/Ports/os_cpu.h

@@ -0,0 +1,128 @@
+/*
+*********************************************************************************************************
+*                                               uC/OS-II
+*                                         The Real-Time Kernel
+*
+*
+*                                (c) Copyright 2006, Micrium, Weston, FL
+*                                          All Rights Reserved
+*
+*                                           ARM Cortex-M3 Port
+*
+* File      : OS_CPU.H
+* Version   : V2.89
+* By        : Jean J. Labrosse
+*             Brian Nagel
+*
+* For       : ARMv7M Cortex-M3
+* Mode      : Thumb2
+* Toolchain : RealView Development Suite
+*             RealView Microcontroller Development Kit (MDK)
+*             ARM Developer Suite (ADS)
+*             Keil uVision
+*********************************************************************************************************
+*/
+
+#ifndef  OS_CPU_H
+#define  OS_CPU_H
+
+
+#ifdef   OS_CPU_GLOBALS
+#define  OS_CPU_EXT
+#else
+#define  OS_CPU_EXT  extern
+#endif
+
+#ifndef  OS_CPU_EXCEPT_STK_SIZE
+#define  OS_CPU_EXCEPT_STK_SIZE    128u          /* Default exception stack size is 128 OS_STK entries */
+#endif
+
+/*
+*********************************************************************************************************
+*                                              DATA TYPES
+*                                         (Compiler Specific)
+*********************************************************************************************************
+*/
+
+typedef unsigned char  BOOLEAN;
+typedef unsigned char  INT8U;                    /* Unsigned  8 bit quantity                           */
+typedef signed   char  INT8S;                    /* Signed    8 bit quantity                           */
+typedef unsigned short INT16U;                   /* Unsigned 16 bit quantity                           */
+typedef signed   short INT16S;                   /* Signed   16 bit quantity                           */
+typedef unsigned int   INT32U;                   /* Unsigned 32 bit quantity                           */
+typedef signed   int   INT32S;                   /* Signed   32 bit quantity                           */
+typedef float          FP32;                     /* Single precision floating point                    */
+typedef double         FP64;                     /* Double precision floating point                    */
+
+typedef unsigned int   OS_STK;                   /* Each stack entry is 32-bit wide                    */
+typedef unsigned int   OS_CPU_SR;                /* Define size of CPU status register (PSR = 32 bits) */
+
+/*
+*********************************************************************************************************
+*                                              Cortex-M3
+*                                      Critical Section Management
+*
+* Method #1:  Disable/Enable interrupts using simple instructions.  After critical section, interrupts
+*             will be enabled even if they were disabled before entering the critical section.
+*             NOT IMPLEMENTED
+*
+* Method #2:  Disable/Enable interrupts by preserving the state of interrupts.  In other words, if
+*             interrupts were disabled before entering the critical section, they will be disabled when
+*             leaving the critical section.
+*             NOT IMPLEMENTED
+*
+* Method #3:  Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking you
+*             would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then
+*             disable interrupts.  'cpu_sr' is allocated in all of uC/OS-II's functions that need to
+*             disable interrupts.  You would restore the interrupt disable state by copying back 'cpu_sr'
+*             into the CPU's status register.
+*********************************************************************************************************
+*/
+
+#define  OS_CRITICAL_METHOD   3u
+
+#if OS_CRITICAL_METHOD == 3u
+#define  OS_ENTER_CRITICAL()  {cpu_sr = OS_CPU_SR_Save();}
+#define  OS_EXIT_CRITICAL()   {OS_CPU_SR_Restore(cpu_sr);}
+#endif
+
+/*
+*********************************************************************************************************
+*                                        Cortex-M3 Miscellaneous
+*********************************************************************************************************
+*/
+
+#define  OS_STK_GROWTH        1u                  /* Stack grows from HIGH to LOW memory on ARM        */
+
+#define  OS_TASK_SW()         OSCtxSw()
+
+/*
+*********************************************************************************************************
+*                                            GLOBAL VARIABLES
+*********************************************************************************************************
+*/
+
+OS_CPU_EXT  OS_STK   OS_CPU_ExceptStk[OS_CPU_EXCEPT_STK_SIZE];
+OS_CPU_EXT  OS_STK  *OS_CPU_ExceptStkBase;
+
+/*
+*********************************************************************************************************
+*                                              PROTOTYPES
+*********************************************************************************************************
+*/
+
+#if OS_CRITICAL_METHOD == 3u                      /* See OS_CPU_A.ASM                                  */
+OS_CPU_SR  OS_CPU_SR_Save(void);
+void       OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);
+#endif
+
+void       OSCtxSw(void);
+void       OSIntCtxSw(void);
+void       OSStartHighRdy(void);
+
+void       OS_CPU_PendSVHandler(void);
+
+                                                  /* See OS_CPU_C.C                                    */
+void       OS_CPU_SysTickHandler(void);
+void       OS_CPU_SysTickInit(INT32U  cnts);
+#endif

+ 246 - 0
app/UCOS-II/Ports/os_cpu_a.asm

@@ -0,0 +1,246 @@
+;********************************************************************************************************
+;                                               uC/OS-II
+;                                         The Real-Time Kernel
+;
+;                               (c) Copyright 1992-2006, Micrium, Weston, FL
+;                                          All Rights Reserved
+;
+;                                           ARM Cortex-M3 Port
+;
+; File      : OS_CPU_A.ASM
+; Version   : V2.89
+; By        : Jean J. Labrosse
+;             Brian Nagel
+;
+; For       : ARMv7M Cortex-M3
+; Mode      : Thumb2
+; Toolchain : RealView Development Suite
+;             RealView Microcontroller Development Kit (MDK)
+;             ARM Developer Suite (ADS)
+;             Keil uVision
+;********************************************************************************************************
+
+;********************************************************************************************************
+;                                           PUBLIC FUNCTIONS
+;********************************************************************************************************
+
+    EXTERN  OSRunning                                           ; External references
+    EXTERN  OSPrioCur
+    EXTERN  OSPrioHighRdy
+    EXTERN  OSTCBCur
+    EXTERN  OSTCBHighRdy
+    EXTERN  OSIntExit
+    EXTERN  OSTaskSwHook
+	EXTERN  OS_CPU_ExceptStkBase
+
+
+    EXPORT  OS_CPU_SR_Save                                      ; Functions declared in this file
+    EXPORT  OS_CPU_SR_Restore
+    EXPORT  OSStartHighRdy
+    EXPORT  OSCtxSw
+    EXPORT  OSIntCtxSw
+    EXPORT  PendSV_Handler
+
+;********************************************************************************************************
+;                                                EQUATES
+;********************************************************************************************************
+
+NVIC_INT_CTRL   EQU     0xE000ED04                              ; Interrupt control state register.
+NVIC_SYSPRI14   EQU     0xE000ED22                              ; System priority register (priority 14).
+NVIC_PENDSV_PRI EQU           0xFF                              ; PendSV priority value (lowest).
+NVIC_PENDSVSET  EQU     0x10000000                              ; Value to trigger PendSV exception.
+
+;********************************************************************************************************
+;                                      CODE GENERATION DIRECTIVES
+;********************************************************************************************************
+
+    AREA |.text|, CODE, READONLY, ALIGN=2
+    THUMB
+    REQUIRE8
+    PRESERVE8
+
+;********************************************************************************************************
+;                                   CRITICAL SECTION METHOD 3 FUNCTIONS
+;
+; Description: Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking you
+;              would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then
+;              disable interrupts.  'cpu_sr' is allocated in all of uC/OS-II's functions that need to
+;              disable interrupts.  You would restore the interrupt disable state by copying back 'cpu_sr'
+;              into the CPU's status register.
+;
+; Prototypes :     OS_CPU_SR  OS_CPU_SR_Save(void);
+;                  void       OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);
+;
+;
+; Note(s)    : 1) These functions are used in general like this:
+;
+;                 void Task (void *p_arg)
+;                 {
+;                 #if OS_CRITICAL_METHOD == 3          /* Allocate storage for CPU status register */
+;                     OS_CPU_SR  cpu_sr;
+;                 #endif
+;
+;                          :
+;                          :
+;                     OS_ENTER_CRITICAL();             /* cpu_sr = OS_CPU_SaveSR();                */
+;                          :
+;                          :
+;                     OS_EXIT_CRITICAL();              /* OS_CPU_RestoreSR(cpu_sr);                */
+;                          :
+;                          :
+;                 }
+;********************************************************************************************************
+
+OS_CPU_SR_Save
+    MRS     R0, PRIMASK                                         ; Set prio int mask to mask all (except faults)
+    CPSID   I
+    BX      LR
+
+OS_CPU_SR_Restore
+    MSR     PRIMASK, R0
+    BX      LR
+
+;********************************************************************************************************
+;                                          START MULTITASKING
+;                                       void OSStartHighRdy(void)
+;
+; Note(s) : 1) This function triggers a PendSV exception (essentially, causes a context switch) to cause
+;              the first task to start.
+;
+;           2) OSStartHighRdy() MUST:
+;              a) Setup PendSV exception priority to lowest;
+;              b) Set initial PSP to 0, to tell context switcher this is first run;
+;              c) Set the main stack to OS_CPU_ExceptStkBase;
+;              d) Set OSRunning to TRUE;
+;              e) Trigger PendSV exception;
+;              f) Enable interrupts (tasks will run with interrupts enabled).
+;********************************************************************************************************
+
+OSStartHighRdy
+    LDR     R0, =NVIC_SYSPRI14                                  ; Set the PendSV exception priority
+    LDR     R1, =NVIC_PENDSV_PRI
+    STRB    R1, [R0]
+
+    MOVS    R0, #0                                              ; Set the PSP to 0 for initial context switch call
+    MSR     PSP, R0
+
+    LDR     R0, =OS_CPU_ExceptStkBase                           ; Initialize the MSP to the OS_CPU_ExceptStkBase
+    LDR     R1, [R0]
+    MSR     MSP, R1    
+
+    LDR     R0, =OSRunning                                      ; OSRunning = TRUE
+    MOVS    R1, #1
+    STRB    R1, [R0]
+
+    LDR     R0, =NVIC_INT_CTRL                                  ; Trigger the PendSV exception (causes context switch)
+    LDR     R1, =NVIC_PENDSVSET
+    STR     R1, [R0]
+
+    CPSIE   I                                                   ; Enable interrupts at processor level
+
+OSStartHang
+    B       OSStartHang                                         ; Should never get here
+
+
+;********************************************************************************************************
+;                               PERFORM A CONTEXT SWITCH (From task level)
+;                                           void OSCtxSw(void)
+;
+; Note(s) : 1) OSCtxSw() is called when OS wants to perform a task context switch.  This function
+;              triggers the PendSV exception which is where the real work is done.
+;********************************************************************************************************
+
+OSCtxSw
+    LDR     R0, =NVIC_INT_CTRL                                  ; Trigger the PendSV exception (causes context switch)
+    LDR     R1, =NVIC_PENDSVSET
+    STR     R1, [R0]
+    BX      LR
+
+;********************************************************************************************************
+;                             PERFORM A CONTEXT SWITCH (From interrupt level)
+;                                         void OSIntCtxSw(void)
+;
+; Notes:    1) OSIntCtxSw() is called by OSIntExit() when it determines a context switch is needed as
+;              the result of an interrupt.  This function simply triggers a PendSV exception which will
+;              be handled when there are no more interrupts active and interrupts are enabled.
+;********************************************************************************************************
+
+OSIntCtxSw
+    LDR     R0, =NVIC_INT_CTRL                                  ; Trigger the PendSV exception (causes context switch)
+    LDR     R1, =NVIC_PENDSVSET
+    STR     R1, [R0]
+    BX      LR
+
+;********************************************************************************************************
+;                                         HANDLE PendSV EXCEPTION
+;                                     void OS_CPU_PendSVHandler(void)
+;
+; Note(s) : 1) PendSV is used to cause a context switch.  This is a recommended method for performing
+;              context switches with Cortex-M3.  This is because the Cortex-M3 auto-saves half of the
+;              processor context on any exception, and restores same on return from exception.  So only
+;              saving of R4-R11 is required and fixing up the stack pointers.  Using the PendSV exception
+;              this way means that context saving and restoring is identical whether it is initiated from
+;              a thread or occurs due to an interrupt or exception.
+;
+;           2) Pseudo-code is:
+;              a) Get the process SP, if 0 then skip (goto d) the saving part (first context switch);
+;              b) Save remaining regs r4-r11 on process stack;
+;              c) Save the process SP in its TCB, OSTCBCur->OSTCBStkPtr = SP;
+;              d) Call OSTaskSwHook();
+;              e) Get current high priority, OSPrioCur = OSPrioHighRdy;
+;              f) Get current ready thread TCB, OSTCBCur = OSTCBHighRdy;
+;              g) Get new process SP from TCB, SP = OSTCBHighRdy->OSTCBStkPtr;
+;              h) Restore R4-R11 from new process stack;
+;              i) Perform exception return which will restore remaining context.
+;
+;           3) On entry into PendSV handler:
+;              a) The following have been saved on the process stack (by processor):
+;                 xPSR, PC, LR, R12, R0-R3
+;              b) Processor mode is switched to Handler mode (from Thread mode)
+;              c) Stack is Main stack (switched from Process stack)
+;              d) OSTCBCur      points to the OS_TCB of the task to suspend
+;                 OSTCBHighRdy  points to the OS_TCB of the task to resume
+;
+;           4) Since PendSV is set to lowest priority in the system (by OSStartHighRdy() above), we
+;              know that it will only be run when no other exception or interrupt is active, and
+;              therefore safe to assume that context being switched out was using the process stack (PSP).
+;********************************************************************************************************
+
+PendSV_Handler
+    CPSID   I                                                   ; Prevent interruption during context switch
+    MRS     R0, PSP                                             ; PSP is process stack pointer
+    CBZ     R0, PendSV_Handler_Nosave                     ; Skip register save the first time
+
+    SUBS    R0, R0, #0x20                                       ; Save remaining regs r4-11 on process stack
+    STM     R0, {R4-R11}
+
+    LDR     R1, =OSTCBCur                                       ; OSTCBCur->OSTCBStkPtr = SP;
+    LDR     R1, [R1]
+    STR     R0, [R1]                                            ; R0 is SP of process being switched out
+
+                                                                ; At this point, entire context of process has been saved
+PendSV_Handler_Nosave
+    PUSH    {R14}                                               ; Save LR exc_return value
+    LDR     R0, =OSTaskSwHook                                   ; OSTaskSwHook();
+    BLX     R0
+    POP     {R14}
+
+    LDR     R0, =OSPrioCur                                      ; OSPrioCur = OSPrioHighRdy;
+    LDR     R1, =OSPrioHighRdy
+    LDRB    R2, [R1]
+    STRB    R2, [R0]
+
+    LDR     R0, =OSTCBCur                                       ; OSTCBCur  = OSTCBHighRdy;
+    LDR     R1, =OSTCBHighRdy
+    LDR     R2, [R1]
+    STR     R2, [R0]
+
+    LDR     R0, [R2]                                            ; R0 is new process SP; SP = OSTCBHighRdy->OSTCBStkPtr;
+    LDM     R0, {R4-R11}                                        ; Restore r4-11 from new process stack
+    ADDS    R0, R0, #0x20
+    MSR     PSP, R0                                             ; Load PSP with new process SP
+    ORR     LR, LR, #0x04                                       ; Ensure exception return uses process stack
+    CPSIE   I
+    BX      LR                                                  ; Exception return will restore remaining context
+
+    END

+ 401 - 0
app/UCOS-II/Ports/os_cpu_c.c

@@ -0,0 +1,401 @@
+/*
+*********************************************************************************************************
+*                                               uC/OS-II
+*                                         The Real-Time Kernel
+*
+*
+*                                (c) Copyright 2006, Micrium, Weston, FL
+*                                          All Rights Reserved
+*
+*                                           ARM Cortex-M3 Port
+*
+* File      : OS_CPU_C.C
+* Version   : V2.89
+* By        : Jean J. Labrosse
+*             Brian Nagel
+*
+* For       : ARMv7M Cortex-M3
+* Mode      : Thumb2
+* Toolchain : RealView Development Suite
+*             RealView Microcontroller Development Kit (MDK)
+*             ARM Developer Suite (ADS)
+*             Keil uVision
+*********************************************************************************************************
+*/
+
+#define  OS_CPU_GLOBALS
+#include <ucos_ii.h>
+
+/*
+*********************************************************************************************************
+*                                          LOCAL VARIABLES
+*********************************************************************************************************
+*/
+
+#if OS_TMR_EN > 0u
+static  INT16U  OSTmrCtr;
+#endif
+
+/*
+*********************************************************************************************************
+*                                          SYS TICK DEFINES
+*********************************************************************************************************
+*/
+
+#define  OS_CPU_CM3_NVIC_ST_CTRL    (*((volatile INT32U *)0xE000E010uL)) /* SysTick Ctrl & Status Reg. */
+#define  OS_CPU_CM3_NVIC_ST_RELOAD  (*((volatile INT32U *)0xE000E014uL)) /* SysTick Reload  Value Reg. */
+#define  OS_CPU_CM3_NVIC_ST_CURRENT (*((volatile INT32U *)0xE000E018uL)) /* SysTick Current Value Reg. */
+#define  OS_CPU_CM3_NVIC_ST_CAL     (*((volatile INT32U *)0xE000E01CuL)) /* SysTick Cal     Value Reg. */
+#define  OS_CPU_CM3_NVIC_PRIO_ST    (*((volatile INT8U  *)0xE000ED23uL)) /* SysTick Handler Prio  Reg. */
+
+#define  OS_CPU_CM3_NVIC_ST_CTRL_COUNT                    0x00010000uL   /* Count flag.                */
+#define  OS_CPU_CM3_NVIC_ST_CTRL_CLK_SRC                  0x00000004uL   /* Clock Source.              */
+#define  OS_CPU_CM3_NVIC_ST_CTRL_INTEN                    0x00000002uL   /* Interrupt enable.          */
+#define  OS_CPU_CM3_NVIC_ST_CTRL_ENABLE                   0x00000001uL   /* Counter mode.              */
+#define  OS_CPU_CM3_NVIC_PRIO_MIN                               0xFFu    /* Min handler prio.          */
+
+/*
+*********************************************************************************************************
+*                                       OS INITIALIZATION HOOK
+*                                            (BEGINNING)
+*
+* Description: This function is called by OSInit() at the beginning of OSInit().
+*
+* Arguments  : none
+*
+* Note(s)    : 1) Interrupts should be disabled during this call.
+*********************************************************************************************************
+*/
+#if OS_CPU_HOOKS_EN > 0u
+void  OSInitHookBegin (void)
+{
+    INT32U   size;
+    OS_STK  *pstk;
+
+                                                           /* Clear exception stack for stack checking.*/
+    pstk = &OS_CPU_ExceptStk[0];
+    size = OS_CPU_EXCEPT_STK_SIZE;
+    while (size > 0u) {
+        size--;
+       *pstk++ = (OS_STK)0;
+    }
+
+    OS_CPU_ExceptStkBase = &OS_CPU_ExceptStk[OS_CPU_EXCEPT_STK_SIZE - 1u];
+
+#if OS_TMR_EN > 0u
+    OSTmrCtr = 0u;
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                       OS INITIALIZATION HOOK
+*                                               (END)
+*
+* Description: This function is called by OSInit() at the end of OSInit().
+*
+* Arguments  : none
+*
+* Note(s)    : 1) Interrupts should be disabled during this call.
+*********************************************************************************************************
+*/
+#if OS_CPU_HOOKS_EN > 0u
+void  OSInitHookEnd (void)
+{
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                          TASK CREATION HOOK
+*
+* Description: This function is called when a task is created.
+*
+* Arguments  : ptcb   is a pointer to the task control block of the task being created.
+*
+* Note(s)    : 1) Interrupts are disabled during this call.
+*********************************************************************************************************
+*/
+#if OS_CPU_HOOKS_EN > 0u
+void  OSTaskCreateHook (OS_TCB *ptcb)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TaskCreateHook(ptcb);
+#else
+    (void)ptcb;                                  /* Prevent compiler warning                           */
+#endif
+}
+#endif
+
+
+/*
+*********************************************************************************************************
+*                                           TASK DELETION HOOK
+*
+* Description: This function is called when a task is deleted.
+*
+* Arguments  : ptcb   is a pointer to the task control block of the task being deleted.
+*
+* Note(s)    : 1) Interrupts are disabled during this call.
+*********************************************************************************************************
+*/
+#if OS_CPU_HOOKS_EN > 0u
+void  OSTaskDelHook (OS_TCB *ptcb)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TaskDelHook(ptcb);
+#else
+    (void)ptcb;                                  /* Prevent compiler warning                           */
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                             IDLE TASK HOOK
+*
+* Description: This function is called by the idle task.  This hook has been added to allow you to do
+*              such things as STOP the CPU to conserve power.
+*
+* Arguments  : none
+*
+* Note(s)    : 1) Interrupts are enabled during this call.
+*********************************************************************************************************
+*/
+#if OS_CPU_HOOKS_EN > 0u
+void  OSTaskIdleHook (void)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TaskIdleHook();
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                            TASK RETURN HOOK
+*
+* Description: This function is called if a task accidentally returns.  In other words, a task should
+*              either be an infinite loop or delete itself when done.
+*
+* Arguments  : ptcb      is a pointer to the task control block of the task that is returning.
+*
+* Note(s)    : none
+*********************************************************************************************************
+*/
+
+#if OS_CPU_HOOKS_EN > 0u
+void  OSTaskReturnHook (OS_TCB  *ptcb)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TaskReturnHook(ptcb);
+#else
+    (void)ptcb;
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                           STATISTIC TASK HOOK
+*
+* Description: This function is called every second by uC/OS-II's statistics task.  This allows your
+*              application to add functionality to the statistics task.
+*
+* Arguments  : none
+*********************************************************************************************************
+*/
+
+#if OS_CPU_HOOKS_EN > 0u
+void  OSTaskStatHook (void)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TaskStatHook();
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                        INITIALIZE A TASK'S STACK
+*
+* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
+*              stack frame of the task being created.  This function is highly processor specific.
+*
+* Arguments  : task          is a pointer to the task code
+*
+*              p_arg         is a pointer to a user supplied data area that will be passed to the task
+*                            when the task first executes.
+*
+*              ptos          is a pointer to the top of stack.  It is assumed that 'ptos' points to
+*                            a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then
+*                            'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if
+*                            OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
+*                            of the stack.
+*
+*              opt           specifies options that can be used to alter the behavior of OSTaskStkInit().
+*                            (see uCOS_II.H for OS_TASK_OPT_xxx).
+*
+* Returns    : Always returns the location of the new top-of-stack once the processor registers have
+*              been placed on the stack in the proper order.
+*
+* Note(s)    : 1) Interrupts are enabled when your task starts executing.
+*              2) All tasks run in Thread mode, using process stack.
+*********************************************************************************************************
+*/
+
+OS_STK *OSTaskStkInit (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT16U opt)
+{
+    OS_STK *stk;
+
+
+    (void)opt;                                   /* 'opt' is not used, prevent warning                 */
+    stk       = ptos;                            /* Load stack pointer                                 */
+
+                                                 /* Registers stacked as if auto-saved on exception    */
+    *(stk)    = (INT32U)0x01000000uL;            /* xPSR                                               */
+    *(--stk)  = (INT32U)task;                    /* Entry Point                                        */
+    *(--stk)  = (INT32U)OS_TaskReturn;           /* R14 (LR)                                           */
+    *(--stk)  = (INT32U)0x12121212uL;            /* R12                                                */
+    *(--stk)  = (INT32U)0x03030303uL;            /* R3                                                 */
+    *(--stk)  = (INT32U)0x02020202uL;            /* R2                                                 */
+    *(--stk)  = (INT32U)0x01010101uL;            /* R1                                                 */
+    *(--stk)  = (INT32U)p_arg;                   /* R0 : argument                                      */
+
+                                                 /* Remaining registers saved on process stack         */
+    *(--stk)  = (INT32U)0x11111111uL;            /* R11                                                */
+    *(--stk)  = (INT32U)0x10101010uL;            /* R10                                                */
+    *(--stk)  = (INT32U)0x09090909uL;            /* R9                                                 */
+    *(--stk)  = (INT32U)0x08080808uL;            /* R8                                                 */
+    *(--stk)  = (INT32U)0x07070707uL;            /* R7                                                 */
+    *(--stk)  = (INT32U)0x06060606uL;            /* R6                                                 */
+    *(--stk)  = (INT32U)0x05050505uL;            /* R5                                                 */
+    *(--stk)  = (INT32U)0x04040404uL;            /* R4                                                 */
+
+    return (stk);
+}
+
+/*
+*********************************************************************************************************
+*                                           TASK SWITCH HOOK
+*
+* Description: This function is called when a task switch is performed.  This allows you to perform other
+*              operations during a context switch.
+*
+* Arguments  : none
+*
+* Note(s)    : 1) Interrupts are disabled during this call.
+*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
+*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
+*                 task being switched out (i.e. the preempted task).
+*********************************************************************************************************
+*/
+#if (OS_CPU_HOOKS_EN > 0u) && (OS_TASK_SW_HOOK_EN > 0u)
+void  OSTaskSwHook (void)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TaskSwHook();
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                           OS_TCBInit() HOOK
+*
+* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
+*
+* Arguments  : ptcb    is a pointer to the TCB of the task being created.
+*
+* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
+*********************************************************************************************************
+*/
+#if OS_CPU_HOOKS_EN > 0u
+void  OSTCBInitHook (OS_TCB *ptcb)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TCBInitHook(ptcb);
+#else
+    (void)ptcb;                                  /* Prevent compiler warning                           */
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                               TICK HOOK
+*
+* Description: This function is called every tick.
+*
+* Arguments  : none
+*
+* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
+*********************************************************************************************************
+*/
+#if (OS_CPU_HOOKS_EN > 0u) && (OS_TIME_TICK_HOOK_EN > 0u)
+void  OSTimeTickHook (void)
+{
+#if OS_APP_HOOKS_EN > 0u
+    App_TimeTickHook();
+#endif
+
+#if OS_TMR_EN > 0u
+    OSTmrCtr++;
+    if (OSTmrCtr >= (OS_TICKS_PER_SEC / OS_TMR_CFG_TICKS_PER_SEC)) {
+        OSTmrCtr = 0;
+        OSTmrSignal();
+    }
+#endif
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                          SYS TICK HANDLER
+*
+* Description: Handle the system tick (SysTick) interrupt, which is used to generate the uC/OS-II tick
+*              interrupt.
+*
+* Arguments  : none.
+*
+* Note(s)    : 1) This function MUST be placed on entry 15 of the Cortex-M3 vector table.
+*********************************************************************************************************
+*/
+
+void  OS_CPU_SysTickHandler (void)
+{
+    OS_CPU_SR  cpu_sr;
+
+
+    OS_ENTER_CRITICAL();                         /* Tell uC/OS-II that we are starting an ISR          */
+    OSIntNesting++;
+    OS_EXIT_CRITICAL();
+
+    OSTimeTick();                                /* Call uC/OS-II's OSTimeTick()                       */
+
+    OSIntExit();                                 /* Tell uC/OS-II that we are leaving the ISR          */
+}
+
+/*
+*********************************************************************************************************
+*                                          INITIALIZE SYS TICK
+*
+* Description: Initialize the SysTick.
+*
+* Arguments  : cnts          is the number of SysTick counts between two OS tick interrupts.
+*
+* Note(s)    : 1) This function MUST be called after OSStart() & after processor initialization.
+*********************************************************************************************************
+*/
+
+void  OS_CPU_SysTickInit (INT32U  cnts)
+{
+    OS_CPU_CM3_NVIC_ST_RELOAD = cnts - 1u;
+                                                 /* Set prio of SysTick handler to min prio.           */
+    OS_CPU_CM3_NVIC_PRIO_ST   = OS_CPU_CM3_NVIC_PRIO_MIN;
+                                                 /* Enable timer.                                      */
+    OS_CPU_CM3_NVIC_ST_CTRL  |= OS_CPU_CM3_NVIC_ST_CTRL_CLK_SRC | OS_CPU_CM3_NVIC_ST_CTRL_ENABLE;
+                                                 /* Enable timer interrupt.                            */
+    OS_CPU_CM3_NVIC_ST_CTRL  |= OS_CPU_CM3_NVIC_ST_CTRL_INTEN;
+}

+ 312 - 0
app/UCOS-II/Ports/os_dbg.c

@@ -0,0 +1,312 @@
+/*
+*********************************************************************************************************
+*                                               uC/OS-II
+*                                         The Real-Time Kernel
+*                                          DEBUGGER CONSTANTS
+*
+*                                (c) Copyright 2006, Micrium, Weston, FL
+*                                          All Rights Reserved
+*
+*                                           ARM Cortex-M3 Port
+*
+* File      : OS_DBG.C
+* Version   : V2.89
+* By        : Jean J. Labrosse
+*
+* For       : ARMv7M Cortex-M3
+* Mode      : Thumb2
+* Toolchain : RealView Development Suite
+*             RealView Microcontroller Development Kit (MDK)
+*             ARM Developer Suite (ADS)
+*             Keil uVision
+*********************************************************************************************************
+*/
+
+#include <ucos_ii.h>
+
+#define  OS_COMPILER_OPT
+
+/*
+*********************************************************************************************************
+*                                             DEBUG DATA
+*********************************************************************************************************
+*/
+
+OS_COMPILER_OPT  INT16U  const  OSDebugEn           = OS_DEBUG_EN;               /* Debug constants are defined below   */
+
+#if OS_DEBUG_EN > 0u
+
+OS_COMPILER_OPT  INT32U  const  OSEndiannessTest    = 0x12345678L;               /* Variable to test CPU endianness     */
+
+OS_COMPILER_OPT  INT16U  const  OSEventEn           = OS_EVENT_EN;
+OS_COMPILER_OPT  INT16U  const  OSEventMax          = OS_MAX_EVENTS;             /* Number of event control blocks      */
+OS_COMPILER_OPT  INT16U  const  OSEventNameEn       = OS_EVENT_NAME_EN;
+#if (OS_EVENT_EN > 0u) && (OS_MAX_EVENTS > 0u)
+OS_COMPILER_OPT  INT16U  const  OSEventSize         = sizeof(OS_EVENT);          /* Size in Bytes of OS_EVENT           */
+OS_COMPILER_OPT  INT16U  const  OSEventTblSize      = sizeof(OSEventTbl);        /* Size of OSEventTbl[] in bytes       */
+#else
+OS_COMPILER_OPT  INT16U  const  OSEventSize         = 0u;
+OS_COMPILER_OPT  INT16U  const  OSEventTblSize      = 0u;
+#endif
+OS_COMPILER_OPT  INT16U  const  OSEventMultiEn      = OS_EVENT_MULTI_EN;
+
+
+OS_COMPILER_OPT  INT16U  const  OSFlagEn            = OS_FLAG_EN;
+#if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
+OS_COMPILER_OPT  INT16U  const  OSFlagGrpSize       = sizeof(OS_FLAG_GRP);       /* Size in Bytes of OS_FLAG_GRP        */
+OS_COMPILER_OPT  INT16U  const  OSFlagNodeSize      = sizeof(OS_FLAG_NODE);      /* Size in Bytes of OS_FLAG_NODE       */
+OS_COMPILER_OPT  INT16U  const  OSFlagWidth         = sizeof(OS_FLAGS);          /* Width (in bytes) of OS_FLAGS        */
+#else
+OS_COMPILER_OPT  INT16U  const  OSFlagGrpSize       = 0u;
+OS_COMPILER_OPT  INT16U  const  OSFlagNodeSize      = 0u;
+OS_COMPILER_OPT  INT16U  const  OSFlagWidth         = 0u;
+#endif
+OS_COMPILER_OPT  INT16U  const  OSFlagMax           = OS_MAX_FLAGS;
+OS_COMPILER_OPT  INT16U  const  OSFlagNameEn        = OS_FLAG_NAME_EN;
+
+OS_COMPILER_OPT  INT16U  const  OSLowestPrio        = OS_LOWEST_PRIO;
+
+OS_COMPILER_OPT  INT16U  const  OSMboxEn            = OS_MBOX_EN;
+
+OS_COMPILER_OPT  INT16U  const  OSMemEn             = OS_MEM_EN;
+OS_COMPILER_OPT  INT16U  const  OSMemMax            = OS_MAX_MEM_PART;           /* Number of memory partitions         */
+OS_COMPILER_OPT  INT16U  const  OSMemNameEn         = OS_MEM_NAME_EN;
+#if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
+OS_COMPILER_OPT  INT16U  const  OSMemSize           = sizeof(OS_MEM);            /* Mem. Partition header sine (bytes)  */
+OS_COMPILER_OPT  INT16U  const  OSMemTblSize        = sizeof(OSMemTbl);
+#else
+OS_COMPILER_OPT  INT16U  const  OSMemSize           = 0u;
+OS_COMPILER_OPT  INT16U  const  OSMemTblSize        = 0u;
+#endif
+OS_COMPILER_OPT  INT16U  const  OSMutexEn           = OS_MUTEX_EN;
+
+OS_COMPILER_OPT  INT16U  const  OSPtrSize           = sizeof(void *);            /* Size in Bytes of a pointer          */
+
+OS_COMPILER_OPT  INT16U  const  OSQEn               = OS_Q_EN;
+OS_COMPILER_OPT  INT16U  const  OSQMax              = OS_MAX_QS;                 /* Number of queues                    */
+#if (OS_Q_EN > 0u) && (OS_MAX_QS > 0u)
+OS_COMPILER_OPT  INT16U  const  OSQSize             = sizeof(OS_Q);              /* Size in bytes of OS_Q structure     */
+#else
+OS_COMPILER_OPT  INT16U  const  OSQSize             = 0u;
+#endif
+
+OS_COMPILER_OPT  INT16U  const  OSRdyTblSize        = OS_RDY_TBL_SIZE;           /* Number of bytes in the ready table  */
+
+OS_COMPILER_OPT  INT16U  const  OSSemEn             = OS_SEM_EN;
+
+OS_COMPILER_OPT  INT16U  const  OSStkWidth          = sizeof(OS_STK);            /* Size in Bytes of a stack entry      */
+
+OS_COMPILER_OPT  INT16U  const  OSTaskCreateEn      = OS_TASK_CREATE_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskCreateExtEn   = OS_TASK_CREATE_EXT_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskDelEn         = OS_TASK_DEL_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskIdleStkSize   = OS_TASK_IDLE_STK_SIZE;
+OS_COMPILER_OPT  INT16U  const  OSTaskProfileEn     = OS_TASK_PROFILE_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskMax           = OS_MAX_TASKS + OS_N_SYS_TASKS; /* Total max. number of tasks      */
+OS_COMPILER_OPT  INT16U  const  OSTaskNameEn        = OS_TASK_NAME_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskStatEn        = OS_TASK_STAT_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskStatStkSize   = OS_TASK_STAT_STK_SIZE;
+OS_COMPILER_OPT  INT16U  const  OSTaskStatStkChkEn  = OS_TASK_STAT_STK_CHK_EN;
+OS_COMPILER_OPT  INT16U  const  OSTaskSwHookEn      = OS_TASK_SW_HOOK_EN;
+
+OS_COMPILER_OPT  INT16U  const  OSTCBPrioTblMax     = OS_LOWEST_PRIO + 1u;       /* Number of entries in OSTCBPrioTbl[] */
+OS_COMPILER_OPT  INT16U  const  OSTCBSize           = sizeof(OS_TCB);            /* Size in Bytes of OS_TCB             */
+OS_COMPILER_OPT  INT16U  const  OSTicksPerSec       = OS_TICKS_PER_SEC;
+OS_COMPILER_OPT  INT16U  const  OSTimeTickHookEn    = OS_TIME_TICK_HOOK_EN;
+OS_COMPILER_OPT  INT16U  const  OSVersionNbr        = OS_VERSION;
+
+OS_COMPILER_OPT  INT16U  const  OSTmrEn             = OS_TMR_EN;
+OS_COMPILER_OPT  INT16U  const  OSTmrCfgMax         = OS_TMR_CFG_MAX;
+OS_COMPILER_OPT  INT16U  const  OSTmrCfgNameEn      = OS_TMR_CFG_NAME_EN;
+OS_COMPILER_OPT  INT16U  const  OSTmrCfgWheelSize   = OS_TMR_CFG_WHEEL_SIZE;
+OS_COMPILER_OPT  INT16U  const  OSTmrCfgTicksPerSec = OS_TMR_CFG_TICKS_PER_SEC;
+
+#if (OS_TMR_EN > 0u) && (OS_TMR_CFG_MAX > 0u)
+OS_COMPILER_OPT  INT16U  const  OSTmrSize           = sizeof(OS_TMR);
+OS_COMPILER_OPT  INT16U  const  OSTmrTblSize        = sizeof(OSTmrTbl);
+OS_COMPILER_OPT  INT16U  const  OSTmrWheelSize      = sizeof(OS_TMR_WHEEL);
+OS_COMPILER_OPT  INT16U  const  OSTmrWheelTblSize   = sizeof(OSTmrWheelTbl);
+#else
+OS_COMPILER_OPT  INT16U  const  OSTmrSize           = 0u;
+OS_COMPILER_OPT  INT16U  const  OSTmrTblSize        = 0u;
+OS_COMPILER_OPT  INT16U  const  OSTmrWheelSize      = 0u;
+OS_COMPILER_OPT  INT16U  const  OSTmrWheelTblSize   = 0u;
+#endif
+
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                             DEBUG DATA
+*                            TOTAL DATA SPACE (i.e. RAM) USED BY uC/OS-II
+*********************************************************************************************************
+*/
+#if OS_DEBUG_EN > 0u
+
+OS_COMPILER_OPT  INT16U  const  OSDataSize = sizeof(OSCtxSwCtr)
+#if (OS_EVENT_EN > 0u) && (OS_MAX_EVENTS > 0u)
+                                           + sizeof(OSEventFreeList)
+                                           + sizeof(OSEventTbl)
+#endif
+#if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
+                                           + sizeof(OSFlagTbl)
+                                           + sizeof(OSFlagFreeList)
+#endif
+#if OS_TASK_STAT_EN > 0u
+                                           + sizeof(OSCPUUsage)
+                                           + sizeof(OSIdleCtrMax)
+                                           + sizeof(OSIdleCtrRun)
+                                           + sizeof(OSStatRdy)
+                                           + sizeof(OSTaskStatStk)
+#endif
+#if OS_TICK_STEP_EN > 0u
+                                           + sizeof(OSTickStepState)
+#endif
+#if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
+                                           + sizeof(OSMemFreeList)
+                                           + sizeof(OSMemTbl)
+#endif
+#if (OS_Q_EN > 0u) && (OS_MAX_QS > 0u)
+                                           + sizeof(OSQFreeList)
+                                           + sizeof(OSQTbl)
+#endif
+#if OS_TIME_GET_SET_EN > 0u
+                                           + sizeof(OSTime)
+#endif
+#if (OS_TMR_EN > 0u) && (OS_TMR_CFG_MAX > 0u)
+                                           + sizeof(OSTmrFree)
+                                           + sizeof(OSTmrUsed)
+                                           + sizeof(OSTmrTime)
+                                           + sizeof(OSTmrSem)
+                                           + sizeof(OSTmrSemSignal)
+                                           + sizeof(OSTmrFreeList)
+                                           + sizeof(OSTmrTbl)
+                                           + sizeof(OSTmrWheelTbl)
+#endif
+                                           + sizeof(OSIntNesting)
+                                           + sizeof(OSLockNesting)
+                                           + sizeof(OSPrioCur)
+                                           + sizeof(OSPrioHighRdy)
+                                           + sizeof(OSRdyGrp)
+                                           + sizeof(OSRdyTbl)
+                                           + sizeof(OSRunning)
+                                           + sizeof(OSTaskCtr)
+                                           + sizeof(OSIdleCtr)
+                                           + sizeof(OSTaskIdleStk)
+                                           + sizeof(OSTCBCur)
+                                           + sizeof(OSTCBFreeList)
+                                           + sizeof(OSTCBHighRdy)
+                                           + sizeof(OSTCBList)
+                                           + sizeof(OSTCBPrioTbl)
+                                           + sizeof(OSTCBTbl);
+
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                       OS DEBUG INITIALIZAZTION
+*
+* Description: This function is used to make sure that debug variables that are unused in the application
+*              are not optimized away.  This function might not be necessary for all compilers.  In this
+*              case, you should simply DELETE the code in this function while still leaving the declaration
+*              of the function itself.
+*
+* Arguments  : none
+*
+* Returns    : none
+*
+* Note(s)    : (1) This code doesn't do anything, it simply prevents the compiler from optimizing out
+*                  the 'const' variables which are declared in this file.
+*********************************************************************************************************
+*/
+
+#if OS_DEBUG_EN > 0u
+void  OSDebugInit (void)
+{
+    void  *ptemp;
+
+
+    ptemp = (void *)&OSDebugEn;
+
+    ptemp = (void *)&OSEndiannessTest;
+
+    ptemp = (void *)&OSEventMax;
+    ptemp = (void *)&OSEventNameEn;
+    ptemp = (void *)&OSEventEn;
+    ptemp = (void *)&OSEventSize;
+    ptemp = (void *)&OSEventTblSize;
+    ptemp = (void *)&OSEventMultiEn;
+
+    ptemp = (void *)&OSFlagEn;
+    ptemp = (void *)&OSFlagGrpSize;
+    ptemp = (void *)&OSFlagNodeSize;
+    ptemp = (void *)&OSFlagWidth;
+    ptemp = (void *)&OSFlagMax;
+    ptemp = (void *)&OSFlagNameEn;
+
+    ptemp = (void *)&OSLowestPrio;
+
+    ptemp = (void *)&OSMboxEn;
+
+    ptemp = (void *)&OSMemEn;
+    ptemp = (void *)&OSMemMax;
+    ptemp = (void *)&OSMemNameEn;
+    ptemp = (void *)&OSMemSize;
+    ptemp = (void *)&OSMemTblSize;
+
+    ptemp = (void *)&OSMutexEn;
+
+    ptemp = (void *)&OSPtrSize;
+
+    ptemp = (void *)&OSQEn;
+    ptemp = (void *)&OSQMax;
+    ptemp = (void *)&OSQSize;
+
+    ptemp = (void *)&OSRdyTblSize;
+
+    ptemp = (void *)&OSSemEn;
+
+    ptemp = (void *)&OSStkWidth;
+
+    ptemp = (void *)&OSTaskCreateEn;
+    ptemp = (void *)&OSTaskCreateExtEn;
+    ptemp = (void *)&OSTaskDelEn;
+    ptemp = (void *)&OSTaskIdleStkSize;
+    ptemp = (void *)&OSTaskProfileEn;
+    ptemp = (void *)&OSTaskMax;
+    ptemp = (void *)&OSTaskNameEn;
+    ptemp = (void *)&OSTaskStatEn;
+    ptemp = (void *)&OSTaskStatStkSize;
+    ptemp = (void *)&OSTaskStatStkChkEn;
+    ptemp = (void *)&OSTaskSwHookEn;
+
+    ptemp = (void *)&OSTCBPrioTblMax;
+    ptemp = (void *)&OSTCBSize;
+
+    ptemp = (void *)&OSTicksPerSec;
+    ptemp = (void *)&OSTimeTickHookEn;
+
+#if OS_TMR_EN > 0u
+    ptemp = (void *)&OSTmrTbl[0];
+    ptemp = (void *)&OSTmrWheelTbl[0];
+
+    ptemp = (void *)&OSTmrEn;
+    ptemp = (void *)&OSTmrCfgMax;
+    ptemp = (void *)&OSTmrCfgNameEn;
+    ptemp = (void *)&OSTmrCfgWheelSize;
+    ptemp = (void *)&OSTmrCfgTicksPerSec;
+    ptemp = (void *)&OSTmrSize;
+    ptemp = (void *)&OSTmrTblSize;
+
+    ptemp = (void *)&OSTmrWheelSize;
+    ptemp = (void *)&OSTmrWheelTblSize;
+#endif
+
+    ptemp = (void *)&OSVersionNbr;
+
+    ptemp = (void *)&OSDataSize;
+
+    ptemp = ptemp;                             /* Prevent compiler warning for 'ptemp' not being used! */
+}
+#endif

+ 314 - 0
app/UCOS-II/Ports/os_dbg_r.c

@@ -0,0 +1,314 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                           DEBUGGER CONSTANTS
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_DBG.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.  
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license 
+* its use in your product. We provide ALL the source code for your convenience and to help you experience 
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a 
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#include <ucos_ii.h>
+
+/*
+*********************************************************************************************************
+*                                             DEBUG DATA
+*********************************************************************************************************
+*/
+
+INT16U  const  OSDebugEn           = OS_DEBUG_EN;               /* Debug constants are defined below   */
+
+#if OS_DEBUG_EN > 0u
+
+INT32U  const  OSEndiannessTest    = 0x12345678uL;              /* Variable to test CPU endianness     */
+
+INT16U  const  OSEventEn           = OS_EVENT_EN;
+INT16U  const  OSEventMax          = OS_MAX_EVENTS;             /* Number of event control blocks      */
+INT16U  const  OSEventNameEn       = OS_EVENT_NAME_EN;
+#if (OS_EVENT_EN) && (OS_MAX_EVENTS > 0u)
+INT16U  const  OSEventSize         = sizeof(OS_EVENT);          /* Size in Bytes of OS_EVENT           */
+INT16U  const  OSEventTblSize      = sizeof(OSEventTbl);        /* Size of OSEventTbl[] in bytes       */
+#else
+INT16U  const  OSEventSize         = 0u;
+INT16U  const  OSEventTblSize      = 0u;
+#endif
+INT16U  const  OSEventMultiEn      = OS_EVENT_MULTI_EN;
+
+
+INT16U  const  OSFlagEn            = OS_FLAG_EN;
+#if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
+INT16U  const  OSFlagGrpSize       = sizeof(OS_FLAG_GRP);       /* Size in Bytes of OS_FLAG_GRP        */
+INT16U  const  OSFlagNodeSize      = sizeof(OS_FLAG_NODE);      /* Size in Bytes of OS_FLAG_NODE       */
+INT16U  const  OSFlagWidth         = sizeof(OS_FLAGS);          /* Width (in bytes) of OS_FLAGS        */
+#else
+INT16U  const  OSFlagGrpSize       = 0u;
+INT16U  const  OSFlagNodeSize      = 0u;
+INT16U  const  OSFlagWidth         = 0u;
+#endif
+INT16U  const  OSFlagMax           = OS_MAX_FLAGS;
+INT16U  const  OSFlagNameEn        = OS_FLAG_NAME_EN;
+
+INT16U  const  OSLowestPrio        = OS_LOWEST_PRIO;
+
+INT16U  const  OSMboxEn            = OS_MBOX_EN;
+
+INT16U  const  OSMemEn             = OS_MEM_EN;
+INT16U  const  OSMemMax            = OS_MAX_MEM_PART;           /* Number of memory partitions         */
+INT16U  const  OSMemNameEn         = OS_MEM_NAME_EN;
+#if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
+INT16U  const  OSMemSize           = sizeof(OS_MEM);            /* Mem. Partition header sine (bytes)  */
+INT16U  const  OSMemTblSize        = sizeof(OSMemTbl);
+#else
+INT16U  const  OSMemSize           = 0u;
+INT16U  const  OSMemTblSize        = 0u;
+#endif
+INT16U  const  OSMutexEn           = OS_MUTEX_EN;
+
+INT16U  const  OSPtrSize           = sizeof(void *);            /* Size in Bytes of a pointer          */
+
+INT16U  const  OSQEn               = OS_Q_EN;
+INT16U  const  OSQMax              = OS_MAX_QS;                 /* Number of queues                    */
+#if (OS_Q_EN > 0u) && (OS_MAX_QS > 0u)
+INT16U  const  OSQSize             = sizeof(OS_Q);              /* Size in bytes of OS_Q structure     */
+#else
+INT16U  const  OSQSize             = 0u;
+#endif
+
+INT16U  const  OSRdyTblSize        = OS_RDY_TBL_SIZE;           /* Number of bytes in the ready table  */
+
+INT16U  const  OSSemEn             = OS_SEM_EN;
+
+INT16U  const  OSStkWidth          = sizeof(OS_STK);            /* Size in Bytes of a stack entry      */
+
+INT16U  const  OSTaskCreateEn      = OS_TASK_CREATE_EN;
+INT16U  const  OSTaskCreateExtEn   = OS_TASK_CREATE_EXT_EN;
+INT16U  const  OSTaskDelEn         = OS_TASK_DEL_EN;
+INT16U  const  OSTaskIdleStkSize   = OS_TASK_IDLE_STK_SIZE;
+INT16U  const  OSTaskProfileEn     = OS_TASK_PROFILE_EN;
+INT16U  const  OSTaskMax           = OS_MAX_TASKS + OS_N_SYS_TASKS; /* Total max. number of tasks      */
+INT16U  const  OSTaskNameEn        = OS_TASK_NAME_EN;  
+INT16U  const  OSTaskStatEn        = OS_TASK_STAT_EN;
+INT16U  const  OSTaskStatStkSize   = OS_TASK_STAT_STK_SIZE;
+INT16U  const  OSTaskStatStkChkEn  = OS_TASK_STAT_STK_CHK_EN;
+INT16U  const  OSTaskSwHookEn      = OS_TASK_SW_HOOK_EN;
+INT16U  const  OSTaskRegTblSize    = OS_TASK_REG_TBL_SIZE;
+
+INT16U  const  OSTCBPrioTblMax     = OS_LOWEST_PRIO + 1u;       /* Number of entries in OSTCBPrioTbl[] */
+INT16U  const  OSTCBSize           = sizeof(OS_TCB);            /* Size in Bytes of OS_TCB             */
+INT16U  const  OSTicksPerSec       = OS_TICKS_PER_SEC;
+INT16U  const  OSTimeTickHookEn    = OS_TIME_TICK_HOOK_EN;
+INT16U  const  OSVersionNbr        = OS_VERSION;
+
+INT16U  const  OSTmrEn             = OS_TMR_EN;
+INT16U  const  OSTmrCfgMax         = OS_TMR_CFG_MAX;
+INT16U  const  OSTmrCfgNameEn      = OS_TMR_CFG_NAME_EN;
+INT16U  const  OSTmrCfgWheelSize   = OS_TMR_CFG_WHEEL_SIZE;
+INT16U  const  OSTmrCfgTicksPerSec = OS_TMR_CFG_TICKS_PER_SEC;
+
+#if (OS_TMR_EN > 0u) && (OS_TMR_CFG_MAX > 0u)
+INT16U  const  OSTmrSize           = sizeof(OS_TMR);
+INT16U  const  OSTmrTblSize        = sizeof(OSTmrTbl);
+INT16U  const  OSTmrWheelSize      = sizeof(OS_TMR_WHEEL);
+INT16U  const  OSTmrWheelTblSize   = sizeof(OSTmrWheelTbl);
+#else
+INT16U  const  OSTmrSize           = 0u;
+INT16U  const  OSTmrTblSize        = 0u;
+INT16U  const  OSTmrWheelSize      = 0u;
+INT16U  const  OSTmrWheelTblSize   = 0u;
+#endif
+
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                             DEBUG DATA
+*                            TOTAL DATA SPACE (i.e. RAM) USED BY uC/OS-II
+*********************************************************************************************************
+*/
+#if OS_DEBUG_EN > 0u
+
+INT16U  const  OSDataSize = sizeof(OSCtxSwCtr)
+#if (OS_EVENT_EN) && (OS_MAX_EVENTS > 0u)
+                          + sizeof(OSEventFreeList)
+                          + sizeof(OSEventTbl)
+#endif
+#if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
+                          + sizeof(OSFlagTbl)
+                          + sizeof(OSFlagFreeList)
+#endif
+#if OS_TASK_STAT_EN > 0u
+                          + sizeof(OSCPUUsage)
+                          + sizeof(OSIdleCtrMax)
+                          + sizeof(OSIdleCtrRun)
+                          + sizeof(OSStatRdy)
+                          + sizeof(OSTaskStatStk)
+#endif
+#if OS_TICK_STEP_EN > 0u
+                          + sizeof(OSTickStepState)
+#endif
+#if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
+                          + sizeof(OSMemFreeList)
+                          + sizeof(OSMemTbl)
+#endif
+#if (OS_Q_EN > 0u) && (OS_MAX_QS > 0u)
+                          + sizeof(OSQFreeList)
+                          + sizeof(OSQTbl)
+#endif
+#if OS_TIME_GET_SET_EN > 0u   
+                          + sizeof(OSTime)
+#endif
+#if (OS_TMR_EN > 0u) && (OS_TMR_CFG_MAX > 0u)
+                          + sizeof(OSTmrFree)
+                          + sizeof(OSTmrUsed)
+                          + sizeof(OSTmrTime)
+                          + sizeof(OSTmrSem)
+                          + sizeof(OSTmrSemSignal)
+                          + sizeof(OSTmrTbl)
+                          + sizeof(OSTmrFreeList)
+                          + sizeof(OSTmrTaskStk)
+                          + sizeof(OSTmrWheelTbl)
+#endif
+                          + sizeof(OSIntNesting)
+                          + sizeof(OSLockNesting)
+                          + sizeof(OSPrioCur)
+                          + sizeof(OSPrioHighRdy)
+                          + sizeof(OSRdyGrp)
+                          + sizeof(OSRdyTbl)
+                          + sizeof(OSRunning)
+                          + sizeof(OSTaskCtr)
+                          + sizeof(OSIdleCtr)
+                          + sizeof(OSTaskIdleStk)
+                          + sizeof(OSTCBCur)
+                          + sizeof(OSTCBFreeList)
+                          + sizeof(OSTCBHighRdy)
+                          + sizeof(OSTCBList)
+                          + sizeof(OSTCBPrioTbl)
+                          + sizeof(OSTCBTbl);
+
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        OS DEBUG INITIALIZATION
+*
+* Description: This function is used to make sure that debug variables that are unused in the application
+*              are not optimized away.  This function might not be necessary for all compilers.  In this
+*              case, you should simply DELETE the code in this function while still leaving the declaration
+*              of the function itself.
+*
+* Arguments  : none
+*
+* Returns    : none
+*
+* Note(s)    : (1) This code doesn't do anything, it simply prevents the compiler from optimizing out
+*                  the 'const' variables which are declared in this file.
+*              (2) You may decide to 'compile out' the code (by using #if 0/#endif) INSIDE the function 
+*                  if your compiler DOES NOT optimize out the 'const' variables above.
+*********************************************************************************************************
+*/
+
+#if OS_DEBUG_EN > 0u
+void  OSDebugInit (void)
+{
+    void  const  *ptemp;
+
+
+    ptemp = (void const *)&OSDebugEn;
+
+    ptemp = (void const *)&OSEndiannessTest;
+
+    ptemp = (void const *)&OSEventMax;
+    ptemp = (void const *)&OSEventNameEn;
+    ptemp = (void const *)&OSEventEn;
+    ptemp = (void const *)&OSEventSize;
+    ptemp = (void const *)&OSEventTblSize;
+    ptemp = (void const *)&OSEventMultiEn;
+
+    ptemp = (void const *)&OSFlagEn;
+    ptemp = (void const *)&OSFlagGrpSize;
+    ptemp = (void const *)&OSFlagNodeSize;
+    ptemp = (void const *)&OSFlagWidth;
+    ptemp = (void const *)&OSFlagMax;
+    ptemp = (void const *)&OSFlagNameEn;
+
+    ptemp = (void const *)&OSLowestPrio;
+
+    ptemp = (void const *)&OSMboxEn;
+
+    ptemp = (void const *)&OSMemEn;
+    ptemp = (void const *)&OSMemMax;
+    ptemp = (void const *)&OSMemNameEn;
+    ptemp = (void const *)&OSMemSize;
+    ptemp = (void const *)&OSMemTblSize;
+
+    ptemp = (void const *)&OSMutexEn;
+
+    ptemp = (void const *)&OSPtrSize;
+
+    ptemp = (void const *)&OSQEn;
+    ptemp = (void const *)&OSQMax;
+    ptemp = (void const *)&OSQSize;
+
+    ptemp = (void const *)&OSRdyTblSize;
+
+    ptemp = (void const *)&OSSemEn;
+
+    ptemp = (void const *)&OSStkWidth;
+
+    ptemp = (void const *)&OSTaskCreateEn;
+    ptemp = (void const *)&OSTaskCreateExtEn;
+    ptemp = (void const *)&OSTaskDelEn;
+    ptemp = (void const *)&OSTaskIdleStkSize;
+    ptemp = (void const *)&OSTaskProfileEn;
+    ptemp = (void const *)&OSTaskMax;
+    ptemp = (void const *)&OSTaskNameEn;
+    ptemp = (void const *)&OSTaskStatEn;
+    ptemp = (void const *)&OSTaskStatStkSize;
+    ptemp = (void const *)&OSTaskStatStkChkEn;
+    ptemp = (void const *)&OSTaskSwHookEn;
+
+    ptemp = (void const *)&OSTCBPrioTblMax;
+    ptemp = (void const *)&OSTCBSize;
+
+    ptemp = (void const *)&OSTicksPerSec;
+    ptemp = (void const *)&OSTimeTickHookEn;
+
+#if OS_TMR_EN > 0u
+    ptemp = (void const *)&OSTmrTbl[0];
+    ptemp = (void const *)&OSTmrWheelTbl[0];
+    
+    ptemp = (void const *)&OSTmrEn;
+    ptemp = (void const *)&OSTmrCfgMax;
+    ptemp = (void const *)&OSTmrCfgNameEn;
+    ptemp = (void const *)&OSTmrCfgWheelSize;
+    ptemp = (void const *)&OSTmrCfgTicksPerSec;
+    ptemp = (void const *)&OSTmrSize;
+    ptemp = (void const *)&OSTmrTblSize;
+
+    ptemp = (void const *)&OSTmrWheelSize;
+    ptemp = (void const *)&OSTmrWheelTblSize;
+#endif
+
+    ptemp = (void const *)&OSVersionNbr;
+
+    ptemp = (void const *)&OSDataSize;
+
+    ptemp = ptemp;                             /* Prevent compiler warning for 'ptemp' not being used! */
+}
+#endif
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

Fichier diff supprimé car celui-ci est trop grand
+ 2028 - 0
app/UCOS-II/Source/os_core.c


Fichier diff supprimé car celui-ci est trop grand
+ 1215 - 0
app/UCOS-II/Source/os_flag.c


+ 647 - 0
app/UCOS-II/Source/os_mbox.c

@@ -0,0 +1,647 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                       MESSAGE MAILBOX MANAGEMENT
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_MBOX.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef  OS_MASTER_FILE
+#include <ucos_ii.h>
+#endif
+
+#if OS_MBOX_EN > 0u
+/*
+*********************************************************************************************************
+*                                     ACCEPT MESSAGE FROM MAILBOX
+*
+* Description: This function checks the mailbox to see if a message is available.  Unlike OSMboxPend(),
+*              OSMboxAccept() does not suspend the calling task if a message is not available.
+*
+* Arguments  : pevent        is a pointer to the event control block
+*
+* Returns    : != (void *)0  is the message in the mailbox if one is available.  The mailbox is cleared
+*                            so the next time OSMboxAccept() is called, the mailbox will be empty.
+*              == (void *)0  if the mailbox is empty or,
+*                            if 'pevent' is a NULL pointer or,
+*                            if you didn't pass the proper event pointer.
+*********************************************************************************************************
+*/
+
+#if OS_MBOX_ACCEPT_EN > 0u
+void  *OSMboxAccept (OS_EVENT *pevent)
+{
+    void      *pmsg;
+#if OS_CRITICAL_METHOD == 3u                              /* Allocate storage for CPU status register  */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                        /* Validate 'pevent'                         */
+        return ((void *)0);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {      /* Validate event block type                 */
+        return ((void *)0);
+    }
+    OS_ENTER_CRITICAL();
+    pmsg               = pevent->OSEventPtr;
+    pevent->OSEventPtr = (void *)0;                       /* Clear the mailbox                         */
+    OS_EXIT_CRITICAL();
+    return (pmsg);                                        /* Return the message received (or NULL)     */
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        CREATE A MESSAGE MAILBOX
+*
+* Description: This function creates a message mailbox if free event control blocks are available.
+*
+* Arguments  : pmsg          is a pointer to a message that you wish to deposit in the mailbox.  If
+*                            you set this value to the NULL pointer (i.e. (void *)0) then the mailbox
+*                            will be considered empty.
+*
+* Returns    : != (OS_EVENT *)0  is a pointer to the event control clock (OS_EVENT) associated with the
+*                                created mailbox
+*              == (OS_EVENT *)0  if no event control blocks were available
+*********************************************************************************************************
+*/
+
+OS_EVENT  *OSMboxCreate (void *pmsg)
+{
+    OS_EVENT  *pevent;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL_IEC61508
+    if (OSSafetyCriticalStartFlag == OS_TRUE) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+    if (OSIntNesting > 0u) {                     /* See if called from ISR ...                         */
+        return ((OS_EVENT *)0);                  /* ... can't CREATE from an ISR                       */
+    }
+    OS_ENTER_CRITICAL();
+    pevent = OSEventFreeList;                    /* Get next free event control block                  */
+    if (OSEventFreeList != (OS_EVENT *)0) {      /* See if pool of free ECB pool was empty             */
+        OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
+    }
+    OS_EXIT_CRITICAL();
+    if (pevent != (OS_EVENT *)0) {
+        pevent->OSEventType    = OS_EVENT_TYPE_MBOX;
+        pevent->OSEventCnt     = 0u;
+        pevent->OSEventPtr     = pmsg;           /* Deposit message in event control block             */
+#if OS_EVENT_NAME_EN > 0u
+        pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+        OS_EventWaitListInit(pevent);
+    }
+    return (pevent);                             /* Return pointer to event control block              */
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                         DELETE A MAIBOX
+*
+* Description: This function deletes a mailbox and readies all tasks pending on the mailbox.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            mailbox.
+*
+*              opt           determines delete options as follows:
+*                            opt == OS_DEL_NO_PEND   Delete the mailbox ONLY if no task pending
+*                            opt == OS_DEL_ALWAYS    Deletes the mailbox even if tasks are waiting.
+*                                                    In this case, all the tasks pending will be readied.
+*
+*              perr          is a pointer to an error code that can contain one of the following values:
+*                            OS_ERR_NONE             The call was successful and the mailbox was deleted
+*                            OS_ERR_DEL_ISR          If you attempted to delete the mailbox from an ISR
+*                            OS_ERR_INVALID_OPT      An invalid option was specified
+*                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the mailbox
+*                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a mailbox
+*                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
+*
+* Returns    : pevent        upon error
+*              (OS_EVENT *)0 if the mailbox was successfully deleted.
+*
+* Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
+*                 the mailbox MUST check the return code of OSMboxPend().
+*              2) OSMboxAccept() callers will not know that the intended mailbox has been deleted!
+*              3) This call can potentially disable interrupts for a long time.  The interrupt disable
+*                 time is directly proportional to the number of tasks waiting on the mailbox.
+*              4) Because ALL tasks pending on the mailbox will be readied, you MUST be careful in
+*                 applications where the mailbox is used for mutual exclusion because the resource(s)
+*                 will no longer be guarded by the mailbox.
+*********************************************************************************************************
+*/
+
+#if OS_MBOX_DEL_EN > 0u
+OS_EVENT  *OSMboxDel (OS_EVENT  *pevent,
+                      INT8U      opt,
+                      INT8U     *perr)
+{
+    BOOLEAN    tasks_waiting;
+    OS_EVENT  *pevent_return;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (pevent);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {       /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (pevent);
+    }
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        *perr = OS_ERR_DEL_ISR;                            /* ... can't DELETE from an ISR             */
+        return (pevent);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                        /* See if any tasks waiting on mailbox      */
+        tasks_waiting = OS_TRUE;                           /* Yes                                      */
+    } else {
+        tasks_waiting = OS_FALSE;                          /* No                                       */
+    }
+    switch (opt) {
+        case OS_DEL_NO_PEND:                               /* Delete mailbox only if no task waiting   */
+             if (tasks_waiting == OS_FALSE) {
+#if OS_EVENT_NAME_EN > 0u
+                 pevent->OSEventName = (INT8U *)(void *)"?";
+#endif
+                 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
+                 pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
+                 pevent->OSEventCnt  = 0u;
+                 OSEventFreeList     = pevent;             /* Get next free event control block        */
+                 OS_EXIT_CRITICAL();
+                 *perr               = OS_ERR_NONE;
+                 pevent_return       = (OS_EVENT *)0;      /* Mailbox has been deleted                 */
+             } else {
+                 OS_EXIT_CRITICAL();
+                 *perr               = OS_ERR_TASK_WAITING;
+                 pevent_return       = pevent;
+             }
+             break;
+
+        case OS_DEL_ALWAYS:                                /* Always delete the mailbox                */
+             while (pevent->OSEventGrp != 0u) {            /* Ready ALL tasks waiting for mailbox      */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX, OS_STAT_PEND_OK);
+             }
+#if OS_EVENT_NAME_EN > 0u
+             pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+             pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
+             pevent->OSEventPtr     = OSEventFreeList;     /* Return Event Control Block to free list  */
+             pevent->OSEventCnt     = 0u;
+             OSEventFreeList        = pevent;              /* Get next free event control block        */
+             OS_EXIT_CRITICAL();
+             if (tasks_waiting == OS_TRUE) {               /* Reschedule only if task(s) were waiting  */
+                 OS_Sched();                               /* Find highest priority task ready to run  */
+             }
+             *perr         = OS_ERR_NONE;
+             pevent_return = (OS_EVENT *)0;                /* Mailbox has been deleted                 */
+             break;
+
+        default:
+             OS_EXIT_CRITICAL();
+             *perr         = OS_ERR_INVALID_OPT;
+             pevent_return = pevent;
+             break;
+    }
+    return (pevent_return);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                      PEND ON MAILBOX FOR A MESSAGE
+*
+* Description: This function waits for a message to be sent to a mailbox
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
+*
+*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
+*                            wait for a message to arrive at the mailbox up to the amount of time
+*                            specified by this argument.  If you specify 0, however, your task will wait
+*                            forever at the specified mailbox or, until a message arrives.
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         The call was successful and your task received a
+*                                                message.
+*                            OS_ERR_TIMEOUT      A message was not received within the specified 'timeout'.
+*                            OS_ERR_PEND_ABORT   The wait on the mailbox was aborted.
+*                            OS_ERR_EVENT_TYPE   Invalid event type
+*                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
+*                                                would lead to a suspension.
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
+*                            OS_ERR_PEND_LOCKED  If you called this function when the scheduler is locked
+*
+* Returns    : != (void *)0  is a pointer to the message received
+*              == (void *)0  if no message was received or,
+*                            if 'pevent' is a NULL pointer or,
+*                            if you didn't pass the proper pointer to the event control block.
+*********************************************************************************************************
+*/
+/*$PAGE*/
+void  *OSMboxPend (OS_EVENT  *pevent,
+                   INT32U     timeout,
+                   INT8U     *perr)
+{
+    void      *pmsg;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        *perr = OS_ERR_PEVENT_NULL;
+        return ((void *)0);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
+        *perr = OS_ERR_EVENT_TYPE;
+        return ((void *)0);
+    }
+    if (OSIntNesting > 0u) {                          /* See if called from ISR ...                    */
+        *perr = OS_ERR_PEND_ISR;                      /* ... can't PEND from an ISR                    */
+        return ((void *)0);
+    }
+    if (OSLockNesting > 0u) {                         /* See if called with scheduler locked ...       */
+        *perr = OS_ERR_PEND_LOCKED;                   /* ... can't PEND when locked                    */
+        return ((void *)0);
+    }
+    OS_ENTER_CRITICAL();
+    pmsg = pevent->OSEventPtr;
+    if (pmsg != (void *)0) {                          /* See if there is already a message             */
+        pevent->OSEventPtr = (void *)0;               /* Clear the mailbox                             */
+        OS_EXIT_CRITICAL();
+        *perr = OS_ERR_NONE;
+        return (pmsg);                                /* Return the message received (or NULL)         */
+    }
+    OSTCBCur->OSTCBStat     |= OS_STAT_MBOX;          /* Message not available, task will pend         */
+    OSTCBCur->OSTCBStatPend  = OS_STAT_PEND_OK;
+    OSTCBCur->OSTCBDly       = timeout;               /* Load timeout in TCB                           */
+    OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
+    OS_EXIT_CRITICAL();
+    OS_Sched();                                       /* Find next highest priority task ready to run  */
+    OS_ENTER_CRITICAL();
+    switch (OSTCBCur->OSTCBStatPend) {                /* See if we timed-out or aborted                */
+        case OS_STAT_PEND_OK:
+             pmsg =  OSTCBCur->OSTCBMsg;
+            *perr =  OS_ERR_NONE;
+             break;
+
+        case OS_STAT_PEND_ABORT:
+             pmsg = (void *)0;
+            *perr =  OS_ERR_PEND_ABORT;               /* Indicate that we aborted                      */
+             break;
+
+        case OS_STAT_PEND_TO:
+        default:
+             OS_EventTaskRemove(OSTCBCur, pevent);
+             pmsg = (void *)0;
+            *perr =  OS_ERR_TIMEOUT;                  /* Indicate that we didn't get event within TO   */
+             break;
+    }
+    OSTCBCur->OSTCBStat          =  OS_STAT_RDY;      /* Set   task  status to ready                   */
+    OSTCBCur->OSTCBStatPend      =  OS_STAT_PEND_OK;  /* Clear pend  status                            */
+    OSTCBCur->OSTCBEventPtr      = (OS_EVENT  *)0;    /* Clear event pointers                          */
+#if (OS_EVENT_MULTI_EN > 0u)
+    OSTCBCur->OSTCBEventMultiPtr = (OS_EVENT **)0;
+#endif
+    OSTCBCur->OSTCBMsg           = (void      *)0;    /* Clear  received message                       */
+    OS_EXIT_CRITICAL();
+    return (pmsg);                                    /* Return received message                       */
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                      ABORT WAITING ON A MESSAGE MAILBOX
+*
+* Description: This function aborts & readies any tasks currently waiting on a mailbox.  This function
+*              should be used to fault-abort the wait on the mailbox, rather than to normally signal
+*              the mailbox via OSMboxPost() or OSMboxPostOpt().
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox.
+*
+*              opt           determines the type of ABORT performed:
+*                            OS_PEND_OPT_NONE         ABORT wait for a single task (HPT) waiting on the
+*                                                     mailbox
+*                            OS_PEND_OPT_BROADCAST    ABORT wait for ALL tasks that are  waiting on the
+*                                                     mailbox
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         No tasks were     waiting on the mailbox.
+*                            OS_ERR_PEND_ABORT   At least one task waiting on the mailbox was readied
+*                                                and informed of the aborted wait; check return value
+*                                                for the number of tasks whose wait on the mailbox
+*                                                was aborted.
+*                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a mailbox.
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
+*
+* Returns    : == 0          if no tasks were waiting on the mailbox, or upon error.
+*              >  0          if one or more tasks waiting on the mailbox are now readied and informed.
+*********************************************************************************************************
+*/
+
+#if OS_MBOX_PEND_ABORT_EN > 0u
+INT8U  OSMboxPendAbort (OS_EVENT  *pevent,
+                        INT8U      opt,
+                        INT8U     *perr)
+{
+    INT8U      nbr_tasks;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (0u);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {       /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (0u);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                        /* See if any task waiting on mailbox?      */
+        nbr_tasks = 0u;
+        switch (opt) {
+            case OS_PEND_OPT_BROADCAST:                    /* Do we need to abort ALL waiting tasks?   */
+                 while (pevent->OSEventGrp != 0u) {        /* Yes, ready ALL tasks waiting on mailbox  */
+                     (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX, OS_STAT_PEND_ABORT);
+                     nbr_tasks++;
+                 }
+                 break;
+
+            case OS_PEND_OPT_NONE:
+            default:                                       /* No,  ready HPT       waiting on mailbox  */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX, OS_STAT_PEND_ABORT);
+                 nbr_tasks++;
+                 break;
+        }
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                        /* Find HPT ready to run                    */
+        *perr = OS_ERR_PEND_ABORT;
+        return (nbr_tasks);
+    }
+    OS_EXIT_CRITICAL();
+    *perr = OS_ERR_NONE;
+    return (0u);                                           /* No tasks waiting on mailbox              */
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                       POST MESSAGE TO A MAILBOX
+*
+* Description: This function sends a message to a mailbox
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
+*
+*              pmsg          is a pointer to the message to send.  You MUST NOT send a NULL pointer.
+*
+* Returns    : OS_ERR_NONE          The call was successful and the message was sent
+*              OS_ERR_MBOX_FULL     If the mailbox already contains a message.  You can can only send one
+*                                   message at a time and thus, the message MUST be consumed before you
+*                                   are allowed to send another one.
+*              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
+*              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
+*              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
+*
+* Note(s)    : 1) HPT means Highest Priority Task
+*********************************************************************************************************
+*/
+
+#if OS_MBOX_POST_EN > 0u
+INT8U  OSMboxPost (OS_EVENT  *pevent,
+                   void      *pmsg)
+{
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (pmsg == (void *)0) {                          /* Make sure we are not posting a NULL pointer   */
+        return (OS_ERR_POST_NULL_PTR);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                   /* See if any task pending on mailbox            */
+                                                      /* Ready HPT waiting on event                    */
+        (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_MBOX, OS_STAT_PEND_OK);
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                   /* Find highest priority task ready to run       */
+        return (OS_ERR_NONE);
+    }
+    if (pevent->OSEventPtr != (void *)0) {            /* Make sure mailbox doesn't already have a msg  */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_MBOX_FULL);
+    }
+    pevent->OSEventPtr = pmsg;                        /* Place message in mailbox                      */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                       POST MESSAGE TO A MAILBOX
+*
+* Description: This function sends a message to a mailbox
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
+*
+*              pmsg          is a pointer to the message to send.  You MUST NOT send a NULL pointer.
+*
+*              opt           determines the type of POST performed:
+*                            OS_POST_OPT_NONE         POST to a single waiting task
+*                                                     (Identical to OSMboxPost())
+*                            OS_POST_OPT_BROADCAST    POST to ALL tasks that are waiting on the mailbox
+*
+*                            OS_POST_OPT_NO_SCHED     Indicates that the scheduler will NOT be invoked
+*
+* Returns    : OS_ERR_NONE          The call was successful and the message was sent
+*              OS_ERR_MBOX_FULL     If the mailbox already contains a message.  You can can only send one
+*                                   message at a time and thus, the message MUST be consumed before you
+*                                   are allowed to send another one.
+*              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
+*              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
+*              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
+*
+* Note(s)    : 1) HPT means Highest Priority Task
+*
+* Warning    : Interrupts can be disabled for a long time if you do a 'broadcast'.  In fact, the
+*              interrupt disable time is proportional to the number of tasks waiting on the mailbox.
+*********************************************************************************************************
+*/
+
+#if OS_MBOX_POST_OPT_EN > 0u
+INT8U  OSMboxPostOpt (OS_EVENT  *pevent,
+                      void      *pmsg,
+                      INT8U      opt)
+{
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (pmsg == (void *)0) {                          /* Make sure we are not posting a NULL pointer   */
+        return (OS_ERR_POST_NULL_PTR);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                   /* See if any task pending on mailbox            */
+        if ((opt & OS_POST_OPT_BROADCAST) != 0x00u) { /* Do we need to post msg to ALL waiting tasks ? */
+            while (pevent->OSEventGrp != 0u) {        /* Yes, Post to ALL tasks waiting on mailbox     */
+                (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_MBOX, OS_STAT_PEND_OK);
+            }
+        } else {                                      /* No,  Post to HPT waiting on mbox              */
+            (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_MBOX, OS_STAT_PEND_OK);
+        }
+        OS_EXIT_CRITICAL();
+        if ((opt & OS_POST_OPT_NO_SCHED) == 0u) {     /* See if scheduler needs to be invoked          */
+            OS_Sched();                               /* Find HPT ready to run                         */
+        }
+        return (OS_ERR_NONE);
+    }
+    if (pevent->OSEventPtr != (void *)0) {            /* Make sure mailbox doesn't already have a msg  */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_MBOX_FULL);
+    }
+    pevent->OSEventPtr = pmsg;                        /* Place message in mailbox                      */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        QUERY A MESSAGE MAILBOX
+*
+* Description: This function obtains information about a message mailbox.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
+*
+*              p_mbox_data   is a pointer to a structure that will contain information about the message
+*                            mailbox.
+*
+* Returns    : OS_ERR_NONE         The call was successful and the message was sent
+*              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non mailbox.
+*              OS_ERR_PEVENT_NULL  If 'pevent'      is a NULL pointer
+*              OS_ERR_PDATA_NULL   If 'p_mbox_data' is a NULL pointer
+*********************************************************************************************************
+*/
+
+#if OS_MBOX_QUERY_EN > 0u
+INT8U  OSMboxQuery (OS_EVENT      *pevent,
+                    OS_MBOX_DATA  *p_mbox_data)
+{
+    INT8U       i;
+    OS_PRIO    *psrc;
+    OS_PRIO    *pdest;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR   cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (p_mbox_data == (OS_MBOX_DATA *)0) {                /* Validate 'p_mbox_data'                   */
+        return (OS_ERR_PDATA_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {       /* Validate event block type                */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    p_mbox_data->OSEventGrp = pevent->OSEventGrp;          /* Copy message mailbox wait list           */
+    psrc                    = &pevent->OSEventTbl[0];
+    pdest                   = &p_mbox_data->OSEventTbl[0];
+    for (i = 0u; i < OS_EVENT_TBL_SIZE; i++) {
+        *pdest++ = *psrc++;
+    }
+    p_mbox_data->OSMsg = pevent->OSEventPtr;               /* Get message from mailbox                 */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif                                                     /* OS_MBOX_QUERY_EN                         */
+#endif                                                     /* OS_MBOX_EN                               */
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

+ 456 - 0
app/UCOS-II/Source/os_mem.c

@@ -0,0 +1,456 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                            MEMORY MANAGEMENT
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_MEM.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef  OS_MASTER_FILE
+#include <ucos_ii.h>
+#endif
+
+#if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
+/*
+*********************************************************************************************************
+*                                        CREATE A MEMORY PARTITION
+*
+* Description : Create a fixed-sized memory partition that will be managed by uC/OS-II.
+*
+* Arguments   : addr     is the starting address of the memory partition
+*
+*               nblks    is the number of memory blocks to create from the partition.
+*
+*               blksize  is the size (in bytes) of each block in the memory partition.
+*
+*               perr     is a pointer to a variable containing an error message which will be set by
+*                        this function to either:
+*
+*                        OS_ERR_NONE              if the memory partition has been created correctly.
+*                        OS_ERR_MEM_INVALID_ADDR  if you are specifying an invalid address for the memory
+*                                                 storage of the partition or, the block does not align
+*                                                 on a pointer boundary
+*                        OS_ERR_MEM_INVALID_PART  no free partitions available
+*                        OS_ERR_MEM_INVALID_BLKS  user specified an invalid number of blocks (must be >= 2)
+*                        OS_ERR_MEM_INVALID_SIZE  user specified an invalid block size
+*                                                   - must be greater than the size of a pointer
+*                                                   - must be able to hold an integral number of pointers
+* Returns    : != (OS_MEM *)0  is the partition was created
+*              == (OS_MEM *)0  if the partition was not created because of invalid arguments or, no
+*                              free partition is available.
+*********************************************************************************************************
+*/
+
+OS_MEM  *OSMemCreate (void   *addr,
+                      INT32U  nblks,
+                      INT32U  blksize,
+                      INT8U  *perr)
+{
+    OS_MEM    *pmem;
+    INT8U     *pblk;
+    void     **plink;
+    INT32U     loops;
+    INT32U     i;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#ifdef OS_SAFETY_CRITICAL_IEC61508
+    if (OSSafetyCriticalStartFlag == OS_TRUE) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (addr == (void *)0) {                          /* Must pass a valid address for the memory part.*/
+        *perr = OS_ERR_MEM_INVALID_ADDR;
+        return ((OS_MEM *)0);
+    }
+    if (((INT32U)addr & (sizeof(void *) - 1u)) != 0u){  /* Must be pointer size aligned                */
+        *perr = OS_ERR_MEM_INVALID_ADDR;
+        return ((OS_MEM *)0);
+    }
+    if (nblks < 2u) {                                 /* Must have at least 2 blocks per partition     */
+        *perr = OS_ERR_MEM_INVALID_BLKS;
+        return ((OS_MEM *)0);
+    }
+    if (blksize < sizeof(void *)) {                   /* Must contain space for at least a pointer     */
+        *perr = OS_ERR_MEM_INVALID_SIZE;
+        return ((OS_MEM *)0);
+    }
+#endif
+    OS_ENTER_CRITICAL();
+    pmem = OSMemFreeList;                             /* Get next free memory partition                */
+    if (OSMemFreeList != (OS_MEM *)0) {               /* See if pool of free partitions was empty      */
+        OSMemFreeList = (OS_MEM *)OSMemFreeList->OSMemFreeList;
+    }
+    OS_EXIT_CRITICAL();
+    if (pmem == (OS_MEM *)0) {                        /* See if we have a memory partition             */
+        *perr = OS_ERR_MEM_INVALID_PART;
+        return ((OS_MEM *)0);
+    }
+    plink = (void **)addr;                            /* Create linked list of free memory blocks      */
+    pblk  = (INT8U *)addr;
+    loops  = nblks - 1u;
+    for (i = 0u; i < loops; i++) {
+        pblk +=  blksize;                             /* Point to the FOLLOWING block                  */
+       *plink = (void  *)pblk;                        /* Save pointer to NEXT block in CURRENT block   */
+        plink = (void **)pblk;                        /* Position to  NEXT      block                  */
+    }
+    *plink              = (void *)0;                  /* Last memory block points to NULL              */
+    pmem->OSMemAddr     = addr;                       /* Store start address of memory partition       */
+    pmem->OSMemFreeList = addr;                       /* Initialize pointer to pool of free blocks     */
+    pmem->OSMemNFree    = nblks;                      /* Store number of free blocks in MCB            */
+    pmem->OSMemNBlks    = nblks;
+    pmem->OSMemBlkSize  = blksize;                    /* Store block size of each memory blocks        */
+    *perr               = OS_ERR_NONE;
+    return (pmem);
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                          GET A MEMORY BLOCK
+*
+* Description : Get a memory block from a partition
+*
+* Arguments   : pmem    is a pointer to the memory partition control block
+*
+*               perr    is a pointer to a variable containing an error message which will be set by this
+*                       function to either:
+*
+*                       OS_ERR_NONE             if the memory partition has been created correctly.
+*                       OS_ERR_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
+*                       OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
+*
+* Returns     : A pointer to a memory block if no error is detected
+*               A pointer to NULL if an error is detected
+*********************************************************************************************************
+*/
+
+void  *OSMemGet (OS_MEM  *pmem,
+                 INT8U   *perr)
+{
+    void      *pblk;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pmem == (OS_MEM *)0) {                        /* Must point to a valid memory partition        */
+        *perr = OS_ERR_MEM_INVALID_PMEM;
+        return ((void *)0);
+    }
+#endif
+    OS_ENTER_CRITICAL();
+    if (pmem->OSMemNFree > 0u) {                      /* See if there are any free memory blocks       */
+        pblk                = pmem->OSMemFreeList;    /* Yes, point to next free memory block          */
+        pmem->OSMemFreeList = *(void **)pblk;         /*      Adjust pointer to new free list          */
+        pmem->OSMemNFree--;                           /*      One less memory block in this partition  */
+        OS_EXIT_CRITICAL();
+        *perr = OS_ERR_NONE;                          /*      No error                                 */
+        return (pblk);                                /*      Return memory block to caller            */
+    }
+    OS_EXIT_CRITICAL();
+    *perr = OS_ERR_MEM_NO_FREE_BLKS;                  /* No,  Notify caller of empty memory partition  */
+    return ((void *)0);                               /*      Return NULL pointer to caller            */
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                   GET THE NAME OF A MEMORY PARTITION
+*
+* Description: This function is used to obtain the name assigned to a memory partition.
+*
+* Arguments  : pmem      is a pointer to the memory partition
+*
+*              pname     is a pointer to a pointer to an ASCII string that will receive the name of the memory partition.
+*
+*              perr      is a pointer to an error code that can contain one of the following values:
+*
+*                        OS_ERR_NONE                if the name was copied to 'pname'
+*                        OS_ERR_MEM_INVALID_PMEM    if you passed a NULL pointer for 'pmem'
+*                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
+*                        OS_ERR_NAME_GET_ISR        You called this function from an ISR
+*
+* Returns    : The length of the string or 0 if 'pmem' is a NULL pointer.
+*********************************************************************************************************
+*/
+
+#if OS_MEM_NAME_EN > 0u
+INT8U  OSMemNameGet (OS_MEM   *pmem,
+                     INT8U   **pname,
+                     INT8U    *perr)
+{
+    INT8U      len;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
+        *perr = OS_ERR_MEM_INVALID_PMEM;
+        return (0u);
+    }
+    if (pname == (INT8U **)0) {                  /* Is 'pname' a NULL pointer?                         */
+        *perr = OS_ERR_PNAME_NULL;
+        return (0u);
+    }
+#endif
+    if (OSIntNesting > 0u) {                     /* See if trying to call from an ISR                  */
+        *perr = OS_ERR_NAME_GET_ISR;
+        return (0u);
+    }
+    OS_ENTER_CRITICAL();
+    *pname = pmem->OSMemName;
+    len    = OS_StrLen(*pname);
+    OS_EXIT_CRITICAL();
+    *perr  = OS_ERR_NONE;
+    return (len);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                 ASSIGN A NAME TO A MEMORY PARTITION
+*
+* Description: This function assigns a name to a memory partition.
+*
+* Arguments  : pmem      is a pointer to the memory partition
+*
+*              pname     is a pointer to an ASCII string that contains the name of the memory partition.
+*
+*              perr      is a pointer to an error code that can contain one of the following values:
+*
+*                        OS_ERR_NONE                if the name was copied to 'pname'
+*                        OS_ERR_MEM_INVALID_PMEM    if you passed a NULL pointer for 'pmem'
+*                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
+*                        OS_ERR_MEM_NAME_TOO_LONG   if the name doesn't fit in the storage area
+*                        OS_ERR_NAME_SET_ISR        if you called this function from an ISR
+*
+* Returns    : None
+*********************************************************************************************************
+*/
+
+#if OS_MEM_NAME_EN > 0u
+void  OSMemNameSet (OS_MEM  *pmem,
+                    INT8U   *pname,
+                    INT8U   *perr)
+{
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
+        *perr = OS_ERR_MEM_INVALID_PMEM;
+        return;
+    }
+    if (pname == (INT8U *)0) {                   /* Is 'pname' a NULL pointer?                         */
+        *perr = OS_ERR_PNAME_NULL;
+        return;
+    }
+#endif
+    if (OSIntNesting > 0u) {                     /* See if trying to call from an ISR                  */
+        *perr = OS_ERR_NAME_SET_ISR;
+        return;
+    }
+    OS_ENTER_CRITICAL();
+    pmem->OSMemName = pname;
+    OS_EXIT_CRITICAL();
+    *perr           = OS_ERR_NONE;
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                         RELEASE A MEMORY BLOCK
+*
+* Description : Returns a memory block to a partition
+*
+* Arguments   : pmem    is a pointer to the memory partition control block
+*
+*               pblk    is a pointer to the memory block being released.
+*
+* Returns     : OS_ERR_NONE              if the memory block was inserted into the partition
+*               OS_ERR_MEM_FULL          if you are returning a memory block to an already FULL memory
+*                                        partition (You freed more blocks than you allocated!)
+*               OS_ERR_MEM_INVALID_PMEM  if you passed a NULL pointer for 'pmem'
+*               OS_ERR_MEM_INVALID_PBLK  if you passed a NULL pointer for the block to release.
+*********************************************************************************************************
+*/
+
+INT8U  OSMemPut (OS_MEM  *pmem,
+                 void    *pblk)
+{
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
+        return (OS_ERR_MEM_INVALID_PMEM);
+    }
+    if (pblk == (void *)0) {                     /* Must release a valid block                         */
+        return (OS_ERR_MEM_INVALID_PBLK);
+    }
+#endif
+    OS_ENTER_CRITICAL();
+    if (pmem->OSMemNFree >= pmem->OSMemNBlks) {  /* Make sure all blocks not already returned          */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_MEM_FULL);
+    }
+    *(void **)pblk      = pmem->OSMemFreeList;   /* Insert released block into free block list         */
+    pmem->OSMemFreeList = pblk;
+    pmem->OSMemNFree++;                          /* One more memory block in this partition            */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);                        /* Notify caller that memory block was released       */
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                          QUERY MEMORY PARTITION
+*
+* Description : This function is used to determine the number of free memory blocks and the number of
+*               used memory blocks from a memory partition.
+*
+* Arguments   : pmem        is a pointer to the memory partition control block
+*
+*               p_mem_data  is a pointer to a structure that will contain information about the memory
+*                           partition.
+*
+* Returns     : OS_ERR_NONE               if no errors were found.
+*               OS_ERR_MEM_INVALID_PMEM   if you passed a NULL pointer for 'pmem'
+*               OS_ERR_MEM_INVALID_PDATA  if you passed a NULL pointer to the data recipient.
+*********************************************************************************************************
+*/
+
+#if OS_MEM_QUERY_EN > 0u
+INT8U  OSMemQuery (OS_MEM       *pmem,
+                   OS_MEM_DATA  *p_mem_data)
+{
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
+        return (OS_ERR_MEM_INVALID_PMEM);
+    }
+    if (p_mem_data == (OS_MEM_DATA *)0) {        /* Must release a valid storage area for the data     */
+        return (OS_ERR_MEM_INVALID_PDATA);
+    }
+#endif
+    OS_ENTER_CRITICAL();
+    p_mem_data->OSAddr     = pmem->OSMemAddr;
+    p_mem_data->OSFreeList = pmem->OSMemFreeList;
+    p_mem_data->OSBlkSize  = pmem->OSMemBlkSize;
+    p_mem_data->OSNBlks    = pmem->OSMemNBlks;
+    p_mem_data->OSNFree    = pmem->OSMemNFree;
+    OS_EXIT_CRITICAL();
+    p_mem_data->OSNUsed    = p_mem_data->OSNBlks - p_mem_data->OSNFree;
+    return (OS_ERR_NONE);
+}
+#endif                                           /* OS_MEM_QUERY_EN                                    */
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                    INITIALIZE MEMORY PARTITION MANAGER
+*
+* Description : This function is called by uC/OS-II to initialize the memory partition manager.  Your
+*               application MUST NOT call this function.
+*
+* Arguments   : none
+*
+* Returns     : none
+*
+* Note(s)    : This function is INTERNAL to uC/OS-II and your application should not call it.
+*********************************************************************************************************
+*/
+
+void  OS_MemInit (void)
+{
+#if OS_MAX_MEM_PART == 1u
+    OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl));   /* Clear the memory partition table          */
+    OSMemFreeList               = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list           */
+#if OS_MEM_NAME_EN > 0u
+    OSMemFreeList->OSMemName    = (INT8U *)"?";           /* Unknown name                              */
+#endif
+#endif
+
+#if OS_MAX_MEM_PART >= 2u
+    OS_MEM  *pmem;
+    INT16U   i;
+
+
+    OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl));   /* Clear the memory partition table          */
+    for (i = 0u; i < (OS_MAX_MEM_PART - 1u); i++) {       /* Init. list of free memory partitions      */
+        pmem                = &OSMemTbl[i];               /* Point to memory control block (MCB)       */
+        pmem->OSMemFreeList = (void *)&OSMemTbl[i + 1u];  /* Chain list of free partitions             */
+#if OS_MEM_NAME_EN > 0u
+        pmem->OSMemName  = (INT8U *)(void *)"?";
+#endif
+    }
+    pmem                = &OSMemTbl[i];
+    pmem->OSMemFreeList = (void *)0;                      /* Initialize last node                      */
+#if OS_MEM_NAME_EN > 0u
+    pmem->OSMemName = (INT8U *)(void *)"?";
+#endif
+
+    OSMemFreeList   = &OSMemTbl[0];                       /* Point to beginning of free list           */
+#endif
+}
+#endif                                                    /* OS_MEM_EN                                 */
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

+ 735 - 0
app/UCOS-II/Source/os_mutex.c

@@ -0,0 +1,735 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                  MUTUAL EXCLUSION SEMAPHORE MANAGEMENT
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_MUTEX.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef  OS_MASTER_FILE
+#include <ucos_ii.h>
+#endif
+
+
+#if OS_MUTEX_EN > 0u
+/*
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*/
+
+#define  OS_MUTEX_KEEP_LOWER_8   ((INT16U)0x00FFu)
+#define  OS_MUTEX_KEEP_UPPER_8   ((INT16U)0xFF00u)
+
+#define  OS_MUTEX_AVAILABLE      ((INT16U)0x00FFu)
+
+/*
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*/
+
+static  void  OSMutex_RdyAtPrio(OS_TCB *ptcb, INT8U prio);
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                   ACCEPT MUTUAL EXCLUSION SEMAPHORE
+*
+* Description: This  function checks the mutual exclusion semaphore to see if a resource is available.
+*              Unlike OSMutexPend(), OSMutexAccept() does not suspend the calling task if the resource is
+*              not available or the event did not occur.
+*
+* Arguments  : pevent     is a pointer to the event control block
+*
+*              perr       is a pointer to an error code which will be returned to your application:
+*                            OS_ERR_NONE         if the call was successful.
+*                            OS_ERR_EVENT_TYPE   if 'pevent' is not a pointer to a mutex
+*                            OS_ERR_PEVENT_NULL  'pevent' is a NULL pointer
+*                            OS_ERR_PEND_ISR     if you called this function from an ISR
+*                            OS_ERR_PIP_LOWER    If the priority of the task that owns the Mutex is
+*                                                HIGHER (i.e. a lower number) than the PIP.  This error
+*                                                indicates that you did not set the PIP higher (lower
+*                                                number) than ALL the tasks that compete for the Mutex.
+*                                                Unfortunately, this is something that could not be
+*                                                detected when the Mutex is created because we don't know
+*                                                what tasks will be using the Mutex.
+*
+* Returns    : == OS_TRUE    if the resource is available, the mutual exclusion semaphore is acquired
+*              == OS_FALSE   a) if the resource is not available
+*                            b) you didn't pass a pointer to a mutual exclusion semaphore
+*                            c) you called this function from an ISR
+*
+* Warning(s) : This function CANNOT be called from an ISR because mutual exclusion semaphores are
+*              intended to be used by tasks only.
+*********************************************************************************************************
+*/
+
+#if OS_MUTEX_ACCEPT_EN > 0u
+BOOLEAN  OSMutexAccept (OS_EVENT  *pevent,
+                        INT8U     *perr)
+{
+    INT8U      pip;                                    /* Priority Inheritance Priority (PIP)          */
+#if OS_CRITICAL_METHOD == 3u                           /* Allocate storage for CPU status register     */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                     /* Validate 'pevent'                            */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (OS_FALSE);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) {  /* Validate event block type                    */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (OS_FALSE);
+    }
+    if (OSIntNesting > 0u) {                           /* Make sure it's not called from an ISR        */
+        *perr = OS_ERR_PEND_ISR;
+        return (OS_FALSE);
+    }
+    OS_ENTER_CRITICAL();                               /* Get value (0 or 1) of Mutex                  */
+    pip = (INT8U)(pevent->OSEventCnt >> 8u);           /* Get PIP from mutex                           */
+    if ((pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8) == OS_MUTEX_AVAILABLE) {
+        pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8;   /*      Mask off LSByte (Acquire Mutex)         */
+        pevent->OSEventCnt |= OSTCBCur->OSTCBPrio;     /*      Save current task priority in LSByte    */
+        pevent->OSEventPtr  = (void *)OSTCBCur;        /*      Link TCB of task owning Mutex           */
+        if (OSTCBCur->OSTCBPrio <= pip) {              /*      PIP 'must' have a SMALLER prio ...      */
+            OS_EXIT_CRITICAL();                        /*      ... than current task!                  */
+            *perr = OS_ERR_PIP_LOWER;
+        } else {
+            OS_EXIT_CRITICAL();
+            *perr = OS_ERR_NONE;
+        }
+        return (OS_TRUE);
+    }
+    OS_EXIT_CRITICAL();
+    *perr = OS_ERR_NONE;
+    return (OS_FALSE);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                  CREATE A MUTUAL EXCLUSION SEMAPHORE
+*
+* Description: This function creates a mutual exclusion semaphore.
+*
+* Arguments  : prio          is the priority to use when accessing the mutual exclusion semaphore.  In
+*                            other words, when the semaphore is acquired and a higher priority task
+*                            attempts to obtain the semaphore then the priority of the task owning the
+*                            semaphore is raised to this priority.  It is assumed that you will specify
+*                            a priority that is LOWER in value than ANY of the tasks competing for the
+*                            mutex.
+*
+*              perr          is a pointer to an error code which will be returned to your application:
+*                               OS_ERR_NONE         if the call was successful.
+*                               OS_ERR_CREATE_ISR   if you attempted to create a MUTEX from an ISR
+*                               OS_ERR_PRIO_EXIST   if a task at the priority inheritance priority
+*                                                   already exist.
+*                               OS_ERR_PEVENT_NULL  No more event control blocks available.
+*                               OS_ERR_PRIO_INVALID if the priority you specify is higher that the
+*                                                   maximum allowed (i.e. > OS_LOWEST_PRIO)
+*
+* Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
+*                            created mutex.
+*              == (void *)0  if an error is detected.
+*
+* Note(s)    : 1) The LEAST significant 8 bits of '.OSEventCnt' are used to hold the priority number
+*                 of the task owning the mutex or 0xFF if no task owns the mutex.
+*
+*              2) The MOST  significant 8 bits of '.OSEventCnt' are used to hold the priority number
+*                 to use to reduce priority inversion.
+*********************************************************************************************************
+*/
+
+OS_EVENT  *OSMutexCreate (INT8U   prio,
+                          INT8U  *perr)
+{
+    OS_EVENT  *pevent;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#ifdef OS_SAFETY_CRITICAL_IEC61508
+    if (OSSafetyCriticalStartFlag == OS_TRUE) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (prio >= OS_LOWEST_PRIO) {                          /* Validate PIP                             */
+        *perr = OS_ERR_PRIO_INVALID;
+        return ((OS_EVENT *)0);
+    }
+#endif
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        *perr = OS_ERR_CREATE_ISR;                         /* ... can't CREATE mutex from an ISR       */
+        return ((OS_EVENT *)0);
+    }
+    OS_ENTER_CRITICAL();
+    if (OSTCBPrioTbl[prio] != (OS_TCB *)0) {               /* Mutex priority must not already exist    */
+        OS_EXIT_CRITICAL();                                /* Task already exist at priority ...       */
+        *perr = OS_ERR_PRIO_EXIST;                         /* ... inheritance priority                 */
+        return ((OS_EVENT *)0);
+    }
+    OSTCBPrioTbl[prio] = OS_TCB_RESERVED;                  /* Reserve the table entry                  */
+    pevent             = OSEventFreeList;                  /* Get next free event control block        */
+    if (pevent == (OS_EVENT *)0) {                         /* See if an ECB was available              */
+        OSTCBPrioTbl[prio] = (OS_TCB *)0;                  /* No, Release the table entry              */
+        OS_EXIT_CRITICAL();
+        *perr              = OS_ERR_PEVENT_NULL;           /* No more event control blocks             */
+        return (pevent);
+    }
+    OSEventFreeList        = (OS_EVENT *)OSEventFreeList->OSEventPtr;   /* Adjust the free list        */
+    OS_EXIT_CRITICAL();
+    pevent->OSEventType    = OS_EVENT_TYPE_MUTEX;
+    pevent->OSEventCnt     = (INT16U)((INT16U)prio << 8u) | OS_MUTEX_AVAILABLE; /* Resource is avail.  */
+    pevent->OSEventPtr     = (void *)0;                                 /* No task owning the mutex    */
+#if OS_EVENT_NAME_EN > 0u
+    pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+    OS_EventWaitListInit(pevent);
+    *perr                  = OS_ERR_NONE;
+    return (pevent);
+}
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                          DELETE A MUTEX
+*
+* Description: This function deletes a mutual exclusion semaphore and readies all tasks pending on the it.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired mutex.
+*
+*              opt           determines delete options as follows:
+*                            opt == OS_DEL_NO_PEND   Delete mutex ONLY if no task pending
+*                            opt == OS_DEL_ALWAYS    Deletes the mutex even if tasks are waiting.
+*                                                    In this case, all the tasks pending will be readied.
+*
+*              perr          is a pointer to an error code that can contain one of the following values:
+*                            OS_ERR_NONE             The call was successful and the mutex was deleted
+*                            OS_ERR_DEL_ISR          If you attempted to delete the MUTEX from an ISR
+*                            OS_ERR_INVALID_OPT      An invalid option was specified
+*                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the mutex
+*                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a mutex
+*                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
+*
+* Returns    : pevent        upon error
+*              (OS_EVENT *)0 if the mutex was successfully deleted.
+*
+* Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
+*                 the mutex MUST check the return code of OSMutexPend().
+*
+*              2) This call can potentially disable interrupts for a long time.  The interrupt disable
+*                 time is directly proportional to the number of tasks waiting on the mutex.
+*
+*              3) Because ALL tasks pending on the mutex will be readied, you MUST be careful because the
+*                 resource(s) will no longer be guarded by the mutex.
+*
+*              4) IMPORTANT: In the 'OS_DEL_ALWAYS' case, we assume that the owner of the Mutex (if there
+*                            is one) is ready-to-run and is thus NOT pending on another kernel object or
+*                            has delayed itself.  In other words, if a task owns the mutex being deleted,
+*                            that task will be made ready-to-run at its original priority.
+*********************************************************************************************************
+*/
+
+#if OS_MUTEX_DEL_EN > 0u
+OS_EVENT  *OSMutexDel (OS_EVENT  *pevent,
+                       INT8U      opt,
+                       INT8U     *perr)
+{
+    BOOLEAN    tasks_waiting;
+    OS_EVENT  *pevent_return;
+    INT8U      pip;                                        /* Priority inheritance priority            */
+    INT8U      prio;
+    OS_TCB    *ptcb;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (pevent);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) {      /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (pevent);
+    }
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        *perr = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
+        return (pevent);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                        /* See if any tasks waiting on mutex        */
+        tasks_waiting = OS_TRUE;                           /* Yes                                      */
+    } else {
+        tasks_waiting = OS_FALSE;                          /* No                                       */
+    }
+    switch (opt) {
+        case OS_DEL_NO_PEND:                               /* DELETE MUTEX ONLY IF NO TASK WAITING --- */
+             if (tasks_waiting == OS_FALSE) {
+#if OS_EVENT_NAME_EN > 0u
+                 pevent->OSEventName = (INT8U *)(void *)"?";
+#endif
+                 pip                 = (INT8U)(pevent->OSEventCnt >> 8u);
+                 OSTCBPrioTbl[pip]   = (OS_TCB *)0;        /* Free up the PIP                          */
+                 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
+                 pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
+                 pevent->OSEventCnt  = 0u;
+                 OSEventFreeList     = pevent;
+                 OS_EXIT_CRITICAL();
+                 *perr               = OS_ERR_NONE;
+                 pevent_return       = (OS_EVENT *)0;      /* Mutex has been deleted                   */
+             } else {
+                 OS_EXIT_CRITICAL();
+                 *perr               = OS_ERR_TASK_WAITING;
+                 pevent_return       = pevent;
+             }
+             break;
+
+        case OS_DEL_ALWAYS:                                /* ALWAYS DELETE THE MUTEX ---------------- */
+             pip  = (INT8U)(pevent->OSEventCnt >> 8u);                    /* Get PIP of mutex          */
+             prio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);  /* Get owner's original prio */
+             ptcb = (OS_TCB *)pevent->OSEventPtr;
+             if (ptcb != (OS_TCB *)0) {                    /* See if any task owns the mutex           */
+                 if (ptcb->OSTCBPrio == pip) {             /* See if original prio was changed         */
+                     OSMutex_RdyAtPrio(ptcb, prio);        /* Yes, Restore the task's original prio    */
+                 }
+             }
+             while (pevent->OSEventGrp != 0u) {            /* Ready ALL tasks waiting for mutex        */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MUTEX, OS_STAT_PEND_OK);
+             }
+#if OS_EVENT_NAME_EN > 0u
+             pevent->OSEventName = (INT8U *)(void *)"?";
+#endif
+             pip                 = (INT8U)(pevent->OSEventCnt >> 8u);
+             OSTCBPrioTbl[pip]   = (OS_TCB *)0;            /* Free up the PIP                          */
+             pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
+             pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
+             pevent->OSEventCnt  = 0u;
+             OSEventFreeList     = pevent;                 /* Get next free event control block        */
+             OS_EXIT_CRITICAL();
+             if (tasks_waiting == OS_TRUE) {               /* Reschedule only if task(s) were waiting  */
+                 OS_Sched();                               /* Find highest priority task ready to run  */
+             }
+             *perr         = OS_ERR_NONE;
+             pevent_return = (OS_EVENT *)0;                /* Mutex has been deleted                   */
+             break;
+
+        default:
+             OS_EXIT_CRITICAL();
+             *perr         = OS_ERR_INVALID_OPT;
+             pevent_return = pevent;
+             break;
+    }
+    return (pevent_return);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                  PEND ON MUTUAL EXCLUSION SEMAPHORE
+*
+* Description: This function waits for a mutual exclusion semaphore.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            mutex.
+*
+*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
+*                            wait for the resource up to the amount of time specified by this argument.
+*                            If you specify 0, however, your task will wait forever at the specified
+*                            mutex or, until the resource becomes available.
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*                               OS_ERR_NONE        The call was successful and your task owns the mutex
+*                               OS_ERR_TIMEOUT     The mutex was not available within the specified 'timeout'.
+*                               OS_ERR_PEND_ABORT  The wait on the mutex was aborted.
+*                               OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a mutex
+*                               OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
+*                               OS_ERR_PEND_ISR    If you called this function from an ISR and the result
+*                                                  would lead to a suspension.
+*                               OS_ERR_PIP_LOWER   If the priority of the task that owns the Mutex is
+*                                                  HIGHER (i.e. a lower number) than the PIP.  This error
+*                                                  indicates that you did not set the PIP higher (lower
+*                                                  number) than ALL the tasks that compete for the Mutex.
+*                                                  Unfortunately, this is something that could not be
+*                                                  detected when the Mutex is created because we don't know
+*                                                  what tasks will be using the Mutex.
+*                               OS_ERR_PEND_LOCKED If you called this function when the scheduler is locked
+*
+* Returns    : none
+*
+* Note(s)    : 1) The task that owns the Mutex MUST NOT pend on any other event while it owns the mutex.
+*
+*              2) You MUST NOT change the priority of the task that owns the mutex
+*********************************************************************************************************
+*/
+
+void  OSMutexPend (OS_EVENT  *pevent,
+                   INT32U     timeout,
+                   INT8U     *perr)
+{
+    INT8U      pip;                                        /* Priority Inheritance Priority (PIP)      */
+    INT8U      mprio;                                      /* Mutex owner priority                     */
+    BOOLEAN    rdy;                                        /* Flag indicating task was ready           */
+    OS_TCB    *ptcb;
+    OS_EVENT  *pevent2;
+    INT8U      y;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return;
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) {      /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return;
+    }
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        *perr = OS_ERR_PEND_ISR;                           /* ... can't PEND from an ISR               */
+        return;
+    }
+    if (OSLockNesting > 0u) {                              /* See if called with scheduler locked ...  */
+        *perr = OS_ERR_PEND_LOCKED;                        /* ... can't PEND when locked               */
+        return;
+    }
+/*$PAGE*/
+    OS_ENTER_CRITICAL();
+    pip = (INT8U)(pevent->OSEventCnt >> 8u);               /* Get PIP from mutex                       */
+                                                           /* Is Mutex available?                      */
+    if ((INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8) == OS_MUTEX_AVAILABLE) {
+        pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8;       /* Yes, Acquire the resource                */
+        pevent->OSEventCnt |= OSTCBCur->OSTCBPrio;         /*      Save priority of owning task        */
+        pevent->OSEventPtr  = (void *)OSTCBCur;            /*      Point to owning task's OS_TCB       */
+        if (OSTCBCur->OSTCBPrio <= pip) {                  /*      PIP 'must' have a SMALLER prio ...  */
+            OS_EXIT_CRITICAL();                            /*      ... than current task!              */
+            *perr = OS_ERR_PIP_LOWER;
+        } else {
+            OS_EXIT_CRITICAL();
+            *perr = OS_ERR_NONE;
+        }
+        return;
+    }
+    mprio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);  /* No, Get priority of mutex owner   */
+    ptcb  = (OS_TCB *)(pevent->OSEventPtr);                       /*     Point to TCB of mutex owner   */
+    if (ptcb->OSTCBPrio > pip) {                                  /*     Need to promote prio of owner?*/
+        if (mprio > OSTCBCur->OSTCBPrio) {
+            y = ptcb->OSTCBY;
+            if ((OSRdyTbl[y] & ptcb->OSTCBBitX) != 0u) {          /*     See if mutex owner is ready   */
+                OSRdyTbl[y] &= (OS_PRIO)~ptcb->OSTCBBitX;         /*     Yes, Remove owner from Rdy ...*/
+                if (OSRdyTbl[y] == 0u) {                          /*          ... list at current prio */
+                    OSRdyGrp &= (OS_PRIO)~ptcb->OSTCBBitY;
+                }
+                rdy = OS_TRUE;
+            } else {
+                pevent2 = ptcb->OSTCBEventPtr;
+                if (pevent2 != (OS_EVENT *)0) {                   /* Remove from event wait list       */
+                    y = ptcb->OSTCBY;
+                    pevent2->OSEventTbl[y] &= (OS_PRIO)~ptcb->OSTCBBitX;
+                    if (pevent2->OSEventTbl[y] == 0u) {
+                        pevent2->OSEventGrp &= (OS_PRIO)~ptcb->OSTCBBitY;
+                    }
+                }
+                rdy = OS_FALSE;                            /* No                                       */
+            }
+            ptcb->OSTCBPrio = pip;                         /* Change owner task prio to PIP            */
+#if OS_LOWEST_PRIO <= 63u
+            ptcb->OSTCBY    = (INT8U)( ptcb->OSTCBPrio >> 3u);
+            ptcb->OSTCBX    = (INT8U)( ptcb->OSTCBPrio & 0x07u);
+#else
+            ptcb->OSTCBY    = (INT8U)((INT8U)(ptcb->OSTCBPrio >> 4u) & 0xFFu);
+            ptcb->OSTCBX    = (INT8U)( ptcb->OSTCBPrio & 0x0Fu);
+#endif
+            ptcb->OSTCBBitY = (OS_PRIO)(1uL << ptcb->OSTCBY);
+            ptcb->OSTCBBitX = (OS_PRIO)(1uL << ptcb->OSTCBX);
+
+            if (rdy == OS_TRUE) {                          /* If task was ready at owner's priority ...*/
+                OSRdyGrp               |= ptcb->OSTCBBitY; /* ... make it ready at new priority.       */
+                OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
+            } else {
+                pevent2 = ptcb->OSTCBEventPtr;
+                if (pevent2 != (OS_EVENT *)0) {            /* Add to event wait list                   */
+                    pevent2->OSEventGrp               |= ptcb->OSTCBBitY;
+                    pevent2->OSEventTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
+                }
+            }
+            OSTCBPrioTbl[pip] = ptcb;
+        }
+    }
+    OSTCBCur->OSTCBStat     |= OS_STAT_MUTEX;         /* Mutex not available, pend current task        */
+    OSTCBCur->OSTCBStatPend  = OS_STAT_PEND_OK;
+    OSTCBCur->OSTCBDly       = timeout;               /* Store timeout in current task's TCB           */
+    OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
+    OS_EXIT_CRITICAL();
+    OS_Sched();                                       /* Find next highest priority task ready         */
+    OS_ENTER_CRITICAL();
+    switch (OSTCBCur->OSTCBStatPend) {                /* See if we timed-out or aborted                */
+        case OS_STAT_PEND_OK:
+             *perr = OS_ERR_NONE;
+             break;
+
+        case OS_STAT_PEND_ABORT:
+             *perr = OS_ERR_PEND_ABORT;               /* Indicate that we aborted getting mutex        */
+             break;
+
+        case OS_STAT_PEND_TO:
+        default:
+             OS_EventTaskRemove(OSTCBCur, pevent);
+             *perr = OS_ERR_TIMEOUT;                  /* Indicate that we didn't get mutex within TO   */
+             break;
+    }
+    OSTCBCur->OSTCBStat          =  OS_STAT_RDY;      /* Set   task  status to ready                   */
+    OSTCBCur->OSTCBStatPend      =  OS_STAT_PEND_OK;  /* Clear pend  status                            */
+    OSTCBCur->OSTCBEventPtr      = (OS_EVENT  *)0;    /* Clear event pointers                          */
+#if (OS_EVENT_MULTI_EN > 0u)
+    OSTCBCur->OSTCBEventMultiPtr = (OS_EVENT **)0;
+#endif
+    OS_EXIT_CRITICAL();
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                  POST TO A MUTUAL EXCLUSION SEMAPHORE
+*
+* Description: This function signals a mutual exclusion semaphore
+*
+* Arguments  : pevent              is a pointer to the event control block associated with the desired
+*                                  mutex.
+*
+* Returns    : OS_ERR_NONE             The call was successful and the mutex was signaled.
+*              OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a mutex
+*              OS_ERR_PEVENT_NULL      'pevent' is a NULL pointer
+*              OS_ERR_POST_ISR         Attempted to post from an ISR (not valid for MUTEXes)
+*              OS_ERR_NOT_MUTEX_OWNER  The task that did the post is NOT the owner of the MUTEX.
+*              OS_ERR_PIP_LOWER        If the priority of the new task that owns the Mutex is
+*                                      HIGHER (i.e. a lower number) than the PIP.  This error
+*                                      indicates that you did not set the PIP higher (lower
+*                                      number) than ALL the tasks that compete for the Mutex.
+*                                      Unfortunately, this is something that could not be
+*                                      detected when the Mutex is created because we don't know
+*                                      what tasks will be using the Mutex.
+*********************************************************************************************************
+*/
+
+INT8U  OSMutexPost (OS_EVENT *pevent)
+{
+    INT8U      pip;                                   /* Priority inheritance priority                 */
+    INT8U      prio;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+    if (OSIntNesting > 0u) {                          /* See if called from ISR ...                    */
+        return (OS_ERR_POST_ISR);                     /* ... can't POST mutex from an ISR              */
+    }
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    pip  = (INT8U)(pevent->OSEventCnt >> 8u);         /* Get priority inheritance priority of mutex    */
+    prio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);  /* Get owner's original priority      */
+    if (OSTCBCur != (OS_TCB *)pevent->OSEventPtr) {   /* See if posting task owns the MUTEX            */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_NOT_MUTEX_OWNER);
+    }
+    if (OSTCBCur->OSTCBPrio == pip) {                 /* Did we have to raise current task's priority? */
+        OSMutex_RdyAtPrio(OSTCBCur, prio);            /* Restore the task's original priority          */
+    }
+    OSTCBPrioTbl[pip] = OS_TCB_RESERVED;              /* Reserve table entry                           */
+    if (pevent->OSEventGrp != 0u) {                   /* Any task waiting for the mutex?               */
+                                                      /* Yes, Make HPT waiting for mutex ready         */
+        prio                = OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MUTEX, OS_STAT_PEND_OK);
+        pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8;  /*      Save priority of mutex's new owner       */
+        pevent->OSEventCnt |= prio;
+        pevent->OSEventPtr  = OSTCBPrioTbl[prio];     /*      Link to new mutex owner's OS_TCB         */
+        if (prio <= pip) {                            /*      PIP 'must' have a SMALLER prio ...       */
+            OS_EXIT_CRITICAL();                       /*      ... than current task!                   */
+            OS_Sched();                               /*      Find highest priority task ready to run  */
+            return (OS_ERR_PIP_LOWER);
+        } else {
+            OS_EXIT_CRITICAL();
+            OS_Sched();                               /*      Find highest priority task ready to run  */
+            return (OS_ERR_NONE);
+        }
+    }
+    pevent->OSEventCnt |= OS_MUTEX_AVAILABLE;         /* No,  Mutex is now available                   */
+    pevent->OSEventPtr  = (void *)0;
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                     QUERY A MUTUAL EXCLUSION SEMAPHORE
+*
+* Description: This function obtains information about a mutex
+*
+* Arguments  : pevent          is a pointer to the event control block associated with the desired mutex
+*
+*              p_mutex_data    is a pointer to a structure that will contain information about the mutex
+*
+* Returns    : OS_ERR_NONE          The call was successful and the message was sent
+*              OS_ERR_QUERY_ISR     If you called this function from an ISR
+*              OS_ERR_PEVENT_NULL   If 'pevent'       is a NULL pointer
+*              OS_ERR_PDATA_NULL    If 'p_mutex_data' is a NULL pointer
+*              OS_ERR_EVENT_TYPE    If you are attempting to obtain data from a non mutex.
+*********************************************************************************************************
+*/
+
+#if OS_MUTEX_QUERY_EN > 0u
+INT8U  OSMutexQuery (OS_EVENT       *pevent,
+                     OS_MUTEX_DATA  *p_mutex_data)
+{
+    INT8U       i;
+    OS_PRIO    *psrc;
+    OS_PRIO    *pdest;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR   cpu_sr = 0u;
+#endif
+
+
+
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        return (OS_ERR_QUERY_ISR);                         /* ... can't QUERY mutex from an ISR        */
+    }
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (p_mutex_data == (OS_MUTEX_DATA *)0) {              /* Validate 'p_mutex_data'                  */
+        return (OS_ERR_PDATA_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) {      /* Validate event block type                */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    p_mutex_data->OSMutexPIP  = (INT8U)(pevent->OSEventCnt >> 8u);
+    p_mutex_data->OSOwnerPrio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);
+    if (p_mutex_data->OSOwnerPrio == 0xFFu) {
+        p_mutex_data->OSValue = OS_TRUE;
+    } else {
+        p_mutex_data->OSValue = OS_FALSE;
+    }
+    p_mutex_data->OSEventGrp  = pevent->OSEventGrp;        /* Copy wait list                           */
+    psrc                      = &pevent->OSEventTbl[0];
+    pdest                     = &p_mutex_data->OSEventTbl[0];
+    for (i = 0u; i < OS_EVENT_TBL_SIZE; i++) {
+        *pdest++ = *psrc++;
+    }
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif                                                     /* OS_MUTEX_QUERY_EN                        */
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                RESTORE A TASK BACK TO ITS ORIGINAL PRIORITY
+*
+* Description: This function makes a task ready at the specified priority
+*
+* Arguments  : ptcb            is a pointer to OS_TCB of the task to make ready
+*
+*              prio            is the desired priority
+*
+* Returns    : none
+*********************************************************************************************************
+*/
+
+static  void  OSMutex_RdyAtPrio (OS_TCB  *ptcb,
+                                 INT8U    prio)
+{
+    INT8U  y;
+
+
+    y            =  ptcb->OSTCBY;                          /* Remove owner from ready list at 'pip'    */
+    OSRdyTbl[y] &= (OS_PRIO)~ptcb->OSTCBBitX;
+    if (OSRdyTbl[y] == 0u) {
+        OSRdyGrp &= (OS_PRIO)~ptcb->OSTCBBitY;
+    }
+    ptcb->OSTCBPrio         = prio;
+    OSPrioCur               = prio;                        /* The current task is now at this priority */
+#if OS_LOWEST_PRIO <= 63u
+    ptcb->OSTCBY            = (INT8U)((INT8U)(prio >> 3u) & 0x07u);
+    ptcb->OSTCBX            = (INT8U)(prio & 0x07u);
+#else
+    ptcb->OSTCBY            = (INT8U)((INT8U)(prio >> 4u) & 0x0Fu);
+    ptcb->OSTCBX            = (INT8U) (prio & 0x0Fu);
+#endif
+    ptcb->OSTCBBitY         = (OS_PRIO)(1uL << ptcb->OSTCBY);
+    ptcb->OSTCBBitX         = (OS_PRIO)(1uL << ptcb->OSTCBX);
+    OSRdyGrp               |= ptcb->OSTCBBitY;             /* Make task ready at original priority     */
+    OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
+    OSTCBPrioTbl[prio]      = ptcb;
+
+}
+
+
+#endif                                                     /* OS_MUTEX_EN                              */
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

+ 893 - 0
app/UCOS-II/Source/os_q.c

@@ -0,0 +1,893 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                        MESSAGE QUEUE MANAGEMENT
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_Q.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef  OS_MASTER_FILE
+#include <ucos_ii.h>
+#endif
+
+#if (OS_Q_EN > 0u) && (OS_MAX_QS > 0u)
+/*
+*********************************************************************************************************
+*                                      ACCEPT MESSAGE FROM QUEUE
+*
+* Description: This function checks the queue to see if a message is available.  Unlike OSQPend(),
+*              OSQAccept() does not suspend the calling task if a message is not available.
+*
+* Arguments  : pevent        is a pointer to the event control block
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         The call was successful and your task received a
+*                                                message.
+*                            OS_ERR_EVENT_TYPE   You didn't pass a pointer to a queue
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
+*                            OS_ERR_Q_EMPTY      The queue did not contain any messages
+*
+* Returns    : != (void *)0  is the message in the queue if one is available.  The message is removed
+*                            from the so the next time OSQAccept() is called, the queue will contain
+*                            one less entry.
+*              == (void *)0  if you received a NULL pointer message
+*                            if the queue is empty or,
+*                            if 'pevent' is a NULL pointer or,
+*                            if you passed an invalid event type
+*
+* Note(s)    : As of V2.60, you can now pass NULL pointers through queues.  Because of this, the argument
+*              'perr' has been added to the API to tell you about the outcome of the call.
+*********************************************************************************************************
+*/
+
+#if OS_Q_ACCEPT_EN > 0u
+void  *OSQAccept (OS_EVENT  *pevent,
+                  INT8U     *perr)
+{
+    void      *pmsg;
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                                  */
+        *perr = OS_ERR_PEVENT_NULL;
+        return ((void *)0);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type                          */
+        *perr = OS_ERR_EVENT_TYPE;
+        return ((void *)0);
+    }
+    OS_ENTER_CRITICAL();
+    pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
+    if (pq->OSQEntries > 0u) {                   /* See if any messages in the queue                   */
+        pmsg = *pq->OSQOut++;                    /* Yes, extract oldest message from the queue         */
+        pq->OSQEntries--;                        /* Update the number of entries in the queue          */
+        if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
+            pq->OSQOut = pq->OSQStart;
+        }
+        *perr = OS_ERR_NONE;
+    } else {
+        *perr = OS_ERR_Q_EMPTY;
+        pmsg  = (void *)0;                       /* Queue is empty                                     */
+    }
+    OS_EXIT_CRITICAL();
+    return (pmsg);                               /* Return message received (or NULL)                  */
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        CREATE A MESSAGE QUEUE
+*
+* Description: This function creates a message queue if free event control blocks are available.
+*
+* Arguments  : start         is a pointer to the base address of the message queue storage area.  The
+*                            storage area MUST be declared as an array of pointers to 'void' as follows
+*
+*                            void *MessageStorage[size]
+*
+*              size          is the number of elements in the storage area
+*
+* Returns    : != (OS_EVENT *)0  is a pointer to the event control clock (OS_EVENT) associated with the
+*                                created queue
+*              == (OS_EVENT *)0  if no event control blocks were available or an error was detected
+*********************************************************************************************************
+*/
+
+OS_EVENT  *OSQCreate (void    **start,
+                      INT16U    size)
+{
+    OS_EVENT  *pevent;
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL_IEC61508
+    if (OSSafetyCriticalStartFlag == OS_TRUE) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+    if (OSIntNesting > 0u) {                     /* See if called from ISR ...                         */
+        return ((OS_EVENT *)0);                  /* ... can't CREATE from an ISR                       */
+    }
+    OS_ENTER_CRITICAL();
+    pevent = OSEventFreeList;                    /* Get next free event control block                  */
+    if (OSEventFreeList != (OS_EVENT *)0) {      /* See if pool of free ECB pool was empty             */
+        OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
+    }
+    OS_EXIT_CRITICAL();
+    if (pevent != (OS_EVENT *)0) {               /* See if we have an event control block              */
+        OS_ENTER_CRITICAL();
+        pq = OSQFreeList;                        /* Get a free queue control block                     */
+        if (pq != (OS_Q *)0) {                   /* Were we able to get a queue control block ?        */
+            OSQFreeList            = OSQFreeList->OSQPtr; /* Yes, Adjust free list pointer to next free*/
+            OS_EXIT_CRITICAL();
+            pq->OSQStart           = start;               /*      Initialize the queue                 */
+            pq->OSQEnd             = &start[size];
+            pq->OSQIn              = start;
+            pq->OSQOut             = start;
+            pq->OSQSize            = size;
+            pq->OSQEntries         = 0u;
+            pevent->OSEventType    = OS_EVENT_TYPE_Q;
+            pevent->OSEventCnt     = 0u;
+            pevent->OSEventPtr     = pq;
+#if OS_EVENT_NAME_EN > 0u
+            pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+            OS_EventWaitListInit(pevent);                 /*      Initalize the wait list              */
+        } else {
+            pevent->OSEventPtr = (void *)OSEventFreeList; /* No,  Return event control block on error  */
+            OSEventFreeList    = pevent;
+            OS_EXIT_CRITICAL();
+            pevent = (OS_EVENT *)0;
+        }
+    }
+    return (pevent);
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        DELETE A MESSAGE QUEUE
+*
+* Description: This function deletes a message queue and readies all tasks pending on the queue.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            queue.
+*
+*              opt           determines delete options as follows:
+*                            opt == OS_DEL_NO_PEND   Delete the queue ONLY if no task pending
+*                            opt == OS_DEL_ALWAYS    Deletes the queue even if tasks are waiting.
+*                                                    In this case, all the tasks pending will be readied.
+*
+*              perr          is a pointer to an error code that can contain one of the following values:
+*                            OS_ERR_NONE             The call was successful and the queue was deleted
+*                            OS_ERR_DEL_ISR          If you tried to delete the queue from an ISR
+*                            OS_ERR_INVALID_OPT      An invalid option was specified
+*                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the queue
+*                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a queue
+*                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
+*
+* Returns    : pevent        upon error
+*              (OS_EVENT *)0 if the queue was successfully deleted.
+*
+* Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
+*                 the queue MUST check the return code of OSQPend().
+*              2) OSQAccept() callers will not know that the intended queue has been deleted unless
+*                 they check 'pevent' to see that it's a NULL pointer.
+*              3) This call can potentially disable interrupts for a long time.  The interrupt disable
+*                 time is directly proportional to the number of tasks waiting on the queue.
+*              4) Because ALL tasks pending on the queue will be readied, you MUST be careful in
+*                 applications where the queue is used for mutual exclusion because the resource(s)
+*                 will no longer be guarded by the queue.
+*              5) If the storage for the message queue was allocated dynamically (i.e. using a malloc()
+*                 type call) then your application MUST release the memory storage by call the counterpart
+*                 call of the dynamic allocation scheme used.  If the queue storage was created statically
+*                 then, the storage can be reused.
+*********************************************************************************************************
+*/
+
+#if OS_Q_DEL_EN > 0u
+OS_EVENT  *OSQDel (OS_EVENT  *pevent,
+                   INT8U      opt,
+                   INT8U     *perr)
+{
+    BOOLEAN    tasks_waiting;
+    OS_EVENT  *pevent_return;
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (pevent);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {          /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (pevent);
+    }
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        *perr = OS_ERR_DEL_ISR;                            /* ... can't DELETE from an ISR             */
+        return (pevent);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                        /* See if any tasks waiting on queue        */
+        tasks_waiting = OS_TRUE;                           /* Yes                                      */
+    } else {
+        tasks_waiting = OS_FALSE;                          /* No                                       */
+    }
+    switch (opt) {
+        case OS_DEL_NO_PEND:                               /* Delete queue only if no task waiting     */
+             if (tasks_waiting == OS_FALSE) {
+#if OS_EVENT_NAME_EN > 0u
+                 pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+                 pq                     = (OS_Q *)pevent->OSEventPtr;  /* Return OS_Q to free list     */
+                 pq->OSQPtr             = OSQFreeList;
+                 OSQFreeList            = pq;
+                 pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
+                 pevent->OSEventPtr     = OSEventFreeList; /* Return Event Control Block to free list  */
+                 pevent->OSEventCnt     = 0u;
+                 OSEventFreeList        = pevent;          /* Get next free event control block        */
+                 OS_EXIT_CRITICAL();
+                 *perr                  = OS_ERR_NONE;
+                 pevent_return          = (OS_EVENT *)0;   /* Queue has been deleted                   */
+             } else {
+                 OS_EXIT_CRITICAL();
+                 *perr                  = OS_ERR_TASK_WAITING;
+                 pevent_return          = pevent;
+             }
+             break;
+
+        case OS_DEL_ALWAYS:                                /* Always delete the queue                  */
+             while (pevent->OSEventGrp != 0u) {            /* Ready ALL tasks waiting for queue        */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_OK);
+             }
+#if OS_EVENT_NAME_EN > 0u
+             pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+             pq                     = (OS_Q *)pevent->OSEventPtr;   /* Return OS_Q to free list        */
+             pq->OSQPtr             = OSQFreeList;
+             OSQFreeList            = pq;
+             pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
+             pevent->OSEventPtr     = OSEventFreeList;     /* Return Event Control Block to free list  */
+             pevent->OSEventCnt     = 0u;
+             OSEventFreeList        = pevent;              /* Get next free event control block        */
+             OS_EXIT_CRITICAL();
+             if (tasks_waiting == OS_TRUE) {               /* Reschedule only if task(s) were waiting  */
+                 OS_Sched();                               /* Find highest priority task ready to run  */
+             }
+             *perr                  = OS_ERR_NONE;
+             pevent_return          = (OS_EVENT *)0;       /* Queue has been deleted                   */
+             break;
+
+        default:
+             OS_EXIT_CRITICAL();
+             *perr                  = OS_ERR_INVALID_OPT;
+             pevent_return          = pevent;
+             break;
+    }
+    return (pevent_return);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                             FLUSH QUEUE
+*
+* Description : This function is used to flush the contents of the message queue.
+*
+* Arguments   : none
+*
+* Returns     : OS_ERR_NONE         upon success
+*               OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a queue
+*               OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
+*
+* WARNING     : You should use this function with great care because, when to flush the queue, you LOOSE
+*               the references to what the queue entries are pointing to and thus, you could cause
+*               'memory leaks'.  In other words, the data you are pointing to that's being referenced
+*               by the queue entries should, most likely, need to be de-allocated (i.e. freed).
+*********************************************************************************************************
+*/
+
+#if OS_Q_FLUSH_EN > 0u
+INT8U  OSQFlush (OS_EVENT *pevent)
+{
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+#endif
+    OS_ENTER_CRITICAL();
+    pq             = (OS_Q *)pevent->OSEventPtr;      /* Point to queue storage structure              */
+    pq->OSQIn      = pq->OSQStart;
+    pq->OSQOut     = pq->OSQStart;
+    pq->OSQEntries = 0u;
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                     PEND ON A QUEUE FOR A MESSAGE
+*
+* Description: This function waits for a message to be sent to a queue
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired queue
+*
+*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
+*                            wait for a message to arrive at the queue up to the amount of time
+*                            specified by this argument.  If you specify 0, however, your task will wait
+*                            forever at the specified queue or, until a message arrives.
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         The call was successful and your task received a
+*                                                message.
+*                            OS_ERR_TIMEOUT      A message was not received within the specified 'timeout'.
+*                            OS_ERR_PEND_ABORT   The wait on the queue was aborted.
+*                            OS_ERR_EVENT_TYPE   You didn't pass a pointer to a queue
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
+*                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
+*                                                would lead to a suspension.
+*                            OS_ERR_PEND_LOCKED  If you called this function with the scheduler is locked
+*
+* Returns    : != (void *)0  is a pointer to the message received
+*              == (void *)0  if you received a NULL pointer message or,
+*                            if no message was received or,
+*                            if 'pevent' is a NULL pointer or,
+*                            if you didn't pass a pointer to a queue.
+*
+* Note(s)    : As of V2.60, this function allows you to receive NULL pointer messages.
+*********************************************************************************************************
+*/
+
+void  *OSQPend (OS_EVENT  *pevent,
+                INT32U     timeout,
+                INT8U     *perr)
+{
+    void      *pmsg;
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                                  */
+        *perr = OS_ERR_PEVENT_NULL;
+        return ((void *)0);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type                          */
+        *perr = OS_ERR_EVENT_TYPE;
+        return ((void *)0);
+    }
+    if (OSIntNesting > 0u) {                     /* See if called from ISR ...                         */
+        *perr = OS_ERR_PEND_ISR;                 /* ... can't PEND from an ISR                         */
+        return ((void *)0);
+    }
+    if (OSLockNesting > 0u) {                    /* See if called with scheduler locked ...            */
+        *perr = OS_ERR_PEND_LOCKED;              /* ... can't PEND when locked                         */
+        return ((void *)0);
+    }
+    OS_ENTER_CRITICAL();
+    pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
+    if (pq->OSQEntries > 0u) {                   /* See if any messages in the queue                   */
+        pmsg = *pq->OSQOut++;                    /* Yes, extract oldest message from the queue         */
+        pq->OSQEntries--;                        /* Update the number of entries in the queue          */
+        if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
+            pq->OSQOut = pq->OSQStart;
+        }
+        OS_EXIT_CRITICAL();
+        *perr = OS_ERR_NONE;
+        return (pmsg);                           /* Return message received                            */
+    }
+    OSTCBCur->OSTCBStat     |= OS_STAT_Q;        /* Task will have to pend for a message to be posted  */
+    OSTCBCur->OSTCBStatPend  = OS_STAT_PEND_OK;
+    OSTCBCur->OSTCBDly       = timeout;          /* Load timeout into TCB                              */
+    OS_EventTaskWait(pevent);                    /* Suspend task until event or timeout occurs         */
+    OS_EXIT_CRITICAL();
+    OS_Sched();                                  /* Find next highest priority task ready to run       */
+    OS_ENTER_CRITICAL();
+    switch (OSTCBCur->OSTCBStatPend) {                /* See if we timed-out or aborted                */
+        case OS_STAT_PEND_OK:                         /* Extract message from TCB (Put there by QPost) */
+             pmsg =  OSTCBCur->OSTCBMsg;
+            *perr =  OS_ERR_NONE;
+             break;
+
+        case OS_STAT_PEND_ABORT:
+             pmsg = (void *)0;
+            *perr =  OS_ERR_PEND_ABORT;               /* Indicate that we aborted                      */
+             break;
+
+        case OS_STAT_PEND_TO:
+        default:
+             OS_EventTaskRemove(OSTCBCur, pevent);
+             pmsg = (void *)0;
+            *perr =  OS_ERR_TIMEOUT;                  /* Indicate that we didn't get event within TO   */
+             break;
+    }
+    OSTCBCur->OSTCBStat          =  OS_STAT_RDY;      /* Set   task  status to ready                   */
+    OSTCBCur->OSTCBStatPend      =  OS_STAT_PEND_OK;  /* Clear pend  status                            */
+    OSTCBCur->OSTCBEventPtr      = (OS_EVENT  *)0;    /* Clear event pointers                          */
+#if (OS_EVENT_MULTI_EN > 0u)
+    OSTCBCur->OSTCBEventMultiPtr = (OS_EVENT **)0;
+#endif
+    OSTCBCur->OSTCBMsg           = (void      *)0;    /* Clear  received message                       */
+    OS_EXIT_CRITICAL();
+    return (pmsg);                                    /* Return received message                       */
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                      ABORT WAITING ON A MESSAGE QUEUE
+*
+* Description: This function aborts & readies any tasks currently waiting on a queue.  This function
+*              should be used to fault-abort the wait on the queue, rather than to normally signal
+*              the queue via OSQPost(), OSQPostFront() or OSQPostOpt().
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired queue.
+*
+*              opt           determines the type of ABORT performed:
+*                            OS_PEND_OPT_NONE         ABORT wait for a single task (HPT) waiting on the
+*                                                     queue
+*                            OS_PEND_OPT_BROADCAST    ABORT wait for ALL tasks that are  waiting on the
+*                                                     queue
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         No tasks were     waiting on the queue.
+*                            OS_ERR_PEND_ABORT   At least one task waiting on the queue was readied
+*                                                and informed of the aborted wait; check return value
+*                                                for the number of tasks whose wait on the queue
+*                                                was aborted.
+*                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a queue.
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
+*
+* Returns    : == 0          if no tasks were waiting on the queue, or upon error.
+*              >  0          if one or more tasks waiting on the queue are now readied and informed.
+*********************************************************************************************************
+*/
+
+#if OS_Q_PEND_ABORT_EN > 0u
+INT8U  OSQPendAbort (OS_EVENT  *pevent,
+                     INT8U      opt,
+                     INT8U     *perr)
+{
+    INT8U      nbr_tasks;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (0u);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {          /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (0u);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                        /* See if any task waiting on queue?        */
+        nbr_tasks = 0u;
+        switch (opt) {
+            case OS_PEND_OPT_BROADCAST:                    /* Do we need to abort ALL waiting tasks?   */
+                 while (pevent->OSEventGrp != 0u) {        /* Yes, ready ALL tasks waiting on queue    */
+                     (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_ABORT);
+                     nbr_tasks++;
+                 }
+                 break;
+
+            case OS_PEND_OPT_NONE:
+            default:                                       /* No,  ready HPT       waiting on queue    */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_ABORT);
+                 nbr_tasks++;
+                 break;
+        }
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                        /* Find HPT ready to run                    */
+        *perr = OS_ERR_PEND_ABORT;
+        return (nbr_tasks);
+    }
+    OS_EXIT_CRITICAL();
+    *perr = OS_ERR_NONE;
+    return (0u);                                           /* No tasks waiting on queue                */
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        POST MESSAGE TO A QUEUE
+*
+* Description: This function sends a message to a queue
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired queue
+*
+*              pmsg          is a pointer to the message to send.
+*
+* Returns    : OS_ERR_NONE           The call was successful and the message was sent
+*              OS_ERR_Q_FULL         If the queue cannot accept any more messages because it is full.
+*              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
+*              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
+*
+* Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
+*********************************************************************************************************
+*/
+
+#if OS_Q_POST_EN > 0u
+INT8U  OSQPost (OS_EVENT  *pevent,
+                void      *pmsg)
+{
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                           /* Allocate storage for CPU status register     */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                     /* Validate 'pevent'                            */
+        return (OS_ERR_PEVENT_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {      /* Validate event block type                    */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                    /* See if any task pending on queue             */
+                                                       /* Ready highest priority task waiting on event */
+        (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                    /* Find highest priority task ready to run      */
+        return (OS_ERR_NONE);
+    }
+    pq = (OS_Q *)pevent->OSEventPtr;                   /* Point to queue control block                 */
+    if (pq->OSQEntries >= pq->OSQSize) {               /* Make sure queue is not full                  */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_Q_FULL);
+    }
+    *pq->OSQIn++ = pmsg;                               /* Insert message into queue                    */
+    pq->OSQEntries++;                                  /* Update the nbr of entries in the queue       */
+    if (pq->OSQIn == pq->OSQEnd) {                     /* Wrap IN ptr if we are at end of queue        */
+        pq->OSQIn = pq->OSQStart;
+    }
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                   POST MESSAGE TO THE FRONT OF A QUEUE
+*
+* Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
+*              the front instead of the end of the queue.  Using OSQPostFront() allows you to send
+*              'priority' messages.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired queue
+*
+*              pmsg          is a pointer to the message to send.
+*
+* Returns    : OS_ERR_NONE           The call was successful and the message was sent
+*              OS_ERR_Q_FULL         If the queue cannot accept any more messages because it is full.
+*              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
+*              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
+*
+* Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
+*********************************************************************************************************
+*/
+
+#if OS_Q_POST_FRONT_EN > 0u
+INT8U  OSQPostFront (OS_EVENT  *pevent,
+                     void      *pmsg)
+{
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                   /* See if any task pending on queue              */
+                                                      /* Ready highest priority task waiting on event  */
+        (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                   /* Find highest priority task ready to run       */
+        return (OS_ERR_NONE);
+    }
+    pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
+    if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_Q_FULL);
+    }
+    if (pq->OSQOut == pq->OSQStart) {                 /* Wrap OUT ptr if we are at the 1st queue entry */
+        pq->OSQOut = pq->OSQEnd;
+    }
+    pq->OSQOut--;
+    *pq->OSQOut = pmsg;                               /* Insert message into queue                     */
+    pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        POST MESSAGE TO A QUEUE
+*
+* Description: This function sends a message to a queue.  This call has been added to reduce code size
+*              since it can replace both OSQPost() and OSQPostFront().  Also, this function adds the
+*              capability to broadcast a message to ALL tasks waiting on the message queue.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired queue
+*
+*              pmsg          is a pointer to the message to send.
+*
+*              opt           determines the type of POST performed:
+*                            OS_POST_OPT_NONE         POST to a single waiting task
+*                                                     (Identical to OSQPost())
+*                            OS_POST_OPT_BROADCAST    POST to ALL tasks that are waiting on the queue
+*                            OS_POST_OPT_FRONT        POST as LIFO (Simulates OSQPostFront())
+*                            OS_POST_OPT_NO_SCHED     Indicates that the scheduler will NOT be invoked
+*
+* Returns    : OS_ERR_NONE           The call was successful and the message was sent
+*              OS_ERR_Q_FULL         If the queue cannot accept any more messages because it is full.
+*              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
+*              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
+*
+* Warning    : Interrupts can be disabled for a long time if you do a 'broadcast'.  In fact, the
+*              interrupt disable time is proportional to the number of tasks waiting on the queue.
+*********************************************************************************************************
+*/
+
+#if OS_Q_POST_OPT_EN > 0u
+INT8U  OSQPostOpt (OS_EVENT  *pevent,
+                   void      *pmsg,
+                   INT8U      opt)
+{
+    OS_Q      *pq;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0x00u) {                /* See if any task pending on queue              */
+        if ((opt & OS_POST_OPT_BROADCAST) != 0x00u) { /* Do we need to post msg to ALL waiting tasks ? */
+            while (pevent->OSEventGrp != 0u) {        /* Yes, Post to ALL tasks waiting on queue       */
+                (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
+            }
+        } else {                                      /* No,  Post to HPT waiting on queue             */
+            (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
+        }
+        OS_EXIT_CRITICAL();
+        if ((opt & OS_POST_OPT_NO_SCHED) == 0u) {	  /* See if scheduler needs to be invoked          */
+            OS_Sched();                               /* Find highest priority task ready to run       */
+        }
+        return (OS_ERR_NONE);
+    }
+    pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
+    if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_Q_FULL);
+    }
+    if ((opt & OS_POST_OPT_FRONT) != 0x00u) {         /* Do we post to the FRONT of the queue?         */
+        if (pq->OSQOut == pq->OSQStart) {             /* Yes, Post as LIFO, Wrap OUT pointer if we ... */
+            pq->OSQOut = pq->OSQEnd;                  /*      ... are at the 1st queue entry           */
+        }
+        pq->OSQOut--;
+        *pq->OSQOut = pmsg;                           /*      Insert message into queue                */
+    } else {                                          /* No,  Post as FIFO                             */
+        *pq->OSQIn++ = pmsg;                          /*      Insert message into queue                */
+        if (pq->OSQIn == pq->OSQEnd) {                /*      Wrap IN ptr if we are at end of queue    */
+            pq->OSQIn = pq->OSQStart;
+        }
+    }
+    pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                        QUERY A MESSAGE QUEUE
+*
+* Description: This function obtains information about a message queue.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired queue
+*
+*              p_q_data      is a pointer to a structure that will contain information about the message
+*                            queue.
+*
+* Returns    : OS_ERR_NONE         The call was successful and the message was sent
+*              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non queue.
+*              OS_ERR_PEVENT_NULL  If 'pevent'   is a NULL pointer
+*              OS_ERR_PDATA_NULL   If 'p_q_data' is a NULL pointer
+*********************************************************************************************************
+*/
+
+#if OS_Q_QUERY_EN > 0u
+INT8U  OSQQuery (OS_EVENT  *pevent,
+                 OS_Q_DATA *p_q_data)
+{
+    OS_Q       *pq;
+    INT8U       i;
+    OS_PRIO    *psrc;
+    OS_PRIO    *pdest;
+#if OS_CRITICAL_METHOD == 3u                           /* Allocate storage for CPU status register     */
+    OS_CPU_SR   cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                     /* Validate 'pevent'                            */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (p_q_data == (OS_Q_DATA *)0) {                  /* Validate 'p_q_data'                          */
+        return (OS_ERR_PDATA_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {      /* Validate event block type                    */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    p_q_data->OSEventGrp = pevent->OSEventGrp;         /* Copy message queue wait list                 */
+    psrc                 = &pevent->OSEventTbl[0];
+    pdest                = &p_q_data->OSEventTbl[0];
+    for (i = 0u; i < OS_EVENT_TBL_SIZE; i++) {
+        *pdest++ = *psrc++;
+    }
+    pq = (OS_Q *)pevent->OSEventPtr;
+    if (pq->OSQEntries > 0u) {
+        p_q_data->OSMsg = *pq->OSQOut;                 /* Get next message to return if available      */
+    } else {
+        p_q_data->OSMsg = (void *)0;
+    }
+    p_q_data->OSNMsgs = pq->OSQEntries;
+    p_q_data->OSQSize = pq->OSQSize;
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif                                                 /* OS_Q_QUERY_EN                                */
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                      QUEUE MODULE INITIALIZATION
+*
+* Description : This function is called by uC/OS-II to initialize the message queue module.  Your
+*               application MUST NOT call this function.
+*
+* Arguments   :  none
+*
+* Returns     : none
+*
+* Note(s)    : This function is INTERNAL to uC/OS-II and your application should not call it.
+*********************************************************************************************************
+*/
+
+void  OS_QInit (void)
+{
+#if OS_MAX_QS == 1u
+    OSQFreeList         = &OSQTbl[0];                /* Only ONE queue!                                */
+    OSQFreeList->OSQPtr = (OS_Q *)0;
+#endif
+
+#if OS_MAX_QS >= 2u
+    INT16U   ix;
+    INT16U   ix_next;
+    OS_Q    *pq1;
+    OS_Q    *pq2;
+
+
+
+    OS_MemClr((INT8U *)&OSQTbl[0], sizeof(OSQTbl));  /* Clear the queue table                          */
+    for (ix = 0u; ix < (OS_MAX_QS - 1u); ix++) {     /* Init. list of free QUEUE control blocks        */
+        ix_next = ix + 1u;
+        pq1 = &OSQTbl[ix];
+        pq2 = &OSQTbl[ix_next];
+        pq1->OSQPtr = pq2;
+    }
+    pq1         = &OSQTbl[ix];
+    pq1->OSQPtr = (OS_Q *)0;
+    OSQFreeList = &OSQTbl[0];
+#endif
+}
+#endif                                               /* OS_Q_EN                                        */
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

+ 629 - 0
app/UCOS-II/Source/os_sem.c

@@ -0,0 +1,629 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                          SEMAPHORE MANAGEMENT
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_SEM.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef  OS_MASTER_FILE
+#include <ucos_ii.h>
+#endif
+
+#if OS_SEM_EN > 0u
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                           ACCEPT SEMAPHORE
+*
+* Description: This function checks the semaphore to see if a resource is available or, if an event
+*              occurred.  Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
+*              resource is not available or the event did not occur.
+*
+* Arguments  : pevent     is a pointer to the event control block
+*
+* Returns    : >  0       if the resource is available or the event did not occur the semaphore is
+*                         decremented to obtain the resource.
+*              == 0       if the resource is not available or the event did not occur or,
+*                         if 'pevent' is a NULL pointer or,
+*                         if you didn't pass a pointer to a semaphore
+*********************************************************************************************************
+*/
+
+#if OS_SEM_ACCEPT_EN > 0u
+INT16U  OSSemAccept (OS_EVENT *pevent)
+{
+    INT16U     cnt;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (0u);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
+        return (0u);
+    }
+    OS_ENTER_CRITICAL();
+    cnt = pevent->OSEventCnt;
+    if (cnt > 0u) {                                   /* See if resource is available                  */
+        pevent->OSEventCnt--;                         /* Yes, decrement semaphore and notify caller    */
+    }
+    OS_EXIT_CRITICAL();
+    return (cnt);                                     /* Return semaphore count                        */
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                           CREATE A SEMAPHORE
+*
+* Description: This function creates a semaphore.
+*
+* Arguments  : cnt           is the initial value for the semaphore.  If the value is 0, no resource is
+*                            available (or no event has occurred).  You initialize the semaphore to a
+*                            non-zero value to specify how many resources are available (e.g. if you have
+*                            10 resources, you would initialize the semaphore to 10).
+*
+* Returns    : != (void *)0  is a pointer to the event control block (OS_EVENT) associated with the
+*                            created semaphore
+*              == (void *)0  if no event control blocks were available
+*********************************************************************************************************
+*/
+
+OS_EVENT  *OSSemCreate (INT16U cnt)
+{
+    OS_EVENT  *pevent;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL_IEC61508
+    if (OSSafetyCriticalStartFlag == OS_TRUE) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        return ((OS_EVENT *)0);                            /* ... can't CREATE from an ISR             */
+    }
+    OS_ENTER_CRITICAL();
+    pevent = OSEventFreeList;                              /* Get next free event control block        */
+    if (OSEventFreeList != (OS_EVENT *)0) {                /* See if pool of free ECB pool was empty   */
+        OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
+    }
+    OS_EXIT_CRITICAL();
+    if (pevent != (OS_EVENT *)0) {                         /* Get an event control block               */
+        pevent->OSEventType    = OS_EVENT_TYPE_SEM;
+        pevent->OSEventCnt     = cnt;                      /* Set semaphore value                      */
+        pevent->OSEventPtr     = (void *)0;                /* Unlink from ECB free list                */
+#if OS_EVENT_NAME_EN > 0u
+        pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+        OS_EventWaitListInit(pevent);                      /* Initialize to 'nobody waiting' on sem.   */
+    }
+    return (pevent);
+}
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                         DELETE A SEMAPHORE
+*
+* Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            semaphore.
+*
+*              opt           determines delete options as follows:
+*                            opt == OS_DEL_NO_PEND   Delete semaphore ONLY if no task pending
+*                            opt == OS_DEL_ALWAYS    Deletes the semaphore even if tasks are waiting.
+*                                                    In this case, all the tasks pending will be readied.
+*
+*              perr          is a pointer to an error code that can contain one of the following values:
+*                            OS_ERR_NONE             The call was successful and the semaphore was deleted
+*                            OS_ERR_DEL_ISR          If you attempted to delete the semaphore from an ISR
+*                            OS_ERR_INVALID_OPT      An invalid option was specified
+*                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the semaphore
+*                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a semaphore
+*                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
+*
+* Returns    : pevent        upon error
+*              (OS_EVENT *)0 if the semaphore was successfully deleted.
+*
+* Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
+*                 the semaphore MUST check the return code of OSSemPend().
+*              2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
+*                 they check 'pevent' to see that it's a NULL pointer.
+*              3) This call can potentially disable interrupts for a long time.  The interrupt disable
+*                 time is directly proportional to the number of tasks waiting on the semaphore.
+*              4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
+*                 applications where the semaphore is used for mutual exclusion because the resource(s)
+*                 will no longer be guarded by the semaphore.
+*********************************************************************************************************
+*/
+
+#if OS_SEM_DEL_EN > 0u
+OS_EVENT  *OSSemDel (OS_EVENT  *pevent,
+                     INT8U      opt,
+                     INT8U     *perr)
+{
+    BOOLEAN    tasks_waiting;
+    OS_EVENT  *pevent_return;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (pevent);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (pevent);
+    }
+    if (OSIntNesting > 0u) {                               /* See if called from ISR ...               */
+        *perr = OS_ERR_DEL_ISR;                            /* ... can't DELETE from an ISR             */
+        return (pevent);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                        /* See if any tasks waiting on semaphore    */
+        tasks_waiting = OS_TRUE;                           /* Yes                                      */
+    } else {
+        tasks_waiting = OS_FALSE;                          /* No                                       */
+    }
+    switch (opt) {
+        case OS_DEL_NO_PEND:                               /* Delete semaphore only if no task waiting */
+             if (tasks_waiting == OS_FALSE) {
+#if OS_EVENT_NAME_EN > 0u
+                 pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+                 pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
+                 pevent->OSEventPtr     = OSEventFreeList; /* Return Event Control Block to free list  */
+                 pevent->OSEventCnt     = 0u;
+                 OSEventFreeList        = pevent;          /* Get next free event control block        */
+                 OS_EXIT_CRITICAL();
+                 *perr                  = OS_ERR_NONE;
+                 pevent_return          = (OS_EVENT *)0;   /* Semaphore has been deleted               */
+             } else {
+                 OS_EXIT_CRITICAL();
+                 *perr                  = OS_ERR_TASK_WAITING;
+                 pevent_return          = pevent;
+             }
+             break;
+
+        case OS_DEL_ALWAYS:                                /* Always delete the semaphore              */
+             while (pevent->OSEventGrp != 0u) {            /* Ready ALL tasks waiting for semaphore    */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_OK);
+             }
+#if OS_EVENT_NAME_EN > 0u
+             pevent->OSEventName    = (INT8U *)(void *)"?";
+#endif
+             pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
+             pevent->OSEventPtr     = OSEventFreeList;     /* Return Event Control Block to free list  */
+             pevent->OSEventCnt     = 0u;
+             OSEventFreeList        = pevent;              /* Get next free event control block        */
+             OS_EXIT_CRITICAL();
+             if (tasks_waiting == OS_TRUE) {               /* Reschedule only if task(s) were waiting  */
+                 OS_Sched();                               /* Find highest priority task ready to run  */
+             }
+             *perr                  = OS_ERR_NONE;
+             pevent_return          = (OS_EVENT *)0;       /* Semaphore has been deleted               */
+             break;
+
+        default:
+             OS_EXIT_CRITICAL();
+             *perr                  = OS_ERR_INVALID_OPT;
+             pevent_return          = pevent;
+             break;
+    }
+    return (pevent_return);
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                           PEND ON SEMAPHORE
+*
+* Description: This function waits for a semaphore.
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            semaphore.
+*
+*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
+*                            wait for the resource up to the amount of time specified by this argument.
+*                            If you specify 0, however, your task will wait forever at the specified
+*                            semaphore or, until the resource becomes available (or the event occurs).
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         The call was successful and your task owns the resource
+*                                                or, the event you are waiting for occurred.
+*                            OS_ERR_TIMEOUT      The semaphore was not received within the specified
+*                                                'timeout'.
+*                            OS_ERR_PEND_ABORT   The wait on the semaphore was aborted.
+*                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
+*                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
+*                                                would lead to a suspension.
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
+*                            OS_ERR_PEND_LOCKED  If you called this function when the scheduler is locked
+*
+* Returns    : none
+*********************************************************************************************************
+*/
+/*$PAGE*/
+void  OSSemPend (OS_EVENT  *pevent,
+                 INT32U     timeout,
+                 INT8U     *perr)
+{
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        *perr = OS_ERR_PEVENT_NULL;
+        return;
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
+        *perr = OS_ERR_EVENT_TYPE;
+        return;
+    }
+    if (OSIntNesting > 0u) {                          /* See if called from ISR ...                    */
+        *perr = OS_ERR_PEND_ISR;                      /* ... can't PEND from an ISR                    */
+        return;
+    }
+    if (OSLockNesting > 0u) {                         /* See if called with scheduler locked ...       */
+        *perr = OS_ERR_PEND_LOCKED;                   /* ... can't PEND when locked                    */
+        return;
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventCnt > 0u) {                    /* If sem. is positive, resource available ...   */
+        pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
+        OS_EXIT_CRITICAL();
+        *perr = OS_ERR_NONE;
+        return;
+    }
+                                                      /* Otherwise, must wait until event occurs       */
+    OSTCBCur->OSTCBStat     |= OS_STAT_SEM;           /* Resource not available, pend on semaphore     */
+    OSTCBCur->OSTCBStatPend  = OS_STAT_PEND_OK;
+    OSTCBCur->OSTCBDly       = timeout;               /* Store pend timeout in TCB                     */
+    OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
+    OS_EXIT_CRITICAL();
+    OS_Sched();                                       /* Find next highest priority task ready         */
+    OS_ENTER_CRITICAL();
+    switch (OSTCBCur->OSTCBStatPend) {                /* See if we timed-out or aborted                */
+        case OS_STAT_PEND_OK:
+             *perr = OS_ERR_NONE;
+             break;
+
+        case OS_STAT_PEND_ABORT:
+             *perr = OS_ERR_PEND_ABORT;               /* Indicate that we aborted                      */
+             break;
+
+        case OS_STAT_PEND_TO:
+        default:
+             OS_EventTaskRemove(OSTCBCur, pevent);
+             *perr = OS_ERR_TIMEOUT;                  /* Indicate that we didn't get event within TO   */
+             break;
+    }
+    OSTCBCur->OSTCBStat          =  OS_STAT_RDY;      /* Set   task  status to ready                   */
+    OSTCBCur->OSTCBStatPend      =  OS_STAT_PEND_OK;  /* Clear pend  status                            */
+    OSTCBCur->OSTCBEventPtr      = (OS_EVENT  *)0;    /* Clear event pointers                          */
+#if (OS_EVENT_MULTI_EN > 0u)
+    OSTCBCur->OSTCBEventMultiPtr = (OS_EVENT **)0;
+#endif
+    OS_EXIT_CRITICAL();
+}
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                      ABORT WAITING ON A SEMAPHORE
+*
+* Description: This function aborts & readies any tasks currently waiting on a semaphore.  This function
+*              should be used to fault-abort the wait on the semaphore, rather than to normally signal
+*              the semaphore via OSSemPost().
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            semaphore.
+*
+*              opt           determines the type of ABORT performed:
+*                            OS_PEND_OPT_NONE         ABORT wait for a single task (HPT) waiting on the
+*                                                     semaphore
+*                            OS_PEND_OPT_BROADCAST    ABORT wait for ALL tasks that are  waiting on the
+*                                                     semaphore
+*
+*              perr          is a pointer to where an error message will be deposited.  Possible error
+*                            messages are:
+*
+*                            OS_ERR_NONE         No tasks were     waiting on the semaphore.
+*                            OS_ERR_PEND_ABORT   At least one task waiting on the semaphore was readied
+*                                                and informed of the aborted wait; check return value
+*                                                for the number of tasks whose wait on the semaphore
+*                                                was aborted.
+*                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
+*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
+*
+* Returns    : == 0          if no tasks were waiting on the semaphore, or upon error.
+*              >  0          if one or more tasks waiting on the semaphore are now readied and informed.
+*********************************************************************************************************
+*/
+
+#if OS_SEM_PEND_ABORT_EN > 0u
+INT8U  OSSemPendAbort (OS_EVENT  *pevent,
+                       INT8U      opt,
+                       INT8U     *perr)
+{
+    INT8U      nbr_tasks;
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        *perr = OS_ERR_PEVENT_NULL;
+        return (0u);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
+        *perr = OS_ERR_EVENT_TYPE;
+        return (0u);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                   /* See if any task waiting on semaphore?         */
+        nbr_tasks = 0u;
+        switch (opt) {
+            case OS_PEND_OPT_BROADCAST:               /* Do we need to abort ALL waiting tasks?        */
+                 while (pevent->OSEventGrp != 0u) {   /* Yes, ready ALL tasks waiting on semaphore     */
+                     (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_ABORT);
+                     nbr_tasks++;
+                 }
+                 break;
+
+            case OS_PEND_OPT_NONE:
+            default:                                  /* No,  ready HPT       waiting on semaphore     */
+                 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_ABORT);
+                 nbr_tasks++;
+                 break;
+        }
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                   /* Find HPT ready to run                         */
+        *perr = OS_ERR_PEND_ABORT;
+        return (nbr_tasks);
+    }
+    OS_EXIT_CRITICAL();
+    *perr = OS_ERR_NONE;
+    return (0u);                                      /* No tasks waiting on semaphore                 */
+}
+#endif
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                         POST TO A SEMAPHORE
+*
+* Description: This function signals a semaphore
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            semaphore.
+*
+* Returns    : OS_ERR_NONE         The call was successful and the semaphore was signaled.
+*              OS_ERR_SEM_OVF      If the semaphore count exceeded its limit.  In other words, you have
+*                                  signalled the semaphore more often than you waited on it with either
+*                                  OSSemAccept() or OSSemPend().
+*              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
+*              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
+*********************************************************************************************************
+*/
+
+INT8U  OSSemPost (OS_EVENT *pevent)
+{
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        return (OS_ERR_PEVENT_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    if (pevent->OSEventGrp != 0u) {                   /* See if any task waiting for semaphore         */
+                                                      /* Ready HPT waiting on event                    */
+        (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_OK);
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                   /* Find HPT ready to run                         */
+        return (OS_ERR_NONE);
+    }
+    if (pevent->OSEventCnt < 65535u) {                /* Make sure semaphore will not overflow         */
+        pevent->OSEventCnt++;                         /* Increment semaphore count to register event   */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_NONE);
+    }
+    OS_EXIT_CRITICAL();                               /* Semaphore value has reached its maximum       */
+    return (OS_ERR_SEM_OVF);
+}
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                          QUERY A SEMAPHORE
+*
+* Description: This function obtains information about a semaphore
+*
+* Arguments  : pevent        is a pointer to the event control block associated with the desired
+*                            semaphore
+*
+*              p_sem_data    is a pointer to a structure that will contain information about the
+*                            semaphore.
+*
+* Returns    : OS_ERR_NONE         The call was successful and the message was sent
+*              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non semaphore.
+*              OS_ERR_PEVENT_NULL  If 'pevent'     is a NULL pointer.
+*              OS_ERR_PDATA_NULL   If 'p_sem_data' is a NULL pointer
+*********************************************************************************************************
+*/
+
+#if OS_SEM_QUERY_EN > 0u
+INT8U  OSSemQuery (OS_EVENT     *pevent,
+                   OS_SEM_DATA  *p_sem_data)
+{
+    INT8U       i;
+    OS_PRIO    *psrc;
+    OS_PRIO    *pdest;
+#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
+    OS_CPU_SR   cpu_sr = 0u;
+#endif
+
+
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
+        return (OS_ERR_PEVENT_NULL);
+    }
+    if (p_sem_data == (OS_SEM_DATA *)0) {                  /* Validate 'p_sem_data'                    */
+        return (OS_ERR_PDATA_NULL);
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
+        return (OS_ERR_EVENT_TYPE);
+    }
+    OS_ENTER_CRITICAL();
+    p_sem_data->OSEventGrp = pevent->OSEventGrp;           /* Copy message mailbox wait list           */
+    psrc                   = &pevent->OSEventTbl[0];
+    pdest                  = &p_sem_data->OSEventTbl[0];
+    for (i = 0u; i < OS_EVENT_TBL_SIZE; i++) {
+        *pdest++ = *psrc++;
+    }
+    p_sem_data->OSCnt = pevent->OSEventCnt;                /* Get semaphore count                      */
+    OS_EXIT_CRITICAL();
+    return (OS_ERR_NONE);
+}
+#endif                                                     /* OS_SEM_QUERY_EN                          */
+
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                              SET SEMAPHORE
+*
+* Description: This function sets the semaphore count to the value specified as an argument.  Typically,
+*              this value would be 0.
+*
+*              You would typically use this function when a semaphore is used as a signaling mechanism
+*              and, you want to reset the count value.
+*
+* Arguments  : pevent     is a pointer to the event control block
+*
+*              cnt        is the new value for the semaphore count.  You would pass 0 to reset the
+*                         semaphore count.
+*
+*              perr       is a pointer to an error code returned by the function as follows:
+*
+*                            OS_ERR_NONE          The call was successful and the semaphore value was set.
+*                            OS_ERR_EVENT_TYPE    If you didn't pass a pointer to a semaphore.
+*                            OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer.
+*                            OS_ERR_TASK_WAITING  If tasks are waiting on the semaphore.
+*********************************************************************************************************
+*/
+
+#if OS_SEM_SET_EN > 0u
+void  OSSemSet (OS_EVENT  *pevent,
+                INT16U     cnt,
+                INT8U     *perr)
+{
+#if OS_CRITICAL_METHOD == 3u                          /* Allocate storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+#ifdef OS_SAFETY_CRITICAL
+    if (perr == (INT8U *)0) {
+        OS_SAFETY_CRITICAL_EXCEPTION();
+    }
+#endif
+
+#if OS_ARG_CHK_EN > 0u
+    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
+        *perr = OS_ERR_PEVENT_NULL;
+        return;
+    }
+#endif
+    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
+        *perr = OS_ERR_EVENT_TYPE;
+        return;
+    }
+    OS_ENTER_CRITICAL();
+    *perr = OS_ERR_NONE;
+    if (pevent->OSEventCnt > 0u) {                    /* See if semaphore already has a count          */
+        pevent->OSEventCnt = cnt;                     /* Yes, set it to the new value specified.       */
+    } else {                                          /* No                                            */
+        if (pevent->OSEventGrp == 0u) {               /*      See if task(s) waiting?                  */
+            pevent->OSEventCnt = cnt;                 /*      No, OK to set the value                  */
+        } else {
+            *perr              = OS_ERR_TASK_WAITING;
+        }
+    }
+    OS_EXIT_CRITICAL();
+}
+#endif
+
+#endif                                                /* OS_SEM_EN                                     */
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

Fichier diff supprimé car celui-ci est trop grand
+ 1263 - 0
app/UCOS-II/Source/os_task.c


+ 264 - 0
app/UCOS-II/Source/os_time.c

@@ -0,0 +1,264 @@
+/*
+*********************************************************************************************************
+*                                                uC/OS-II
+*                                          The Real-Time Kernel
+*                                             TIME MANAGEMENT
+*
+*                              (c) Copyright 1992-2009, Micrium, Weston, FL
+*                                           All Rights Reserved
+*
+* File    : OS_TIME.C
+* By      : Jean J. Labrosse
+* Version : V2.91
+*
+* LICENSING TERMS:
+* ---------------
+*   uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
+* If you plan on using  uC/OS-II  in a commercial product you need to contact Micriµm to properly license
+* its use in your product. We provide ALL the source code for your convenience and to help you experience
+* uC/OS-II.   The fact that the  source is provided does  NOT  mean that you can use it without  paying a
+* licensing fee.
+*********************************************************************************************************
+*/
+
+#ifndef  OS_MASTER_FILE
+#include <ucos_ii.h>
+#endif
+
+/*
+*********************************************************************************************************
+*                                       DELAY TASK 'n' TICKS
+*
+* Description: This function is called to delay execution of the currently running task until the
+*              specified number of system ticks expires.  This, of course, directly equates to delaying
+*              the current task for some time to expire.  No delay will result If the specified delay is
+*              0.  If the specified delay is greater than 0 then, a context switch will result.
+*
+* Arguments  : ticks     is the time delay that the task will be suspended in number of clock 'ticks'.
+*                        Note that by specifying 0, the task will not be delayed.
+*
+* Returns    : none
+*********************************************************************************************************
+*/
+
+void  OSTimeDly (INT32U ticks)
+{
+    INT8U      y;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+    if (OSIntNesting > 0u) {                     /* See if trying to call from an ISR                  */
+        return;
+    }
+    if (OSLockNesting > 0u) {                    /* See if called with scheduler locked                */
+        return;
+    }
+    if (ticks > 0u) {                            /* 0 means no delay!                                  */
+        OS_ENTER_CRITICAL();
+        y            =  OSTCBCur->OSTCBY;        /* Delay current task                                 */
+        OSRdyTbl[y] &= (OS_PRIO)~OSTCBCur->OSTCBBitX;
+        if (OSRdyTbl[y] == 0u) {
+            OSRdyGrp &= (OS_PRIO)~OSTCBCur->OSTCBBitY;
+        }
+        OSTCBCur->OSTCBDly = ticks;              /* Load ticks in TCB                                  */
+        OS_EXIT_CRITICAL();
+        OS_Sched();                              /* Find next task to run!                             */
+    }
+}
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                     DELAY TASK FOR SPECIFIED TIME
+*
+* Description: This function is called to delay execution of the currently running task until some time
+*              expires.  This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
+*              MILLISECONDS instead of ticks.
+*
+* Arguments  : hours     specifies the number of hours that the task will be delayed (max. is 255)
+*              minutes   specifies the number of minutes (max. 59)
+*              seconds   specifies the number of seconds (max. 59)
+*              ms        specifies the number of milliseconds (max. 999)
+*
+* Returns    : OS_ERR_NONE
+*              OS_ERR_TIME_INVALID_MINUTES
+*              OS_ERR_TIME_INVALID_SECONDS
+*              OS_ERR_TIME_INVALID_MS
+*              OS_ERR_TIME_ZERO_DLY
+*              OS_ERR_TIME_DLY_ISR
+*
+* Note(s)    : The resolution on the milliseconds depends on the tick rate.  For example, you can't do
+*              a 10 mS delay if the ticker interrupts every 100 mS.  In this case, the delay would be
+*              set to 0.  The actual delay is rounded to the nearest tick.
+*********************************************************************************************************
+*/
+
+#if OS_TIME_DLY_HMSM_EN > 0u
+INT8U  OSTimeDlyHMSM (INT8U   hours,
+                      INT8U   minutes,
+                      INT8U   seconds,
+                      INT16U  ms)
+{
+    INT32U ticks;
+
+
+    if (OSIntNesting > 0u) {                     /* See if trying to call from an ISR                  */
+        return (OS_ERR_TIME_DLY_ISR);
+    }
+    if (OSLockNesting > 0u) {                    /* See if called with scheduler locked                */
+        return (OS_ERR_SCHED_LOCKED);
+    }
+#if OS_ARG_CHK_EN > 0u
+    if (hours == 0u) {
+        if (minutes == 0u) {
+            if (seconds == 0u) {
+                if (ms == 0u) {
+                    return (OS_ERR_TIME_ZERO_DLY);
+                }
+            }
+        }
+    }
+    if (minutes > 59u) {
+        return (OS_ERR_TIME_INVALID_MINUTES);    /* Validate arguments to be within range              */
+    }
+    if (seconds > 59u) {
+        return (OS_ERR_TIME_INVALID_SECONDS);
+    }
+    if (ms > 999u) {
+        return (OS_ERR_TIME_INVALID_MS);
+    }
+#endif
+                                                 /* Compute the total number of clock ticks required.. */
+                                                 /* .. (rounded to the nearest tick)                   */
+    ticks = ((INT32U)hours * 3600uL + (INT32U)minutes * 60uL + (INT32U)seconds) * OS_TICKS_PER_SEC
+          + OS_TICKS_PER_SEC * ((INT32U)ms + 500uL / OS_TICKS_PER_SEC) / 1000uL;
+    OSTimeDly(ticks);
+    return (OS_ERR_NONE);
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                         RESUME A DELAYED TASK
+*
+* Description: This function is used resume a task that has been delayed through a call to either
+*              OSTimeDly() or OSTimeDlyHMSM().  Note that you can call this function to resume a
+*              task that is waiting for an event with timeout.  This would make the task look
+*              like a timeout occurred.
+*
+* Arguments  : prio                      specifies the priority of the task to resume
+*
+* Returns    : OS_ERR_NONE               Task has been resumed
+*              OS_ERR_PRIO_INVALID       if the priority you specify is higher that the maximum allowed
+*                                        (i.e. >= OS_LOWEST_PRIO)
+*              OS_ERR_TIME_NOT_DLY       Task is not waiting for time to expire
+*              OS_ERR_TASK_NOT_EXIST     The desired task has not been created or has been assigned to a Mutex.
+*********************************************************************************************************
+*/
+
+#if OS_TIME_DLY_RESUME_EN > 0u
+INT8U  OSTimeDlyResume (INT8U prio)
+{
+    OS_TCB    *ptcb;
+#if OS_CRITICAL_METHOD == 3u                                   /* Storage for CPU status register      */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+    if (prio >= OS_LOWEST_PRIO) {
+        return (OS_ERR_PRIO_INVALID);
+    }
+    OS_ENTER_CRITICAL();
+    ptcb = OSTCBPrioTbl[prio];                                 /* Make sure that task exist            */
+    if (ptcb == (OS_TCB *)0) {
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_TASK_NOT_EXIST);                        /* The task does not exist              */
+    }
+    if (ptcb == OS_TCB_RESERVED) {
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_TASK_NOT_EXIST);                        /* The task does not exist              */
+    }
+    if (ptcb->OSTCBDly == 0u) {                                /* See if task is delayed               */
+        OS_EXIT_CRITICAL();
+        return (OS_ERR_TIME_NOT_DLY);                          /* Indicate that task was not delayed   */
+    }
+
+    ptcb->OSTCBDly = 0u;                                       /* Clear the time delay                 */
+    if ((ptcb->OSTCBStat & OS_STAT_PEND_ANY) != OS_STAT_RDY) {
+        ptcb->OSTCBStat     &= ~OS_STAT_PEND_ANY;              /* Yes, Clear status flag               */
+        ptcb->OSTCBStatPend  =  OS_STAT_PEND_TO;               /* Indicate PEND timeout                */
+    } else {
+        ptcb->OSTCBStatPend  =  OS_STAT_PEND_OK;
+    }
+    if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) {  /* Is task suspended?                   */
+        OSRdyGrp               |= ptcb->OSTCBBitY;             /* No,  Make ready                      */
+        OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
+        OS_EXIT_CRITICAL();
+        OS_Sched();                                            /* See if this is new highest priority  */
+    } else {
+        OS_EXIT_CRITICAL();                                    /* Task may be suspended                */
+    }
+    return (OS_ERR_NONE);
+}
+#endif
+/*$PAGE*/
+/*
+*********************************************************************************************************
+*                                         GET CURRENT SYSTEM TIME
+*
+* Description: This function is used by your application to obtain the current value of the 32-bit
+*              counter which keeps track of the number of clock ticks.
+*
+* Arguments  : none
+*
+* Returns    : The current value of OSTime
+*********************************************************************************************************
+*/
+
+#if OS_TIME_GET_SET_EN > 0u
+INT32U  OSTimeGet (void)
+{
+    INT32U     ticks;
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+    OS_ENTER_CRITICAL();
+    ticks = OSTime;
+    OS_EXIT_CRITICAL();
+    return (ticks);
+}
+#endif
+
+/*
+*********************************************************************************************************
+*                                            SET SYSTEM CLOCK
+*
+* Description: This function sets the 32-bit counter which keeps track of the number of clock ticks.
+*
+* Arguments  : ticks      specifies the new value that OSTime needs to take.
+*
+* Returns    : none
+*********************************************************************************************************
+*/
+
+#if OS_TIME_GET_SET_EN > 0u
+void  OSTimeSet (INT32U ticks)
+{
+#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
+    OS_CPU_SR  cpu_sr = 0u;
+#endif
+
+
+
+    OS_ENTER_CRITICAL();
+    OSTime = ticks;
+    OS_EXIT_CRITICAL();
+}
+#endif
+	 	   	  		 			 	    		   		 		 	 	 			 	    		   	 			 	  	 		 				 		  			 		 					 	  	  		      		  	   		      		  	 		 	      		   		 		  	 		 	      		  		  		  

Fichier diff supprimé car celui-ci est trop grand
+ 1073 - 0
app/UCOS-II/Source/os_tmr.c


+ 0 - 0
app/UCOS-II/Source/ucos_ii.c


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff