Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Dependents: denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more
Deprecated
This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.
Diff: rtx/TARGET_CORTEX_M/rt_MemBox.c
- Revision:
- 112:53ace74b190c
- Parent:
- 49:77c8e4604045
diff -r 162b12aea5f2 -r 53ace74b190c rtx/TARGET_CORTEX_M/rt_MemBox.c
--- a/rtx/TARGET_CORTEX_M/rt_MemBox.c Tue May 03 00:15:52 2016 +0100
+++ b/rtx/TARGET_CORTEX_M/rt_MemBox.c Thu May 05 20:45:13 2016 +0100
@@ -1,12 +1,12 @@
/*----------------------------------------------------------------------------
- * RL-ARM - RTX
+ * CMSIS-RTOS - RTX
*----------------------------------------------------------------------------
* Name: RT_MEMBOX.C
* Purpose: Interface functions for fixed memory block management system
- * Rev.: V4.60
+ * Rev.: V4.79
*----------------------------------------------------------------------------
*
- * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
+ * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -33,7 +33,7 @@
*---------------------------------------------------------------------------*/
#include "rt_TypeDef.h"
-#include "RTX_Conf.h"
+#include "RTX_Config.h"
#include "rt_System.h"
#include "rt_MemBox.h"
#include "rt_HAL_CM.h"
@@ -45,7 +45,7 @@
/*--------------------------- _init_box -------------------------------------*/
-int _init_box (void *box_mem, U32 box_size, U32 blk_size) {
+U32 _init_box (void *box_mem, U32 box_size, U32 blk_size) {
/* Initialize memory block system, returns 0 if OK, 1 if fails. */
void *end;
void *blk;
@@ -54,20 +54,20 @@
/* Create memory structure. */
if (blk_size & BOX_ALIGN_8) {
- /* Memory blocks 8-byte aligned. */
- blk_size = ((blk_size & ~BOX_ALIGN_8) + 7) & ~7;
- sizeof_bm = (sizeof (struct OS_BM) + 7) & ~7;
+ /* Memory blocks 8-byte aligned. */
+ blk_size = ((blk_size & ~BOX_ALIGN_8) + 7U) & ~(U32)7U;
+ sizeof_bm = (sizeof (struct OS_BM) + 7U) & ~(U32)7U;
}
else {
/* Memory blocks 4-byte aligned. */
- blk_size = (blk_size + 3) & ~3;
+ blk_size = (blk_size + 3U) & ~(U32)3U;
sizeof_bm = sizeof (struct OS_BM);
}
- if (blk_size == 0) {
- return (1);
+ if (blk_size == 0U) {
+ return (1U);
}
if ((blk_size + sizeof_bm) > box_size) {
- return (1);
+ return (1U);
}
/* Create a Memory structure. */
blk = ((U8 *) box_mem) + sizeof_bm;
@@ -80,13 +80,13 @@
end = ((U8 *) end) - blk_size;
while (1) {
next = ((U8 *) blk) + blk_size;
- if (next > end) break;
+ if (next > end) { break; }
*((void **)blk) = next;
blk = next;
}
/* end marker */
- *((void **)blk) = 0;
- return (0);
+ *((void **)blk) = 0U;
+ return (0U);
}
/*--------------------------- rt_alloc_box ----------------------------------*/
@@ -95,17 +95,17 @@
/* Allocate a memory block and return start address. */
void **free;
#ifndef __USE_EXCLUSIVE_ACCESS
- int irq_dis;
+ U32 irq_mask;
- irq_dis = __disable_irq ();
+ irq_mask = (U32)__disable_irq ();
free = ((P_BM) box_mem)->free;
if (free) {
((P_BM) box_mem)->free = *free;
}
- if (!irq_dis) __enable_irq ();
+ if (irq_mask == 0U) { __enable_irq (); }
#else
do {
- if ((free = (void **)__ldrex(&((P_BM) box_mem)->free)) == 0) {
+ if ((free = (void **)__ldrex(&((P_BM) box_mem)->free)) == 0U) {
__clrex();
break;
}
@@ -126,8 +126,8 @@
free = _alloc_box (box_mem);
if (free) {
p = free;
- for (i = ((P_BM) box_mem)->blk_size; i; i -= 4) {
- *p = 0;
+ for (i = ((P_BM) box_mem)->blk_size; i; i -= 4U) {
+ *p = 0U;
p++;
}
}
@@ -137,30 +137,32 @@
/*--------------------------- rt_free_box -----------------------------------*/
-int rt_free_box (void *box_mem, void *box) {
+U32 rt_free_box (void *box_mem, void *box) {
/* Free a memory block, returns 0 if OK, 1 if box does not belong to box_mem */
#ifndef __USE_EXCLUSIVE_ACCESS
- int irq_dis;
+ U32 irq_mask;
#endif
- if (box < box_mem || box >= ((P_BM) box_mem)->end) {
- return (1);
+ if ((box < box_mem) || (box >= ((P_BM) box_mem)->end)) {
+ return (1U);
}
#ifndef __USE_EXCLUSIVE_ACCESS
- irq_dis = __disable_irq ();
+ irq_mask = (U32)__disable_irq ();
*((void **)box) = ((P_BM) box_mem)->free;
((P_BM) box_mem)->free = box;
- if (!irq_dis) __enable_irq ();
+ if (irq_mask == 0U) { __enable_irq (); }
#else
do {
- *((void **)box) = (void *)__ldrex(&((P_BM) box_mem)->free);
+ do {
+ *((void **)box) = ((P_BM) box_mem)->free;
+ __DMB();
+ } while (*(void**)box != (void *)__ldrex(&((P_BM) box_mem)->free));
} while (__strex ((U32)box, &((P_BM) box_mem)->free));
#endif
- return (0);
+ return (0U);
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
-
mbed official




