MCUXpresso_LPC55S69/boards/lpcxpresso55s69/demo_apps/shell/cm33_core0/shell.c

182 lines
5.1 KiB
C

/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
*
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_component_serial_manager.h"
#include "fsl_shell.h"
#include "fsl_common.h"
#include "fsl_power.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define LED_NUMBERS 3U
#define LED_1_INIT() LED_RED_INIT(LOGIC_LED_OFF)
#define LED_2_INIT() LED_BLUE_INIT(LOGIC_LED_OFF)
#define LED_3_INIT() LED_GREEN_INIT(LOGIC_LED_OFF)
#define LED_1_ON() LED_RED_ON()
#define LED_1_OFF() LED_RED_OFF()
#define LED_2_ON() LED_BLUE_ON()
#define LED_2_OFF() LED_BLUE_OFF()
#define LED_3_ON() LED_GREEN_ON()
#define LED_3_OFF() LED_GREEN_OFF()
#define SHELL_Printf PRINTF
/*******************************************************************************
* Prototypes
******************************************************************************/
void Led_Init(void);
static shell_status_t LedControl(shell_handle_t shellHandle, int32_t argc, char **argv);
/*******************************************************************************
* Variables
******************************************************************************/
SHELL_COMMAND_DEFINE(led,
"\r\n\"led arg1 arg2\":\r\n Usage:\r\n arg1: 1|2|3|4... "
" Led index\r\n arg2: on|off Led status\r\n",
LedControl,
2);
SDK_ALIGN(static uint8_t s_shellHandleBuffer[SHELL_HANDLE_SIZE], 4);
static shell_handle_t s_shellHandle;
extern serial_handle_t g_serialHandle;
/*******************************************************************************
* Code
******************************************************************************/
void Led_Init(void)
{
LED_1_INIT();
LED_2_INIT();
LED_3_INIT();
}
static shell_status_t LedControl(shell_handle_t shellHandle, int32_t argc, char **argv)
{
int32_t kLedIndex = ((int32_t)atoi(argv[1]));
char *kLedCommand = argv[2];
/* Check second argument to control led */
switch (kLedIndex)
{
#if defined(LED_NUMBERS) && LED_NUMBERS > 0
case 1:
if (strcmp(kLedCommand, "on") == 0)
{
LED_1_ON();
}
else if (strcmp(kLedCommand, "off") == 0)
{
LED_1_OFF();
}
else
{
SHELL_Printf("Control conmmand is wrong!\r\n");
}
break;
#endif
#if defined(LED_NUMBERS) && LED_NUMBERS > 1
case 2:
if (strcmp(kLedCommand, "on") == 0)
{
LED_2_ON();
}
else if (strcmp(kLedCommand, "off") == 0)
{
LED_2_OFF();
}
else
{
SHELL_Printf("Control conmmand is wrong!\r\n");
}
break;
#endif
#if defined(LED_NUMBERS) && LED_NUMBERS > 2
case 3:
if (strcmp(kLedCommand, "on") == 0)
{
LED_3_ON();
}
else if (strcmp(kLedCommand, "off") == 0)
{
LED_3_OFF();
}
else
{
SHELL_Printf("Control conmmand is wrong!\r\n");
}
break;
#endif
#if defined(LED_NUMBERS) && LED_NUMBERS > 3
case 4:
if (strcmp(kLedCommand, "on") == 0)
{
LED_4_ON();
}
else if (strcmp(kLedCommand, "off") == 0)
{
LED_4_OFF();
}
else
{
SHELL_Printf("Control conmmand is wrong!\r\n");
}
break;
#endif
default:
SHELL_Printf("LED index is wrong\r\n");
break;
}
return kStatus_SHELL_Success;
}
/*! @brief Main function */
int main(void)
{
/* set BOD VBAT level to 1.65V */
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* enable clock for GPIO*/
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
#if !defined(DONT_ENABLE_FLASH_PREFETCH)
/* enable flash prefetch for better performance */
SYSCON->FMCCR |= SYSCON_FMCCR_PREFEN_MASK;
#endif
/* Init led */
Led_Init();
/* Init SHELL */
s_shellHandle = &s_shellHandleBuffer[0];
SHELL_Init(s_shellHandle, g_serialHandle, "SHELL>> ");
/* Add new command to commands list */
SHELL_RegisterCommand(s_shellHandle, SHELL_COMMAND(led));
while (1)
{
#if !(defined(SHELL_NON_BLOCKING_MODE) && (SHELL_NON_BLOCKING_MODE > 0U))
SHELL_Task(s_shellHandle);
#endif
}
}