Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cEthernetMM.c
00001 #include "NyLPC_cEthernetMM.h" 00002 00003 /** 00004 * メモリブロックの配置 00005 */ 00006 static struct NyLPC_TcEthernetMM_TxMemoryBlock* _mem_addr; 00007 00008 00009 00010 /** 00011 * デバック用。使用中のTxブロックの数を返す。 00012 */ 00013 int NyLPC_cEthernetMM_dbg_getNumofUsedTx(void) 00014 { 00015 int x; 00016 NyLPC_TUInt8 r1,r2,r3,r4,r5; 00017 r1=r2=r3=r4=r5=0; 00018 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_MAX_BUF;x++){ 00019 if(_mem_addr->buf_max[x].h.is_lock || _mem_addr->buf_max[x].h.ref>0){ 00020 r1++; 00021 continue; 00022 } 00023 } 00024 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_512_BUF;x++){ 00025 if(_mem_addr->buf_512[x].h.is_lock || _mem_addr->buf_512[x].h.ref>0){ 00026 r2++; 00027 continue; 00028 } 00029 } 00030 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_256_BUF;x++){ 00031 if(_mem_addr->buf_256[x].h.is_lock || _mem_addr->buf_256[x].h.ref>0){ 00032 r3++; 00033 continue; 00034 } 00035 } 00036 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_128_BUF;x++){ 00037 if(_mem_addr->buf_128[x].h.is_lock || _mem_addr->buf_128[x].h.ref>0){ 00038 r4++; 00039 continue; 00040 } 00041 } 00042 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_64_BUF;x++){ 00043 if(_mem_addr->buf_64[x].h.is_lock || _mem_addr->buf_64[x].h.ref>0){ 00044 r5++; 00045 continue; 00046 } 00047 } 00048 return r1+r2+r3+r4+r5; 00049 } 00050 00051 00052 void NyLPC_cEthernetMM_initialize(void* i_memblock_addr) 00053 { 00054 int x; 00055 _mem_addr=i_memblock_addr; 00056 //TXバッファを初期化 00057 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_MAX_BUF;x++){ 00058 _mem_addr->buf_max[x].h.is_lock=NyLPC_TUInt8_FALSE; 00059 _mem_addr->buf_max[x].h.ref=0; 00060 } 00061 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_512_BUF;x++){ 00062 _mem_addr->buf_512[x].h.is_lock=NyLPC_TUInt8_FALSE; 00063 _mem_addr->buf_512[x].h.ref=0; 00064 } 00065 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_256_BUF;x++){ 00066 _mem_addr->buf_256[x].h.is_lock=NyLPC_TUInt8_FALSE; 00067 _mem_addr->buf_256[x].h.ref=0; 00068 } 00069 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_128_BUF;x++){ 00070 _mem_addr->buf_128[x].h.is_lock=NyLPC_TUInt8_FALSE; 00071 _mem_addr->buf_128[x].h.ref=0; 00072 } 00073 for(x=0;x<NyLPC_TcEthernetMM_NUM_OF_64_BUF;x++){ 00074 _mem_addr->buf_64[x].h.is_lock=NyLPC_TUInt8_FALSE; 00075 _mem_addr->buf_64[x].h.ref=0; 00076 } 00077 } 00078 00079 /** 00080 * 空のTxバッファのポインタを返します。 00081 */ 00082 void* NyLPC_cEthernetMM_alloc(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size) 00083 { 00084 int i; 00085 //ヒントから、割り当てるメモリブロックを決定 00086 00087 //特殊ブロック 00088 if(i_hint==NyLPC_TcEthernetMM_HINT_CTRL_PACKET){ 00089 for(i=0;i<NyLPC_TcEthernetMM_NUM_OF_64_BUF;i++){ 00090 //未参照かつ送信中でないもの。 00091 if(_mem_addr->buf_64[i].h.ref>0 || _mem_addr->buf_64[i].h.is_lock){ 00092 continue; 00093 } 00094 _mem_addr->buf_64[i].h.ref++; 00095 *o_size=64; 00096 return _mem_addr->buf_64[i].b; 00097 } 00098 return NULL; 00099 } 00100 00101 //汎用ブロック 00102 if(i_hint<=128){ 00103 goto ALLOC_128; 00104 }else if(i_hint<=256){ 00105 goto ALLOC_256; 00106 }else if(i_hint<=512){ 00107 goto ALLOC_512; 00108 }else{ 00109 goto ALLOC_MAX; 00110 } 00111 00112 ALLOC_MAX: 00113 for(i=0;i<NyLPC_TcEthernetMM_NUM_OF_MAX_BUF;i++){ 00114 //未参照かつ送信中でないもの。 00115 if(_mem_addr->buf_max[i].h.ref>0 || _mem_addr->buf_max[i].h.is_lock){ 00116 continue; 00117 } 00118 _mem_addr->buf_max[i].h.ref++; 00119 *o_size=NyLPC_TcEthernetMM_MAX_TX_ETHERNET_FRAME_SIZE; 00120 return _mem_addr->buf_max[i].b; 00121 } 00122 ALLOC_512: 00123 for(i=0;i<NyLPC_TcEthernetMM_NUM_OF_512_BUF;i++){ 00124 //未参照かつ送信中でないもの。 00125 if(_mem_addr->buf_512[i].h.ref>0 || _mem_addr->buf_512[i].h.is_lock){ 00126 continue; 00127 } 00128 *o_size=512; 00129 _mem_addr->buf_512[i].h.ref++; 00130 return _mem_addr->buf_512[i].b; 00131 } 00132 ALLOC_256: 00133 for(i=0;i<NyLPC_TcEthernetMM_NUM_OF_256_BUF;i++){ 00134 //未参照かつ送信中でないもの。 00135 if(_mem_addr->buf_256[i].h.ref>0 || (_mem_addr->buf_256[i].h.is_lock)){ 00136 continue; 00137 } 00138 *o_size=256; 00139 _mem_addr->buf_256[i].h.ref++; 00140 return _mem_addr->buf_256[i].b; 00141 } 00142 ALLOC_128: 00143 for(i=0;i<NyLPC_TcEthernetMM_NUM_OF_128_BUF;i++){ 00144 //未参照かつ送信中でないもの。 00145 if(_mem_addr->buf_128[i].h.ref>0 || (_mem_addr->buf_128[i].h.is_lock)){ 00146 continue; 00147 } 00148 *o_size=128; 00149 _mem_addr->buf_128[i].h.ref++; 00150 return _mem_addr->buf_128[i].b; 00151 } 00152 return NULL; 00153 } 00154 00155 00156 void NyLPC_cEthernetMM_release(void* i_buf) 00157 { 00158 struct NyLPC_TTxBufferHeader* h=NyLPC_TTxBufferHeader_getBufferHeaderAddr(i_buf); 00159 //参照カウンタを1減算 00160 NyLPC_Assert(h->ref>0); 00161 h->ref--; 00162 return; 00163 } 00164
Generated on Tue Jul 12 2022 16:22:57 by
1.7.2
