added prescaler for 16 bit pwm in LPC1347 target
Fork of mbed-dev by
targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_MCU_K64F/entropy_hardware_poll.c@144:ef7eb2e8f9f7, 2016-09-02 (annotated)
- Committer:
- <>
- Date:
- Fri Sep 02 15:07:44 2016 +0100
- Revision:
- 144:ef7eb2e8f9f7
This updates the lib to the mbed lib v125
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* |
<> | 144:ef7eb2e8f9f7 | 2 | * Hardware entropy collector for the K64F, using Freescale's RNGA |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
<> | 144:ef7eb2e8f9f7 | 5 | * SPDX-License-Identifier: Apache-2.0 |
<> | 144:ef7eb2e8f9f7 | 6 | * |
<> | 144:ef7eb2e8f9f7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
<> | 144:ef7eb2e8f9f7 | 8 | * not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 9 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 10 | * |
<> | 144:ef7eb2e8f9f7 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 12 | * |
<> | 144:ef7eb2e8f9f7 | 13 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
<> | 144:ef7eb2e8f9f7 | 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 16 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 17 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 18 | * |
<> | 144:ef7eb2e8f9f7 | 19 | */ |
<> | 144:ef7eb2e8f9f7 | 20 | |
<> | 144:ef7eb2e8f9f7 | 21 | /* |
<> | 144:ef7eb2e8f9f7 | 22 | * Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34 |
<> | 144:ef7eb2e8f9f7 | 23 | */ |
<> | 144:ef7eb2e8f9f7 | 24 | |
<> | 144:ef7eb2e8f9f7 | 25 | #include <stdlib.h> |
<> | 144:ef7eb2e8f9f7 | 26 | #include "cmsis.h" |
<> | 144:ef7eb2e8f9f7 | 27 | #include "fsl_common.h" |
<> | 144:ef7eb2e8f9f7 | 28 | #include "fsl_clock.h" |
<> | 144:ef7eb2e8f9f7 | 29 | |
<> | 144:ef7eb2e8f9f7 | 30 | /* |
<> | 144:ef7eb2e8f9f7 | 31 | * Get one byte of entropy from the RNG, assuming it is up and running. |
<> | 144:ef7eb2e8f9f7 | 32 | * As recommended (34.1.1), get only one bit of each output. |
<> | 144:ef7eb2e8f9f7 | 33 | */ |
<> | 144:ef7eb2e8f9f7 | 34 | static void rng_get_byte( unsigned char *byte ) |
<> | 144:ef7eb2e8f9f7 | 35 | { |
<> | 144:ef7eb2e8f9f7 | 36 | size_t bit; |
<> | 144:ef7eb2e8f9f7 | 37 | |
<> | 144:ef7eb2e8f9f7 | 38 | /* 34.5 Steps 3-4-5: poll SR and read from OR when ready */ |
<> | 144:ef7eb2e8f9f7 | 39 | for( bit = 0; bit < 8; bit++ ) |
<> | 144:ef7eb2e8f9f7 | 40 | { |
<> | 144:ef7eb2e8f9f7 | 41 | while( ( RNG->SR & RNG_SR_OREG_LVL_MASK ) == 0 ); |
<> | 144:ef7eb2e8f9f7 | 42 | *byte |= ( RNG->OR & 1 ) << bit; |
<> | 144:ef7eb2e8f9f7 | 43 | } |
<> | 144:ef7eb2e8f9f7 | 44 | } |
<> | 144:ef7eb2e8f9f7 | 45 | |
<> | 144:ef7eb2e8f9f7 | 46 | /* |
<> | 144:ef7eb2e8f9f7 | 47 | * Get len bytes of entropy from the hardware RNG. |
<> | 144:ef7eb2e8f9f7 | 48 | */ |
<> | 144:ef7eb2e8f9f7 | 49 | int mbedtls_hardware_poll( void *data, |
<> | 144:ef7eb2e8f9f7 | 50 | unsigned char *output, size_t len, size_t *olen ) |
<> | 144:ef7eb2e8f9f7 | 51 | { |
<> | 144:ef7eb2e8f9f7 | 52 | size_t i; |
<> | 144:ef7eb2e8f9f7 | 53 | int ret; |
<> | 144:ef7eb2e8f9f7 | 54 | ((void) data); |
<> | 144:ef7eb2e8f9f7 | 55 | |
<> | 144:ef7eb2e8f9f7 | 56 | CLOCK_EnableClock( kCLOCK_Rnga0 ); |
<> | 144:ef7eb2e8f9f7 | 57 | CLOCK_DisableClock( kCLOCK_Rnga0 ); |
<> | 144:ef7eb2e8f9f7 | 58 | CLOCK_EnableClock( kCLOCK_Rnga0 ); |
<> | 144:ef7eb2e8f9f7 | 59 | |
<> | 144:ef7eb2e8f9f7 | 60 | /* Set "Interrupt Mask", "High Assurance" and "Go", |
<> | 144:ef7eb2e8f9f7 | 61 | * unset "Clear interrupt" and "Sleep" */ |
<> | 144:ef7eb2e8f9f7 | 62 | RNG->CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK; |
<> | 144:ef7eb2e8f9f7 | 63 | |
<> | 144:ef7eb2e8f9f7 | 64 | for( i = 0; i < len; i++ ) |
<> | 144:ef7eb2e8f9f7 | 65 | rng_get_byte( output + i ); |
<> | 144:ef7eb2e8f9f7 | 66 | |
<> | 144:ef7eb2e8f9f7 | 67 | /* Just be extra sure that we didn't do it wrong */ |
<> | 144:ef7eb2e8f9f7 | 68 | if( ( RNG->SR & RNG_SR_SECV_MASK ) != 0 ) |
<> | 144:ef7eb2e8f9f7 | 69 | { |
<> | 144:ef7eb2e8f9f7 | 70 | ret = -1; |
<> | 144:ef7eb2e8f9f7 | 71 | goto cleanup; |
<> | 144:ef7eb2e8f9f7 | 72 | } |
<> | 144:ef7eb2e8f9f7 | 73 | |
<> | 144:ef7eb2e8f9f7 | 74 | *olen = len; |
<> | 144:ef7eb2e8f9f7 | 75 | ret = 0; |
<> | 144:ef7eb2e8f9f7 | 76 | |
<> | 144:ef7eb2e8f9f7 | 77 | cleanup: |
<> | 144:ef7eb2e8f9f7 | 78 | /* Disable clock to save power - assume we're the only users of RNG */ |
<> | 144:ef7eb2e8f9f7 | 79 | CLOCK_DisableClock( kCLOCK_Rnga0 ); |
<> | 144:ef7eb2e8f9f7 | 80 | |
<> | 144:ef7eb2e8f9f7 | 81 | return( ret ); |
<> | 144:ef7eb2e8f9f7 | 82 | } |
<> | 144:ef7eb2e8f9f7 | 83 |