/***************************************************************************** * * * Application Control Interface Example for Phyton ChipProgUSB Programmer * * * * Description: Example of operation in gang mode. Waits until all devices * * are in sockets, then executes auto programming on all sockets. * * * * Code to modify: See main() function at the end of this file. Change * * the path to the programmer executable file and device type. * * * * (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(UINT site_num); UINT Attach(const char * exe, const char * command_line, BOOL debug); UINT SetDevice(const char * manufacturer, const char * device_name); 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; case ACI_ERR_INVALID_SITE: msg = "ACI_ERR_INVALID_SITE: Invalid site number (gang mode)"; break; case ACI_ERR_GANG_MODE: msg = "ACI_ERR_GANG_MODE: Gang mode function was called in the single-programmer mode or vice versa"; 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*/ UINT Attach(const char * exe, const char * command_line, BOOL debug) { // Returns number of sockets (sites) or 0 on error 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? params.NumSites : 0; } /*+ 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; } /*+ WaitDevice ° 13.07.09 13:11:24*/ UINT WaitDevice(UINT site_number) { UINT r; printf("Waiting until a new device is in socket %u. Please insert a device...\n", site_number); Status.SiteNumber = site_number; 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) }; UINT r, i, num_sites; // Launch the programmer executable in gang mode printf("Launching programmer...\n"); num_sites = Attach("C:\\Program Files\\ChipProgUSB\\4_93_00\\UPrognt2.exe", "/gang", FALSE); if (num_sites == 0) return -1; printf("Connected, number of sites = %u\n", num_sites); // Select device to operate on if (!SetDevice("SST", "SST89E52RD2")) return -1; // Load file to buffer if (!LoadHexFile("C:\\Program\\test.hex", 0, 0)) 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 all devices are in sockets for (i = 0; i < num_sites; i++) if (WaitDevice(i) != ACI_ERR_SUCCESS) return -1; printf("All %u devices are in sockets\n", num_sites); // Start programming for all sites for (i = 0; i < num_sites; i++) { ACI_GangStart_Params start_params; start_params.Size = sizeof(start_params); start_params.SiteNumber = i; start_params.BufferNumber = 0; start_params.Silent = FALSE; r = ACI_GangStart(&start_params); PrintError(r); } printf("Programming started\n"); // Wait until programming is complete for (i = 0; i < num_sites; i++) { Status.SiteNumber = i; r = ACI_GetStatus(&Status); PrintError(r); if (r != ACI_ERR_SUCCESS) break; if (Status.Executing) i--; } printf("Programming complete\n"); return 0; }