1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
Static void showmeminfo (void) { OS _mem_data mem_data; Osmemquery (pmem, & mem_data );
Printf ("begining address of memory: \ t % x \ r \ n", (INT) (mem_data.osaddr )); Printf ("block size in the memory area: \ t % d \ r \ n", (INT) (mem_data.osblksize )); Printf ("Free blocks in the memory area: \ t % d \ r \ n", (INT) (mem_data.osnfree )); Printf ("used blocks in the memory area: \ t % d \ r \ n", (INT) mem_data.osnused ); Printf ("\ r \ n "); Ostimedlyhmsm (0, 0, 2, 0 ); } Static void getmem (int8u I) { Int8u err;
// Apply for memory space
Pmemmsg [I] = osmemget (pmem, & ERR ); If (pmemmsg [I]! = (Void *) null & err = OS _no_err) { Printf ("got memory _ % d. \ r \ n", I); // The memory block has been allocated Showmeminfo (); } Else Printf ("not got memory _ % d. \ r \ n", I );} Static void putmem (void * pmemmsg, int8u I) { Int8u err; // Release memory space Err = osmemput (pmem, pmemmsg ); If (ERR = OS _no_err) { Printf ("released memory _ % d. \ r \ n", I);/* release the memory block */ Showmeminfo (); } Else Printf ("not exist memory _ % d. \ r \ n", I ); } Void taskmem1 (void * pdata) { Int8u I; I = 0;
While (1) { Getmem (I ++ % msgsize ); Ostimedlyhmsm (0, 0, 2, 0 ); } } Void taskmem2 (void * pdata) { Int8u I; I = 0;
While (1) { Putmem (pmemmsg [I ++ % msgsize], I ++ % msgsize ); Ostimedlyhmsm (0, 0, 2, 0 ); } } |