void initBufferPool(void) { char * tmpPtr; uint16_t i; #ifndef UCOS_SKIP_FILL_BUFFERS uint16_t j; #endif SYSIO_USING_MONITOR; SYSIO_ENTER_MONITOR; #if UCOS_NUM_SMALL_XBUFFERS != 0 smallxBufferPoolStart = nextFreeSmallxBuffer = &smallxBufferPool[0]; smallxBufferPoolEnd = &smallxBufferPool[UCOS_NUM_SMALL_XBUFFERS]; for (i=0;i<UCOS_NUM_SMALL_XBUFFERS;i++) { smallxBufferPool[i].next = &smallxBufferPool[i+1]; tmpPtr = &smallxBufferPool[i].buffer[0]; #ifndef UCOS_SKIP_FILL_BUFFERS for (j=0;j<sizeof(smallxBufferPool[0].buffer);j++) { tmpPtr[j] = (uint8_t)0x88; } #endif } smallxBufferPool[UCOS_NUM_SMALL_XBUFFERS-1].next = NULL; #endif #if UCOS_NUM_LARGE_XBUFFERS != 0 largexBufferPoolStart = nextFreeLargexBuffer = &largexBufferPool[0]; largexBufferPoolEnd = &largexBufferPool[UCOS_NUM_LARGE_XBUFFERS]; for (i=0;i<UCOS_NUM_LARGE_XBUFFERS;i++) { largexBufferPool[i].next = &largexBufferPool[i+1]; tmpPtr = &largexBufferPool[i].buffer[0]; #ifndef UCOS_SKIP_FILL_BUFFERS for (j=0;j<sizeof(largexBufferPool[0].buffer);j++) { tmpPtr[j] = (uint8_t)0x99; } #endif } largexBufferPool[UCOS_NUM_LARGE_XBUFFERS-1].next = NULL; #endif #ifndef SMALL_UCOS HEAP_init(); #endif SYSIO_EXIT_MONITOR; } /* End UCOS_initBufferPool */
void HEAP_test() { HEAP heap; HEntry entry,*pentry; int *tmp,i; VISITCTX sorted_ctx; VASSERT( !HEAP_init( &heap, 10, sizeof(HEntry), HEntry_compare) ); tmp = shuffle(TEST_SIZE); #ifdef SHOW_RESULTS printheap(&heap); #endif for(i=0;i<TEST_SIZE;i++) { entry.Key = tmp[i]; sprintf(entry.Name,"N:%03d",tmp[i]); HEAP_push( &heap, (unsigned char *) &entry, sizeof(entry) ); #ifdef SHOW_RESULTS printheap(&heap); #endif VASSERT( HEAP_check(&heap) ); } free(tmp); #ifdef SHOW_RESULTS printf("pop!\n"); #endif VASSERT( HEAP_check(&heap) ); VASSERT( HEAP_size(&heap) == TEST_SIZE ); i = -1; while( (pentry = (HEntry *) HEAP_top( &heap )) != 0 ) { #ifdef SHOW_RESULTS printheap(&heap); printf("->%d\n",pentry->Key); #endif VASSERT(pentry->Key > i); sprintf(entry.Name,"N:%03d",pentry->Key); VASSERT( pentry->Key >= i); VASSERT( strcmp(pentry->Name,entry.Name) == 0); i = pentry->Key; HEAP_pop( &heap); } VASSERT(HEAP_check(&heap)); sorted_ctx.entry = 0; HEAP_foreach_sorted( &heap, heap_visitor_check_sorted, &sorted_ctx); HEAP_free(&heap); }