]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - i3-mote/i3-mote.git/blob - Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Master_MSP432_SlaveIRQ/main.c
f96d6413fe77a203d952a8ba38f27d98c51aeecb
[i3-mote/i3-mote.git] / Basic-Test-Package / CC2650 / Test_CC2650_3wSPI_Master_MSP432_SlaveIRQ / main.c
1 /*
2  *  ======== empty_min.c ========
3  */
4 /* XDCtools Header files */
5 #include <xdc/std.h>
6 #include <xdc/runtime/System.h>
8 /* BIOS Header files */
9 #include <ti/sysbios/BIOS.h>
10 #include <ti/sysbios/knl/Task.h>
11 #include <ti/sysbios/knl/Clock.h>
12 #include <ti/sysbios/knl/Semaphore.h>
14 /* TI-RTOS Header files */
15 //#include <ti/drivers/I2C.h>
16 #include <ti/drivers/PIN.h>
17 #include <ti/drivers/SPI.h>
18 #include <ti/drivers/UART.h>
19 // #include <ti/drivers/Watchdog.h>
21 /* Board Header files */
22 #include "Board.h"
23 #include "uart_printf.h"
25 #define TASKSTACKSIZE   512
27 Task_Struct task0Struct;
28 Char task0Stack[TASKSTACKSIZE];
30 Task_Struct task1Struct;
31 Char task1Stack[TASKSTACKSIZE];
33 Semaphore_Struct semStruct;
34 Semaphore_Handle semHandle;
37 /*
38  * Application LED pin configuration table:
39  *   - All LEDs board LEDs are off.
40  */
41 static PIN_Handle ledPinHandle;
42 static PIN_State ledPinState;
44 PIN_Config ledPinTable[] = {
45     Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
46     Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
47     PIN_TERMINATE
48 };
51 /* Global memory storage for a PIN_Config table */
52 static PIN_Handle buttonPinHandle;
53 static PIN_State buttonPinState;
55 PIN_Config buttonPinTable[] = {
56     Board_BUTTON1  | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
57     PIN_TERMINATE
58 };
60 void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
62         /* Wait IRQ from MSP432 line*/
63         PIN_setOutputValue(ledPinHandle, Board_LED1,1);
64     CPUdelay(8000*100);
65     Semaphore_post(semHandle);
66         PIN_setOutputValue(ledPinHandle, Board_LED1,0);
68 }
72 Void echoFxn(UArg arg0, UArg arg1)
73 {
74         uint8_t i=0;
75         uint8_t         txBufferPointer[4];
76         uint8_t         rxBufferPointer[4];
77         SPI_Handle      spi;
78         SPI_Params      spiParams;
79     SPI_Transaction spiTransaction;
82     SPI_Params_init(&spiParams);
83     // Slave mode
84     spiParams.mode = SPI_MASTER;
85     spiParams.bitRate = 1000000;
86     spiParams.frameFormat = SPI_POL1_PHA1;
88     spi=SPI_open(Board_SPI1,&spiParams);
89     if(!spi){
90       System_printf("SPI did not open");
91     }
92     System_printf("SPI-Master Open\r\n");
94         spiTransaction.rxBuf= rxBufferPointer;
95         spiTransaction.txBuf = txBufferPointer;
96         spiTransaction.count=1;
98     while(1) {
100         Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
102         //txBufferPointer[0]=i++;
103         //rxBufferPointer[0]=0;
105         txBufferPointer[0]=rxBufferPointer[0];
107                 if (SPI_transfer(spi,&spiTransaction)) {
108                         System_printf("RxData: %x TxData: %x\r\n",rxBufferPointer[0],txBufferPointer[0]);
109                 }
110     }
112     /* Deinitialized I2C */
113     SPI_close(spi);
117 /*
118  *  ======== heartBeatFxn ========
119  *  Toggle the Board_LED0. The Task_sleep is determined by arg0 which
120  *  is configured for the heartBeat Task instance.
121  */
122 Void heartBeatFxn(UArg arg0, UArg arg1)
124     while (1) {
125         Task_sleep((UInt)arg0);
126         //PIN_setOutputValue(ledPinHandle, Board_LED0,!PIN_getOutputValue(Board_LED0));
127         //PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
128     }
131 /*
132  *  ======== main ========
133  */
134 int main(void)
136     Task_Params taskParams;
137     Semaphore_Params semParams;
139     /* Call board init functions */
140     Board_initGeneral();
141     Board_initSPI();
142     // Board_initI2C();
143     // Board_initUART();
144     // Board_initWatchdog();
146     /* UART */
147     /* Init UART for System_printf()*/
148     UART_Params uartParams;
149     UART_Params_init(&uartParams);
150     //uartParams.baudRate = 9600;
151     uartParams.baudRate = 115200;
152     UartPrintf_init(UART_open(Board_UART, &uartParams));
153     System_printf("Uart open\r\n");
155     /* Construct heartBeat Task thread */
156     Task_Params_init(&taskParams);
157     taskParams.arg0 = 500000 / Clock_tickPeriod;
158     taskParams.stackSize = TASKSTACKSIZE;
159     taskParams.stack = &task0Stack;
160     Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
162     /* Construct SPI Echo Task thread */
163     Task_Params_init(&taskParams);
164     taskParams.arg0 = 1000000 / Clock_tickPeriod;
165     taskParams.stackSize = TASKSTACKSIZE;
166     taskParams.stack = &task1Stack;
167     Task_construct(&task1Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);
169     /* Construct Semaphore */
170     Semaphore_Params_init(&semParams);
171     Semaphore_construct(&semStruct, 1, &semParams);
173     /* Obtain instance handle */
174     semHandle = Semaphore_handle(&semStruct);
176     /* Setup callback for button pins */
177     buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
178     if(!buttonPinHandle) {
179         System_abort("Error initializing button pins\n");
180     }
181     if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
182         System_abort("Error registering button callback function");
183     }
185     /* Open LED pins */
186     ledPinHandle = PIN_open(&ledPinState, ledPinTable);
187     if(!ledPinHandle) {
188         System_abort("Error initializing board LED pins\n");
189     }
191     PIN_setOutputValue(ledPinHandle, Board_LED0, 0);
192     PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
194     /* Start BIOS */
195     BIOS_start();
197     return (0);