app_uplat7d.c

来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 1,435 行 · 第 1/4 页

C
1,435
字号
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : uPLATsmpAP_Uart                                   */
/*  Input           : void                                              */
/*  Output          : int16_t OK(1)                                     */
/*                            ERROR(-1)                                 */
/*                                                                      */
/*  Note : Sample program of uart.                                      */
/*                                                                      */
/************************************************************************/
int16_t uPLATsmpAP_UART(void)
{
    int16_t rtnVal = OK;
    int16_t handle_uart = HANDLE_ID_INIT;
    struct uPLAT_UartParam uart_trans_param;
    int8_t rev_data[UART_BUFF_SIZE + 1];
    boolean uart_end = FALSE;
    smpDrvInitPeripheral init_peripheral;
    uint16_t i;

    /* Initialize peripheral. */
    init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
    init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
    init_peripheral.init_xbus.iobw = BWC_IOBW_16;

    init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
    init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;

    init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
    init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;

    init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;

    init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;

    init_peripheral.init_xbus.standby = FALSE;

    init_peripheral.cache_mode = CACHE_WRITE_BACK;

    init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
    init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
    init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
    init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
    rtnVal = smpDrv_reset(&init_peripheral);
    if (rtnVal != OK) {
        return rtnVal;
    }

    debug_msg(_3_LED_START, NULL);       /* 3 bit LED : start */

    uart_trans_param.baudrate = BPS_115200;     /* 115200bps */
    uart_trans_param.parity = 0;       /* Non parity */
    uart_trans_param.data_len = 8;    /* 8bit */
    uart_trans_param.stop_bit = 1;      /* 1 stop bit */
    uart_trans_param.flow_ctrl=0;         /* Non flow control */
    uart_trans_param.fifo_byte_num=4;     /* 4byte fifo number */
    uart_trans_param.fifo_mode=1;         /* fifo mode */
    uart_trans_param.dma_mode=0;          /* Non dma */
    
    handle_uart = smpDrv_open(DRVNO_UART, (uint32_t)(&uart_trans_param));
    if (handle_uart == HANDLE_ID_1) {
        do {
            rtnVal = smpDrv_read(DRVNO_UART, rev_data, UART_BUFF_SIZE, handle_uart);
            rev_data[UART_BUFF_SIZE] = '\0';
            if (rtnVal == OK) {
                if ((rev_data[0] == ESC_CODE)
                    || (rev_data[1] == ESC_CODE)
                    || (rev_data[2] == ESC_CODE)
                    || (rev_data[3] == ESC_CODE)) {    /* exit by ESC code */
                    uart_end = TRUE;
                }
                else {
                    rtnVal = smpDrv_write(DRVNO_UART, rev_data, (uint16_t)strlen(rev_data), handle_uart);
                    for (i = 0; i < UART_BUFF_SIZE + 1; i++) {
                        rev_data[i] = '\0';
                    }
                }
            }
            if ((rtnVal & DRV_UART_OVR_ERROR) == DRV_UART_OVR_ERROR) {
                smpDrv_write(DRVNO_UART, (int8_t *)overrun_error_message, sizeof(overrun_error_message), handle_uart);
            }
            if ((rtnVal & DRV_UART_PRT_ERROR) == DRV_UART_PRT_ERROR) {
                smpDrv_write(DRVNO_UART, (int8_t *)parity_error_message, sizeof(parity_error_message), handle_uart);
            }
            if ((rtnVal & DRV_UART_FRM_ERROR) == DRV_UART_FRM_ERROR) {
                smpDrv_write(DRVNO_UART, (int8_t *)framing_error_message, sizeof(framing_error_message), handle_uart);
            }
            if ((rtnVal & DRV_UART_OVF_ERROR) == DRV_UART_OVF_ERROR) {
                smpDrv_write(DRVNO_UART, (int8_t *)overflow_error_message, sizeof(overflow_error_message), handle_uart);
            }
        } while ((rtnVal == OK) && (uart_end == FALSE));
    }

    smpDrv_close(DRVNO_UART, handle_uart);
    
    /* Execution result */
    if(rtnVal == OK){
        debug_msg(_3_LED_OK, NULL);       /* 3 bit LED : OK */
    }else{
        debug_msg(_3_LED_NG, NULL);       /* 3 bit LED : NG */
    }

    return rtnVal;
}




