Compare commits
6 Commits
1s
...
cf62e0c0a0
Author | SHA1 | Date | |
---|---|---|---|
cf62e0c0a0
|
|||
044779681b
|
|||
167617ad2c | |||
26db6bf03d | |||
a4adf6ac27 | |||
8da88e96c2
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <msp430g2553.h>
|
||||||
|
|
||||||
|
|
||||||
#include "PontCoopScheduler.h"
|
#include "PontCoopScheduler.h"
|
||||||
@ -15,7 +16,7 @@ tTask tasks[MAX_NUM_OF_TASKS];
|
|||||||
|
|
||||||
|
|
||||||
void schInit() {
|
void schInit() {
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
tasks[i].delay = 0;
|
tasks[i].delay = 0;
|
||||||
tasks[i].period = 0;
|
tasks[i].period = 0;
|
||||||
tasks[i].run = 0;
|
tasks[i].run = 0;
|
||||||
@ -25,7 +26,7 @@ void schInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period) {
|
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period) {
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
if (tasks[i].exec == NULL) {
|
if (tasks[i].exec == NULL) {
|
||||||
tasks[i].delay = delay;
|
tasks[i].delay = delay;
|
||||||
tasks[i].period = period;
|
tasks[i].period = period;
|
||||||
@ -41,23 +42,34 @@ void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void schDel(void (*exec)(void *), void *handle) {
|
void schDel(void (*exec)(void *), void *handle) {
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) {
|
if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) {
|
||||||
tasks[i].exec = NULL;
|
tasks[i].exec = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void schExec() {
|
void schExec() {
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
|
// synchronize access to tasks[].run
|
||||||
|
__disable_interrupt();
|
||||||
if (tasks[i].exec != NULL && tasks[i].run > 0) {
|
if (tasks[i].exec != NULL && tasks[i].run > 0) {
|
||||||
tasks[i].run--;
|
tasks[i].run--;
|
||||||
|
// synchronize access to tasks[].run
|
||||||
|
// reenable interrupts before actually executing task
|
||||||
|
__enable_interrupt();
|
||||||
tasks[i].exec(tasks[i].handle);
|
tasks[i].exec(tasks[i].handle);
|
||||||
if (tasks[i].period == 0) {
|
if (tasks[i].period == 0) {
|
||||||
tasks[i].exec = NULL;
|
tasks[i].exec = NULL;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// synchronize access to tasks[].run
|
||||||
|
// reenable interrupts in case task is not yet executable
|
||||||
|
__enable_interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +77,7 @@ void schExec() {
|
|||||||
|
|
||||||
|
|
||||||
void schUpdate() {
|
void schUpdate() {
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
if (tasks[i].exec != NULL) {
|
if (tasks[i].exec != NULL) {
|
||||||
if (tasks[i].delay == 0) {
|
if (tasks[i].delay == 0) {
|
||||||
tasks[i].delay = tasks[i].period;
|
tasks[i].delay = tasks[i].period;
|
||||||
@ -76,13 +88,3 @@ void schUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t schTaskCnt() {
|
|
||||||
uint8_t cnt = 0;
|
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
|
||||||
if (tasks[i].exec != NULL){
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cnt;
|
|
||||||
}
|
|
4
canvas.c
4
canvas.c
@ -28,4 +28,6 @@ void canvasShow() {
|
|||||||
displayDriverTransferCanvas();
|
displayDriverTransferCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color) {
|
||||||
|
*((canvas.canvas) + (row * canvas.width + column)) = (color + 0x80);
|
||||||
|
}
|
||||||
|
1
canvas.h
1
canvas.h
@ -17,6 +17,7 @@ typedef struct {
|
|||||||
void canvasInit();
|
void canvasInit();
|
||||||
canvas_t *canvasGet();
|
canvas_t *canvasGet();
|
||||||
void canvasShow();
|
void canvasShow();
|
||||||
|
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ void displayDriverInit() {
|
|||||||
UCB0CTL0 = UCMST;
|
UCB0CTL0 = UCMST;
|
||||||
// SPI timing config
|
// SPI timing config
|
||||||
UCB0CTL1 = UCSSEL_3;
|
UCB0CTL1 = UCSSEL_3;
|
||||||
UCB0BR0 = 8;
|
UCB0BR0 = 4; // 2 would be too fast and ends up with errors
|
||||||
UCB0BR1 = 0;
|
UCB0BR1 = 0;
|
||||||
|
|
||||||
// BIT5: UCB0CLK
|
// BIT5: UCB0CLK
|
||||||
|
@ -4,19 +4,84 @@
|
|||||||
|
|
||||||
|
|
||||||
static canvas_t *canvas;
|
static canvas_t *canvas;
|
||||||
static uint8_t lastPixel = 0xff;
|
|
||||||
static uint8_t currentPixel = 0;
|
#define MAX_COLOR 0x0d
|
||||||
|
|
||||||
void displayTestExec(void *args) {
|
void displayTestExec(void *args) {
|
||||||
if (lastPixel != 0xff) {
|
static uint8_t last = 0xff;
|
||||||
*((canvas->canvas)+lastPixel) = 0x80;
|
static uint8_t current = 0;
|
||||||
|
static uint8_t color = 0x01;
|
||||||
|
static uint8_t state = 1;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
for (uint16_t i = 0; i < canvas->height; i++) {
|
||||||
|
canvasSetPixel(last, i, 0);
|
||||||
|
}
|
||||||
|
last = 0xff;
|
||||||
|
state = 1;
|
||||||
|
case 1:
|
||||||
|
if (last != 0xff) {
|
||||||
|
*((canvas->canvas)+last) = 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = current;
|
||||||
|
*((canvas->canvas)+current) = (color + 0x80);
|
||||||
|
current++;
|
||||||
|
if (current >= canvas->size) {
|
||||||
|
current = 0;
|
||||||
|
state = 2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
*((canvas->canvas)+last) = 0x80;
|
||||||
|
last = 0xff;
|
||||||
|
state = 3;
|
||||||
|
case 3:
|
||||||
|
if (last != 0xff) {
|
||||||
|
for (uint16_t i = 0; i < canvas->width; i++) {
|
||||||
|
canvasSetPixel(i, last, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last = current;
|
||||||
|
for (uint16_t i = 0; i < canvas->width; i++) {
|
||||||
|
canvasSetPixel(i, current, color);
|
||||||
|
}
|
||||||
|
current++;
|
||||||
|
if (current >= canvas->height) {
|
||||||
|
current = 0;
|
||||||
|
state = 4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
for (uint16_t i = 0; i < canvas->width; i++) {
|
||||||
|
canvasSetPixel(i, last, 0);
|
||||||
|
}
|
||||||
|
last = 0xff;
|
||||||
|
state = 5;
|
||||||
|
case 5:
|
||||||
|
if (last != 0xff) {
|
||||||
|
for (uint16_t i = 0; i < canvas->height; i++) {
|
||||||
|
canvasSetPixel(last, i, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last = current;
|
||||||
|
for (uint16_t i = 0; i < canvas->height; i++) {
|
||||||
|
canvasSetPixel(current, i, color);
|
||||||
|
}
|
||||||
|
current++;
|
||||||
|
if (current >= canvas->width) {
|
||||||
|
current = 0;
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPixel = currentPixel;
|
color++;
|
||||||
*((canvas->canvas)+currentPixel) = 0x81;
|
if (color > MAX_COLOR) {
|
||||||
currentPixel++;
|
color = 1;
|
||||||
if (currentPixel >= canvas->size) {
|
|
||||||
currentPixel = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canvasShow();
|
canvasShow();
|
||||||
|
BIN
docs/1second.png
Normal file
BIN
docs/1second.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
BIN
docs/one-color.png
Normal file
BIN
docs/one-color.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
BIN
docs/working-transfer.png
Normal file
BIN
docs/working-transfer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
4
led.c
4
led.c
@ -21,7 +21,7 @@ void ledBlueOff() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ledExec(void *args) {
|
void ledExec(void *args) {
|
||||||
static int i = 0;
|
static uint16_t i = 0;
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
ledGreenOff();
|
ledGreenOff();
|
||||||
@ -41,7 +41,7 @@ void ledInit() {
|
|||||||
ledBlueOff();
|
ledBlueOff();
|
||||||
|
|
||||||
|
|
||||||
// schAdd(ledExec, NULL, 0, 50);
|
schAdd(ledExec, NULL, 0, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
main.c
2
main.c
@ -29,7 +29,7 @@ int main() {
|
|||||||
ledInit();
|
ledInit();
|
||||||
displayDriverInit();
|
displayDriverInit();
|
||||||
canvasInit();
|
canvasInit();
|
||||||
displayTestInit();
|
displayTestInit();
|
||||||
|
|
||||||
|
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
14
time.c
14
time.c
@ -1,30 +1,16 @@
|
|||||||
#include <msp430g2553.h>
|
#include <msp430g2553.h>
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "PontCoopScheduler.h"
|
#include "PontCoopScheduler.h"
|
||||||
|
|
||||||
|
|
||||||
volatile uint32_t timestamp;
|
|
||||||
|
|
||||||
void __attribute__ ((interrupt (TIMER0_A0_VECTOR))) ta0_isr() {
|
void __attribute__ ((interrupt (TIMER0_A0_VECTOR))) ta0_isr() {
|
||||||
timestamp++;
|
|
||||||
schUpdate();
|
schUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeInit() {
|
void timeInit() {
|
||||||
timestamp = 0;
|
|
||||||
|
|
||||||
TACCR0 = 32;
|
TACCR0 = 32;
|
||||||
TACCTL0 = CCIE;
|
TACCTL0 = CCIE;
|
||||||
TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR;
|
TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getMillis() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ms_active_delay(uint16_t delay) {
|
|
||||||
uint32_t start = timestamp;
|
|
||||||
while (start + delay > timestamp);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user