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.

RTOS/TM4C123GH6PM: i am trying to write a program blinking led using semaphore can u share any referance program?

Part Number: TM4C123GH6PM
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

  • 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

  • **** Build of configuration Debug for project task_TivaTM4C123GH6PM ****

    "D:\\ti\\ccsv7\\utils\\bin\\gmake" -k -j 4 all -O

    making ../src/sysbios/sysbios.aem4f ...
    gmake[1]: Nothing to be done for 'all'.
    'Building file: "../mutex.c"'
    'Invoking: ARM Compiler'
    "D:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.6.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="C:/Users/sateesh/workspace_v7/task_TivaTM4C123GH6PM" --include_path="C:/ti/bios_6_73_01_01/packages/ti/posix/ccs" --include_path="D:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.6.LTS/include" --define=ccs="ccs" --define=PART_TM4C123GH6PM -g --gcc --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --abi=eabi --preproc_with_compile --preproc_dependency="mutex.d_raw" --cmd_file="configPkg/compiler.opt" "../mutex.c"

    >> Compilation failure
    subdir_rules.mk:9: recipe for target 'mutex.obj' failed
    "../mutex.c", line 48: fatal error #1965: cannot open source file "ti/drivers/GPIO.h"
    1 catastrophic error detected in the compilation of "../mutex.c".
    Compilation terminated.
    gmake: *** [mutex.obj] Error 1
    gmake: Target 'all' not remade because of errors.

    **** Build Finished ****


    getting error sir please help me .
  • Please open a new thread with more description.
  • send header files also hear ti/driver/GPIO.h and "Board.h" am stucked here i don't have idea please help me sir.