/// <summary> /// Renames a file: Cm0Start.c -> Cm0plusStart.c /// </summary> private CyAPICustomizer RenameCm0plusApi(CyAPICustomizer api) { string[] filesToRename = { STARTUP_CM0, STARTUP_CM0_GCC, STARTUP_CM0_IAR, STARTUP_CM0_RVDS }; for (int i = 0; i < filesToRename.Length; i++) { string fileName = filesToRename[i]; if (fileName == api.OutputName || InsertNumberIntoFilename(fileName, 1) == api.OutputName || InsertNumberIntoFilename(fileName, 2) == api.OutputName) { string newName = api.OutputName.Replace("m0", "m0plus"); api.OutputName = newName; } } return(api); }
public IEnumerable <CyAPICustomizer> CustomizeAPIs( ICyInstQuery_v1 query, ICyTerminalQuery_v1 termQuery, IEnumerable <CyAPICustomizer> apis) { List <CyAPICustomizer> customizers = new List <CyAPICustomizer>(apis); Dictionary <string, string> paramDict = new Dictionary <string, string>(); string instanceName = ""; // Get the parameters from the characterLCD.c file customizer for (int i = 0; i < customizers.Count; i++) { CyAPICustomizer api = customizers[i]; // Get dict from main file. if (api.OriginalName.EndsWith(LCD_CFILE_NAME)) { paramDict = api.MacroDictionary; paramDict.TryGetValue(INSTANCE_NAME_PARAM, out instanceName); } else if (api.OriginalName.EndsWith(CUST_CHARS_CFILE_NAME)) { m_custChar_CFile = api; } else if (api.OriginalName.EndsWith(BARGRAPH_CFILE_NAME)) { m_barGraph_CFile = api; } } // Determine Custom Character Set string value; paramDict.TryGetValue(CUSTOM_CHARACTER_SET_PARAM, out value); m_customCharacterSet = (CyCustomCharacterSetTypes)(int.Parse(value)); // Determine existence of ASCII Routines paramDict.TryGetValue(CONVERSION_ROUTINE_PARAM, out value); m_conversionRoutines = (value == "1"); #region New Code Substitution Values const string CUSTOM_CHAR_DEFINES_MACRO = "CustomCharDefines_API_GEN"; const string CONVERSION_ROUTINE_MACRO = "ConversionRoutines_DEF"; string customCharDeleted = "0"; string customCharDefined = ((byte)m_customCharacterSet).ToString(); #region Literal String Code for Conversion Routines string conversionRoutineDeleted = "0"; string conversionRoutineDefined = "1"; #endregion #endregion // If a character set is selected, build c file with data in it. switch (m_customCharacterSet) { case CyCustomCharacterSetTypes.USERDEFINED: ConvertCharacters(LoadUserDefinedCharacters(paramDict), paramDict); paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDefined); customizers.Remove(m_barGraph_CFile); break; case CyCustomCharacterSetTypes.VERTICAL: GenerateVerticalBargraph(paramDict); paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDefined); customizers.Remove(m_custChar_CFile); break; case CyCustomCharacterSetTypes.HORIZONTAL: GenerateHorizontalBargraph(paramDict); paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDefined); customizers.Remove(m_custChar_CFile); break; default: paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDeleted); customizers.Remove(m_barGraph_CFile); customizers.Remove(m_custChar_CFile); break; } // If conversion routines are selected, import them if (m_conversionRoutines) { paramDict.Add(CONVERSION_ROUTINE_MACRO, conversionRoutineDefined); } else { paramDict.Add(CONVERSION_ROUTINE_MACRO, conversionRoutineDeleted); } // Replace macro dictionaries with paramDict for (int i = 0; i < customizers.Count; i++) { CyAPICustomizer api = customizers[i]; api.MacroDictionary = paramDict; } return(customizers); }
public IEnumerable<CyAPICustomizer> CustomizeAPIs( ICyInstQuery_v1 query, ICyTerminalQuery_v1 termQuery, IEnumerable<CyAPICustomizer> apis) { List<CyAPICustomizer> customizers = new List<CyAPICustomizer>(apis); Dictionary<string, string> paramDict = new Dictionary<string, string>(); string instanceName = ""; // Get the parameters from the characterLCD.c file customizer for (int i = 0; i < customizers.Count; i++) { CyAPICustomizer api = customizers[i]; // Get dict from main file. if (api.OriginalName.EndsWith(LCD_CFILE_NAME)) { paramDict = api.MacroDictionary; paramDict.TryGetValue(INSTANCE_NAME_PARAM, out instanceName); } else if (api.OriginalName.EndsWith(CUST_CHARS_CFILE_NAME)) { m_custChar_CFile = api; } else if (api.OriginalName.EndsWith(BARGRAPH_CFILE_NAME)) { m_barGraph_CFile = api; } } // Determine Custom Character Set string value; paramDict.TryGetValue(CUSTOM_CHARACTER_SET_PARAM, out value); m_customCharacterSet = (CyCustomCharacterSetTypes)(int.Parse(value)); // Determine existence of ASCII Routines paramDict.TryGetValue(CONVERSION_ROUTINE_PARAM, out value); m_conversionRoutines = (value == "1"); #region New Code Substitution Values const string CUSTOM_CHAR_DEFINES_MACRO = "CustomCharDefines_API_GEN"; const string CONVERSION_ROUTINE_MACRO = "ConversionRoutines_DEF"; string customCharDeleted = "0"; string customCharDefined = ((byte)m_customCharacterSet).ToString(); #region Literal String Code for Conversion Routines string conversionRoutineDeleted = "0"; string conversionRoutineDefined = "1"; #endregion #endregion // If a character set is selected, build c file with data in it. switch (m_customCharacterSet) { case CyCustomCharacterSetTypes.USERDEFINED: ConvertCharacters(LoadUserDefinedCharacters(paramDict), paramDict); paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDefined); customizers.Remove(m_barGraph_CFile); break; case CyCustomCharacterSetTypes.VERTICAL: GenerateVerticalBargraph(paramDict); paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDefined); customizers.Remove(m_custChar_CFile); break; case CyCustomCharacterSetTypes.HORIZONTAL: GenerateHorizontalBargraph(paramDict); paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDefined); customizers.Remove(m_custChar_CFile); break; default: paramDict.Add(CUSTOM_CHAR_DEFINES_MACRO, customCharDeleted); customizers.Remove(m_barGraph_CFile); customizers.Remove(m_custChar_CFile); break; } // If conversion routines are selected, import them if (m_conversionRoutines) { paramDict.Add(CONVERSION_ROUTINE_MACRO, conversionRoutineDefined); } else { paramDict.Add(CONVERSION_ROUTINE_MACRO, conversionRoutineDeleted); } // Replace macro dictionaries with paramDict for (int i = 0; i < customizers.Count; i++) { CyAPICustomizer api = customizers[i]; api.MacroDictionary = paramDict; } return customizers; }
public IEnumerable <CyAPICustomizer> CustomizeAPIs(ICyDWComponentAPIArgs_v1 args) { List <CyAPICustomizer> inputCustomizers = new List <CyAPICustomizer>(args.Apis); List <CyAPICustomizer> outputCustomizers = new List <CyAPICustomizer>(); // Get a parameter dictionary. Any one will do because they all come identical // (Yes I am assuming there will be at least one) Dictionary <string, string> paramDict = inputCustomizers[0].MacroDictionary; bool enableCmsis = "0" != (args.ApiFitterQueryV2.GetFitterAPIEntry(USE_BUNDLED_CMSIS) ?? "1").TrimEnd('u'); bool isCm0plus = IsCm0plus(args.DeviceQueryV1); uint appCount; // Application images count uint firstAvailableMetaRow; // First available meta row string projType; // Project type bool isExportingCode, isImportingCode; // If any component is sharing the code // Temporary variables that are used to extract values from paramDict string appCountStr, firstAvailableMetaRowStr, isImportingCodeStr, isExportingCodeStr; paramDict.TryGetValue(PROJ_TYPE, out projType); paramDict.TryGetValue(PROJ_APP_COUNT, out appCountStr); paramDict.TryGetValue(FIRST_AVAILABLE_META_ROW, out firstAvailableMetaRowStr); paramDict.TryGetValue(IS_IMPORTING_CODE, out isImportingCodeStr); paramDict.TryGetValue(IS_EXPORTING_CODE, out isExportingCodeStr); uint.TryParse(appCountStr, out appCount); uint.TryParse(firstAvailableMetaRowStr, out firstAvailableMetaRow); isImportingCode = isImportingCodeStr == "1"; isExportingCode = isExportingCodeStr == "1"; // Now copy the customizers to the output list following the simple rules // If it is not a special file, copy it. Otherwise the rules are based on PROJ_TYPE foreach (CyAPICustomizer api in inputCustomizers) { switch (api.OutputName) { case CMSIS_CORE_FUNC_HFILE: case CMSIS_CORE_INSTR_HFILE: case CMSIS_CORE_CM0_HFILE: case CMSIS_CORE_CM3_CFILE: case CMSIS_CORE_CM3_HFILE: case CMSIS_CORE_CM0PLUS_HFILE: case CMSIS_ARMCC: case CMSIS_GCC: case CMSIS_COMPILER: if (enableCmsis) { api.ExcludeFromProjectHeader = true; outputCustomizers.Add(api); } break; case CMSIS_PSOC4_HFILE: case CMSIS_PSOC5_HFILE: case CMSIS_CORE_CM0PLUS_PSOC4_HFILE: if (enableCmsis) { outputCustomizers.Add(api); } break; case STARTUP_8051_KEIL: case STARTUP_CM0_GCC: case STARTUP_CM0_RVDS: case STARTUP_CM0_IAR: case STARTUP_CM3_GCC: case STARTUP_CM3_RVDS: case STARTUP_CM3_IAR: if ((projType == PROJ_TYPE_LOADABLE || projType == PROJ_TYPE_LOADABLEANDBOOTLOADER) && appCount > 1) { CyAPICustomizer newApi; for (uint i = 1; i <= appCount; i++) { string newName = Path.GetFileNameWithoutExtension(api.OutputName); newName += "_" + i; newName += Path.GetExtension(api.OutputName); string newContent = api.OriginalContent; string appImageDefine = string.Format("APP_IMAGE_{0}_START", i); newContent = newContent.Replace("PROJ_FIRST_FLS_BYTE", appImageDefine); newContent = newContent.Replace("`$CYAPPL_NUM`", i.ToString()); newContent = newContent.Replace("`$CYAPPL_MAX`", appCount.ToString()); string gccChecksumExcludeSectionBtldblParamValue = (i == 1) ? GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_APP_1_OF_2 : GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_APP_2_OF_2; newContent = newContent.Replace(string.Format("`${0}`", GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_PARAM), gccChecksumExcludeSectionBtldblParamValue); newApi = new CyAPICustomizer( api.OriginalName, newName, newContent, api.MacroDictionary, api.BuildType); outputCustomizers.Add(newApi); } } else { string newContent = api.OriginalContent; newContent = newContent.Replace("`$CYAPPL_NUM`", "1"); newContent = newContent.Replace("`$CYAPPL_MAX`", "1"); api.OutputContent = newContent; outputCustomizers.Add(api); } break; default: outputCustomizers.Add(api); break; } } // Add the code here if any of the parameters need to be modified by the customizer // Make the changes to paramDict. The completion code updates all of the customizer // to dictionaries with paramDict // Rename API if isCm0plus if (isCm0plus) { for (int i = 0; i < outputCustomizers.Count; i++) { RenameCm0plusApi(outputCustomizers[i]); } } // Remove CM0/CM0plus files depending on the device for (int i = 0; i < outputCustomizers.Count; i++) { if (isCm0plus && (outputCustomizers[i].OutputName == CMSIS_CORE_CM0_HFILE || outputCustomizers[i].OutputName == CMSIS_PSOC4_HFILE)) { outputCustomizers.RemoveAt(i--); } else if (isCm0plus == false && (outputCustomizers[i].OutputName == CMSIS_CORE_CM0PLUS_HFILE || outputCustomizers[i].OutputName == CMSIS_CORE_CM0PLUS_PSOC4_HFILE)) { outputCustomizers.RemoveAt(i--); } } // Add define if the project is in the OTA structure bool isOtaStack = (appCount <= 1) && (projType == PROJ_TYPE_LOADABLEANDBOOTLOADER) && isExportingCode; bool isOtaApp = (appCount <= 1) && (projType == PROJ_TYPE_LOADABLE) && (firstAvailableMetaRow == 2) && isImportingCode; paramDict.Add(OTA_PROJ_FLAG, isOtaApp ? "1" : "0"); // Add GCC checksum exclude section parameters switch (projType) { case PROJ_TYPE_LOADABLE: case PROJ_TYPE_LOADABLEANDBOOTLOADER: if (isOtaStack) { paramDict.Add(GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_PARAM, GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_APP_EXPORT); } else if (isOtaApp) { paramDict.Add(GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_PARAM, GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_APP_IMPORT); } else { // The dual-application bootloadables are handled above paramDict.Add(GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_PARAM, GCC_CHECKSUM_EXCLUDE_SECTION_BTLDBL_APP_1_OF_1); } break; default: paramDict.Add(GCC_CHECKSUM_EXCLUDE_SECTION_PARAM, ".cy_checksum_exclude : { KEEP(*(.cy_checksum_exclude)) } >rom"); break; } //Save result foreach (CyAPICustomizer api in outputCustomizers) { api.MacroDictionary = paramDict; } return(outputCustomizers); }