comparison gsm-fw/bsp/abb+spi/spi_task.c @ 148:63750f70796d

gsm-fw/bsp/abb+spi: initial import from the Leonardo TCS211 version
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 16 Nov 2013 19:03:37 +0000
parents
children e48ea5875df7
comparison
equal deleted inserted replaced
147:4ac657b95f52 148:63750f70796d
1 /*****************************************************************************/
2 /* */
3 /* Name spi_task.c */
4 /* */
5 /* Function this file contains the main SPI function: spi_core. */
6 /* It contains the body of the SPI task. */
7 /* It will initialize the SPI and then wait for messages */
8 /* or functions calls. */
9 /* */
10 /* Version 0.1 */
11 /* Author Candice Bazanegue */
12 /* */
13 /* Date Modification */
14 /* ------------------------------------ */
15 /* 20/08/2000 Create */
16 /* 01/09/2003 Modfication */
17 /* Author Pascal Puel */
18 /* */
19 /* (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved */
20 /*****************************************************************************/
21
22 #ifndef _WINDOWS
23 #include "chipset.cfg"
24 #if (CHIPSET == 12)
25 #include "inth/sys_inth.h"
26 #else
27 #include "inth/iq.h" // for IQ_Unmask()
28 #endif
29 #include "power/power.h" // for Switch_ON()
30 #endif
31
32 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE
33 #include "rvm/rvm_use_id_list.h"
34 #include "spi/spi_env.h"
35 #include "spi/spi_process.h"
36 #include "spi/spi_task.h"
37
38 #ifdef RVM_PWR_SWE
39 #include "pwr/pwr_liion_cha.h"
40 #include "pwr/pwr_disch.h"
41 #include "pwr/pwr_process.h"
42 #include "pwr/pwr_env.h"
43 #endif
44
45
46
47 /*******************************************************************************
48 ** Function spi_core
49 **
50 ** Description Core of the spi task, which initiliazes the spi SWE and
51 ** waits for messages.
52 **
53 *******************************************************************************/
54 T_RV_RET spi_core(void)
55 {
56 BOOLEAN error_occured = FALSE;
57 T_RV_HDR * msg_ptr;
58
59 rvf_send_trace("SPI_task: Initialization", 24, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
60 SPI_GBL_INFO_PTR->SpiTaskReady = TRUE;
61
62 #ifndef _WINDOWS
63 /* Unmask External Interrupt once the SPI task is started */
64 #if (CHIPSET == 12)
65 // Unmask ABB ext interrupt
66 F_INTH_ENABLE_ONE_IT(C_INTH_ABB_IRQ_IT);
67 #else
68 // Unmask external (ABB) interrupt
69 IQ_Unmask(IQ_EXT);
70 #endif
71 // Get the switch on cause from ABB.
72 Set_Switch_ON_Cause();
73 #endif
74
75 /* loop to process messages */
76 while (error_occured == FALSE)
77 {
78 /* Wait for the necessary events (infinite wait for a msg in the mailbox 0). */
79 UINT16 received_event = rvf_wait (0xffff, 0);
80
81 /* If an event related to mailbox 0 is received, then */
82 if (received_event & RVF_TASK_MBOX_0_EVT_MASK)
83 {
84 /* Read the message in the driver mailbox and delegate action..*/
85 msg_ptr = (T_RV_HDR *) rvf_read_mbox(SPI_MAILBOX);
86
87 #ifdef RVM_PWR_SWE
88 if(spi_process(msg_ptr))
89 {
90 pwr_process(msg_ptr);
91 }
92 #else
93 spi_process(msg_ptr);
94 #endif
95 }
96
97 #ifdef RVM_PWR_SWE
98 /* Timers */
99 if (received_event & SPI_TIMER0_WAIT_EVENT)
100 {
101 pwr_bat_test_timer_process();
102 }
103
104 if (received_event & SPI_TIMER1_WAIT_EVENT)
105 /* timer used to detect the end of the CI charge */
106 {
107 pwr_CI_charge_timer_process();
108 }
109
110 if (received_event & SPI_TIMER2_WAIT_EVENT)
111 /* timer used to detect the end of the CV charge */
112 {
113 pwr_CV_charge_timer_process();
114 }
115
116 if (received_event & SPI_TIMER3_WAIT_EVENT)
117 /* timer used to check the battery discharge level */
118 {
119 pwr_discharge_timer_process();
120 }
121 #endif
122 } // end of while
123 return RV_OK;
124 }
125
126
127
128 /**********************************************************************************
129 * Function : spi_adc_on
130 *
131 * Description : Put the variable is_adc_on of the T_SPI_GBL_INFO structure to TRUE.
132 * This variable is used for the battery management.
133 * This function is called by the CST entity.
134 *
135 * Parameters : None
136 *
137 * Return : None
138 *
139 **********************************************************************************/
140 void spi_adc_on (void)
141 {
142 SPI_GBL_INFO_PTR->is_adc_on = TRUE;
143
144 rvf_send_trace("SPI: ADC are on",15,
145 NULL_PARAM,
146 RV_TRACE_LEVEL_DEBUG_LOW,
147 SPI_USE_ID);
148 }