summaryrefslogtreecommitdiff
path: root/polux/devkit/plc-polux/gpio/gpio_management.c
blob: b90ef5b86aed43785b0ae5dc7399fc695803d53e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/************************************************************/
/*!
  \file gpio_management.c
  \brief GPIO management routines

  \author Philippe Petillon (philippe.petillon@elsys-design.com)
  \author Joseph Antunes (joseph.antunes@spidcom.com)
  \author (c) Spidcom Technologies

  \version 1.0
  \date 04/02/04
*/
/************************************************************/


#ifdef __KERNEL__
#include "hal.h"
#else
#include <stdint.h>
#include "shell.h"
#endif
#include "platform.h"
#include "gpio.h"

#if defined(CONFIG_ARCH_MSE500)
#include "asm/arch/gpio.h"
#endif /* CONFIG_ARCH_MSE500 */

#ifdef SP_CRISTINA
static ApGpio_dev_t *ApGpio_dev = (ApGpio_dev_t *) GPIO_BASE;
#endif

int shell_software_reset_no_wait(int argc, char **argv) {
#ifdef SP_CRISTINA
  // software reset on GPIO
  // 31     : OUT (software reset)
  ApGpio_dev->GPIO_31_24.direction = 0x7F;
  ApGpio_dev->GPIO_31_24.data_out &= ~0x80;
#endif 
  return RET_SUCCESS;
}

#ifndef __KERNEL__
int shell_software_reset(int argc, char **argv) {
#ifdef SP_CRISTINA
  trace_and_wait_for_reset();
  shell_mibSave(0, NULL);
  ApGpio_dev = (ApGpio_dev_t *) GPIO_BASE;

  // software reset on GPIO
  // 31     : OUT (software reset)
  ApGpio_dev->GPIO_31_24.direction = 0x7F;
  ApGpio_dev->GPIO_31_24.data_out &= ~0x80;
#endif 
  return RET_SUCCESS;
}

/* If dip-switch is on reset , otherwise not */
int soft_reset() {
#ifdef SP_CRISTINA
  ApGpio_dev = (ApGpio_dev_t *) GPIO_BASE;

  // software recovery on GPIO
  // 1     : IN (software recovery on CRISTINA 1)
  // 6     : IN (software recovery on CRISTINA 2)
  ApGpio_dev->GPIO_7_0.direction = 0xFF;
#ifdef CLK60 /* CRISTINA 2 */
  if (ApGpio_dev->GPIO_7_0.data_in & (1<<6)) {
#else 
  if (ApGpio_dev->GPIO_7_0.data_in & (1<<1)) {
#endif
    shell_software_reset_no_wait(0, NULL);
  }
#endif /* SP_CRISTINA */ 
  return RET_SUCCESS;
}
#endif

int plc_system_led(bool value, bool low_level_on)
{
	value ^= low_level_on;
#ifdef SP_CRISTINA
	if (value)
		ApGpio_dev->GPIO_15_8.data_out |= (1<<5) ;
	else
		ApGpio_dev->GPIO_15_8.data_out &=  (~(1<<5));
	ApGpio_dev->GPIO_15_8.direction = 0;
#elif defined(SP_LISA)
        if(value)
               CSP_PIO_SET_SODR((CSP_PIO_PTR)CSP_PIO_BASE, (unsigned int)(1<<7));
        else
               CSP_PIO_SET_CODR((CSP_PIO_PTR)CSP_PIO_BASE, (unsigned int)(1<<7));
#elif defined(CONFIG_ARCH_MSE500)
    gpio_write(GPIO_OUT_PLC_SYSTEM_LED, (int)value);
#endif
	return 0;
}