Contiki-NG
pka.c
Go to the documentation of this file.
1/*
2 * Original file:
3 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4 * All rights reserved.
5 *
6 * Port to Contiki:
7 * Copyright (c) 2014 Andreas Dröscher <contiki@anticat.ch>
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 * OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/**
36 * \addtogroup cc2538-pka
37 * @{
38 *
39 * \file
40 * Implementation of the cc2538 PKA engine driver
41 */
42#include "contiki.h"
43#include "dev/pka.h"
44#include "dev/sys-ctrl.h"
45#include "dev/nvic.h"
46#include "lpm.h"
47#include "reg.h"
48
49#include <stdbool.h>
50#include <stdint.h>
51
52static volatile struct process *notification_process = NULL;
53/*---------------------------------------------------------------------------*/
54/** \brief The PKA engine ISR
55 *
56 * This is the interrupt service routine for the PKA engine.
57 *
58 * This ISR is called at worst from PM0, so lpm_exit() does not need
59 * to be called.
60 */
61void
63{
64 NVIC_ClearPendingIRQ(PKA_IRQn);
65 NVIC_DisableIRQ(PKA_IRQn);
66
67 if(notification_process != NULL) {
68 process_poll((struct process *)notification_process);
69 notification_process = NULL;
70 }
71}
72/*---------------------------------------------------------------------------*/
73static bool
74permit_pm1(void)
75{
76 return (REG(PKA_FUNCTION) & PKA_FUNCTION_RUN) == 0;
77}
78/*---------------------------------------------------------------------------*/
79void
81{
82 volatile int i;
83
84 lpm_register_peripheral(permit_pm1);
85
86 pka_enable();
87
88 /* Reset the PKA engine */
90 for(i = 0; i < 16; i++) {
91 REG(SYS_CTRL_SRSEC) &= ~SYS_CTRL_SRSEC_PKA;
92 }
93}
94/*---------------------------------------------------------------------------*/
95void
97{
98 /* Enable the clock for the PKA engine */
102}
103/*---------------------------------------------------------------------------*/
104void
106{
107 /* Gate the clock for the PKA engine */
108 REG(SYS_CTRL_RCGCSEC) &= ~SYS_CTRL_RCGCSEC_PKA;
109 REG(SYS_CTRL_SCGCSEC) &= ~SYS_CTRL_SCGCSEC_PKA;
110 REG(SYS_CTRL_DCGCSEC) &= ~SYS_CTRL_DCGCSEC_PKA;
111}
112/*---------------------------------------------------------------------------*/
113uint8_t
115{
116 return (REG(PKA_FUNCTION) & PKA_FUNCTION_RUN) == 0;
117}
118void
120{
121 notification_process = p;
122}
123/** @} */
@ PKA_IRQn
PKA Interrupt.
Definition: cc2538_cm3.h:112
#define PKA_FUNCTION_RUN
The host sets this bit to instruct the PKA module to begin processing the basic PKCP or complex seque...
Definition: pka.h:438
uint8_t pka_check_status(void)
Checks the status of the PKA engine operation.
Definition: pka.c:114
#define PKA_FUNCTION
PKA function This register contains the control bits to start basic PKCP as well as complex sequencer...
Definition: pka.h:173
void pka_register_process_notification(struct process *p)
Registers a process to be notified of the completion of a PKA operation.
Definition: pka.c:119
void pka_isr(void)
The PKA engine ISR.
Definition: pka.c:62
void pka_disable(void)
Disables the PKA engine.
Definition: pka.c:105
void pka_init(void)
Enables and resets the PKA engine.
Definition: pka.c:80
void pka_enable(void)
Enables the PKA engine.
Definition: pka.c:96
#define SYS_CTRL_SRSEC
Sec Mod reset control.
Definition: sys-ctrl.h:86
#define SYS_CTRL_SRSEC_PKA
PKA is reset.
Definition: sys-ctrl.h:194
#define SYS_CTRL_RCGCSEC
Sec Mod clocks - active mode.
Definition: sys-ctrl.h:83
#define SYS_CTRL_SCGCSEC_PKA
PKA clock enable, CPU IDLE.
Definition: sys-ctrl.h:180
#define SYS_CTRL_SCGCSEC
Sec Mod clocks - sleep mode.
Definition: sys-ctrl.h:84
#define SYS_CTRL_RCGCSEC_PKA
PKA clock enable, CPU running.
Definition: sys-ctrl.h:173
#define SYS_CTRL_DCGCSEC
Sec Mod clocks - PM0.
Definition: sys-ctrl.h:85
#define SYS_CTRL_DCGCSEC_PKA
PKA clock enable, PM0.
Definition: sys-ctrl.h:187
void process_poll(struct process *p)
Request a process to be polled.
Definition: process.c:371
Header file for the ARM Nested Vectored Interrupt Controller.
Header file for the cc2538 PKA engine driver.
Header file with register manipulation macro definitions.
Header file for the cc2538 System Control driver.