Demo tasks:
- Complete the demo projects for the RX113 using IAR, GCC and Renesas compilers by including a basic UART CLI. Standard demo tasks: - Add some volatile qualifiers to variables in IntQueue.c.pull/1/head
parent
cd42d2c215
commit
f218cf5680
@ -1,112 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only
|
||||
* intended for use with Renesas products. No other uses are authorized. This
|
||||
* software is owned by Renesas Electronics Corporation and is protected under
|
||||
* all applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
|
||||
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
|
||||
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
|
||||
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
|
||||
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
|
||||
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software
|
||||
* and to discontinue the availability of this software. By using this software,
|
||||
* you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*******************************************************************************/
|
||||
/* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved. */
|
||||
/*******************************************************************************
|
||||
* File Name : r_rsk_async.c
|
||||
* Version : 1.00
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* H/W Platform : RSKRX113
|
||||
* Description : Functions used to send data via the SCI in asynchronous mode
|
||||
*******************************************************************************/
|
||||
/*******************************************************************************
|
||||
* History : 26.08.2014 Ver. 1.00 First Release
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
System Includes
|
||||
*******************************************************************************/
|
||||
/* Following header file provides string type definitions. */
|
||||
#include <string.h>
|
||||
|
||||
/*******************************************************************************
|
||||
User Includes (Project Level Includes)
|
||||
*******************************************************************************/
|
||||
/* Defines port registers */
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_sci.h"
|
||||
#include "r_rsk_async.h"
|
||||
|
||||
/*******************************************************************************
|
||||
User Defines
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global Variables
|
||||
*******************************************************************************/
|
||||
|
||||
/* Declaration of the command string to clear the terminal screen */
|
||||
static const char cmd_clr_scr[] =
|
||||
{ 27, 91, 50, 74, 0, 27, 91, 72, 0 };
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Prototypes
|
||||
*******************************************************************************/
|
||||
|
||||
/* text_write function prototype */
|
||||
static void text_write (const char * const msg_string);
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name: R_ASYNC_Init
|
||||
* Description : This function initialises the SCI channel connected to the
|
||||
* RS232 connector on the RSK. The channel is configured for
|
||||
* transmission and reception, and instructions are sent to the
|
||||
* terminal.
|
||||
* Argument : none
|
||||
* Return value : none
|
||||
*******************************************************************************/
|
||||
void R_ASYNC_Init (void)
|
||||
{
|
||||
|
||||
/* Set up SCI1 receive buffer */
|
||||
R_SCI1_Serial_Receive((uint8_t *) &g_rx_char, 1);
|
||||
|
||||
/* Enable SCI1 operations */
|
||||
R_SCI1_Start();
|
||||
|
||||
/* Clear the text on terminal window */
|
||||
text_write(cmd_clr_scr);
|
||||
|
||||
/* Display splash screen on terminal window */
|
||||
text_write("Renesas RSKRX113 Async Serial \r\n");
|
||||
|
||||
/* Inform user on how to stop transmission */
|
||||
text_write("Press 'z' to stop and any key to resume\r\n\n");
|
||||
}
|
||||
/*******************************************************************************
|
||||
* End of function R_ASYNC_Init
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : text_write
|
||||
* Description : Transmits null-terminated string.
|
||||
* Argument : (char*) msg_string - null terminated string
|
||||
* Return value : None
|
||||
*******************************************************************************/
|
||||
static void text_write (const char * const msg_string)
|
||||
{
|
||||
R_SCI1_AsyncTransmit((uint8_t *) msg_string, (uint16_t) strlen(msg_string));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* End of function text_write
|
||||
*******************************************************************************/
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only
|
||||
* intended for use with Renesas products. No other uses are authorized. This
|
||||
* software is owned by Renesas Electronics Corporation and is protected under
|
||||
* all applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
|
||||
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
|
||||
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
|
||||
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
|
||||
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
|
||||
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software
|
||||
* and to discontinue the availability of this software. By using this software,
|
||||
* you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*******************************************************************************/
|
||||
/* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved. */
|
||||
/*******************************************************************************
|
||||
* File Name : r_rsk_async.h
|
||||
* Version : 1.00
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* H/W Platform : RSKRX113
|
||||
* Description : Functions used to send data via the SCI in asynchronous mode
|
||||
******************************************************************************/
|
||||
/*******************************************************************************
|
||||
* History : 26.08.2014 Ver. 1.00 First Release
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Definitions
|
||||
*******************************************************************************/
|
||||
/* Multiple inclusion prevention macro */
|
||||
#ifndef R_RSK_ASYNC_H
|
||||
#define R_RSK_ASYNC_H
|
||||
|
||||
/*******************************************************************************
|
||||
* Global Function Prototypes
|
||||
*******************************************************************************/
|
||||
/* initialise asynchronous transmission*/
|
||||
void R_ASYNC_Init (void);
|
||||
|
||||
/* End of multiple inclusion prevention macro */
|
||||
#endif
|
||||
|
@ -1,86 +0,0 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_sbrk.c
|
||||
* Version : Code Generator for RX113 V1.02.01.02 [28 May 2015]
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* Description : Program of sbrk.
|
||||
* Creation Date: 21/09/2015
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include "r_cg_sbrk.h"
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
int8_t *sbrk(size_t size);
|
||||
|
||||
extern int8_t *_s1ptr;
|
||||
|
||||
union HEAP_TYPE
|
||||
{
|
||||
int16_t dummy ; /* Dummy for 4-byte boundary */
|
||||
int8_t heap[HEAPSIZE]; /* Declaration of the area managed by sbrk */
|
||||
};
|
||||
|
||||
static union HEAP_TYPE heap_area ;
|
||||
|
||||
/* End address allocated by sbrk */
|
||||
static int8_t *brk = (int8_t *) &heap_area;
|
||||
|
||||
/**************************************************************************/
|
||||
/* sbrk:Memory area allocation */
|
||||
/* Return value:Start address of allocated area (Pass) */
|
||||
/* -1 (Failure) */
|
||||
/**************************************************************************/
|
||||
int8_t *sbrk(size_t size) /* Assigned area size */
|
||||
{
|
||||
int8_t *p;
|
||||
|
||||
if (brk+size > heap_area.heap + HEAPSIZE) /* Empty area size */
|
||||
{
|
||||
p = (int8_t *)-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = brk; /* Area assignment */
|
||||
brk += size; /* End address update */
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
@ -1,48 +0,0 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_sbrk.h
|
||||
* Version : Code Generator for RX113 V1.02.01.02 [28 May 2015]
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* Description : Header file of sbrk file.
|
||||
* Creation Date: 21/09/2015
|
||||
***********************************************************************************************************************/
|
||||
#ifndef _SBRK_H
|
||||
#define _SBRK_H
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions (Register bit)
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Typedef definitions
|
||||
***********************************************************************************************************************/
|
||||
#define HEAPSIZE (0x400U) /* Size of area managed by sbrk */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global functions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#endif
|
@ -0,0 +1,364 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_sci_user.c
|
||||
* Version : Code Generator for RX113 V1.02.01.02 [28 May 2015]
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* Description : This file implements device driver for SCI module.
|
||||
* Creation Date: 21/09/2015
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
|
||||
|
||||
/*
|
||||
* This file originated from an example project for the RSK - it has been
|
||||
* adapted to allow it to be used in the FreeRTOS demo. Functions required by
|
||||
* UARTCommandConsole.c have been added.
|
||||
*
|
||||
* ***NOTE***: Transmitting generates an interrupt for each character, which
|
||||
* consumes CPU time, and can cause standard demo RTOS tasks that monitor their
|
||||
* own performance to fail asserts - therefore when using GCC it is best to
|
||||
* compile this file with maximum speed optimisation.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_sci.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
#include "rskrx113def.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "serial.h"
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
extern uint8_t * gp_sci1_tx_address; /* SCI1 send buffer address */
|
||||
extern uint16_t g_sci1_tx_count; /* SCI1 send data number */
|
||||
extern uint8_t * gp_sci1_rx_address; /* SCI1 receive buffer address */
|
||||
extern uint16_t g_sci1_rx_count; /* SCI1 receive data number */
|
||||
extern uint16_t g_sci1_rx_length; /* SCI1 receive data length */
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
|
||||
/* Global used to receive a character from the PC terminal */
|
||||
uint8_t g_rx_char;
|
||||
|
||||
/* Flag used to control transmission to PC terminal */
|
||||
volatile uint8_t g_tx_flag = FALSE;
|
||||
|
||||
/* Characters received from the UART are stored in this queue, ready to be
|
||||
received by the application. ***NOTE*** Using a queue in this way is very
|
||||
convenient, but also very inefficient. It can be used here because characters
|
||||
will only arrive slowly. In a higher bandwidth system a circular RAM buffer or
|
||||
DMA should be used in place of this queue. */
|
||||
static QueueHandle_t xRxQueue = NULL;
|
||||
|
||||
/* When a task calls vSerialPutString() its handle is stored in xSendingTask,
|
||||
before being placed into the Blocked state (so does not use any CPU time) to
|
||||
wait for the transmission to end. The task handle is then used from the UART
|
||||
transmit end interrupt to remove the task from the Blocked state. */
|
||||
static TaskHandle_t xSendingTask = NULL;
|
||||
|
||||
/* Flag used locally to detect transmission complete. This is used by the
|
||||
auto generated API only. */
|
||||
static volatile uint8_t sci1_txdone;
|
||||
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_transmit_interrupt
|
||||
* Description : None
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_transmit_interrupt(void) __attribute__((interrupt));
|
||||
void r_sci1_transmit_interrupt(void)
|
||||
{
|
||||
if (g_sci1_tx_count > 0U)
|
||||
{
|
||||
SCI1.TDR = *gp_sci1_tx_address;
|
||||
gp_sci1_tx_address++;
|
||||
g_sci1_tx_count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCI1.SCR.BIT.TIE = 0U;
|
||||
SCI1.SCR.BIT.TEIE = 1U;
|
||||
}
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_transmitend_interrupt
|
||||
* Description : None
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_transmitend_interrupt(void) __attribute__((interrupt));
|
||||
void r_sci1_transmitend_interrupt(void)
|
||||
{
|
||||
/* Set TXD1 pin */
|
||||
PORT1.PMR.BYTE &= 0xBFU;
|
||||
SCI1.SCR.BIT.TIE = 0U;
|
||||
SCI1.SCR.BIT.TE = 0U;
|
||||
SCI1.SCR.BIT.TEIE = 0U;
|
||||
|
||||
r_sci1_callback_transmitend();
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_receive_interrupt
|
||||
* Description : None
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_receive_interrupt(void) __attribute__((interrupt));
|
||||
void r_sci1_receive_interrupt(void)
|
||||
{
|
||||
if (g_sci1_rx_length > g_sci1_rx_count)
|
||||
{
|
||||
*gp_sci1_rx_address = SCI1.RDR;
|
||||
gp_sci1_rx_address++;
|
||||
g_sci1_rx_count++;
|
||||
|
||||
if (g_sci1_rx_length == g_sci1_rx_count)
|
||||
{
|
||||
r_sci1_callback_receiveend();
|
||||
}
|
||||
}
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_receiveerror_interrupt
|
||||
* Description : None
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_receiveerror_interrupt(void) __attribute__((interrupt));
|
||||
void r_sci1_receiveerror_interrupt(void)
|
||||
{
|
||||
uint8_t err_type;
|
||||
|
||||
r_sci1_callback_receiveerror();
|
||||
|
||||
/* Clear overrun, framing and parity error flags */
|
||||
err_type = SCI1.SSR.BYTE;
|
||||
SCI1.SSR.BYTE = err_type & ( uint8_t ) 0xC7;
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_callback_transmitend
|
||||
* Description : This function is a callback function when SCI1 finishes transmission.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_callback_transmitend(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
/* The sci1_txdone flag is used by the auto generated API only. */
|
||||
sci1_txdone = TRUE;
|
||||
|
||||
if( xSendingTask != NULL )
|
||||
{
|
||||
/* A task is waiting for the end of the Tx, unblock it now.
|
||||
http://www.freertos.org/vTaskNotifyGiveFromISR.html */
|
||||
vTaskNotifyGiveFromISR( xSendingTask, &xHigherPriorityTaskWoken );
|
||||
xSendingTask = NULL;
|
||||
|
||||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||||
}
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_callback_receiveend
|
||||
* Description : This function is a callback function when SCI1 finishes reception.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_callback_receiveend(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
configASSERT( xRxQueue );
|
||||
|
||||
/* Transmitting generates an interrupt for each character, which consumes
|
||||
CPU time, and can cause standard demo RTOS tasks that monitor their own
|
||||
performance to fail asserts - so don't receive new CLI commands if a
|
||||
transmit is not already in progress. */
|
||||
if( sci1_txdone == TRUE )
|
||||
{
|
||||
/* Characters received from the UART are stored in this queue, ready to be
|
||||
received by the application. ***NOTE*** Using a queue in this way is very
|
||||
convenient, but also very inefficient. It can be used here because
|
||||
characters will only arrive slowly. In a higher bandwidth system a circular
|
||||
RAM buffer or DMA should be used in place of this queue. */
|
||||
xQueueSendFromISR( xRxQueue, &g_rx_char, &xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
||||
/* Set up SCI1 receive buffer again */
|
||||
R_SCI1_Serial_Receive((uint8_t *) &g_rx_char, 1);
|
||||
|
||||
/* See http://www.freertos.org/xQueueOverwriteFromISR.html for information
|
||||
on the semantics of this ISR. */
|
||||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_sci1_callback_receiveerror
|
||||
* Description : This function is a callback function when SCI1 reception encounters error.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void r_sci1_callback_receiveerror(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_SCI1_AsyncTransmit
|
||||
* Description : This function sends SCI1 data and waits for the transmit end flag.
|
||||
* Arguments : tx_buf -
|
||||
* transfer buffer pointer
|
||||
* tx_num -
|
||||
* buffer size
|
||||
* Return Value : status -
|
||||
* MD_OK or MD_ARGERROR
|
||||
***********************************************************************************************************************/
|
||||
MD_STATUS R_SCI1_AsyncTransmit (uint8_t * const tx_buf, const uint16_t tx_num)
|
||||
{
|
||||
MD_STATUS status = MD_OK;
|
||||
|
||||
/* clear the flag before initiating a new transmission */
|
||||
sci1_txdone = FALSE;
|
||||
|
||||
/* Send the data using the API */
|
||||
status = R_SCI1_Serial_Send(tx_buf, tx_num);
|
||||
|
||||
/* Wait for the transmit end flag */
|
||||
while (FALSE == sci1_txdone)
|
||||
{
|
||||
/* Wait */
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
/***********************************************************************************************************************
|
||||
* End of function R_SCI1_AsyncTransmit
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/* Function required in order to link UARTCommandConsole.c - which is used by
|
||||
multiple different demo application. */
|
||||
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
|
||||
{
|
||||
( void ) ulWantedBaud;
|
||||
( void ) uxQueueLength;
|
||||
|
||||
/* Characters received from the UART are stored in this queue, ready to be
|
||||
received by the application. ***NOTE*** Using a queue in this way is very
|
||||
convenient, but also very inefficient. It can be used here because
|
||||
characters will only arrive slowly. In a higher bandwidth system a circular
|
||||
RAM buffer or DMA should be used in place of this queue. */
|
||||
xRxQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
|
||||
configASSERT( xRxQueue );
|
||||
|
||||
/* Set up SCI1 receive buffer */
|
||||
R_SCI1_Serial_Receive((uint8_t *) &g_rx_char, 1);
|
||||
|
||||
/* Ensure the interrupt priority is at or below
|
||||
configMAX_SYSCALL_INTERRUPT_PRIORITY. */
|
||||
IPR( SCI1, ERI1 ) = configKERNEL_INTERRUPT_PRIORITY + 1;
|
||||
|
||||
/* Enable SCI1 operations */
|
||||
R_SCI1_Start();
|
||||
|
||||
/* Only one UART is supported, so it doesn't matter what is returned
|
||||
here. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Function required in order to link UARTCommandConsole.c - which is used by
|
||||
multiple different demo application. */
|
||||
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
|
||||
{
|
||||
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 5000 );
|
||||
|
||||
/* Only one port is supported. */
|
||||
( void ) pxPort;
|
||||
|
||||
/* Clear the flag before initiating a new transmission */
|
||||
sci1_txdone = FALSE;
|
||||
|
||||
/* Don't send the string unless the previous string has been sent. */
|
||||
if( xSendingTask == NULL )
|
||||
{
|
||||
/* Ensure the calling task's notification state is not already
|
||||
pending. */
|
||||
vTaskNotifyClear( NULL );
|
||||
|
||||
/* Store the handle of the transmitting task. This is used to unblock
|
||||
the task when the transmission has completed. */
|
||||
xSendingTask = xTaskGetCurrentTaskHandle();
|
||||
|
||||
/* Send the string using the auto-generated API. */
|
||||
R_SCI1_Serial_Send( ( uint8_t * ) pcString, usStringLength );
|
||||
|
||||
/* Wait in the Blocked state (so not using any CPU time) until the
|
||||
transmission has completed. */
|
||||
ulTaskNotifyTake( pdTRUE, xMaxBlockTime );
|
||||
}
|
||||
}
|
||||
|
||||
/* Function required in order to link UARTCommandConsole.c - which is used by
|
||||
multiple different demo application. */
|
||||
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
|
||||
{
|
||||
/* Only one UART is supported. */
|
||||
( void ) pxPort;
|
||||
|
||||
/* Return a received character, if any are available. Otherwise block to
|
||||
wait for a character. */
|
||||
return xQueueReceive( xRxQueue, pcRxedChar, xBlockTime );
|
||||
}
|
||||
|
||||
/* Function required in order to link UARTCommandConsole.c - which is used by
|
||||
multiple different demo application. */
|
||||
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
|
||||
{
|
||||
/* Just mapped to vSerialPutString() so the block time is not used. */
|
||||
( void ) xBlockTime;
|
||||
|
||||
vSerialPutString( pxPort, &cOutChar, sizeof( cOutChar ) );
|
||||
return pdPASS;
|
||||
}
|
||||
|
||||
/* End user code. Do not edit comment generated here */
|
@ -1,112 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only
|
||||
* intended for use with Renesas products. No other uses are authorized. This
|
||||
* software is owned by Renesas Electronics Corporation and is protected under
|
||||
* all applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
|
||||
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
|
||||
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
|
||||
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
|
||||
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
|
||||
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software
|
||||
* and to discontinue the availability of this software. By using this software,
|
||||
* you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*******************************************************************************/
|
||||
/* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved. */
|
||||
/*******************************************************************************
|
||||
* File Name : r_rsk_async.c
|
||||
* Version : 1.00
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* H/W Platform : RSKRX113
|
||||
* Description : Functions used to send data via the SCI in asynchronous mode
|
||||
*******************************************************************************/
|
||||
/*******************************************************************************
|
||||
* History : 26.08.2014 Ver. 1.00 First Release
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
System Includes
|
||||
*******************************************************************************/
|
||||
/* Following header file provides string type definitions. */
|
||||
#include <string.h>
|
||||
|
||||
/*******************************************************************************
|
||||
User Includes (Project Level Includes)
|
||||
*******************************************************************************/
|
||||
/* Defines port registers */
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_sci.h"
|
||||
#include "r_rsk_async.h"
|
||||
|
||||
/*******************************************************************************
|
||||
User Defines
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global Variables
|
||||
*******************************************************************************/
|
||||
|
||||
/* Declaration of the command string to clear the terminal screen */
|
||||
static const char cmd_clr_scr[] =
|
||||
{ 27, 91, 50, 74, 0, 27, 91, 72, 0 };
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Prototypes
|
||||
*******************************************************************************/
|
||||
|
||||
/* text_write function prototype */
|
||||
static void text_write (const char * const msg_string);
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name: R_ASYNC_Init
|
||||
* Description : This function initialises the SCI channel connected to the
|
||||
* RS232 connector on the RSK. The channel is configured for
|
||||
* transmission and reception, and instructions are sent to the
|
||||
* terminal.
|
||||
* Argument : none
|
||||
* Return value : none
|
||||
*******************************************************************************/
|
||||
void R_ASYNC_Init (void)
|
||||
{
|
||||
|
||||
/* Set up SCI1 receive buffer */
|
||||
R_SCI1_Serial_Receive((uint8_t *) &g_rx_char, 1);
|
||||
|
||||
/* Enable SCI1 operations */
|
||||
R_SCI1_Start();
|
||||
|
||||
/* Clear the text on terminal window */
|
||||
text_write(cmd_clr_scr);
|
||||
|
||||
/* Display splash screen on terminal window */
|
||||
text_write("Renesas RSKRX113 Async Serial \r\n");
|
||||
|
||||
/* Inform user on how to stop transmission */
|
||||
text_write("Press 'z' to stop and any key to resume\r\n\n");
|
||||
}
|
||||
/*******************************************************************************
|
||||
* End of function R_ASYNC_Init
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : text_write
|
||||
* Description : Transmits null-terminated string.
|
||||
* Argument : (char*) msg_string - null terminated string
|
||||
* Return value : None
|
||||
*******************************************************************************/
|
||||
static void text_write (const char * const msg_string)
|
||||
{
|
||||
R_SCI1_AsyncTransmit((uint8_t *) msg_string, (uint16_t) strlen(msg_string));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* End of function text_write
|
||||
*******************************************************************************/
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only
|
||||
* intended for use with Renesas products. No other uses are authorized. This
|
||||
* software is owned by Renesas Electronics Corporation and is protected under
|
||||
* all applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
|
||||
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
|
||||
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
|
||||
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
|
||||
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
|
||||
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software
|
||||
* and to discontinue the availability of this software. By using this software,
|
||||
* you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*******************************************************************************/
|
||||
/* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved. */
|
||||
/*******************************************************************************
|
||||
* File Name : r_rsk_async.h
|
||||
* Version : 1.00
|
||||
* Device(s) : R5F51138AxFP
|
||||
* Tool-Chain : CCRX
|
||||
* H/W Platform : RSKRX113
|
||||
* Description : Functions used to send data via the SCI in asynchronous mode
|
||||
******************************************************************************/
|
||||
/*******************************************************************************
|
||||
* History : 26.08.2014 Ver. 1.00 First Release
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Definitions
|
||||
*******************************************************************************/
|
||||
/* Multiple inclusion prevention macro */
|
||||
#ifndef R_RSK_ASYNC_H
|
||||
#define R_RSK_ASYNC_H
|
||||
|
||||
/*******************************************************************************
|
||||
* Global Function Prototypes
|
||||
*******************************************************************************/
|
||||
/* initialise asynchronous transmission*/
|
||||
void R_ASYNC_Init (void);
|
||||
|
||||
/* End of multiple inclusion prevention macro */
|
||||
#endif
|
||||
|
@ -1,429 +0,0 @@
|
||||
/*
|
||||
FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
|
||||
All rights reserved
|
||||
|
||||
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||
|
||||
***************************************************************************
|
||||
>>! NOTE: The modification to the GPL is included to allow you to !<<
|
||||
>>! distribute a combined work that includes FreeRTOS without being !<<
|
||||
>>! obliged to provide the source code for proprietary components !<<
|
||||
>>! outside of the FreeRTOS kernel. !<<
|
||||
***************************************************************************
|
||||
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. Full license text is available on the following
|
||||
link: http://www.freertos.org/a00114.html
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS provides completely free yet professionally developed, *
|
||||
* robust, strictly quality controlled, supported, and cross *
|
||||
* platform software that is more than just the market leader, it *
|
||||
* is the industry's de facto standard. *
|
||||
* *
|
||||
* Help yourself get started quickly while simultaneously helping *
|
||||
* to support the FreeRTOS project by purchasing a FreeRTOS *
|
||||
* tutorial book, reference manual, or both: *
|
||||
* http://www.FreeRTOS.org/Documentation *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
|
||||
the FAQ page "My application does not run, what could be wrong?". Have you
|
||||
defined configASSERT()?
|
||||
|
||||
http://www.FreeRTOS.org/support - In return for receiving this top quality
|
||||
embedded software for free we request you assist our global community by
|
||||
participating in the support forum.
|
||||
|
||||
http://www.FreeRTOS.org/training - Investing in training allows your team to
|
||||
be as productive as possible as early as possible. Now you can receive
|
||||
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
|
||||
Ltd, and the world's leading authority on the world's leading RTOS.
|
||||
|
||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||
|
||||
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
|
||||
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
|
||||
|
||||
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
|
||||
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||
licenses offer ticketed support, indemnification and commercial middleware.
|
||||
|
||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||
engineered and independently SIL3 certified version for use in safety and
|
||||
mission critical applications that require provable dependability.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
/*
|
||||
The tasks defined on this page demonstrate the use of recursive mutexes.
|
||||
|
||||
For recursive mutex functionality the created mutex should be created using
|
||||
xSemaphoreCreateRecursiveMutex(), then be manipulated
|
||||
using the xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() API
|
||||
functions.
|
||||
|
||||
This demo creates three tasks all of which access the same recursive mutex:
|
||||
|
||||
prvRecursiveMutexControllingTask() has the highest priority so executes
|
||||
first and grabs the mutex. It then performs some recursive accesses -
|
||||
between each of which it sleeps for a short period to let the lower
|
||||
priority tasks execute. When it has completed its demo functionality
|
||||
it gives the mutex back before suspending itself.
|
||||
|
||||
prvRecursiveMutexBlockingTask() attempts to access the mutex by performing
|
||||
a blocking 'take'. The blocking task has a lower priority than the
|
||||
controlling task so by the time it executes the mutex has already been
|
||||
taken by the controlling task, causing the blocking task to block. It
|
||||
does not unblock until the controlling task has given the mutex back,
|
||||
and it does not actually run until the controlling task has suspended
|
||||
itself (due to the relative priorities). When it eventually does obtain
|
||||
the mutex all it does is give the mutex back prior to also suspending
|
||||
itself. At this point both the controlling task and the blocking task are
|
||||
suspended.
|
||||
|
||||
prvRecursiveMutexPollingTask() runs at the idle priority. It spins round
|
||||
a tight loop attempting to obtain the mutex with a non-blocking call. As
|
||||
the lowest priority task it will not successfully obtain the mutex until
|
||||
both the controlling and blocking tasks are suspended. Once it eventually
|
||||
does obtain the mutex it first unsuspends both the controlling task and
|
||||
blocking task prior to giving the mutex back - resulting in the polling
|
||||
task temporarily inheriting the controlling tasks priority.
|
||||
*/
|
||||
|
||||
/* Scheduler include files. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
|
||||
/* Demo app include files. */
|
||||
#include "recmutex.h"
|
||||
|
||||
/* Priorities assigned to the three tasks. */
|
||||
#define recmuCONTROLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||
#define recmuBLOCKING_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
#define recmuPOLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 0 )
|
||||
|
||||
/* In this version the tick period is very long, so the short delay cannot be
|
||||
for too many ticks, or the check task will execute and find that the recmutex
|
||||
tasks have not completed their functionality and then signal an error. The
|
||||
delay does however have to be long enough to allow the lower priority tasks
|
||||
a chance of executing - this is basically achieved by reducing the number
|
||||
of times the loop that takes/gives the recursive mutex executes. */
|
||||
#define recmuMAX_COUNT ( 2 )
|
||||
#define recmuSHORT_DELAY ( 20 )
|
||||
#define recmuNO_DELAY ( ( TickType_t ) 0 )
|
||||
#define recmuFIVE_TICK_DELAY ( ( TickType_t ) 5 )
|
||||
|
||||
/* The three tasks as described at the top of this file. */
|
||||
static void prvRecursiveMutexControllingTask( void *pvParameters );
|
||||
static void prvRecursiveMutexBlockingTask( void *pvParameters );
|
||||
static void prvRecursiveMutexPollingTask( void *pvParameters );
|
||||
|
||||
/* The mutex used by the demo. */
|
||||
static SemaphoreHandle_t xMutex;
|
||||
|
||||
/* Variables used to detect and latch errors. */
|
||||
static volatile portBASE_TYPE xErrorOccurred = pdFALSE, xControllingIsSuspended = pdFALSE, xBlockingIsSuspended = pdFALSE;
|
||||
static volatile unsigned portBASE_TYPE uxControllingCycles = 0, uxBlockingCycles = 0, uxPollingCycles = 0;
|
||||
|
||||
/* Handles of the two higher priority tasks, required so they can be resumed
|
||||
(unsuspended). */
|
||||
static TaskHandle_t xControllingTaskHandle, xBlockingTaskHandle, xPollingTaskHandle;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartRecursiveMutexTasks( void )
|
||||
{
|
||||
/* Just creates the mutex and the three tasks. */
|
||||
|
||||
xMutex = xSemaphoreCreateRecursiveMutex();
|
||||
|
||||
/* vQueueAddToRegistry() adds the mutex to the registry, if one is
|
||||
in use. The registry is provided as a means for kernel aware
|
||||
debuggers to locate mutex and has no purpose if a kernel aware debugger
|
||||
is not being used. The call to vQueueAddToRegistry() will be removed
|
||||
by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
|
||||
defined to be less than 1. */
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" );
|
||||
|
||||
|
||||
if( xMutex != NULL )
|
||||
{
|
||||
xTaskCreate( prvRecursiveMutexControllingTask, "Rec1Ctrl", configMINIMAL_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle );
|
||||
xTaskCreate( prvRecursiveMutexBlockingTask, "Rec2Blck", configMINIMAL_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle );
|
||||
xTaskCreate( prvRecursiveMutexPollingTask, "Rec3Poll", configMINIMAL_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, &xPollingTaskHandle );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecursiveMutexControllingTask( void *pvParameters )
|
||||
{
|
||||
unsigned portBASE_TYPE ux;
|
||||
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Should not be able to 'give' the mutex, as we have not yet 'taken'
|
||||
it. The first time through, the mutex will not have been used yet,
|
||||
subsequent times through, at this point the mutex will be held by the
|
||||
polling task. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
for( ux = 0; ux < recmuMAX_COUNT; ux++ )
|
||||
{
|
||||
/* We should now be able to take the mutex as many times as
|
||||
we like.
|
||||
|
||||
The first time through the mutex will be immediately available, on
|
||||
subsequent times through the mutex will be held by the polling task
|
||||
at this point and this Take will cause the polling task to inherit
|
||||
the priority of this task. In this case the block time must be
|
||||
long enough to ensure the polling task will execute again before the
|
||||
block time expires. If the block time does expire then the error
|
||||
flag will be set here. */
|
||||
if( xSemaphoreTakeRecursive( xMutex, recmuFIVE_TICK_DELAY ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Ensure the other task attempting to access the mutex (and the
|
||||
other demo tasks) are able to execute to ensure they either block
|
||||
(where a block time is specified) or return an error (where no
|
||||
block time is specified) as the mutex is held by this task. */
|
||||
vTaskDelay( recmuSHORT_DELAY );
|
||||
}
|
||||
|
||||
/* For each time we took the mutex, give it back. */
|
||||
for( ux = 0; ux < recmuMAX_COUNT; ux++ )
|
||||
{
|
||||
/* Ensure the other task attempting to access the mutex (and the
|
||||
other demo tasks) are able to execute. */
|
||||
vTaskDelay( recmuSHORT_DELAY );
|
||||
|
||||
/* We should now be able to give the mutex as many times as we
|
||||
took it. When the mutex is available again the Blocking task
|
||||
should be unblocked but not run because it has a lower priority
|
||||
than this task. The polling task should also not run at this point
|
||||
as it too has a lower priority than this task. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Having given it back the same number of times as it was taken, we
|
||||
should no longer be the mutex owner, so the next give should fail. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Keep count of the number of cycles this task has performed so a
|
||||
stall can be detected. */
|
||||
uxControllingCycles++;
|
||||
|
||||
/* Suspend ourselves so the blocking task can execute. */
|
||||
xControllingIsSuspended = pdTRUE;
|
||||
vTaskSuspend( NULL );
|
||||
xControllingIsSuspended = pdFALSE;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecursiveMutexBlockingTask( void *pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* This task will run while the controlling task is blocked, and the
|
||||
controlling task will block only once it has the mutex - therefore
|
||||
this call should block until the controlling task has given up the
|
||||
mutex, and not actually execute past this call until the controlling
|
||||
task is suspended. */
|
||||
if( xSemaphoreTakeRecursive( xMutex, portMAX_DELAY ) == pdPASS )
|
||||
{
|
||||
if( xControllingIsSuspended != pdTRUE )
|
||||
{
|
||||
/* Did not expect to execute until the controlling task was
|
||||
suspended. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Give the mutex back before suspending ourselves to allow
|
||||
the polling task to obtain the mutex. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
xBlockingIsSuspended = pdTRUE;
|
||||
vTaskSuspend( NULL );
|
||||
xBlockingIsSuspended = pdFALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We should not leave the xSemaphoreTakeRecursive() function
|
||||
until the mutex was obtained. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* The controlling and blocking tasks should be in lock step. */
|
||||
if( uxControllingCycles != ( uxBlockingCycles + 1 ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Keep count of the number of cycles this task has performed so a
|
||||
stall can be detected. */
|
||||
uxBlockingCycles++;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecursiveMutexPollingTask( void *pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Keep attempting to obtain the mutex. We should only obtain it when
|
||||
the blocking task has suspended itself, which in turn should only
|
||||
happen when the controlling task is also suspended. */
|
||||
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
|
||||
{
|
||||
/* Is the blocking task suspended? */
|
||||
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Keep count of the number of cycles this task has performed
|
||||
so a stall can be detected. */
|
||||
uxPollingCycles++;
|
||||
|
||||
/* We can resume the other tasks here even though they have a
|
||||
higher priority than the polling task. When they execute they
|
||||
will attempt to obtain the mutex but fail because the polling
|
||||
task is still the mutex holder. The polling task (this task)
|
||||
will then inherit the higher priority. The Blocking task will
|
||||
block indefinitely when it attempts to obtain the mutex, the
|
||||
Controlling task will only block for a fixed period and an
|
||||
error will be latched if the polling task has not returned the
|
||||
mutex by the time this fixed period has expired. */
|
||||
vTaskResume( xBlockingTaskHandle );
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
vTaskResume( xControllingTaskHandle );
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
/* The other two tasks should now have executed and no longer
|
||||
be suspended. */
|
||||
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Release the mutex, disinheriting the higher priority again. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
{
|
||||
taskYIELD();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This is called to check that all the created tasks are still running. */
|
||||
portBASE_TYPE xAreRecursiveMutexTasksStillRunning( void )
|
||||
{
|
||||
portBASE_TYPE xReturn;
|
||||
static unsigned portBASE_TYPE uxLastControllingCycles = 0, uxLastBlockingCycles = 0, uxLastPollingCycles = 0;
|
||||
|
||||
/* Is the controlling task still cycling? */
|
||||
if( uxLastControllingCycles == uxControllingCycles )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
uxLastControllingCycles = uxControllingCycles;
|
||||
}
|
||||
|
||||
/* Is the blocking task still cycling? */
|
||||
if( uxLastBlockingCycles == uxBlockingCycles )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
uxLastBlockingCycles = uxBlockingCycles;
|
||||
}
|
||||
|
||||
/* Is the polling task still cycling? */
|
||||
if( uxLastPollingCycles == uxPollingCycles )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
uxLastPollingCycles = uxPollingCycles;
|
||||
}
|
||||
|
||||
if( xErrorOccurred == pdTRUE )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdTRUE;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue