Cubebite Publish

Dependencies:   mbed

Fork of HelloWorld_IDS01A4 by ST

Files at this revision

API Documentation at this revision

Comitter:
rosarium
Date:
Mon Jun 19 08:23:08 2017 +0000
Parent:
0:2ddc0583bcec
Child:
2:a0677b17a570
Commit message:
Updated main.cpp

Changed in this revision

X_NUCLEO_IDS01A5/Components/Common/component_def.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/X_NUCLEO_IDS01A5/Components/Common/component_def.h	Thu May 25 16:38:55 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-/**
- ******************************************************************************
- * @file    component_def.h
- * @author  AST
- * @version V1.0.0
- * @date    1 April 2015
- * @brief   Generic header file containing a generic component's definitions
- *          and I/O functions.
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *   1. Redistributions of source code must retain the above copyright notice,
- *      this list of conditions and the following disclaimer.
- *   2. Redistributions in binary form must reproduce the above copyright notice,
- *      this list of conditions and the following disclaimer in the documentation
- *      and/or other materials provided with the distribution.
- *   3. Neither the name of STMicroelectronics nor the names of its contributors
- *      may be used to endorse or promote products derived from this software
- *      without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-
-#ifndef __COMPONENT_H
-#define __COMPONENT_H
-
-
-/* Types ---------------------------------------------------------------------*/
-
-/**
- * @brief  Component's Context structure definition.
- */
-typedef struct
-{  
-    /* Identity. */
-    uint8_t who_am_i;
-
-    /* ACTION ----------------------------------------------------------------*/
-    /* There should be only a unique identifier for each component, which     */
-    /* should be the "who_am_i" parameter, hence this parameter is optional.  */
-    /* -----------------------------------------------------------------------*/
-    /* Type. */
-    uint8_t type;
-
-    /* Configuration. */
-    uint8_t address;
-
-    /* Pointer to the Data. */
-    void *p_data;
-
-    /* Pointer to the Virtual Table. */
-    void *p_vt;
-
-    /* ACTION ----------------------------------------------------------------*/
-    /* There should be only a unique virtual table for each component, which  */
-    /* should be the "p_vt" parameter, hence this parameter is optional.      */
-    /* -----------------------------------------------------------------------*/
-    /* Pointer to the Extended Virtual Table. */
-    void *p_ext_vt;
-} handle_t;
-
-/**
- * @brief  Component's Status enumerator definition.
- */
-typedef enum
-{
-    COMPONENT_OK = 0,
-    COMPONENT_ERROR,
-    COMPONENT_TIMEOUT,
-    COMPONENT_NOT_IMPLEMENTED
-} status_t;
-
-#endif /* __COMPONENT_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/main.cpp	Thu May 25 16:38:55 2017 +0000
+++ b/main.cpp	Mon Jun 19 08:23:08 2017 +0000
@@ -4,7 +4,7 @@
  * @author  Rosarium PILA, STMicroelectronics
  * @version V1.0.0
  * @date    May 17th, 2017
- * @brief   mbed HelloWorld P2P example for the STMicroelectronics X-NUCLEO-IDB01A4/5
+ * @brief   mbed Hello World test application for the STMicroelectronics X-NUCLEO-IDB01A4/5
  *          Spirit1 Expansion Board
  ******************************************************************************
  * @attention
@@ -39,69 +39,61 @@
 #include "mbed.h"
 #include "SimpleSpirit1.h"
 
-#define TEST_STR_LEN (32)  //512
+#define TEST_STR_LEN (32) 
 static uint8_t send_buf[TEST_STR_LEN] ={'S','P','I','R','I','T','1',' ','H','E','L','L','O',' ','W','O','R','L','D',' ','P','2','P',' ','D','E','M','O'};
 static uint8_t read_buf[TEST_STR_LEN] ={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
-
-#define PCKT_MARGIN (2) //32
+          
+static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); //RPi: (SPI_CLK) = (D13:PA5:resistorR7 --> D3:PB3:resistorR4)
 
-//#define SIGNAL_BIT (0x1)                                                      //RPi //Removed OS dependency for mbed classic
-//static osThreadId main_thread_id;                                             //RPi //Removed OS dependency for mbed classic
+volatile bool rx_done_flag = 0; 
+volatile bool tx_done_flag = 0; 
 
-          
-static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); //RPi
-bool SIGNAL_BIT = 0; //RPi
 static int curr_len = 0;
 unsigned char myValue = 0;
 
-InterruptIn event(USER_BUTTON);                                                 //RPi //Added interrupt event to give userinterface to send pkt.
+InterruptIn event(USER_BUTTON); //RPi : //Added interrupt event to give userinterface to send pkt.
 
+/**
+ * @brief  callback_func
+ * @param  callback event
+ * @retval None.
+ */
 static void callback_func(int event) 
 {
-	if(event == SimpleSpirit1::RX_DONE) {
-//		osSignalSet(main_thread_id, SIGNAL_BIT);                        //RPi //Removed OS dependency for mbed classic                
-          SIGNAL_BIT = 1;
-	} else if (event != SimpleSpirit1::TX_DONE) {
-		printf("Got unexpected event %d\r\n", event);
-	} else {
-		printf("TX done!\n\r\n");
-	}
+  if(event == SimpleSpirit1::RX_DONE) 
+  {              
+    rx_done_flag = 1;
+  }
+  else if (event == SimpleSpirit1::TX_DONE) 
+  {
+    tx_done_flag = 1;
+  }
 }
 
