spi.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**********************************************************************
  2. ***********************************************************************
  3. * Software that is described herein is for illustrative purposes only
  4. * which provides customers with programming information regarding the
  5. * products. This software is supplied "AS IS" without any warranties.
  6. * NXP Semiconductors assumes no responsibility or liability for the
  7. * use of the software, conveys no license or title under any patent,
  8. * copyright, or mask work right to the product. NXP Semiconductors
  9. * reserves the right to make changes in the software without
  10. * notification. NXP Semiconductors also make no representation or
  11. * warranty that such application will be suitable for the specified
  12. * use without further testing or modification.
  13. * Permission to use, copy, modify, and distribute this software and its
  14. * documentation is hereby granted, under NXP Semiconductors�
  15. * relevant copyright in the software, without fee, provided that it
  16. * is used in conjunction with NXP Semiconductors microcontrollers. This
  17. * copyright, permission, and disclaimer notice must appear in all copies of
  18. * this code.
  19. **********************************************************************/
  20. #ifndef lpc8xx_SPI_H_
  21. #define lpc8xx_SPI_H_
  22. #include "LPC8xx.h"
  23. #include "swm.h"
  24. #define SPI_FLASH_CS1() (LPC_GPIO_PORT->SET[0] = 1<<P0_16) /* Use for LPC804 */
  25. #define SPI_FLASH_CS0() (LPC_GPIO_PORT->CLR[0] = 1<<P0_16) /* Use for LPC804 */
  26. #define DATA_WIDTH 8
  27. #define DUMMY_BYTE 0x55
  28. #define BUFFER_SIZE 64
  29. #define LPC_SPI0BAUDRate 500000
  30. #define SPI_CFG_ENABLE (1 << 0)
  31. #define SPI_CFG_MASTER (1 << 2)
  32. #define SPI_CFG_SLAVE (0 << 2)
  33. #define SPI_CFG_LSBF (1 << 3)
  34. #define SPI_CFG_CPHA (1 << 4)
  35. #define SPI_CFG_CPOL (1 << 5)
  36. #define SPI_CFG_MOSIDRV (1 << 6)
  37. #define SPI_CFG_LOOPBACK (1 << 7)
  38. #define SPI_CFG_SPOL (1<<8)
  39. //#define SPI_CFG_SPOL(s) (1 << (8 + s))
  40. #define SPI_DLY_PREDELAY(d) ((d) << 0)
  41. #define SPI_DLY_POSTDELAY(d) ((d) << 4)
  42. #define SPI_DLY_FRAMEDELAY(d) ((d) << 8)
  43. #define SPI_DLY_INTERDELAY(d) ((d) << 12)
  44. #define SPI_STAT_RXRDY (1 << 0)
  45. #define SPI_STAT_TXRDY (1 << 1)
  46. #define SPI_STAT_RXOVERRUN (1 << 2)
  47. #define SPI_STAT_TXUNDERRUN (1 << 3)
  48. #define SPI_STAT_SELNASSERT (1 << 4)
  49. #define SPI_STAT_SELNDEASSERT (1 << 5)
  50. #define SPI_STAT_CLKSTALL (1 << 6)
  51. #define SPI_STAT_ET (1 << 7)
  52. #define SPI_STAT_MSTIDLE (1<<8)
  53. #define SPI_STAT_ERROR_MASK (SPI_STAT_RXOVERRUN|SPI_STAT_TXUNDERRUN|SPI_STAT_SELNASSERT|SPI_STAT_SELNDEASSERT|SPI_STAT_CLKSTALL)
  54. #define SPI_RXRDYEN (1<<0)
  55. #define SPI_TXRDYEN (1<<1)
  56. #define SPI_RXOVEN (1<<2)
  57. #define SPI_TXUREN (1<<3)
  58. #define SPI_SSAEN (1<<4)
  59. #define SPI_SSDEN (1<<5)
  60. #define SPI_RXRDY (1<<0)
  61. #define SPI_TXRDY (1<<1)
  62. #define SPI_RXOV (1<<2)
  63. #define SPI_TXUR (1<<3)
  64. #define SPI_SSA (1<<4)
  65. #define SPI_SSD (1<<5)
  66. #define SPI_CTL_TXSSELN (1<<16)
  67. #define SPI_CTL_EOT (1<<20)
  68. #define SPI_CTL_EOF (1<<21)
  69. #define SPI_CTL_RXIGNORE (1<<22)
  70. #define SPI_CTL_LEN(b) (((b)-1)<<24)
  71. #define SPI_TXDATCTL_SSELN(s) (s << 16)
  72. #define SPI_TXDATCTL_EOT (1 << 20)
  73. #define SPI_TXDATCTL_EOF (1 << 21)
  74. #define SPI_TXDATCTL_RX_IGNORE (1 << 22)
  75. #define SPI_TXDATCTL_FSIZE(s) ((s) << 24)
  76. #define SPI_RXDAT_SOT (1 << 20)
  77. void SPI0_IRQHandler(void);
  78. void SPImasterWriteOnly( uint8_t *WrBuf, uint32_t WrLen );
  79. void SPImasterWriteRead( uint8_t *WrBuf, uint8_t *RdBuf, uint32_t WrLen );
  80. void SPImasterReadOnly( uint8_t *RdBuf, uint32_t RdLen );
  81. #endif /* lpc8xx_SPI_H_ */