1 /*
2 * ======== empty_min.c ========
3 */
4 /* XDCtools Header files */
5 #include <xdc/std.h>
6 #include <xdc/runtime/System.h>
7 #include <xdc/runtime/Error.h>
9 /* BIOS Header files */
10 #include <ti/sysbios/BIOS.h>
11 #include <ti/sysbios/knl/Task.h>
12 #include <ti/sysbios/knl/Clock.h>
13 #include <ti/sysbios/knl/Semaphore.h>
14 #include <ti/sysbios/knl/Event.h>
16 /* TI-RTOS Header files */
17 //#include <ti/drivers/I2C.h>
18 #include <ti/drivers/PIN.h>
19 // #include <ti/drivers/SPI.h>
20 #include <ti/drivers/UART.h>
21 // #include <ti/drivers/Watchdog.h>
23 /* Board Header files */
24 #include "Board.h"
26 #include "uart_printf.h"
28 #define TASKSTACKSIZE (1024)
30 Task_Struct task0Struct;
31 Char task0Stack[TASKSTACKSIZE];
33 /* Semaphore */
34 Semaphore_Struct semStruct;
35 Semaphore_Handle semHandle;
38 /* Pin driver handle */
39 static PIN_Handle ledPinHandle;
40 static PIN_State ledPinState;
42 /*
43 * Application LED pin configuration table:
44 * - All LEDs board LEDs are off.
45 */
46 PIN_Config ledPinTable[] = {
47 Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
48 Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
49 PIN_TERMINATE
50 };
52 /* Global memory storage for a PIN_Config table */
53 static PIN_Handle buttonPinHandle;
54 static PIN_State buttonPinState;
56 PIN_Config buttonPinTable[] = {
57 Board_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
58 //Board_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
59 PIN_TERMINATE
60 };
63 void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
65 Semaphore_post(semHandle);
66 System_printf("***\r\n");
67 System_flush();
69 }
71 /*
72 * ======== heartBeatFxn ========
73 * Toggle the Board_LED0. The Task_sleep is determined by arg0 which
74 * is configured for the heartBeat Task instance.
75 */
76 Void heartBeatFxn(UArg arg0, UArg arg1)
77 {
79 //PIN_setOutputValue(ledPinHandle, Board_LED0,1);
80 //PIN_setOutputValue(ledPinHandle, Board_LED1,1);
82 Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
84 /* Start test */
85 //PIN_setOutputValue(ledPinHandle, Board_LED0,0);
86 //PIN_setOutputValue(ledPinHandle, Board_LED1,0);
88 while (1)
89 {
90 Task_sleep((UInt)arg0);
91 PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
92 PIN_setOutputValue(ledPinHandle, Board_LED0,!PIN_getOutputValue(Board_LED0));
93 }
95 }
99 /*
100 * ======== main ========
101 */
104 int main(void)
105 {
106 Task_Params taskParams;
108 Semaphore_Params semParams;
110 /* Call board init functions */
111 Board_initGeneral();
112 //Board_initI2C();
113 // Board_initSPI();
114 Board_initUART();
115 // Board_initWatchdog();
118 UART_Params uartParams;
119 UART_Params_init(&uartParams);
120 uartParams.baudRate = 115200;
121 //uartParams.readEcho = UART_ECHO_OFF;
122 UartPrintf_init(UART_open(Board_UART, &uartParams));
124 /* Construct heartBeat Task thread */
125 Task_Params_init(&taskParams);
126 taskParams.arg0 = 100000 / Clock_tickPeriod;
127 taskParams.stackSize = TASKSTACKSIZE;
128 taskParams.stack = &task0Stack;
129 Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
132 /* Construct Semaphore and Obtain instance handle */
133 Semaphore_Params_init(&semParams);
134 Semaphore_construct(&semStruct,0, &semParams);
135 semHandle = Semaphore_handle(&semStruct);
137 /* Setup callback for button pins */
138 buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
139 if(!buttonPinHandle) {
140 System_abort("Error initializing button pins\n");
141 }
142 if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
143 System_abort("Error registering button callback function");
144 }
146 /* Open LED pins */
147 ledPinHandle = PIN_open(&ledPinState, ledPinTable);
148 if(!ledPinHandle) {
149 System_abort("Error initializing board LED pins\n");
150 }
152 PIN_setOutputValue(ledPinHandle, Board_LED0,0);
153 PIN_setOutputValue(ledPinHandle, Board_LED1,0);
155 /* Start BIOS */
156 BIOS_start();
158 return (0);
159 }