Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
249:68ed571e0002
Child:
259:341f04be325e
diff -r e156e33b8b38 -r 68ed571e0002 BLE/src/ble_spi.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE/src/ble_spi.cpp	Fri Oct 21 13:48:57 2016 +0000
@@ -0,0 +1,148 @@
+/**
+  ******************************************************************************
+  * @file    ble_uart.cpp
+  * @author  Happiesstminds Firmware Team
+  * @version v1.0
+  * @date    4-Oct-2016
+  * @brief   
+  *
+  ******************************************************************************
+  * @attention
+  *  
+  *
+  ******************************************************************************
+  */
+
+/******************************************************************************/
+/* Include Files*/
+/******************************************************************************/
+#include "mbed.h"
+
+/******************************************************************************/
+/* Local Defines                                                              */
+/******************************************************************************/
+SPI spimaster(SPI1_MOSI, SPI1_MISO, SPI1_SCK);
+DigitalOut cs(SPI1_CS);
+
+/******************************************************************************/
+/* Global Functions                                                              */
+/******************************************************************************/
+/*****************************************************************************
+ * Function:            InitSpiMaster()
+ * Description:         InitSpiMaster 
+ *
+ * @param               None
+ * @return              none
+ *****************************************************************************/
+uint8_t InitSpiMaster(void)
+{
+     uint8_t status = SUCCESS;
+    // Chip must be deselected
+    cs = 1;
+    // Setup the spi for 8 bit data, high steady state clock,
+    // second edge capture, with a 1MHz clock rate
+    spimaster.format(8, 0);
+    // spimaster.frequency(1000000);
+    spimaster.frequency(1000000);
+    return status;
+}
+
+/*****************************************************************************
+ * Function:            WriteSpiData()
+ * Description:         WriteSpiData 
+ *
+ * @param               pointer to buffer
+  * @param              length
+ * @return              none
+ *****************************************************************************/
+uint8_t WriteSpiData(uint8_t * p_buffer, uint16_t length)
+{    
+    uint8_t i;
+    uint8_t status = SUCCESS;
+    int response[20];  //need to be removed
+    // Select the device by seting chip select low    
+
+#if 0
+    for(i=0;i<length;i++)
+    {
+        printf("Array %d = 0x%x\n\r",i,p_buffer[i]);
+    }
+#endif    
+    for(i=0;i<length;i++)
+    {
+        cs = 0;
+        response[i] = spimaster.write(p_buffer[i]);
+        cs = 1;
+        wait_ms(5);
+    }    
+
+    return status;      
+}
+
+/*****************************************************************************
+ * Function:            ReadSpiData()
+ * Description:         ReadSpiData 
+ *
+ * @param               pointer to rx_buf
+ * @return              none
+ *****************************************************************************/
+uint8_t ReadSpiData(uint8_t *rx_buf)
+{    
+    uint8_t msg_len;
+    static uint8_t received_string[16];  
+    int i;
+ 
+    // Dummy read to get first garbage value
+    cs = 0;
+    rx_buf[0] = spimaster.write(0xFF);
+    cs = 1;
+    wait_ms(5);
+    
+    cs = 0;
+    rx_buf[1] = spimaster.write(0xFF);
+    cs = 1;
+    wait_ms(5);
+    
+    cs = 0;
+    rx_buf[2] = spimaster.write(0xFF);
+    cs = 1;
+    wait_ms(5);
+    
+    cs = 0;
+    rx_buf[3] = spimaster.write(0xFF);
+    cs = 1;
+    wait_ms(5);
+    
+    msg_len = rx_buf[3];
+  
+    for(i = 4; i < msg_len; i++)
+    {
+        cs = 0;
+        rx_buf[i] = spimaster.write(0xFF);
+        cs = 1;
+        wait_ms(5);
+    } 
+    
+//    spimaster.write(0xFF);
+#if 0    
+    for(i = 0; i < (msg_len); i++)
+    {
+        printf("Received Packet is 0x%X\n\r",rx_buf[i]);
+    } 
+#endif    
+    memcpy (received_string, &rx_buf[4], rx_buf[3]); 
+    
+//    printf("received_string is %s length is %d\n\r", received_string,(rx_buf[3]-5));
+//added for testing purpose.need to be removed
+    if(rx_buf[3]>0)
+    {
+        //TODO- this data will be pushed to Application layer
+        printf("received_string is %s\n\r", received_string); 
+    }
+    return (msg_len);
+    
+}
+
+/******************************************************************************/
+/* END OF FILE                                                                */
+/******************************************************************************/
\ No newline at end of file