Skip to content

Commit

Permalink
#374 first example running with HW CIAA-NXP
Browse files Browse the repository at this point in the history
  • Loading branch information
jcecconi committed Jan 13, 2016
1 parent 912c840 commit fe37f5f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 32 deletions.
10 changes: 5 additions & 5 deletions examples/hisio_example/etc/hisio_example.oil
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ DIL DIL {
DIO MyDioConfig {
ERRORHOOK = TRUE;

PIN Led1 {
PORT = 3;
PIN = 7;
PIN MOSFET1 {
PORT = 4;
PIN = 8;
DIRECTION = OUTPUT_INIT_LOW;
INVERTED = TRUE;
}

PIN Led2 {
PIN Relay1 {
PORT = 4;
PIN = 5;
PIN = 4;
DIRECTION = OUTPUT_INIT_HIGH;
INVERTED = FALSE;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/hisio_example/src/hisio_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ int main(void)
{
/* set the Led1 pin to HIGH, this will really set the port to 0V since
* the pin is configured as inverted in the DIL File */
Dio_SetSync(Led1, IO_HIGH);
Dio_SetSync(MOSFET1, IO_HIGH);
}
else
{
Dio_SetSync(Led1, IO_LOW);
Dio_SetSync(MOSFET1, IO_LOW);
}

/* set the DataBus port to the value 0x3F */
Expand All @@ -129,7 +129,7 @@ int main(void)

/* DIO Notifications will not be supported in te first version */

for(loop = 0; loop < 0xFFFF; loop++) {
for(loop = 0; loop < 0x3FFFFF; loop++) {
/* do nothing */
/* again a good example how not to perform a dealy. this delay
* will keep the cpu on his maximal speed and wasting energy... :( */
Expand Down
28 changes: 20 additions & 8 deletions modules/hisio/gen/helpers/cortexM4/lpc43xx/lpc4337/hisio.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@
/** \addtogroup HISIO HisIO Module
** @{ */

class Hisio_Base {
}

class Hisio extends Hisio_Base {

public $dio_pins;
function __construct() {
print "Y_constructor_finished\n" ;
}
$this->init();
}
function init() {
$dio_pins = array (
$this->dio_pins = array (
/* port GPIO0 */
"GPIO0[0]" => "P0_0",
"GPIO0[1]" => "P0_1",
Expand Down Expand Up @@ -84,8 +88,17 @@ function init() {
"GPIO1[13]" => "P2_13",
"GPIO1[14]" => "P3_4",
"GPIO1[15]" => "P3_5",
/* port GPIO2 */
"GPIO2[4]" => "P4_4",
"GPIO2[5]" => "P4_5",
"GPIO2[6]" => "P4_6",
/* port GPIO5 */
"GPIO5[1]" => "P2_1",
"GPIO5[12]" => "P4_8",
"GPIO5[13]" => "P4_9",
"GPIO5[14]" => "P4_10",
);
$this->addDioPins($dio_pins);
/* $this->addDioPins($dio_pins); */

$dio_ports = array (
"GPIO0" => array (
Expand Down Expand Up @@ -125,13 +138,13 @@ function init() {
"P3_5",
)
);
$this->addDioPorts($dio_ports);
/* $this->addDioPorts($dio_ports); */

$pwm_ports = array (
"PWM0" => "P4_0",
"PWM1" => "P5_5"
);
$this->addPwm($pwm_ports);
/* $this->addPwm($pwm_ports); */

$uart_ports = array (
"U0" => array (
Expand Down Expand Up @@ -161,8 +174,7 @@ function init() {
"ADC0_4" => "P7_4",
"ADC0_3" => "P7_5",
);

$this->addAdc($adc_ports);
/* $this->addAdc($adc_ports); */
}


Expand Down
2 changes: 2 additions & 0 deletions modules/hisio/gen/inc/Dio_Cfg.h.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
typedef struct {
uint8_t Port;
uint8_t Pin;
uint8_t GPIO_Port;
uint8_t GPIO_Pin;
uint32_t Flags; /* Inverted, Direction, I/O, etc */
} Dio_PinConfigType;

Expand Down
16 changes: 13 additions & 3 deletions modules/hisio/gen/src/Dio_Cfg.c.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@
/*==================[external data definition]==============================*/

<?php

require_once './modules/hisio/gen/helpers/cortexM4/lpc43xx/lpc4337/hisio.php';
$MyHisio = new Hisio;

$dios = $config->getList("/DIL", "DIO");
foreach ($dios as $count=>$dio) {
if ($count != 0) {
$this->error("Maximal one configuration is supported.");
$this->log->error("Maximal one configuration is supported.");
}
$pins = $config->getList("/DIL/" . $dio, "PIN");

Expand All @@ -86,6 +90,12 @@
foreach($pins as $count=>$pin) {
$pin_port = $config->getValue("/DIL/" . $dio . "/" . $pin, "PORT");
$pin_pin = $config->getValue("/DIL/" . $dio . "/" . $pin, "PIN");
$GPIO = array_search("P" . $pin_port . "_" . $pin_pin, $MyHisio->dio_pins);
if ($GPIO == NULL) {
$this->log->error("PIN " . $pin . " has a 'Port-Pin' pair that doesn't match a valid GPIO.");
}
sscanf($GPIO, "GPIO%d[%d]", $GPIO_Port, $GPIO_Pin);

$pin_direction = $config->getValue("/DIL/" . $dio . "/" . $pin, "DIRECTION");
switch ($pin_direction)
{
Expand All @@ -111,8 +121,8 @@
$this->log->error("The pin $pin hasn't a defined 'inverted' configuration!");
break;
}
print "/** \brief Port: " . $pin_port . " Pin: " . $pin_pin . " called " . $pin . " */\n";
print "{" . $pin_port . "," . $pin_pin . "," . $pin_flags . "},\n";
print "/** \brief Port: " . $pin_port . " Pin: " . $pin_pin . " , " . $GPIO . " called " . $pin . " */\n";
print "{" . $pin_port . "," . $pin_pin . "," . $GPIO_Port . "," . $GPIO_Pin . "," . $pin_flags . "},\n";
}
print "}\n";
print ", 0 /* foo var */\n";
Expand Down
11 changes: 8 additions & 3 deletions modules/hisio/inc/cortexM4/lpc43xx/lpc4337/Dio_Arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ extern "C" {
#endif

/*==================[macros]=================================================*/
#define Dio_SetSync_Arch

#define Dio_GetSync_Arch

/*==================[typedef]================================================*/

Expand All @@ -79,6 +76,14 @@ extern "C" {
**/
extern IO_ErrorType Dio_InitSync_Arch(void * address);

/** \brief
**/
extern void Dio_SetSync_Arch(IO_ChannelType channel, IO_ValueType value);

/** \brief
**/
extern IO_ValueType Dio_GetSync_Arch(IO_ChannelType channel);

/*==================[cplusplus]==============================================*/
#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions modules/hisio/src/Dio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ extern IO_ErrorType Dio_InitSync(void * address)

extern IO_ValueType Dio_GetSync(IO_ChannelType channel)
{
return IO_HIGH;
return Dio_GetSync_Arch(channel);
}

extern void Dio_SetSync(IO_ChannelType channel, IO_ValueType value)
{

Dio_SetSync_Arch(channel, value);
}

extern IO_ValueType Dio_GetPortSync(IO_ChannelType channel)
Expand Down
44 changes: 36 additions & 8 deletions modules/hisio/src/cortexM4/lpc43xx/lpc4337/Dio_Arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@

/*==================[inclusions]=============================================*/
#include "IODriver_Base.h"
#include "Dio_Cfg.h"
#include "chip.h"

/*==================[macros and definitions]=================================*/

/*==================[internal data declaration]==============================*/
Expand All @@ -79,28 +82,53 @@ extern IO_ErrorType Dio_InitSync_Arch(void * address)
{
if(Dio_Config.Pins[i].Flags & DIO_CONFIG_PIN_DIRECTION_INPUT)
{
Chip_SCU_PinMux(Dio_Config.Pins[i].Port, Dio_Config.Pins[i].Pin, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS, FUNC0);
//Chip_GPIO_SetDir( LPC_GPIO_PORT, gpioPort, ( 1 << gpioPin ), INPUT );
Chip_SCU_PinMux(Dio_Config.Pins[i].Port, Dio_Config.Pins[i].Pin, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS, FUNC0); /* Set it as GPIO */
Chip_GPIO_SetDir(LPC_GPIO_PORT, Dio_Config.Pins[i].GPIO_Port, (1 << Dio_Config.Pins[i].GPIO_Pin), 0); /* Set it as input */
}
else if(Dio_Config.Pins[i].Flags & DIO_CONFIG_PIN_DIRECTION_OUTPUT_INIT_LOW)
{
Chip_SCU_PinMux(Dio_Config.Pins[i].Port, Dio_Config.Pins[i].Pin, SCU_MODE_INACT | SCU_MODE_ZIF_DIS, FUNC0);
//Chip_GPIO_SetDir( LPC_GPIO_PORT, gpioPort, ( 1 << gpioPin ), OUTPUT );
//Chip_GPIO_ClearValue(LPC_GPIO_PORT, gpioPort, ( 1 << gpioPin ));
Chip_SCU_PinMux(Dio_Config.Pins[i].Port, Dio_Config.Pins[i].Pin, SCU_MODE_INACT | SCU_MODE_ZIF_DIS, FUNC4);
Chip_GPIO_SetDir(LPC_GPIO_PORT, Dio_Config.Pins[i].GPIO_Port, (1 << Dio_Config.Pins[i].GPIO_Pin), 1); /* Set it as output */
Chip_GPIO_SetPinState(LPC_GPIO_PORT, Dio_Config.Pins[i].GPIO_Port, Dio_Config.Pins[i].GPIO_Pin, 0); /* Set it as low */
}
else if(Dio_Config.Pins[i].Flags & DIO_CONFIG_PIN_DIRECTION_OUTPUT_INIT_HIGH)
{
Chip_SCU_PinMux(Dio_Config.Pins[i].Port, Dio_Config.Pins[i].Pin, SCU_MODE_INACT | SCU_MODE_ZIF_DIS, FUNC4);
Chip_GPIO_SetDir(LPC_GPIO_PORT, Dio_Config.Pins[i].GPIO_Port, (1 << Dio_Config.Pins[i].GPIO_Pin), 1); /* Set it as output */
Chip_GPIO_SetPinState(LPC_GPIO_PORT, Dio_Config.Pins[i].GPIO_Port, Dio_Config.Pins[i].GPIO_Pin, 1); /* Set it as high */
}

}
return IO_E_OK;
}

extern IO_ValueType Dio_GetSync_Arch(IO_ChannelType channel)
{
return IO_HIGH;
IO_ValueType value;
#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
if(DIO_PINS_COUNT > channel && (Dio_Config.Pins[channel].Flags & (DIO_CONFIG_PIN_DIRECTION_OUTPUT_INIT_LOW | DIO_CONFIG_PIN_DIRECTION_OUTPUT_INIT_HIGH)))
#endif
{
value = (IO_ValueType) Chip_GPIO_GetPinState(LPC_GPIO_PORT, Dio_Config.Pins[channel].GPIO_Port, Dio_Config.Pins[channel].GPIO_Pin); /* Get this value */
if(Dio_Config.Pins[channel].Flags & DIO_CONFIG_PIN_INVERTED)
{
value = !value;
}
}
return value;
}

extern void Dio_SetSync_Arch(IO_ChannelType channel, IO_ValueType value)
{

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
if(DIO_PINS_COUNT > channel && (Dio_Config.Pins[channel].Flags & (DIO_CONFIG_PIN_DIRECTION_OUTPUT_INIT_LOW | DIO_CONFIG_PIN_DIRECTION_OUTPUT_INIT_HIGH)))
#endif
{
if(Dio_Config.Pins[channel].Flags & DIO_CONFIG_PIN_INVERTED)
{
value = !value;
}
Chip_GPIO_SetPinState(LPC_GPIO_PORT, Dio_Config.Pins[channel].GPIO_Port, Dio_Config.Pins[channel].GPIO_Pin, value); /* Set this value */
}
}

extern IO_ValueType Dio_GetPortSync_Arch(IO_ChannelType channel)
Expand Down

0 comments on commit fe37f5f

Please sign in to comment.