add uart_dma demo

uart_dma
xiangbingj 2019-09-04 10:09:54 +08:00
parent 285db1475f
commit 1c357550cf
4 changed files with 78 additions and 0 deletions

View File

@ -177,6 +177,7 @@ public:
xSemaphoreTake(session_.stage_completion_event, portMAX_DELAY);
next_free_buffer = session_.next_free_buffer;
}
configASSERT(session_.buffer_ptr + buffer.size() * sizeof(uint32_t) <= session_.buffer_size);
uint32_t *v_recv_buf = (uint32_t *)(session_.buffer + session_.buffer_size * next_free_buffer + session_.buffer_ptr);
for(uint32_t i = 0; i < buffer.size(); i++)
{

5
src/uart_dma/README.md Normal file
View File

@ -0,0 +1,5 @@
UART use dma
=====
"project_cfg.h" is the hardware related configuration files. Include pin config ...
1.Serial write and display.

42
src/uart_dma/main.c Normal file
View File

@ -0,0 +1,42 @@
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <devices.h>
#include <stdio.h>
#include <string.h>
#include "project_cfg.h"
handle_t uart1;
int main()
{
uint8_t recv[12] = {0};
uart1 = io_open("/dev/uart1");
uart_config(uart1, 115200, 8, UART_STOP_1, UART_PARITY_NONE);
uart_set_read_timeout(uart1, 10*1000);
char *hel = {"hello uart!\n"};
io_write(uart1, (uint8_t *)hel, strlen(hel));
uart_config_use_dma(uart1, 10, UART_USE_DMA);
while (1)
{
if(io_read(uart1, recv, 10) < 0)
printf("time out \n");
io_write(uart1, recv, 10);
}
}

View File

@ -0,0 +1,30 @@
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _PROJECT_CFG_H_
#define _PROJECT_CFG_H_
#include <pin_cfg.h>
const fpioa_cfg_t g_fpioa_cfg =
{
.version = PIN_CFG_VERSION,
.functions_count = 2,
.functions =
{
{30, FUNC_UART1_RX},
{31, FUNC_UART1_TX}
}
};
#endif