LPCOpen Platform for LPC18XX/43XX microcontrollers  18XX43XX
LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers
otp_18xx_43xx.c
Go to the documentation of this file.
1 /*
2  * @brief LPC18xx/43xx OTP Controller driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #include "chip.h"
33 
34 /*****************************************************************************
35  * Private types/enumerations/variables
36  ****************************************************************************/
37 
38 #define BOOTROM_BASE 0x10400100
39 #define OTP_API_TABLE_OFFSET 0x1
40 
41 static unsigned long *BOOTROM_API_TABLE;
42 
43 /*****************************************************************************
44  * Public types/enumerations/variables
45  ****************************************************************************/
46 
47 /*****************************************************************************
48  * Private functions
49  ****************************************************************************/
50 
51 static uint32_t (*Otp_ProgBootSrc)(CHIP_OTP_BOOT_SRC_T BootSrc);
52 static uint32_t (*Otp_ProgJTAGDis)(void);
53 static uint32_t (*Otp_ProgUSBID)(uint32_t ProductID, uint32_t VendorID);
54 static uint32_t (*Otp_ProgGP0)(uint32_t Data, uint32_t Mask);
55 static uint32_t (*Otp_ProgGP1)(uint32_t Data, uint32_t Mask);
56 static uint32_t (*Otp_ProgGP2)(uint32_t Data, uint32_t Mask);
57 static uint32_t (*Otp_ProgKey1)(uint8_t *key);
58 static uint32_t (*Otp_ProgKey2)(uint8_t *key);
59 static uint32_t (*Otp_GenRand)(void);
60 
61 /*****************************************************************************
62  * Public functions
63  ****************************************************************************/
64 
65 /* CHIP OTP Initialisation function */
66 uint32_t Chip_OTP_Init(void)
67 {
68  uint32_t (*ROM_otp_Init)(void);
69 
70  BOOTROM_API_TABLE = *((unsigned long * *) BOOTROM_BASE + OTP_API_TABLE_OFFSET);
71 
72  ROM_otp_Init = (uint32_t (*)(void))BOOTROM_API_TABLE[0];
73  Otp_ProgBootSrc = (uint32_t (*)(CHIP_OTP_BOOT_SRC_T BootSrc))BOOTROM_API_TABLE[1];
74  Otp_ProgJTAGDis = (uint32_t (*)(void))BOOTROM_API_TABLE[2];
75  Otp_ProgUSBID = (uint32_t (*)(uint32_t ProductID, uint32_t VendorID))BOOTROM_API_TABLE[3];
76  Otp_ProgGP0 = (uint32_t (*)(uint32_t Data, uint32_t Mask))BOOTROM_API_TABLE[8];
77  Otp_ProgGP1 = (uint32_t (*)(uint32_t Data, uint32_t Mask))BOOTROM_API_TABLE[9];
78  Otp_ProgGP2 = (uint32_t (*)(uint32_t Data, uint32_t Mask))BOOTROM_API_TABLE[10];
79  Otp_ProgKey1 = (uint32_t (*)(uint8_t *key))BOOTROM_API_TABLE[11];
80  Otp_ProgKey2 = (uint32_t (*)(uint8_t *key))BOOTROM_API_TABLE[12];
81  Otp_GenRand = (uint32_t (*)(void))BOOTROM_API_TABLE[13];
82 
83  return ROM_otp_Init();
84 }
85 
86 /* Program boot source in OTP Controller */
88 {
89  return Otp_ProgBootSrc(BootSrc);
90 }
91 
92 /* Program the JTAG bit in OTP Controller */
93 uint32_t Chip_OTP_ProgJTAGDis(void)
94 {
95  return Otp_ProgJTAGDis();
96 }
97 
98 /* Program USB ID in OTP Controller */
99 uint32_t Chip_OTP_ProgUSBID(uint32_t ProductID, uint32_t VendorID)
100 {
101  return Otp_ProgUSBID(ProductID, VendorID);
102 }
103 
104 /* Program OTP GP Word memory */
105 uint32_t Chip_OTP_ProgGPWord(uint32_t WordNum, uint32_t Data, uint32_t Mask)
106 {
107  uint32_t status;
108 
109  switch (WordNum) {
110  case 1:
111  status = Otp_ProgGP1(Data, Mask);
112  break;
113 
114  case 2:
115  status = Otp_ProgGP2(Data, Mask);
116  break;
117 
118  case 0:
119  default:
120  status = Otp_ProgGP0(Data, Mask);
121  break;
122  }
123 
124  return status;
125 }
126 
127 /* Program AES Key */
128 uint32_t Chip_OTP_ProgKey(uint32_t KeyNum, uint8_t *key)
129 {
130  uint32_t status;
131 
132  if (KeyNum) {
133  status = Otp_ProgKey2(key);
134  }
135  else {
136  status = Otp_ProgKey1(key);
137  }
138  return status;
139 }
140 
141 /* Generate Random Number using HW Random Number Generator */
142 uint32_t Chip_OTP_GenRand(void)
143 {
144  return Otp_GenRand();
145 }