Subversion Repositories HomeAutomation

Rev

Rev 1703 | Rev 1712 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1703 Rev 1711
Line 2... Line 2...
2
#include "act_pcaPWM.h"
2
#include "act_pcaPWM.h"
3
#include "drivers/io/PCA9634.h"
3
#include "drivers/io/PCA9634.h"
-
 
4
 
-
 
5
static uint16_t setValue[8];
-
 
6
static uint16_t isValue[8];
4
 
7
 
5
#ifdef act_pcaPWM_USEEEPROM
8
#ifdef act_pcaPWM_USEEEPROM
6
#include "act_pcaPWM_eeprom.h"
9
#include "act_pcaPWM_eeprom.h"
7
struct eeprom_act_pcaPWM EEMEM eeprom_act_pcaPWM =
10
struct eeprom_act_pcaPWM EEMEM eeprom_act_pcaPWM =
8
{
11
{
9
    {
12
    {
10
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file.
13
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file.
-
 
14
        0x0000, // ch 1
11
        0xAB,       // x
15
        0x0000, // ch 2
12
        0x1234      // y
16
        0x0000, // ch 3
-
 
17
        0x0000, // ch 4
-
 
18
        0x0000, // ch 5
-
 
19
        0x0000, // ch 6
13
        0x12345678  // z
20
        0x0000, // ch 7
-
 
21
        0x0000  // ch 8
14
    },
22
    },
15
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
23
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
16
};
24
};
17
#endif
25
#endif
18
 
26
 
19
void act_pcaPWM_Init(void)
27
void act_pcaPWM_Init(void)
20
{
28
{
21
#ifdef act_pcaPWM_USEEEPROM
29
#ifdef act_pcaPWM_USEEEPROM
22
    if (EEDATA_OK)
30
    if (EEDATA_OK)
23
    {
31
    {
-
 
32
      setValue[0] = eeprom_read_word(EEDATA16.ch1);
24
      ///TODO: Use stored data to set initial values for the module
33
      setValue[1] = eeprom_read_word(EEDATA16.ch2);
25
      blablaX = eeprom_read_byte(EEDATA.x);
34
      setValue[2] = eeprom_read_word(EEDATA16.ch3);
-
 
35
      setValue[3] = eeprom_read_word(EEDATA16.ch4);
-
 
36
      setValue[4] = eeprom_read_word(EEDATA16.ch5);
-
 
37
      setValue[5] = eeprom_read_word(EEDATA16.ch6);
26
      blablaY = eeprom_read_word(EEDATA16.y);
38
      setValue[6] = eeprom_read_word(EEDATA16.ch7);
27
      blablaZ = eeprom_read_dword(EEDATA32.y);
39
      setValue[7] = eeprom_read_word(EEDATA16.ch8);
28
    } else
40
    } else
29
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
41
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
-
 
42
      eeprom_write_word_crc(EEDATA16.ch1, 0x0000, WITHOUT_CRC);
-
 
43
      eeprom_write_word_crc(EEDATA16.ch2, 0x0000, WITHOUT_CRC);
-
 
44
      eeprom_write_word_crc(EEDATA16.ch3, 0x0000, WITHOUT_CRC);
30
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
45
      eeprom_write_word_crc(EEDATA16.ch4, 0x0000, WITHOUT_CRC);
-
 
46
      eeprom_write_word_crc(EEDATA16.ch5, 0x0000, WITHOUT_CRC);
-
 
47
      eeprom_write_word_crc(EEDATA16.ch6, 0x0000, WITHOUT_CRC);
31
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
48
      eeprom_write_word_crc(EEDATA16.ch7, 0x0000, WITHOUT_CRC);
32
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
49
      eeprom_write_word_crc(EEDATA16.ch8, 0x0000, WITHOUT_CRC);
33
      EEDATA_UPDATE_CRC;
50
      EEDATA_UPDATE_CRC;
34
    }
51
    }
35
#endif
52
#endif
36
    ///TODO: Initialize hardware etc here
-
 
37
 
53
 
38
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
54
    pca9634_init(act_pcaPWM_I2C_ADDRESS);
-
 
55
    for (uint8_t i=0; i<8; i++)
-
 
56
    {
-
 
57
        pca9634_setOpMode(i, PCA9634_OP_IND);
39
    // Pcint_SetCallbackPin(act_pcaPWM_PCINT, EXP_C , &act_pcaPWM_pcint_callback);
58
        /* Set "current" value to something impossible to force an update at start */
-
 
59
        isValue[i] = 10001;
-
 
60
    }
40
 
61
   
-
 
62
#ifdef act_pcaPWM_OUTPUT_ENABLE_IO
-
 
63
    gpio_set_out(act_pcaPWM_OUTPUT_ENABLE_IO);
-
 
64
    gpio_clr_pin(act_pcaPWM_OUTPUT_ENABLE_IO);
-
 
65
#endif
-
 
66
#ifdef act_pcaPWM_LED_OVERRIDE_IO
-
 
67
    gpio_set_out(act_pcaPWM_LED_OVERRIDE_IO);
-
 
68
    gpio_clr_pin(act_pcaPWM_LED_OVERRIDE_IO);
-
 
69
#endif
41
}
70
}
42
 
71
 
