JunMo Hong / Mbed 2 deprecated cubebite_rnd_SPSGRFC433

Dependencies:   mbed

Fork of HelloWorld_IDS01A4 by ST

Revision:
10:cc81b87e005e
Parent:
5:a65ed26b0f98
Child:
11:f8396aa48de6
diff -r baee9699401f -r cc81b87e005e main.cpp
--- a/main.cpp	Wed Sep 13 09:21:34 2017 +0000
+++ b/main.cpp	Tue Jan 09 01:58:33 2018 +0000
@@ -39,11 +39,79 @@
 #include "mbed.h"
 #include "SimpleSpirit1.h"
 
+/* 180108 cubebite HJM : SimpleSpirit1 Debug define */
+#define NDEBUG
+#define HEAVY_DEBUG
+
+
+/* 180108 cubebite HJM : cubebite Debug define */
+#define CUBEBITE_DEBUG
+
+
+/* 180108 cubebite HJM : cubebite Testing define */
+//#define CUBEBITE_TEST
+//#define CUBEBITE_RF_DEVICE_PARTNUMBER_TEST
+//#define CUBEBITE_RF_GPIO_0_TEST
+
+
+/* 180109 cubebite HJM : cubebite Compile define */
+//#define CUBEBITE_BOARD_F746ZG
+#define CUBEBITE_BOARD_F401RE
+
+
+/* 180108 cubebite HJM : send testing, orignal code  */
 #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'};
-          
-static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); /* (SPI_CLK) = (D13:PA5:resistorR7 --> D3:PB3:resistorR4)*/
+
+/* 180108 cubebite HJM : send testing, testing code  */
+//#define TEST_STR_LEN (3) 
+//static uint8_t send_buf[TEST_STR_LEN] ={'H'};
+//static uint8_t read_buf[TEST_STR_LEN] ={'0','0','0'};
+
+/* 180108 cubebite HJM : orignal code, backup */          
+//static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); /* (SPI_CLK) = (D13:PA5:resistorR7 --> D3:PB3:resistorR4)*/
+
+#ifdef  CUBEBITE_BOARD_F401RE
+/* 180108 cubebite HJM : F401re borad, AnalogIn PIN Info, A0(PA_0) A1(PA_1) A2(PA_4) A3(PB_0) A4(PC_1) A5(PC_0) */
+/* RF Module 과 상관 관계 => A0(PA_0)[SPI GPIO 3] A1(PA_1)[CSN] A2(PA_4)[SPI1 GPIO 2] A3(PB_0)[SPI1 GPIO 1] A4(PC_1)[SPI1_GPIO 0] */
+/* 180108 cubebite HJM : F401re borad Init code */
+//static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PA_7, PA_6, PA_5, PC_7, PB_6, PA_10);    //F401re borad
+static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PA_7, PA_6, PA_5, PA_0, PB_6, PA_10);    //F401re borad, IRQ Testing, GPIO 3 -> IRQ
+#endif
+
+#ifdef  CUBEBITE_BOARD_F401RE
+    #ifdef  CUBEBITE_RF_GPIO_0_TEST
+/* 180108 cubebite HJM : F401re borad, PC_1 == RF_MODULE_GPIO 0, Testing code */
+static DigitalIn RF_GPIO_0_INPUT(PC_1);   //F401re borad
+    #endif
+#endif
+//static DigitalIn RF_GPIO_3_INPUT(PA_0);   //F401re borad, 사용시, send 정상 동작 안함, Spirit1 IRQ 핀이랑 같이 물려있기 때문
+
+
+
+
+
+#ifdef  CUBEBITE_BOARD_F746ZG
+/* 180108 cubebite HJM : F746zg borad, AnalogIn PIN Info, A0(PA_3) A1(PC_0) A2(PC_3) A3(PF_3) A4(PF_5) A5(PF_10)  */
+/* RF Module 과 상관 관계 => A0(PA_3)[SPI GPIO 3] A1(PC_0)[CSN] A2(PC_3)[SPI1 GPIO 2] A3(PF_3)[SPI1 GPIO 1] A4(PF_5)[SPI1_GPIO 0] */
+/* 180108 cubebite HJM : F746zg borad Init code */
+//static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PB_5, PB_4, PB_3, PD_14, PD_5, PD_6);    //F746zg borad
+static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PB_5, PB_4, PB_3, PA_3, PD_5, PD_6);    //F746zg borad, IRQ Testing, GPIO 3 -> IRQ
+#endif
+
+#ifdef  CUBEBITE_BOARD_F746ZG
+    #ifdef  CUBEBITE_RF_GPIO_0_TEST
+/* 180108 cubebite HJM : F746zg borad, PC_1 == RF_MODULE_GPIO 0, Testing code */
+static DigitalIn RF_GPIO_0_INPUT(PF_5); //F746zg borad
+    #endif
+#endif
+
+//static DigitalIn RF_GPIO_3_INPUT(PA_3); //F746zg borad, 사용시, send 정상 동작 안함, Spirit1 IRQ 핀이랑 같이 물려있기 때문
+
+
+
+
 
 static volatile bool rx_done_flag = false; 
 static volatile bool tx_done_flag = false; 
