'''
-config_doc = '''\
-/**
- * Modules include RPP configuration options
- */
-'''
-
files = OrderedDict([
('din' , 'Digital Input RPP API {type_name} file.'),
('dout' , 'Digital Output RPP API {type_name} file.'),
mneu=mne.upper()
if ext == '.h':
- f.write('#ifndef __RPP_{mneu}_H\n'.format(**locals()))
- f.write('#define __RPP_{mneu}_H\n\n\n'.format(**locals()))
- f.write('void rpp_{mne}_init();\n\n'.format(**locals()))
- f.write('#endif /* __RPP_{mneu}_H */\n\n'.format(**locals()))
+ f.write(('#ifndef __RPP_{mneu}_H\n'
+ '#define __RPP_{mneu}_H\n\n'
+ '/**\n'
+ ' * {mneu} module initialization.\n'
+ ' * Call this method before using this module.\n'
+ ' */\n'
+ 'void rpp_{mne}_init();\n\n\n'
+ '#endif /* __RPP_{mneu}_H */\n\n').format(**locals()))
else:
- f.write('/**\n')
- f.write(' * {mneu} module initialization.\n'.format(**locals()))
- f.write(' * Call this method before using this module./\n')
- f.write(' */\n')
- f.write('void rpp_{mne}_init() {\n'.format(**locals()))
- f.write(' // FIXME: Implement.\n')
- f.write('}\n')
+ f.write(('void rpp_{mne}_init() {{\n'
+ ' // FIXME: Implement.\n'
+ '}}\n\n\n').format(**locals()))
def generate_files():
if not os.path.exists('src'):
os.makedirs('src')
-
- # Generate files
+
+ # Generate modules sources and header files
for where, ext, type_name in [['include/', '.h', 'header' ],
- ['', '.c', 'implementation']]:
+ ['src/', '.c', 'implementation']]:
for mne in files:
abstract = files[mne].format(**locals())
generate_file(where, 'rpp_', mne, ext, abstract, type_name)
- # Generate config file
+ # Generate library config file
with open('include/RppConfig.h', 'w') as f:
# Write header
abstract='RPP API configuration file.'))
# Write include configuration options
- f.write(config_doc)
+ f.write(('/**\n'
+ '* Modules include RPP configuration options\n'
+ '*/\n'))
+
for mne in files:
line = '#define rppCONFIG_INCLUDE_{mne}{{space}}1\n'.format(mne=mne.upper())
f.write(line.format(space=((50-len(line)) * ' ')))
f.write('\n\n')
- # Generate API header file
+ # Generate main library header file
with open('include/rpp.h', 'w') as f:
# Write header
abstract='RPP API library header file.'))
# Include configuration file
- f.write('#include "RppConfig.h"\n\n')
+ f.write('/* Include configuration and modules */\n'
+ '#include "RppConfig.h"\n\n')
# Write includes
for mne in files:
- f.write('#if rppCONFIG_INCLUDE_{mne} == 1\n'.format(mne=mne.upper()))
- f.write('#include "rpp_{mne}.h"\n'.format(mne=mne))
- f.write('#endif\n\n')
+ mneu = mne.upper()
+ f.write(('#if rppCONFIG_INCLUDE_{mneu} == 1\n'
+ '#include "rpp_{mne}.h"\n'
+ '#endif\n\n').format(**locals()))
+
+ # Declare initialization function
+ f.write('\n/* Library main functions */\n'
+ '\n'
+ '/**\n'
+ ' * Library initialization function.\n'
+ ' * Call this method before using this library.\n'
+ ' */\n'
+ 'void rpp_init();\n\n')
+
+ # Generate library main file
+ with open('src/rpp.c', 'w') as f:
+
+ # Write header
+ f.write(header.format(prefix='',
+ mne='rpp',
+ ext='.c',
+ abstract='RPP API library implementation file.'))
+
+ # Include library file
+ f.write('#include "rpp.h"\n\n')
+
+ # Declare initialization function
+ f.write('void rpp_init() {\n\n')
+ for mne in files:
+ mneu = mne.upper()
+ f.write(('#if rppCONFIG_INCLUDE_{mneu} == 1\n'
+ ' rpp_{mne}_init();\n'
+ '#endif\n\n').format(**locals()))
+ f.write('}\n\n')
if __name__ == '__main__':
--- /dev/null
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ * - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : rpp.c
+ * Abstract:
+ * RPP API library implementation file.
+ *
+ * References:
+ * RPP API documentation.
+ */
+
+
+#include "rpp.h"
+
+void rpp_init() {
+
+#if rppCONFIG_INCLUDE_DIN == 1
+ rpp_din_init();
+#endif
+
+#if rppCONFIG_INCLUDE_DOUT == 1
+ rpp_dout_init();
+#endif
+
+#if rppCONFIG_INCLUDE_AIN == 1
+ rpp_ain_init();
+#endif
+
+#if rppCONFIG_INCLUDE_AOUT == 1
+ rpp_aout_init();
+#endif
+
+#if rppCONFIG_INCLUDE_HOUT == 1
+ rpp_hout_init();
+#endif
+
+#if rppCONFIG_INCLUDE_POUT == 1
+ rpp_pout_init();
+#endif
+
+#if rppCONFIG_INCLUDE_MOUT == 1
+ rpp_mout_init();
+#endif
+
+#if rppCONFIG_INCLUDE_CAN == 1
+ rpp_can_init();
+#endif
+
+#if rppCONFIG_INCLUDE_LIN == 1
+ rpp_lin_init();
+#endif
+
+#if rppCONFIG_INCLUDE_FR == 1
+ rpp_fr_init();
+#endif
+
+#if rppCONFIG_INCLUDE_SCI == 1
+ rpp_sci_init();
+#endif
+
+#if rppCONFIG_INCLUDE_ETH == 1
+ rpp_eth_init();
+#endif
+
+#if rppCONFIG_INCLUDE_SDC == 1
+ rpp_sdc_init();
+#endif
+
+#if rppCONFIG_INCLUDE_SDR == 1
+ rpp_sdr_init();
+#endif
+
+}
+