Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ======== Blink_Task.c ========
- * Author: Michael Kramer / Matthias Wenzl
- */
- #include <stdbool.h>
- #include <inc/hw_memmap.h>
- /* XDCtools Header files */
- #include <xdc/std.h>
- #include <xdc/cfg/global.h>
- #include <xdc/runtime/System.h>
- #include <xdc/runtime/Error.h>
- #include <xdc/runtime/Memory.h>
- /* BIOS Header files */
- #include <ti/sysbios/BIOS.h>
- #include <ti/sysbios/knl/Task.h>
- #include <ti/sysbios/knl/Semaphore.h>
- #include <ti/sysbios/knl/Queue.h>
- #include <ti/sysbios/knl/Mailbox.h>
- #include <ti/sysbios/knl/Event.h>
- #include <ti/sysbios/hal/Timer.h>
- #include <ti/sysbios/knl/Event.h>
- /* TI-RTOS Header files */
- #include <ti/drivers/UART.h>
- #include <ti/drivers/GPIO.h>
- #include <driverlib/sysctl.h>
- #include <driverlib/i2c.h>
- #include <driverlib/ssi.h>
- #include <driverlib/uart.h>
- #include <driverlib/gpio.h>
- #include <driverlib/pin_map.h>
- /*Board Header files */
- #include <Board.h>
- #include <EK_TM4C1294XL.h>
- /*application header files*/
- #include <ctype.h>
- #include <string.h>
- #include <ctype.h>
- #include <string.h>
- typedef struct {
- uint32_t port_base;
- uint8_t led;
- }led_descriptor_t;
- int setup_UART_Task(void);
- void BlinkFxn(UArg arg0, UArg arg1);
- int setup_Blink_Task(led_descriptor_t *led_desc, uint32_t wait_ticks);
- void UARTFxn(UArg arg0, UArg arg1);
- long handle_input(char input,long inputval);
- Queue_Handle queuehandl;
- typedef struct Queue_record {
- Queue_Elem element;
- long data;
- } queuerecord;
- Semaphore_Handle semap;
- int main(void)
- {
- uint32_t ui32SysClock;
- static led_descriptor_t led_desc[2];
- Error_Block eb;
- /* Call board init functions. */
- ui32SysClock = Board_initGeneral(120*1000*1000);
- (void)ui32SysClock; // We don't really need this (yet)
- Error_init(&eb);
- /* Create a Semaphore object to be use as a resource lock */
- semap = Semaphore_create(1, NULL, &eb);
- if(semap == NULL) {
- System_abort("Semaphore create failed");
- }
- Error_init(&eb);
- queuehandl = Queue_create(NULL, &eb);
- if (queuehandl == NULL) {
- System_abort("Queue create failed");
- }
- /*Initialize+start UART Task*/
- (void) setup_UART_Task();
- System_printf("Created UART Task\n");
- /* SysMin will only print to the console upon calling flush or exit */
- System_printf("Start BIOS\n");
- System_flush();
- /* Start BIOS */
- BIOS_start();
- }
- /*
- * setup task function
- */
- int setup_Blink_Task(led_descriptor_t *led_desc, uint32_t wait_ticks)
- {
- Task_Params taskLedParams;
- Task_Handle taskLed;
- Error_Block eb;
- /*configure gpio port_base according to led*/
- GPIOPinTypeGPIOOutput(led_desc->port_base, led_desc->led);
- /* Create Blink task with priority 15*/
- Error_init(&eb);
- Task_Params_init(&taskLedParams);
- taskLedParams.stackSize = 1024;/*stack in bytes*/
- taskLedParams.priority = 15;/*15 is default 16 is highest priority -> see RTOS configuration*/
- taskLedParams.arg0 = (UArg) led_desc;/*pass led descriptor to arg0*/
- taskLedParams.arg1 = (UArg) wait_ticks;
- taskLed = Task_create((Task_FuncPtr)BlinkFxn, &taskLedParams, &eb);
- if (taskLed == NULL) {
- System_abort("TaskLed create failed");
- }
- return (0);
- }
- long handle_input(char input,long inputval)
- {
- switch(input) {
- case 'w':
- System_printf("freq runter");
- break;
- case 's':
- System_printf("freq rauf");
- break;
- case 'a':
- System_printf("puls rauf");
- break;
- case 'd':
- System_printf("puls runter");
- break;
- case 13: //ENTER
- System_printf("%ld\n",inputval);
- break;
- case 8: //Backspace
- case 127:
- inputval=inputval/10;
- System_printf("backspace received.\n");
- break;
- case 66: //down key
- System_printf("\nDown Key\n");
- break;
- case 65: //up key
- System_printf("\nUp Key\n");
- break;
- case 67: //right key
- System_printf("\nright Key\n");
- break;
- case 68: //left key
- System_printf("\nleft Key\n");
- break;
- case 48://0-9
- inputval=inputval*10;
- System_printf("%l\n",inputval);
- break;
- case 49:
- case 50:
- case 51:
- case 52:
- case 53:
- case 54:
- case 55:
- case 56:
- case 57:
- case 58:
- case 59:
- inputval=inputval*10;
- inputval+=input-48;
- System_printf("%ld\n",inputval);
- break;
- default:
- //System_printf("%d",input);
- break;
- }
- System_flush();
- return inputval;
- }
- /*
- * ======== UART ========
- * Echo Characters recieved and show reception on Port N Led 0
- */
- void UARTFxn(UArg arg0, UArg arg1)
- {
- char input;
- UART_Handle uart;
- UART_Params uartParams;
- long inputval=0;
- const char echoPrompt[] = "\fEchoing characters:\r\n";
- /* Create a UART with data processing off. */
- UART_Params_init(&uartParams);
- uartParams.writeDataMode = UART_DATA_BINARY;
- uartParams.readDataMode = UART_DATA_BINARY;
- uartParams.readReturnMode = UART_RETURN_FULL;
- uartParams.readEcho = UART_ECHO_OFF;
- uartParams.baudRate = 9600;
- uart = UART_open(Board_UART0, &uartParams);
- if (uart == NULL) {
- System_abort("Error opening the UART");
- }
- UART_write(uart, echoPrompt, sizeof(echoPrompt));
- /* Loop forever echoing */
- while (1) {
- UART_read(uart, &input, 1);
- inputval=handle_input(input,inputval);
- UART_write(uart, &input, 1); //Remove this line to stop echoing!
- Task_sleep(5);
- }
- }
- /*
- * setup task function
- */
- int setup_UART_Task(void)
- {
- Task_Params taskUARTParams;
- Task_Handle taskUART;
- Error_Block eb;
- /* Enable and configure the peripherals used by the UART0 */
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
- GPIOPinConfigure(GPIO_PA0_U0RX);
- GPIOPinConfigure(GPIO_PA1_U0TX);
- GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
- UART_init();
- /* Create Uart task with priority 15*/
- Error_init(&eb);
- Task_Params_init(&taskUARTParams);
- taskUARTParams.stackSize = 1024;/*stack in bytes*/
- taskUARTParams.priority = 15;/*15 is default 16 is highest priority -> see RTOS configuration*/
- taskUART = Task_create((Task_FuncPtr)UARTFxn, &taskUARTParams, &eb);
- if (taskUART == NULL) {
- System_abort("TaskUART create failed");
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement