PageRenderTime 34ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/bus/au1500.c

https://bitbucket.org/rsachetto/urjtag-debian-package
C | 310 lines | 196 code | 58 blank | 56 comment | 13 complexity | e845691ce1ce2697a337608c3395e887 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * $Id: au1500.c 1366 2008-09-26 22:14:08Z arniml $
  3. *
  4. * Copyright (C) 2003 BLXCPU co. Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. *
  21. * Written by ZHANG WEI <zwblue@sohu.com>, 2003
  22. *
  23. * Documentation:
  24. * [1] AMD, "AMD Alchemy Solutions AU1500 Processor Data Book -
  25. * Preliminary Information", June 2003, Publication ID: 30361B
  26. *
  27. */
  28. #include "sysdep.h"
  29. #include <string.h>
  30. #include <stdint.h>
  31. #include <stdlib.h>
  32. #include "part.h"
  33. #include "bus.h"
  34. #include "chain.h"
  35. #include "bssignal.h"
  36. #include "jtag.h"
  37. #include "buses.h"
  38. #include "generic_bus.h"
  39. typedef struct{
  40. signal_t *rad[32];
  41. signal_t *nrcs[4];
  42. signal_t *nrwe;
  43. signal_t *nroe;
  44. signal_t *rd[32];
  45. } bus_params_t;
  46. #define RAD ((bus_params_t *) bus->params)->rad
  47. #define nRCS ((bus_params_t *) bus->params)->nrcs
  48. #define nRWE ((bus_params_t *) bus->params)->nrwe
  49. #define nROE ((bus_params_t *) bus->params)->nroe
  50. #define RD ((bus_params_t *) bus->params)->rd
  51. /**
  52. * bus->driver->(*new_bus)
  53. *
  54. */
  55. static bus_t *au1500_bus_new( chain_t *chain, const bus_driver_t *driver, char *cmd_params[] )
  56. {
  57. bus_t *bus;
  58. part_t *part;
  59. char buff[10];
  60. int i;
  61. int failed = 0;
  62. bus = calloc( 1, sizeof (bus_t) );
  63. if (!bus)
  64. return NULL;
  65. bus->driver = driver;
  66. bus->params = calloc( 1, sizeof(bus_params_t) );
  67. if (!bus->params){
  68. free(bus);
  69. return NULL;
  70. }
  71. CHAIN = chain;
  72. PART = part = chain->parts->parts[chain->active_part];
  73. for(i=0; i<32; i++){
  74. sprintf( buff, "RAD%d", i);
  75. failed |= generic_bus_attach_sig( part, &(RAD[i]), buff );
  76. }
  77. for(i=0; i<4; i++){
  78. sprintf( buff, "RCE_N%d", i);
  79. failed |= generic_bus_attach_sig( part, &(nRCS[i]), buff );
  80. }
  81. failed |= generic_bus_attach_sig( part, &(nRWE), "RWE_N" );
  82. failed |= generic_bus_attach_sig( part, &(nROE), "ROE_N" );
  83. for(i=0; i<32; i++){
  84. sprintf( buff, "RD%d", i);
  85. failed |= generic_bus_attach_sig( part, &(RD[i]), buff );
  86. }
  87. if (failed) {
  88. free( bus->params );
  89. free ( bus );
  90. return NULL;
  91. }
  92. return bus;
  93. }
  94. /**
  95. * bus->driver->(*printinfo)
  96. *
  97. */
  98. static void
  99. au1500_bus_printinfo( bus_t *bus)
  100. {
  101. int i;
  102. for (i = 0; i < CHAIN->parts->len; i++)
  103. if (PART == CHAIN->parts->parts[i])
  104. break;
  105. printf( _("AU1500 compatible bus driver via BSR (JTAG part No. %d)\n"), i );
  106. }
  107. /**
  108. * bus->driver->(*area)
  109. *
  110. */
  111. static int
  112. au1500_bus_area(bus_t *bus, uint32_t addr, bus_area_t *area)
  113. {
  114. area->description = NULL;
  115. area->start = UINT32_C(0x00000000);
  116. area->length = UINT64_C(0x00100000000);
  117. // area->width = 16;
  118. area->width = part_get_signal( PART, part_find_signal( PART, "ROMSIZ" ) ) ? 16 : 32;
  119. return URJTAG_STATUS_OK;
  120. }
  121. static void
  122. setup_address( bus_t *bus, uint32_t a)
  123. {
  124. int i;
  125. part_t *p = PART;
  126. for( i = 0; i < 32; i++)
  127. part_set_signal( p, RAD[i], 1, (a >>i) & 1);
  128. }
  129. static void
  130. set_data_in( bus_t *bus )
  131. {
  132. int i;
  133. part_t *p = PART;
  134. bus_area_t area;
  135. au1500_bus_area( bus, 0, &area);
  136. for( i = 0; i < area.width; i++ )
  137. part_set_signal( p, RD[i], 0, 0 );
  138. }
  139. static uint32_t
  140. get_data_out( bus_t *bus )
  141. {
  142. int i;
  143. part_t *p = PART;
  144. bus_area_t area;
  145. uint32_t d = 0;
  146. au1500_bus_area( bus, 0, &area);
  147. for( i = 0; i < area.width; i++ )
  148. d |= (uint32_t)(part_get_signal( p, RD[i] ) << i);
  149. return d;
  150. }
  151. static void
  152. setup_data( bus_t *bus, uint32_t d)
  153. {
  154. int i;
  155. part_t *p = PART;
  156. bus_area_t area;
  157. au1500_bus_area( bus, 0, &area);
  158. for( i = 0; i < area.width; i++ )
  159. part_set_signal( p, RD[i], 1, ( d>>i ) & 1 );
  160. }
  161. /**
  162. * bus->driver->(*read_start)
  163. *
  164. */
  165. static void
  166. au1500_bus_read_start( bus_t *bus, uint32_t adr )
  167. {
  168. part_t *p = PART;
  169. chain_t *chain = CHAIN;
  170. part_set_signal( p, nRCS[0], 1, 0 );
  171. part_set_signal( p, nRCS[1], 1, 1 );
  172. part_set_signal( p, nRCS[2], 1, 1 );
  173. part_set_signal( p, nRCS[3], 1, 1 );
  174. part_set_signal( p, nRWE, 1, 1 );
  175. part_set_signal( p, nROE, 1, 0);
  176. setup_address( bus, adr);
  177. set_data_in( bus );
  178. chain_shift_data_registers( chain, 0 );
  179. }
  180. /**
  181. * bus->driver->(*read_next)
  182. *
  183. */
  184. static uint32_t
  185. au1500_bus_read_next( bus_t *bus, uint32_t adr )
  186. {
  187. chain_t *chain = CHAIN;
  188. setup_address( bus, adr );
  189. chain_shift_data_registers( chain, 1 );
  190. return get_data_out( bus );
  191. }
  192. /**
  193. * bus->driver->(*read_end)
  194. *
  195. */
  196. static uint32_t
  197. au1500_bus_read_end( bus_t *bus )
  198. {
  199. part_t *p = PART;
  200. chain_t *chain = CHAIN;
  201. part_set_signal( p, nRCS[0], 1, 1 );
  202. part_set_signal( p, nRCS[1], 1, 1 );
  203. part_set_signal( p, nRCS[2], 1, 1 );
  204. part_set_signal( p, nRCS[3], 1, 1 );
  205. part_set_signal( p, nRWE, 1, 1 );
  206. part_set_signal( p, nROE, 1, 1 );
  207. chain_shift_data_registers( chain, 1 );
  208. return get_data_out( bus );
  209. }
  210. /**
  211. * bus->driver->(*write)
  212. *
  213. */
  214. static void
  215. au1500_bus_write( bus_t *bus, uint32_t adr, uint32_t data )
  216. {
  217. part_t *p = PART;
  218. chain_t *chain = CHAIN;
  219. part_set_signal( p, nRCS[0], 1, 0 );
  220. part_set_signal( p, nRCS[1], 1, 1 );
  221. part_set_signal( p, nRCS[2], 1, 1 );
  222. part_set_signal( p, nRCS[3], 1, 1 );
  223. part_set_signal( p, nRWE, 1, 1 );
  224. part_set_signal( p, nROE, 1, 1 );
  225. setup_address( bus, adr );
  226. setup_data( bus, data );
  227. chain_shift_data_registers( chain, 0 );
  228. part_set_signal( p, nRWE, 1, 0 );
  229. chain_shift_data_registers( chain, 0 );
  230. part_set_signal( p, nRWE, 1, 1);
  231. part_set_signal( p, nROE, 1, 1);
  232. part_set_signal( p, nRCS[0], 1, 1);
  233. part_set_signal( p, nRCS[1], 1, 1 );
  234. part_set_signal( p, nRCS[2], 1, 1 );
  235. part_set_signal( p, nRCS[3], 1, 1 );
  236. chain_shift_data_registers( chain, 0);
  237. }
  238. const bus_driver_t au1500_bus = {
  239. "au1500",
  240. N_("AU1500 BUS Driver via BSR"),
  241. au1500_bus_new,
  242. generic_bus_free,
  243. au1500_bus_printinfo,
  244. generic_bus_prepare_extest,
  245. au1500_bus_area,
  246. au1500_bus_read_start,
  247. au1500_bus_read_next,
  248. au1500_bus_read_end,
  249. generic_bus_read,
  250. au1500_bus_write,
  251. generic_bus_no_init
  252. };