File indexing completed on 2025-05-11 08:23:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include <stdio.h>
0036
0037 #include <mpc55xx/mpc55xx.h>
0038 #include <mpc55xx/regs.h>
0039 #include <mpc55xx/dspi.h>
0040
0041 #include <bsp.h>
0042
0043 #include <rtems/status-checks.h>
0044
0045 #ifdef MPC55XX_BOARD_MPC5566EVB
0046
0047 static rtems_status_code mpc55xx_dspi_init(void)
0048 {
0049 int rv = 0;
0050 int i = 0;
0051 char device_name [] = "/dev/spi0";
0052 union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS;
0053
0054 rv = rtems_libi2c_initialize();
0055 RTEMS_CHECK_RV_SC( rv, "rtems_libi2c_initialize");
0056
0057
0058 SIU.DISR.R = 0x000000FC;
0059
0060
0061 pcr.B.PA = 1;
0062 pcr.B.ODE = 0;
0063 pcr.B.HYS = 0;
0064 pcr.B.SRC = 3;
0065 pcr.B.WPE = 1;
0066 pcr.B.WPS = 1;
0067
0068
0069 pcr.B.OBE = 1;
0070 pcr.B.IBE = 0;
0071 SIU.PCR [93].R = pcr.R;
0072
0073
0074 pcr.B.OBE = 0;
0075 pcr.B.IBE = 1;
0076 SIU.PCR [94].R = pcr.R;
0077
0078
0079 pcr.B.OBE = 1;
0080 pcr.B.IBE = 0;
0081 SIU.PCR [95].R = pcr.R;
0082
0083
0084 pcr.B.OBE = 1;
0085 pcr.B.IBE = 0;
0086 SIU.PCR [96].R = pcr.R;
0087 SIU.PCR [97].R = pcr.R;
0088 SIU.PCR [98].R = pcr.R;
0089 SIU.PCR [99].R = pcr.R;
0090 SIU.PCR [100].R = pcr.R;
0091 SIU.PCR [101].R = pcr.R;
0092
0093 mpc55xx_dspi_bus_table [3].master = 0;
0094 for (i = 0; i < MPC55XX_DSPI_NUMBER; ++i) {
0095 device_name [8] = (char) ('0' + i);
0096 rv = rtems_libi2c_register_bus( device_name, (rtems_libi2c_bus_t *) &mpc55xx_dspi_bus_table [i]);
0097 RTEMS_CHECK_RV_SC( rv, device_name);
0098 }
0099
0100 return RTEMS_SUCCESSFUL;
0101 }
0102
0103 #include <stdio.h>
0104 #include <rtems/fsmount.h>
0105 #include <rtems/dosfs.h>
0106 #include <rtems/bdpart.h>
0107 #include <rtems/console.h>
0108
0109 #include <libchip/spi-sd-card.h>
0110
0111 #define MPC55XX_DEVICE "sd-card-a"
0112 #define MPC55XX_DEVICE_FILE "/dev/" MPC55XX_DEVICE
0113 #define MPC55XX_PARTITION "/dev/sd-card-a1"
0114 #define MPC55XX_MOUNT_POINT "/mnt"
0115
0116 static fstab_t mpc55xx_fs_table [] = { {
0117 MPC55XX_PARTITION, MPC55XX_MOUNT_POINT,
0118 "dosfs", RTEMS_FILESYSTEM_READ_WRITE,
0119 FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
0120 FSMOUNT_MNT_OK
0121 }, {
0122 MPC55XX_DEVICE_FILE, MPC55XX_MOUNT_POINT,
0123 "dosfs", RTEMS_FILESYSTEM_READ_WRITE,
0124 FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
0125 0
0126 }
0127 };
0128
0129 sd_card_driver_entry sd_card_driver_table [] = {
0130 {
0131 .device_name = "/dev/sd-card-a",
0132 .bus = 0,
0133 .transfer_mode = SD_CARD_TRANSFER_MODE_DEFAULT,
0134 .command = SD_CARD_COMMAND_DEFAULT,
0135
0136 .response_index = SD_CARD_COMMAND_SIZE,
0137 .n_ac_max = SD_CARD_N_AC_MAX_DEFAULT,
0138 .block_number = 0,
0139 .block_size = 0,
0140 .block_size_shift = 0,
0141 .busy = true,
0142 .verbose = true,
0143 .schedule_if_busy = false
0144 }
0145 };
0146
0147 size_t sd_card_driver_table_size = sizeof( sd_card_driver_table) / sizeof( sd_card_driver_table [0]);
0148
0149 rtems_status_code mpc55xx_sd_card_init( bool mount)
0150 {
0151 rtems_status_code sc = RTEMS_SUCCESSFUL;
0152 int rv = 0;
0153 sd_card_driver_entry *e = &sd_card_driver_table [0];
0154
0155 RTEMS_DEBUG_PRINT( "Task started\n");
0156
0157 sc = mpc55xx_dspi_init();
0158 RTEMS_CHECK_SC( rv, "Intitalize DSPI bus");
0159
0160 e->bus = mpc55xx_dspi_bus_table [0].bus_number;
0161
0162 sc = sd_card_register();
0163 RTEMS_CHECK_SC( sc, "Register SD Card");
0164
0165 if (mount) {
0166 sc = rtems_bdpart_register_from_disk( MPC55XX_DEVICE_FILE);
0167 RTEMS_CHECK_SC( sc, "Initialize IDE partition table");
0168
0169 rv = rtems_fsmount( mpc55xx_fs_table, sizeof( mpc55xx_fs_table) / sizeof( mpc55xx_fs_table [0]), NULL);
0170 RTEMS_CHECK_RV_SC( rv, "Mount file systems");
0171 }
0172
0173 return RTEMS_SUCCESSFUL;
0174 }
0175
0176 #endif