Update CC2650 Tests
authorBorja Martinez <borja.martinez@gmail.com>
Fri, 16 Dec 2016 16:35:28 +0000 (17:35 +0100)
committerBorja Martinez <borja.martinez@gmail.com>
Fri, 16 Dec 2016 16:35:28 +0000 (17:35 +0100)
Basic-Test-Package/CC2650/Test_CC2650_3wSPI_DAC8730/main.c
Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Master_MSP432_SlaveIRQ/main.c
Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Slave_MSP432_Master/main.c
Basic-Test-Package/CC2650/Test_CC2650_DebugUART_EchoPC/main.c
Basic-Test-Package/CC2650/Test_CC2650_I2C_Sensors/main.c

index a3594192c94fe90cce12243337ff6e61bc394eff..3d5ed6a3f8fa4587a27ae78f5ff5fef2bb1ea2e4 100644 (file)
@@ -4,12 +4,14 @@
 /* XDCtools Header files */
 #include <xdc/std.h>
 #include <xdc/runtime/System.h>
+#include <xdc/runtime/Error.h>
 
 /* BIOS Header files */
 #include <ti/sysbios/BIOS.h>
 #include <ti/sysbios/knl/Task.h>
 #include <ti/sysbios/knl/Clock.h>
 #include <ti/sysbios/knl/Semaphore.h>
+#include <ti/sysbios/knl/Event.h>
 
 /* TI-RTOS Header files */
 //#include <ti/drivers/I2C.h>
@@ -34,6 +36,10 @@ Task_Struct task2Struct;
 Char task2Stack[TASKSTACKSIZE];
 
 
+
+Event_Handle myEvent;
+Error_Block eb;
+
 Semaphore_Struct semStruct;
 Semaphore_Handle semHandle;
 
@@ -73,22 +79,49 @@ PIN_Config buttonPinTable[] = {
 
 void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
 
-       PIN_setOutputValue(ledPinHandle, Board_LED1,1);
-    Semaphore_post(semHandle);
-    CPUdelay(8000*50);
-       PIN_setOutputValue(ledPinHandle, Board_LED1,0);
+       CPUdelay(8000*200);
+
+       Semaphore_post(semHandle);
+       //Event_post(myEvent,Event_Id_02);
+
+}
+
+Void uartFxn(UArg arg0, UArg arg1)
+{
+       char input;
+
+       while (1) {
+               // Blocking Read
+               input=uart_getch();
+               if(input=='g'){
+                   //Event_post(myEvent,Event_Id_02);
+                   Semaphore_post(semHandle);
+               }
+           Task_sleep((UInt)arg0);
+       }
+
 }
 
 
+
 #define REGSBW 0x1E
 #define REGSBR 0x0F
+
+#define EEPSBW 0x5A
 #define EEPSBR 0x4B
 
 #define CMRST 0xC3
 
-#define WENA 0x00
+#define WENA  0x00
+#define VCFG1 0x01
+#define VCFG2 0x01
+
+#define STA1 0x07
+#define STA2 0x08
 #define GPVR 0x0C
 
