Skip to content

Commit

Permalink
Merge pull request #25 from kendryte/develop
Browse files Browse the repository at this point in the history
v0.5.2 release
  • Loading branch information
zzxcanaan authored Nov 13, 2018
2 parents 6d05eba + 1c55a03 commit d13b380
Show file tree
Hide file tree
Showing 23 changed files with 1,590 additions and 156 deletions.
824 changes: 808 additions & 16 deletions .gitignore

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,51 @@ Kendryte K210 first SDK with FreeRTOS, have fun.
- Non-breaking bug fixes
- Fix out of memory issues
- Fix lcd unused issues

## 0.4.1

- Major change
- Add dma support for aes driver
- Add uarths driver
- Add dma interrupt handler

- Non-breaking bug fixes
- Fix the procedure of setting pll
- Fix wdt interrupt bug
- Fix serveral bugs in i2s drivers

## 0.5.0

- Major change
- Add KPU driver
- Find toolchain automatically

- Non-breaking bug fixes
- Fix aes gcm bug
- Fix dmac interrupt bug
- Fix i2s transfer bug

## 0.5.1

- Major changes
- Add i2c slave driver

- Non-breaking bug fixes
- Fix pll init issues
- Fix spi receive mode issues
- Fix redefine function does not report error issues
- Reduce stack size

## 0.5.2
- Major change
- Add KPU driver for latest model compiler
- Automatic set PROJ if user not set it
- Update timer driver to support better interrupt
- Add uart dma and interrupt function
- Non-breaking bug fixes
- Fix rtc issues
- Fix sccb issues

- Breaking change
- Fix timer interrupt lost problem
- Add new timer interrupt API
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ set(BUILDING_SDK "yes" CACHE INTERNAL "")

# basic config
if (NOT PROJ)
message(FATAL_ERROR "PROJ must be set. e.g. -DPROJ=hello_world")
get_filename_component(PROJ ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY)
get_filename_component(PROJ ${PROJ} NAME)
string(REPLACE " " "_" PROJ ${PROJ})
message(STATUS "PROJ not set, use ${PROJ} as PROJ. Also, you can set it manually. e.g. -DPROJ=hello_world")
else()
message("PROJ = ${PROJ}")
endif ()
Expand Down
13 changes: 6 additions & 7 deletions lib/bsp/include/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ typedef struct _corelock
int core;
} corelock_t;