+
+/**
+ * @brief  send_data
+ * @param  None
+ * @retval None
+ */
 void send_data(void)
-{
-  int cnt = 0;
-  cnt++;
-  if(cnt >= MAX_PACKET_LEN) cnt = 0;
+{  
+  printf("\r\n***Sending a packet***\r\n");  
   
-  printf("\r\n***Sending a packet***\r\nSent string ='%s' (len=%d)\n\r", send_buf, strlen((const char*)send_buf) + 1);  
-  
-  uint32_t before_cca = us_ticker_read();
   while(myspirit.is_receiving()); // wait for ongoing RX ends
-  uint32_t after_cca = us_ticker_read();
-  
+ 
   curr_len = strlen((const char*)send_buf) + 1;
   myspirit.send(send_buf, curr_len);
-  uint32_t after_send = us_ticker_read();
-  
-  printf("CCA time: %uus\n", (unsigned int)(after_cca - before_cca));
-  printf("Send time: %uus\n\r", (unsigned int)(after_send - after_cca));
 }
-
+/**
+ * @brief  main routine
+ * @param  None
+ * @retval int
+ */
 int main() 
-{
-  //	osStatus ret;                                                           //RPi //Removed OS dependency for mbed classic
-
-  unsigned int pckts_fails = 0;
-  unsigned int first_failed_packet = 0;
-  unsigned int last_failed_packet = 0;
-  int validate_cnt = -1;
-  
-  //	main_thread_id = Thread::gettid();                                      //RPi //Removed OS dependency for mbed classic
-  
-  
-  DigitalOut TestLED = D5; //RPi //LED of IDS01A4/5
-  TestLED = 0; //RPi //LED off
+{  
+  DigitalOut TestLED = D5;      //RPi //LED of IDS01A4/5
+  TestLED = 0;                  //RPi //LED off
   
   myspirit.attach_irq_callback(callback_func);
   
@@ -110,48 +102,35 @@
   printf("\n**************HelloWorld mbed demo for Spirit1 (X-NUCLEO-IDS01A4/5)**************\r\n");
   printf("\nPress User Button on one of the two boards to send a packaet to the other and the LED D1 on the receiver X-NUCLEO-IDS01A4/5 should toggle \n\r\n");
   
+  event.rise(&send_data); //RPi: User button interrupt trigger to send data
+  
   while(1) 
   {
-    
-    event.rise(&send_data); //RPi // Added User button interrupt trigger to send data
+    __WFE(); // low power in idle condition., waiting for an event
     
-    if(SIGNAL_BIT) //RPi //Data pkt received
+    if(rx_done_flag) 
     {
-      SIGNAL_BIT = 0; 
-      
-      for(unsigned int flush_count = 0; flush_count < TEST_STR_LEN; flush_count++) read_buf[flush_count] = 0 ;//RPi//clear the read buffer
+      rx_done_flag = 0; 
+     
+      for(unsigned int flush_count = 0; flush_count < TEST_STR_LEN; flush_count++) read_buf[flush_count] = 0 ;//RPi:clear the read buffer
       
       int ret = myspirit.read(read_buf, sizeof(read_buf));
       
-      myValue = 1 - myValue; //RPi //Toggle LED at the receiver
-      TestLED = myValue;     //RPi //Toggle LED at the receiver
+      myValue = 1 - myValue; 
+      TestLED = myValue;     //RPi: Toggle LED at the receiver
       
       if(ret == 0) {
         printf("\nNothing to read\n\r");
         continue;
       }
-      int len = strlen((const char*)read_buf) + 1;
-      if(validate_cnt < 0) {
-        validate_cnt = ret;
-      } else {
-        validate_cnt++;
-        if(validate_cnt > MAX_PACKET_LEN) validate_cnt = 1;
-      }
-
-      if(ret != len) {
-        pckts_fails++;
-        if((ret > (int)(first_failed_packet + PCKT_MARGIN) || (ret < (int)(first_failed_packet - PCKT_MARGIN)))) {
-          first_failed_packet = ret;
-        }
-        last_failed_packet = ret;
-      }
-
       printf("\r\n***Received a packet***\r\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); 
-      printf("RSSI: %f, LQI: %u\r\n", myspirit.get_last_rssi_dbm(), (unsigned int)myspirit.get_last_sqi());
-      printf("Packets failed:\t%d\t(ff=%d, lf=%d)\r\n", pckts_fails, first_failed_packet, last_failed_packet);
-      
-      while(myspirit.is_receiving()); // wait for ongoing RX ends
-    } 
+    }
+    
+    else if (tx_done_flag)
+    {
+      tx_done_flag = 0;
+      printf("\r\n***Packet sent***\r\nSent string ='%s' (len=%d)\n\r", send_buf, strlen((const char*)send_buf) + 1);
+    }
   }
   
   myspirit.off();