/*---------------------------------------------------------------------------* Project: Utilities for sample programs of NAND library File: util.c Programmer: HIRATSU Daisuke Copyright (C) 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: util.c,v $ Revision 1.8 07/27/2006 05:55:57 hiratsu Removed outdated error code: NAND_RESULT_INIT_FAILED. Revision 1.7 07/26/2006 08:39:24 hiratsu Renamed error code. Revision 1.6 07/24/2006 07:22:21 hiratsu Added new error code. Revision 1.5 05/09/2006 09:09:14 hiratsu Modified error code handling. Revision 1.4 03/17/2006 02:39:36 hiratsu Implemented MEM library wrapper in order to allocate buffer from MEM2 with 32byte alignment. Revision 1.3 03/16/2006 11:52:30 hiratsu New error code is arrived. Fixed. Revision 1.2 01/30/2006 10:33:15 hiratsu Now this file includes "nand.h", not "nandEmu.h". Revision 1.1 01/24/2006 12:35:17 hiratsu Utility functions for NAND library demo program. *---------------------------------------------------------------------------*/ #include "util.h" #include #include #include static MEMAllocator s_mem2Allocator; static MEMHeapHandle s_handle; void initializeHeap(void) { void *lo = OSGetMEM2ArenaLo(); void *hi = OSGetMEM2ArenaHi(); s_handle = MEMCreateFrmHeap(lo, (u32)hi - (u32)lo); if ( s_handle == MEM_HEAP_INVALID_HANDLE ) { OSHalt("MEM2 heap allocation error.\n"); } else { OSSetMEM2ArenaLo(hi); MEMInitAllocatorForFrmHeap(&s_mem2Allocator, s_handle, 32); // buffer requires 32byte alignment. } } void finalizeHeap(void) { MEMDestroyFrmHeap(s_handle); } void* alloc32(u32 size) { return MEMAllocFromAllocator(&s_mem2Allocator, size); } void free32(void *addr) { MEMFreeToAllocator(&s_mem2Allocator, addr); } void printErrMsg(s32 err) { switch(err) { case NAND_RESULT_ACCESS: OSReport("NAND_RESULT_ACCESS\n"); break; case NAND_RESULT_ALLOC_FAILED: OSReport("NAND_RESULT_ALLOC_FAILED\n"); break; case NAND_RESULT_BUSY: OSReport("NAND_RESULT_BUSY\n"); break; case NAND_RESULT_CORRUPT: OSReport("NAND_RESULT_CORRUPT\n"); break; case NAND_RESULT_ECC_CRIT: OSReport("NAND_RESULT_ECC_CRIT\n"); break; case NAND_RESULT_EXISTS: OSReport("NAND_RESULT_EXISTS\n"); break; case NAND_RESULT_INVALID: OSReport("NAND_RESULT_INVALID\n"); break; case NAND_RESULT_MAXBLOCKS: OSReport("NAND_RESULT_MAXBLOCKS\n"); break; case NAND_RESULT_MAXFD: OSReport("NAND_RESULT_MAXFD\n"); break; case NAND_RESULT_MAXFILES: OSReport("NAND_RESULT_MAXFILES\n"); break; case NAND_RESULT_NOEXISTS: OSReport("NAND_RESULT_NOEXISTS\n"); break; case NAND_RESULT_NOTEMPTY: OSReport("NAND_RESULT_NOTEMPTY\n"); break; case NAND_RESULT_OPENFD: OSReport("NAND_RESULT_OPENFD\n"); break; case NAND_RESULT_AUTHENTICATION: OSReport("NAND_RESULT_AUTHENTICATION\n"); break; case NAND_RESULT_UNKNOWN: OSReport("NAND_RESULT_UNKNOWN\n"); break; case NAND_RESULT_FATAL_ERROR: OSReport("NAND_RESULT_FATAL_ERROR\n"); break; default: OSReport("Result: %d\n", err); break; } }