summaryrefslogtreecommitdiffstats
blob: 2cfa0cae113fa12d902f99133c6deeec9c4c17cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 *  ======== empty_min.c ========
 */
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.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>

/* TI-RTOS Header files */
//#include <ti/drivers/I2C.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/SPI.h>
#include <ti/drivers/UART.h>
// #include <ti/drivers/Watchdog.h>

/* Board Header files */
#include "Board.h"
#include "uart_printf.h"

#define TASKSTACKSIZE   512

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];

Task_Struct task1Struct;
Char task1Stack[TASKSTACKSIZE];

Semaphore_Struct semStruct;
Semaphore_Handle semHandle;


/*
 * Application LED pin configuration table:
 *   - All LEDs board LEDs are off.
 */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;

PIN_Config ledPinTable[] = {
    Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
};


/* Global memory storage for a PIN_Config table */
static PIN_Handle buttonPinHandle;
static PIN_State buttonPinState;

PIN_Config buttonPinTable[] = {
    Board_BUTTON1  | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
    PIN_TERMINATE
};

void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {

	/* Wait IRQ from MSP432 line*/
	PIN_setOutputValue(ledPinHandle, Board_LED1,1);
    Semaphore_post(semHandle);
    CPUdelay(8000*100);
	PIN_setOutputValue(ledPinHandle, Board_LED1,0);

}



Void echoFxn(UArg arg0, UArg arg1)
{
	uint8_t i=0;
	uint8_t         txBufferPointer[4];
	uint8_t         rxBufferPointer[4];
	SPI_Handle      spi;
	SPI_Params      spiParams;
    SPI_Transaction spiTransaction;


    SPI_Params_init(&spiParams);
    // Slave mode
    spiParams.mode = SPI_MASTER;
    spiParams.bitRate = 1000000;
    spiParams.frameFormat = SPI_POL1_PHA1;

    spi=SPI_open(Board_SPI1,&spiParams);
    if(!spi){
      System_printf("SPI did not open");
    }
    System_printf("SPI Init Done\r\n");

	spiTransaction.rxBuf= rxBufferPointer;
	spiTransaction.txBuf = txBufferPointer;
	spiTransaction.count=1;

    while(1) {

    	Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);

    	txBufferPointer[0]=i++;
    	rxBufferPointer[0]=0;

		if (SPI_transfer(spi,&spiTransaction)) {
			System_printf("TxData: %x RxData: %x\r\n",txBufferPointer[0],rxBufferPointer[0]);
		}
    }

    /* Deinitialized I2C */
    SPI_close(spi);
}


/*
 *  ======== heartBeatFxn ========
 *  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);
        //PIN_setOutputValue(ledPinHandle, Board_LED0,!PIN_getOutputValue(Board_LED0));
        //PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
    }
}

/*
 *  ======== main ========
 */
int main(void)
{
    Task_Params taskParams;
    Semaphore_Params semParams;

    /* Call board init functions */
    Board_initGeneral();
    Board_initSPI();
    // Board_initI2C();
    // Board_initUART();
    // Board_initWatchdog();

    /* UART */
    /* Init UART for System_printf()*/
    UART_Params uartParams;
    UART_Params_init(&uartParams);
    //uartParams.baudRate = 9600;
    uartParams.baudRate = 115200;
    UartPrintf_init(UART_open(Board_UART, &uartParams));
    System_printf("Uart open\r\n");

    /* Construct heartBeat Task thread */
    Task_Params_init(&taskParams);
    taskParams.arg0 = 500000 / Clock_tickPeriod;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);

    /* 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)echoFxn, &taskParams, NULL);

    /* Construct Semaphore */
    Semaphore_Params_init(&semParams);
    Semaphore_construct(&semStruct, 1, &semParams);

    /* Obtain instance handle */
    semHandle = Semaphore_handle(&semStruct);

    /* Setup callback for button pins */
    buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
    if(!buttonPinHandle) {
        System_abort("Error initializing button pins\n");
    }
    if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
        System_abort("Error registering button callback function");
    }

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
        System_abort("Error initializing board LED pins\n");
    }

    PIN_setOutputValue(ledPinHandle, Board_LED0, 0);
    PIN_setOutputValue(ledPinHandle, Board_LED1, 0);

    /* Start BIOS */
    BIOS_start();

    return (0);
}