Changeset 55a685b in rtems


Ignore:
Timestamp:
Oct 25, 2007, 4:17:56 PM (12 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, 4.9, master
Children:
abe0cdb1
Parents:
0a23c714
Message:

added SPI support to libi2c
added IRQ support to MPC83xx i2c driver
added mpc83xx spi driver

Files:
16 edited

Legend:

Unmodified
Added
Removed
  • c/src/ChangeLog

    r0a23c714 r55a685b  
     12007-09-24      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     2
     3        * libchip/i2c/spi-flash-m25p40.c, libchip/i2c/spi-flash-m25p40.c,
     4        * libchip/Makefile.am:
     5        added SPI flash driver for a M25P40 chip (based on libi2c extensions)
     6
    172007-09-25      Joel Sherrill <joel.sherrill@OARcorp.com>
    28
  • c/src/lib/libbsp/powerpc/gen83xx/ChangeLog

    r0a23c714 r55a685b  
     12007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     2
     3        * include/bsp.h: fixed some typos
     4
     52007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     6
     7        * Makefile.am, spi/spi_init.c, include/bsp.h: add spi support
     8
    192007-09-17      Joel Sherrill <joel.sherrill@OARcorp.com>
    210
  • c/src/lib/libbsp/powerpc/gen83xx/Makefile.am

    r0a23c714 r55a685b  
    7777
    7878noinst_PROGRAMS += console.rel
    79 console_rel_SOURCES = console/console.c console/ns16550cfg.c
     79console_rel_SOURCES = console/console.c console/ns16550cfg.c 
    8080console_rel_CPPFLAGS = $(AM_CPPFLAGS)
    8181console_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
     
    9494bsp_i2c_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
    9595
     96noinst_PROGRAMS += bsp_spi.rel
     97bsp_spi_rel_SOURCES   = spi/spi_init.c
     98bsp_spi_rel_CPPFLAGS  = $(AM_CPPFLAGS)
     99bsp_spi_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
     100
     101
    96102noinst_LIBRARIES = libbsp.a
    97103libbsp_a_SOURCES =
    98104libbsp_a_LIBADD = startup.rel pclock.rel console.rel vectors.rel irq.rel \
    99     mpc83xx_regs.rel bsp_i2c.rel
     105    mpc83xx_regs.rel bsp_i2c.rel bsp_spi.rel
    100106libbsp_a_LIBADD += ../../../libcpu/@RTEMS_CPU@/shared/cpuIdent.rel \
    101107    ../../../libcpu/@RTEMS_CPU@/shared/cache.rel \
     
    107113    ../../../libcpu/@RTEMS_CPU@/mpc6xx/mmu.rel   \
    108114    ../../../libcpu/@RTEMS_CPU@/mpc6xx/timer.rel \
    109     ../../../libcpu/@RTEMS_CPU@/mpc83xx/i2c.rel
     115    ../../../libcpu/@RTEMS_CPU@/mpc83xx/i2c.rel  \
     116    ../../../libcpu/@RTEMS_CPU@/mpc83xx/spi.rel
    110117
    111118if HAS_NETWORKING
  • c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c

    r0a23c714 r55a685b  
    7474{
    7575  int ret_code;
     76  int i2c1_busno,i2c2_busno;
    7677
    7778  /*
    78    * init I2C library
     79   * init I2C library (if not already done)
    7980   */
    8081  rtems_libi2c_initialize ();
     
    8889    return -ret_code;
    8990  }
     91  i2c1_busno = ret_code;
    9092  /*
    9193   * register second I2C bus
     
    9698    return -ret_code;
    9799  }
     100  i2c2_busno = ret_code;
    98101  /*
    99102   * register EEPROM to bus 1, Address 0x50
     
    101104  ret_code = rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME,
    102105                                       i2c_2b_eeprom_driver_descriptor,
    103                                        0,0x50);
     106                                       i2c1_busno,0x50);
    104107  if (ret_code < 0) {
    105108    return -ret_code;
  • c/src/lib/libbsp/powerpc/gen83xx/include/bsp.h

    r0a23c714 r55a685b  
    240240void bsp_cleanup(void);
    241241rtems_status_code bsp_register_i2c(void);
     242rtems_status_code bsp_register_spi(void);
    242243
    243244/* console modes (only termios) */
     
    281282#define RTEMS_BSP_I2C_EEPROM_DEVICE_PATH "/dev/i2c1.eeprom"
    282283
     284/*
     285 * SPI Flash device name
     286 */
     287#define RTEMS_BSP_SPI_FLASH_DEVICE_NAME "flash"
     288#define RTEMS_BSP_SPI_FLASH_DEVICE_PATH "/dev/spi.flash"
     289
    283290#ifdef __cplusplus
    284291}
  • c/src/lib/libcpu/powerpc/ChangeLog

    r0a23c714 r55a685b  
     12007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     2
     3        * mpc83xx/network/tsec.c:
     4        fixed typo in comment of attach function
     5       
     62007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     7
     8        * Makefile.am, mpc83xx/spi/mpc83xx_spidrv.c, 
     9        * mpc83xx/spi/mpc83xx_spidrv.h, mpc83xx/include/mpc83xx.h:
     10        added spi driver
     11       
     122007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     13
     14        * mpc83xx/i2c/mpc83xx_i2cdrv.c: 
     15        added IRQ support in I2C driver
     16       
     172007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     18
     19        * mpc83xx/network/tsec.c: 
     20        added statistics counters to tsec
     21       
    1222007-09-12      Joel Sherrill <joel.sherrill@OARcorp.com>
    223
  • c/src/lib/libcpu/powerpc/Makefile.am

    r0a23c714 r55a685b  
    349349mpc83xx_i2c_rel_LDFLAGS   = $(RTEMS_RELLDFLAGS)
    350350
     351## mpc83xx/spi
     352include_mpc83xx_HEADERS += mpc83xx/spi/mpc83xx_spidrv.h
     353noinst_PROGRAMS += mpc83xx/spi.rel
     354mpc83xx_spi_rel_SOURCES   = mpc83xx/spi/mpc83xx_spidrv.c \
     355                            mpc83xx/spi/mpc83xx_spidrv.h
     356mpc83xx_spi_rel_CPPFLAGS  = $(AM_CPPFLAGS)
     357mpc83xx_spi_rel_LDFLAGS   = $(RTEMS_RELLDFLAGS)
     358
    351359endif
    352360
  • c/src/lib/libcpu/powerpc/mpc83xx/i2c/mpc83xx_i2cdrv.c

    r0a23c714 r55a685b  
    2727#include <rtems/libi2c.h>
    2828
    29 /* #define DEBUG */
    30 
    31 /*
    32  * XXX: for the beginning, this driver works polled
    33  */
     29#define DEBUG
    3430
    3531/*=========================================================================*\
     
    111107  printk("mpc83xx_i2c_wait called... ");
    112108#endif
    113   softc_ptr->reg_ptr->i2ccr |= MPC83XX_I2CCR_MIEN;
    114109
    115110  if (softc_ptr->initialized) {
     111    /*
     112     * enable interrupt mask
     113     */
     114    softc_ptr->reg_ptr->i2ccr |= MPC83XX_I2CCR_MIEN;
    116115    rc = rtems_semaphore_obtain(softc_ptr->irq_sema_id,RTEMS_WAIT,100);
    117116    if (rc != RTEMS_SUCCESSFUL) {
     
    132131  softc_ptr->reg_ptr->i2ccr &= ~MPC83XX_I2CCR_MIEN;
    133132
    134   act_status = softc_ptr->reg_ptr->i2csr & status_mask;
    135   if (act_status != desired_status) {
     133  act_status = softc_ptr->reg_ptr->i2csr;
     134  if ((act_status  & status_mask) != desired_status) {
    136135#if defined(DEBUG)
    137136    printk("... exit with RTEMS_IO_ERROR\r\n");
     
    143142#endif
    144143  return RTEMS_SUCCESSFUL;
     144}
     145
     146/*=========================================================================*\
     147| Function:                                                                 |
     148\*-------------------------------------------------------------------------*/
     149static void mpc83xx_i2c_irq_handler
     150(
     151/*-------------------------------------------------------------------------*\
     152| Purpose:                                                                  |
     153|   handle interrupts                                                       |
     154+---------------------------------------------------------------------------+
     155| Input Parameters:                                                         |
     156\*-------------------------------------------------------------------------*/
     157 rtems_irq_hdl_param handle     /* handle, is softc_ptr structure          */
     158)
     159/*-------------------------------------------------------------------------*\
     160| Return Value:                                                             |
     161|    <none>                                                                 |
     162\*=========================================================================*/
     163{
     164  mpc83xx_i2c_softc_t *softc_ptr = (mpc83xx_i2c_softc_t *)handle;
     165 
     166  /*
     167   * disable interrupt mask
     168   */
     169  softc_ptr->reg_ptr->i2ccr &= ~MPC83XX_I2CCR_MIEN;
     170  if (softc_ptr->initialized) {
     171    rtems_semaphore_release(softc_ptr->irq_sema_id);
     172  } 
     173}
     174
     175/*=========================================================================*\
     176| Function:                                                                 |
     177\*-------------------------------------------------------------------------*/
     178static void mpc83xx_i2c_irq_on_off
     179(
     180/*-------------------------------------------------------------------------*\
     181| Purpose:                                                                  |
     182|   enable/disable interrupts (void, handled at different position)         |
     183+---------------------------------------------------------------------------+
     184| Input Parameters:                                                         |
     185\*-------------------------------------------------------------------------*/
     186 const
     187 rtems_irq_connect_data *irq_conn_data   /* irq connect data                */
     188)
     189/*-------------------------------------------------------------------------*\
     190| Return Value:                                                             |
     191|    <none>                                                                 |
     192\*=========================================================================*/
     193{
     194}
     195
     196
     197/*=========================================================================*\
     198| Function:                                                                 |
     199\*-------------------------------------------------------------------------*/
     200static int mpc83xx_i2c_irq_isOn
     201(
     202/*-------------------------------------------------------------------------*\
     203| Purpose:                                                                  |
     204|   check state of interrupts, void, done differently                       |
     205+---------------------------------------------------------------------------+
     206| Input Parameters:                                                         |
     207\*-------------------------------------------------------------------------*/
     208 const
     209 rtems_irq_connect_data *irq_conn_data  /* irq connect data                */
     210)
     211/*-------------------------------------------------------------------------*\
     212| Return Value:                                                             |
     213|    TRUE, if enabled                                                       |
     214\*=========================================================================*/
     215{
     216  return (TRUE);
     217}
     218
     219/*=========================================================================*\
     220| Function:                                                                 |
     221\*-------------------------------------------------------------------------*/
     222static void mpc83xx_i2c_install_irq_handler
     223(
     224/*-------------------------------------------------------------------------*\
     225| Purpose:                                                                  |
     226|   (un-)install the interrupt handler                                      |
     227+---------------------------------------------------------------------------+
     228| Input Parameters:                                                         |
     229\*-------------------------------------------------------------------------*/
     230 mpc83xx_i2c_softc_t *softc_ptr,        /* ptr to control structure        */
     231 int install                            /* TRUE: install, FALSE: remove    */
     232)
     233/*-------------------------------------------------------------------------*\
     234| Return Value:                                                             |
     235|    <none>                                                                 |
     236\*=========================================================================*/
     237{
     238  rtems_status_code rc = RTEMS_SUCCESSFUL;
     239
     240  rtems_irq_connect_data irq_conn_data = {
     241    softc_ptr->irq_number,
     242    mpc83xx_i2c_irq_handler,           /* rtems_irq_hdl           */
     243    (rtems_irq_hdl_param)softc_ptr,    /* (rtems_irq_hdl_param)   */
     244    mpc83xx_i2c_irq_on_off,            /* (rtems_irq_enable)      */
     245    mpc83xx_i2c_irq_on_off,            /* (rtems_irq_disable)     */
     246    mpc83xx_i2c_irq_isOn               /* (rtems_irq_is_enabled)  */
     247  };
     248
     249  /*
     250   * (un-)install handler for I2C device
     251   */
     252  if (install) {
     253    /*
     254     * create semaphore for IRQ synchronization
     255     */
     256    rc = rtems_semaphore_create(rtems_build_name('i','2','c','s'),
     257                                0,
     258                                RTEMS_FIFO
     259                                | RTEMS_SIMPLE_BINARY_SEMAPHORE,
     260                                0,
     261                                &softc_ptr->irq_sema_id);
     262    if (rc != RTEMS_SUCCESSFUL) {
     263      rtems_panic("I2C: cannot create semaphore");
     264    }
     265    if (!BSP_install_rtems_irq_handler (&irq_conn_data)) {
     266      rtems_panic("I2C: cannot install IRQ handler");
     267    }
     268  }
     269  else {
     270    if (!BSP_remove_rtems_irq_handler (&irq_conn_data)) {
     271      rtems_panic("I2C: cannot uninstall IRQ handler");
     272    }
     273    /*
     274     * delete sync semaphore
     275     */
     276    if (softc_ptr->irq_sema_id != 0) {
     277      rc = rtems_semaphore_delete(softc_ptr->irq_sema_id);
     278      if (rc != RTEMS_SUCCESSFUL) {
     279        rtems_panic("I2C: cannot delete semaphore");
     280      }
     281    }
     282  }
    145283}
    146284
     
    186324  softc_ptr->reg_ptr->i2cdfsrr = 0x10 ; /* no special filtering needed */
    187325  /*
    188    * set own slave address to broadcasr (0x00)
     326   * set own slave address to broadcast (0x00)
    189327   */
    190328  softc_ptr->reg_ptr->i2cadr = 0x00 ;
     
    196334 
    197335  /*
    198    * FIXME: init interrupt stuff
    199    */ 
    200   /*
    201    * FIXME: init other stuff
    202    */
     336   * init interrupt stuff
     337   */
     338  mpc83xx_i2c_install_irq_handler(softc_ptr,TRUE);
     339
     340  /*
     341   * mark, that we have initialized
     342   */
     343  softc_ptr->initialized = TRUE;
    203344#if defined(DEBUG)
    204345  printk("... exit OK\r\n");
  • c/src/lib/libcpu/powerpc/mpc83xx/include/mpc83xx.h

    r0a23c714 r55a685b  
    377377  uint8_t reserved0_7038[0x07100-0x07038];/* 0x0_7038-70FF Reserved */
    378378} m83xxSPIRegisters_t;
     379                                              /* SPIMODE register fields    */
     380#define  MPC83XX_SPIMODE_LOOP   (1   << (31- 1)) /* loopback                */
     381#define  MPC83XX_SPIMODE_CI     (1   << (31- 2)) /* clock invert            */
     382#define  MPC83XX_SPIMODE_CP     (1   << (31- 3)) /* clock phase             */
     383#define  MPC83XX_SPIMODE_DIV16  (1   << (31- 4)) /* divide by 16            */
     384#define  MPC83XX_SPIMODE_REV    (1   << (31- 5)) /* LSB first               */
     385#define  MPC83XX_SPIMODE_M_S    (1   << (31- 6)) /* master/slave            */
     386#define  MPC83XX_SPIMODE_EN     (1   << (31- 7)) /* enable                  */
     387#define  MPC83XX_SPIMODE_LEN(n) ((n) << (31-11)) /* length code             */
     388#define  MPC83XX_SPIMODE_PM(n)  ((n) << (31-15)) /* prescaler               */
     389#define  MPC83XX_SPIMODE_OD     (1   << (31-19)) /* open drain              */
     390
     391                                               /* SPCOM  register fields    */
     392#define  MPC83XX_SPCOM_LST    (1   << (31- 9))  /* last transfer            */
     393
     394                                            /* SPIE/M register fields     */
     395#define  MPC83XX_SPIE_LT     (1 << (31-17)) /* last character transmitted */
     396#define  MPC83XX_SPIE_DNR    (1 << (31-18)) /* data not ready             */
     397#define  MPC83XX_SPIE_OV     (1 << (31-19)) /* overrun                    */
     398#define  MPC83XX_SPIE_UN     (1 << (31-20)) /* unterrun                   */
     399#define  MPC83XX_SPIE_MME    (1 << (31-21)) /* multi-master error         */
     400#define  MPC83XX_SPIE_NE     (1 << (31-22)) /* not empty                  */
     401#define  MPC83XX_SPIE_NF     (1 << (31-23)) /* not full                   */
    379402
    380403typedef struct m83xxDMARegisters_ {
     
    775798#define M83xx_TSEC_TSTAT_THLT  (1<<(31-0))
    776799
     800/*
     801 * TSEC RSTAT bit definitions
     802 */
     803#define M83xx_TSEC_RSTAT_QHLT  (1<<(31-8))
    777804  /*
    778805   * TSEC ECNTRL bit positions
  • c/src/lib/libcpu/powerpc/mpc83xx/network/tsec.c

    r0a23c714 r55a685b  
    9595   */
    9696  unsigned long           rxInterrupts;
    97   unsigned long           rxNotLast;
    98   unsigned long           rxGiant;
    99   unsigned long           rxNonOctet;
    100   unsigned long           rxBadCRC;
    101   unsigned long           rxOverrun;
    102   unsigned long           rxCollision;
    103 
     97  unsigned long           rxErrors;
    10498  /*
    10599   * statistic counters Tx
    106100   */
    107101  unsigned long           txInterrupts;
    108   unsigned long           txDeferred;
    109   unsigned long           txLateCollision;
    110   unsigned long           txUnderrun;
    111   unsigned long           txMisaligned;
    112   unsigned long           rxNotFirst;
    113   unsigned long           txRetryLimit;
     102  unsigned long           txErrors;
    114103  };
    115104
     
    239228
    240229  /*
    241    * init EDIS register: enable all error reportings
    242    * FIXME: make sure we handle these errors correctly
    243    */
    244   reg_ptr->edis = 0;
     230   * init EDIS register: disable all error reportings
     231   */
     232  reg_ptr->edis = (M83xx_TSEC_EDIS_BSYDIS    |
     233                   M83xx_TSEC_EDIS_EBERRDIS  |
     234                   M83xx_TSEC_EDIS_TXEDIS    |
     235                   M83xx_TSEC_EDIS_LCDIS     |
     236                   M83xx_TSEC_EDIS_CRLXDADIS |
     237                   M83xx_TSEC_EDIS_FUNDIS);
    245238  /*
    246239   * init minimum frame length register
     
    617610       */
    618611      MFREE(m,n);
    619       /*
    620        * update statistics
    621        */
    622       if (0 != (status & M83xx_BD_LAST))
    623         sc->rxNotLast++;
    624       if (0 != (status & M83xx_BD_FIRST_IN_FRAME))
    625         sc->rxNotFirst++;
    626 
    627       if (0 == (status & M83xx_BD_LONG)) {
    628         sc->rxGiant++;
    629       }
    630       if (0 == (status & M83xx_BD_NONALIGNED)) {
    631         sc->rxNonOctet++;
    632       }
    633       if (0 == (status & M83xx_BD_CRC_ERROR)) {
    634         sc->rxBadCRC++;
    635       }
    636       if (0 == (status & M83xx_BD_OVERRUN)) {
    637         sc->rxOverrun++;
    638       }
    639612    }
    640613    /*
     
    12351208\*=========================================================================*/
    12361209{
    1237   /*
    1238    * FIXME: check error conditions, do something useful
    1239    */
    1240 #if 0
    1241   /*
    1242    * disable error interrupts
    1243    */
    1244   M83xx_TSEC_IMASK_SET(sc->reg_ptr->imask,M83xx_IEVENT_ERRALL,0);
    1245   /*
    1246    * FIXME: do something :-)
    1247    */
    1248 #endif
     1210  struct mpc83xx_tsec_struct *sc =
     1211    (struct mpc83xx_tsec_struct *)handle;
     1212  /*
     1213   * clear error events in IEVENT
     1214   */
     1215  sc->reg_ptr->tstat = M83xx_IEVENT_ERRALL;
     1216  /*
     1217   * has Rx been stopped? then restart it
     1218   */
     1219  if (0 != (sc->reg_ptr->rstat & M83xx_TSEC_RSTAT_QHLT)) {
     1220    sc->rxErrors++;
     1221    sc->reg_ptr->rstat = M83xx_TSEC_RSTAT_QHLT;
     1222  }
     1223  /*
     1224   * has Tx been stopped? then restart it
     1225   */
     1226  if (0 != (sc->reg_ptr->tstat & M83xx_TSEC_TSTAT_THLT)) {
     1227    sc->txErrors++;
     1228    sc->reg_ptr->tstat = M83xx_TSEC_TSTAT_THLT;
     1229  }
    12491230}
    12501231
     
    15301511{
    15311512  /*
    1532    * FIXME: deinitialize driver
     1513   * deinitialize driver?
    15331514   */
    15341515}
     
    15411522/*-------------------------------------------------------------------------*\
    15421523| Purpose:                                                                  |
    1543 |   perform io control functions                                            |
     1524|   print statistics                                                        |
    15441525+---------------------------------------------------------------------------+
    15451526| Input Parameters:                                                         |
     
    15691550   * print some statistics
    15701551   */
    1571   printf ("  Rx Interrupts:%-8lu",   sc->rxInterrupts);
    1572   printf ("      Not First:%-8lu",   sc->rxNotFirst);
    1573   printf ("       Not Last:%-8lu\n", sc->rxNotLast);
    1574   printf ("          Giant:%-8lu",   sc->rxGiant);
    1575   printf ("      Non-octet:%-8lu\n", sc->rxNonOctet);
    1576   printf ("        Bad CRC:%-8lu",   sc->rxBadCRC);
    1577   printf ("        Overrun:%-8lu",   sc->rxOverrun);
    1578   printf ("      Collision:%-8lu\n", sc->rxCollision);
     1552  printf ("   Rx Interrupts:%-8lu",   sc->rxInterrupts);
     1553  printf ("       Rx Errors:%-8lu",   sc->rxErrors);
     1554  printf ("      Rx packets:%-8lu\n",   
     1555          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_rpkt]);
     1556  printf ("   Rx broadcasts:%-8lu",   
     1557          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_rbca]);
     1558  printf ("   Rx multicasts:%-8lu",   
     1559          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_rmca]);
     1560  printf ("           Giant:%-8lu\n",
     1561          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_rovr]);
     1562  printf ("       Non-octet:%-8lu",
     1563          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_raln]);
     1564  printf ("         Bad CRC:%-8lu",
     1565          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_rfcs]);
     1566  printf ("         Overrun:%-8lu\n",
     1567          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_rdrp]);
    15791568 
    1580   printf ("  Tx Interrupts:%-8lu",   sc->txInterrupts);
    1581   printf ("       Deferred:%-8lu",   sc->txDeferred);
    1582   printf (" Late Collision:%-8lu\n", sc->txLateCollision);
    1583   printf ("Retransmit Limit:%-8lu",   sc->txRetryLimit);
    1584   printf ("        Underrun:%-8lu",   sc->txUnderrun);
    1585   printf ("     Misaligned:%-8lu\n", sc->txMisaligned);
     1569  printf ("   Tx Interrupts:%-8lu",   sc->txInterrupts);
     1570  printf ("       Tx Errors:%-8lu",   sc->txErrors);
     1571  printf ("      Tx packets:%-8lu\n",   
     1572          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_tpkt]);
     1573  printf ("        Deferred:%-8lu",
     1574          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_tdfr]);
     1575  printf ("  Late Collision:%-8lu",
     1576          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_tlcl]);
     1577  printf ("Retransmit Limit:%-8lu\n",
     1578          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_tedf]);
     1579  printf ("        Underrun:%-8lu\n",
     1580          sc->reg_ptr->rmon_mib[m83xx_tsec_rmon_tund]);
    15861581}
    15871582
     
    16331628    }
    16341629    if (ifp->if_flags & IFF_UP) {
    1635       mpc83xx_tsec_off(sc);
     1630      mpc83xx_tsec_init(sc);
    16361631    }
    16371632    break;
     
    16451640
    16461641    /*
    1647      * FIXME: All sorts of multicast commands need to be added here!
     1642     * All sorts of multicast commands need to be added here!
    16481643     */
    16491644  default:
     
    18001795/*-------------------------------------------------------------------------*\
    18011796| Return Value:                                                             |
    1802 |    zero, if success                                                       |
     1797|    1, if success                                                          |
    18031798\*=========================================================================*/
    18041799{
     
    19011896}
    19021897
    1903 
    19041898/*=========================================================================*\
    19051899| Function:                                                                 |
  • c/src/lib/libcpu/powerpc/preinstall.am

    r0a23c714 r55a685b  
    212212        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/mpc83xx/mpc83xx_i2cdrv.h
    213213PREINSTALL_FILES += $(PROJECT_INCLUDE)/mpc83xx/mpc83xx_i2cdrv.h
    214 endif
     214
     215$(PROJECT_INCLUDE)/mpc83xx/mpc83xx_spidrv.h: mpc83xx/spi/mpc83xx_spidrv.h $(PROJECT_INCLUDE)/mpc83xx/$(dirstamp)
     216        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/mpc83xx/mpc83xx_spidrv.h
     217PREINSTALL_FILES += $(PROJECT_INCLUDE)/mpc83xx/mpc83xx_spidrv.h
     218endif
  • c/src/libchip/Makefile.am

    r0a23c714 r55a685b  
    6565# i2c
    6666if LIBCHIP
    67 include_libchip_HEADERS += i2c/i2c-ds1621.h i2c/i2c-2b-eeprom.h
     67include_libchip_HEADERS += i2c/i2c-ds1621.h i2c/i2c-2b-eeprom.h \
     68                           i2c/spi-flash-m25p40.h
    6869
    6970noinst_LIBRARIES += libi2cio.a
    7071libi2cio_a_CPPFLAGS = $(AM_CPPFLAGS)
    7172libi2cio_a_SOURCES  = i2c/i2c-ds1621.c i2c/i2c-2b-eeprom.c \
    72     i2c/i2c-ds1621.h i2c/i2c-2b-eeprom.h
     73    i2c/i2c-ds1621.h i2c/i2c-2b-eeprom.h \
     74    i2c/spi-flash-m25p40.c i2c/spi-flash-m25p40.h
    7375endif
    7476
  • c/src/libchip/preinstall.am

    r0a23c714 r55a685b  
    116116        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/libchip/i2c-2b-eeprom.h
    117117PREINSTALL_FILES += $(PROJECT_INCLUDE)/libchip/i2c-2b-eeprom.h
     118
     119$(PROJECT_INCLUDE)/libchip/spi-flash-m25p40.h: i2c/spi-flash-m25p40.h $(PROJECT_INCLUDE)/libchip/$(dirstamp)
     120        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/libchip/spi-flash-m25p40.h
     121PREINSTALL_FILES += $(PROJECT_INCLUDE)/libchip/spi-flash-m25p40.h
    118122endif
    119123if LIBCHIP
  • cpukit/ChangeLog

    r0a23c714 r55a685b  
     12007-10-25      Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
     2
     3        * libi2c/libi2c.c, libi2c/libi2c.h:
     4        extend API to support SPI devices
     5        made libi2c.h C++-proof
     6
    172007-10-19      Joel Sherrill <joel.sherrill@OARcorp.com>
    28
  • cpukit/libi2c/libi2c.c

    r0a23c714 r55a685b  
    4747 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
    4848 */
     49/*
     50 * adaptations to also handle SPI devices
     51 * by Thomas Doerfler, embedded brains GmbH, Puchheim, Germany
     52 */
    4953#if HAVE_CONFIG_H
    5054#include "config.h"
     
    5660#include <errno.h>
    5761#include <assert.h>
     62#include <stdarg.h>
    5863
    5964#include <rtems.h>
     
    319324{
    320325  rtems_status_code sc;
    321 
     326  static boolean is_initialized = FALSE;
     327
     328  if (is_initialized) {
     329    /*
     330     * already called before? then skip this step
     331     */
     332    return 0;
     333  }
     334 
    322335  if (!(libmutex = mutexCreate (rtems_build_name ('l', 'I', '2', 'C'))))
    323336    return -1;
     
    332345    return -1;
    333346  }
     347  is_initialized = TRUE;
    334348
    335349  return 0;
     
    429443
    430444rtems_status_code
    431 rtems_libi2c_send_start (uint32_t minor)
     445rtems_libi2c_send_start (rtems_device_minor_number minor)
    432446{
    433447  int rval;
     
    460474
    461475rtems_status_code
    462 rtems_libi2c_send_stop (uint32_t minor)
     476rtems_libi2c_send_stop (rtems_device_minor_number minor)
    463477{
    464478  rtems_status_code rval;
     
    477491
    478492rtems_status_code
    479 rtems_libi2c_send_addr (uint32_t minor, int rw)
     493rtems_libi2c_send_addr (rtems_device_minor_number minor, int rw)
    480494{
    481495  rtems_status_code sc;
     
    492506
    493507int
    494 rtems_libi2c_read_bytes (uint32_t minor, unsigned char *bytes, int nbytes)
     508rtems_libi2c_read_bytes (rtems_device_minor_number minor,
     509                         unsigned char *bytes,
     510                         int nbytes)
    495511{
    496512  int sc;
     
    507523
    508524int
    509 rtems_libi2c_write_bytes (uint32_t minor, unsigned char *bytes, int nbytes)
     525rtems_libi2c_write_bytes (rtems_device_minor_number minor,
     526                          unsigned char *bytes,
     527                          int nbytes)
    510528{
    511529  int sc;
     
    521539}
    522540
     541int
     542rtems_libi2c_ioctl (rtems_device_minor_number minor,
     543                    int cmd,
     544                    ...)
     545{
     546  va_list            ap;
     547  int sc = 0;
     548  void *args;
     549  DECL_CHECKED_BH (busno, bush, minor, -)
     550
     551    if (not_started (busno))
     552    return -RTEMS_NOT_OWNER_OF_RESOURCE;
     553
     554  va_start(ap, cmd);
     555  args = va_arg(ap, void *);
     556
     557  switch(cmd) {
     558    /*
     559     * add ioctls defined for this level here:   
     560     */
     561   
     562  case RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE:
     563    /*
     564     * address device, then set transfer mode and perform read_write transfer
     565     */
     566    /*
     567     * perform start/address
     568     */
     569    if (sc == 0) {
     570      sc = rtems_libi2c_send_start (minor);
     571    }
     572    /*
     573     * set tfr mode
     574     */
     575    if (sc == 0) {
     576      sc = bush->ops->ioctl
     577        (bush,
     578         RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
     579         &((rtems_libi2c_tfm_read_write_t *)args)->tfr_mode);
     580    }
     581    /*
     582     * perform read_write
     583     */
     584    if (sc == 0) {
     585      sc = bush->ops->ioctl
     586        (bush,
     587         RTEMS_LIBI2C_IOCTL_READ_WRITE,
     588         &((rtems_libi2c_tfm_read_write_t *)args)->rd_wr);
     589    }
     590    break;
     591  default:
     592    sc = bush->ops->ioctl (bush, cmd, args);
     593    break;
     594  }
     595  if (sc < 0)
     596    rtems_libi2c_send_stop (minor);
     597  return sc;
     598}
     599
    523600static int
    524 do_s_rw (uint32_t minor, unsigned char *bytes, int nbytes, int rw)
     601do_s_rw (rtems_device_minor_number minor,
     602         unsigned char *bytes,
     603         int nbytes,
     604         int rw)
    525605{
    526606  rtems_status_code sc;
     
    550630
    551631int
    552 rtems_libi2c_start_read_bytes (uint32_t minor, unsigned char *bytes,
     632rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
     633                               unsigned char *bytes,
    553634                               int nbytes)
    554635{
     
    557638
    558639int
    559 rtems_libi2c_start_write_bytes (uint32_t minor, unsigned char *bytes,
     640rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
     641                                unsigned char *bytes,
    560642                                int nbytes)
    561643{
  • cpukit/libi2c/libi2c.h

    r0a23c714 r55a685b  
    4747 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
    4848 */
     49
    4950#include <rtems.h>
    5051
     
    102103  int (*write_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes,
    103104                      int nbytes);
     105  /* ioctl misc functions */
     106  int (*ioctl) (rtems_libi2c_bus_t * bushdl,
     107                int   cmd,
     108                void *buffer;
     109                );
    104110} rtems_libi2c_bus_ops_t;
    105111
     
    266272/* Send start, send address and read bytes */
    267273int
    268 rtems_libi2c_start_read_bytes (uint32_t minor, unsigned char *bytes,
     274rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
     275                               unsigned char *bytes,
    269276                               int nbytes);
    270277
    271278/* Send start, send address and write bytes */
    272279int
    273 rtems_libi2c_start_write_bytes (uint32_t minor, unsigned char *bytes,
     280rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
     281                                unsigned char *bytes,
    274282                                int nbytes);
     283
     284
     285/* call misc iocontrol function */
     286int
     287rtems_libi2c_ioctl (rtems_device_minor_number minor,
     288                    int cmd,
     289                    ...);
     290/*
     291 * NOTE: any low-level driver ioctl returning a negative
     292 * result for release the bus (perform a STOP condition)
     293 */
     294/*******************************
     295 * defined IOCTLs:
     296 *******************************/
     297#define RTEMS_LIBI2C_IOCTL_READ_WRITE  1
     298/*
     299 * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
     300 *                             RTEMS_LIBI2C_IOCTL_READ_WRITE,
     301 *                              rtems_libi2c_read_write_t *arg);
     302 *
     303 * This call performs a simultanous read/write transfer,
     304 * which is possible (and sometimes needed) for SPI devices
     305 *
     306 *   arg is a pointer to a rd_wr info data structure
     307 *
     308 * This call is only needed for SPI devices
     309 */
     310#define RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE  2
     311/*
     312 * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
     313 *                             RTEMS_LIBI2C_IOCTL_START_READ_WRITE,
     314 *                             unsigned char *rd_buffer,
     315 *                             const unsigned char *wr_buffer,
     316 *                             int byte_cnt,
     317 *                             const rtems_libi2c_tfr_mode_t *tfr_mode_ptr);
     318 *
     319 * This call addresses a slave and then:
     320 * - sets the proper transfer mode,
     321 *  - performs a simultanous  read/write transfer,
     322 *    (which is possible and sometimes needed for SPI devices)
     323 *    NOTE: - if rd_buffer is NULL, receive data will be dropped
     324 *          - if wr_buffer is NULL, bytes with content 0 will transmitted
     325 *
     326 *   rd_buffer is a pointer to a receive buffer (or NULL)
     327 *   wr_buffer is a pointer to the data to be sent (or NULL)
     328 *
     329 * This call is only needed for SPI devices
     330 */
     331
     332#define RTEMS_LIBI2C_IOCTL_SET_TFRMODE 3
     333/*
     334 * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
     335 *                             RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
     336 *                             const rtems_libi2c_tfr_mode_t *tfr_mode_ptr);
     337 *
     338 * This call sets an SPI device to the transfer mode needed (baudrate etc.)
     339 *
     340 *   tfr_mode is a pointer to a structure defining the SPI transfer mode needed
     341 *   (see below).
     342 *
     343 * This call is only needed for SPI devices
     344 */
     345
     346/*
     347 * arguemtn data structures for IOCTLs defined above
     348 */
     349typedef struct {
     350  unsigned char       *rd_buf;
     351  const unsigned char *wr_buf;
     352  int                  byte_cnt;
     353} rtems_libi2c_read_write_t;
     354
     355typedef struct {
     356  uint32_t baudrate;       /* maximum bits per second               */
     357                           /* only valid for SPI drivers:           */
     358  uint8_t  bits_per_char;  /* how many bits per byte/word/longword? */
     359  boolean  lsb_first;      /* TRUE: send LSB first                  */
     360  boolean  clock_inv;      /* TRUE: inverted clock (high active)    */
     361  boolean  clock_phs;      /* TRUE: clock starts toggling at start of data tfr */
     362} rtems_libi2c_tfr_mode_t;
     363
     364typedef struct {
     365  rtems_libi2c_tfr_mode_t   tfr_mode;
     366  rtems_libi2c_read_write_t rd_wr;
     367} rtems_libi2c_tfm_read_write_t;
     368
    275369
    276370#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.