commit
cf892196b0
15
.cproject
15
.cproject
@ -146,6 +146,7 @@
|
||||
<buildTargets>
|
||||
<target name="all" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@ -153,6 +154,7 @@
|
||||
</target>
|
||||
<target name="clean" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@ -160,7 +162,6 @@
|
||||
</target>
|
||||
<target name="distclean" path="software/source" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
@ -216,6 +217,7 @@
|
||||
</target>
|
||||
<target name="all" path="software/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@ -247,6 +249,7 @@
|
||||
</target>
|
||||
<target name="distclean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@ -292,6 +295,14 @@
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="rng test" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments>TEST_APP=rng BOARD=stm32f4-discovery DEBUG=y</buildArguments>
|
||||
<buildTarget>test</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="msp430-ccrf example_radio_rx all" path="software/source/test" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments>APP=example_radio_rx BOARD=msp430-ccrf DEBUG=y</buildArguments>
|
||||
@ -318,6 +329,7 @@
|
||||
</target>
|
||||
<target name="all" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@ -325,6 +337,7 @@
|
||||
</target>
|
||||
<target name="clean" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
|
@ -1,7 +1,7 @@
|
||||
variables:
|
||||
SW_KERNEL: "0"
|
||||
SW_MAJOR: "1"
|
||||
SW_MINOR: "6"
|
||||
SW_MINOR: "7"
|
||||
|
||||
before_script:
|
||||
- "echo $CI_BUILD_ID"
|
||||
|
@ -24,8 +24,35 @@
|
||||
|
||||
#include "gpio.h"
|
||||
#include "stm32f4_gpio.h"
|
||||
|
||||
#include "rng.h"
|
||||
#include "stm32f4_rng.h"
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
// Random number generator
|
||||
static RNG_HandleTypeDef stm32f4_rng_handle = {
|
||||
.Instance = RNG,
|
||||
};
|
||||
|
||||
static struct stm32f4_rng stm32f4_rng = {
|
||||
.rng_handle = &stm32f4_rng_handle,
|
||||
};
|
||||
|
||||
static struct rng __rng = {
|
||||
.arch_dep_device = &stm32f4_rng,
|
||||
.fp = &rng_fp,
|
||||
};
|
||||
|
||||
#ifdef TEST_APP
|
||||
static const struct driver rng = {
|
||||
#else
|
||||
const struct driver rng = {
|
||||
#endif
|
||||
.driver_type = DRIVER_TYPE_RNG,
|
||||
.device_driver = &__rng,
|
||||
};
|
||||
|
||||
// GPIO_C0
|
||||
static const GPIO_InitTypeDef port_cfg_c0 = {
|
||||
.Pin = GPIO_PIN_0,
|
||||
|
25
source/firmware/arch/stm32f4xx/driver/include/stm32f4_rng.h
Normal file
25
source/firmware/arch/stm32f4xx/driver/include/stm32f4_rng.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* stm32f4_rng.h
|
||||
*
|
||||
* Created on: Aug 30, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_FIRMWARE_ARCH_STM32F4XX_INCLUDE_STM32F4_RNG_H_
|
||||
#define SOURCE_FIRMWARE_ARCH_STM32F4XX_INCLUDE_STM32F4_RNG_H_
|
||||
|
||||
struct stm32f4_rng {
|
||||
RNG_HandleTypeDef *rng_handle;
|
||||
};
|
||||
|
||||
int stm32f4_rng_open(const void *this);
|
||||
int stm32f4_rng_close(const void *this);
|
||||
unsigned int stm32f4_rng_read(const void *this);
|
||||
|
||||
static const struct rng_fp rng_fp = {
|
||||
.open = stm32f4_rng_open,
|
||||
.close = stm32f4_rng_close,
|
||||
.read = stm32f4_rng_read,
|
||||
};
|
||||
|
||||
#endif /* SOURCE_FIRMWARE_ARCH_STM32F4XX_INCLUDE_STM32F4_RNG_H_ */
|
43
source/firmware/arch/stm32f4xx/driver/stm32f4_rng.c
Normal file
43
source/firmware/arch/stm32f4xx/driver/stm32f4_rng.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* stm32f4_rng.c
|
||||
*
|
||||
* Created on: Aug 30, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
int stm32f4_rng_open(const void *this)
|
||||
{
|
||||
if(NULL == this)
|
||||
return -1;
|
||||
struct stm32f4_rng *dev = (struct stm32f4_rng *)this;
|
||||
|
||||
__HAL_RCC_RNG_CLK_ENABLE();
|
||||
HAL_RNG_DeInit(dev->rng_handle);
|
||||
HAL_RNG_Init(dev->rng_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stm32f4_rng_close(const void *this)
|
||||
{
|
||||
if(NULL == this)
|
||||
return -1;
|
||||
struct stm32f4_rng *dev = (struct stm32f4_rng *)this;
|
||||
__HAL_RCC_RNG_CLK_DISABLE();
|
||||
HAL_RNG_DeInit(dev->rng_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int stm32f4_rng_read(const void *this)
|
||||
{
|
||||
if(NULL == this)
|
||||
return -1;
|
||||
struct stm32f4_rng *dev = (struct stm32f4_rng *)this;
|
||||
uint32_t random = 0;
|
||||
HAL_RNG_GenerateRandomNumber(dev->rng_handle, &random);
|
||||
return random;
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
#include "gpio.h"
|
||||
#include "i2c.h"
|
||||
#include "pwm.h"
|
||||
//#include "rtc.h"
|
||||
#include "rng.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
|
||||
@ -34,8 +34,10 @@ int drv_open(const struct driver *driver)
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = pwm_open((const struct pwm *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RNG:
|
||||
ret = rng_open((const struct rng *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
// ret = rtc_open((const struct rtc *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_SPI:
|
||||
ret = spi_open((const struct spi *)(driver->device_driver));
|
||||
@ -65,8 +67,10 @@ int drv_close(const struct driver *driver)
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = pwm_close((const struct pwm *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RNG:
|
||||
ret = rng_close((const struct rng *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
// ret = rtc_close((const struct rtc *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_SPI:
|
||||
ret = spi_close((const struct spi *)(driver->device_driver));
|
||||
@ -96,7 +100,9 @@ int drv_read(const struct driver *driver, char *buffer, int len)
|
||||
case DRIVER_TYPE_I2C:
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = -1;
|
||||
break;
|
||||
case DRIVER_TYPE_RNG:
|
||||
ret = rng_read((const struct rng *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
break;
|
||||
@ -129,7 +135,8 @@ int drv_write(const struct driver *driver, const char *buffer, int len)
|
||||
case DRIVER_TYPE_I2C:
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = -1;
|
||||
break;
|
||||
case DRIVER_TYPE_RNG:
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
break;
|
||||
@ -166,6 +173,8 @@ int drv_ioctl(const struct driver *driver, unsigned int cmd, const void *data)
|
||||
return pwm_get_pulse_width_ns((const struct pwm *)(driver->device_driver));
|
||||
}
|
||||
break;
|
||||
case DRIVER_TYPE_RNG:
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
break;
|
||||
case DRIVER_TYPE_SPI:
|
||||
|
30
source/firmware/kernel/driver/include/rng.h
Normal file
30
source/firmware/kernel/driver/include/rng.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* rng.h
|
||||
*
|
||||
* Created on: Aug 30, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_RNG_H_
|
||||
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_RNG_H_
|
||||
|
||||
typedef int (*rng_fp_open_t)(const void*);
|
||||
typedef int (*rng_fp_close_t)(const void*);
|
||||
typedef unsigned int (*rng_fp_read_t)(const void*);
|
||||
|
||||
struct rng_fp {
|
||||
const rng_fp_open_t open;
|
||||
const rng_fp_close_t close;
|
||||
const rng_fp_read_t read;
|
||||
};
|
||||
|
||||
struct rng {
|
||||
const void *arch_dep_device;
|
||||
const struct rng_fp *fp;
|
||||
};
|
||||
|
||||
int rng_open(const struct rng *device);
|
||||
int rng_close(const struct rng *device);
|
||||
unsigned int rng_read(const struct rng *device);
|
||||
|
||||
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_RNG_H_ */
|
36
source/firmware/kernel/driver/rng.c
Normal file
36
source/firmware/kernel/driver/rng.c
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* rng.c
|
||||
*
|
||||
* Created on: Aug 30, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "rng.h"
|
||||
|
||||
int rng_open(const struct rng *device)
|
||||
{
|
||||
if(device == NULL)
|
||||
return -1;
|
||||
|
||||
rng_fp_open_t open = device->fp->open;
|
||||
return open(device->arch_dep_device);
|
||||
}
|
||||
|
||||
int rng_close(const struct rng *device)
|
||||
{
|
||||
if(device == NULL)
|
||||
return -1;
|
||||
|
||||
rng_fp_close_t close = device->fp->close;
|
||||
return close(device->arch_dep_device);
|
||||
}
|
||||
|
||||
unsigned int rng_read(const struct rng *device)
|
||||
{
|
||||
if(device == NULL)
|
||||
return 0;
|
||||
|
||||
rng_fp_read_t read = device->fp->read;
|
||||
return read(device->arch_dep_device);
|
||||
}
|
@ -17,6 +17,7 @@ enum driver_type {
|
||||
DRIVER_TYPE_GPIO,
|
||||
DRIVER_TYPE_I2C,
|
||||
DRIVER_TYPE_PWM,
|
||||
DRIVER_TYPE_RNG,
|
||||
DRIVER_TYPE_RTC,
|
||||
DRIVER_TYPE_SPI,
|
||||
DRIVER_TYPE_UART
|
||||
|
@ -67,7 +67,7 @@ static void *cmd_list_all_commands_cb(const char *cmd)
|
||||
int i, len = list_get_len(&shell_object.command_list);
|
||||
|
||||
drv_write(shell_object.shell_device, greeter, strlen(greeter));
|
||||
for(i = 0; i < (len - 1); i++) {
|
||||
for(i = 0; i < (len); i++) {
|
||||
if(NULL != it) {
|
||||
struct command *command = (struct command *)it->data;
|
||||
drv_write(shell_object.shell_device, command->command, strlen(command->command));
|
||||
|
38
source/test/rng/main.c
Normal file
38
source/test/rng/main.c
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created on: Aug 2, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "driver.h"
|
||||
#include "board.h"
|
||||
#include "stack.h"
|
||||
#include "queue.h"
|
||||
#include "kernel.h"
|
||||
#include "driver.h"
|
||||
#include "list.h"
|
||||
#include "shell.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char print_buffer[50];
|
||||
shell_init(&uart_1);
|
||||
drv_open(&rng);
|
||||
|
||||
while(1) {
|
||||
int random = drv_read(&rng, NULL, 0);
|
||||
sprintf(print_buffer, "random: %d\r\n", random);
|
||||
shell_write(print_buffer, strlen(print_buffer));
|
||||
sleep_ms(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1
source/test/rng/rng.mk
Normal file
1
source/test/rng/rng.mk
Normal file
@ -0,0 +1 @@
|
||||
SRC_DIR += source/test/rng
|
@ -6,6 +6,10 @@ ifeq ($(TEST_APP), pwm)
|
||||
include source/test/pwm/pwm.mk
|
||||
endif
|
||||
|
||||
ifeq ($(TEST_APP), rng)
|
||||
include source/test/rng/rng.mk
|
||||
endif
|
||||
|
||||
ifeq ($(TEST_APP), shell)
|
||||
include source/test/shell/shell.mk
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user