Advertisement
steschm0712

Untitled

Feb 14th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.24 KB | None | 0 0
  1. /*
  2.  *  ======== Blink_Task.c ========
  3.  *  Author: Michael Kramer / Matthias Wenzl
  4.  */
  5. #include <stdbool.h>
  6. #include <inc/hw_memmap.h>
  7.  
  8. /* XDCtools Header files */
  9. #include <xdc/std.h>
  10. #include <xdc/cfg/global.h>
  11. #include <xdc/runtime/System.h>
  12. #include <xdc/runtime/Error.h>
  13. #include <xdc/runtime/Memory.h>
  14.  
  15. /* BIOS Header files */
  16. #include <ti/sysbios/BIOS.h>
  17. #include <ti/sysbios/knl/Task.h>
  18. #include <ti/sysbios/knl/Semaphore.h>
  19. #include <ti/sysbios/knl/Queue.h>
  20. #include <ti/sysbios/knl/Mailbox.h>
  21. #include <ti/sysbios/knl/Event.h>
  22. #include <ti/sysbios/hal/Timer.h>
  23. #include <ti/sysbios/knl/Event.h>
  24.  
  25. /* TI-RTOS Header files */
  26. #include <ti/drivers/UART.h>
  27. #include <ti/drivers/GPIO.h>
  28. #include <driverlib/sysctl.h>
  29. #include <driverlib/i2c.h>
  30. #include <driverlib/ssi.h>
  31. #include <driverlib/uart.h>
  32. #include <driverlib/gpio.h>
  33. #include <driverlib/pin_map.h>
  34.  
  35.  
  36. /*Board Header files */
  37. #include <Board.h>
  38. #include <EK_TM4C1294XL.h>
  39.  
  40. /*application header files*/
  41. #include <ctype.h>
  42. #include <string.h>
  43.  
  44. #include <ctype.h>
  45. #include <string.h>
  46.  
  47. typedef struct {
  48.     uint32_t port_base;
  49.     uint8_t led;
  50. }led_descriptor_t;
  51.  
  52. int setup_UART_Task(void);
  53. void BlinkFxn(UArg arg0, UArg arg1);
  54. int setup_Blink_Task(led_descriptor_t *led_desc, uint32_t wait_ticks);
  55. void UARTFxn(UArg arg0, UArg arg1);
  56. long handle_input(char input,long inputval);
  57.  
  58. Queue_Handle queuehandl;
  59. typedef struct Queue_record {
  60.     Queue_Elem element;
  61.     long data;
  62. } queuerecord;
  63.  
  64. Semaphore_Handle semap;
  65.  
  66.  
  67. int main(void)
  68. {
  69.  
  70.     uint32_t ui32SysClock;
  71.     static led_descriptor_t led_desc[2];
  72.     Error_Block eb;
  73.  
  74.  
  75.     /* Call board init functions. */
  76.     ui32SysClock = Board_initGeneral(120*1000*1000);
  77.     (void)ui32SysClock; // We don't really need this (yet)
  78.  
  79.     Error_init(&eb);
  80.  
  81.  
  82.     /* Create a Semaphore object to be use as a resource lock */
  83.     semap = Semaphore_create(1, NULL, &eb);
  84.     if(semap == NULL) {
  85.         System_abort("Semaphore create failed");
  86.     }
  87.  
  88.     Error_init(&eb);
  89.     queuehandl = Queue_create(NULL, &eb);
  90.     if (queuehandl == NULL) {
  91.         System_abort("Queue create failed");
  92.     }
  93.  
  94.  
  95.  
  96.     /*Initialize+start UART Task*/
  97.     (void) setup_UART_Task();
  98.     System_printf("Created UART Task\n");
  99.  
  100.     /* SysMin will only print to the console upon calling flush or exit */
  101.  
  102.     System_printf("Start BIOS\n");
  103.     System_flush();
  104.  
  105.     /* Start BIOS */
  106.     BIOS_start();
  107.  
  108. }
  109.  
  110.  
  111.  
  112. /*
  113.  *  setup task function
  114.  */
  115. int setup_Blink_Task(led_descriptor_t *led_desc, uint32_t wait_ticks)
  116. {
  117.     Task_Params taskLedParams;
  118.     Task_Handle taskLed;
  119.     Error_Block eb;
  120.  
  121.     /*configure gpio port_base according to led*/
  122.     GPIOPinTypeGPIOOutput(led_desc->port_base, led_desc->led);
  123.    
  124.     /* Create Blink task with priority 15*/
  125.     Error_init(&eb);
  126.     Task_Params_init(&taskLedParams);
  127.     taskLedParams.stackSize = 1024;/*stack in bytes*/
  128.     taskLedParams.priority = 15;/*15 is default 16 is highest priority -> see RTOS configuration*/
  129.     taskLedParams.arg0 = (UArg) led_desc;/*pass led descriptor to arg0*/
  130.     taskLedParams.arg1 = (UArg) wait_ticks;
  131.     taskLed = Task_create((Task_FuncPtr)BlinkFxn, &taskLedParams, &eb);
  132.     if (taskLed == NULL) {
  133.         System_abort("TaskLed create failed");
  134.     }
  135.  
  136.     return (0);
  137. }
  138.  
  139. long handle_input(char input,long inputval)
  140. {
  141.  
  142.     switch(input) {
  143.     case 'w':
  144.         System_printf("freq runter");
  145.         break;
  146.     case 's':
  147.         System_printf("freq rauf");
  148.         break;
  149.     case 'a':
  150.         System_printf("puls rauf");
  151.         break;
  152.     case 'd':
  153.         System_printf("puls runter");
  154.         break;
  155.     case 13: //ENTER
  156.         System_printf("%ld\n",inputval);
  157.         break;
  158.     case 8: //Backspace
  159.     case 127:
  160.         inputval=inputval/10;
  161.         System_printf("backspace received.\n");
  162.         break;
  163.     case 66: //down key
  164.         System_printf("\nDown Key\n");
  165.         break;
  166.     case 65: //up key
  167.         System_printf("\nUp Key\n");
  168.         break;
  169.     case 67: //right key
  170.             System_printf("\nright Key\n");
  171.             break;
  172.     case 68: //left key
  173.             System_printf("\nleft Key\n");
  174.             break;
  175.     case 48://0-9
  176.             inputval=inputval*10;
  177.             System_printf("%l\n",inputval);
  178.             break;
  179.     case 49:
  180.     case 50:
  181.     case 51:
  182.     case 52:
  183.     case 53:
  184.     case 54:
  185.     case 55:
  186.     case 56:
  187.     case 57:
  188.     case 58:
  189.     case 59:
  190.         inputval=inputval*10;
  191.         inputval+=input-48;
  192.         System_printf("%ld\n",inputval);
  193.         break;
  194.     default:
  195.         //System_printf("%d",input);
  196.         break;
  197.     }
  198.     System_flush();
  199.     return inputval;
  200. }
  201. /*
  202.  *  ======== UART  ========
  203.  *  Echo Characters recieved and show reception on Port N Led 0
  204.  */
  205. void UARTFxn(UArg arg0, UArg arg1)
  206. {
  207.  
  208.     char input;
  209.     UART_Handle uart;
  210.     UART_Params uartParams;
  211.  
  212.     long inputval=0;
  213.  
  214.     const char echoPrompt[] = "\fEchoing characters:\r\n";
  215.  
  216.         /* Create a UART with data processing off. */
  217.         UART_Params_init(&uartParams);
  218.         uartParams.writeDataMode = UART_DATA_BINARY;
  219.         uartParams.readDataMode = UART_DATA_BINARY;
  220.         uartParams.readReturnMode = UART_RETURN_FULL;
  221.         uartParams.readEcho = UART_ECHO_OFF;
  222.         uartParams.baudRate = 9600;
  223.         uart = UART_open(Board_UART0, &uartParams);
  224.  
  225.         if (uart == NULL) {
  226.             System_abort("Error opening the UART");
  227.         }
  228.  
  229.         UART_write(uart, echoPrompt, sizeof(echoPrompt));
  230.  
  231.         /* Loop forever echoing */
  232.         while (1) {
  233.             UART_read(uart, &input, 1);
  234.             inputval=handle_input(input,inputval);
  235.             UART_write(uart, &input, 1); //Remove this line to stop echoing!
  236.             Task_sleep(5);
  237.  
  238.         }
  239.  
  240.  
  241. }
  242.  
  243.  
  244. /*
  245.  *  setup task function
  246.  */
  247. int setup_UART_Task(void)
  248. {
  249.     Task_Params taskUARTParams;
  250.     Task_Handle taskUART;
  251.     Error_Block eb;
  252.  
  253.  
  254.     /* Enable and configure the peripherals used by the UART0 */
  255.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  256.     SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  257.     GPIOPinConfigure(GPIO_PA0_U0RX);
  258.     GPIOPinConfigure(GPIO_PA1_U0TX);
  259.     GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  260.     UART_init();
  261.  
  262.  
  263.     /* Create Uart task with priority 15*/
  264.     Error_init(&eb);
  265.     Task_Params_init(&taskUARTParams);
  266.     taskUARTParams.stackSize = 1024;/*stack in bytes*/
  267.     taskUARTParams.priority = 15;/*15 is default 16 is highest priority -> see RTOS configuration*/
  268.     taskUART = Task_create((Task_FuncPtr)UARTFxn, &taskUARTParams, &eb);
  269.     if (taskUART == NULL) {
  270.         System_abort("TaskUART create failed");
  271.     }
  272.  
  273.     return (0);
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement