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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mqx/util_lib/.project b/mqx/util_lib/.project
index 4e538b6e1..5f5f5ffaa 100644
--- a/mqx/util_lib/.project
+++ b/mqx/util_lib/.project
@@ -7,52 +7,7 @@
org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
- ?name?
-
-
-
- org.eclipse.cdt.make.core.append_environment
- true
-
-
- org.eclipse.cdt.make.core.buildArguments
- -j6
-
-
- org.eclipse.cdt.make.core.buildCommand
- ${system:ECLIPSE_HOME}/../gnu/bin/mingw32-make
-
-
- org.eclipse.cdt.make.core.buildLocation
- ${ProjDirPath}/twrk70f120m_Int_Flash_SramData_Debug
-
-
- org.eclipse.cdt.make.core.contents
- org.eclipse.cdt.make.core.activeConfigSettings
-
-
- org.eclipse.cdt.make.core.enableAutoBuild
- false
-
-
- org.eclipse.cdt.make.core.enableCleanBuild
- true
-
-
- org.eclipse.cdt.make.core.enableFullBuild
- true
-
-
- org.eclipse.cdt.make.core.stopOnError
- true
-
-
- org.eclipse.cdt.make.core.useDefaultBuildCmd
- true
-
@@ -70,7 +25,7 @@
MQX_ROOT_DIR
- file:/C:/Freescale/Freescale%20MQX%203.8
+ file:/C:/Freescale/Freescale_MQX_4_1
diff --git a/mqx/util_lib/Sources/util.c b/mqx/util_lib/Sources/util.c
index 0a3f396b5..c7ce08bca 100644
--- a/mqx/util_lib/Sources/util.c
+++ b/mqx/util_lib/Sources/util.c
@@ -1,178 +1,180 @@
-/* util.c */
-
-#include
-#include
-#include
-#include
-
-#include "util.h"
-
-#if !BSPCFG_ENABLE_IO_SUBSYSTEM
- #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined \
- non-zero in user_config.h. Please recompile BSP with this option.
-#endif
-
-#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED
- #error This application requires BSP_DEFAULT_IO_CHANNEL to be not \
- NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero \
- in user_config.h and recompile BSP with this option.
-#endif
-
-#if defined BSP_SDCARD_ESDHC_CHANNEL
- #if ! BSPCFG_ENABLE_ESDHC
- #error This application requires BSPCFG_ENABLE_ESDHC defined \
- non-zero in user_config.h. Please recompile libraries with \
- this option.
- #endif
-#elif defined BSP_SDCARD_SDHC_CHANNEL
- #if ! BSPCFG_ENABLE_SDHC
- #error This application requires BSPCFG_ENABLE_SDHC defined \
- non-zero in user_config.h. Please recompile libraries with \
- this option.
- #endif
-#endif
-
-#if defined (BSP_SDCARD_SPI_CHANNEL)
- #define SDCARD_COM_CHANNEL BSP_SDCARD_SPI_CHANNEL
-#elif defined (BSP_SDCARD_ESDHC_CHANNEL)
- #define SDCARD_COM_CHANNEL BSP_SDCARD_ESDHC_CHANNEL
-#elif defined (BSP_SDCARD_SDHC_CHANNEL)
- #define SDCARD_COM_CHANNEL BSP_SDCARD_SDHC_CHANNEL
-#else
- #error "SDCARD low level communication device not defined!"
-#endif
-
-int sdcard_open(MQX_FILE_PTR *com_handle, MQX_FILE_PTR *sdcard_handle,
- MQX_FILE_PTR *partman_handle, MQX_FILE_PTR *filesystem_handle,
- char *partman_name, char *filesystem_name)
-{
-
- _mqx_int error_code;
- _mqx_uint param;
-
- /* Open low level communication device */
- *com_handle = fopen(SDCARD_COM_CHANNEL, NULL);
-
- if (NULL == *com_handle) {
- printf("Error installing communication handle.\n");
- return -60;
- }
-
- /* Install SD card device */
- error_code = _io_sdcard_install("sdcard:", (pointer) &_bsp_sdcard0_init,
- *com_handle);
- if (error_code != MQX_OK) {
- printf("Error installing SD card device (0x%x)\n", error_code);
- return -61;
- }
-
- _time_delay(200);
-
- /* Open the device which MFS will be installed on */
- *sdcard_handle = fopen("sdcard:", 0);
- if (*sdcard_handle == NULL) {
- printf("Unable to open SD card device.\n");
- return -62;
- }
-
- /* Install partition manager over SD card driver */
- error_code = _io_part_mgr_install(*sdcard_handle, partman_name, 0);
- if (error_code != MFS_NO_ERROR) {
- printf("Error installing partition manager: %s\n", MFS_Error_text(
- (uint_32) error_code));
- return -63;
- }
-
- /* Open partition manager */
- *partman_handle = fopen(partman_name, NULL);
- if (*partman_handle == NULL) {
- error_code = ferror(*partman_handle);
- printf("Error opening partition manager: %s\n", MFS_Error_text(
- (uint_32) error_code));
- return -64;
- }
-
- /* Validate partition 1 */
- param = 1;
- error_code = _io_ioctl(*partman_handle, IO_IOCTL_VAL_PART, ¶m);
- if (error_code == MQX_OK) {
- /* Install MFS over partition 1 */
- error_code = _io_mfs_install(*partman_handle, filesystem_name, param);
- if (error_code != MFS_NO_ERROR) {
- printf("Error initializing MFS over partition: %s\n",
- MFS_Error_text((uint_32) error_code));
- return -65;
- }
-
- } else {
- /* Install MFS over SD card driver */
- error_code = _io_mfs_install(*sdcard_handle, filesystem_name,
- (_file_size) 0);
- if (error_code != MFS_NO_ERROR) {
- printf("Error initializing MFS: %s\n", MFS_Error_text(
- (uint_32) error_code));
- return -66;
- }
- } /* end Validate partition 1 */
-
- /* Open file system */
- *filesystem_handle = fopen(filesystem_name, NULL);
- error_code = ferror(*filesystem_handle);
- if ((error_code != MFS_NO_ERROR) && (error_code != MFS_NOT_A_DOS_DISK)) {
- printf("Error opening filesystem: %s\n", MFS_Error_text(
- (uint_32) error_code));
- return -67;
- }
- if (error_code == MFS_NOT_A_DOS_DISK) {
- printf("NOT A DOS DISK! You must format to continue.\n");
- return -68;
- }
-
- return 0;
-}
-
-int sdcard_close(MQX_FILE_PTR *sdcard_handle, MQX_FILE_PTR *partman_handle,
- MQX_FILE_PTR *filesystem_handle,
- char *partman_name, char *filesystem_name)
-{
- _mqx_int error_code;
-
- /* Close the filesystem */
- if (MQX_OK != fclose(*filesystem_handle)) {
- printf("Error closing filesystem.\n");
- return -69;
- }
- *filesystem_handle = NULL;
-
- /* Uninstall MFS */
- error_code = _io_dev_uninstall(filesystem_name);
- if (error_code != MFS_NO_ERROR) {
- printf("Error uninstalling filesystem.\n");
- return -70;
- }
-
- /* Close partition manager */
- if (MQX_OK != fclose(*partman_handle)) {
- printf("Unable to close partition manager.\n");
- return -71;
- }
- *partman_handle = NULL;
-
- /* Uninstall partition manager */
- error_code = _io_dev_uninstall(partman_name);
- if (error_code != MFS_NO_ERROR) {
- printf("Error uninstalling partition manager.\n");
- return -72;
- }
-
- /* Close the SD card device */
- if (MQX_OK != fclose(*sdcard_handle)) {
- printf("Unable to close SD card device.\n");
- return -73;
- }
- *sdcard_handle = NULL;
-
- return 0;
-}
-
-/* EOF */
+/* util.c */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "util.h"
+
+#if !BSPCFG_ENABLE_IO_SUBSYSTEM
+ #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined \
+ non-zero in user_config.h. Please recompile BSP with this option.
+#endif
+
+#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED
+ #error This application requires BSP_DEFAULT_IO_CHANNEL to be not \
+ NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero \
+ in user_config.h and recompile BSP with this option.
+#endif
+
+#if defined BSP_SDCARD_ESDHC_CHANNEL
+ #if ! BSPCFG_ENABLE_ESDHC
+ #error This application requires BSPCFG_ENABLE_ESDHC defined \
+ non-zero in user_config.h. Please recompile libraries with \
+ this option.
+ #endif
+#elif defined BSP_SDCARD_SDHC_CHANNEL
+ #if ! BSPCFG_ENABLE_SDHC
+ #error This application requires BSPCFG_ENABLE_SDHC defined \
+ non-zero in user_config.h. Please recompile libraries with \
+ this option.
+ #endif
+#endif
+
+#if defined (BSP_SDCARD_SPI_CHANNEL)
+ #define SDCARD_COM_CHANNEL BSP_SDCARD_SPI_CHANNEL
+#elif defined (BSP_SDCARD_ESDHC_CHANNEL)
+ #define SDCARD_COM_CHANNEL BSP_SDCARD_ESDHC_CHANNEL
+#elif defined (BSP_SDCARD_SDHC_CHANNEL)
+ #define SDCARD_COM_CHANNEL BSP_SDCARD_SDHC_CHANNEL
+#else
+ #error "SDCARD low level communication device not defined!"
+#endif
+
+int sdcard_open(MQX_FILE_PTR *com_handle, MQX_FILE_PTR *sdcard_handle,
+ MQX_FILE_PTR *partman_handle, MQX_FILE_PTR *filesystem_handle,
+ char *partman_name, char *filesystem_name)
+{
+ _mqx_int error_code;
+ _mqx_uint param;
+
+ /* Open low level communication device */
+ *com_handle = fopen(SDCARD_COM_CHANNEL, NULL);
+
+ if (NULL == *com_handle) {
+ printf("Error installing communication handle.\n");
+ return -60;
+ }
+
+ /* Install SD card device */
+ error_code = _io_sdcard_install("sdcard:", (void *)&_bsp_sdcard0_init,
+ *com_handle);
+ if (error_code != MQX_OK) {
+ printf("Error installing SD card device (0x%x)\n", error_code);
+ return -61;
+ }
+
+ _time_delay(200);
+
+ /* Open the device which MFS will be installed on */
+ *sdcard_handle = fopen("sdcard:", 0);
+ if (*sdcard_handle == NULL) {
+ printf("Unable to open SD card device.\n");
+ return -62;
+ }
+
+ /* Install partition manager over SD card driver */
+ error_code = _io_part_mgr_install(*sdcard_handle, partman_name, 0);
+ if (error_code != MFS_NO_ERROR) {
+ printf("Error installing partition manager: %s\n", MFS_Error_text(
+ (uint32_t) error_code));
+ return -63;
+ }
+
+ /* Open partition manager */
+ *partman_handle = fopen(partman_name, NULL);
+ if (*partman_handle == NULL) {
+ error_code = ferror(*partman_handle);
+ printf("Error opening partition manager: %s\n", MFS_Error_text(
+ (uint32_t) error_code));
+ return -64;
+ }
+
+ /* Validate partition 1 */
+ param = 1;
+ error_code = _io_ioctl(*partman_handle, IO_IOCTL_VAL_PART, ¶m);
+ if (error_code == MQX_OK) {
+ /* Install MFS over partition 1 */
+ error_code = _io_mfs_install(*partman_handle, filesystem_name, param);
+ if (error_code != MFS_NO_ERROR) {
+ printf("Error initializing MFS over partition: %s\n",
+ MFS_Error_text((uint32_t) error_code));
+ return -65;
+ }
+
+ } else {
+ /* Install MFS over SD card driver */
+ error_code = _io_mfs_install(*sdcard_handle, filesystem_name,
+ (_file_size) 0);
+ if (error_code != MFS_NO_ERROR) {
+ printf("Error initializing MFS: %s\n", MFS_Error_text(
+ (uint32_t) error_code));
+ return -66;
+ }
+ } /* end Validate partition 1 */
+
+ /* Open file system */
+ *filesystem_handle = fopen(filesystem_name, NULL);
+ error_code = ferror(*filesystem_handle);
+ if ((error_code != MFS_NO_ERROR) && (error_code != MFS_NOT_A_DOS_DISK)) {
+ printf("Error opening filesystem: %s\n", MFS_Error_text(
+ (uint32_t) error_code));
+ return -67;
+ }
+ if (error_code == MFS_NOT_A_DOS_DISK) {
+ printf("NOT A DOS DISK! You must format to continue.\n");
+ return -68;
+ }
+
+ return 0;
+}
+
+int sdcard_close(MQX_FILE_PTR *sdcard_handle, MQX_FILE_PTR *partman_handle,
+ MQX_FILE_PTR *filesystem_handle,
+ char *partman_name, char *filesystem_name)
+{
+ _mqx_int error_code;
+
+ /* Close the filesystem */
+ if (MQX_OK != fclose(*filesystem_handle)) {
+ printf("Error closing filesystem.\n");
+ return -69;
+ }
+ *filesystem_handle = NULL;
+
+ /* Uninstall MFS */
+ error_code = _io_dev_uninstall(filesystem_name);
+ if (error_code != MFS_NO_ERROR) {
+ printf("Error uninstalling filesystem.\n");
+ return -70;
+ }
+
+ /* Close partition manager */
+ if (MQX_OK != fclose(*partman_handle)) {
+ printf("Unable to close partition manager.\n");
+ return -71;
+ }
+ *partman_handle = NULL;
+
+ /* Uninstall partition manager */
+ error_code = _io_dev_uninstall(partman_name);
+ if (error_code != MFS_NO_ERROR) {
+ printf("Error uninstalling partition manager.\n");
+ return -72;
+ }
+
+ /* Close the SD card device */
+ if (MQX_OK != fclose(*sdcard_handle)) {
+ printf("Unable to close SD card device.\n");
+ return -73;
+ }
+ *sdcard_handle = NULL;
+
+ return 0;
+}
+
+/* EOF */