Check this one ! mbos setup changed, WTX hor pos changed, no font style check, no checksum check

Dependencies:   4DGL MODSERIAL mbed mbos

Fork of CDU_Mbed_21 by Engravity-CDU

Committer:
WillemBraat
Date:
Mon Jul 21 14:24:15 2014 +0000
Revision:
11:d60c746c097c
Parent:
8:422544d24df3
screen_handler.cpp
; Added external flag S_Exec in procedure . Inhibits screen updates when 1. S_Exec is declared in line 77 of FS2CDU_data_5.cpp
;
; keyboard2.cpp
; Line 40. Added Key_led=0
;
; keyboard2.cpp "
; Added switch value in CDU_SET_BGL_INTENSIT...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
LvdK 7:6576a287e563 1 // L. van der Kolk, W.Braat
LvdK 7:6576a287e563 2 // File: main.cpp
LvdK 8:422544d24df3 3 // Version 26 --->> other MBOS setup !
LvdK 8:422544d24df3 4 // -----------------------------------------
LvdK 5:99594f4ab659 5
LvdK 0:6f71ca095e78 6 #include "mbed.h"
LvdK 6:e0bf3b244d7c 7 #include "MODSERIAL.h"
LvdK 6:e0bf3b244d7c 8 #include "mbos.h"
LvdK 8:422544d24df3 9 #include "mbos_def2.h" // : Mbos tasks, timer and resource definitions
LvdK 6:e0bf3b244d7c 10
LvdK 7:6576a287e563 11 // Setup USB communication defined by Mbed USB TX and RX lines
LvdK 7:6576a287e563 12 // with TX and RX ringbuffers :
LvdK 8:422544d24df3 13 MODSERIAL USB(USBTX, USBRX, 256, 1024);
LvdK 7:6576a287e563 14 DigitalOut alive_led(LED1); // : LED 1 on Mbed board toggles when CDU is alive
LvdK 7:6576a287e563 15
LvdK 8:422544d24df3 16 //void test_update_flags(); // << for testing only << !!!!!!!
LvdK 6:e0bf3b244d7c 17
LvdK 8:422544d24df3 18 // --- Debug only ----------------------------------------
LvdK 7:6576a287e563 19 // extra serial port to show debug info :
LvdK 8:422544d24df3 20 MODSERIAL SERIAL_DEBUG(p9, p10, 512, 64); //: tx, rx
LvdK 8:422544d24df3 21 // -------------------------------------------------------
LvdK 7:6576a287e563 22
LvdK 6:e0bf3b244d7c 23 int CDU_FS_interface = 0; // : defines interface to FS: 0 = USB, 1 = Ethernet
LvdK 7:6576a287e563 24 extern int key_hit_ID;
LvdK 7:6576a287e563 25 extern PwmOut BGL_LED;
LvdK 0:6f71ca095e78 26
LvdK 7:6576a287e563 27 void init_USB(void);
LvdK 8:422544d24df3 28 void set_initial_data(void); // : fill datastructures with initial data
LvdK 8:422544d24df3 29 void Send_KEY_message(int key_nr);
LvdK 6:e0bf3b244d7c 30 void Send_ALIVE_message(int seconds);
LvdK 6:e0bf3b244d7c 31 void collect_FSdata();
LvdK 6:e0bf3b244d7c 32
LvdK 7:6576a287e563 33 mbos CDU_OS( 9, 5, 5); // : instantiate mbos O.S (tasks, timers, resources)
LvdK 6:e0bf3b244d7c 34
LvdK 7:6576a287e563 35 // Task function prototypes:
LvdK 7:6576a287e563 36 void ALIVE_TASK(void);
LvdK 7:6576a287e563 37 void RECEIVE_DECODE_TASK(void);
LvdK 7:6576a287e563 38 void SEND_KEYMESSAGE_TASK(void);
LvdK 7:6576a287e563 39 void CDU_DSP_CSS_TASK(void);
LvdK 7:6576a287e563 40 void READ_POT_TASK(void);
LvdK 6:e0bf3b244d7c 41
LvdK 7:6576a287e563 42 // keyboard function prototypes:
LvdK 7:6576a287e563 43 void CDU_KB_COMM_INIT(void);
LvdK 7:6576a287e563 44 void CDU_KB_INT_START(void);
LvdK 7:6576a287e563 45 void CDU_KB_GET_KEY(void);
LvdK 7:6576a287e563 46 void CDU_SET_BGL_INTENSITY(int);
LvdK 6:e0bf3b244d7c 47
LvdK 8:422544d24df3 48 // display function prototypes:
LvdK 7:6576a287e563 49 void CDU_InitDisplay(void);
LvdK 7:6576a287e563 50 void CDU_ScreenAlign(void);
LvdK 7:6576a287e563 51 void CDU_StartScreen(void);
LvdK 7:6576a287e563 52 void CDU_Page(void);
LvdK 7:6576a287e563 53 void CDU_DSP_CSS(void);
LvdK 7:6576a287e563 54 void CDU_displayclear(void);
LvdK 6:e0bf3b244d7c 55
LvdK 8:422544d24df3 56 //------ USB buffer overflow interrupt handling: -------------
LvdK 7:6576a287e563 57 void rx_buf_overflow(MODSERIAL_IRQ_INFO *q)
LvdK 8:422544d24df3 58 { // This functiom will be called when RX buffer overflows.
LvdK 7:6576a287e563 59 // Blue-Leds-of-Death will be showed on Mbed board
LvdK 7:6576a287e563 60 error("RX OVERFLOW !");
LvdK 6:e0bf3b244d7c 61 }
LvdK 6:e0bf3b244d7c 62
LvdK 7:6576a287e563 63 void tx_buf_overflow(MODSERIAL_IRQ_INFO *q)
LvdK 8:422544d24df3 64 { // This functiom will be called when TX buffer overflows.
LvdK 7:6576a287e563 65 // Blue-Leds-of-Death will be showed on Mbed board
LvdK 7:6576a287e563 66 error("RX OVERFLOW !");
LvdK 6:e0bf3b244d7c 67 }
LvdK 8:422544d24df3 68 //------------------------------------------------------------
LvdK 6:e0bf3b244d7c 69
LvdK 6:e0bf3b244d7c 70 void init_USB()
LvdK 8:422544d24df3 71 { // -- This function controls the setup for the CDU-FS USB communication --
LvdK 7:6576a287e563 72 // Function char_received() will be attached to RX interrupt.
LvdK 7:6576a287e563 73 USB.baud(38400); // : set default baudrate to 38400
LvdK 7:6576a287e563 74 USB.rxBufferFlush(); // : empty USB rx buffer in case it is not empty:
LvdK 7:6576a287e563 75 USB.txBufferFlush(); // : empty USB tx buffer in case it is not empty:
LvdK 7:6576a287e563 76 USB.attach(&rx_buf_overflow, MODSERIAL::RxOvIrq); // : attach function to call when USB RX buffer overflows
LvdK 7:6576a287e563 77 USB.attach(&tx_buf_overflow, MODSERIAL::TxOvIrq); // : attach function to call when USB TX buffer overflows
LvdK 6:e0bf3b244d7c 78 }
LvdK 7:6576a287e563 79
LvdK 7:6576a287e563 80 main() // : MBOS main()
LvdK 0:6f71ca095e78 81 {
LvdK 7:6576a287e563 82 init_USB(); // : setup USB communication to FS
LvdK 7:6576a287e563 83
LvdK 8:422544d24df3 84 // CDU keyboard initialisation and keyboard interrrupt setup:
LvdK 7:6576a287e563 85 CDU_KB_COMM_INIT();
LvdK 7:6576a287e563 86 CDU_KB_INT_START();
LvdK 7:6576a287e563 87 BGL_LED.period(0.01);
LvdK 5:99594f4ab659 88
LvdK 8:422544d24df3 89 // CDU display initialisation:
LvdK 7:6576a287e563 90 CDU_InitDisplay();
LvdK 7:6576a287e563 91 CDU_StartScreen();
LvdK 8:422544d24df3 92 wait(0.2);
LvdK 8:422544d24df3 93 //CDU_Page();
LvdK 7:6576a287e563 94 CDU_ScreenAlign();
LvdK 8:422544d24df3 95
LvdK 8:422544d24df3 96 set_initial_data(); //: fill FS datastructures with initial data
LvdK 7:6576a287e563 97
LvdK 8:422544d24df3 98 // -- debug only -------------------------------------
LvdK 7:6576a287e563 99 SERIAL_DEBUG.baud(38400); // : set baudrate to 38400
LvdK 8:422544d24df3 100 SERIAL_DEBUG.printf("\n--- CDU_Mbed_26 ---\r\n");
LvdK 8:422544d24df3 101 // ---------------------------------------------------
LvdK 7:6576a287e563 102
LvdK 8:422544d24df3 103 // Create all mbos tasks, timers and resources:
LvdK 8:422544d24df3 104 // Tasks:
LvdK 7:6576a287e563 105 CDU_OS.CreateTask(ALIVE_TASK_ID, ALIVE_TASK_PRIO, ALIVE_TASK_STACK_SZ, ALIVE_TASK);
LvdK 7:6576a287e563 106 CDU_OS.CreateTask(RECEIVE_DECODE_TASK_ID, RECEIVE_DECODE_TASK_PRIO, RECEIVE_DECODE_TASK_STACK_SZ, RECEIVE_DECODE_TASK);
LvdK 7:6576a287e563 107 CDU_OS.CreateTask(SEND_KEYMESSAGE_TASK_ID, SEND_KEYMESSAGE_TASK_PRIO, SEND_KEYMESSAGE_TASK_STACK_SZ, SEND_KEYMESSAGE_TASK);
LvdK 7:6576a287e563 108 CDU_OS.CreateTask(CDU_DSP_CSS_TASK_ID, CDU_DSP_CSS_TASK_PRIO, CDU_DSP_CSS_TASK_STACK_SZ, CDU_DSP_CSS_TASK );
LvdK 7:6576a287e563 109 CDU_OS.CreateTask(READ_POT_TASK_ID, READ_POT_TASK_PRIO, READ_POT_TASK_STACK_SZ, READ_POT_TASK );
LvdK 8:422544d24df3 110 // Timers:
LvdK 7:6576a287e563 111 CDU_OS.CreateTimer(READ_POT_TIMER_ID, READ_POT_TASK_ID, READ_POT_TIMER_EVENT);
LvdK 8:422544d24df3 112 CDU_OS.CreateTimer(ALIVE_TIMER_ID, ALIVE_TASK_ID, ALIVE_EVENT);
LvdK 8:422544d24df3 113 CDU_OS.CreateTimer(DECODE_TIMER_ID, RECEIVE_DECODE_TASK_ID, DECODE_TIMER_EVENT);
LvdK 8:422544d24df3 114 // Resources:
LvdK 7:6576a287e563 115 CDU_OS.CreateResource(USB_TX_RESOURCE, USB_TX_PRIO);
LvdK 8:422544d24df3 116 CDU_OS.CreateResource(FS_DATA_RESOURCE, FS_DATA_PRIO);
LvdK 7:6576a287e563 117
LvdK 7:6576a287e563 118 // Start mbos O.S with a final statement in main() :
LvdK 7:6576a287e563 119 CDU_OS.Start(); // : MBOS is running tasks now....
LvdK 8:422544d24df3 120 // end of main <<---- program never reaches this point !
LvdK 7:6576a287e563 121 }
LvdK 6:e0bf3b244d7c 122
LvdK 6:e0bf3b244d7c 123 void RECEIVE_DECODE_TASK(void)
LvdK 8:422544d24df3 124 { // Mbos task triggered by mbos timer to scan USB receive buffer every 100 msec.
LvdK 8:422544d24df3 125 // Collects and decodes data received from USB.
LvdK 8:422544d24df3 126 CDU_OS.SetTimer( DECODE_TIMER_ID, DECODE_TIMER_PERIOD, DECODE_TIMER_PERIOD );
LvdK 7:6576a287e563 127 while(1) { // : loop forever because it is a mbos taskfunction
LvdK 8:422544d24df3 128 CDU_OS.WaitEvent(DECODE_TIMER_EVENT ); // : wait for Mbos timer event
LvdK 8:422544d24df3 129 // start collecting and decoding of received data:
LvdK 8:422544d24df3 130 CDU_OS.LockResource(FS_DATA_RESOURCE); // : lock FS database
LvdK 6:e0bf3b244d7c 131 collect_FSdata();
LvdK 8:422544d24df3 132 CDU_OS.FreeResource(FS_DATA_RESOURCE); // : free FS database
LvdK 7:6576a287e563 133 }
LvdK 6:e0bf3b244d7c 134 }
LvdK 6:e0bf3b244d7c 135
LvdK 7:6576a287e563 136 void SEND_KEYMESSAGE_TASK(void)
LvdK 8:422544d24df3 137 { // Mbos task triggered by a KEY_EVENT ( = "CDU key pressed" )
LvdK 7:6576a287e563 138 while(1) { // : loop forever because it is a mbos taskfunction
LvdK 8:422544d24df3 139 CDU_OS.WaitEvent(KEY_EVENT); // : wait for KEY event
LvdK 7:6576a287e563 140 CDU_KB_GET_KEY(); // : read key from CDU keyboard
LvdK 7:6576a287e563 141 CDU_OS.LockResource(USB_TX_RESOURCE);
LvdK 6:e0bf3b244d7c 142 Send_KEY_message(key_hit_ID);
LvdK 8:422544d24df3 143 CDU_OS.FreeResource(USB_TX_RESOURCE);
LvdK 7:6576a287e563 144 key_hit_ID = 0; // : reset key_hit_ID flag
LvdK 0:6f71ca095e78 145 }
LvdK 6:e0bf3b244d7c 146 }
LvdK 6:e0bf3b244d7c 147
LvdK 6:e0bf3b244d7c 148 void ALIVE_TASK(void)
LvdK 8:422544d24df3 149 { // Mbos task triggered by mbos timer to send ALIVE message to FS every 5 sec.
LvdK 6:e0bf3b244d7c 150 CDU_OS.SetTimer( ALIVE_TIMER_ID, ALIVE_TIMER_PERIOD, ALIVE_TIMER_PERIOD );
LvdK 6:e0bf3b244d7c 151 static int seconds = 0;
LvdK 7:6576a287e563 152 while(1) { // : loop forever because it is a mbos taskfunction
LvdK 6:e0bf3b244d7c 153 CDU_OS.WaitEvent(ALIVE_EVENT ); // : wait for Mbos timer event (5 sec)
LvdK 7:6576a287e563 154 seconds += 5 ; // : increase seconds by 5
LvdK 7:6576a287e563 155 if (seconds >= 60) seconds = 0 ; // : overflow handling
LvdK 7:6576a287e563 156 CDU_OS.LockResource(USB_TX_RESOURCE);
LvdK 6:e0bf3b244d7c 157 Send_ALIVE_message(seconds);
LvdK 7:6576a287e563 158 CDU_OS.FreeResource(USB_TX_RESOURCE);
LvdK 7:6576a287e563 159 alive_led = !alive_led; // : toggle LED
LvdK 6:e0bf3b244d7c 160 }
LvdK 7:6576a287e563 161 }
LvdK 6:e0bf3b244d7c 162
LvdK 8:422544d24df3 163 void CDU_DSP_CSS_TASK(void)
LvdK 8:422544d24df3 164 { // Mbos task to read new screendata from FS datastructures and show on CDU screen.
LvdK 8:422544d24df3 165 // Triggered by FS_DATA_EVENT ( = "new screendata available" )
LvdK 7:6576a287e563 166 while(1) { // : loop forever because it is a mbos taskfunction
LvdK 8:422544d24df3 167
LvdK 8:422544d24df3 168 if (CDU_OS.TestResource(FS_DATA_RESOURCE) == 0) {
LvdK 8:422544d24df3 169 // FS_DATA_RESOURCE is free to access.
LvdK 8:422544d24df3 170 // Lock it to get exclusive access and prevent intermediate updates:
LvdK 8:422544d24df3 171 CDU_OS.LockResource(FS_DATA_RESOURCE);
LvdK 8:422544d24df3 172 CDU_OS.WaitEvent(FS_DATA_EVENT); // wait for FS_DATA_EVENT
LvdK 8:422544d24df3 173 //test_update_flags(); // : >>>>> debug ONLY !!!
LvdK 8:422544d24df3 174 CDU_DSP_CSS(); // : get data and show on screen
LvdK 8:422544d24df3 175 CDU_OS.FreeResource(FS_DATA_RESOURCE); // : free FS_DATA_RESOURCE
LvdK 8:422544d24df3 176 }
LvdK 8:422544d24df3 177 else {
LvdK 8:422544d24df3 178 // FS_DATA_RESOURCE is occupied, don’t read it !
LvdK 8:422544d24df3 179 }
LvdK 8:422544d24df3 180 }
LvdK 6:e0bf3b244d7c 181 }
LvdK 7:6576a287e563 182
LvdK 8:422544d24df3 183
LvdK 7:6576a287e563 184 void READ_POT_TASK(void)
LvdK 7:6576a287e563 185 { // Mbos task started by mbos timer to scan potmeter every 100 msec
LvdK 8:422544d24df3 186 CDU_OS.SetTimer( READ_POT_TIMER_ID, READ_POT_TIMER_PERIOD, READ_POT_TIMER_PERIOD );
LvdK 7:6576a287e563 187 while(1) { // : loop forever because it is a mbos taskfunction
LvdK 8:422544d24df3 188 CDU_OS.WaitEvent(READ_POT_TIMER_EVENT ); // : wait for Mbos timer event
LvdK 7:6576a287e563 189 CDU_SET_BGL_INTENSITY(255);
LvdK 7:6576a287e563 190 }
LvdK 7:6576a287e563 191 }
LvdK 7:6576a287e563 192
LvdK 8:422544d24df3 193