Ti-rtos Control LED Light

Source: Internet
Author: User

TI will freertos on their own chip, so get ti-rtos, the difference between the two I'm not too clear, recently because the project needs, began to try Ti-rtos, first to a lighting experiment bar, is Hello World.

This time the board is CC1310 LaunchPad Rev 1.3, which has two lights, two keys, according to the common sense of the first light driver will be more simple. Plan to make a light, a light 1 seconds flash once.

Such a function is generally and timer, IO deal with, but on the OS, timing can temporarily use Task_sleep to replace, fortunately Ti-rtos enabled this module by default, it is quite convenient to use.

The driver for IO is written, and it can be used to find the API name. The code is as follows:

/**************************************************************************************************
Filename:ledtask.c
Editor:tome @ newbit
Revised: $Date: 2016-8-10 11:20:02 +0800 $
Revision: $Revision: 00001 $

Description: Understanding the use of Ti-rtos, Gpio control, task hibernation
History:
Notes: To understand this part of the interface, you can read the TI document
1. Ti-rtos 2.20 User ' s Guide.pdf
2. Bios User Guide.pdf

Hardware platform Cc1130_launchpad Rev1.3

**************************************************************************************************/

/**************************************************************************************************
Includes
**************************************************************************************************/
/* 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>

/* Ti-rtos Header Files */
#include <ti/drivers/PIN.h>


#include "Board.h"


/**************************************************************************************************
TYPEDEF
**************************************************************************************************/

/**************************************************************************************************
CONSTANTS
**************************************************************************************************/
#define TASKSTACKSIZE 768


/**************************************************************************************************
LOCAL veriable
**************************************************************************************************/
Task_struct ledtaskstruct;
Char Ledtaskstack[taskstacksize]; Stack space for this task, static assignment


/* Global memory storage for a pin_config table */
Static Pin_state ledpinstate;


/*
* Application LED pin configuration table:
*-All LEDs board LEDs is off.
*/
Pin_config ledpintable[] = {
board_led1 | Pin_gpio_output_en | Pin_gpio_low | Pin_pushpull | Pin_drvstr_max,
Board_led2 | Pin_gpio_output_en | Pin_gpio_low | Pin_pushpull | Pin_drvstr_max,
Pin_terminate
};

/**************************************************************************************************
FUNCTIONS decleration
**************************************************************************************************/
Void ledfxn (Uarg arg0, Uarg arg1);

/**************************************************************************************************
FUNCTIONS
**************************************************************************************************/

/**************************************************************************************************
* @fn Ledtaskadd
*
* @brief
*
* @param void
*
* @return void
**************************************************************************************************/
void Ledtaskadd (void)
{
Task_params Taskparams;

/* Construct BIOS Objects */
Task_params_init (&taskparams); The parameters that are required to create the task are set to the default values
Taskparams.stacksize = taskstacksize; Stack space
Taskparams.stack = &ledTaskStack; Stack Address
To pass parameters to the BIOS and set up a control light task
Task_construct (&ledtaskstruct, (task_funcptr) ledfxn, &taskparams, NULL);
}


/*
* ======== LEDFXN ========
* Task for this function is created statically. See Ledtaskadd ().
*/
Void ledfxn (Uarg arg0, Uarg arg1)
{
Pin_handle Ledpinhandle;
uint_t ledstate;


This is not to initialize, but to get the handle of the operation (handle)
Function Description: Allocate One or more pins for a driver or an application.
Ledpinhandle = Pin_open (&ledpinstate, ledpintable);
if (!ledpinhandle) {
System_abort ("Error Initializing Board LED pins\n");
}

Light the first LED light.
Pin_setoutputvalue (Ledpinhandle, board_led1, 1);


while (1)
{
Read the status of the LED light and set it to the opposite state
Ledstate = Pin_getoutputvalue (BOARD_LED2);
Ledstate =!ledstate;
The set operation requires handle
Pin_setoutputvalue (Ledpinhandle, Board_led2, ledstate);

Task hibernation 1 seconds, 1000000US, the following function is the unit 10US
Task_sleep (100000);
}

}

/**************************************************************************************************
Copyright newbit Studio. All rights reserved.
**************************************************************************************************/

Ti-rtos Control LED Light

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.