@@ -52,6 +120,8 @@
 static DigitalOut TestLED(D5);         /* LED of IDS01A4/5 */
 static InterruptIn event(USER_BUTTON); /* Interrupt event to give userinterface to send pkt. */
 
+
+
 /**
  * @brief  callback_func
  * @param  callback event
@@ -59,6 +129,8 @@
  */
 static void callback_func(int event) 
 {
+  printf("\r\n***EVENT !!!!!!!!!!!!!***\r\n");  
+  
   if(event == SimpleSpirit1::RX_DONE) 
   {              
     rx_done_flag = 1;
@@ -86,12 +158,36 @@
  */
 static void send_data(void)
 {
-  printf("\r\n***Sending a packet***\r\n");  
+  printf("\r\n***Sending a packet Start***\r\n");  
   
+  printf("[CUBEBITE] myspirit, is_receiving()\t......");
   while(myspirit.is_receiving()); /* wait for ongoing RX ends */
+  printf("OK\n");
  
   size_t curr_len = strlen((const char*)send_buf) + 1;
-  myspirit.send(send_buf, curr_len);
+ 
+    int iRet = 0;
+  
+  printf("[CUBEBITE] myspirit, send()\t......");
+  iRet = myspirit.send(send_buf, curr_len);
+    if (iRet == RADIO_TX_OK)
+    {
+      printf("[RADIO_TX_OK]\n");
+    }
+    else if (iRet == RADIO_TX_ERR)
+    {
+        printf("[RADIO_TX_ERR]\n");
+    }
+    else if (iRet == RADIO_TX_COLLISION)
+    {
+        printf("[RADIO_TX_COLLISION]\n");
+    }
+    else if (iRet == RADIO_TX_NOACK)
+    {
+        printf("[RADIO_TX_NOACK]\n");
+    }
+    
+    printf("\r***Sending a packet End***\r\n");
 }
 
 /**
@@ -101,10 +197,13 @@
  */
 static void read_rcvd_data(void)
 {  
+    printf("\r\n***Recving a packet Start***\r\n");  
  
   for(unsigned int flush_count = 0; flush_count < TEST_STR_LEN; flush_count++) read_buf[flush_count] = 0 ;/* clear the read buffer */
-      
+      printf("[CUBEBITE][myspirit] read()\t......");
       int ret = myspirit.read(read_buf, sizeof(read_buf));
+      printf("OK => ");
+      printf("read value : [%s]\n", read_buf);
       
       TestLED = !TestLED;     /* Toggle LED at the receiver */
       
@@ -113,7 +212,10 @@
         printf("\nNothing to read\n\r");
         return;
       }
-      printf("\r\n***Received a packet***\r\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); 
+      //printf("\r\n***Received a packet***\r\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); 
+      printf("\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); 
+      
+      printf("\r\n***Recving a packet End***\r\n");
 }
 
 
@@ -124,21 +226,109 @@
  */
 int main() 
 {  
-  TestLED = 0;                  /* LED off */
-  
-  myspirit.attach_irq_callback(callback_func);
-  
-  myspirit.on();
+    TestLED = 0;                  /* LED off */
+    
+    /* 180108 cubebite HJM : function return value print */
+    int iRet = 0;
+    
+    
+    /* 180108 cubebite HJM : GPIO 0, init code */
+    SGpioInit gpioIRQ={
+        SPIRIT_GPIO_0,
+        SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_LP,
+        SPIRIT_GPIO_DIG_OUT_IRQ
+    };
+    SpiritGpioInit(&gpioIRQ);
+    
+    
+    
+    /* 180108 cubebite HJM : GPIO 0, For spiritFunctionalState(), Testing code */
+#ifdef  CUBEBITE_RF_GPIO_0_TEST    
+    SpiritFunctionalState spiritFunctionalState={
+          S_DISABLE
+    };
+#endif    
+    
+    
+    
+    
+    /* 180108 cubebite HJM : spirit module, init code  */
+    printf("[CUBEBITE] myspirit, attach_irq_callback()\t......");
+    myspirit.attach_irq_callback(callback_func);
+    printf("OK\n");    
+      
+    printf("[CUBEBITE] myspirit, on()\t......");
+    iRet = myspirit.on();
+    if ( 0 == iRet )
+    {
+        printf("OK\n");    
+    }
+    else
+    {
+        printf("ERROR\n");
+    }
+    
   
-  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");
-  
+ // 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");
+
+
+
+
+      
+  printf("[CUBEBITE] rise(&set_send_data_flag)\t......");
   event.rise(&set_send_data_flag); /*User button interrupt trigger to set send data flag */
-  
+  printf("OK\n");
+
+#ifdef  CUBEBITE_RF_DEVICE_PARTNUMBER_TEST  
+  uint16_t int16SpiritPartNum = 0;
+#endif
   while(1) 
   {
+#ifdef  CUBEBITE_RF_DEVICE_PARTNUMBER_TEST
+    printf("[CUBEBITE][devicePartNumber] SpiritGeneralGetDevicePartNumber()\t......");
+
+    int16SpiritPartNum = SpiritGeneralGetDevicePartNumber();
+    printf("OK => ");
+    printf("int16SpiritPartNum value : [0x%04X]\n", int16SpiritPartNum);
+    int16SpiritPartNum = 0;
+#endif    
+
     __WFE(); /* low power in idle condition., waiting for an event */
     
+    //180108 HJM : For spiritFunctionalState(), testing code
+    /*
+    if (S_ENABLE == spiritFunctionalState)
+    {
+        spiritFunctionalState = S_DISABLE;    
+    }
+    else
+    {
+        spiritFunctionalState = S_ENABLE;    
+    }
+    */
+    
+    
+    
+#ifdef  CUBEBITE_RF_GPIO_0_TEST    
+    /* 180108 cubebite HJM : GPIO 0, For, spiritFunctionalState() => Enables or Disables the output of temperature sensor on SPIRIT GPIO_0. */
+    SpiritGpioTemperatureSensor(spiritFunctionalState);
+    
+    /* 180108 cubebite HJM : RF_GPIO_0_INPUT pin value print */
+    printf("****** RF GPIO_0 Status Testing => [%d] ******\n", (int)RF_GPIO_0_INPUT);
+    //wait(1);
+#endif
+    
+    
+    /* 180108 cubebite HJM : RF_GPIO_3_INPUT pin value print */    
+//    printf("****** RF GPIO_3 Status Testing => [%d] ******\n", (int)RF_GPIO_3_INPUT);    
+    
+    
+    
+    
+    
+    /* 180108 cubebite HJM : RF 모듈 간 통신 때 사용되는 코드 */
+    //read_rcvd_data();
     if(rx_done_flag) 
     {
       rx_done_flag = false; 
@@ -156,6 +346,7 @@
       tx_done_flag = false;
       printf("\r\n***Packet sent ***\r\nSent string ='%s' (len=%d)\n\r", send_buf, strlen((const char*)send_buf) + 1);
     }
+    
   }
   
   /* unreachable */