+#define CFG3 0xA6
+
 
 Void spiFxn(UArg arg0, UArg arg1)
 {
@@ -97,11 +130,13 @@ Void spiFxn(UArg arg0, UArg arg1)
 
        int i;
        uint8_t k=0;
+       int flagerr=0;
 
        SPI_Handle      spi;
        SPI_Params      spiParams;
     SPI_Transaction spiTransaction;
 
+    UInt events;
 
     SPI_Params_init(&spiParams);
     // Slave mode
@@ -119,8 +154,15 @@ Void spiFxn(UArg arg0, UArg arg1)
        //Task_sleep((UInt)arg0);
 
     System_printf("Press button:\r\n");
+    PIN_setOutputValue(ledPinHandle, Board_LED0,1);
+    PIN_setOutputValue(ledPinHandle, Board_LED1,1);
+
     Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
 
+       /* Start test */
+    PIN_setOutputValue(ledPinHandle, Board_LED0,0);
+    PIN_setOutputValue(ledPinHandle, Board_LED1,0);
+
        /* Send SPI Reset Command */
 
        spiTransaction.rxBuf = rxBufferPointer;
@@ -136,8 +178,17 @@ Void spiFxn(UArg arg0, UArg arg1)
        rxBufferPointer[2]=0;
 
        if (SPI_transfer(spi,&spiTransaction)) {
-               System_printf("Rst: %x %x %x\r\n",rxBufferPointer[0],rxBufferPointer[1],rxBufferPointer[2]);
+               if (rxBufferPointer[2] != 0xF0)
+               {
+                       Event_post(myEvent, Event_Id_00);
+                       flagerr=1;
+               }
+               System_printf("RST: %x %x %x\r\n",rxBufferPointer[0],rxBufferPointer[1],rxBufferPointer[2]);
                System_flush();
+       }else{
+               Event_post(myEvent, Event_Id_00);
+               flagerr=1;
+               //Task_exit();
        }
        for(i=1000;i>0;i--);
 
@@ -156,14 +207,37 @@ Void spiFxn(UArg arg0, UArg arg1)
        spiTransaction.count = 7;
 
        if (SPI_transfer(spi,&spiTransaction)) {
+
+               if (rxBufferPointer[2] != 0xF0)
+               {
+                       Event_post(myEvent, Event_Id_00);
+                       flagerr=1;
+               }
+
                System_printf("IDC: ");
                for(i=0;i<7;i++){
                        System_printf("%x ",rxBufferPointer[i]);
                }
                System_printf("\r\n");
                System_flush();
+       }else{
+               Event_post(myEvent, Event_Id_00);
+               flagerr=1;
+               //Task_exit();
        }
 
+       /* OK! */
+       if(flagerr==0){
+               Event_post(myEvent, Event_Id_01);
+               System_printf("***\r\n");
+               System_flush();
+       }else{
+               System_printf("KO!\r\n");
+               System_flush();
+       }
+
+    System_printf("Press button to continue:\r\n");
+    Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
 
        while(1){
 
@@ -216,7 +290,6 @@ Void spiFxn(UArg arg0, UArg arg1)
                        System_flush();
                }
 
-
                /* READ 1 BYTE from EEPROM
                txBufferPointer[0]=EEPSBR;
                txBufferPointer[1]=0xA0;
@@ -247,10 +320,26 @@ Void spiFxn(UArg arg0, UArg arg1)
  */
 Void heartBeatFxn(UArg arg0, UArg arg1)
 {
-    while (1) {
+
+       UInt events;
+
+       events=Event_pend(myEvent,Event_Id_NONE,Event_Id_00+Event_Id_01,BIOS_WAIT_FOREVER);
+
+       if(events & Event_Id_00){
+         while (1)
+         {
+        Task_sleep((UInt)arg0);
+        PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
+      }
+       }
+
+       if(events & Event_Id_01){
+      while (1)
+      {
         Task_sleep((UInt)arg0);
         PIN_setOutputValue(ledPinHandle, Board_LED0,!PIN_getOutputValue(Board_LED0));
-    }
+      }
+       }
 }
 
 /*
@@ -268,6 +357,15 @@ int main(void)
     Board_initUART();
     // Board_initWatchdog();
 
+
+    /* Default instance configuration params */
+    Error_init(&eb);
+    myEvent = Event_create(NULL,&eb);
+    if (myEvent == NULL) {
+        System_abort("Event create failed");
+    }
+
+
     /* BMH  Init UART for System_printf() */
     UART_Params uartParams;
     UART_Params_init(&uartParams);
@@ -276,6 +374,14 @@ int main(void)
     System_printf("Uart open\r\n");
 
 
+    /* Construct SPI Echo Task thread */
+    Task_Params_init(&taskParams);
+    taskParams.arg0 = 1000000 / Clock_tickPeriod;
+    taskParams.stackSize = TASKSTACKSIZE;
+    taskParams.stack = &task1Stack;
+    Task_construct(&task1Struct, (Task_FuncPtr)spiFxn, &taskParams, NULL);
+
+
     /* Construct heartBeat Task thread */
     Task_Params_init(&taskParams);
     taskParams.arg0 = 500000 / Clock_tickPeriod;
@@ -283,20 +389,21 @@ int main(void)
     taskParams.stack = &task0Stack;
     Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
 
-    /* Construct SPI Echo Task thread */
+
+    /* Construct Uart Task  thread */
     Task_Params_init(&taskParams);
-    taskParams.arg0 = 1000000 / Clock_tickPeriod;
+    taskParams.arg0 = 100000 / Clock_tickPeriod;
     taskParams.stackSize = TASKSTACKSIZE;
-    taskParams.stack = &task1Stack;
-    Task_construct(&task1Struct, (Task_FuncPtr)spiFxn, &taskParams, NULL);
+    taskParams.stack = &task2Stack;
+    Task_construct(&task2Struct, (Task_FuncPtr)uartFxn, &taskParams, NULL);
 
-    /* Construct Semaphore */
+
+    /* Construct Semaphore Obtain instance handle */
     Semaphore_Params_init(&semParams);
     Semaphore_construct(&semStruct,0, &semParams);
-
-    /* Obtain instance handle */
     semHandle = Semaphore_handle(&semStruct);
 
+
     /* Setup callback for button pins */
     buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
     if(!buttonPinHandle) {
@@ -313,8 +420,8 @@ int main(void)
         System_abort("Error initializing board LED pins\n");
     }
 
-    PIN_setOutputValue(ledPinHandle, Board_LED0, 0);
-    PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
+    PIN_setOutputValue(ledPinHandle, Board_LED0, 1);
+    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
 
     /* Start BIOS */
     BIOS_start();
index f96d6413fe77a203d952a8ba38f27d98c51aeecb..e758490d52b6d819fbdfe5e8246ee35569a47e0e 100644 (file)
@@ -59,19 +59,15 @@ PIN_Config buttonPinTable[] = {
 
 void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
 
-       /* Wait IRQ from MSP432 line*/
-       PIN_setOutputValue(ledPinHandle, Board_LED1,1);
-    CPUdelay(8000*100);
-    Semaphore_post(semHandle);
-       PIN_setOutputValue(ledPinHandle, Board_LED1,0);
+       Semaphore_post(semHandle);
+       PIN_setOutputValue(ledPinHandle, Board_LEDR,1);
 
 }
 
 
-
 Void echoFxn(UArg arg0, UArg arg1)
 {
-       uint8_t i=0;
+
        uint8_t         txBufferPointer[4];
        uint8_t         rxBufferPointer[4];
        SPI_Handle      spi;
@@ -99,13 +95,11 @@ Void echoFxn(UArg arg0, UArg arg1)
 
        Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
 
-       //txBufferPointer[0]=i++;
-       //rxBufferPointer[0]=0;
-
        txBufferPointer[0]=rxBufferPointer[0];
 
                if (SPI_transfer(spi,&spiTransaction)) {
-                       System_printf("RxData: %x TxData: %x\r\n",rxBufferPointer[0],txBufferPointer[0]);
+                       //System_printf("RxData: %x TxData: %x\r\n",rxBufferPointer[0],txBufferPointer[0]);
+                       PIN_setOutputValue(ledPinHandle, Board_LEDR,0);
                }
     }
 
@@ -119,10 +113,18 @@ Void echoFxn(UArg arg0, UArg arg1)
  *  Toggle the Board_LED0. The Task_sleep is determined by arg0 which
  *  is configured for the heartBeat Task instance.
  */
+
 Void heartBeatFxn(UArg arg0, UArg arg1)
 {
+
     while (1) {
-        Task_sleep((UInt)arg0);
+
+        Task_sleep((UInt)arg0-5000/Clock_tickPeriod);
+        PIN_setOutputValue(ledPinHandle, Board_LEDG,1);
+        Task_sleep((UInt)5000/Clock_tickPeriod);
+        PIN_setOutputValue(ledPinHandle, Board_LEDG,0);
+
+        //Task_sleep((UInt)arg0);
         //PIN_setOutputValue(ledPinHandle, Board_LED0,!PIN_getOutputValue(Board_LED0));
         //PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
     }
@@ -154,7 +156,7 @@ int main(void)
 
     /* Construct heartBeat Task thread */
     Task_Params_init(&taskParams);
-    taskParams.arg0 = 500000 / Clock_tickPeriod;
+    taskParams.arg0 = 2000000 / Clock_tickPeriod;
     taskParams.stackSize = TASKSTACKSIZE;
     taskParams.stack = &task0Stack;
     Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
index 9a6dadfe7a956b864adea8fe2875b78e690895f0..a8f2bee0a3c6aa2fcf9feeb2240f8d957325925e 100644 (file)
@@ -65,20 +65,26 @@ Void echoFxn(UArg arg0, UArg arg1)
     if(!spi){
       System_printf("SPI did not open");
     }
-    System_printf("SPI-Slave Open\r\n");
+    System_printf("SPI Slave Mode Open\r\n");
 
     rxBufferPointer[0]='*';
+
     while(1) {
 
        spiTransaction.rxBuf= rxBufferPointer;
        spiTransaction.txBuf = txBufferPointer;
        spiTransaction.count=1;
 
-               PIN_setOutputValue(ledPinHandle, Board_LEDG,!PIN_getOutputValue(Board_LEDG));
+               PIN_setOutputValue(ledPinHandle, Board_LEDR,0);
+
                if (SPI_transfer(spi,&spiTransaction)) {
 
+                       PIN_setOutputValue(ledPinHandle, Board_LEDR,1);
+
+                       System_printf("RxData: %x\r\n",rxBufferPointer[0]);
+
                        txBufferPointer[0]=rxBufferPointer[0];
-                       System_printf("RxData: %x TxData: %x\r\n",rxBufferPointer[0],txBufferPointer[0]);
+                       rxBufferPointer[0]=0x55;
 
                }
 
@@ -98,7 +104,12 @@ Void echoFxn(UArg arg0, UArg arg1)
 Void heartBeatFxn(UArg arg0, UArg arg1)
 {
     while (1) {
-        Task_sleep((UInt)arg0);
+
+       Task_sleep((UInt)arg0-5000/Clock_tickPeriod);
+       PIN_setOutputValue(ledPinHandle, Board_LEDG,1);
+       Task_sleep((UInt)5000/Clock_tickPeriod);
+       PIN_setOutputValue(ledPinHandle, Board_LEDG,0);
+
         //PIN_setOutputValue(ledPinHandle, Board_LEDG,!PIN_getOutputValue(Board_LEDG));
         //PIN_setOutputValue(ledPinHandle, Board_LEDR,!PIN_getOutputValue(Board_LEDR));
     }
@@ -127,7 +138,7 @@ int main(void)
 
     /* Construct heartBeat Task thread */
     Task_Params_init(&taskParams);
-    taskParams.arg0 = 200000 / Clock_tickPeriod;
+    taskParams.arg0 = 2000000 / Clock_tickPeriod;
     taskParams.stackSize = TASKSTACKSIZE;
     taskParams.stack = &task0Stack;
     Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
index 4d2d3f5ba454285a7b151386f874343e018e8f34..7f9f337dd55443f7f54b0b3055aa75e9e20244c6 100644 (file)
@@ -67,7 +67,8 @@ Void taskFxn(UArg arg0, UArg arg1)
        while (1) {
                /* Blocking Read */
                UART_read(uart, &input, 1);
-           UART_write(uart, &input, 1);
+               /* Echo */
+               UART_write(uart, &input, 1);
        }
 
 }
@@ -81,8 +82,8 @@ Void heartBeatFxn(UArg arg0, UArg arg1)
 {
     while (1) {
         Task_sleep((UInt)arg0);
-        PIN_setOutputValue(ledPinHandle, Board_LED0,!PIN_getOutputValue(Board_LED0));
-        //PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
+        //PIN_setOutputValue(ledPinHandle, Board_LEDR,!PIN_getOutputValue(Board_LED0));
+        PIN_setOutputValue(ledPinHandle, Board_LEDG,!PIN_getOutputValue(Board_LED1));
     }
 }
 
@@ -102,7 +103,7 @@ int main(void)
 
     /* Construct heartBeat Task  thread */
     Task_Params_init(&taskParams);
-    taskParams.arg0 = 2000000 / Clock_tickPeriod;
+    taskParams.arg0 = 1000000 / Clock_tickPeriod;
     taskParams.stackSize = TASKSTACKSIZE;
     taskParams.stack = &task0Stack;
     Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
index afb520e338e072d42db8c7b24405f03ec98e8998..6908811d6c0bc76fc27697b536331131b0002a1e 100644 (file)
@@ -79,11 +79,7 @@ PIN_Config buttonPinTable[] = {
 
 void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
 
-       PIN_setOutputValue(ledPinHandle, Board_LED0,0);
-       PIN_setOutputValue(ledPinHandle, Board_LED1,0);
-    CPUdelay(8000*200);
-       PIN_setOutputValue(ledPinHandle, Board_LED0,1);
-       PIN_setOutputValue(ledPinHandle, Board_LED1,1);
+       CPUdelay(8000*200);
 
        //Event_post(myEvent,Event_Id_02);
        Semaphore_post(semHandle);
@@ -126,12 +122,15 @@ Void taskFxn(UArg arg0, UArg arg1)
     if (i2c == NULL) {
         System_abort("Error Initializing I2C\r\n");
     }
-
     System_printf("I2C Initialized\r\n");
 
-    System_printf("Press button:\r\n");
-       Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
+    /* Wait Semaphore */
+    System_printf("Press Button:\r\n");
+
+    PIN_setOutputValue(ledPinHandle, Board_LED0,1);
+    PIN_setOutputValue(ledPinHandle, Board_LED1,1);
 
+    Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
 
        /* Start test */
     PIN_setOutputValue(ledPinHandle, Board_LED0,0);
@@ -155,7 +154,7 @@ Void taskFxn(UArg arg0, UArg arg1)
                                Event_post(myEvent, Event_Id_00);
                                flagerr=1;
                        }
-                       System_printf("OPT3001 ID 0x5449: %x\r\n",data);
+                       System_printf("OPT3001 Device ID [0x5449]: %x\r\n",data);
                }else{
                        System_printf("OPT3001 I2c Transaction Failed\r\n");
                        Event_post(myEvent, Event_Id_00);
@@ -180,7 +179,7 @@ Void taskFxn(UArg arg0, UArg arg1)
                                flagerr=1;
                        }
                        //System_printf("HDC1080 Manufactured ID 0x5449: %x\n",data);
-                       System_printf("HDC1080 Device ID 0x1050: %x\r\n",data);
+                       System_printf("HDC1080 Device ID [0x1050]: %x\r\n",data);
                }
                else{
                        System_printf("HDC1080 I2c Transaction Failed\r\n");
@@ -225,7 +224,7 @@ Void taskFxn(UArg arg0, UArg arg1)
                                Event_post(myEvent, Event_Id_00);
                                flagerr=1;
                        }
-                       System_printf("TMP007 Device ID 0x0078: %x\r\n",data);
+                       System_printf("TMP007 Device ID [0x0078]: %x\r\n",data);
                }else{
                        System_printf("TMP007 I2c Transaction Failed\r\n");
                        Event_post(myEvent, Event_Id_00);
@@ -249,7 +248,7 @@ Void taskFxn(UArg arg0, UArg arg1)
                                Event_post(myEvent, Event_Id_00);
                                flagerr=1;
                        }
