From: asterix Date: Fri, 15 Oct 2010 16:33:49 +0000 (+0000) Subject: Put the specific random cpu backend to correct dir. X-Git-Tag: 2.6.0~5^2~89 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=05b576afecd2ac6f391250a9248861c7855eefd2;p=bertos.git Put the specific random cpu backend to correct dir. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4431 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/cortex-m3/drv/random_lm3s.c b/bertos/cpu/cortex-m3/drv/random_lm3s.c new file mode 100644 index 00000000..71ce64d5 --- /dev/null +++ b/bertos/cpu/cortex-m3/drv/random_lm3s.c @@ -0,0 +1,93 @@ +/** + * \file + * + * + * \brief LM3 backend implementation entropy pulling. + * \author Giovanni Bajo + */ + +#include "random_p.h" + +#include + +#include + +#include + +/* + * Return the cpu core temperature in raw format + */ +INLINE uint16_t hw_readRawTemp(void) +{ + /* Trig the temperature sampling */ + HWREG(ADC0_BASE + ADC_O_PSSI) |= ADC_PSSI_SS3; + + while (!(HWREG(ADC0_BASE + ADC_O_SSFSTAT3) & ADC_SSFSTAT3_FULL)) + cpu_relax(); + + return (uint16_t)HWREG(ADC0_BASE + ADC_O_SSFIFO3); +} + +INLINE void hw_initIntTemp(void) +{ + SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADC0; + + lm3s_busyWait(10); + + /* Disable all sequence */ + HWREG(ADC0_BASE + ADC_O_ACTSS) = 0; + /* Set trigger event to programmed (for all sequence) */ + HWREG(ADC0_BASE + ADC_O_EMUX) = 0; + /* Enalbe read of temperature sensor */ + HWREG(ADC0_BASE + ADC_O_SSCTL3) |= ADC_SSCTL3_TS0; + /* Enable sequence S03 (single sample on select channel) */ + HWREG(ADC0_BASE + ADC_O_ACTSS) |= ADC_ACTSS_ASEN3; +} + + +void random_pull_entropy(uint8_t *entropy, size_t len) +{ + // We use the internal temperature sensor of LM3S as a source of entropy. + // The last bit of the acquisition is very variable and with a decent distribution + // to consider it "entropic". It does not really matter because it will + // go through a randomness extractor anyway. + hw_initIntTemp(); + + for (size_t j=0; j + * + * \brief STM32 backend implementation entropy pulling. + * \author Daniele Basile + * + */ + +#include + +#include + +#include + +#include + +struct stm32_adc *adc = (struct stm32_adc *)ADC1_BASE; + +/* + * Return the cpu core temperature in raw format + */ +INLINE uint16_t hw_readRawTemp(void) +{ + /* We sample only from one channel */ + adc->SQR1 |= BV(SQR1_SQ_LEN_SHIFT); + adc->SQR3 = (ADC_TEMP_CH & SQR3_SQ_MASK); + + /* Start convertion */ + adc->CR2 |= CR2_EXTTRIG_SWSTRT_SET; + + /* Wait in polling until conversion is done */ + while (!(adc->SR & BV(SR_EOC))) + cpu_relax(); + + /* Return the last converted data */ + return (uint16_t)adc->DR; +} + +INLINE void hw_initIntTemp(void) +{ + RCC->APB2ENR |= RCC_APB2_ADC1; + + /* Reset registry */ + adc->CR1 = 0; + adc->CR2 = 0; + adc->SQR1 = 0; + adc->SQR2 = 0; + adc->SQR3 = 0; + + /* + * Configure ADC + * - Regular mode + * - Wake up adc + * - Wake up temperature and Vrefint + */ + adc->CR2 |= BV(CR2_ADON) | ADC_EXTERNALTRIGCONV_NONE | BV(CR2_TSVREFE); + + /* Set 17.1usec sampling time*/ + adc->SMPR1 |= ((ADC_SAMPLETIME_239CYCLES5 << SMPR1_CH17) | (ADC_SAMPLETIME_239CYCLES5 << SMPR1_CH16)); +} + + +void random_pull_entropy(uint8_t *entropy, size_t len) +{ + // We use the internal temperature sensor of LM3S as a source of entropy. + // The last bit of the acquisition is very variable and with a decent distribution + // to consider it "entropic". It does not really matter because it will + // go through a randomness extractor anyway. + hw_initIntTemp(); + + for (size_t j=0; j - * - * \brief LM3 backend implementation entropy pulling. - * \author Giovanni Bajo - */ - -#include "random_p.h" - -#include - -#include - -#include - -/* - * Return the cpu core temperature in raw format - */ -INLINE uint16_t hw_readRawTemp(void) -{ - /* Trig the temperature sampling */ - HWREG(ADC0_BASE + ADC_O_PSSI) |= ADC_PSSI_SS3; - - while (!(HWREG(ADC0_BASE + ADC_O_SSFSTAT3) & ADC_SSFSTAT3_FULL)) - cpu_relax(); - - return (uint16_t)HWREG(ADC0_BASE + ADC_O_SSFIFO3); -} - -INLINE void hw_initIntTemp(void) -{ - SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADC0; - - lm3s_busyWait(10); - - /* Disable all sequence */ - HWREG(ADC0_BASE + ADC_O_ACTSS) = 0; - /* Set trigger event to programmed (for all sequence) */ - HWREG(ADC0_BASE + ADC_O_EMUX) = 0; - /* Enalbe read of temperature sensor */ - HWREG(ADC0_BASE + ADC_O_SSCTL3) |= ADC_SSCTL3_TS0; - /* Enable sequence S03 (single sample on select channel) */ - HWREG(ADC0_BASE + ADC_O_ACTSS) |= ADC_ACTSS_ASEN3; -} - - -void random_pull_entropy(uint8_t *entropy, size_t len) -{ - // We use the internal temperature sensor of LM3S as a source of entropy. - // The last bit of the acquisition is very variable and with a decent distribution - // to consider it "entropic". It does not really matter because it will - // go through a randomness extractor anyway. - hw_initIntTemp(); - - for (size_t j=0; j - * - * \brief STM32 backend implementation entropy pulling. - * \author Daniele Basile - * - */ - -#include "random_p.h" - -#include - -#include - -#include - -struct stm32_adc *adc = (struct stm32_adc *)ADC1_BASE; - -/* - * Return the cpu core temperature in raw format - */ -INLINE uint16_t hw_readRawTemp(void) -{ - /* We sample only from one channel */ - adc->SQR1 |= BV(SQR1_SQ_LEN_SHIFT); - adc->SQR3 = (ADC_TEMP_CH & SQR3_SQ_MASK); - - /* Start convertion */ - adc->CR2 |= CR2_EXTTRIG_SWSTRT_SET; - - /* Wait in polling until conversion is done */ - while (!(adc->SR & BV(SR_EOC))) - cpu_relax(); - - /* Return the last converted data */ - return (uint16_t)adc->DR; -} - -INLINE void hw_initIntTemp(void) -{ - RCC->APB2ENR |= RCC_APB2_ADC1; - - /* Reset registry */ - adc->CR1 = 0; - adc->CR2 = 0; - adc->SQR1 = 0; - adc->SQR2 = 0; - adc->SQR3 = 0; - - /* - * Configure ADC - * - Regular mode - * - Wake up adc - * - Wake up temperature and Vrefint - */ - adc->CR2 |= BV(CR2_ADON) | ADC_EXTERNALTRIGCONV_NONE | BV(CR2_TSVREFE); - - /* Set 17.1usec sampling time*/ - adc->SMPR1 |= ((ADC_SAMPLETIME_239CYCLES5 << SMPR1_CH17) | (ADC_SAMPLETIME_239CYCLES5 << SMPR1_CH16)); -} - - -void random_pull_entropy(uint8_t *entropy, size_t len) -{ - // We use the internal temperature sensor of LM3S as a source of entropy. - // The last bit of the acquisition is very variable and with a decent distribution - // to consider it "entropic". It does not really matter because it will - // go through a randomness extractor anyway. - hw_initIntTemp(); - - for (size_t j=0; j