static inline int spinlock_trylock(spinlock_t *lock)
{
int res = atomic_swap(&lock->lock, -1);
Expand All @@ -83,18 +82,15 @@ static inline int spinlock_trylock(spinlock_t *lock)

static inline void spinlock_lock(spinlock_t *lock)
{
do
{
while (atomic_read(&lock->lock))
;
} while (spinlock_trylock(lock));
while (spinlock_trylock(lock));
}

static inline void spinlock_unlock(spinlock_t *lock)
{
/* Use memory barrier to keep coherency */
mb();
atomic_set(&lock->lock, 0);
asm volatile ("nop");
}

static inline void semaphore_signal(semaphore_t *semaphore, int i)
Expand Down Expand Up @@ -143,7 +139,10 @@ static inline int corelock_trylock(corelock_t *lock)

asm volatile("csrr %0, mhartid;"
: "=r"(core));
spinlock_lock(&lock->lock);
if(spinlock_trylock(&lock->lock))
{
return -1;
}

if (lock->count == 0)
{
Expand Down
15 changes: 0 additions & 15 deletions lib/bsp/printf.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/* 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.
*/

/**
* File: printf.c
*
Expand Down
4 changes: 2 additions & 2 deletions lib/drivers/clint.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int clint_timer_register(clint_timer_callback_t callback, void *ctx)
return 0;
}

int clint_timer_deregister(void)
int clint_timer_unregister(void)
{
/* Just assign NULL to user callback function and context */
return clint_timer_register(NULL, NULL);
Expand Down Expand Up @@ -211,7 +211,7 @@ int clint_ipi_register(clint_ipi_callback_t callback, void *ctx)
return 0;
}

int clint_ipi_deregister(void)
int clint_ipi_unregister(void)
{
/* Just assign NULL to user callback function and context */
return clint_ipi_register(NULL, NULL);
Expand Down
31 changes: 21 additions & 10 deletions lib/drivers/dmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void src_transaction_complete_int_enable(dmac_channel_number_t channel_num)
writeq(ch_intstat.data, &dmac->channel[channel_num].intstatus_en);
}

static void dmac_channel_enable(dmac_channel_number_t channel_num)
void dmac_channel_enable(dmac_channel_number_t channel_num)
{
dmac_chen_u_t chen;

Expand Down Expand Up @@ -125,36 +125,37 @@ static void dmac_channel_enable(dmac_channel_number_t channel_num)
writeq(chen.data, &dmac->chen);
}

static void dmac_channel_disable(dmac_channel_number_t channel_num)
void dmac_channel_disable(dmac_channel_number_t channel_num)
{
dmac_chen_u_t chen;

chen.data = readq(&dmac->chen);

switch (channel_num) {
switch (channel_num)
{
case DMAC_CHANNEL0:
chen.dmac_chen.ch1_en = 0;
chen.dmac_chen.ch1_en_we = 0;
chen.dmac_chen.ch1_en_we = 1;
break;
case DMAC_CHANNEL1:
chen.dmac_chen.ch2_en = 0;
chen.dmac_chen.ch2_en_we = 0;
chen.dmac_chen.ch2_en_we = 1;
break;
case DMAC_CHANNEL2:
chen.dmac_chen.ch3_en = 0;
chen.dmac_chen.ch3_en_we = 0;
chen.dmac_chen.ch3_en_we = 1;
break;
case DMAC_CHANNEL3:
chen.dmac_chen.ch4_en = 0;
chen.dmac_chen.ch4_en_we = 0;
chen.dmac_chen.ch4_en_we = 1;
break;
case DMAC_CHANNEL4:
chen.dmac_chen.ch5_en = 0;
chen.dmac_chen.ch5_en_we = 0;
chen.dmac_chen.ch5_en_we = 1;
break;
case DMAC_CHANNEL5:
chen.dmac_chen.ch6_en = 0;
chen.dmac_chen.ch6_en_we = 0;
chen.dmac_chen.ch6_en_we = 1;
break;
default:
break;
Expand Down Expand Up @@ -708,6 +709,7 @@ void dmac_set_single_mode(dmac_channel_number_t channel_num,
size_t block_size) {
dmac_chanel_interrupt_clear(channel_num);
dmac_channel_disable(channel_num);
dmac_wait_idle(channel_num);
dmac_set_channel_param(channel_num, src, dest, src_inc, dest_inc,
dmac_burst_size, dmac_trans_width, block_size);
dmac_enable();
Expand All @@ -733,7 +735,7 @@ int dmac_is_idle(dmac_channel_number_t channel_num)
{
dmac_chen_u_t chen;
chen.data = readq(&dmac->chen);
if((chen.data >> channel_num) & 0x101UL)
if((chen.data >> channel_num) & 0x1UL)
return 0;
else
return 1;
Expand Down Expand Up @@ -777,3 +779,12 @@ void dmac_set_irq(dmac_channel_number_t channel_num , plic_irq_callback_t dmac_c
plic_irq_enable(IRQN_DMA0_INTERRUPT + channel_num);
plic_irq_register(IRQN_DMA0_INTERRUPT + channel_num, dmac_irq_callback, &dmac_context[channel_num]);
}

void dmac_free_irq(dmac_channel_number_t channel_num)
{
dmac_context[channel_num].callback = NULL;
dmac_context[channel_num].ctx = NULL;
dmac_disable_channel_interrupt(channel_num);
plic_irq_unregister(IRQN_DMA0_INTERRUPT + channel_num);
}

18 changes: 17 additions & 1 deletion lib/drivers/dvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "utils.h"
#include "fpioa.h"
#include "sysctl.h"
#include <math.h>

volatile dvp_t* const dvp = (volatile dvp_t*)DVP_BASE_ADDR;
static uint8_t g_sccb_reg_len = 8;
Expand All @@ -38,11 +39,26 @@ static void dvp_sccb_clk_init(void)
uint32_t tmp;

tmp = dvp->sccb_cfg & (~(DVP_SCCB_SCL_LCNT_MASK | DVP_SCCB_SCL_HCNT_MASK));
tmp |= DVP_SCCB_SCL_LCNT(500) | DVP_SCCB_SCL_HCNT(500);
tmp |= DVP_SCCB_SCL_LCNT(255) | DVP_SCCB_SCL_HCNT(255);

dvp->sccb_cfg = tmp;
}

uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate)
{
uint32_t tmp;
uint32_t v_sccb_freq = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1);
uint16_t v_period_clk_cnt = round(v_sccb_freq / clk_rate / 2.0);
if(v_period_clk_cnt > 255)
{
return 0;
}
tmp = dvp->sccb_cfg & (~(DVP_SCCB_SCL_LCNT_MASK | DVP_SCCB_SCL_HCNT_MASK));
tmp |= DVP_SCCB_SCL_LCNT(v_period_clk_cnt) | DVP_SCCB_SCL_HCNT(v_period_clk_cnt);
dvp->sccb_cfg = tmp;
return sysctl_clock_get_freq(SYSCTL_CLOCK_DVP) / (v_period_clk_cnt * 2);
}

static void dvp_sccb_start_transfer(void)
{
while (dvp->sts & DVP_STS_SCCB_EN)
Expand Down
4 changes: 2 additions & 2 deletions lib/drivers/include/clint.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ int clint_timer_register(clint_timer_callback_t callback, void *ctx);
* - 0 Success
* - Other Fail
*/
int clint_timer_deregister(void);
int clint_timer_unregister(void);

/**
* @brief Initialize local interprocessor interrupt
Expand Down Expand Up @@ -328,7 +328,7 @@ int clint_ipi_register(clint_ipi_callback_t callback, void *ctx);
* - 0 Success
* - Other Fail
*/
int clint_ipi_deregister(void);
int clint_ipi_unregister(void);

#ifdef __cplusplus
}
Expand Down
24 changes: 24 additions & 0 deletions lib/drivers/include/dmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,14 @@ void dmac_wait_idle(dmac_channel_number_t channel_num);
*/
void dmac_set_irq(dmac_channel_number_t channel_num , plic_irq_callback_t dmac_callback, void *ctx, uint32_t priority);

/**
* @brief Disable dmac interrupt
*
* @param[in] channel_num Dmac channel
*
*/
void dmac_free_irq(dmac_channel_number_t channel_num);

/**
* @brief Set source dest and length
*
Expand All @@ -1492,6 +1500,22 @@ void dmac_set_src_dest_length(dmac_channel_number_t channel_num, const void *src
*/
void dmac_disable_channel_interrupt(dmac_channel_number_t channel_num);

/**
* @brief Disable dmac channel
*
* @param[in] channel_num Dmac channel
*
*/
void dmac_channel_disable(dmac_channel_number_t channel_num);

/**
* @brief Enable dmac channel
*
* @param[in] channel_num Dmac channel
*
*/
void dmac_channel_enable(dmac_channel_number_t channel_num);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions lib/drivers/include/dvp.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ void dvp_disable_auto(void);
*/
void dvp_set_output_enable(dvp_output_mode_t index, int enable);

/**
* @brief Set sccb clock rate
*
* @param[in] clk_rate Sccb clock rate
*
* @return The real sccb clock rate
*/
uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 5 additions & 1 deletion lib/drivers/include/kpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,16 @@ extern volatile kpu_config_t *const kpu;
typedef struct
{
kpu_layer_argument_t* layers;
kpu_layer_argument_t* remain_layers;
uint64_t* dst;
plic_irq_callback_t cb;
uint32_t length;
uint32_t layers_length;
uint32_t remain_layers_length;
uint32_t dst_length;
uint32_t dma_ch;
uint32_t eight_bit_mode;
volatile float output_scale;
volatile float output_bias;
} kpu_task_t;

/**
Expand Down
11 changes: 11 additions & 0 deletions lib/drivers/include/plic.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ void plic_irq_register(plic_irq_t irq, plic_irq_callback_t callback, void *ctx);
*/
void plic_irq_deregister(plic_irq_t irq);

/**
* @brief Deegister user callback function by IRQ number
*
* @param[in] irq The irq
*
* @return result
* - 0 Success
* - Other Fail
*/
void plic_irq_unregister(plic_irq_t irq);

/* For c++ compatibility */
#ifdef __cplusplus
}
Expand Down
7 changes: 7 additions & 0 deletions lib/drivers/include/sysctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,13 @@ void sysctl_enable_irq(void);
*/
void sysctl_disable_irq(void);

/**
* @brief Get the time start up to now
*
* @return The time of microsecond
*/
uint64_t sysctl_get_time_us(void);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit d13b380

Please sign in to comment.