These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
SPI/sc16is750_int/spi_interrupt_test.c@0:bf7b9fba3924, 2011-03-20 (annotated)
- Committer:
- frank26080115
- Date:
- Sun Mar 20 05:38:56 2011 +0000
- Revision:
- 0:bf7b9fba3924
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frank26080115 | 0:bf7b9fba3924 | 1 | /***********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 2 | * @file spi_interrupt_test.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * @purpose This example describes how to use SPI at mode SPI master/8bit |
frank26080115 | 0:bf7b9fba3924 | 4 | * on LPC1768 to communicate with SC16IS750/760 Demo board |
frank26080115 | 0:bf7b9fba3924 | 5 | * in interrupt mode |
frank26080115 | 0:bf7b9fba3924 | 6 | * @version 2.0 |
frank26080115 | 0:bf7b9fba3924 | 7 | * @date 21. May. 2010 |
frank26080115 | 0:bf7b9fba3924 | 8 | * @author NXP MCU SW Application Team |
frank26080115 | 0:bf7b9fba3924 | 9 | *--------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 10 | * Software that is described herein is for illustrative purposes only |
frank26080115 | 0:bf7b9fba3924 | 11 | * which provides customers with programming information regarding the |
frank26080115 | 0:bf7b9fba3924 | 12 | * products. This software is supplied "AS IS" without any warranties. |
frank26080115 | 0:bf7b9fba3924 | 13 | * NXP Semiconductors assumes no responsibility or liability for the |
frank26080115 | 0:bf7b9fba3924 | 14 | * use of the software, conveys no license or title under any patent, |
frank26080115 | 0:bf7b9fba3924 | 15 | * copyright, or mask work right to the product. NXP Semiconductors |
frank26080115 | 0:bf7b9fba3924 | 16 | * reserves the right to make changes in the software without |
frank26080115 | 0:bf7b9fba3924 | 17 | * notification. NXP Semiconductors also make no representation or |
frank26080115 | 0:bf7b9fba3924 | 18 | * warranty that such application will be suitable for the specified |
frank26080115 | 0:bf7b9fba3924 | 19 | * use without further testing or modification. |
frank26080115 | 0:bf7b9fba3924 | 20 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "lpc17xx_spi.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:bf7b9fba3924 | 23 | #include "lpc17xx_pinsel.h" |
frank26080115 | 0:bf7b9fba3924 | 24 | #include "debug_frmwrk.h" |
frank26080115 | 0:bf7b9fba3924 | 25 | #include "lpc17xx_gpio.h" |
frank26080115 | 0:bf7b9fba3924 | 26 | |
frank26080115 | 0:bf7b9fba3924 | 27 | /* Example group ----------------------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 28 | /** @defgroup SPI_sc16is750_int sc16is750_int |
frank26080115 | 0:bf7b9fba3924 | 29 | * @ingroup SPI_Examples |
frank26080115 | 0:bf7b9fba3924 | 30 | * @{ |
frank26080115 | 0:bf7b9fba3924 | 31 | */ |
frank26080115 | 0:bf7b9fba3924 | 32 | |
frank26080115 | 0:bf7b9fba3924 | 33 | /************************** PRIVATE DEFINTIONS *********************/ |
frank26080115 | 0:bf7b9fba3924 | 34 | // PORT number that /CS pin assigned on |
frank26080115 | 0:bf7b9fba3924 | 35 | #define CS_PORT_NUM 0 |
frank26080115 | 0:bf7b9fba3924 | 36 | // PIN number that /CS pin assigned on |
frank26080115 | 0:bf7b9fba3924 | 37 | #define CS_PIN_NUM 16 |
frank26080115 | 0:bf7b9fba3924 | 38 | |
frank26080115 | 0:bf7b9fba3924 | 39 | /* Idle char */ |
frank26080115 | 0:bf7b9fba3924 | 40 | #define IDLE_CHAR 0xFF |
frank26080115 | 0:bf7b9fba3924 | 41 | |
frank26080115 | 0:bf7b9fba3924 | 42 | // Define macro used in command when using SPI with SC16IS740 |
frank26080115 | 0:bf7b9fba3924 | 43 | #define SC16IS740_WR_CMD(x) ((uint8_t) (x << 3)) |
frank26080115 | 0:bf7b9fba3924 | 44 | #define SC16IS740_RD_CMD(x) ((uint8_t) ((x << 3) | 0x80)) |
frank26080115 | 0:bf7b9fba3924 | 45 | |
frank26080115 | 0:bf7b9fba3924 | 46 | // Define register address of SC16IS740 |
frank26080115 | 0:bf7b9fba3924 | 47 | #define SC16IS740_IODIR_REG 0x0A |
frank26080115 | 0:bf7b9fba3924 | 48 | #define SC16IS740_IOSTATE_REG 0x0B |
frank26080115 | 0:bf7b9fba3924 | 49 | #define SC16IS740_IOCON_REG 0x0E |
frank26080115 | 0:bf7b9fba3924 | 50 | |
frank26080115 | 0:bf7b9fba3924 | 51 | /************************** PRIVATE VARIABLES *************************/ |
frank26080115 | 0:bf7b9fba3924 | 52 | uint8_t menu1[] = |
frank26080115 | 0:bf7b9fba3924 | 53 | "********************************************************************************\n\r" |
frank26080115 | 0:bf7b9fba3924 | 54 | "Hello NXP Semiconductors \n\r" |
frank26080115 | 0:bf7b9fba3924 | 55 | "SPI demo \n\r" |
frank26080115 | 0:bf7b9fba3924 | 56 | "\t - MCU: LPC17xx \n\r" |
frank26080115 | 0:bf7b9fba3924 | 57 | "\t - Core: ARM Cortex-M3 \n\r" |
frank26080115 | 0:bf7b9fba3924 | 58 | "\t - Communicate via: UART0 - 115200bps \n\r" |
frank26080115 | 0:bf7b9fba3924 | 59 | " Communicate with SPI function on SC16IS750/760 Demo Board\n\r" |
frank26080115 | 0:bf7b9fba3924 | 60 | " Use IO function on SC16IS740/750/760 chip to turn ON/OFF LEDs\n\r" |
frank26080115 | 0:bf7b9fba3924 | 61 | "Press '1' to turn ON LEDs, '2' to turn OFF LEDs \n\r" |
frank26080115 | 0:bf7b9fba3924 | 62 | "********************************************************************************\n\r"; |
frank26080115 | 0:bf7b9fba3924 | 63 | uint8_t menu2[] = "Demo terminated! \n\r"; |
frank26080115 | 0:bf7b9fba3924 | 64 | |
frank26080115 | 0:bf7b9fba3924 | 65 | uint8_t iocon_cfg[2] = {SC16IS740_WR_CMD(SC16IS740_IOCON_REG), 0x00}; |
frank26080115 | 0:bf7b9fba3924 | 66 | uint8_t iodir_cfg[2] = {SC16IS740_WR_CMD(SC16IS740_IODIR_REG), 0xFF}; |
frank26080115 | 0:bf7b9fba3924 | 67 | uint8_t iostate_on[2] = {SC16IS740_WR_CMD(SC16IS740_IOSTATE_REG), 0x00}; |
frank26080115 | 0:bf7b9fba3924 | 68 | uint8_t iostate_off[2] = {SC16IS740_WR_CMD(SC16IS740_IOSTATE_REG), 0xFF}; |
frank26080115 | 0:bf7b9fba3924 | 69 | uint8_t spireadbuf[2]; |
frank26080115 | 0:bf7b9fba3924 | 70 | |
frank26080115 | 0:bf7b9fba3924 | 71 | /* Status Flag indicates current SPI transmission complete or not */ |
frank26080115 | 0:bf7b9fba3924 | 72 | __IO FlagStatus complete; |
frank26080115 | 0:bf7b9fba3924 | 73 | |
frank26080115 | 0:bf7b9fba3924 | 74 | // SPI Configuration structure variable |
frank26080115 | 0:bf7b9fba3924 | 75 | SPI_CFG_Type SPI_ConfigStruct; |
frank26080115 | 0:bf7b9fba3924 | 76 | // SPI Data Setup structure variable |
frank26080115 | 0:bf7b9fba3924 | 77 | SPI_DATA_SETUP_Type xferConfig; |
frank26080115 | 0:bf7b9fba3924 | 78 | |
frank26080115 | 0:bf7b9fba3924 | 79 | |
frank26080115 | 0:bf7b9fba3924 | 80 | /************************** PRIVATE FUNCTIONS *************************/ |
frank26080115 | 0:bf7b9fba3924 | 81 | void SPI_IRQHandler(void); |
frank26080115 | 0:bf7b9fba3924 | 82 | |
frank26080115 | 0:bf7b9fba3924 | 83 | void CS_Init(void); |
frank26080115 | 0:bf7b9fba3924 | 84 | void CS_Force(int32_t state); |
frank26080115 | 0:bf7b9fba3924 | 85 | void print_menu(void); |
frank26080115 | 0:bf7b9fba3924 | 86 | |
frank26080115 | 0:bf7b9fba3924 | 87 | /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 88 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 89 | * @brief SPI Interrupt used for reading and writing handler |
frank26080115 | 0:bf7b9fba3924 | 90 | * @param None |
frank26080115 | 0:bf7b9fba3924 | 91 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 92 | ***********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 93 | void SPI_IRQHandler(void) |
frank26080115 | 0:bf7b9fba3924 | 94 | { |
frank26080115 | 0:bf7b9fba3924 | 95 | SPI_DATA_SETUP_Type *xf_setup; |
frank26080115 | 0:bf7b9fba3924 | 96 | uint16_t tmp; |
frank26080115 | 0:bf7b9fba3924 | 97 | uint8_t dataword; |
frank26080115 | 0:bf7b9fba3924 | 98 | |
frank26080115 | 0:bf7b9fba3924 | 99 | xf_setup = &xferConfig; |
frank26080115 | 0:bf7b9fba3924 | 100 | |
frank26080115 | 0:bf7b9fba3924 | 101 | if(SPI_GetDataSize(LPC_SPI) == 8) |
frank26080115 | 0:bf7b9fba3924 | 102 | dataword = 0; |
frank26080115 | 0:bf7b9fba3924 | 103 | else dataword = 1; |
frank26080115 | 0:bf7b9fba3924 | 104 | |
frank26080115 | 0:bf7b9fba3924 | 105 | /* Dummy read to clear SPI interrupt flag */ |
frank26080115 | 0:bf7b9fba3924 | 106 | SPI_ClearIntPending(LPC_SPI); |
frank26080115 | 0:bf7b9fba3924 | 107 | |
frank26080115 | 0:bf7b9fba3924 | 108 | // save status |
frank26080115 | 0:bf7b9fba3924 | 109 | tmp = SPI_GetStatus(LPC_SPI); |
frank26080115 | 0:bf7b9fba3924 | 110 | xf_setup->status = tmp; |
frank26080115 | 0:bf7b9fba3924 | 111 | // Check for error |
frank26080115 | 0:bf7b9fba3924 | 112 | if (tmp & (SPI_SPSR_ABRT | SPI_SPSR_MODF | SPI_SPSR_ROVR | SPI_SPSR_WCOL)){ |
frank26080115 | 0:bf7b9fba3924 | 113 | xf_setup->status |= SPI_STAT_ERROR; |
frank26080115 | 0:bf7b9fba3924 | 114 | // Disable Interrupt and call call-back |
frank26080115 | 0:bf7b9fba3924 | 115 | SPI_IntCmd(LPC_SPI, DISABLE); |
frank26080115 | 0:bf7b9fba3924 | 116 | // Set Complete Flag |
frank26080115 | 0:bf7b9fba3924 | 117 | complete = SET; |
frank26080115 | 0:bf7b9fba3924 | 118 | return; |
frank26080115 | 0:bf7b9fba3924 | 119 | } |
frank26080115 | 0:bf7b9fba3924 | 120 | |
frank26080115 | 0:bf7b9fba3924 | 121 | /* Check SPI complete flag */ |
frank26080115 | 0:bf7b9fba3924 | 122 | if (tmp & SPI_SPSR_SPIF){ |
frank26080115 | 0:bf7b9fba3924 | 123 | // Read data from SPI data |
frank26080115 | 0:bf7b9fba3924 | 124 | tmp = SPI_ReceiveData(LPC_SPI); |
frank26080115 | 0:bf7b9fba3924 | 125 | if (xf_setup->rx_data != NULL) |
frank26080115 | 0:bf7b9fba3924 | 126 | { |
frank26080115 | 0:bf7b9fba3924 | 127 | if (dataword == 0){ |
frank26080115 | 0:bf7b9fba3924 | 128 | *(uint8_t *)((uint8_t *)(xf_setup->rx_data) + xf_setup->counter) = (uint8_t) tmp; |
frank26080115 | 0:bf7b9fba3924 | 129 | } else { |
frank26080115 | 0:bf7b9fba3924 | 130 | *(uint16_t *)((uint8_t *)(xf_setup->rx_data) + xf_setup->counter) = (uint8_t) tmp; |
frank26080115 | 0:bf7b9fba3924 | 131 | } |
frank26080115 | 0:bf7b9fba3924 | 132 | } |
frank26080115 | 0:bf7b9fba3924 | 133 | // Increase counter |
frank26080115 | 0:bf7b9fba3924 | 134 | if (dataword == 0){ |
frank26080115 | 0:bf7b9fba3924 | 135 | xf_setup->counter++; |
frank26080115 | 0:bf7b9fba3924 | 136 | } else { |
frank26080115 | 0:bf7b9fba3924 | 137 | xf_setup->counter += 2; |
frank26080115 | 0:bf7b9fba3924 | 138 | } |
frank26080115 | 0:bf7b9fba3924 | 139 | } |
frank26080115 | 0:bf7b9fba3924 | 140 | |
frank26080115 | 0:bf7b9fba3924 | 141 | if (xf_setup->counter < xf_setup->length){ |
frank26080115 | 0:bf7b9fba3924 | 142 | // Write data to buffer |
frank26080115 | 0:bf7b9fba3924 | 143 | if(xf_setup->tx_data == NULL){ |
frank26080115 | 0:bf7b9fba3924 | 144 | if (dataword == 0){ |
frank26080115 | 0:bf7b9fba3924 | 145 | SPI_SendData(LPC_SPI, 0xFF); |
frank26080115 | 0:bf7b9fba3924 | 146 | } else { |
frank26080115 | 0:bf7b9fba3924 | 147 | SPI_SendData(LPC_SPI, 0xFFFF); |
frank26080115 | 0:bf7b9fba3924 | 148 | } |
frank26080115 | 0:bf7b9fba3924 | 149 | } else { |
frank26080115 | 0:bf7b9fba3924 | 150 | if (dataword == 0){ |
frank26080115 | 0:bf7b9fba3924 | 151 | SPI_SendData(LPC_SPI, (*(uint8_t *)((uint8_t *)(xf_setup->tx_data) + xf_setup->counter))); |
frank26080115 | 0:bf7b9fba3924 | 152 | } else { |
frank26080115 | 0:bf7b9fba3924 | 153 | SPI_SendData(LPC_SPI, (*(uint16_t *)((uint8_t *)(xf_setup->tx_data) + xf_setup->counter))); |
frank26080115 | 0:bf7b9fba3924 | 154 | } |
frank26080115 | 0:bf7b9fba3924 | 155 | } |
frank26080115 | 0:bf7b9fba3924 | 156 | } |
frank26080115 | 0:bf7b9fba3924 | 157 | // No more data to send |
frank26080115 | 0:bf7b9fba3924 | 158 | else { |
frank26080115 | 0:bf7b9fba3924 | 159 | xf_setup->status |= SPI_STAT_DONE; |
frank26080115 | 0:bf7b9fba3924 | 160 | // Disable Interrupt and call call-back |
frank26080115 | 0:bf7b9fba3924 | 161 | SPI_IntCmd(LPC_SPI, DISABLE); |
frank26080115 | 0:bf7b9fba3924 | 162 | // Set Complete Flag |
frank26080115 | 0:bf7b9fba3924 | 163 | complete = SET; |
frank26080115 | 0:bf7b9fba3924 | 164 | } |
frank26080115 | 0:bf7b9fba3924 | 165 | } |
frank26080115 | 0:bf7b9fba3924 | 166 | |
frank26080115 | 0:bf7b9fba3924 | 167 | /*-------------------------PRIVATE FUNCTIONS------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 168 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 169 | * @brief Initialize CS pin as GPIO function to drive /CS pin |
frank26080115 | 0:bf7b9fba3924 | 170 | * due to definition of CS_PORT_NUM and CS_PORT_NUM |
frank26080115 | 0:bf7b9fba3924 | 171 | * @param None |
frank26080115 | 0:bf7b9fba3924 | 172 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 173 | ***********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 174 | void CS_Init(void) |
frank26080115 | 0:bf7b9fba3924 | 175 | { |
frank26080115 | 0:bf7b9fba3924 | 176 | GPIO_SetDir(CS_PORT_NUM, (1<<CS_PIN_NUM), 1); |
frank26080115 | 0:bf7b9fba3924 | 177 | GPIO_SetValue(CS_PORT_NUM, (1<<CS_PIN_NUM)); |
frank26080115 | 0:bf7b9fba3924 | 178 | } |
frank26080115 | 0:bf7b9fba3924 | 179 | |
frank26080115 | 0:bf7b9fba3924 | 180 | |
frank26080115 | 0:bf7b9fba3924 | 181 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 182 | * @brief Drive CS output pin to low/high level to select slave device |
frank26080115 | 0:bf7b9fba3924 | 183 | * via /CS pin state |
frank26080115 | 0:bf7b9fba3924 | 184 | * @param[in] state State of CS output pin that will be driven: |
frank26080115 | 0:bf7b9fba3924 | 185 | * - 0: Drive CS pin to low level |
frank26080115 | 0:bf7b9fba3924 | 186 | * - 1: Drive CS pin to high level |
frank26080115 | 0:bf7b9fba3924 | 187 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 188 | ***********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 189 | void CS_Force(int32_t state) |
frank26080115 | 0:bf7b9fba3924 | 190 | { |
frank26080115 | 0:bf7b9fba3924 | 191 | if (state){ |
frank26080115 | 0:bf7b9fba3924 | 192 | GPIO_SetValue(CS_PORT_NUM, (1<<CS_PIN_NUM)); |
frank26080115 | 0:bf7b9fba3924 | 193 | }else{ |
frank26080115 | 0:bf7b9fba3924 | 194 | GPIO_ClearValue(CS_PORT_NUM, (1<<CS_PIN_NUM)); |
frank26080115 | 0:bf7b9fba3924 | 195 | } |
frank26080115 | 0:bf7b9fba3924 | 196 | } |
frank26080115 | 0:bf7b9fba3924 | 197 | |
frank26080115 | 0:bf7b9fba3924 | 198 | |
frank26080115 | 0:bf7b9fba3924 | 199 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 200 | * @brief Print Welcome menu |
frank26080115 | 0:bf7b9fba3924 | 201 | * @param[in] none |
frank26080115 | 0:bf7b9fba3924 | 202 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 203 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 204 | void print_menu(void) |
frank26080115 | 0:bf7b9fba3924 | 205 | { |
frank26080115 | 0:bf7b9fba3924 | 206 | _DBG(menu1); |
frank26080115 | 0:bf7b9fba3924 | 207 | } |
frank26080115 | 0:bf7b9fba3924 | 208 | |
frank26080115 | 0:bf7b9fba3924 | 209 | /*-------------------------MAIN FUNCTION------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 210 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 211 | * @brief c_entry: Main SPI program body |
frank26080115 | 0:bf7b9fba3924 | 212 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 213 | * @return int |
frank26080115 | 0:bf7b9fba3924 | 214 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 215 | int c_entry(void) |
frank26080115 | 0:bf7b9fba3924 | 216 | { |
frank26080115 | 0:bf7b9fba3924 | 217 | uint8_t tmpchar[2] = {0, 0}; |
frank26080115 | 0:bf7b9fba3924 | 218 | PINSEL_CFG_Type PinCfg; |
frank26080115 | 0:bf7b9fba3924 | 219 | __IO FlagStatus exitflag; |
frank26080115 | 0:bf7b9fba3924 | 220 | |
frank26080115 | 0:bf7b9fba3924 | 221 | /* |
frank26080115 | 0:bf7b9fba3924 | 222 | * Initialize SPI pin connect |
frank26080115 | 0:bf7b9fba3924 | 223 | * P0.15 - SCK; |
frank26080115 | 0:bf7b9fba3924 | 224 | * P0.16 - SSEL - used as GPIO |
frank26080115 | 0:bf7b9fba3924 | 225 | * P0.17 - MISO |
frank26080115 | 0:bf7b9fba3924 | 226 | * P0.18 - MOSI |
frank26080115 | 0:bf7b9fba3924 | 227 | */ |
frank26080115 | 0:bf7b9fba3924 | 228 | PinCfg.Funcnum = 3; |
frank26080115 | 0:bf7b9fba3924 | 229 | PinCfg.OpenDrain = 0; |
frank26080115 | 0:bf7b9fba3924 | 230 | PinCfg.Pinmode = 0; |
frank26080115 | 0:bf7b9fba3924 | 231 | PinCfg.Portnum = 0; |
frank26080115 | 0:bf7b9fba3924 | 232 | PinCfg.Pinnum = 15; |
frank26080115 | 0:bf7b9fba3924 | 233 | PINSEL_ConfigPin(&PinCfg); |
frank26080115 | 0:bf7b9fba3924 | 234 | PinCfg.Pinnum = 17; |
frank26080115 | 0:bf7b9fba3924 | 235 | PINSEL_ConfigPin(&PinCfg); |
frank26080115 | 0:bf7b9fba3924 | 236 | PinCfg.Pinnum = 18; |
frank26080115 | 0:bf7b9fba3924 | 237 | PINSEL_ConfigPin(&PinCfg); |
frank26080115 | 0:bf7b9fba3924 | 238 | PinCfg.Pinnum = 16; |
frank26080115 | 0:bf7b9fba3924 | 239 | PinCfg.Funcnum = 0; |
frank26080115 | 0:bf7b9fba3924 | 240 | PINSEL_ConfigPin(&PinCfg); |
frank26080115 | 0:bf7b9fba3924 | 241 | |
frank26080115 | 0:bf7b9fba3924 | 242 | /* Initialize debug via UART0 |
frank26080115 | 0:bf7b9fba3924 | 243 | * 115200bps |
frank26080115 | 0:bf7b9fba3924 | 244 | * 8 data bit |
frank26080115 | 0:bf7b9fba3924 | 245 | * No parity |
frank26080115 | 0:bf7b9fba3924 | 246 | * 1 stop bit |
frank26080115 | 0:bf7b9fba3924 | 247 | * No flow control |
frank26080115 | 0:bf7b9fba3924 | 248 | */ |
frank26080115 | 0:bf7b9fba3924 | 249 | debug_frmwrk_init(); |
frank26080115 | 0:bf7b9fba3924 | 250 | |
frank26080115 | 0:bf7b9fba3924 | 251 | // print welcome screen |
frank26080115 | 0:bf7b9fba3924 | 252 | print_menu(); |
frank26080115 | 0:bf7b9fba3924 | 253 | |
frank26080115 | 0:bf7b9fba3924 | 254 | // initialize SPI configuration structure to default |
frank26080115 | 0:bf7b9fba3924 | 255 | SPI_ConfigStructInit(&SPI_ConfigStruct); |
frank26080115 | 0:bf7b9fba3924 | 256 | // Initialize SPI peripheral with parameter given in structure above |
frank26080115 | 0:bf7b9fba3924 | 257 | SPI_Init(LPC_SPI, &SPI_ConfigStruct); |
frank26080115 | 0:bf7b9fba3924 | 258 | |
frank26080115 | 0:bf7b9fba3924 | 259 | // Initialize /CS pin to GPIO function |
frank26080115 | 0:bf7b9fba3924 | 260 | CS_Init(); |
frank26080115 | 0:bf7b9fba3924 | 261 | |
frank26080115 | 0:bf7b9fba3924 | 262 | /* preemption = 1, sub-priority = 1 */ |
frank26080115 | 0:bf7b9fba3924 | 263 | NVIC_SetPriority(SPI_IRQn, ((0x01<<3)|0x01)); |
frank26080115 | 0:bf7b9fba3924 | 264 | /* Enable SSP0 interrupt */ |
frank26080115 | 0:bf7b9fba3924 | 265 | NVIC_EnableIRQ(SPI_IRQn); |
frank26080115 | 0:bf7b9fba3924 | 266 | |
frank26080115 | 0:bf7b9fba3924 | 267 | /* First, send some command to reset SC16IS740 chip via SPI bus interface |
frank26080115 | 0:bf7b9fba3924 | 268 | * note driver /CS pin to low state before transferring by CS_Enable() function |
frank26080115 | 0:bf7b9fba3924 | 269 | */ |
frank26080115 | 0:bf7b9fba3924 | 270 | complete = RESET; |
frank26080115 | 0:bf7b9fba3924 | 271 | CS_Force(0); |
frank26080115 | 0:bf7b9fba3924 | 272 | xferConfig.tx_data = iocon_cfg; |
frank26080115 | 0:bf7b9fba3924 | 273 | xferConfig.rx_data = spireadbuf; |
frank26080115 | 0:bf7b9fba3924 | 274 | xferConfig.length = sizeof (iocon_cfg); |
frank26080115 | 0:bf7b9fba3924 | 275 | SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_INTERRUPT); |
frank26080115 | 0:bf7b9fba3924 | 276 | while (complete == RESET); |
frank26080115 | 0:bf7b9fba3924 | 277 | CS_Force(1); |
frank26080115 | 0:bf7b9fba3924 | 278 | |
frank26080115 | 0:bf7b9fba3924 | 279 | complete = RESET; |
frank26080115 | 0:bf7b9fba3924 | 280 | CS_Force(0); |
frank26080115 | 0:bf7b9fba3924 | 281 | xferConfig.tx_data = iodir_cfg; |
frank26080115 | 0:bf7b9fba3924 | 282 | xferConfig.rx_data = spireadbuf; |
frank26080115 | 0:bf7b9fba3924 | 283 | xferConfig.length = sizeof (iodir_cfg); |
frank26080115 | 0:bf7b9fba3924 | 284 | SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_INTERRUPT); |
frank26080115 | 0:bf7b9fba3924 | 285 | while (complete == RESET); |
frank26080115 | 0:bf7b9fba3924 | 286 | CS_Force(1); |
frank26080115 | 0:bf7b9fba3924 | 287 | |
frank26080115 | 0:bf7b9fba3924 | 288 | // Reset exit flag |
frank26080115 | 0:bf7b9fba3924 | 289 | exitflag = RESET; |
frank26080115 | 0:bf7b9fba3924 | 290 | |
frank26080115 | 0:bf7b9fba3924 | 291 | // Start to use SPI polling mode |
frank26080115 | 0:bf7b9fba3924 | 292 | /* Read some data from the buffer */ |
frank26080115 | 0:bf7b9fba3924 | 293 | while (exitflag == RESET) |
frank26080115 | 0:bf7b9fba3924 | 294 | { |
frank26080115 | 0:bf7b9fba3924 | 295 | while((tmpchar[0] = _DG) == 0); |
frank26080115 | 0:bf7b9fba3924 | 296 | |
frank26080115 | 0:bf7b9fba3924 | 297 | if (tmpchar[0] == 27){ |
frank26080115 | 0:bf7b9fba3924 | 298 | /* ESC key, set exit flag */ |
frank26080115 | 0:bf7b9fba3924 | 299 | _DBG_(menu2); |
frank26080115 | 0:bf7b9fba3924 | 300 | exitflag = SET; |
frank26080115 | 0:bf7b9fba3924 | 301 | } |
frank26080115 | 0:bf7b9fba3924 | 302 | else if (tmpchar[0] == 'r'){ |
frank26080115 | 0:bf7b9fba3924 | 303 | print_menu(); |
frank26080115 | 0:bf7b9fba3924 | 304 | } else { |
frank26080115 | 0:bf7b9fba3924 | 305 | if (tmpchar[0] == '1') |
frank26080115 | 0:bf7b9fba3924 | 306 | { |
frank26080115 | 0:bf7b9fba3924 | 307 | // LEDs are ON now... |
frank26080115 | 0:bf7b9fba3924 | 308 | CS_Force(0); |
frank26080115 | 0:bf7b9fba3924 | 309 | xferConfig.tx_data = iostate_on; |
frank26080115 | 0:bf7b9fba3924 | 310 | xferConfig.rx_data = spireadbuf; |
frank26080115 | 0:bf7b9fba3924 | 311 | xferConfig.length = sizeof (iostate_on); |
frank26080115 | 0:bf7b9fba3924 | 312 | SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); |
frank26080115 | 0:bf7b9fba3924 | 313 | CS_Force(1); |
frank26080115 | 0:bf7b9fba3924 | 314 | } |
frank26080115 | 0:bf7b9fba3924 | 315 | else if (tmpchar[0] == '2') |
frank26080115 | 0:bf7b9fba3924 | 316 | { |
frank26080115 | 0:bf7b9fba3924 | 317 | // LEDs are OFF now... |
frank26080115 | 0:bf7b9fba3924 | 318 | CS_Force(0); |
frank26080115 | 0:bf7b9fba3924 | 319 | xferConfig.tx_data = iostate_off; |
frank26080115 | 0:bf7b9fba3924 | 320 | xferConfig.rx_data = spireadbuf; |
frank26080115 | 0:bf7b9fba3924 | 321 | xferConfig.length = sizeof (iostate_off); |
frank26080115 | 0:bf7b9fba3924 | 322 | SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); |
frank26080115 | 0:bf7b9fba3924 | 323 | CS_Force(1); |
frank26080115 | 0:bf7b9fba3924 | 324 | } |
frank26080115 | 0:bf7b9fba3924 | 325 | /* Then Echo it back */ |
frank26080115 | 0:bf7b9fba3924 | 326 | _DBG_(tmpchar); |
frank26080115 | 0:bf7b9fba3924 | 327 | } |
frank26080115 | 0:bf7b9fba3924 | 328 | } |
frank26080115 | 0:bf7b9fba3924 | 329 | // DeInitialize UART0 peripheral |
frank26080115 | 0:bf7b9fba3924 | 330 | SPI_DeInit(LPC_SPI); |
frank26080115 | 0:bf7b9fba3924 | 331 | /* Loop forever */ |
frank26080115 | 0:bf7b9fba3924 | 332 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 333 | return 1; |
frank26080115 | 0:bf7b9fba3924 | 334 | } |
frank26080115 | 0:bf7b9fba3924 | 335 | |
frank26080115 | 0:bf7b9fba3924 | 336 | /* With ARM and GHS toolsets, the entry point is main() - this will |
frank26080115 | 0:bf7b9fba3924 | 337 | allow the linker to generate wrapper code to setup stacks, allocate |
frank26080115 | 0:bf7b9fba3924 | 338 | heap area, and initialize and copy code and data segments. For GNU |
frank26080115 | 0:bf7b9fba3924 | 339 | toolsets, the entry point is through __start() in the crt0_gnu.asm |
frank26080115 | 0:bf7b9fba3924 | 340 | file, and that startup code will setup stacks and data */ |
frank26080115 | 0:bf7b9fba3924 | 341 | int main(void) |
frank26080115 | 0:bf7b9fba3924 | 342 | { |
frank26080115 | 0:bf7b9fba3924 | 343 | return c_entry(); |
frank26080115 | 0:bf7b9fba3924 | 344 | } |
frank26080115 | 0:bf7b9fba3924 | 345 | |
frank26080115 | 0:bf7b9fba3924 | 346 | |
frank26080115 | 0:bf7b9fba3924 | 347 | #ifdef DEBUG |
frank26080115 | 0:bf7b9fba3924 | 348 | /******************************************************************************* |
frank26080115 | 0:bf7b9fba3924 | 349 | * @brief Reports the name of the source file and the source line number |
frank26080115 | 0:bf7b9fba3924 | 350 | * where the CHECK_PARAM error has occurred. |
frank26080115 | 0:bf7b9fba3924 | 351 | * @param[in] file Pointer to the source file name |
frank26080115 | 0:bf7b9fba3924 | 352 | * @param[in] line assert_param error line source number |
frank26080115 | 0:bf7b9fba3924 | 353 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 354 | *******************************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 355 | void check_failed(uint8_t *file, uint32_t line) |
frank26080115 | 0:bf7b9fba3924 | 356 | { |
frank26080115 | 0:bf7b9fba3924 | 357 | /* User can add his own implementation to report the file name and line number, |
frank26080115 | 0:bf7b9fba3924 | 358 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
frank26080115 | 0:bf7b9fba3924 | 359 | |
frank26080115 | 0:bf7b9fba3924 | 360 | /* Infinite loop */ |
frank26080115 | 0:bf7b9fba3924 | 361 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 362 | } |
frank26080115 | 0:bf7b9fba3924 | 363 | #endif |
frank26080115 | 0:bf7b9fba3924 | 364 | |
frank26080115 | 0:bf7b9fba3924 | 365 | /* |
frank26080115 | 0:bf7b9fba3924 | 366 | * @} |
frank26080115 | 0:bf7b9fba3924 | 367 | */ |