/*********************************************************************/
/*                                                                   */
/*    Function Name  :  uPLATsmpAP_SIO                               */
/*    Parameter      :                                               */
/*        Input      :                                               */
/*        Output     :                                               */
/*    Return         :                                               */
/*    Note           :  Sample program of SIO.                       */
/*    Create         :  LXF 05/12/22                                 */
/*                                                                   */
/*********************************************************************/
int16_t uPLATsmpAP_SIO(void)
{
    int16_t rtnVal = OK;
    int16_t handle_sio = HANDLE_ID_INIT;
    struct uPLAT_SioParam sio_trans_param;
    int8_t rev_data[128];
    smpDrvInitPeripheral init_peripheral;

    /* Initialize peripheral. */
    init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
    init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
    init_peripheral.init_xbus.iobw = BWC_IOBW_16;

    init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_3;
    init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;

    init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
    init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;

    init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;

    init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;

    init_peripheral.init_xbus.standby = FALSE;

    init_peripheral.cache_mode = CACHE_WRITE_BACK;

    init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
    init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
    init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
    init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
    rtnVal = smpDrv_reset(&init_peripheral);
    if (rtnVal != OK) {
        return rtnVal;
    }

    debug_msg(_3_LED_START, NULL);       /* 3 bit LED : start */

    sio_trans_param.baudrate = BPS_115200;      /* 115200bps */
    sio_trans_param.parity = NON_PARITY;        /* Non parity */
    sio_trans_param.data_len = LENGTH_8BIT;     /* 8bit */
    sio_trans_param.stop_bit = STOP_1BIT;       /* 1 stop bit */
    
    handle_sio = smpDrv_open(DRVNO_SIO, (uint32_t)(&sio_trans_param));
    if (handle_sio == HANDLE_ID_1) {
        rtnVal = smpDrv_write(DRVNO_SIO, (int8_t *)title_message, sizeof(title_message), handle_sio);
        do{
            rtnVal = smpDrv_read(DRVNO_SIO, &rev_data[0], 1, handle_sio);
            if(rtnVal == OK){
                if(rev_data[0] != ESC_CODE){    /* exit by ESC code */
                    rtnVal = smpDrv_write(DRVNO_SIO, &rev_data[0], 1, handle_sio);
                }
            }
            switch( rtnVal ){
            case DRV_SIO_OVR_ERROR:
                smpDrv_write(DRVNO_SIO, (int8_t *)overrun_error_message, sizeof(overrun_error_message), handle_sio);
                break;
            case DRV_SIO_PRT_ERROR:
                smpDrv_write(DRVNO_SIO, (int8_t *)parity_error_message, sizeof(parity_error_message), handle_sio);
                break;
            case DRV_SIO_FRM_ERROR:
                smpDrv_write(DRVNO_SIO, (int8_t *)framing_error_message, sizeof(framing_error_message), handle_sio);
                break;
            case DRV_SIO_OVF_ERROR:
                smpDrv_write(DRVNO_SIO, (int8_t *)overflow_error_message, sizeof(overflow_error_message), handle_sio);
                break;
            default :
                break ;
            }
        }while(rev_data[0] != ESC_CODE);
    }
    else {
        rtnVal = ERROR;
    }
    smpDrv_close(DRVNO_SIO, handle_sio);
    
    /* Execution result */
    if(rtnVal == OK){
        debug_msg(_3_LED_OK, NULL);       /* 3 bit LED : OK */
    }else{
        debug_msg(_3_LED_NG, NULL);       /* 3 bit LED : NG */
    }

    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : uPLATsmpAP_Remap                                  */
/*  Input           : Noting                                            */
/*  Output          : OK(1)                                             */
/*                    ERROR(-1)                                         */
/*                                                                      */
/*  Note : Sample program of Remap.                                     */
/*                                                                      */
/************************************************************************/
uint32_t counter_ram = 0;
int16_t uPLATsmpAP_Remap(void)
{
    int16_t rtnVal = OK;
    int16_t handle_remap = HANDLE_ID_INIT;
    uint8_t expand_area;
    uint8_t memory_area;
    smpDrvInitPeripheral init_peripheral;

    /* Initialize peripheral. */
    init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
    init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
    init_peripheral.init_xbus.iobw = BWC_IOBW_16;

    init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
    init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;

    init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
    init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;

    init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;

    init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;

    init_peripheral.init_xbus.standby = FALSE;

    init_peripheral.cache_mode = CACHE_WRITE_BACK;

    init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
    init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
    init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
    init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
    rtnVal = smpDrv_reset(&init_peripheral);
    if (rtnVal != OK) {
        return rtnVal;
    }
    
    debug_msg(_3_LED_START, NULL);  /* 3 bit LED start. */
    
    /* copy code region from bank0 to bank10 */
    image_bank0_base = BANK0_BASE;
    image_bank0_limit = BANK26_COPY_SIZE;
    CopyCode_bank0tobank10();
    
    /* Remap bank10 to bank0 */
    expand_area = 0;                        /* USB2.0: Enable, LCD: Enable */
    handle_remap = smpDrv_open(DRVNO_REMAP, (uint32_t)(expand_area));
    if (handle_remap == HANDLE_ID_1) {
        memory_area = EXTSRAM_REMAP;
        rtnVal = smpDrv_ioctl(DRVNO_REMAP, UPLAT_7D_HAL_REMAP_SET_FUNCTION, (uint32_t)memory_area, handle_remap);
    }else{
        rtnVal = ERROR;
    }
    
    /* Call count up function */
    if (rtnVal == OK) {
        rtnVal = countup(&counter_ram);
    }
    rtnVal = smpDrv_close(DRVNO_REMAP, handle_remap);
    
    /* Check counter number */
    if(counter_ram != 30){
        rtnVal = ERROR;
    }
    /* Execution result */
    if(rtnVal == OK){
        debug_msg(_3_LED_OK, NULL);       /* 3 bit LED : OK */
    }else{
        debug_msg(_3_LED_NG, NULL);       /* 3 bit LED : NG */
    }
    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : CopyCode_bank0tobank10                            */
/*  Input           : Noting                                            */
/*  Output          : Noting                                            */
/*                                                                      */
/*  Note : Copy code region from bank0 to bank10.                       */
/*                                                                      */
/************************************************************************/
#if defined(__arm)
static void CopyCode_bank0tobank10(void)
#else
void CopyCode_bank0tobank10(void)
#endif
{
    uint32_t i;
    uint32_t data;

    for(i=image_bank0_base; i<image_bank0_limit; i+=4){
        data = OkiCLib_read32(i);
        OkiCLib_write32(BANK26_BASE+i, data);
    }
}


/************************************************************************/
/*                                                                      */
/*  Function Name   : uPLATsmpAP_DMAC                                   */
/*  Input           : void                                              */
/*  Output          : int16_t OK(1)                                     */
/*                            ERROR(-1)                                 */
/*                                                                      */
/*  Note : Sample program of dmac.                                      */
/*                                                                      */
/************************************************************************/
int16_t uPLATsmpAP_DMAC(void)
{
    int16_t rtnVal = OK;
    int16_t handle_dmac = HANDLE_ID_INIT;
    uint32_t dmac_status;
    uPLAT_DmacParam dmac_param;
    smpDrvInitPeripheral init_peripheral;
    int16_t error = NO_ERR;

    /* Initialize peripheral. */
    init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
    init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
    init_peripheral.init_xbus.iobw = BWC_IOBW_16;

    init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
    init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;

    init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
    init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;

    init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;

    init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;

    init_peripheral.init_xbus.standby = FALSE;

    init_peripheral.cache_mode = CACHE_WRITE_BACK;

    init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
    init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
    init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
    init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
    rtnVal = smpDrv_reset(&init_peripheral);
    if (rtnVal != OK) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?