kb_machblue_core_memory.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:4k
源码类别:

DVD

开发平台:

C/C++

  1. //*****************************************************************************
  2. //File Name: kb_machblue_core_memory.c
  3. //
  4. //Description: memory function
  5. //
  6. // used by Machblue to access the platform's memory utility
  7. // used by Machblue to allocate memory from the platform
  8. // used by Machblue to allocate moveable memory blocks from
  9. //
  10. //Author: steven
  11. //
  12. //Date:  2006.12.29
  13. //
  14. //Version:  v1.0
  15. //*****************************************************************************
  16. #include "string.h"
  17. #include "section.h"
  18. #include "osp.h"
  19. #include "machblue_defines.h"
  20. #include "machblue_customer.h"
  21. #include "machblue_porting_core.h"
  22. /**
  23.  * Sets a memory block to a given pattern.
  24.  * ptr  < pointer to memory block to set >
  25.  * pattern < pattern to set > 
  26.  * n  < number of bytes to set >
  27.  
  28.  * @return none.
  29.  */
  30. void mb_memset(void *ptr,int pattern,mb_size_t n)
  31. {
  32. memset(ptr, pattern,n);
  33. }
  34. /**
  35.  * Moves n bytes from src to dest.
  36.  * dest  < destination to move bytes to >
  37.  * src  < source to move bytes from >
  38.  * n  < numbers of bytes to move >
  39.  
  40.  * @return none.
  41.  */
  42. void mb_memmove(void *dest,const void *src,mb_size_t n)
  43. {
  44.   memmove(dest,src,n);
  45. }
  46. /**
  47.  * Copies n bytes from src to dest.
  48.  * dest  < destination to copy bytes to >
  49.  * src  < source to copy bytes from >
  50.  * n   < numbers of bytes to copy >
  51.  
  52.  * @return none.
  53.  */
  54. void mb_memcpy(void *dest,const void *src,mb_size_t n)
  55. {
  56. memcpy(dest, src,n);
  57. }
  58. /**
  59.  * Compares n bytes from ptr1 against ptr2.
  60.  * ptr1  < pointer to first memory block to compare >
  61.  * ptr2  < pointer to second memory block to compare >
  62.  * n     < number of bytes to compare >
  63.  
  64.  * @return none.
  65.  */
  66. int mb_memcmp(const void *ptr1,const void *ptr2,mb_size_t n)
  67. {
  68. return memcmp(ptr1, ptr2,n);
  69. }
  70. /**
  71.  * Allocates a memory chunk from the system heap. This function will only be called
  72.  * if Machblue's heap is initialized as growable. 
  73.  * size  < size to allocate in bytes >
  74.  
  75.  * @return an aligned pointer to the allocated memory chunk on success or NULL on failure.
  76.  */
  77. void *mb_malloc(mb_size_t size)
  78. {
  79. void *p;
  80. if(size<=0)
  81. return NULL;
  82. p=KB_OSPMalloc(size);
  83. if(p==NULL)
  84. mb_printf("n[Machblue]:Memory malloc error[%ld].",size);
  85. else
  86. mb_memset(p,0xFF,size);
  87. return p;
  88. }
  89. /**
  90.  * Deletes a previously allocated memory chunk.
  91.  * ptr  < previously allocated memory chunk to free >
  92.  
  93.  * @return none.
  94.  */
  95. void mb_free(void *ptr)
  96. {
  97. KB_OSPFree(ptr);
  98. }
  99. /**
  100.  * Allocates a movable memory block from the system heap.
  101.  * On systems that do not support movable memory blocks, MB_FAILURE
  102.  * should be returned. This function  will only be called if Machblue's heap 
  103.  * is initialized as growable. 
  104.  * size  < size to allocate in bytes >
  105.  * mem_block   < pointer to mem block to allocate >
  106.  
  107.  * @return MB_SUCCESS and updates "mem_block" on success or MB_FAILURE on failure.
  108.  */
  109. mb_error_t mb_mem_block_alloc(mb_size_t size,mb_mem_block_t *mem_block)
  110. {
  111.     if(mem_block == NULL)
  112.     {
  113.        return MB_FAILURE ;
  114.     }
  115. *mem_block = (mb_mem_block_t)mb_malloc(size);
  116.     if(*mem_block == 0)
  117.     {
  118.        return MB_FAILURE ;
  119.     }
  120.     return MB_SUCCESS ;
  121. }
  122. /**
  123.  * Deletes a previously allocated memory block.
  124.  * mem_block   < previously allocated memory block handle to free >
  125.  
  126.  * @return none.
  127.  */
  128. void mb_mem_block_free(mb_mem_block_t mem_block)
  129. {
  130. mb_free((void *)mem_block);
  131. }
  132. /**
  133.  * Locks (pins) a memory block in memory. 
  134.  * mem_block  < memory block handle to lock >
  135.  * locked_ptr   < pointer to location to store pointer to locked memory block >
  136.  
  137.  * @return MB_SUCCESS and sets locked_prt to an aligned pointer to the 
  138.  * allocated memory block on success, MB_FAILURE on failure.
  139.  */
  140. mb_error_t mb_mem_block_lock(mb_mem_block_t mem_block,void **locked_ptr)
  141. {
  142.     *locked_ptr=(void *)mem_block;
  143.     return MB_SUCCESS ;
  144. }
  145. /**
  146.  * Unlocks (unpins) a memory block
  147.  * mem_block  < memory block handle to unlock >
  148.  
  149.  * @return none.
  150.  */
  151. void mb_mem_block_unlock(mb_mem_block_t mem_block)
  152. {
  153. }