센서보드 RF IRQ 테스트 중

Fork of stm-spirit1-rf-driver by ST

Revision:
84:45b9ff78a066
Parent:
83:54b207156a91
diff -r 54b207156a91 -r 45b9ff78a066 stm-spirit1-rf-driver/SimpleSpirit1.h
--- a/stm-spirit1-rf-driver/SimpleSpirit1.h	Wed Mar 21 05:06:08 2018 +0000
+++ b/stm-spirit1-rf-driver/SimpleSpirit1.h	Fri Jun 22 03:42:24 2018 +0000
@@ -39,13 +39,21 @@
 /* max payload */
 #define SPIRIT1_MAX_PAYLOAD     (MAX_PACKET_LEN)
 
+//180619 HJM : init 재시작을 위한 OnOff 변수
+//			: 15:22, 일단 안해보고 해보기로.. spi init을 두번해도 상관 없는 거면 뭐
+//static volatile bool isItDoItRFInit;
+//static volatile bool isItDoItSPIInit;
+
+
+
 
 /*** Missing Cube External Declarations ***/
 extern "C" void SpiritManagementSetFrequencyBase(uint32_t);
 
 
 /*** UnlockedSPI for Usage in IRQ context ***/
-class UnlockedSPI : public SPI {
+class UnlockedSPI : public SPI 
+{
 public:
     UnlockedSPI(PinName mosi, PinName miso, PinName sclk) :
         SPI(mosi, miso, sclk) { }
@@ -96,7 +104,8 @@
  * }
  * @endcode
  */
-class SimpleSpirit1 {
+class SimpleSpirit1 
+{
  protected:
 	static SimpleSpirit1 *_singleton;
 
@@ -119,7 +128,8 @@
     Callback<void(int)> _current_irq_callback;
     Timeout _rx_receiving_timeout;
 
-    void rx_timeout_handler(void) {
+    void rx_timeout_handler(void) 
+    {
     	set_ready_state();
 	    cmd_strobe(SPIRIT1_STROBE_RX);
 #ifdef DEBUG_IRQ
@@ -127,11 +137,13 @@
 #endif
     }
 
-    void start_rx_timeout(void) {
+    void start_rx_timeout(void) 
+    {
     	_rx_receiving_timeout.attach_us(Callback<void()>(this, &SimpleSpirit1::rx_timeout_handler), 100 * 1000); // 100ms
     }
 
-    void stop_rx_timeout(void) {
+    void stop_rx_timeout(void) 
+    {
     	_rx_receiving_timeout.detach();
     }
 
@@ -148,6 +160,8 @@
     volatile bool _spirit_rx_err;
     uint8_t spirit_rx_buf[MAX_PACKET_LEN];
     volatile bool _is_receiving;
+    
+    
 
     /** Status Variables from Cube Implementation **/
     unsigned int spirit_on;
@@ -157,6 +171,11 @@
     /** Low Level Instance Variables **/
     unsigned int _nr_of_irq_disables;
 
+	//HJM : SPI 셋팅 변수
+	volatile uint32_t _uint32SpiClkSettingValue;
+	
+
+
     /** Low Level Instance Methods **/
     void disable_spirit_irq(void) 
     {
@@ -167,7 +186,8 @@
 #endif
     }
 
-    void enable_spirit_irq(void) {
+    void enable_spirit_irq(void) 
+    {
 #ifndef NDEBUG
     	debug_if(_nr_of_irq_disables == 0, "\r\nassert failed in: %s (%d)\r\n", __func__, __LINE__);
 #endif
@@ -188,7 +208,8 @@
     	wait_ms(10); // wait 10 milliseconds (to allow Spirit1 a proper boot-up sequence)
     }
 
-    void cs_to_sclk_delay(void) {
+    void cs_to_sclk_delay(void) 
+    {
     	wait_us(1); // heuristic value
     }
 
@@ -367,7 +388,7 @@
     }
 
     /** Internal Spirit Methods */
-    void set_ready_state(void);
+    int set_ready_state(void);
     uint8_t refresh_state(void);
 
     /** Friend Functions **/
@@ -402,20 +423,40 @@
     /** Spirit Irq Callback */
     void IrqHandler();
 
+
+
     /** Constructor **/
     SimpleSpirit1(PinName mosi, PinName miso, PinName sclk,
 		  PinName irq, PinName cs, PinName sdn,
-		  PinName led);
+		  PinName led, 
+		  uint32_t uint32SClkSettingValue);
 
     /** Destructor **/
     ~SimpleSpirit1(void); // should never be called!
 
+
+
+
+
+
+
+
+
+
+
+
 public:
-    enum {
+    enum 
+    {
     	RX_DONE,
     	TX_DONE,
 		TX_ERR
     };
+    
+    
+    
+    
+    
 
     /** Create singleton instance of 'SimpleSpirit1'
      *
@@ -428,32 +469,61 @@
      *
      * @returns     reference to singleton instance
      */
-    static SimpleSpirit1& CreateInstance(PinName mosi, PinName miso, PinName sclk,
-    		PinName irq, PinName cs, PinName sdn,
-			PinName led = NC) {
-
-    	if(_singleton == NULL) {
+    static SimpleSpirit1& CreateInstance(
+    										PinName mosi, PinName miso, PinName sclk,
+    										PinName irq, PinName cs, PinName sdn,
+											PinName led = NC, 
+											uint32_t uint32SClkSettingValue = 6500000	//6.5Mhz, SPI CLK speed 초기값, 최고 속도									
+										) 
+	{
+    	if(_singleton == NULL) 
+    	{
     		_singleton = new SimpleSpirit1(mosi, miso, sclk,
-    				irq, cs, sdn, led);
+    				irq, cs, sdn, led, uint32SClkSettingValue);
+    		printf("[INIT_REVISE] init start..\n");				
+//    		isItDoItRFInit = false;
+//    		isItDoItSPIInit = false;
+    		wait(0.1);
     		_singleton->init();
-    	} else {
+    		printf("[INIT_REVISE] init end..\n");		
+    	} 
+    	else 
+    	{
     		error("SimpleSpirit1 singleton already created!\n");
     	}
 
     	return *_singleton;
     }
+    
+    
+    
+    
 
     /** Get singleton instance of 'SimpleSpirit1'
      *
      * @returns     reference to singleton instance
      */
-    static SimpleSpirit1& Instance() {
-    	if(_singleton == NULL) {
+    static SimpleSpirit1& Instance() 
+    {
+    	if(_singleton == NULL) 
+    	{
     		error("SimpleSpirit1 must be created before used!\n");
     	}
 
     	return *_singleton;
     }
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
 
     /** Attach a function to be called by the Spirit Irq handler when an event has occurred
      *
@@ -463,7 +533,8 @@
      *  @note  Function 'func' will be call with either 'RX_DONE', 'TX_DONE', or 'TX_ERR' as parameter
      *         to indicate which event has occurred.
      */
-    void attach_irq_callback(Callback<void(int)> func) {
+    void attach_irq_callback(Callback<void(int)> func) 
+    {
     	_current_irq_callback = func;
     }
 
@@ -550,7 +621,69 @@
 
     /** Reset Board
      */
-    void reset_board() {
+    void reset_board() 
+    {
+    	printf("[INIT_REVISE]reset board ...\n");
     	init();
+    	printf("[INIT_REVISE]reset board end.\n");
     }
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+//*************************************************************************************
+//HJM SUDO code : SPI 클럭 셋팅 가능 함수
+//*************************************************************************************
+    /** Set SPI Clock
+     */
+    void set_spi_clock(uint32_t ) 
+    {
+    	
+    }
+    
+    
+    
+    
+    
+//*************************************************************************************    
+    
+    
+    
+    
 };
+
+
+
+
+/*
+HJM SUDO code : 고려 상황 정리
+1. 올바르지 않은 행동을 할 인스턴스가 생성 되었을 시는 어떻게 하나??
+	-> 생성자를 사용했을 시 포인터를 반환 하도록 해서, 올바르지 않은 인스턴스가 만들어졌을 시에는 반환 객체 주소 값을 반환하지 않도록 하면 된다.
+		=> ex> 
+			test *t;
+    		t = new test();
+			if(NULL == t)
+			{
+				printf("올바르지 않은 객체가 생성되었습니다!\n");
+				return;
+			}
+
+
+
+
+
+*/
+
+
+