Lab4_Cau1
Lab4_Cau1
* @file main.c
* @brief main() function.
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#include "sl_component_catalog.h"
#include "sl_system_init.h"
#include "app.h"
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#include "sl_power_manager.h"
#endif
#if defined(SL_CATALOG_KERNEL_PRESENT)
#include "sl_system_kernel.h"
#else // SL_CATALOG_KERNEL_PRESENT
#include "sl_system_process_action.h"
#endif // SL_CATALOG_KERNEL_PRESENT
#include "em_chip.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
#include "em_ldma.h"
#include "em_emu.h"
/**************************************************************************//**
* DEFINE
*****************************************************************************/
/**************************************************************************//**
* STATIC VARIABLES
*****************************************************************************/
// LDMA descriptor and transfer configuration structures for USART TX channel
LDMA_Descriptor_t ldmaTXDescriptor;
LDMA_TransferCfg_t ldmaTXConfig;
// Outgoing data
uint8_t outbuf[BUFLEN];
// Incoming data
uint8_t inbuf[BUFLEN];
/**************************************************************************//**
* @brief
* GPIO initialization
*****************************************************************************/
void initGPIO(void)
{
// Configure the USART TX pin to the board controller as an output
GPIO_PinModeSet(BSP_TXPORT, BSP_TXPIN, gpioModePushPull, 1);
/*
* Configure the BCC_ENABLE pin as output and set high. This enables
* the virtual COM port (VCOM) connection to the board controller and
* permits serial port traffic over the debug connection to the host
* PC.
*
* To disable the VCOM connection and use the pins on the kit
* expansion (EXP) header, comment out the following line.
*/
GPIO_PinModeSet(BSP_ENABLE_PORT, BSP_ENABLE_PIN, gpioModePushPull, 1);
}
/**************************************************************************//**
* @brief
* USART0 initialization
*****************************************************************************/
void initUSART0(void)
{
// Default asynchronous initializer (115.2 Kbps, 8N1, no flow control)
USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
ldmaTXDescriptor.xfer.blockSize = ldmaCtrlBlockSizeUnit1;
ldmaTXConfig =
(LDMA_TransferCfg_t)LDMA_TRANSFER_CFG_PERIPHERAL(ldmaPeripheralSignal_USART0_TXBL);
ldmaRXDescriptor.xfer.blockSize = ldmaCtrlBlockSizeUnit1;
ldmaRXConfig =
(LDMA_TransferCfg_t)LDMA_TRANSFER_CFG_PERIPHERAL(ldmaPeripheralSignal_USART0_RXDATA
V);
}
void LDMA_IRQHandler()
{
uint32_t flags = LDMA_IntGet();
int main(void)
{
sl_system_init();
app_init();
#if defined(SL_CATALOG_KERNEL_PRESENT)
sl_system_kernel_start();
#else // SL_CATALOG_KERNEL_PRESENT
initGPIO();
initUSART0();
initLDMA();
while (1) {
sl_system_process_action();
app_process_action();
rx_done = false;
while (!rx_done){
EMU_EnterEM1();
}
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
// Let the CPU go to sleep if the system allows it.
sl_power_manager_sleep();
#endif
}
#endif // SL_CATALOG_KERNEL_PRESENT
}