Contiki 3.x
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 "sys/energest.h"
44 #include "dev/pka.h"
45 #include "dev/sys-ctrl.h"
46 #include "dev/nvic.h"
47 #include "lpm.h"
48 #include "reg.h"
49 
50 #include <stdbool.h>
51 #include <stdint.h>
52 
53 static volatile struct process *notification_process = NULL;
54 /*---------------------------------------------------------------------------*/
55 /** \brief The PKA engine ISR
56  *
57  * This is the interrupt service routine for the PKA engine.
58  *
59  * This ISR is called at worst from PM0, so lpm_exit() does not need
60  * to be called.
61  */
62 void
63 pka_isr(void)
64 {
65  ENERGEST_ON(ENERGEST_TYPE_IRQ);
66 
69 
70  if(notification_process != NULL) {
71  process_poll((struct process *)notification_process);
72  notification_process = NULL;
73  }
74 
75  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
76 }
77 /*---------------------------------------------------------------------------*/
78 static bool
79 permit_pm1(void)
80 {
81  return (REG(PKA_FUNCTION) & PKA_FUNCTION_RUN) == 0;
82 }
83 /*---------------------------------------------------------------------------*/
84 void
85 pka_init(void)
86 {
87  volatile int i;
88 
89  lpm_register_peripheral(permit_pm1);
90 
91  pka_enable();
92 
93  /* Reset the PKA engine */
95  for(i = 0; i < 16; i++) {
97  }
98 }
99 /*---------------------------------------------------------------------------*/
100 void
102 {
103  /* Enable the clock for the PKA engine */
107 }
108 /*---------------------------------------------------------------------------*/
109 void
111 {
112  /* Gate the clock for the PKA engine */
116 }
117 /*---------------------------------------------------------------------------*/
118 uint8_t
120 {
121  return (REG(PKA_FUNCTION) & PKA_FUNCTION_RUN) == 0;
122 }
123 void
125 {
126  notification_process = p;
127 }
128 /** @} */
void process_poll(struct process *p)
Request a process to be polled.
Definition: process.c:371
#define SYS_CTRL_SCGCSEC_PKA
PKA clock enable, CPU IDLE.
Definition: sys-ctrl.h:180
Header file with register manipulation macro definitions.
void pka_init(void)
Enables and resets the PKA engine.
Definition: pka.c:85
void pka_disable(void)
Disables the PKA engine.
Definition: pka.c:110
#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:733
Header file for the ARM Nested Vectored Interrupt Controller.
#define SYS_CTRL_DCGCSEC_PKA
PKA clock enable, PM0.
Definition: sys-ctrl.h:187
Header file for the energy estimation mechanism
#define PKA_FUNCTION
PKA function This register contains the control bits to start basic PKCP as well as complex sequencer...
Definition: pka.h:273
#define SYS_CTRL_SCGCSEC
Sec Mod clocks - sleep mode.
Definition: sys-ctrl.h:84
void pka_register_process_notification(struct process *p)
Registers a process to be notified of the completion of a PKA operation.
Definition: pka.c:124
#define NULL
The null pointer.
void nvic_interrupt_unpend(uint32_t intr)
Sets intr to no longer pending.
Definition: nvic.c:106
#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_DCGCSEC
Sec Mod clocks - PM0.
Definition: sys-ctrl.h:85
Header file for the cc2538 System Control driver.
void lpm_register_peripheral(lpm_periph_permit_pm1_func_t permit_pm1_func)
Register a peripheral function which will get called by the LPM module to get 'permission' to drop to...
void pka_isr(void)
The PKA engine ISR.
Definition: pka.c:63
uint8_t pka_check_status(void)
Checks the status of the PKA engine operation.
Definition: pka.c:119
void nvic_interrupt_disable(uint32_t intr)
Disables interrupt intr.
Definition: nvic.c:71
#define SYS_CTRL_RCGCSEC_PKA
PKA clock enable, CPU running.
Definition: sys-ctrl.h:173
#define SYS_CTRL_RCGCSEC
Sec Mod clocks - active mode.
Definition: sys-ctrl.h:83
void pka_enable(void)
Enables the PKA engine.
Definition: pka.c:101
Header file for the cc2538 PKA engine driver.
#define NVIC_INT_PKA
PKA.
Definition: nvic.h:99