Commit 5581084e authored by Stefan Tauner's avatar Stefan Tauner
Browse files

Clean up blink example

 - indentation, whitespace
 - includes
 - typos
 - additional comments
parent a35a5402
......@@ -3,9 +3,9 @@
* Author: Michael Kramer / Matthias Wenzl
*/
#include <stdbool.h>
#include <stdint.h>
#include <inc/hw_memmap.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
......@@ -17,62 +17,58 @@
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* Driverlib headers */
#include <driverlib/gpio.h>
/*Board Header files */
#include <Blink_Task.h>
/* Board Header files */
#include <Board.h>
#include <EK_TM4C1294XL.h>
#include <ctype.h>
#include <string.h>
/* Application headers */
#include "Blink_Task.h"
/*
* ======== Blink ========
* Perform Blink Operation on led given at arg0
* Perform blink operation on LED given as arg0, with period defined by arg1.
*/
void BlinkFxn(UArg arg0, UArg arg1)
{
led_descriptor_t *led_desc = (led_descriptor_t *)arg0;
uint32_t wait_ticks = (uint32_t)arg1;
/* GPIO driverlib API uses same bit pattern for GPIO mask and value. */
uint8_t ui8val = (uint8_t)led_desc->led;
led_descriptor_t *led_desc = (led_descriptor_t *)arg0;
uint32_t wait_ticks = (uint32_t) arg1;
/*gpio driverlib api uses same bit pattern for gpio mask and value*/
uint8_t ui8val = (uint8_t)led_desc->led;
while(1) {
ui8val ^= (uint8_t)led_desc->led;//initially off
GPIOPinWrite (led_desc->port_base, led_desc->led, ui8val);
Task_sleep(wait_ticks);
}
while(1) {
ui8val ^= (uint8_t)led_desc->led; // initially off
GPIOPinWrite (led_desc->port_base, led_desc->led, ui8val);
Task_sleep(wait_ticks);
}
}
/*
* setup task function
* 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*/
Task_Params taskLedParams;
Task_Handle taskLed;
Error_Block eb;
/* Configure GPIO port_base according to LED descriptor */
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;/*0-15 (15 is highest priority on default -> see RTOS Task configuration)*/
taskLedParams.arg0 = (UArg) led_desc;/*pass led descriptor to arg0*/
taskLedParams.arg1 = (UArg) wait_ticks;
taskLedParams.stackSize = 1024; /* stack in bytes */
taskLedParams.priority = 15; /* 0-15 (15 is highest priority on default -> see RTOS Task configuration) */
taskLedParams.arg0 = (UArg)led_desc; /* pass led descriptor as arg0 */
taskLedParams.arg1 = (UArg)wait_ticks; /* pass periods in ticks as arg1 */
taskLed = Task_create((Task_FuncPtr)BlinkFxn, &taskLedParams, &eb);
if (taskLed == NULL) {
System_abort("TaskLed create failed");
System_abort("TaskLed create failed");
}
return (0);
......
/*
* CCSv6 project using TI-RTOS
*
*/
/*
* ======== StartBIOS.c ========
*/
#include <stdbool.h>
#include <stdint.h>
#include <inc/hw_memmap.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
......@@ -15,58 +14,45 @@
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Mailbox.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/hal/Timer.h>
#include <ti/sysbios/knl/Event.h>
/* TI-RTOS Header files */
#include <ti/drivers/UART.h>
/* Driverlib headers */
#include <driverlib/gpio.h>
/*Board Header files */
/* Board Header files */
#include <Board.h>
#include <EK_TM4C1294XL.h>
/*application header files*/
#include <ctype.h>
#include <string.h>
/* Application headers */
#include <Blink_Task.h>
#include <UART_Task.h>
int main(void)
{
uint32_t ui32SysClock;
static led_descriptor_t led_desc[2];
/* Call board init functions. */
ui32SysClock = Board_initGeneral(120*1000*1000);
(void)ui32SysClock; // We don't really need this (yet)
led_desc[0].port_base = GPIO_PORTN_BASE;
led_desc[0].led = GPIO_PIN_1;
/*Initialize+start Blink Task*/
(void) setup_Blink_Task(&led_desc[0], 500);
/*System_printf() is VERY slow!*/
System_printf("Created Blink Task1\n");
System_flush();
/* Call board init functions. */
ui32SysClock = Board_initGeneral(120*1000*1000);
(void)ui32SysClock; // We don't really need this (yet)
led_desc[0].port_base = GPIO_PORTN_BASE;
led_desc[0].led = GPIO_PIN_1;
/* Initialize+start Blink Task*/
(void)setup_Blink_Task(&led_desc[0], 500);
/* System_printf() is VERY slow!*/
System_printf("Created Blink Task1\n");
System_flush();
led_desc[1].port_base = GPIO_PORTF_BASE;
led_desc[1].led = GPIO_PIN_0;
/*Initialize+start Blink Task*/
(void) setup_Blink_Task(&led_desc[1], 250);
System_printf("Created Blink Task2\n");
System_flush();
led_desc[1].port_base = GPIO_PORTF_BASE;
led_desc[1].led = GPIO_PIN_0;
/*Initialize+start Blink Task*/
(void)setup_Blink_Task(&led_desc[1], 250);
System_printf("Created Blink Task2\n");
System_flush();
/*Initialize+start UART Task*/
(void) setup_UART_Task();
System_printf("Created UART Task\n");
/*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 */
......@@ -75,5 +61,4 @@ int main(void)
/* Start BIOS */
BIOS_start();
}
......@@ -3,9 +3,9 @@
* Author: Michael Kramer / Matthias Wenzl
*/
#include <stdbool.h>
#include <stdint.h>
#include <inc/hw_memmap.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
......@@ -19,21 +19,19 @@
/* TI-RTOS Header files */
#include <driverlib/sysctl.h>
#include <driverlib/i2c.h>
#include <driverlib/ssi.h>
#include <driverlib/uart.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>
/* Driverlib headers */
#include <driverlib/gpio.h>
#include <driverlib/pin_map.h>
/*Board Header files */
#include <Blink_Task.h>
#include <Board.h>
#include <EK_TM4C1294XL.h>
/* Application headers */
#include "UART_Task.h"
#include <ctype.h>
#include <string.h>
/*
* ======== UART ========
......@@ -41,70 +39,65 @@
*/
void UARTFxn(UArg arg0, UArg arg1)
{
UART_Handle uart;
UART_Params uartParams;
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");
}
char input;
UART_Handle uart;
UART_Params uartParams;
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);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 1);
UART_write(uart, &input, 1); //Remove this line to stop echoing!
Task_sleep(5);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
}
UART_write(uart, echoPrompt, sizeof(echoPrompt));
/* Loop forever echoing */
while (1) {
char input;
UART_read(uart, &input, 1);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 1);
UART_write(uart, &input, 1); // Remove this line to stop echoing!
Task_sleep(5);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
}
}
/*
* setup task function
* Setup task function
*/
int setup_UART_Task(void)
{
Task_Params taskUARTParams;
Task_Handle taskUART;
Error_Block eb;
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);
/* 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();
//Setup PortN LED1 activity signaling
/* Setup PortN LED1 activity signaling */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0);
/* Create Blink task with priority 15*/
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
Error_init(&eb);
Task_Params_init(&taskUARTParams);
taskUARTParams.stackSize = 1024;/*stack in bytes*/
taskUARTParams.priority = 15;/*0-15 (15 is highest priority on default -> see RTOS Task configuration)*/
taskUARTParams.stackSize = 1024; /* stack in bytes */
taskUARTParams.priority = 15; /* 0-15 (15 is highest priority on default -> see RTOS Task configuration) */
taskUART = Task_create((Task_FuncPtr)UARTFxn, &taskUARTParams, &eb);
if (taskUART == NULL) {
System_abort("TaskUART create failed");
System_abort("TaskUART create failed");
}
return (0);
......
......@@ -3,38 +3,30 @@
\author Matthias Wenzl
\author Michael Kramer
Blinking LED Task example.
*/
#include <stdbool.h>
#include <stdint.h>
/* Drivers Header files - fall back to driverlib for gpio*/
#include <driverlib/gpio.h>
#include <driverlib/pin_map.h>
#include <inc/hw_memmap.h>
#ifndef BLINK_TASK_H_
#define BLINK_TASK_H_
#include <stdbool.h>
#include <stdint.h>
#include <xdc/std.h>
typedef struct {
uint32_t port_base;
uint8_t led;
}led_descriptor_t;
} led_descriptor_t;
/*! \fn BlinkFxn
* \brief Execute Blink Task
*
*
* \param arg0 led descriptor struct
* \param arg1 Ticks to wait
*
*/
*/
void BlinkFxn(UArg arg0, UArg arg1);
/*! \fn setup_Blink_Task
......@@ -43,13 +35,11 @@ void BlinkFxn(UArg arg0, UArg arg1);
* Setup Blink task
* Task has highest priority and receives 1kB of stack
*
* \param led description.
* \param time wo wait in ticks for led to toggle
* \param led_desc LED descriptor.
* \param time to wait in ticks for led to toggle
*
* \return always zero. In case of error the system halts.
*/
*/
int setup_Blink_Task(led_descriptor_t *led_desc, uint32_t wait_ticks);
#endif /* UIP_TASK_H_ */
#endif
......@@ -8,18 +8,12 @@
*/
#include <stdbool.h>
#include <stdint.h>
/* Drivers Header files - fall back to driverlib for gpio*/
#include <driverlib/gpio.h>
#include <driverlib/pin_map.h>
#include <inc/hw_memmap.h>
#ifndef UART_TASK_H_
#define UART_TASK_H_
#include <stdbool.h>
#include <stdint.h>
#include <xdc/std.h>
/*! \fn UARTFxn
......@@ -29,7 +23,7 @@
* \param arg0 void
* \param arg1 void
*
*/
*/
void UARTFxn(UArg arg0, UArg arg1);
/*! \fn setup_UART_Task
......@@ -39,9 +33,7 @@ void UARTFxn(UArg arg0, UArg arg1);
* Task has highest priority and receives 1kB of stack
*
* \return always zero. In case of error the system halts.
*/
*/
int setup_UART_Task(void);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment