LPCXpresso 1769に接続されたDIPスイッチを介してさまざまな機能を使用するCプログラムを作成しようとしています。実行する機能を選択する必要があります(たとえば、00バイナリカウンタ01回転LEDなど) 。さて、私はすでに作っていますが、入れ子のif文からswitch文まで実行するプログラムを選択する関数を変更したかったが、うまくいきませんでした。しかし、コンパイルすると、デバッガはLPCXpressoに点滅し、それが行っていない各タスクの組み合わせを選択した後で、いくつかの警告(123行目と132行目も '未使用パラメータpvParameter'ものをしないでください。 NXPのLPCXpresso IDEを使用しています。CスイッチステートメントCMSIS FreeRTOS
は、ここでは、コード
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "lpc17xx_gpio.h"
#include "lpc17xx_timer.h"
#include "lpc17xx_adc.h"
#include "lpc17xx_pinsel.h"
/* Library includes. */
#include "LPC17xx.h"
#include "LPC17xx_gpio.h"
#include "system_LPC17xx.h"
/* Used as a loop counter to create a very crude delay. */
IRQn_Type TIMER0;
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
/* Used in the run time stats calculations. */
/* Used in the run time stats calculations. */
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL;
#define mainDELAY_LOOP_COUNT (0xfffff)
void CONFIG_GPIO(void);
static void init_adc(void);
extern int Timer0_Wait();
#define RGB_RED 0x01000000
#define RGB_BLUE 0x02000000
#define RGB_GREEN 0x04000000
void init_rgb (void);
void counter_rgb (void);
void vTaskKit(void *pvParameters);
int main(void)
{
init_adc();
init_rgb();
CONFIG_GPIO();
xTaskCreate (vTaskKit, "Kit", 240, NULL, 1, NULL);
/* Start the FreeRTOS scheduler. */
vTaskStartScheduler();
/* The following line should never execute. If it does, it means there was
insufficient FreeRTOS heap memory available to create the Idle and/or timer
tasks. See the memory management section on the http://www.FreeRTOS.org web
site for more information. */
for(;;);
}
/*-----------------------------------------------------------*/
void CONFIG_GPIO(void)
{
GPIO_SetDir(0,0x000000FF, 1);
GPIO_ClearValue(0, 0x000000FF);
GPIO_SetDir(2,0x000000FF,0);
GPIO_ClearValue(2, 0x000000FF);
}
void init_rgb (void)
{
GPIO_SetDir (0,0x01000000, 1);
GPIO_SetDir (0,0x02000000, 1);
GPIO_SetDir (0,0x04000000, 1);
}
static void init_adc(void)
{
/*
* Init ADC pin connect
* AD0.0 on P0.23
*/
PINSEL_CFG_Type PinCfg;
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 23;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
/* Configuration for ADC :
* Frequency at 1Mhz
* ADC channel 0, no Interrupt
*/
ADC_Init(LPC_ADC, 100000);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,ENABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE);
ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING);
}
void vTaskKit(void *pvParameters)
{
volatile unsigned long ul;
uint32_t var1=0x00000001;
uint32_t del =0x000000FF;
uint32_t var2=0x00000001;
uint32_t analog = 0;
uint32_t sw=0x00000000;
unsigned int var=0;
while(1)
{
sw=GPIO_ReadValue(2);
switch(sw)
{
case 0x00000001://Contador Binario
GPIO_SetValue(0,var);
var++;
vTaskDelay(100);
GPIO_ClearValue(0,0x000000FF);
break;
case 0x00000002://Auto Increible
for(var2;var2<=7;var2++)
{
GPIO_SetValue(0,var1);
var1= var1<<1;
for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++)
{
}
GPIO_ClearValue(0,del);
}
for(var2;var2>=2;var2--)
{
GPIO_SetValue(0,var1);
var1= var1>>1;
for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++)
{
}
GPIO_ClearValue(0,del);
}
break;
case 0x00000003://Contador RGB
GPIO_SetValue (0,RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_RED);
GPIO_SetValue (0,RGB_BLUE);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_BLUE);
GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
GPIO_SetValue (0,RGB_GREEN);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN);
GPIO_SetValue (0,RGB_GREEN+RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
break;
case 0x00000004://Contador ADC Binario
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
analog=analog/16;
GPIO_SetValue(0,analog);
vTaskDelay(100/portTICK_RATE_MS);
GPIO_ClearValue(0,0x000000FF);
break;
case 0x00000005://Contador ADC RGB
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
if(analog<585)
{
GPIO_SetValue(0,RGB_RED);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_RED);
}
if(585<analog && analog<1170)
{
GPIO_SetValue (0,RGB_BLUE);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_BLUE);
}
if(1170<analog && analog<1755)
{
GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
}
if(1755<analog && analog<2340)
{
GPIO_SetValue (0,RGB_GREEN);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN);
}
if(2340<analog && analog<2925)
{
GPIO_SetValue (0,RGB_GREEN+RGB_RED);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
}
if(2925<analog && analog<3510)
{
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
}
if(3510<analog && analog<4095)
{
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
}
break;
}
}
}
void vMainConfigureTimerForRunTimeStats(void)
{
/* How many clocks are there per tenth of a millisecond? */
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ/10000UL;
}
/*-----------------------------------------------------------*/
uint32_t ulMainGetRunTimeCounterValue(void)
{
uint32_t ulSysTickCounts, ulTickCount, ulReturn;
const uint32_t ulSysTickReloadValue = (configCPU_CLOCK_HZ/ configTICK_RATE_HZ) - 1UL;
volatile uint32_t * const pulCurrentSysTickCount = ((volatile uint32_t *) 0xe000e018);
volatile uint32_t * const pulInterruptCTRLState = ((volatile uint32_t *) 0xe000ed04);
const uint32_t ulSysTickPendingBit = 0x04000000UL;
/* NOTE: There are potentially race conditions here. However, it is used
anyway to keep the examples simple, and to avoid reliance on a separate
timer peripheral. */
/* The SysTick is a down counter. How many clocks have passed since it was
last reloaded? */
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
/* How many times has it overflowed? */
ulTickCount = xTaskGetTickCountFromISR();
/* Is there a SysTick interrupt pending? */
if((*pulInterruptCTRLState & ulSysTickPendingBit) != 0UL)
{
/* There is a SysTick interrupt pending, so the SysTick has overflowed
but the tick count not yet incremented. */
ulTickCount++;
/* Read the SysTick again, as the overflow might have occurred since
it was read last. */
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
}
/* Convert the tick count into tenths of a millisecond. THIS ASSUMES
configTICK_RATE_HZ is 1000! */
ulReturn = (ulTickCount * 10UL) ;
/* Add on the number of tenths of a millisecond that have passed since the
tick count last got updated. */
ulReturn += (ulSysTickCounts/ulClocksPer10thOfAMilliSecond);
return ulReturn;
}
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName)
{
(void) pcTaskName;
(void) pxTask;
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for(;;);
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook(void)
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c or heap_2.c are used, then the size of the
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
to query the size of free heap space that remains (although it does not
provide information on how the remaining heap might be fragmented). */
taskDISABLE_INTERRUPTS();
for(;;);
}
/*-----------------------------------------------------------*/
そして働く一つだが、入れ子になったと
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "lpc17xx_gpio.h"
#include "lpc17xx_timer.h"
#include "lpc17xx_adc.h"
#include "lpc17xx_pinsel.h"
/* Library includes. */
#include "LPC17xx.h"
#include "LPC17xx_gpio.h"
#include "system_LPC17xx.h"
/* Used as a loop counter to create a very crude delay. */
IRQn_Type TIMER0;
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
/* Used in the run time stats calculations. */
/* Used in the run time stats calculations. */
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL;
#define mainDELAY_LOOP_COUNT (0xfffff)
void CONFIG_GPIO(void);
static void init_adc(void);
extern int Timer0_Wait();
#define RGB_RED 0x01000000
#define RGB_BLUE 0x02000000
#define RGB_GREEN 0x04000000
void init_rgb (void);
void counter_rgb (void);
void vTaskKit(void *pvParameters);
int main(void)
{
init_adc();
init_rgb();
CONFIG_GPIO();
xTaskCreate (vTaskKit, "Kit", 240, NULL, 1, NULL);
/* Start the FreeRTOS scheduler. */
vTaskStartScheduler();
/* The following line should never execute. If it does, it means there was
insufficient FreeRTOS heap memory available to create the Idle and/or timer
tasks. See the memory management section on the http://www.FreeRTOS.org web
site for more information. */
for(;;);
}
/*-----------------------------------------------------------*/
void CONFIG_GPIO(void)
{
GPIO_SetDir(0,0x000000FF, 1);
GPIO_ClearValue(0, 0x000000FF);
GPIO_SetDir(2,0x000000FF,0);
GPIO_ClearValue(2, 0x000000FF);
}
void init_rgb (void)
{
GPIO_SetDir (0,0x01000000, 1);
GPIO_SetDir (0,0x02000000, 1);
GPIO_SetDir (0,0x04000000, 1);
}
static void init_adc(void)
{
/*
* Init ADC pin connect
* AD0.0 on P0.23
*/
PINSEL_CFG_Type PinCfg;
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 23;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
/* Configuration for ADC :
* Frequency at 1Mhz
* ADC channel 0, no Interrupt
*/
ADC_Init(LPC_ADC, 100000);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,ENABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE);
ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING);
}
void vTaskKit(void *pvParameters)
{
volatile unsigned long ul;
uint32_t var1=0x00000001;
uint32_t del =0x000000FF;
uint32_t var2=0x00000001;
uint32_t analog = 0;
char var=0;
char sw=0x000000000;
char bin=0x00000001;
char inc=0x00000002;
char rgb=0x00000003;
char adcbin=0x00000004;
char adcrgb=0x00000005;
while(1)
{
sw=GPIO_ReadValue(2);
if(sw==bin)
{
GPIO_SetValue(0,var);
var++;
vTaskDelay(100);
GPIO_ClearValue(0,0x000000FF);
}
if(sw==inc)
{
for(var2;var2<=7;var2++)
{
GPIO_SetValue(0,var1);
var1= var1<<1;
for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++)
{
}
GPIO_ClearValue(0,del);
}
for(var2;var2>=2;var2--)
{
GPIO_SetValue(0,var1);
var1= var1>>1;
for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++)
{
}
GPIO_ClearValue(0,del);
}
}
if(sw==rgb)
{
GPIO_SetValue (0,RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_RED);
GPIO_SetValue (0,RGB_BLUE);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_BLUE);
GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
GPIO_SetValue (0,RGB_GREEN);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN);
GPIO_SetValue (0,RGB_GREEN+RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
vTaskDelay(200/portTICK_RATE_MS);
}
if(sw==adcbin)
{
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
analog=analog/16;
GPIO_SetValue(0,analog);
vTaskDelay(100/portTICK_RATE_MS);
GPIO_ClearValue(0,0x000000FF);
}
if(sw==adcrgb)
{
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
if(analog<585)
{
GPIO_SetValue(0,RGB_RED);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_RED);
}
if(585<analog && analog<1170)
{
GPIO_SetValue (0,RGB_BLUE);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_BLUE);
}
if(1170<analog && analog<1755)
{
GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
}
if(1755<analog && analog<2340)
{
GPIO_SetValue (0,RGB_GREEN);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN);
}
if(2340<analog && analog<2925)
{
GPIO_SetValue (0,RGB_GREEN+RGB_RED);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
}
if(2925<analog && analog<3510)
{
GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
}
if(3510<analog && analog<4095)
{
GPIO_SetValue
(0,RGB_GREEN+RGB_BLUE+RGB_RED);
vTaskDelay(50/portTICK_RATE_MS);
GPIO_ClearValue
(0,RGB_GREEN+RGB_BLUE+RGB_RED);
}
}
}
}
void vMainConfigureTimerForRunTimeStats(void)
{
/* How many clocks are there per tenth of a millisecond? */
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ/10000UL;
}
/*-----------------------------------------------------------*/
uint32_t ulMainGetRunTimeCounterValue(void)
{
uint32_t ulSysTickCounts, ulTickCount, ulReturn;
const uint32_t ulSysTickReloadValue = (configCPU_CLOCK_HZ/ configTICK_RATE_HZ) - 1UL;
volatile uint32_t * const pulCurrentSysTickCount = ((volatile uint32_t *) 0xe000e018);
volatile uint32_t * const pulInterruptCTRLState = ((volatile uint32_t *) 0xe000ed04);
const uint32_t ulSysTickPendingBit = 0x04000000UL;
/* NOTE: There are potentially race conditions here. However, it is used
anyway to keep the examples simple, and to avoid reliance on a separate
timer peripheral. */
/* The SysTick is a down counter. How many clocks have passed since it was
last reloaded? */
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
/* How many times has it overflowed? */
ulTickCount = xTaskGetTickCountFromISR();
/* Is there a SysTick interrupt pending? */
if((*pulInterruptCTRLState & ulSysTickPendingBit) != 0UL)
{
/* There is a SysTick interrupt pending, so the SysTick has overflowed
but the tick count not yet incremented. */
ulTickCount++;
/* Read the SysTick again, as the overflow might have occurred since
it was read last. */
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
}
/* Convert the tick count into tenths of a millisecond. THIS ASSUMES
configTICK_RATE_HZ is 1000! */
ulReturn = (ulTickCount * 10UL) ;
/* Add on the number of tenths of a millisecond that have passed since the
tick count last got updated. */
ulReturn += (ulSysTickCounts/ulClocksPer10thOfAMilliSecond);
return ulReturn;
}
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName)
{
(void) pcTaskName;
(void) pxTask;
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for(;;);
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook(void)
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c or heap_2.c are used, then the size of the
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
to query the size of free heap space that remains (although it does not
provide information on how the remaining heap might be fragmented). */
taskDISABLE_INTERRUPTS();
for(;;);
}
/*-----------------------------------------------------------*/
ようこそStackOverflow!ヘルプセンターにアクセスし、良い質問を投稿する方法に関するガイドラインを読んでください。なぜなら、あなたにはたくさんのコードが掲載されているためです。尋ねられる質問は、可能な限り明確かつ簡潔でなければならず、質問に最も関連性の高いコードのみを投稿することを忘れないでください。ありがとうございました。 –
デバッガでコードをステップ実行しましたか? switch文を入力するときに 'sw'の値は何ですか? 'GPIO_ReadValue()'はどのような型を返しますか?なぜあなたはswの型を変えたのですか? – kkrambo
これらのメッセージはデバッガからのものではありません。そして、私たちはコードの壁のためのデバッグサービスはありません。 – Olaf