43
void act_pcaPWM_Process(void)
72
void act_pcaPWM_Process(void)
44
{
73
{
-
 
74
 
45
    ///TODO: Stuff that needs doing is done here
75
    for (uint8_t i=0; i < 8; i++)
-
 
76
    {
-
 
77
        if (setValue[i] != isValue[i])
-
 
78
        {
-
 
79
            isValue[i] = setValue[i];
-
 
80
            pca9634_setDuty(i, isValue[i]*act_pcaPWM_FACT);
-
 
81
            Timer_SetTimeout(act_pcaPWM_STORE_VALUE_TIMEOUT, act_pcaPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
-
 
82
        }
-
 
83
    }
-
 
84
 
-
 
85
    if (Timer_Expired(act_pcaPWM_STORE_VALUE_TIMEOUT))
-
 
86
    {
-
 
87
        if (isValue[0] != eeprom_read_word(EEDATA16.ch1))
-
 
88
        {
-
 
89
            eeprom_write_word_crc(EEDATA16.ch1, isValue[0], WITH_CRC);
-
 
90
        }
-
 
91
        if (isValue[1] != eeprom_read_word(EEDATA16.ch2))
-
 
92
        {
-
 
93
            eeprom_write_word_crc(EEDATA16.ch2, isValue[1], WITH_CRC);
-
 
94
        }
-
 
95
        if (isValue[2] != eeprom_read_word(EEDATA16.ch3))
-
 
96
        {
-
 
97
            eeprom_write_word_crc(EEDATA16.ch3, isValue[2], WITH_CRC);
-
 
98
        }
-
 
99
        if (isValue[3] != eeprom_read_word(EEDATA16.ch4))
-
 
100
        {
-
 
101
            eeprom_write_word_crc(EEDATA16.ch4, isValue[3], WITH_CRC);
-
 
102
        }
-
 
103
        if (isValue[4] != eeprom_read_word(EEDATA16.ch5))
-
 
104
        {
-
 
105
            eeprom_write_word_crc(EEDATA16.ch5, isValue[4], WITH_CRC);
-
 
106
        }
-
 
107
        if (isValue[5] != eeprom_read_word(EEDATA16.ch6))
-
 
108
        {
-
 
109
            eeprom_write_word_crc(EEDATA16.ch6, isValue[5], WITH_CRC);
-
 
110
        }
-
 
111
        if (isValue[6] != eeprom_read_word(EEDATA16.ch7))
-
 
112
        {
-
 
113
            eeprom_write_word_crc(EEDATA16.ch7, isValue[6], WITH_CRC);
-
 
114
        }
-
 
115
        if (isValue[7] != eeprom_read_word(EEDATA16.ch8))
-
 
116
        {
-
 
117
            eeprom_write_word_crc(EEDATA16.ch8, isValue[7], WITH_CRC);
-
 
118
        }
-
 
119
    }
-
 
120
 
46
}
121
}
47
 
122
 
48
void act_pcaPWM_HandleMessage(StdCan_Msg_t *rxMsg)
123
void act_pcaPWM_HandleMessage(StdCan_Msg_t *rxMsg)
49
{
124
{
50
#if 0
-
 
51
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_xyz && ///TODO: Change this to the actual class type
125
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
52
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
126
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
53
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_xyz && ///TODO: Change this to the actual module type
127
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_PCAPWM &&
54
        rxMsg->Header.ModuleId == act_pcaPWM_ID)
128
        rxMsg->Header.ModuleId == act_pcaPWM_ID)
55
    {
129
    {
-
 
130
        uint8_t channel = 0;
56
        switch (rxMsg->Header.Command)
131
        switch (rxMsg->Header.Command)
57
        {
132
        {
58
        case CAN_CMD_MODULE_DUMMY:
133
        case CAN_MODULE_CMD_PHYSICAL_PWM:
59
        ///TODO: Do something dummy
134
            if (rxMsg->Length == 3) {
-
 
135
                channel = rxMsg->Data[0];
-
 
136
                setValue[channel] = (rxMsg->Data[1]<<8)+(rxMsg->Data[2]);
-
 
137
            }
-
 
138
           
60
        break;
139
        break;
61
        }
140
        }
62
    }
141
    }
63
#endif
-
 
64
}
142
}
65
 
143
 
66
void act_pcaPWM_List(uint8_t ModuleSequenceNumber)
144
void act_pcaPWM_List(uint8_t ModuleSequenceNumber)
67
{
145
{
68
#if 0
-
 
69
    StdCan_Msg_t txMsg;
146
    StdCan_Msg_t txMsg;
70
 
147
 
71
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_xyz); ///TODO: Change this to the actual class type
148
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
72
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
149
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
73
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_xyz; ///TODO: Change this to the actual module type
150
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_PCAPWM;
74
    txMsg.Header.ModuleId = act_pcaPWM_ID;
151
    txMsg.Header.ModuleId = act_pcaPWM_ID;
75
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
152
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
76
    txMsg.Length = 6;
153
    txMsg.Length = 6;
77
 
154
 
78
    txMsg.Data[0] = NODE_HW_ID_BYTE0;
155
    txMsg.Data[0] = NODE_HW_ID_BYTE0;
Line 82... Line 159...
82
 
159
 
83
    txMsg.Data[4] = NUMBER_OF_MODULES;
160
    txMsg.Data[4] = NUMBER_OF_MODULES;
84
    txMsg.Data[5] = ModuleSequenceNumber;
161
    txMsg.Data[5] = ModuleSequenceNumber;
85
 
162
 
86
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
163
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
87
#endif
-
 
88
}
164
}