2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 __xdata uint8_t ao_aes_mutex;
21 __xdata uint8_t ao_aes_done;
22 __xdata uint8_t ao_aes_dma_in, ao_aes_dma_out;
23 __xdata uint8_t ao_aes_dma_in_done, ao_aes_dma_out_done;
24 __pdata enum ao_aes_mode ao_aes_current_mode;
27 ao_aes_isr(void) __interrupt 4
30 if (ENCCCS & ENCCCS_RDY) {
32 ao_wakeup(&ao_aes_done);
37 ao_aes_set_mode(enum ao_aes_mode mode)
39 ao_aes_current_mode = mode;
43 ao_aes_set_key(__xdata uint8_t *in)
45 ao_dma_set_transfer(ao_aes_dma_in,
50 DMA_CFG0_TMODE_SINGLE |
51 DMA_CFG0_TRIGGER_ENC_DW,
54 DMA_CFG1_PRIORITY_LOW);
56 ENCCCS = ENCCCS_MODE_CBC_MAC |
60 ao_sleep(&ao_aes_done);
64 ao_aes_run(__xdata uint8_t *in,
69 ao_dma_set_transfer(ao_aes_dma_in,
74 DMA_CFG0_TMODE_SINGLE |
75 DMA_CFG0_TRIGGER_ENC_DW,
78 DMA_CFG1_PRIORITY_LOW);
81 ao_dma_set_transfer(ao_aes_dma_out,
86 DMA_CFG0_TMODE_SINGLE |
87 DMA_CFG0_TRIGGER_ENC_UP,
90 DMA_CFG1_PRIORITY_LOW);
92 switch (ao_aes_current_mode) {
93 case ao_aes_mode_cbc_mac:
95 b = (ENCCCS_MODE_CBC |
99 b = (ENCCCS_MODE_CBC_MAC |
109 while (!ao_aes_dma_out_done)
110 ao_sleep(&ao_aes_dma_out_done);
113 ao_sleep(&ao_aes_done);
119 ao_aes_dma_in = ao_dma_alloc(&ao_aes_dma_in_done);
120 ao_aes_dma_out = ao_dma_alloc(&ao_aes_dma_out_done);