diff options
Diffstat (limited to 'Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Slave_MSP432_Master/main.c')
-rw-r--r-- | Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Slave_MSP432_Master/main.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Slave_MSP432_Master/main.c b/Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Slave_MSP432_Master/main.c new file mode 100644 index 0000000..9a6dadf --- /dev/null +++ b/Basic-Test-Package/CC2650/Test_CC2650_3wSPI_Slave_MSP432_Master/main.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | * ======== empty_min.c ======== | ||
3 | */ | ||
4 | /* XDCtools Header files */ | ||
5 | #include <xdc/std.h> | ||
6 | #include <xdc/runtime/System.h> | ||
7 | |||
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 | |||
13 | /* TI-RTOS Header files */ | ||
14 | //#include <ti/drivers/I2C.h> | ||
15 | #include <ti/drivers/PIN.h> | ||
16 | #include <ti/drivers/SPI.h> | ||
17 | #include <ti/drivers/UART.h> | ||
18 | // #include <ti/drivers/Watchdog.h> | ||
19 | |||
20 | /* Board Header files */ | ||
21 | #include "Board.h" | ||
22 | #include "uart_printf.h" | ||
23 | |||
24 | #define TASKSTACKSIZE 512 | ||
25 | |||
26 | Task_Struct task0Struct; | ||
27 | Char task0Stack[TASKSTACKSIZE]; | ||
28 | |||
29 | Task_Struct task1Struct; | ||
30 | Char task1Stack[TASKSTACKSIZE]; | ||
31 | |||
32 | |||
33 | /* Pin driver handle */ | ||
34 | static PIN_Handle ledPinHandle; | ||
35 | static PIN_State ledPinState; | ||
36 | |||
37 | /* | ||
38 | * Application LED pin configuration table: | ||
39 | * - All LEDs board LEDs are off. | ||
40 | */ | ||
41 | |||
42 | PIN_Config ledPinTable[] = { | ||
43 | Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, | ||
44 | Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, | ||
45 | PIN_TERMINATE | ||
46 | }; | ||
47 | |||
48 | Void echoFxn(UArg arg0, UArg arg1) | ||
49 | { | ||
50 | uint8_t rxBufferPointer[4]; | ||
51 | uint8_t txBufferPointer[4]; | ||
52 | SPI_Handle spi; | ||
53 | SPI_Params spiParams; | ||
54 | SPI_Transaction spiTransaction; | ||
55 | |||
56 | SPI_Params_init(&spiParams); | ||
57 | // Slave mode | ||
58 | spiParams.mode = SPI_SLAVE; | ||
59 | spiParams.bitRate = 500000; | ||
60 | spiParams.frameFormat = SPI_POL1_PHA1; | ||
61 | // params.transferMode = SPI_MODE_CALLBACK; | ||
62 | //spiParams.transferCallbackFxn = spi_tx_call; | ||
63 | |||
64 | spi=SPI_open(Board_SPI1,&spiParams); | ||
65 | if(!spi){ | ||
66 | System_printf("SPI did not open"); | ||
67 | } | ||
68 | System_printf("SPI-Slave Open\r\n"); | ||
69 | |||
70 | rxBufferPointer[0]='*'; | ||
71 | while(1) { | ||
72 | |||
73 | spiTransaction.rxBuf= rxBufferPointer; | ||
74 | spiTransaction.txBuf = txBufferPointer; | ||
75 | spiTransaction.count=1; | ||
76 | |||
77 | PIN_setOutputValue(ledPinHandle, Board_LEDG,!PIN_getOutputValue(Board_LEDG)); | ||
78 | if (SPI_transfer(spi,&spiTransaction)) { | ||
79 | |||
80 | txBufferPointer[0]=rxBufferPointer[0]; | ||
81 | System_printf("RxData: %x TxData: %x\r\n",rxBufferPointer[0],txBufferPointer[0]); | ||
82 | |||
83 | } | ||
84 | |||
85 | |||
86 | } | ||
87 | |||
88 | /* Deinitialized I2C */ | ||
89 | SPI_close(spi); | ||
90 | } | ||
91 | |||
92 | |||
93 | /* | ||
94 | * ======== heartBeatFxn ======== | ||
95 | * Toggle the Board_LED0. The Task_sleep is determined by arg0 which | ||
96 | * is configured for the heartBeat Task instance. | ||
97 | */ | ||
98 | Void heartBeatFxn(UArg arg0, UArg arg1) | ||
99 | { | ||
100 | while (1) { | ||
101 | Task_sleep((UInt)arg0); | ||
102 | //PIN_setOutputValue(ledPinHandle, Board_LEDG,!PIN_getOutputValue(Board_LEDG)); | ||
103 | //PIN_setOutputValue(ledPinHandle, Board_LEDR,!PIN_getOutputValue(Board_LEDR)); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /* | ||
108 | * ======== main ======== | ||
109 | */ | ||
110 | int main(void) | ||
111 | { | ||
112 | Task_Params taskParams; | ||
113 | |||
114 | /* Call board init functions */ | ||
115 | Board_initGeneral(); | ||
116 | Board_initSPI(); | ||
117 | // Board_initI2C(); | ||
118 | // Board_initUART(); | ||
119 | // Board_initWatchdog(); | ||
120 | |||
121 | /* Init UART for System_printf()*/ | ||
122 | UART_Params uartParams; | ||
123 | UART_Params_init(&uartParams); | ||
124 | uartParams.baudRate = 115200; | ||
125 | UartPrintf_init(UART_open(Board_UART, &uartParams)); | ||
126 | System_printf("Uart open\r\n"); | ||
127 | |||
128 | /* Construct heartBeat Task thread */ | ||
129 | Task_Params_init(&taskParams); | ||
130 | taskParams.arg0 = 200000 / Clock_tickPeriod; | ||
131 | taskParams.stackSize = TASKSTACKSIZE; | ||
132 | taskParams.stack = &task0Stack; | ||
133 | Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL); | ||
134 | |||
135 | /* Construct SPI Echo Task thread */ | ||
136 | Task_Params_init(&taskParams); | ||
137 | taskParams.arg0 = 0; | ||
138 | taskParams.stackSize = TASKSTACKSIZE; | ||
139 | taskParams.stack = &task1Stack; | ||
140 | Task_construct(&task1Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL); | ||
141 | |||
142 | /* Open LED pins */ | ||
143 | ledPinHandle = PIN_open(&ledPinState, ledPinTable); | ||
144 | if(!ledPinHandle) { | ||
145 | System_abort("Error initializing board LED pins\n"); | ||
146 | } | ||
147 | |||
148 | PIN_setOutputValue(ledPinHandle, Board_LED0, 0); | ||
149 | PIN_setOutputValue(ledPinHandle, Board_LED1, 0); | ||
150 | |||
151 | /* Start BIOS */ | ||
152 | BIOS_start(); | ||
153 | |||
154 | return (0); | ||
155 | } | ||