示例#1
0
        public IEnumerable <CyAPICustomizer> CustomizeAPIs(ICyDWComponentAPIArgs_v1 args)
        {
            List <CyAPICustomizer>      customizers    = new List <CyAPICustomizer>(args.Apis);
            Dictionary <string, string> paramDict      = new Dictionary <string, string>();
            IList <CyPropertyBundle>    listBundleIFC1 = args.GetPropertyBundlesFor(BUNDLE_ID_IFC1);
            IList <string> instNames = args.GetInstNamesFor("LIN");

            string isMultiInstance = "0";

            if (customizers.Count > 0)
            {
                paramDict = customizers[0].MacroDictionary;
            }

            Debug.Assert(listBundleIFC1.Count == 1, "Should have been caught by ICyDWComponent_v1.GetDRCs");

            // determine the second LIN instance name
            string secondInstName = "NOT_DEFINED";

            if (instNames.Count == 2)
            {
                isMultiInstance = "1";
                for (int i = 0; i < instNames.Count; i++)
                {
                    if (instNames[i] != listBundleIFC1[0].InstName)
                    {
                        secondInstName = instNames[i];
                    }
                }
            }

            // read input string
            string strH = listBundleIFC1[0].GetProperty <string>(BDNAME_H_FILE);
            string strC = listBundleIFC1[0].GetProperty <string>(BDNAME_C_FILE);

            // replace replacement string on the name of second instance
            if (strH.Contains(SECOND_INST_NAME))
            {
                strH = strH.Replace(SECOND_INST_NAME, secondInstName);
            }
            if (strC.Contains(SECOND_INST_NAME))
            {
                strC = strC.Replace(SECOND_INST_NAME, secondInstName);
            }

            paramDict.Add(IS_MULTI_INSTANCE, isMultiInstance);
            paramDict.Add(INSTANCE_1_NAME, listBundleIFC1[0].InstName);
            paramDict.Add(INSTANCE_2_NAME, secondInstName);

            // write in API output string
            paramDict.Add(BDNAME_H_FILE, strH);
            paramDict.Add(BDNAME_C_FILE, strC);

            for (int i = 0; i < customizers.Count; i++)
            {
                customizers[i].MacroDictionary = paramDict;
                yield return(customizers[i]);
            }
        }
示例#2
0
        public IEnumerable <CyAPICustomizer> CustomizeAPIs(ICyDWComponentAPIArgs_v1 args)
        {
            List <CyAPICustomizer>      customizers = new List <CyAPICustomizer>(args.Apis);
            Dictionary <string, string> paramDict   = new Dictionary <string, string>();

            if (customizers.Count > 0)
            {
                paramDict = customizers[0].MacroDictionary;
            }

            for (int i = 0; i < customizers.Count; i++)
            {
                customizers[i].MacroDictionary = paramDict;
                yield return(customizers[i]);
            }
        }
示例#3
0
        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);
        }