/***************************************************************************** * * * Application Control Interface Example for Phyton ChipProgUSB Programmer * * * * Description: Waits until a device is in socket, reads device memory and * * saves it into a binary file. * * * * Code to modify: See main() function at the end of this file. Change * * the path to the programmer executable file, device type and path to * * the binary file. * * * * (C) Phyton * * * ******************************************************************************/ #define _CRT_SECURE_NO_WARNINGS #define WIN32_LEAN_AND_MEAN #include #include #include #include #include "..\aciprog.h" void PrintError(UINT error_code); UINT WaitDevice(void); BOOL Attach(const char * exe, const char * command_line, BOOL debug); UINT SetDevice(const char * manufacturer, const char * device_name); BOOL ExecFunction(const char * function_name, UINT buffer_num, BOOL silent); ACI_PStatus_Params Status = { sizeof(ACI_PStatus_Params) }; /*+ PrintError ° 01.07.09 15:07:30*/ void PrintError(UINT error_code) { const char * msg; char text[48]; switch (error_code) { case ACI_ERR_SUCCESS: return; case ACI_ERR_INVALID_PARAMS_SIZE: msg = "ACI_ERR_INVALID_PARAMS_SIZE: Invalid structure size in ACI function"; break; case ACI_ERR_INVALID_EXE: msg = "ACI_ERR_INVALID_EXE: Invalid executable in ACI_Launch()"; break; case ACI_ERR_EXE_FAILED: msg = "ACI_ERR_EXE_FAILED: Programmer executable failed to launch"; break; case ACI_ERR_FILE_ERROR: msg = "ACI_ERR_FILE_ERROR: File error"; break; case ACI_ERR_ATTACH_FAILED: msg = "ACI_ERR_ATTACH_FAILED: ACI_Launch() failed"; break; case ACI_ERR_INVALID_PARAMETER: msg = "ACI_ERR_INVALID_PARAMETER: Invalid parameter in function structure"; break; case ACI_ERR_FUNCTION_FAILED: msg = "ACI_ERR_FUNCTION_FAILED: Function execution failed in ACI_ExecFunction()"; break; case ACI_ERR_NOT_CONNECTED: msg = "ACI_ERR_NOT_CONNECTED: No connection to the target hardware"; break; case ACI_ERR_NOT_AVAILABLE_NOW: msg = "ACI_ERR_NOT_AVAILABLE_NOW: Requested operation is not available at the moment"; break; case ACI_ERR_INVALID_LAYER: msg = "ACI_ERR_INVALID_LAYER: Invalid buffer or layer number"; break; case ACI_ERR_INVALID_ADDR: msg = "ACI_ERR_INVALID_ADDR: Invalid address"; break; case ACI_ERR_OUT_OF_RANGE: msg = "ACI_ERR_OUT_OF_RANGE: Value is out of range"; break; default: sprintf(text, "%u: Unknown error code", error_code); msg = text; break; } printf("Error: %s\n", msg); } /*+ Attach ° 01.07.09 15:04:27*/ BOOL Attach(const char * exe, const char * command_line, BOOL debug) { UINT r; static ACI_Launch_Params params; params.Size = sizeof(ACI_Launch_Params); // UINT Size; // (in) Size of structure, in bytes params.ProgrammerExe = exe; // LPCSTR ProgrammerExe; // (in) Programmer executable file name params.CommandLine = command_line; // LPCSTR CommandLine; // (in) Optional programmer command-line parameters params.DebugMode = debug; // BOOL DebugMode; // (in) Debug mode. Programmer window is not hidden r = ACI_Launch(¶ms); PrintError(r); return r == ACI_ERR_SUCCESS;} /*+ SetDevice ° 01.07.09 15:15:01*/ UINT SetDevice(const char * manufacturer, const char * device_name) { UINT r; ACI_Device_Params params = { sizeof(ACI_Device_Params) }; strcpy(params.Manufacturer, manufacturer); strcpy(params.Name, device_name); r = ACI_SetDevice(¶ms); PrintError(r); return r == ACI_ERR_SUCCESS; } /*+ ExecFunction ° 01.07.09 18:40:21*/ BOOL ExecFunction(const char * function_name, UINT buffer_num, BOOL silent) { UINT r; ACI_Function_Params params = { sizeof(ACI_Function_Params) }; params.FunctionName = function_name; params.BufferNumber = buffer_num; params.Silent = silent; printf("Executing %s...\n", function_name); r = ACI_ExecFunction(¶ms); PrintError(r); if (r == ACI_ERR_SUCCESS) printf("%s complete.\n", function_name); else printf("%s error: %s.\n", function_name, params.ErrorMessage); return r == ACI_ERR_SUCCESS; } /*+ WaitDevice ° 13.07.09 13:11:24*/ UINT WaitDevice(void) { UINT r; printf("Waiting until a new device is in socket. Please insert a device...\n"); do { r = ACI_GetStatus(&Status); PrintError(r); if (r != ACI_ERR_SUCCESS) return r; Sleep(0); } while (!Status.NewDevice || Status.DeviceStatus != ACI_DS_OK); return ACI_ERR_SUCCESS; } /*+ main ° 01.07.09 17:37:24*/ int main(void /*int argc, char ** argv*/) { ACI_Layer_Params layer_params = { sizeof(ACI_Layer_Params) }; ACI_Memory_Params memory_params = { sizeof(ACI_Memory_Params) }; ACI_Programming_Params prog_params = { sizeof(ACI_Programming_Params) }; ACI_File_Params file_params; UINT r; // Launch the programmer executable if (!Attach("C:\\Program Files\\ChipProgUSB\\4_72_00\\UPrognt2.exe", "", FALSE)) return -1; // Select device to operate on if (!SetDevice("SST", "SST89V564RD")) return -1; // Set programming options ACI_GetProgrammingParams(&prog_params); // first get options to keep option values that we do not modify prog_params.InsertTest = TRUE; prog_params.CheckDeviceId = TRUE; prog_params.AutoDetectAction = ACI_AD_DO_NOTHING; // do nothing when device is inserted because we handle the process prog_params.DeviceAutoDetect = TRUE; // turn device autodetect on ACI_SetProgrammingParams(&prog_params); // Wait until device is in socket if (WaitDevice() != ACI_ERR_SUCCESS) return -1; // Read device memory into the buffer if (!ExecFunction("Read", 0, TRUE)) return -1; // Save binary file memset(&file_params, 0, sizeof(file_params)); file_params.Size = sizeof(ACI_File_Params); file_params.FileName = "C:\\Program\\test.bin"; file_params.Format = ACI_PLF_BINARY; file_params.BufferNumber = 0; file_params.LayerNumber = 0; file_params.StartAddressLow = 0; file_params.EndAddressLow = 0xFFFF; r = ACI_FileSave(&file_params); PrintError(r); return 0; }