123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("AutoChips Software") are
- * protected under relevant copyright laws. The information contained herein is
- * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
- * the prior written permission of AutoChips inc. and/or its licensors, any
- * reproduction, modification, use or disclosure of AutoChips Software, and
- * information contained herein, in whole or in part, shall be strictly
- * prohibited.
- *
- * AutoChips Inc. (C) 2021. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
- * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
- * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
- * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
- * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
- * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
- * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
- * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
- * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
- * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
- * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
- * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
- * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
- * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
- * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
- */
- /*!
- * @file debugout_ac7840x.c
- *
- * @brief This file provides debug information output integration functions.
- *
- */
- /* =========================================== Includes =========================================== */
- #include "device_register.h"
- #include "gpio_drv.h"
- #include "ckgen_drv.h"
- #include "debugout_ac7840x.h"
- #include "../src/uart/uart_hw.h"
- /* ============================================ Define ============================================ */
- #define MAX_DEBUG_BUFF_SIZE 100UL /* define uart max receive buffer size */
- #define DEBUG_INSTANCE 1UL
- #define DEBUG_UART UART1 /* define uart1 for debug output */
- #define DEBUG_UART_IRQ UART1_IRQn /* define uart1 interrupt vector */
- #define DEBUG_UART_CLK CLK_UART1 /* define uart1 ckgen clock value */
- #define DEBUG_UART_SRST SRST_UART1 /* define uart1 ckgen reset value */
- #define DEBUG_UART_BAUDRATE 115200UL
- #if 0
- #define DEBUG_UART_TX_PIN PORTB, 22UL /* define uart1 tx gpio */
- #define DEBUG_UART_RX_PIN PORTB, 23UL /* define uart1 rx gpio */
- #define DEBUG_UART_TX_FUNC PORT_MUX_ALT5 /* define uart1 tx pinmux */
- #define DEBUG_UART_RX_FUNC PORT_MUX_ALT3 /* define uart1 rx pinmux */
- #else
- #define DEBUG_UART_TX_PIN PORTC, 9UL /* define uart1 tx gpio */
- #define DEBUG_UART_RX_PIN PORTC, 8UL /* define uart1 rx gpio */
- #define DEBUG_UART_TX_FUNC PORT_MUX_ALT2 /* define uart1 tx pinmux */
- #define DEBUG_UART_RX_FUNC PORT_MUX_ALT2 /* define uart1 rx pinmux */
- #endif
- /* =========================================== Typedef ============================================ */
- /* ========================================== Variables =========================================== */
- /* debug uart receive buf */
- uint8_t g_debugBuff[MAX_DEBUG_BUFF_SIZE] = {0U};
- /* debug init flag */
- static uint8_t s_debugInit = 0U;
- /* define std FILE struct */
- struct __FILE
- {
- int handle;
- };
- /* refine stdout,stdin,stderr */
- FILE __stdout;
- FILE __stdin;
- FILE __stderr;
- /* ==================================== Functions declaration ===================================== */
- /* ====================================== Functions define ======================================== */
- /*!
- * @brief Refine _sys_exit.
- *
- * @param[in] x: no use
- * @return always 0
- */
- int _sys_exit(int x)
- {
- x = x;
- (void)x;
- return 0;
- }
- /*!
- * @brief Refine _ttywrch.
- *
- * @param[in] x: no use
- * @return always 0
- */
- int _ttywrch(int x)
- {
- x = x;
- (void)x;
- return 0;
- }
- #ifdef ITM_DEBUG_OUT
- /*!
- * @brief Put a char to ITM.
- *
- * @param[in] ch: the char to put
- * @param[in] f: file pointer for the std input
- * @return return the char of be put
- */
- int fputc(int ch, FILE *f)
- {
- if (s_debugInit)
- {
- ITM_SendChar(ch);
- }
- return ch;
- }
- /* for ITM use */
- volatile int ITM_RxBuffer;
- /*!
- * @brief Get a char from ITM.
- *
- * @param[in] f: file pointer for the std input
- * @return -1: not get char, other: the char get from ITM
- */
- int fgetc(FILE *f)
- {
- int ch = ITM_ReceiveChar();
- return ch;
- }
- #else
- /*!
- * @brief Put a char to UART.
- *
- * @param[in] ch: the char to put
- * @param[in] f: file pointer for the std input
- * @return return the char of be put
- */
- int fputc(int ch, FILE *f)
- {
- if (s_debugInit)
- {
- while (!UART_GetStatusFlag(DEBUG_UART, UART_TX_DATA_NOT_FULL));
- UART_Putchar(DEBUG_UART, (uint8_t)ch);
- }
- return ch;
- }
- /*!
- * @brief Get a char from UART.
- *
- * @param[in] f: file pointer for the std input
- * @return -1: not get char, other: the char get from UART
- */
- int fgetc(FILE *f)
- {
- int ch = -1;
- if (s_debugInit)
- {
- if (UART_GetStatusFlag(DEBUG_UART, UART_RX_DATA_READY))
- {
- UART_Getchar(DEBUG_UART, (uint8_t *)&ch);
- ch &= 0xFF;
- }
- }
- return ch;
- }
- #endif /* ITM_DEBUG_OUT */
- /*!
- * @brief Set the debug out is invalid.
- *
- * @param[in] none
- * @return none
- */
- void DeinitDebug(void)
- {
- s_debugInit = 0U;
- }
- /*!
- * @brief Init debug out, and set the debug out is valid.
- *
- * @param[in] none
- * @return none
- */
- void InitDebug(void)
- {
- #ifndef ITM_DEBUG_OUT
- #ifdef DEBUG_CMD_INTERRUPT
- NVIC_SetPriority(DEBUG_UART_IRQ, 3U);
- NVIC_ClearPendingIRQ(DEBUG_UART_IRQ);
- NVIC_EnableIRQ(DEBUG_UART_IRQ);
- #endif /* DEBUG_CMD_INTERRUPT */
- /* Set pinmux */
- GPIO_DRV_SetMuxModeSel(DEBUG_UART_TX_PIN, DEBUG_UART_TX_FUNC);
- GPIO_DRV_SetMuxModeSel(DEBUG_UART_RX_PIN, DEBUG_UART_RX_FUNC);
- /* Check UART function clock */
- if (0U == (CKGEN->PERI_CLK_MUX2 & \
- (CKGEN_PERI_CLK_MUX2_UART0_MUX_Msk << ((uint32_t)DEBUG_UART_CLK * 4U))))
- {
- /* Default set clock to HSIDIV2 */
- CKGEN->PERI_CLK_MUX2 |= 5U << ((uint32_t)DEBUG_UART_CLK * 4U);
- }
- /* Enable UART bus clock and release UART module from reset status */
- CKGEN_DRV_Enable(DEBUG_UART_CLK, true);
- CKGEN_DRV_SoftReset(DEBUG_UART_SRST, true);
- /* Set the baudrate */
- (void)UART_DRV_SetBaudRate(DEBUG_INSTANCE, DEBUG_UART_BAUDRATE);
- UART_SetBitCountPerChar(DEBUG_UART, UART_8_BITS_PER_CHAR);
- UART_SetStopBitCount(DEBUG_UART, UART_ONE_STOP_BIT);
- UART_SetParityMode(DEBUG_UART, UART_PARITY_DISABLED);
- UART_SetFIFO(DEBUG_UART, true);
- /* Enable UART TX and RX */
- UART_SetTransmitterCmd(DEBUG_UART, true);
- UART_SetReceiverCmd(DEBUG_UART, true);
- #endif /* ITM_DEBUG_OUT */
- s_debugInit = 1U;
- }
- /* ============================================= EOF ============================================== */
|