Other Parts Discussed in Thread: SYSBIOS,
Tool/software: TI-RTOS
i am trying to write a program blinking led using semaphore can u share any referance program
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI-RTOS
i am trying to write a program blinking led using semaphore can u share any referance program
Hi Sateesh,
Here is a modified gpiointerrupt.c file from the GPIO Interrupt example. An ISR (GPIO callback) calls Semaphore_pend to release a Task that will toggle an LED.
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== gpiointerrupt.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
/* Example/Board Header files */
#include "Board.h"
/* variable to be read by GUI Composer */
int count = 0;
Semaphore_Handle semHandle;
Task_Handle taskHandle;
/*
* ======== gpioButtonFxn0 ========
* Callback function for the GPIO interrupt on Board_BUTTON0.
*/
void gpioButtonFxn0(unsigned int index)
{
/* Clear the GPIO interrupt and toggle an LED */
//GPIO_toggle(Board_LED0);
Semaphore_post(semHandle);
if (count++ == 100) {
count = 0;
}
}
/*
* ======== gpioButtonFxn1 ========
* Callback function for the GPIO interrupt on Board_BUTTON1.
* This may not be used for all boards.
*/
void gpioButtonFxn1(unsigned int index)
{
/* Clear the GPIO interrupt and toggle an LED */
GPIO_toggle(Board_LED1);
if (count++ == 100) {
count = 0;
}
}
Void myTaskFxn(UArg arg0, UArg arg1)
{
while(1) {
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
GPIO_toggle(Board_LED0);
}
}
/*
* ======== main ========
*/
int main(void)
{
Error_Block eb;
Error_init(&eb);
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initUART();
Semaphore_Params semParams;
/*
* Use counting semaphore...which is the default, but just to show how
* to explicit set it.
*/
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_COUNTING;
semHandle = Semaphore_create(0, &semParams, &eb);
if (semHandle == NULL) {
System_abort("Semaphore_create failed");
}
/* Use default params */
taskHandle = Task_create(myTaskFxn, NULL, &eb);
if (taskHandle == NULL) {
System_abort("Task_create failed");
}
/* Turn on user LED */
GPIO_write(Board_LED0, Board_LED_ON);
System_printf("Starting the GPIO Interrupt example\nSystem provider is set"
" to SysMin. Halt the target to view any SysMin contents in"
" ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* install Button callback */
GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);
/* Enable interrupts */
GPIO_enableInt(Board_BUTTON0);
/*
* If more than one input pin is available for your device, interrupts
* will be enabled on Board_BUTTON1.
*/
if (Board_BUTTON0 != Board_BUTTON1) {
/* install Button callback */
GPIO_setCallback(Board_BUTTON1, gpioButtonFxn1);
GPIO_enableInt(Board_BUTTON1);
}
/* Start BIOS */
BIOS_start();
return (0);
}
Todd