libctr9
Nintendo 3DS ARM9 library
protocol_ctr.h
1 // Copyright 2014 Normmatt
2 // Licensed under GPLv2 or any later version
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <stdint.h>
8 #include <stdbool.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define REG_CTRCARDCNT (*(volatile uint32_t*)0x10004000)
15 #define REG_CTRCARDBLKCNT (*(volatile uint32_t*)0x10004004)
16 #define REG_CTRCARDSECCNT (*(volatile uint32_t*)0x10004008)
17 #define REG_CTRCARDSECSEED (*(volatile uint32_t*)0x10004010)
18 #define REG_CTRCARDCMD ((volatile uint32_t*)0x10004020)
19 #define REG_CTRCARDFIFO (*(volatile uint32_t*)0x10004030)
20 
21 #define CTRCARD_PAGESIZE_0 (0<<16)
22 #define CTRCARD_PAGESIZE_4 (1u<<16)
23 #define CTRCARD_PAGESIZE_16 (2u<<16)
24 #define CTRCARD_PAGESIZE_64 (3u<<16)
25 #define CTRCARD_PAGESIZE_512 (4u<<16)
26 #define CTRCARD_PAGESIZE_1K (5u<<16)
27 #define CTRCARD_PAGESIZE_2K (6u<<16)
28 #define CTRCARD_PAGESIZE_4K (7u<<16)
29 #define CTRCARD_PAGESIZE_16K (8u<<16)
30 #define CTRCARD_PAGESIZE_64K (9u<<16)
31 
32 #define CTRCARD_CRC_ERROR (1u<<4)
33 #define CTRCARD_ACTIVATE (1u<<31) // when writing, get the ball rolling
34 #define CTRCARD_IE (1u<<30) // Interrupt enable
35 #define CTRCARD_WR (1u<<29) // Card write enable
36 #define CTRCARD_nRESET (1u<<28) // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
37 #define CTRCARD_BLK_SIZE(n) (((n)&0xFu)<<16) // Transfer block size
38 
39 #define CTRCARD_BUSY (1u<<31) // when reading, still expecting incomming data?
40 #define CTRCARD_DATA_READY (1u<<27) // when reading, REG_CTRCARDFIFO has another word of data and is good to go
41 
42 #define CTRKEY_PARAM 0x1000000u
43 
44 void CTR_SetSecKey(uint32_t value);
45 void CTR_SetSecSeed(const uint32_t* seed, bool flag);
46 
47 void CTR_SendCommand(const uint32_t command[4], uint32_t pageSize, uint32_t blocks, uint32_t latency, void* buffer);
48 
49 #ifdef __cplusplus
50 }
51 #endif
52