-                       System_printf("BMP280 ID 0x58: %x\r\n",data);
+                       System_printf("BMP280 Device ID [0x58]: %x\r\n",data);
                }else{
                        System_printf("BMP280 I2c Transaction Failed\r\n");
                        Event_post(myEvent, Event_Id_00);
@@ -271,7 +270,7 @@ Void taskFxn(UArg arg0, UArg arg1)
                                Event_post(myEvent, Event_Id_00);
                                flagerr=1;
                        }
-                       System_printf("MPU9250 WHOIAM 0x71: %x\r\n",data);
+                       System_printf("MPU9250 WHOIAM [0x71]: %x\r\n",data);
                }else{
                        System_printf("MPU9250 I2c Transaction Failed\r\n");
                        Event_post(myEvent, Event_Id_00);
@@ -294,7 +293,7 @@ Void taskFxn(UArg arg0, UArg arg1)
                                Event_post(myEvent, Event_Id_00);
                                flagerr=1;
                        }
-                       System_printf("LISHH12 WHOIAM 0x41: %x\r\n",data);
+                       System_printf("LISHH12 WHOIAM [0x41]: %x\r\n",data);
                }else{
                        System_printf("LISHH12 I2c Transaction Failed\r\n");
                        Event_post(myEvent, Event_Id_00);